- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / captive_portal / testing_utils.h
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_CAPTIVE_PORTAL_TESTING_UTILS_H_
6 #define CHROME_BROWSER_CAPTIVE_PORTAL_TESTING_UTILS_H_
7
8 #include <string>
9
10 #include "base/basictypes.h"
11 #include "chrome/browser/captive_portal/captive_portal_detector.h"
12 #include "net/url_request/test_url_fetcher_factory.h"
13
14 namespace base {
15 class Time;
16 }
17
18 namespace net {
19 class URLFetcher;
20 }
21
22 namespace captive_portal {
23
24 class CaptivePortalDetectorTestBase {
25  public:
26   CaptivePortalDetectorTestBase();
27   virtual ~CaptivePortalDetectorTestBase();
28
29   // Sets test time for captive portal detector.
30   void SetTime(const base::Time& time);
31
32   // Advances test time for captive portal detector.
33   void AdvanceTime(const base::TimeDelta& time_delta);
34
35   bool FetchingURL();
36
37   // Sets URL fetcher state and notifies portal detector.
38   void CompleteURLFetch(int net_error,
39                         int status_code,
40                         const char* response_headers);
41
42   void set_detector(CaptivePortalDetector* detector) { detector_ = detector; }
43
44   CaptivePortalDetector* detector() { return detector_; }
45
46   net::TestURLFetcher* fetcher() { return factory_.GetFetcherByID(0); }
47
48  protected:
49   CaptivePortalDetector* detector_;
50
51   net::TestURLFetcherFactory factory_;
52
53   DISALLOW_COPY_AND_ASSIGN(CaptivePortalDetectorTestBase);
54 };
55
56 }  // namespace captive_portal
57
58 #endif  // CHROME_BROWSER_CAPTIVE_PORTAL_TESTING_UTILS_H_