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