1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/command_line.h"
#include "base/memory/scoped_ptr.h"
#include "base/prefs/pref_service.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/login/screens/mock_error_screen.h"
#include "chrome/browser/chromeos/login/screens/mock_screen_observer.h"
#include "chrome/browser/chromeos/login/screens/update_screen.h"
#include "chrome/browser/chromeos/login/startup_utils.h"
#include "chrome/browser/chromeos/login/test/wizard_in_process_browser_test.h"
#include "chrome/browser/chromeos/login/wizard_controller.h"
#include "chrome/browser/chromeos/net/network_portal_detector_test_impl.h"
#include "chrome/common/pref_names.h"
#include "chromeos/chromeos_switches.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/fake_update_engine_client.h"
#include "chromeos/network/portal_detector/network_portal_detector.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
using ::testing::AnyNumber;
using ::testing::AtLeast;
using ::testing::Exactly;
using ::testing::Invoke;
using ::testing::Return;
using ::testing::_;
namespace chromeos {
namespace {
const char kStubEthernetGuid[] = "eth0";
const char kStubWifiGuid[] = "wlan0";
} // namespace
class UpdateScreenTest : public WizardInProcessBrowserTest {
public:
UpdateScreenTest() : WizardInProcessBrowserTest("update"),
fake_update_engine_client_(NULL),
network_portal_detector_(NULL) {
}
protected:
virtual void SetUpInProcessBrowserTestFixture() override {
fake_update_engine_client_ = new FakeUpdateEngineClient;
chromeos::DBusThreadManager::GetSetterForTesting()->SetUpdateEngineClient(
scoped_ptr<UpdateEngineClient>(fake_update_engine_client_));
WizardInProcessBrowserTest::SetUpInProcessBrowserTestFixture();
// Setup network portal detector to return online state for both
// ethernet and wifi networks. Ethernet is an active network by
// default.
network_portal_detector_ = new NetworkPortalDetectorTestImpl();
NetworkPortalDetector::InitializeForTesting(network_portal_detector_);
NetworkPortalDetector::CaptivePortalState online_state;
online_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE;
online_state.response_code = 204;
SetDefaultNetwork(kStubEthernetGuid);
SetDetectionResults(kStubEthernetGuid, online_state);
SetDetectionResults(kStubWifiGuid, online_state);
}
virtual void SetUpOnMainThread() override {
WizardInProcessBrowserTest::SetUpOnMainThread();
mock_screen_observer_.reset(new MockScreenObserver());
mock_error_screen_actor_.reset(new MockErrorScreenActor());
mock_error_screen_.reset(
new MockErrorScreen(mock_screen_observer_.get(),
mock_error_screen_actor_.get()));
EXPECT_CALL(*mock_screen_observer_, ShowCurrentScreen())
.Times(AnyNumber());
EXPECT_CALL(*mock_screen_observer_, GetErrorScreen())
.Times(AnyNumber())
.WillRepeatedly(Return(mock_error_screen_.get()));
ASSERT_TRUE(WizardController::default_controller() != NULL);
update_screen_ = UpdateScreen::Get(WizardController::default_controller());
ASSERT_TRUE(update_screen_ != NULL);
ASSERT_EQ(WizardController::default_controller()->current_screen(),
update_screen_);
update_screen_->screen_observer_ = mock_screen_observer_.get();
}
virtual void TearDownOnMainThread() override {
mock_error_screen_.reset();
mock_error_screen_actor_.reset();
WizardInProcessBrowserTest::TearDownOnMainThread();
}
virtual void TearDownInProcessBrowserTestFixture() override {
NetworkPortalDetector::Shutdown();
WizardInProcessBrowserTest::TearDownInProcessBrowserTestFixture();
}
void SetDefaultNetwork(const std::string& guid) {
DCHECK(network_portal_detector_);
network_portal_detector_->SetDefaultNetworkForTesting(guid);
}
void SetDetectionResults(
const std::string& guid,
const NetworkPortalDetector::CaptivePortalState& state) {
DCHECK(network_portal_detector_);
network_portal_detector_->SetDetectionResultsForTesting(guid, state);
}
void NotifyPortalDetectionCompleted() {
DCHECK(network_portal_detector_);
network_portal_detector_->NotifyObserversForTesting();
}
FakeUpdateEngineClient* fake_update_engine_client_;
scoped_ptr<MockScreenObserver> mock_screen_observer_;
scoped_ptr<MockErrorScreenActor> mock_error_screen_actor_;
scoped_ptr<MockErrorScreen> mock_error_screen_;
UpdateScreen* update_screen_;
NetworkPortalDetectorTestImpl* network_portal_detector_;
private:
DISALLOW_COPY_AND_ASSIGN(UpdateScreenTest);
};
IN_PROC_BROWSER_TEST_F(UpdateScreenTest, TestBasic) {
ASSERT_TRUE(update_screen_->actor_ != NULL);
}
IN_PROC_BROWSER_TEST_F(UpdateScreenTest, TestNoUpdate) {
update_screen_->SetIgnoreIdleStatus(true);
UpdateEngineClient::Status status;
status.status = UpdateEngineClient::UPDATE_STATUS_IDLE;
update_screen_->UpdateStatusChanged(status);
status.status = UpdateEngineClient::UPDATE_STATUS_CHECKING_FOR_UPDATE;
update_screen_->UpdateStatusChanged(status);
status.status = UpdateEngineClient::UPDATE_STATUS_IDLE;
// GetLastStatus() will be called via ExitUpdate() called from
// UpdateStatusChanged().
fake_update_engine_client_->set_default_status(status);
EXPECT_CALL(*mock_screen_observer_, OnExit(ScreenObserver::UPDATE_NOUPDATE))
.Times(1);
update_screen_->UpdateStatusChanged(status);
}
IN_PROC_BROWSER_TEST_F(UpdateScreenTest, TestUpdateAvailable) {
update_screen_->is_ignore_update_deadlines_ = true;
UpdateEngineClient::Status status;
status.status = UpdateEngineClient::UPDATE_STATUS_UPDATE_AVAILABLE;
status.new_version = "latest and greatest";
update_screen_->UpdateStatusChanged(status);
status.status = UpdateEngineClient::UPDATE_STATUS_DOWNLOADING;
status.download_progress = 0.0;
update_screen_->UpdateStatusChanged(status);
status.download_progress = 0.5;
update_screen_->UpdateStatusChanged(status);
status.download_progress = 1.0;
update_screen_->UpdateStatusChanged(status);
status.status = UpdateEngineClient::UPDATE_STATUS_VERIFYING;
update_screen_->UpdateStatusChanged(status);
status.status = UpdateEngineClient::UPDATE_STATUS_FINALIZING;
update_screen_->UpdateStatusChanged(status);
status.status = UpdateEngineClient::UPDATE_STATUS_UPDATED_NEED_REBOOT;
update_screen_->UpdateStatusChanged(status);
// UpdateStatusChanged(status) calls RebootAfterUpdate().
EXPECT_EQ(1, fake_update_engine_client_->reboot_after_update_call_count());
// Check that OOBE will resume back at this screen.
base::MessageLoop::current()->RunUntilIdle();
EXPECT_FALSE(StartupUtils::IsOobeCompleted());
EXPECT_EQ(update_screen_->GetName(),
g_browser_process->local_state()->GetString(prefs::kOobeScreenPending));
}
IN_PROC_BROWSER_TEST_F(UpdateScreenTest, TestErrorIssuingUpdateCheck) {
// First, cancel the update that is already in progress.
EXPECT_CALL(*mock_screen_observer_,
OnExit(ScreenObserver::UPDATE_NOUPDATE))
.Times(1);
update_screen_->CancelUpdate();
fake_update_engine_client_->set_update_check_result(
chromeos::UpdateEngineClient::UPDATE_RESULT_FAILED);
EXPECT_CALL(*mock_screen_observer_,
OnExit(ScreenObserver::UPDATE_ERROR_CHECKING_FOR_UPDATE))
.Times(1);
update_screen_->StartNetworkCheck();
}
IN_PROC_BROWSER_TEST_F(UpdateScreenTest, TestErrorCheckingForUpdate) {
UpdateEngineClient::Status status;
status.status = UpdateEngineClient::UPDATE_STATUS_ERROR;
// GetLastStatus() will be called via ExitUpdate() called from
// UpdateStatusChanged().
fake_update_engine_client_->set_default_status(status);
EXPECT_CALL(*mock_screen_observer_,
OnExit(ScreenObserver::UPDATE_ERROR_CHECKING_FOR_UPDATE))
.Times(1);
update_screen_->UpdateStatusChanged(status);
}
IN_PROC_BROWSER_TEST_F(UpdateScreenTest, TestErrorUpdating) {
UpdateEngineClient::Status status;
status.status = UpdateEngineClient::UPDATE_STATUS_UPDATE_AVAILABLE;
status.new_version = "latest and greatest";
// GetLastStatus() will be called via ExitUpdate() called from
// UpdateStatusChanged().
fake_update_engine_client_->set_default_status(status);
update_screen_->UpdateStatusChanged(status);
status.status = UpdateEngineClient::UPDATE_STATUS_ERROR;
// GetLastStatus() will be called via ExitUpdate() called from
// UpdateStatusChanged().
fake_update_engine_client_->set_default_status(status);
EXPECT_CALL(*mock_screen_observer_,
OnExit(ScreenObserver::UPDATE_ERROR_UPDATING))
.Times(1);
update_screen_->UpdateStatusChanged(status);
}
IN_PROC_BROWSER_TEST_F(UpdateScreenTest, TestTemproraryOfflineNetwork) {
EXPECT_CALL(*mock_screen_observer_,
OnExit(ScreenObserver::UPDATE_NOUPDATE))
.Times(1);
update_screen_->CancelUpdate();
// Change ethernet state to portal.
NetworkPortalDetector::CaptivePortalState portal_state;
portal_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL;
portal_state.response_code = 200;
SetDetectionResults(kStubEthernetGuid, portal_state);
// Update screen will show error message about portal state because
// ethernet is behind captive portal.
EXPECT_CALL(*mock_error_screen_actor_,
SetUIState(ErrorScreen::UI_STATE_UPDATE))
.Times(1);
EXPECT_CALL(*mock_error_screen_actor_,
SetErrorState(ErrorScreen::ERROR_STATE_PORTAL, std::string()))
.Times(1);
EXPECT_CALL(*mock_error_screen_actor_, FixCaptivePortal())
.Times(1);
EXPECT_CALL(*mock_screen_observer_, ShowErrorScreen())
.Times(1);
update_screen_->StartNetworkCheck();
NetworkPortalDetector::CaptivePortalState online_state;
online_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE;
online_state.response_code = 204;
SetDetectionResults(kStubEthernetGuid, online_state);
// Second notification from portal detector will be about online state,
// so update screen will hide error message and proceed to update.
EXPECT_CALL(*mock_screen_observer_, HideErrorScreen(update_screen_))
.Times(1);
fake_update_engine_client_->set_update_check_result(
chromeos::UpdateEngineClient::UPDATE_RESULT_FAILED);
EXPECT_CALL(*mock_screen_observer_,
OnExit(ScreenObserver::UPDATE_ERROR_CHECKING_FOR_UPDATE))
.Times(1);
NotifyPortalDetectionCompleted();
}
IN_PROC_BROWSER_TEST_F(UpdateScreenTest, TestTwoOfflineNetworks) {
EXPECT_CALL(*mock_screen_observer_,
OnExit(ScreenObserver::UPDATE_NOUPDATE))
.Times(1);
update_screen_->CancelUpdate();
// Change ethernet state to portal.
NetworkPortalDetector::CaptivePortalState portal_state;
portal_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL;
portal_state.response_code = 200;
SetDetectionResults(kStubEthernetGuid, portal_state);
// Update screen will show error message about portal state because
// ethernet is behind captive portal.
EXPECT_CALL(*mock_error_screen_actor_,
SetUIState(ErrorScreen::UI_STATE_UPDATE))
.Times(1);
EXPECT_CALL(*mock_error_screen_actor_,
SetErrorState(ErrorScreen::ERROR_STATE_PORTAL, std::string()))
.Times(1);
EXPECT_CALL(*mock_error_screen_actor_, FixCaptivePortal())
.Times(1);
EXPECT_CALL(*mock_screen_observer_, ShowErrorScreen())
.Times(1);
update_screen_->StartNetworkCheck();
// Change active network to the wifi behind proxy.
NetworkPortalDetector::CaptivePortalState proxy_state;
proxy_state.status =
NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PROXY_AUTH_REQUIRED;
proxy_state.response_code = -1;
SetDefaultNetwork(kStubWifiGuid);
SetDetectionResults(kStubWifiGuid, proxy_state);
// Update screen will show message about proxy error because wifie
// network requires proxy authentication.
EXPECT_CALL(*mock_error_screen_actor_,
SetErrorState(ErrorScreen::ERROR_STATE_PROXY, std::string()))
.Times(1);
NotifyPortalDetectionCompleted();
}
IN_PROC_BROWSER_TEST_F(UpdateScreenTest, TestVoidNetwork) {
SetDefaultNetwork(std::string());
// Cancels pending update request.
EXPECT_CALL(*mock_screen_observer_,
OnExit(ScreenObserver::UPDATE_NOUPDATE))
.Times(1);
update_screen_->CancelUpdate();
// First portal detection attempt returns NULL network and undefined
// results, so detection is restarted.
EXPECT_CALL(*mock_error_screen_actor_,
SetUIState(_))
.Times(Exactly(0));
EXPECT_CALL(*mock_error_screen_actor_,
SetErrorState(_, _))
.Times(Exactly(0));
EXPECT_CALL(*mock_screen_observer_, ShowErrorScreen())
.Times(Exactly(0));
update_screen_->StartNetworkCheck();
// Second portal detection also returns NULL network and undefined
// results. In this case, offline message should be displayed.
EXPECT_CALL(*mock_error_screen_actor_,
SetUIState(ErrorScreen::UI_STATE_UPDATE))
.Times(1);
EXPECT_CALL(*mock_error_screen_actor_,
SetErrorState(ErrorScreen::ERROR_STATE_OFFLINE, std::string()))
.Times(1);
EXPECT_CALL(*mock_screen_observer_, ShowErrorScreen())
.Times(1);
base::MessageLoop::current()->RunUntilIdle();
NotifyPortalDetectionCompleted();
}
IN_PROC_BROWSER_TEST_F(UpdateScreenTest, TestAPReselection) {
EXPECT_CALL(*mock_screen_observer_,
OnExit(ScreenObserver::UPDATE_NOUPDATE))
.Times(1);
update_screen_->CancelUpdate();
// Change ethernet state to portal.
NetworkPortalDetector::CaptivePortalState portal_state;
portal_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL;
portal_state.response_code = 200;
SetDetectionResults(kStubEthernetGuid, portal_state);
// Update screen will show error message about portal state because
// ethernet is behind captive portal.
EXPECT_CALL(*mock_error_screen_actor_,
SetUIState(ErrorScreen::UI_STATE_UPDATE))
.Times(1);
EXPECT_CALL(*mock_error_screen_actor_,
SetErrorState(ErrorScreen::ERROR_STATE_PORTAL, std::string()))
.Times(1);
EXPECT_CALL(*mock_error_screen_actor_, FixCaptivePortal())
.Times(1);
EXPECT_CALL(*mock_screen_observer_, ShowErrorScreen())
.Times(1);
update_screen_->StartNetworkCheck();
// User re-selects the same network manually. In this case, hide
// offline message and skip network check. Since ethernet is still
// behind portal, update engine fails to update.
EXPECT_CALL(*mock_screen_observer_, HideErrorScreen(update_screen_))
.Times(1);
fake_update_engine_client_->set_update_check_result(
chromeos::UpdateEngineClient::UPDATE_RESULT_FAILED);
EXPECT_CALL(*mock_screen_observer_,
OnExit(ScreenObserver::UPDATE_ERROR_CHECKING_FOR_UPDATE))
.Times(1);
update_screen_->OnConnectToNetworkRequested();
base::MessageLoop::current()->RunUntilIdle();
}
} // namespace chromeos
|