OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #include <string> | 5 #include <string> |
6 | 6 |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/chromeos/net/network_portal_detector_impl.h" | 10 #include "chrome/browser/chromeos/net/network_portal_detector_impl.h" |
| 11 #include "chrome/browser/chromeos/net/network_portal_notification_controller.h" |
11 #include "chrome/browser/extensions/extension_apitest.h" | 12 #include "chrome/browser/extensions/extension_apitest.h" |
12 #include "chromeos/dbus/dbus_thread_manager.h" | 13 #include "chromeos/dbus/dbus_thread_manager.h" |
13 #include "chromeos/dbus/shill_device_client.h" | 14 #include "chromeos/dbus/shill_device_client.h" |
14 #include "chromeos/dbus/shill_profile_client.h" | 15 #include "chromeos/dbus/shill_profile_client.h" |
15 #include "chromeos/dbus/shill_service_client.h" | 16 #include "chromeos/dbus/shill_service_client.h" |
16 #include "components/captive_portal/captive_portal_testing_utils.h" | 17 #include "components/captive_portal/captive_portal_testing_utils.h" |
17 #include "content/public/test/test_utils.h" | 18 #include "content/public/test/test_utils.h" |
18 #include "extensions/test/result_catcher.h" | 19 #include "extensions/test/result_catcher.h" |
19 #include "net/base/net_errors.h" | 20 #include "net/base/net_errors.h" |
20 #include "third_party/cros_system_api/dbus/service_constants.h" | 21 #include "third_party/cros_system_api/dbus/service_constants.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 base::StringValue("01:02:ab:7f:90:00")); | 99 base::StringValue("01:02:ab:7f:90:00")); |
99 service_test->SetServiceProperty(kWifi1ServicePath, | 100 service_test->SetServiceProperty(kWifi1ServicePath, |
100 shill::kSignalStrengthProperty, | 101 shill::kSignalStrengthProperty, |
101 base::FundamentalValue(40)); | 102 base::FundamentalValue(40)); |
102 profile_test->AddService(ShillProfileClient::GetSharedProfilePath(), | 103 profile_test->AddService(ShillProfileClient::GetSharedProfilePath(), |
103 kWifi1ServicePath); | 104 kWifi1ServicePath); |
104 | 105 |
105 content::RunAllPendingInMessageLoop(); | 106 content::RunAllPendingInMessageLoop(); |
106 | 107 |
107 network_portal_detector_ = new NetworkPortalDetectorImpl( | 108 network_portal_detector_ = new NetworkPortalDetectorImpl( |
108 g_browser_process->system_request_context()); | 109 g_browser_process->system_request_context(), |
| 110 true /* create_notification_controller */); |
109 NetworkPortalDetector::InitializeForTesting(network_portal_detector_); | 111 NetworkPortalDetector::InitializeForTesting(network_portal_detector_); |
110 network_portal_detector_->Enable(false /* start_detection */); | 112 network_portal_detector_->Enable(false /* start_detection */); |
111 set_detector(network_portal_detector_->captive_portal_detector_.get()); | 113 set_detector(network_portal_detector_->captive_portal_detector_.get()); |
112 } | 114 } |
113 | 115 |
114 void LoadTestExtension() { | 116 void LoadTestExtension() { |
115 extension_ = LoadExtension(test_data_dir_.AppendASCII("networking_config")); | 117 extension_ = LoadExtension(test_data_dir_.AppendASCII("networking_config")); |
116 } | 118 } |
117 | 119 |
118 bool RunExtensionTest(const std::string& path) { | 120 bool RunExtensionTest(const std::string& path) { |
119 return RunExtensionSubtest("networking_config", | 121 return RunExtensionSubtest("networking_config", |
120 extension_->GetResourceURL(path).spec()); | 122 extension_->GetResourceURL(path).spec()); |
121 } | 123 } |
122 | 124 |
123 void SimulateCaptivePortal() { | 125 void SimulateCaptivePortal() { |
124 network_portal_detector_->StartDetection(); | 126 network_portal_detector_->StartDetection(); |
125 content::RunAllPendingInMessageLoop(); | 127 content::RunAllPendingInMessageLoop(); |
126 | 128 |
127 // Simulate a captive portal reply. | 129 // Simulate a captive portal reply. |
128 CompleteURLFetch(net::OK, 200, nullptr); | 130 CompleteURLFetch(net::OK, 200, nullptr); |
129 } | 131 } |
130 | 132 |
131 void SimulateSuccessfulCaptivePortalAuth() { | 133 void SimulateSuccessfulCaptivePortalAuth() { |
132 content::RunAllPendingInMessageLoop(); | 134 content::RunAllPendingInMessageLoop(); |
133 CompleteURLFetch(net::OK, 204, nullptr); | 135 CompleteURLFetch(net::OK, 204, nullptr); |
134 } | 136 } |
135 | 137 |
| 138 NetworkPortalDetector::CaptivePortalStatus GetCaptivePortalStatus( |
| 139 const std::string& guid) { |
| 140 return network_portal_detector_->GetCaptivePortalState(kWifi1ServiceGUID) |
| 141 .status; |
| 142 } |
| 143 |
136 NetworkPortalDetectorImpl* network_portal_detector_ = nullptr; | 144 NetworkPortalDetectorImpl* network_portal_detector_ = nullptr; |
137 | 145 |
138 private: | 146 private: |
139 const extensions::Extension* extension_ = nullptr; | 147 const extensions::Extension* extension_ = nullptr; |
140 }; | 148 }; |
141 | 149 |
142 IN_PROC_BROWSER_TEST_F(NetworkingConfigTest, ApiAvailability) { | 150 IN_PROC_BROWSER_TEST_F(NetworkingConfigTest, ApiAvailability) { |
143 ASSERT_TRUE(RunExtensionSubtest("networking_config", "api_availability.html")) | 151 ASSERT_TRUE(RunExtensionSubtest("networking_config", "api_availability.html")) |
144 << message_; | 152 << message_; |
145 } | 153 } |
(...skipping 25 matching lines...) Expand all Loading... |
171 MessageCenter::Get()->ClickOnNotificationButton( | 179 MessageCenter::Get()->ClickOnNotificationButton( |
172 NetworkPortalNotificationController::kNotificationId, | 180 NetworkPortalNotificationController::kNotificationId, |
173 NetworkPortalNotificationController::kUseExtensionButtonIndex); | 181 NetworkPortalNotificationController::kUseExtensionButtonIndex); |
174 | 182 |
175 extensions::ResultCatcher catcher; | 183 extensions::ResultCatcher catcher; |
176 EXPECT_TRUE(catcher.GetNextResult()); | 184 EXPECT_TRUE(catcher.GetNextResult()); |
177 | 185 |
178 // Simulate the captive portal vanishing. | 186 // Simulate the captive portal vanishing. |
179 SimulateSuccessfulCaptivePortalAuth(); | 187 SimulateSuccessfulCaptivePortalAuth(); |
180 | 188 |
181 NetworkPortalDetector::CaptivePortalState state = | 189 ASSERT_EQ(NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE, |
182 network_portal_detector_->GetCaptivePortalState(kWifi1ServiceGUID); | 190 GetCaptivePortalStatus(kWifi1ServiceGUID)); |
183 ASSERT_EQ(NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE, state.status); | |
184 } | 191 } |
OLD | NEW |