| 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(), true); |
| 109 NetworkPortalDetector::InitializeForTesting(network_portal_detector_); | 110 NetworkPortalDetector::InitializeForTesting(network_portal_detector_); |
| 110 network_portal_detector_->Enable(false /* start_detection */); | 111 network_portal_detector_->Enable(false /* start_detection */); |
| 111 set_detector(network_portal_detector_->captive_portal_detector_.get()); | 112 set_detector(network_portal_detector_->captive_portal_detector_.get()); |
| 112 } | 113 } |
| 113 | 114 |
| 114 void LoadTestExtension() { | 115 void LoadTestExtension() { |
| 115 extension_ = LoadExtension(test_data_dir_.AppendASCII("networking_config")); | 116 extension_ = LoadExtension(test_data_dir_.AppendASCII("networking_config")); |
| 116 } | 117 } |
| 117 | 118 |
| 118 bool RunExtensionTest(const std::string& path) { | 119 bool RunExtensionTest(const std::string& path) { |
| 119 return RunExtensionSubtest("networking_config", | 120 return RunExtensionSubtest("networking_config", |
| 120 extension_->GetResourceURL(path).spec()); | 121 extension_->GetResourceURL(path).spec()); |
| 121 } | 122 } |
| 122 | 123 |
| 123 void SimulateCaptivePortal() { | 124 void SimulateCaptivePortal() { |
| 124 network_portal_detector_->StartDetection(); | 125 network_portal_detector_->StartDetection(); |
| 125 content::RunAllPendingInMessageLoop(); | 126 content::RunAllPendingInMessageLoop(); |
| 126 | 127 |
| 127 // Simulate a captive portal reply. | 128 // Simulate a captive portal reply. |
| 128 CompleteURLFetch(net::OK, 200, nullptr); | 129 CompleteURLFetch(net::OK, 200, nullptr); |
| 129 } | 130 } |
| 130 | 131 |
| 131 void SimulateSuccessfulCaptivePortalAuth() { | 132 void SimulateSuccessfulCaptivePortalAuth() { |
| 132 content::RunAllPendingInMessageLoop(); | 133 content::RunAllPendingInMessageLoop(); |
| 133 CompleteURLFetch(net::OK, 204, nullptr); | 134 CompleteURLFetch(net::OK, 204, nullptr); |
| 134 } | 135 } |
| 135 | 136 |
| 137 NetworkPortalDetector::CaptivePortalStatus GetCaptivePortalStatus( |
| 138 const std::string& guid) { |
| 139 return network_portal_detector_->GetCaptivePortalState(kWifi1ServiceGUID) |
| 140 .status; |
| 141 } |
| 142 |
| 136 NetworkPortalDetectorImpl* network_portal_detector_ = nullptr; | 143 NetworkPortalDetectorImpl* network_portal_detector_ = nullptr; |
| 137 | 144 |
| 138 private: | 145 private: |
| 139 const extensions::Extension* extension_ = nullptr; | 146 const extensions::Extension* extension_ = nullptr; |
| 140 }; | 147 }; |
| 141 | 148 |
| 142 IN_PROC_BROWSER_TEST_F(NetworkingConfigTest, ApiAvailability) { | 149 IN_PROC_BROWSER_TEST_F(NetworkingConfigTest, ApiAvailability) { |
| 143 ASSERT_TRUE(RunExtensionSubtest("networking_config", "api_availability.html")) | 150 ASSERT_TRUE(RunExtensionSubtest("networking_config", "api_availability.html")) |
| 144 << message_; | 151 << message_; |
| 145 } | 152 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 171 MessageCenter::Get()->ClickOnNotificationButton( | 178 MessageCenter::Get()->ClickOnNotificationButton( |
| 172 NetworkPortalNotificationController::kNotificationId, | 179 NetworkPortalNotificationController::kNotificationId, |
| 173 NetworkPortalNotificationController::kUseExtensionButtonIndex); | 180 NetworkPortalNotificationController::kUseExtensionButtonIndex); |
| 174 | 181 |
| 175 extensions::ResultCatcher catcher; | 182 extensions::ResultCatcher catcher; |
| 176 EXPECT_TRUE(catcher.GetNextResult()); | 183 EXPECT_TRUE(catcher.GetNextResult()); |
| 177 | 184 |
| 178 // Simulate the captive portal vanishing. | 185 // Simulate the captive portal vanishing. |
| 179 SimulateSuccessfulCaptivePortalAuth(); | 186 SimulateSuccessfulCaptivePortalAuth(); |
| 180 | 187 |
| 181 NetworkPortalDetector::CaptivePortalState state = | 188 ASSERT_EQ(NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE, |
| 182 network_portal_detector_->GetCaptivePortalState(kWifi1ServiceGUID); | 189 GetCaptivePortalStatus(kWifi1ServiceGUID)); |
| 183 ASSERT_EQ(NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE, state.status); | |
| 184 } | 190 } |
| OLD | NEW |