OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_CAPTIVE_PORTAL_TESTING_UTILS_H_ | 5 #ifndef CHROME_BROWSER_CAPTIVE_PORTAL_TESTING_UTILS_H_ |
6 #define CHROME_BROWSER_CAPTIVE_PORTAL_TESTING_UTILS_H_ | 6 #define CHROME_BROWSER_CAPTIVE_PORTAL_TESTING_UTILS_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/memory/ref_counted.h" | 10 #include "base/basictypes.h" |
11 #include "chrome/browser/captive_portal/captive_portal_detector.h" | 11 #include "chrome/browser/captive_portal/captive_portal_detector.h" |
12 #include "net/http/http_response_headers.h" | 12 #include "net/url_request/test_url_fetcher_factory.h" |
13 | 13 |
14 namespace base { | 14 namespace base { |
15 class Time; | 15 class Time; |
16 } | 16 } |
17 | 17 |
18 namespace net { | 18 namespace net { |
19 class URLFetcher; | 19 class URLFetcher; |
20 } | 20 } |
21 | 21 |
22 namespace captive_portal { | 22 namespace captive_portal { |
23 | 23 |
24 scoped_refptr<net::HttpResponseHeaders> CreateResponseHeaders( | |
25 const std::string& response_headers); | |
26 | |
27 class CaptivePortalDetectorTestBase { | 24 class CaptivePortalDetectorTestBase { |
28 public: | 25 public: |
29 CaptivePortalDetectorTestBase(); | 26 CaptivePortalDetectorTestBase(); |
30 virtual ~CaptivePortalDetectorTestBase(); | 27 virtual ~CaptivePortalDetectorTestBase(); |
31 | 28 |
32 // Sets test time for captive portal detector. | 29 // Sets test time for captive portal detector. |
33 void SetTime(const base::Time& time); | 30 void SetTime(const base::Time& time); |
34 | 31 |
35 // Advances test time for captive portal detector. | 32 // Advances test time for captive portal detector. |
36 void AdvanceTime(const base::TimeDelta& time_delta); | 33 void AdvanceTime(const base::TimeDelta& time_delta); |
37 | 34 |
38 bool FetchingURL(); | 35 bool FetchingURL(); |
39 | 36 |
40 // Calls the corresponding CaptivePortalDetector function. | 37 // Sets URL fetcher state and notifies portal detector. |
41 void OnURLFetchComplete(net::URLFetcher* fetcher); | 38 void CompleteURLFetch(int net_error, |
| 39 int status_code, |
| 40 const char* response_headers); |
42 | 41 |
43 void set_detector(CaptivePortalDetector* detector) { detector_ = detector; } | 42 void set_detector(CaptivePortalDetector* detector) { detector_ = detector; } |
44 | 43 |
45 CaptivePortalDetector* detector() { return detector_; } | 44 CaptivePortalDetector* detector() { return detector_; } |
46 | 45 |
| 46 net::TestURLFetcher* fetcher() { return factory_.GetFetcherByID(0); } |
| 47 |
47 protected: | 48 protected: |
48 CaptivePortalDetector* detector_; | 49 CaptivePortalDetector* detector_; |
| 50 |
| 51 net::TestURLFetcherFactory factory_; |
| 52 |
| 53 DISALLOW_COPY_AND_ASSIGN(CaptivePortalDetectorTestBase); |
49 }; | 54 }; |
50 | 55 |
51 } // namespace captive_portal | 56 } // namespace captive_portal |
52 | 57 |
53 #endif // CHROME_BROWSER_CAPTIVE_PORTAL_TESTING_UTILS_H_ | 58 #endif // CHROME_BROWSER_CAPTIVE_PORTAL_TESTING_UTILS_H_ |
OLD | NEW |