• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 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 #include "chrome/browser/chromeos/net/network_portal_detector_test_impl.h"
6 
7 #include "chromeos/network/network_state.h"
8 
9 namespace chromeos {
10 
NetworkPortalDetectorTestImpl()11 NetworkPortalDetectorTestImpl::NetworkPortalDetectorTestImpl()
12     : strategy_id_(PortalDetectorStrategy::STRATEGY_ID_LOGIN_SCREEN) {
13 }
14 
~NetworkPortalDetectorTestImpl()15 NetworkPortalDetectorTestImpl::~NetworkPortalDetectorTestImpl() {
16 }
17 
SetDefaultNetworkPathForTesting(const std::string & service_path,const std::string & guid)18 void NetworkPortalDetectorTestImpl::SetDefaultNetworkPathForTesting(
19     const std::string& service_path,
20     const std::string& guid) {
21   DVLOG(1) << "SetDefaultNetworkPathForTesting:"
22            << " service path: " << service_path
23            << " guid: " << guid;
24   if (service_path.empty()) {
25     default_network_.reset();
26   } else {
27     default_network_.reset(new NetworkState(service_path));
28     default_network_->SetGuid(guid);
29   }
30 }
31 
SetDetectionResultsForTesting(const std::string & service_path,const CaptivePortalState & state)32 void NetworkPortalDetectorTestImpl::SetDetectionResultsForTesting(
33     const std::string& service_path,
34     const CaptivePortalState& state) {
35   DVLOG(1) << "SetDetectionResultsForTesting: " << service_path << " = "
36            << NetworkPortalDetector::CaptivePortalStatusString(state.status);
37   if (!service_path.empty())
38     portal_state_map_[service_path] = state;
39 }
40 
NotifyObserversForTesting()41 void NetworkPortalDetectorTestImpl::NotifyObserversForTesting() {
42   CaptivePortalState state;
43   if (default_network_ &&
44       portal_state_map_.count(default_network_->path())) {
45     state = portal_state_map_[default_network_->path()];
46   }
47   FOR_EACH_OBSERVER(Observer, observers_,
48                     OnPortalDetectionCompleted(default_network_.get(), state));
49 }
50 
AddObserver(Observer * observer)51 void NetworkPortalDetectorTestImpl::AddObserver(Observer* observer) {
52   if (observer && !observers_.HasObserver(observer))
53     observers_.AddObserver(observer);
54 }
55 
AddAndFireObserver(Observer * observer)56 void NetworkPortalDetectorTestImpl::AddAndFireObserver(Observer* observer) {
57   AddObserver(observer);
58   if (!observer)
59     return;
60   if (!default_network_ ||
61       !portal_state_map_.count(default_network_->path())) {
62     observer->OnPortalDetectionCompleted(default_network_.get(),
63                                          CaptivePortalState());
64   } else {
65     observer->OnPortalDetectionCompleted(
66         default_network_.get(),
67         portal_state_map_[default_network_->path()]);
68   }
69 }
70 
RemoveObserver(Observer * observer)71 void NetworkPortalDetectorTestImpl::RemoveObserver(Observer* observer) {
72   if (observer)
73     observers_.RemoveObserver(observer);
74 }
75 
76 NetworkPortalDetector::CaptivePortalState
GetCaptivePortalState(const std::string & service_path)77 NetworkPortalDetectorTestImpl::GetCaptivePortalState(
78     const std::string& service_path) {
79   CaptivePortalStateMap::iterator it = portal_state_map_.find(service_path);
80   if (it == portal_state_map_.end()) {
81     DVLOG(2) << "GetCaptivePortalState Not found: " << service_path;
82     return CaptivePortalState();
83   }
84   DVLOG(2) << "GetCaptivePortalState: " << service_path << " = "
85            << CaptivePortalStatusString(it->second.status);
86   return it->second;
87 }
88 
IsEnabled()89 bool NetworkPortalDetectorTestImpl::IsEnabled() {
90   return true;
91 }
92 
Enable(bool start_detection)93 void NetworkPortalDetectorTestImpl::Enable(bool start_detection) {
94 }
95 
StartDetectionIfIdle()96 bool NetworkPortalDetectorTestImpl::StartDetectionIfIdle() {
97   return false;
98 }
99 
SetStrategy(PortalDetectorStrategy::StrategyId id)100 void NetworkPortalDetectorTestImpl::SetStrategy(
101     PortalDetectorStrategy::StrategyId id) {
102   strategy_id_ = id;
103 }
104 
105 }  // namespace chromeos
106