Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(166)

Side by Side Diff: chrome/browser/chromeos/login/screens/update_screen_browsertest.cc

Issue 14134007: NetworkPortalDetector/NetworkStateInformer: Switch over to use NetworkStateHandler (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "chrome/browser/chromeos/cros/mock_network_library.h" 7 #include "chrome/browser/chromeos/cros/mock_network_library.h"
8 #include "chrome/browser/chromeos/login/screens/mock_error_screen.h" 8 #include "chrome/browser/chromeos/login/screens/mock_error_screen.h"
9 #include "chrome/browser/chromeos/login/screens/mock_screen_observer.h" 9 #include "chrome/browser/chromeos/login/screens/mock_screen_observer.h"
10 #include "chrome/browser/chromeos/login/screens/update_screen.h" 10 #include "chrome/browser/chromeos/login/screens/update_screen.h"
(...skipping 10 matching lines...) Expand all
21 using ::testing::_; 21 using ::testing::_;
22 using ::testing::AnyNumber; 22 using ::testing::AnyNumber;
23 using ::testing::AtLeast; 23 using ::testing::AtLeast;
24 using ::testing::Invoke; 24 using ::testing::Invoke;
25 using ::testing::Return; 25 using ::testing::Return;
26 26
27 namespace chromeos { 27 namespace chromeos {
28 28
29 namespace { 29 namespace {
30 30
31 const char kDefaultEthernetServicePath[] = "eth0"; 31 const char kStubEthernetServicePath[] = "eth0";
32 const char kDefaultWifiServicePath[] = "wlan0"; 32 const char kStubWifiServicePath[] = "wlan0";
33 33
34 } // namespace 34 } // namespace
35 35
36 class UpdateScreenTest : public WizardInProcessBrowserTest { 36 class UpdateScreenTest : public WizardInProcessBrowserTest {
37 public: 37 public:
38 UpdateScreenTest() : WizardInProcessBrowserTest("update"), 38 UpdateScreenTest() : WizardInProcessBrowserTest("update"),
39 fake_update_engine_client_(NULL), 39 fake_update_engine_client_(NULL),
40 mock_network_library_(NULL), 40 mock_network_library_(NULL),
41 network_portal_detector_stub_(NULL) { 41 network_portal_detector_stub_(NULL) {
42 } 42 }
43 43
44 protected: 44 protected:
45 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { 45 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
46 MockDBusThreadManagerWithoutGMock* mock_dbus_thread_manager = 46 MockDBusThreadManagerWithoutGMock* mock_dbus_thread_manager =
47 new MockDBusThreadManagerWithoutGMock; 47 new MockDBusThreadManagerWithoutGMock;
48 DBusThreadManager::InitializeForTesting(mock_dbus_thread_manager); 48 DBusThreadManager::InitializeForTesting(mock_dbus_thread_manager);
49 WizardInProcessBrowserTest::SetUpInProcessBrowserTestFixture(); 49 WizardInProcessBrowserTest::SetUpInProcessBrowserTestFixture();
50 cros_mock_->InitStatusAreaMocks(); 50 cros_mock_->InitStatusAreaMocks();
51 cros_mock_->SetStatusAreaMocksExpectations(); 51 cros_mock_->SetStatusAreaMocksExpectations();
52 52
53 fake_update_engine_client_ 53 fake_update_engine_client_
54 = mock_dbus_thread_manager->fake_update_engine_client(); 54 = mock_dbus_thread_manager->fake_update_engine_client();
55 55
56 mock_network_library_ = cros_mock_->mock_network_library(); 56 mock_network_library_ = cros_mock_->mock_network_library();
57 stub_ethernet_.reset(new EthernetNetwork(kDefaultEthernetServicePath));
58 stub_wifi_.reset(new WifiNetwork(kDefaultWifiServicePath));
59 EXPECT_CALL(*mock_network_library_, SetDefaultCheckPortalList()) 57 EXPECT_CALL(*mock_network_library_, SetDefaultCheckPortalList())
60 .Times(1); 58 .Times(1);
61 EXPECT_CALL(*mock_network_library_, AddNetworkManagerObserver(_))
62 .Times(1)
63 .RetiresOnSaturation();
64 EXPECT_CALL(*mock_network_library_, AddUserActionObserver(_))
65 .Times(AnyNumber());
66 EXPECT_CALL(*mock_network_library_, FindWifiDevice())
67 .Times(AnyNumber());
68 EXPECT_CALL(*mock_network_library_, FindEthernetDevice())
69 .Times(AnyNumber());
70 EXPECT_CALL(*mock_network_library_, LoadOncNetworks(_, _)) 59 EXPECT_CALL(*mock_network_library_, LoadOncNetworks(_, _))
71 .Times(AnyNumber()); 60 .Times(AnyNumber());
72 EXPECT_CALL(*mock_network_library_,
73 FindNetworkByPath(kDefaultEthernetServicePath))
74 .Times(AnyNumber())
75 .WillRepeatedly((Return(stub_ethernet_.get())));
76 EXPECT_CALL(*mock_network_library_,
77 FindNetworkByPath(kDefaultWifiServicePath))
78 .Times(AnyNumber())
79 .WillRepeatedly((Return(stub_wifi_.get())));
80 61
81 // Setup network portal detector to return online state for both 62 // Setup network portal detector to return online state for both
82 // ethernet and wifi networks. Ethernet is an active network by 63 // ethernet and wifi networks. Ethernet is an active network by
83 // default. 64 // default.
84 network_portal_detector_stub_ = 65 network_portal_detector_stub_ =
85 static_cast<NetworkPortalDetectorStub*>( 66 static_cast<NetworkPortalDetectorStub*>(
86 NetworkPortalDetector::GetInstance()); 67 NetworkPortalDetector::GetInstance());
87 NetworkPortalDetector::CaptivePortalState online_state; 68 NetworkPortalDetector::CaptivePortalState online_state;
88 online_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE; 69 online_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE;
89 online_state.response_code = 204; 70 online_state.response_code = 204;
90 SetActiveNetwork(stub_ethernet_.get()); 71 SetDefaultNetworkPath(kStubEthernetServicePath);
91 SetDetectionResults(stub_ethernet_.get(), online_state); 72 SetDetectionResults(kStubEthernetServicePath, online_state);
92 SetDetectionResults(stub_wifi_.get(), online_state); 73 SetDetectionResults(kStubWifiServicePath, online_state);
93 } 74 }
94 75
95 virtual void SetUpOnMainThread() OVERRIDE { 76 virtual void SetUpOnMainThread() OVERRIDE {
96 WizardInProcessBrowserTest::SetUpOnMainThread(); 77 WizardInProcessBrowserTest::SetUpOnMainThread();
97 78
98 mock_screen_observer_.reset(new MockScreenObserver()); 79 mock_screen_observer_.reset(new MockScreenObserver());
99 mock_error_screen_actor_.reset(new MockErrorScreenActor()); 80 mock_error_screen_actor_.reset(new MockErrorScreenActor());
100 mock_error_screen_.reset( 81 mock_error_screen_.reset(
101 new MockErrorScreen(mock_screen_observer_.get(), 82 new MockErrorScreen(mock_screen_observer_.get(),
102 mock_error_screen_actor_.get())); 83 mock_error_screen_actor_.get()));
103 EXPECT_CALL(*mock_screen_observer_, ShowCurrentScreen()) 84 EXPECT_CALL(*mock_screen_observer_, ShowCurrentScreen())
104 .Times(AnyNumber()); 85 .Times(AnyNumber());
105 EXPECT_CALL(*mock_screen_observer_, GetErrorScreen()) 86 EXPECT_CALL(*mock_screen_observer_, GetErrorScreen())
106 .Times(AnyNumber()) 87 .Times(AnyNumber())
107 .WillRepeatedly(Return(mock_error_screen_.get())); 88 .WillRepeatedly(Return(mock_error_screen_.get()));
108 89
109 ASSERT_TRUE(WizardController::default_controller() != NULL); 90 ASSERT_TRUE(WizardController::default_controller() != NULL);
110 update_screen_ = WizardController::default_controller()->GetUpdateScreen(); 91 update_screen_ = WizardController::default_controller()->GetUpdateScreen();
111 ASSERT_TRUE(update_screen_ != NULL); 92 ASSERT_TRUE(update_screen_ != NULL);
112 ASSERT_EQ(WizardController::default_controller()->current_screen(), 93 ASSERT_EQ(WizardController::default_controller()->current_screen(),
113 update_screen_); 94 update_screen_);
114 update_screen_->screen_observer_ = mock_screen_observer_.get(); 95 update_screen_->screen_observer_ = mock_screen_observer_.get();
115 } 96 }
116 97
117 virtual void TearDownInProcessBrowserTestFixture() OVERRIDE { 98 virtual void TearDownInProcessBrowserTestFixture() OVERRIDE {
118 WizardInProcessBrowserTest::TearDownInProcessBrowserTestFixture(); 99 WizardInProcessBrowserTest::TearDownInProcessBrowserTestFixture();
119 DBusThreadManager::Shutdown(); 100 DBusThreadManager::Shutdown();
120 } 101 }
121 102
122 void SetActiveNetwork(const Network* network) { 103 void SetDefaultNetworkPath(const std::string& service_path) {
123 DCHECK(network_portal_detector_stub_); 104 DCHECK(network_portal_detector_stub_);
124 network_portal_detector_stub_->SetActiveNetworkForTesting(network); 105 network_portal_detector_stub_->SetDefaultNetworkPathForTesting(
106 service_path);
125 } 107 }
126 108
127 void SetDetectionResults( 109 void SetDetectionResults(
128 const Network* network, 110 const std::string& service_path,
129 const NetworkPortalDetector::CaptivePortalState& state) { 111 const NetworkPortalDetector::CaptivePortalState& state) {
130 DCHECK(network_portal_detector_stub_); 112 DCHECK(network_portal_detector_stub_);
131 network_portal_detector_stub_->SetDetectionResultsForTesting(network, 113 network_portal_detector_stub_->SetDetectionResultsForTesting(service_path,
132 state); 114 state);
133 } 115 }
134 116
135 void NotifyPortalDetectionCompleted() { 117 void NotifyPortalDetectionCompleted() {
136 DCHECK(network_portal_detector_stub_); 118 DCHECK(network_portal_detector_stub_);
137 network_portal_detector_stub_->NotifyObserversForTesting(); 119 network_portal_detector_stub_->NotifyObserversForTesting();
138 } 120 }
139 121
140 FakeUpdateEngineClient* fake_update_engine_client_; 122 FakeUpdateEngineClient* fake_update_engine_client_;
141 MockNetworkLibrary* mock_network_library_; 123 MockNetworkLibrary* mock_network_library_;
142 scoped_ptr<Network> stub_ethernet_;
143 scoped_ptr<Network> stub_wifi_;
144 scoped_ptr<MockScreenObserver> mock_screen_observer_; 124 scoped_ptr<MockScreenObserver> mock_screen_observer_;
145 scoped_ptr<MockErrorScreenActor> mock_error_screen_actor_; 125 scoped_ptr<MockErrorScreenActor> mock_error_screen_actor_;
146 scoped_ptr<MockErrorScreen> mock_error_screen_; 126 scoped_ptr<MockErrorScreen> mock_error_screen_;
147 UpdateScreen* update_screen_; 127 UpdateScreen* update_screen_;
148 NetworkPortalDetectorStub* network_portal_detector_stub_; 128 NetworkPortalDetectorStub* network_portal_detector_stub_;
149 129
150 private: 130 private:
151 DISALLOW_COPY_AND_ASSIGN(UpdateScreenTest); 131 DISALLOW_COPY_AND_ASSIGN(UpdateScreenTest);
152 }; 132 };
153 133
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 IN_PROC_BROWSER_TEST_F(UpdateScreenTest, TestTemproraryOfflineNetwork) { 234 IN_PROC_BROWSER_TEST_F(UpdateScreenTest, TestTemproraryOfflineNetwork) {
255 EXPECT_CALL(*mock_screen_observer_, 235 EXPECT_CALL(*mock_screen_observer_,
256 OnExit(ScreenObserver::UPDATE_NOUPDATE)) 236 OnExit(ScreenObserver::UPDATE_NOUPDATE))
257 .Times(1); 237 .Times(1);
258 update_screen_->CancelUpdate(); 238 update_screen_->CancelUpdate();
259 239
260 // Change ethernet state to portal. 240 // Change ethernet state to portal.
261 NetworkPortalDetector::CaptivePortalState portal_state; 241 NetworkPortalDetector::CaptivePortalState portal_state;
262 portal_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL; 242 portal_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL;
263 portal_state.response_code = 200; 243 portal_state.response_code = 200;
264 SetDetectionResults(stub_ethernet_.get(), portal_state); 244 SetDetectionResults(kStubEthernetServicePath, portal_state);
265 245
266 // Update screen will show error message about portal state because 246 // Update screen will show error message about portal state because
267 // ethernet is behind captive portal. 247 // ethernet is behind captive portal.
268 EXPECT_CALL(*mock_error_screen_actor_, 248 EXPECT_CALL(*mock_error_screen_actor_,
269 SetUIState(ErrorScreen::UI_STATE_UPDATE)) 249 SetUIState(ErrorScreen::UI_STATE_UPDATE))
270 .Times(1); 250 .Times(1);
271 EXPECT_CALL(*mock_error_screen_actor_, 251 EXPECT_CALL(*mock_error_screen_actor_,
272 SetErrorState(ErrorScreen::ERROR_STATE_PORTAL, std::string())) 252 SetErrorState(ErrorScreen::ERROR_STATE_PORTAL, std::string()))
273 .Times(1); 253 .Times(1);
274 EXPECT_CALL(*mock_error_screen_actor_, FixCaptivePortal()) 254 EXPECT_CALL(*mock_error_screen_actor_, FixCaptivePortal())
275 .Times(1); 255 .Times(1);
276 EXPECT_CALL(*mock_screen_observer_, ShowErrorScreen()) 256 EXPECT_CALL(*mock_screen_observer_, ShowErrorScreen())
277 .Times(1); 257 .Times(1);
278 258
279 update_screen_->StartNetworkCheck(); 259 update_screen_->StartNetworkCheck();
280 260
281 NetworkPortalDetector::CaptivePortalState online_state; 261 NetworkPortalDetector::CaptivePortalState online_state;
282 online_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE; 262 online_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE;
283 online_state.response_code = 204; 263 online_state.response_code = 204;
284 SetDetectionResults(stub_ethernet_.get(), online_state); 264 SetDetectionResults(kStubEthernetServicePath, online_state);
285 265
286 // Second notification from portal detector will be about online state, 266 // Second notification from portal detector will be about online state,
287 // so update screen will hide error message and proceed to update. 267 // so update screen will hide error message and proceed to update.
288 EXPECT_CALL(*mock_screen_observer_, HideErrorScreen(update_screen_)) 268 EXPECT_CALL(*mock_screen_observer_, HideErrorScreen(update_screen_))
289 .Times(1); 269 .Times(1);
290 fake_update_engine_client_->set_update_check_result( 270 fake_update_engine_client_->set_update_check_result(
291 chromeos::UpdateEngineClient::UPDATE_RESULT_FAILED); 271 chromeos::UpdateEngineClient::UPDATE_RESULT_FAILED);
292 272
293 EXPECT_CALL(*mock_screen_observer_, 273 EXPECT_CALL(*mock_screen_observer_,
294 OnExit(ScreenObserver::UPDATE_ERROR_CHECKING_FOR_UPDATE)) 274 OnExit(ScreenObserver::UPDATE_ERROR_CHECKING_FOR_UPDATE))
295 .Times(1); 275 .Times(1);
296 276
297 NotifyPortalDetectionCompleted(); 277 NotifyPortalDetectionCompleted();
298 } 278 }
299 279
300 IN_PROC_BROWSER_TEST_F(UpdateScreenTest, TestTwoOfflineNetworks) { 280 IN_PROC_BROWSER_TEST_F(UpdateScreenTest, TestTwoOfflineNetworks) {
301 EXPECT_CALL(*mock_screen_observer_, 281 EXPECT_CALL(*mock_screen_observer_,
302 OnExit(ScreenObserver::UPDATE_NOUPDATE)) 282 OnExit(ScreenObserver::UPDATE_NOUPDATE))
303 .Times(1); 283 .Times(1);
304 update_screen_->CancelUpdate(); 284 update_screen_->CancelUpdate();
305 285
306 // Change ethernet state to portal. 286 // Change ethernet state to portal.
307 NetworkPortalDetector::CaptivePortalState portal_state; 287 NetworkPortalDetector::CaptivePortalState portal_state;
308 portal_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL; 288 portal_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL;
309 portal_state.response_code = 200; 289 portal_state.response_code = 200;
310 SetDetectionResults(stub_ethernet_.get(), portal_state); 290 SetDetectionResults(kStubEthernetServicePath, portal_state);
311 291
312 // Update screen will show error message about portal state because 292 // Update screen will show error message about portal state because
313 // ethernet is behind captive portal. 293 // ethernet is behind captive portal.
314 EXPECT_CALL(*mock_error_screen_actor_, 294 EXPECT_CALL(*mock_error_screen_actor_,
315 SetUIState(ErrorScreen::UI_STATE_UPDATE)) 295 SetUIState(ErrorScreen::UI_STATE_UPDATE))
316 .Times(1); 296 .Times(1);
317 EXPECT_CALL(*mock_error_screen_actor_, 297 EXPECT_CALL(*mock_error_screen_actor_,
318 SetErrorState(ErrorScreen::ERROR_STATE_PORTAL, std::string())) 298 SetErrorState(ErrorScreen::ERROR_STATE_PORTAL, std::string()))
319 .Times(1); 299 .Times(1);
320 EXPECT_CALL(*mock_error_screen_actor_, FixCaptivePortal()) 300 EXPECT_CALL(*mock_error_screen_actor_, FixCaptivePortal())
321 .Times(1); 301 .Times(1);
322 EXPECT_CALL(*mock_screen_observer_, ShowErrorScreen()) 302 EXPECT_CALL(*mock_screen_observer_, ShowErrorScreen())
323 .Times(1); 303 .Times(1);
324 304
325 update_screen_->StartNetworkCheck(); 305 update_screen_->StartNetworkCheck();
326 306
327 // Change active network to the wifi behind proxy. 307 // Change active network to the wifi behind proxy.
328 NetworkPortalDetector::CaptivePortalState proxy_state; 308 NetworkPortalDetector::CaptivePortalState proxy_state;
329 proxy_state.status = 309 proxy_state.status =
330 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PROXY_AUTH_REQUIRED; 310 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PROXY_AUTH_REQUIRED;
331 proxy_state.response_code = -1; 311 proxy_state.response_code = -1;
332 SetActiveNetwork(stub_wifi_.get()); 312 SetDefaultNetworkPath(kStubWifiServicePath);
333 SetDetectionResults(stub_wifi_.get(), proxy_state); 313 SetDetectionResults(kStubWifiServicePath, proxy_state);
334 314
335 // Update screen will show message about proxy error because wifie 315 // Update screen will show message about proxy error because wifie
336 // network requires proxy authentication. 316 // network requires proxy authentication.
337 EXPECT_CALL(*mock_error_screen_actor_, 317 EXPECT_CALL(*mock_error_screen_actor_,
338 SetErrorState(ErrorScreen::ERROR_STATE_PROXY, std::string())) 318 SetErrorState(ErrorScreen::ERROR_STATE_PROXY, std::string()))
339 .Times(1); 319 .Times(1);
340 320
341 NotifyPortalDetectionCompleted(); 321 NotifyPortalDetectionCompleted();
342 } 322 }
343 323
344 } // namespace chromeos 324 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/screens/update_screen.cc ('k') | chrome/browser/chromeos/net/network_portal_detector.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698