blob: ee58cf972f5fd97acf30db61eada35a80dc83eca [file] [log] [blame]
Rebecca Silbersteinf4365a62014-09-16 11:40:32 -07001// Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef SHILL_CONNECTION_TESTER_H_
6#define SHILL_CONNECTION_TESTER_H_
7
Ben Chan22f1fbc2014-10-17 14:18:07 -07008#include <memory>
Rebecca Silbersteinf4365a62014-09-16 11:40:32 -07009#include <string>
10#include <vector>
11
12#include <base/callback.h>
13#include <base/cancelable_callback.h>
14#include <base/memory/ref_counted.h>
Rebecca Silbersteinf4365a62014-09-16 11:40:32 -070015#include <base/memory/weak_ptr.h>
16#include <gtest/gtest_prod.h> // for FRIEND_TEST
17
18#include "shill/connectivity_trial.h"
19#include "shill/refptr_types.h"
20
21namespace shill {
22
23// The ConnectionTester class implements a single trial connectivity test
24// to evaluate a connection in shill. This will evaluate if a connection has
25// "general internet connectivity."
26//
27// This test will be triggered through a D-Bus call on demand by a user to
28// capture state of an existing connection and create detailed logging
29// information to be used for debugging connectivity issues.
30//
31// This functionality will be implemented by testing the connection with a
32// single ConnectivityTrial attempt.
33class ConnectionTester {
34 public:
35 ConnectionTester(ConnectionRefPtr connection,
Paul Stewarta794cd62015-06-16 13:13:10 -070036 EventDispatcher* dispatcher,
37 const base::Closure& callback);
Rebecca Silbersteinf4365a62014-09-16 11:40:32 -070038 virtual ~ConnectionTester();
39
40 // Start a connectivity test. The Start method creates a ConnectivityTrial
41 // instance and performs a single ConnectivityTrial. The results are logged
42 // and when the trial completes, the supplied callback is notified.
43 virtual void Start();
44
45 // End the current ConnectivityTester by calling Stop on underlying
46 // ConnectivityTrial. The callback will not be called.
47 virtual void Stop();
48
49 private:
50 friend class ConnectionTesterTest;
51 FRIEND_TEST(ConnectionTesterTest, CompleteTest);
52
53 // Time to wait for the attempt to complete.
54 static const int kTrialTimeoutSeconds;
55 // Callback used by ConnectivityTrial to report results.
56 void CompleteTest(ConnectivityTrial::Result result);
57
58 ConnectionRefPtr connection_;
Paul Stewarta794cd62015-06-16 13:13:10 -070059 EventDispatcher* dispatcher_;
Rebecca Silbersteinf4365a62014-09-16 11:40:32 -070060 base::WeakPtrFactory<ConnectionTester> weak_ptr_factory_;
61 base::Callback<void()> tester_callback_;
Ben Chan22f1fbc2014-10-17 14:18:07 -070062 std::unique_ptr<ConnectivityTrial> connectivity_trial_;
Rebecca Silbersteinf4365a62014-09-16 11:40:32 -070063
64 DISALLOW_COPY_AND_ASSIGN(ConnectionTester);
65};
66
67} // namespace shill
68
69#endif // SHILL_CONNECTION_TESTER_H_