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 11 NetworkPortalDetectorTestImpl::NetworkPortalDetectorTestImpl() {} 12 13 NetworkPortalDetectorTestImpl::~NetworkPortalDetectorTestImpl() { 14 } 15 16 void NetworkPortalDetectorTestImpl::SetDefaultNetworkPathForTesting( 17 const std::string& service_path) { 18 if (service_path.empty()) 19 default_network_.reset(); 20 else 21 default_network_.reset(new NetworkState(service_path)); 22 } 23 24 void NetworkPortalDetectorTestImpl::SetDetectionResultsForTesting( 25 const std::string& service_path, 26 const CaptivePortalState& state) { 27 if (!service_path.empty()) 28 portal_state_map_[service_path] = state; 29 } 30 31 void NetworkPortalDetectorTestImpl::NotifyObserversForTesting() { 32 CaptivePortalState state; 33 if (default_network_ && 34 portal_state_map_.count(default_network_->path())) { 35 state = portal_state_map_[default_network_->path()]; 36 } 37 FOR_EACH_OBSERVER(Observer, observers_, 38 OnPortalDetectionCompleted(default_network_.get(), state)); 39 } 40 41 void NetworkPortalDetectorTestImpl::AddObserver(Observer* observer) { 42 if (observer && !observers_.HasObserver(observer)) 43 observers_.AddObserver(observer); 44 } 45 46 void NetworkPortalDetectorTestImpl::AddAndFireObserver(Observer* observer) { 47 AddObserver(observer); 48 if (!observer) 49 return; 50 if (!default_network_ || 51 !portal_state_map_.count(default_network_->path())) { 52 observer->OnPortalDetectionCompleted(default_network_.get(), 53 CaptivePortalState()); 54 } else { 55 observer->OnPortalDetectionCompleted( 56 default_network_.get(), 57 portal_state_map_[default_network_->path()]); 58 } 59 } 60 61 void NetworkPortalDetectorTestImpl::RemoveObserver(Observer* observer) { 62 if (observer) 63 observers_.RemoveObserver(observer); 64 } 65 66 NetworkPortalDetector::CaptivePortalState 67 NetworkPortalDetectorTestImpl::GetCaptivePortalState( 68 const chromeos::NetworkState* network) { 69 if (!network || !portal_state_map_.count(network->path())) 70 return CaptivePortalState(); 71 return portal_state_map_[network->path()]; 72 } 73 74 bool NetworkPortalDetectorTestImpl::IsEnabled() { 75 return true; 76 } 77 78 void NetworkPortalDetectorTestImpl::Enable(bool start_detection) { 79 } 80 81 bool NetworkPortalDetectorTestImpl::StartDetectionIfIdle() { 82 return false; 83 } 84 85 void NetworkPortalDetectorTestImpl::EnableLazyDetection() { 86 } 87 88 void NetworkPortalDetectorTestImpl::DisableLazyDetection() { 89 } 90 91 } // namespace chromeos 92