ExtensionSyncService: listen for relevant changes instead of being explicitly called...
[chromium-blink-merge.git] / chrome / browser / chromeos / login / wizard_controller_browsertest.cc
blobdb26cd0c75fc506cc976063698ad09a3af79ef41
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
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/login/wizard_controller.h"
7 #include "base/basictypes.h"
8 #include "base/command_line.h"
9 #include "base/compiler_specific.h"
10 #include "base/prefs/pref_registry_simple.h"
11 #include "base/prefs/pref_service.h"
12 #include "base/prefs/pref_service_factory.h"
13 #include "base/prefs/testing_pref_store.h"
14 #include "base/run_loop.h"
15 #include "base/strings/string_util.h"
16 #include "base/strings/utf_string_conversions.h"
17 #include "chrome/browser/browser_process.h"
18 #include "chrome/browser/browser_shutdown.h"
19 #include "chrome/browser/chrome_notification_types.h"
20 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
21 #include "chrome/browser/chromeos/base/locale_util.h"
22 #include "chrome/browser/chromeos/login/enrollment/enrollment_screen.h"
23 #include "chrome/browser/chromeos/login/enrollment/enterprise_enrollment_helper.h"
24 #include "chrome/browser/chromeos/login/enrollment/mock_auto_enrollment_check_screen.h"
25 #include "chrome/browser/chromeos/login/enrollment/mock_enrollment_screen.h"
26 #include "chrome/browser/chromeos/login/existing_user_controller.h"
27 #include "chrome/browser/chromeos/login/screens/device_disabled_screen.h"
28 #include "chrome/browser/chromeos/login/screens/error_screen.h"
29 #include "chrome/browser/chromeos/login/screens/hid_detection_screen.h"
30 #include "chrome/browser/chromeos/login/screens/mock_device_disabled_screen_actor.h"
31 #include "chrome/browser/chromeos/login/screens/mock_enable_debugging_screen.h"
32 #include "chrome/browser/chromeos/login/screens/mock_eula_screen.h"
33 #include "chrome/browser/chromeos/login/screens/mock_network_screen.h"
34 #include "chrome/browser/chromeos/login/screens/mock_update_screen.h"
35 #include "chrome/browser/chromeos/login/screens/mock_wrong_hwid_screen.h"
36 #include "chrome/browser/chromeos/login/screens/network_screen.h"
37 #include "chrome/browser/chromeos/login/screens/reset_screen.h"
38 #include "chrome/browser/chromeos/login/screens/user_image_screen.h"
39 #include "chrome/browser/chromeos/login/screens/wrong_hwid_screen.h"
40 #include "chrome/browser/chromeos/login/startup_utils.h"
41 #include "chrome/browser/chromeos/login/test/wizard_in_process_browser_test.h"
42 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h"
43 #include "chrome/browser/chromeos/login/ui/webui_login_view.h"
44 #include "chrome/browser/chromeos/net/network_portal_detector_test_impl.h"
45 #include "chrome/browser/chromeos/policy/enrollment_config.h"
46 #include "chrome/browser/chromeos/policy/server_backed_device_state.h"
47 #include "chrome/browser/chromeos/policy/stub_enterprise_install_attributes.h"
48 #include "chrome/browser/chromeos/profiles/profile_helper.h"
49 #include "chrome/browser/profiles/profile_manager.h"
50 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h"
51 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h"
52 #include "chrome/common/chrome_switches.h"
53 #include "chrome/common/pref_names.h"
54 #include "chrome/grit/generated_resources.h"
55 #include "chromeos/audio/cras_audio_handler.h"
56 #include "chromeos/chromeos_switches.h"
57 #include "chromeos/chromeos_test_utils.h"
58 #include "chromeos/dbus/dbus_thread_manager.h"
59 #include "chromeos/dbus/fake_session_manager_client.h"
60 #include "chromeos/geolocation/simple_geolocation_provider.h"
61 #include "chromeos/network/network_state.h"
62 #include "chromeos/network/network_state_handler.h"
63 #include "chromeos/settings/timezone_settings.h"
64 #include "chromeos/system/fake_statistics_provider.h"
65 #include "chromeos/system/statistics_provider.h"
66 #include "chromeos/timezone/timezone_request.h"
67 #include "components/policy/core/common/cloud/cloud_policy_constants.h"
68 #include "content/public/test/browser_test_utils.h"
69 #include "content/public/test/test_utils.h"
70 #include "net/test/spawned_test_server/spawned_test_server.h"
71 #include "net/url_request/test_url_fetcher_factory.h"
72 #include "net/url_request/url_fetcher_impl.h"
73 #include "testing/gmock/include/gmock/gmock.h"
74 #include "testing/gtest/include/gtest/gtest.h"
75 #include "third_party/icu/source/common/unicode/locid.h"
76 #include "ui/base/accelerators/accelerator.h"
77 #include "ui/base/l10n/l10n_util.h"
79 using ::testing::Exactly;
80 using ::testing::Invoke;
81 using ::testing::Mock;
82 using ::testing::Return;
84 namespace chromeos {
86 namespace {
88 const char kGeolocationResponseBody[] =
89 "{\n"
90 " \"location\": {\n"
91 " \"lat\": 51.0,\n"
92 " \"lng\": -0.1\n"
93 " },\n"
94 " \"accuracy\": 1200.4\n"
95 "}";
97 // Timezone should not match kGeolocationResponseBody to check that exactly
98 // this value will be used.
99 const char kTimezoneResponseBody[] =
100 "{\n"
101 " \"dstOffset\" : 0.0,\n"
102 " \"rawOffset\" : -32400.0,\n"
103 " \"status\" : \"OK\",\n"
104 " \"timeZoneId\" : \"America/Anchorage\",\n"
105 " \"timeZoneName\" : \"Pacific Standard Time\"\n"
106 "}";
108 const char kDisabledMessage[] = "This device has been disabled.";
110 // Matches on the mode parameter of an EnrollmentConfig object.
111 MATCHER_P(EnrollmentModeMatches, mode, "") {
112 return arg.mode == mode;
115 class PrefStoreStub : public TestingPrefStore {
116 public:
117 // TestingPrefStore overrides:
118 PrefReadError GetReadError() const override {
119 return PersistentPrefStore::PREF_READ_ERROR_JSON_PARSE;
122 bool IsInitializationComplete() const override { return true; }
124 private:
125 ~PrefStoreStub() override {}
128 struct SwitchLanguageTestData {
129 SwitchLanguageTestData() : result("", "", false), done(false) {}
131 locale_util::LanguageSwitchResult result;
132 bool done;
135 void OnLocaleSwitched(SwitchLanguageTestData* self,
136 const locale_util::LanguageSwitchResult& result) {
137 self->result = result;
138 self->done = true;
141 void RunSwitchLanguageTest(const std::string& locale,
142 const std::string& expected_locale,
143 const bool expect_success) {
144 SwitchLanguageTestData data;
145 locale_util::SwitchLanguageCallback callback(
146 base::Bind(&OnLocaleSwitched, base::Unretained(&data)));
147 locale_util::SwitchLanguage(locale, true, false, callback,
148 ProfileManager::GetActiveUserProfile());
150 // Token writing moves control to BlockingPool and back.
151 content::RunAllBlockingPoolTasksUntilIdle();
153 EXPECT_EQ(data.done, true);
154 EXPECT_EQ(data.result.requested_locale, locale);
155 EXPECT_EQ(data.result.loaded_locale, expected_locale);
156 EXPECT_EQ(data.result.success, expect_success);
159 void SetUpCrasAndEnableChromeVox(int volume_percent, bool mute_on) {
160 AccessibilityManager* a11y = AccessibilityManager::Get();
161 CrasAudioHandler* cras = CrasAudioHandler::Get();
163 // Audio output is at |volume_percent| and |mute_on|. Spoken feedback
164 // is disabled.
165 cras->SetOutputVolumePercent(volume_percent);
166 cras->SetOutputMute(mute_on);
167 a11y->EnableSpokenFeedback(false, ui::A11Y_NOTIFICATION_NONE);
169 // Spoken feedback is enabled.
170 a11y->EnableSpokenFeedback(true, ui::A11Y_NOTIFICATION_NONE);
171 base::RunLoop().RunUntilIdle();
174 void QuitLoopOnAutoEnrollmentProgress(
175 policy::AutoEnrollmentState expected_state,
176 base::RunLoop* loop,
177 policy::AutoEnrollmentState actual_state) {
178 if (expected_state == actual_state)
179 loop->Quit();
182 void WaitForAutoEnrollmentState(policy::AutoEnrollmentState state) {
183 base::RunLoop loop;
184 AutoEnrollmentController* auto_enrollment_controller =
185 LoginDisplayHostImpl::default_host()->GetAutoEnrollmentController();
186 scoped_ptr<AutoEnrollmentController::ProgressCallbackList::Subscription>
187 progress_subscription(
188 auto_enrollment_controller->RegisterProgressCallback(
189 base::Bind(&QuitLoopOnAutoEnrollmentProgress, state, &loop)));
190 loop.Run();
193 } // namespace
195 using ::testing::_;
197 template <class T, class H>
198 class MockOutShowHide : public T {
199 public:
200 template <class P> explicit MockOutShowHide(P p) : T(p) {}
201 template <class P> MockOutShowHide(P p, H* actor)
202 : T(p, actor), actor_(actor) {}
203 template <class P, class Q>
204 MockOutShowHide(P p, Q q, H* actor)
205 : T(p, q, actor), actor_(actor) {}
207 H* actor() const { return actor_.get(); }
209 MOCK_METHOD0(Show, void());
210 MOCK_METHOD0(Hide, void());
212 void RealShow() {
213 T::Show();
216 void RealHide() {
217 T::Hide();
220 private:
221 scoped_ptr<H> actor_;
224 #define MOCK(mock_var, screen_name, mocked_class, actor_class) \
225 mock_var = new MockOutShowHide<mocked_class, actor_class>( \
226 WizardController::default_controller(), new actor_class); \
227 WizardController::default_controller() \
228 ->screens_[WizardController::screen_name] = make_linked_ptr(mock_var); \
229 EXPECT_CALL(*mock_var, Show()).Times(0); \
230 EXPECT_CALL(*mock_var, Hide()).Times(0);
232 #define MOCK_WITH_DELEGATE(mock_var, screen_name, mocked_class, actor_class) \
233 mock_var = new MockOutShowHide<mocked_class, actor_class>( \
234 WizardController::default_controller(), \
235 WizardController::default_controller(), \
236 new actor_class); \
237 WizardController::default_controller() \
238 ->screens_[WizardController::screen_name] = make_linked_ptr(mock_var); \
239 EXPECT_CALL(*mock_var, Show()).Times(0); \
240 EXPECT_CALL(*mock_var, Hide()).Times(0);
242 class WizardControllerTest : public WizardInProcessBrowserTest {
243 protected:
244 WizardControllerTest() : WizardInProcessBrowserTest(
245 WizardController::kTestNoScreenName) {}
246 ~WizardControllerTest() override {}
248 void SetUpOnMainThread() override {
249 AccessibilityManager::Get()->
250 SetProfileForTest(ProfileHelper::GetSigninProfile());
251 WizardInProcessBrowserTest::SetUpOnMainThread();
254 ErrorScreen* GetErrorScreen() {
255 return static_cast<BaseScreenDelegate*>(
256 WizardController::default_controller())->GetErrorScreen();
259 OobeUI* GetOobeUI() {
260 OobeUI* oobe_ui = static_cast<LoginDisplayHostImpl*>(
261 LoginDisplayHostImpl::default_host())->GetOobeUI();
262 return oobe_ui;
265 content::WebContents* GetWebContents() {
266 LoginDisplayHostImpl* host = static_cast<LoginDisplayHostImpl*>(
267 LoginDisplayHostImpl::default_host());
268 if (!host)
269 return NULL;
270 WebUILoginView* webui_login_view = host->GetWebUILoginView();
271 if (!webui_login_view)
272 return NULL;
273 return webui_login_view->GetWebContents();
276 void WaitUntilJSIsReady() {
277 LoginDisplayHostImpl* host = static_cast<LoginDisplayHostImpl*>(
278 LoginDisplayHostImpl::default_host());
279 if (!host)
280 return;
281 chromeos::OobeUI* oobe_ui = host->GetOobeUI();
282 if (!oobe_ui)
283 return;
284 base::RunLoop run_loop;
285 const bool oobe_ui_ready = oobe_ui->IsJSReady(run_loop.QuitClosure());
286 if (!oobe_ui_ready)
287 run_loop.Run();
290 bool JSExecute(const std::string& expression) {
291 return content::ExecuteScript(
292 GetWebContents(),
293 "window.domAutomationController.send(!!(" + expression + "));");
296 bool JSExecuteBooleanExpression(const std::string& expression) {
297 bool result;
298 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
299 GetWebContents(),
300 "window.domAutomationController.send(!!(" + expression + "));",
301 &result));
302 return result;
305 void CheckCurrentScreen(const std::string& screen_name) {
306 EXPECT_EQ(WizardController::default_controller()->GetScreen(screen_name),
307 WizardController::default_controller()->current_screen());
310 private:
311 DISALLOW_COPY_AND_ASSIGN(WizardControllerTest);
314 IN_PROC_BROWSER_TEST_F(WizardControllerTest, SwitchLanguage) {
315 ASSERT_TRUE(WizardController::default_controller() != NULL);
316 WizardController::default_controller()->AdvanceToScreen(
317 WizardController::kNetworkScreenName);
319 // Checking the default locale. Provided that the profile is cleared in SetUp.
320 EXPECT_EQ("en-US", g_browser_process->GetApplicationLocale());
321 EXPECT_STREQ("en", icu::Locale::getDefault().getLanguage());
322 EXPECT_FALSE(base::i18n::IsRTL());
323 const base::string16 en_str =
324 l10n_util::GetStringUTF16(IDS_NETWORK_SELECTION_TITLE);
326 RunSwitchLanguageTest("fr", "fr", true);
327 EXPECT_EQ("fr", g_browser_process->GetApplicationLocale());
328 EXPECT_STREQ("fr", icu::Locale::getDefault().getLanguage());
329 EXPECT_FALSE(base::i18n::IsRTL());
330 const base::string16 fr_str =
331 l10n_util::GetStringUTF16(IDS_NETWORK_SELECTION_TITLE);
333 EXPECT_NE(en_str, fr_str);
335 RunSwitchLanguageTest("ar", "ar", true);
336 EXPECT_EQ("ar", g_browser_process->GetApplicationLocale());
337 EXPECT_STREQ("ar", icu::Locale::getDefault().getLanguage());
338 EXPECT_TRUE(base::i18n::IsRTL());
339 const base::string16 ar_str =
340 l10n_util::GetStringUTF16(IDS_NETWORK_SELECTION_TITLE);
342 EXPECT_NE(fr_str, ar_str);
345 IN_PROC_BROWSER_TEST_F(WizardControllerTest, VolumeIsChangedForChromeVox) {
346 SetUpCrasAndEnableChromeVox(75 /* volume_percent */, true /* mute_on */);
348 // Check that output is unmuted now and at some level.
349 CrasAudioHandler* cras = CrasAudioHandler::Get();
350 ASSERT_FALSE(cras->IsOutputMuted());
351 ASSERT_EQ(WizardController::kMinAudibleOutputVolumePercent,
352 cras->GetOutputVolumePercent());
355 IN_PROC_BROWSER_TEST_F(WizardControllerTest, VolumeIsUnchangedForChromeVox) {
356 SetUpCrasAndEnableChromeVox(75 /* volume_percent */, false /* mute_on */);
358 // Check that output is unmuted now and at some level.
359 CrasAudioHandler* cras = CrasAudioHandler::Get();
360 ASSERT_FALSE(cras->IsOutputMuted());
361 ASSERT_EQ(75, cras->GetOutputVolumePercent());
364 IN_PROC_BROWSER_TEST_F(WizardControllerTest, VolumeIsAdjustedForChromeVox) {
365 SetUpCrasAndEnableChromeVox(5 /* volume_percent */, false /* mute_on */);
367 // Check that output is unmuted now and at some level.
368 CrasAudioHandler* cras = CrasAudioHandler::Get();
369 ASSERT_FALSE(cras->IsOutputMuted());
370 ASSERT_EQ(WizardController::kMinAudibleOutputVolumePercent,
371 cras->GetOutputVolumePercent());
374 class WizardControllerTestURLFetcherFactory
375 : public net::TestURLFetcherFactory {
376 public:
377 scoped_ptr<net::URLFetcher> CreateURLFetcher(
378 int id,
379 const GURL& url,
380 net::URLFetcher::RequestType request_type,
381 net::URLFetcherDelegate* d) override {
382 if (base::StartsWith(
383 url.spec(),
384 SimpleGeolocationProvider::DefaultGeolocationProviderURL().spec(),
385 base::CompareCase::SENSITIVE)) {
386 return scoped_ptr<net::URLFetcher>(new net::FakeURLFetcher(
387 url, d, std::string(kGeolocationResponseBody), net::HTTP_OK,
388 net::URLRequestStatus::SUCCESS));
390 if (base::StartsWith(url.spec(),
391 chromeos::DefaultTimezoneProviderURL().spec(),
392 base::CompareCase::SENSITIVE)) {
393 return scoped_ptr<net::URLFetcher>(new net::FakeURLFetcher(
394 url, d, std::string(kTimezoneResponseBody), net::HTTP_OK,
395 net::URLRequestStatus::SUCCESS));
397 return net::TestURLFetcherFactory::CreateURLFetcher(
398 id, url, request_type, d);
400 ~WizardControllerTestURLFetcherFactory() override {}
403 class TimeZoneTestRunner {
404 public:
405 void OnResolved() { loop_.Quit(); }
406 void Run() { loop_.Run(); }
408 private:
409 base::RunLoop loop_;
412 class WizardControllerFlowTest : public WizardControllerTest {
413 protected:
414 WizardControllerFlowTest() {}
415 // Overriden from InProcessBrowserTest:
416 void SetUpOnMainThread() override {
417 WizardControllerTest::SetUpOnMainThread();
419 // Make sure that OOBE is run as an "official" build.
420 WizardController* wizard_controller =
421 WizardController::default_controller();
422 wizard_controller->is_official_build_ = true;
424 // Clear portal list (as it is by default in OOBE).
425 NetworkHandler::Get()->network_state_handler()->SetCheckPortalList("");
427 // Set up the mocks for all screens.
428 mock_network_screen_.reset(new MockNetworkScreen(
429 WizardController::default_controller(),
430 WizardController::default_controller(), GetOobeUI()->GetNetworkView()));
431 mock_network_screen_->Initialize(nullptr /* context */);
432 WizardController::default_controller()
433 ->screens_[WizardController::kNetworkScreenName] = mock_network_screen_;
434 EXPECT_CALL(*mock_network_screen_, Show()).Times(0);
435 EXPECT_CALL(*mock_network_screen_, Hide()).Times(0);
437 MOCK(mock_update_screen_, kUpdateScreenName, MockUpdateScreen,
438 MockUpdateView);
439 MOCK_WITH_DELEGATE(mock_eula_screen_, kEulaScreenName, MockEulaScreen,
440 MockEulaView);
441 MOCK(mock_enrollment_screen_,
442 kEnrollmentScreenName,
443 MockEnrollmentScreen,
444 MockEnrollmentScreenActor);
445 MOCK(mock_auto_enrollment_check_screen_,
446 kAutoEnrollmentCheckScreenName,
447 MockAutoEnrollmentCheckScreen,
448 MockAutoEnrollmentCheckScreenActor);
449 MOCK(mock_wrong_hwid_screen_, kWrongHWIDScreenName, MockWrongHWIDScreen,
450 MockWrongHWIDScreenActor);
451 MOCK(mock_enable_debugging_screen_,
452 kEnableDebuggingScreenName,
453 MockEnableDebuggingScreen,
454 MockEnableDebuggingScreenActor);
455 device_disabled_screen_actor_.reset(new MockDeviceDisabledScreenActor);
456 wizard_controller->screens_[WizardController::kDeviceDisabledScreenName] =
457 make_linked_ptr(new DeviceDisabledScreen(
458 wizard_controller,
459 device_disabled_screen_actor_.get()));
460 EXPECT_CALL(*device_disabled_screen_actor_, Show()).Times(0);
462 // Switch to the initial screen.
463 EXPECT_EQ(NULL, wizard_controller->current_screen());
464 EXPECT_CALL(*mock_network_screen_, Show()).Times(1);
465 wizard_controller->AdvanceToScreen(WizardController::kNetworkScreenName);
468 void TearDownOnMainThread() override {
469 mock_network_screen_.reset();
470 device_disabled_screen_actor_.reset();
471 WizardControllerTest::TearDownOnMainThread();
474 void TearDown() override {
475 if (fallback_fetcher_factory_) {
476 fetcher_factory_.reset();
477 net::URLFetcherImpl::set_factory(fallback_fetcher_factory_.get());
478 fallback_fetcher_factory_.reset();
482 void InitTimezoneResolver() {
483 fallback_fetcher_factory_.reset(new WizardControllerTestURLFetcherFactory);
484 net::URLFetcherImpl::set_factory(NULL);
485 fetcher_factory_.reset(
486 new net::FakeURLFetcherFactory(fallback_fetcher_factory_.get()));
488 network_portal_detector_ = new NetworkPortalDetectorTestImpl();
489 NetworkPortalDetector::InitializeForTesting(network_portal_detector_);
491 NetworkPortalDetector::CaptivePortalState online_state;
492 online_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE;
493 online_state.response_code = 204;
495 // Default detworks happens to be usually "eth1" in tests.
496 const NetworkState* default_network =
497 NetworkHandler::Get()->network_state_handler()->DefaultNetwork();
499 network_portal_detector_->SetDefaultNetworkForTesting(
500 default_network->guid());
501 network_portal_detector_->SetDetectionResultsForTesting(
502 default_network->guid(),
503 online_state);
506 void OnExit(BaseScreen& screen, BaseScreenDelegate::ExitCodes exit_code) {
507 WizardController::default_controller()->OnExit(screen, exit_code,
508 nullptr /* context */);
511 chromeos::SimpleGeolocationProvider* GetGeolocationProvider() {
512 return WizardController::default_controller()->geolocation_provider_.get();
515 void WaitUntilTimezoneResolved() {
516 scoped_ptr<TimeZoneTestRunner> runner(new TimeZoneTestRunner);
517 if (!WizardController::default_controller()
518 ->SetOnTimeZoneResolvedForTesting(
519 base::Bind(&TimeZoneTestRunner::OnResolved,
520 base::Unretained(runner.get()))))
521 return;
523 runner->Run();
526 void ResetAutoEnrollmentCheckScreen() {
527 WizardController::default_controller()->screens_.erase(
528 WizardController::kAutoEnrollmentCheckScreenName);
531 linked_ptr<MockNetworkScreen> mock_network_screen_;
532 MockOutShowHide<MockUpdateScreen, MockUpdateView>* mock_update_screen_;
533 MockOutShowHide<MockEulaScreen, MockEulaView>* mock_eula_screen_;
534 MockOutShowHide<MockEnrollmentScreen,
535 MockEnrollmentScreenActor>* mock_enrollment_screen_;
536 MockOutShowHide<MockAutoEnrollmentCheckScreen,
537 MockAutoEnrollmentCheckScreenActor>* mock_auto_enrollment_check_screen_;
538 MockOutShowHide<MockWrongHWIDScreen, MockWrongHWIDScreenActor>*
539 mock_wrong_hwid_screen_;
540 MockOutShowHide<MockEnableDebuggingScreen,
541 MockEnableDebuggingScreenActor>* mock_enable_debugging_screen_;
542 scoped_ptr<MockDeviceDisabledScreenActor> device_disabled_screen_actor_;
544 private:
545 NetworkPortalDetectorTestImpl* network_portal_detector_;
547 // Use a test factory as a fallback so we don't have to deal with other
548 // requests.
549 scoped_ptr<WizardControllerTestURLFetcherFactory> fallback_fetcher_factory_;
550 scoped_ptr<net::FakeURLFetcherFactory> fetcher_factory_;
552 DISALLOW_COPY_AND_ASSIGN(WizardControllerFlowTest);
555 IN_PROC_BROWSER_TEST_F(WizardControllerFlowTest, ControlFlowMain) {
556 CheckCurrentScreen(WizardController::kNetworkScreenName);
558 WaitUntilJSIsReady();
560 // Check visibility of the header bar.
561 ASSERT_FALSE(JSExecuteBooleanExpression("$('login-header-bar').hidden"));
563 EXPECT_CALL(*mock_network_screen_, Hide()).Times(1);
564 EXPECT_CALL(*mock_eula_screen_, Show()).Times(1);
565 OnExit(*mock_network_screen_, BaseScreenDelegate::NETWORK_CONNECTED);
567 CheckCurrentScreen(WizardController::kEulaScreenName);
569 // Header bar should still be visible.
570 ASSERT_FALSE(JSExecuteBooleanExpression("$('login-header-bar').hidden"));
572 EXPECT_CALL(*mock_eula_screen_, Hide()).Times(1);
573 EXPECT_CALL(*mock_update_screen_, StartNetworkCheck()).Times(1);
574 EXPECT_CALL(*mock_update_screen_, Show()).Times(1);
575 // Enable TimeZone resolve
576 InitTimezoneResolver();
577 OnExit(*mock_eula_screen_, BaseScreenDelegate::EULA_ACCEPTED);
578 EXPECT_TRUE(GetGeolocationProvider());
580 // Let update screen smooth time process (time = 0ms).
581 content::RunAllPendingInMessageLoop();
583 CheckCurrentScreen(WizardController::kUpdateScreenName);
584 EXPECT_CALL(*mock_update_screen_, Hide()).Times(1);
585 EXPECT_CALL(*mock_auto_enrollment_check_screen_, Show()).Times(1);
586 OnExit(*mock_update_screen_, BaseScreenDelegate::UPDATE_INSTALLED);
588 CheckCurrentScreen(WizardController::kAutoEnrollmentCheckScreenName);
589 EXPECT_CALL(*mock_auto_enrollment_check_screen_, Hide()).Times(0);
590 EXPECT_CALL(*mock_eula_screen_, Show()).Times(0);
591 OnExit(*mock_auto_enrollment_check_screen_,
592 BaseScreenDelegate::ENTERPRISE_AUTO_ENROLLMENT_CHECK_COMPLETED);
594 EXPECT_FALSE(ExistingUserController::current_controller() == NULL);
595 EXPECT_EQ("ethernet,wifi,cellular",
596 NetworkHandler::Get()->network_state_handler()
597 ->GetCheckPortalListForTest());
599 WaitUntilTimezoneResolved();
600 EXPECT_EQ("America/Anchorage",
601 base::UTF16ToUTF8(chromeos::system::TimezoneSettings::GetInstance()
602 ->GetCurrentTimezoneID()));
605 IN_PROC_BROWSER_TEST_F(WizardControllerFlowTest, ControlFlowErrorUpdate) {
606 CheckCurrentScreen(WizardController::kNetworkScreenName);
607 EXPECT_CALL(*mock_update_screen_, StartNetworkCheck()).Times(0);
608 EXPECT_CALL(*mock_eula_screen_, Show()).Times(1);
609 EXPECT_CALL(*mock_update_screen_, Show()).Times(0);
610 EXPECT_CALL(*mock_network_screen_, Hide()).Times(1);
611 OnExit(*mock_network_screen_, BaseScreenDelegate::NETWORK_CONNECTED);
613 CheckCurrentScreen(WizardController::kEulaScreenName);
614 EXPECT_CALL(*mock_eula_screen_, Hide()).Times(1);
615 EXPECT_CALL(*mock_update_screen_, StartNetworkCheck()).Times(1);
616 EXPECT_CALL(*mock_update_screen_, Show()).Times(1);
617 OnExit(*mock_eula_screen_, BaseScreenDelegate::EULA_ACCEPTED);
619 // Let update screen smooth time process (time = 0ms).
620 content::RunAllPendingInMessageLoop();
622 CheckCurrentScreen(WizardController::kUpdateScreenName);
623 EXPECT_CALL(*mock_update_screen_, Hide()).Times(1);
624 EXPECT_CALL(*mock_auto_enrollment_check_screen_, Show()).Times(1);
625 OnExit(*mock_update_screen_, BaseScreenDelegate::UPDATE_ERROR_UPDATING);
627 CheckCurrentScreen(WizardController::kAutoEnrollmentCheckScreenName);
628 EXPECT_CALL(*mock_auto_enrollment_check_screen_, Hide()).Times(0);
629 EXPECT_CALL(*mock_eula_screen_, Show()).Times(0);
630 OnExit(*mock_auto_enrollment_check_screen_,
631 BaseScreenDelegate::ENTERPRISE_AUTO_ENROLLMENT_CHECK_COMPLETED);
633 EXPECT_FALSE(ExistingUserController::current_controller() == NULL);
636 IN_PROC_BROWSER_TEST_F(WizardControllerFlowTest, ControlFlowSkipUpdateEnroll) {
637 CheckCurrentScreen(WizardController::kNetworkScreenName);
638 EXPECT_CALL(*mock_update_screen_, StartNetworkCheck()).Times(0);
639 EXPECT_CALL(*mock_eula_screen_, Show()).Times(1);
640 EXPECT_CALL(*mock_update_screen_, Show()).Times(0);
641 EXPECT_CALL(*mock_network_screen_, Hide()).Times(1);
642 OnExit(*mock_network_screen_, BaseScreenDelegate::NETWORK_CONNECTED);
644 CheckCurrentScreen(WizardController::kEulaScreenName);
645 EXPECT_CALL(*mock_eula_screen_, Hide()).Times(1);
646 EXPECT_CALL(*mock_update_screen_, StartNetworkCheck()).Times(0);
647 EXPECT_CALL(*mock_update_screen_, Show()).Times(0);
648 WizardController::default_controller()->SkipUpdateEnrollAfterEula();
649 EXPECT_CALL(*mock_enrollment_screen_->actor(),
650 SetParameters(
651 mock_enrollment_screen_,
652 EnrollmentModeMatches(policy::EnrollmentConfig::MODE_MANUAL)))
653 .Times(1);
654 EXPECT_CALL(*mock_auto_enrollment_check_screen_, Show()).Times(1);
655 OnExit(*mock_eula_screen_, BaseScreenDelegate::EULA_ACCEPTED);
656 content::RunAllPendingInMessageLoop();
658 CheckCurrentScreen(WizardController::kAutoEnrollmentCheckScreenName);
659 EXPECT_CALL(*mock_auto_enrollment_check_screen_, Hide()).Times(1);
660 EXPECT_CALL(*mock_enrollment_screen_, Show()).Times(1);
661 EXPECT_CALL(*mock_enrollment_screen_, Hide()).Times(0);
662 OnExit(*mock_auto_enrollment_check_screen_,
663 BaseScreenDelegate::ENTERPRISE_AUTO_ENROLLMENT_CHECK_COMPLETED);
664 content::RunAllPendingInMessageLoop();
666 CheckCurrentScreen(WizardController::kEnrollmentScreenName);
667 EXPECT_EQ("ethernet,wifi,cellular",
668 NetworkHandler::Get()->network_state_handler()
669 ->GetCheckPortalListForTest());
672 IN_PROC_BROWSER_TEST_F(WizardControllerFlowTest, ControlFlowEulaDeclined) {
673 CheckCurrentScreen(WizardController::kNetworkScreenName);
674 EXPECT_CALL(*mock_update_screen_, StartNetworkCheck()).Times(0);
675 EXPECT_CALL(*mock_eula_screen_, Show()).Times(1);
676 EXPECT_CALL(*mock_network_screen_, Hide()).Times(1);
677 OnExit(*mock_network_screen_, BaseScreenDelegate::NETWORK_CONNECTED);
679 CheckCurrentScreen(WizardController::kEulaScreenName);
680 EXPECT_CALL(*mock_eula_screen_, Hide()).Times(1);
681 EXPECT_CALL(*mock_network_screen_, Show()).Times(1);
682 EXPECT_CALL(*mock_network_screen_, Hide()).Times(0); // last transition
683 OnExit(*mock_eula_screen_, BaseScreenDelegate::EULA_BACK);
685 CheckCurrentScreen(WizardController::kNetworkScreenName);
688 IN_PROC_BROWSER_TEST_F(WizardControllerFlowTest,
689 ControlFlowEnrollmentCompleted) {
690 CheckCurrentScreen(WizardController::kNetworkScreenName);
691 EXPECT_CALL(*mock_update_screen_, StartNetworkCheck()).Times(0);
692 EXPECT_CALL(*mock_enrollment_screen_->actor(),
693 SetParameters(
694 mock_enrollment_screen_,
695 EnrollmentModeMatches(policy::EnrollmentConfig::MODE_MANUAL)))
696 .Times(1);
697 EXPECT_CALL(*mock_enrollment_screen_, Show()).Times(1);
698 EXPECT_CALL(*mock_network_screen_, Hide()).Times(1);
700 WizardController::default_controller()->AdvanceToScreen(
701 WizardController::kEnrollmentScreenName);
702 CheckCurrentScreen(WizardController::kEnrollmentScreenName);
703 OnExit(*mock_enrollment_screen_,
704 BaseScreenDelegate::ENTERPRISE_ENROLLMENT_COMPLETED);
706 EXPECT_FALSE(ExistingUserController::current_controller() == NULL);
709 IN_PROC_BROWSER_TEST_F(WizardControllerFlowTest,
710 ControlFlowWrongHWIDScreenFromLogin) {
711 CheckCurrentScreen(WizardController::kNetworkScreenName);
713 LoginDisplayHostImpl::default_host()->StartSignInScreen(LoginScreenContext());
714 EXPECT_FALSE(ExistingUserController::current_controller() == NULL);
715 ExistingUserController::current_controller()->ShowWrongHWIDScreen();
717 CheckCurrentScreen(WizardController::kWrongHWIDScreenName);
719 // After warning is skipped, user returns to sign-in screen.
720 // And this destroys WizardController.
721 OnExit(*mock_wrong_hwid_screen_,
722 BaseScreenDelegate::WRONG_HWID_WARNING_SKIPPED);
723 EXPECT_FALSE(ExistingUserController::current_controller() == NULL);
726 class WizardControllerDeviceStateTest : public WizardControllerFlowTest {
727 protected:
728 WizardControllerDeviceStateTest()
729 : install_attributes_(std::string(),
730 std::string(),
731 std::string(),
732 policy::DEVICE_MODE_NOT_SET) {
733 fake_statistics_provider_.SetMachineStatistic("serial_number", "test");
734 fake_statistics_provider_.SetMachineStatistic(system::kActivateDateKey,
735 "2000-01");
738 void SetUpCommandLine(base::CommandLine* command_line) override {
739 WizardControllerFlowTest::SetUpCommandLine(command_line);
741 command_line->AppendSwitchASCII(
742 switches::kEnterpriseEnableForcedReEnrollment,
743 chromeos::AutoEnrollmentController::kForcedReEnrollmentAlways);
744 command_line->AppendSwitchASCII(
745 switches::kEnterpriseEnrollmentInitialModulus, "1");
746 command_line->AppendSwitchASCII(
747 switches::kEnterpriseEnrollmentModulusLimit, "2");
750 system::ScopedFakeStatisticsProvider fake_statistics_provider_;
752 private:
753 policy::ScopedStubEnterpriseInstallAttributes install_attributes_;
755 DISALLOW_COPY_AND_ASSIGN(WizardControllerDeviceStateTest);
758 IN_PROC_BROWSER_TEST_F(WizardControllerDeviceStateTest,
759 ControlFlowForcedReEnrollment) {
760 CheckCurrentScreen(WizardController::kNetworkScreenName);
761 EXPECT_CALL(*mock_network_screen_, Hide()).Times(1);
762 EXPECT_CALL(*mock_eula_screen_, Show()).Times(1);
763 OnExit(*mock_network_screen_, BaseScreenDelegate::NETWORK_CONNECTED);
765 CheckCurrentScreen(WizardController::kEulaScreenName);
766 EXPECT_CALL(*mock_eula_screen_, Hide()).Times(1);
767 EXPECT_CALL(*mock_update_screen_, StartNetworkCheck()).Times(1);
768 EXPECT_CALL(*mock_update_screen_, Show()).Times(1);
769 OnExit(*mock_eula_screen_, BaseScreenDelegate::EULA_ACCEPTED);
771 // Let update screen smooth time process (time = 0ms).
772 content::RunAllPendingInMessageLoop();
774 CheckCurrentScreen(WizardController::kUpdateScreenName);
775 EXPECT_CALL(*mock_update_screen_, Hide()).Times(1);
776 EXPECT_CALL(*mock_auto_enrollment_check_screen_, Show()).Times(1);
777 OnExit(*mock_update_screen_, BaseScreenDelegate::UPDATE_INSTALLED);
779 CheckCurrentScreen(WizardController::kAutoEnrollmentCheckScreenName);
780 EXPECT_CALL(*mock_auto_enrollment_check_screen_, Hide()).Times(1);
781 mock_auto_enrollment_check_screen_->RealShow();
783 // Wait for auto-enrollment controller to encounter the connection error.
784 WaitForAutoEnrollmentState(policy::AUTO_ENROLLMENT_STATE_CONNECTION_ERROR);
786 // The error screen shows up if there's no auto-enrollment decision.
787 EXPECT_FALSE(StartupUtils::IsOobeCompleted());
788 EXPECT_EQ(GetErrorScreen(),
789 WizardController::default_controller()->current_screen());
790 base::DictionaryValue device_state;
791 device_state.SetString(policy::kDeviceStateRestoreMode,
792 policy::kDeviceStateRestoreModeReEnrollmentEnforced);
793 g_browser_process->local_state()->Set(prefs::kServerBackedDeviceState,
794 device_state);
795 EXPECT_CALL(*mock_enrollment_screen_, Show()).Times(1);
796 EXPECT_CALL(*mock_enrollment_screen_->actor(),
797 SetParameters(mock_enrollment_screen_,
798 EnrollmentModeMatches(
799 policy::EnrollmentConfig::MODE_SERVER_FORCED)))
800 .Times(1);
801 OnExit(*mock_auto_enrollment_check_screen_,
802 BaseScreenDelegate::ENTERPRISE_AUTO_ENROLLMENT_CHECK_COMPLETED);
804 ResetAutoEnrollmentCheckScreen();
806 // Make sure enterprise enrollment page shows up.
807 CheckCurrentScreen(WizardController::kEnrollmentScreenName);
808 OnExit(*mock_enrollment_screen_,
809 BaseScreenDelegate::ENTERPRISE_ENROLLMENT_COMPLETED);
811 EXPECT_TRUE(StartupUtils::IsOobeCompleted());
814 IN_PROC_BROWSER_TEST_F(WizardControllerDeviceStateTest,
815 ControlFlowNoForcedReEnrollmentOnFirstBoot) {
816 fake_statistics_provider_.ClearMachineStatistic(system::kActivateDateKey);
817 EXPECT_NE(policy::AUTO_ENROLLMENT_STATE_NO_ENROLLMENT,
818 LoginDisplayHostImpl::default_host()
819 ->GetAutoEnrollmentController()
820 ->state());
822 CheckCurrentScreen(WizardController::kNetworkScreenName);
823 EXPECT_CALL(*mock_network_screen_, Hide()).Times(1);
824 EXPECT_CALL(*mock_eula_screen_, Show()).Times(1);
825 OnExit(*mock_network_screen_, BaseScreenDelegate::NETWORK_CONNECTED);
827 CheckCurrentScreen(WizardController::kEulaScreenName);
828 EXPECT_CALL(*mock_eula_screen_, Hide()).Times(1);
829 EXPECT_CALL(*mock_update_screen_, StartNetworkCheck()).Times(1);
830 EXPECT_CALL(*mock_update_screen_, Show()).Times(1);
831 OnExit(*mock_eula_screen_, BaseScreenDelegate::EULA_ACCEPTED);
833 // Let update screen smooth time process (time = 0ms).
834 content::RunAllPendingInMessageLoop();
836 CheckCurrentScreen(WizardController::kUpdateScreenName);
837 EXPECT_CALL(*mock_update_screen_, Hide()).Times(1);
838 EXPECT_CALL(*mock_auto_enrollment_check_screen_, Show()).Times(1);
839 OnExit(*mock_update_screen_, BaseScreenDelegate::UPDATE_INSTALLED);
841 CheckCurrentScreen(WizardController::kAutoEnrollmentCheckScreenName);
842 mock_auto_enrollment_check_screen_->RealShow();
843 EXPECT_EQ(policy::AUTO_ENROLLMENT_STATE_NO_ENROLLMENT,
844 LoginDisplayHostImpl::default_host()
845 ->GetAutoEnrollmentController()
846 ->state());
849 IN_PROC_BROWSER_TEST_F(WizardControllerDeviceStateTest,
850 ControlFlowDeviceDisabled) {
851 CheckCurrentScreen(WizardController::kNetworkScreenName);
852 EXPECT_CALL(*mock_network_screen_, Hide()).Times(1);
853 EXPECT_CALL(*mock_eula_screen_, Show()).Times(1);
854 OnExit(*mock_network_screen_, BaseScreenDelegate::NETWORK_CONNECTED);
856 CheckCurrentScreen(WizardController::kEulaScreenName);
857 EXPECT_CALL(*mock_eula_screen_, Hide()).Times(1);
858 EXPECT_CALL(*mock_update_screen_, StartNetworkCheck()).Times(1);
859 EXPECT_CALL(*mock_update_screen_, Show()).Times(1);
860 OnExit(*mock_eula_screen_, BaseScreenDelegate::EULA_ACCEPTED);
862 // Let update screen smooth time process (time = 0ms).
863 content::RunAllPendingInMessageLoop();
865 CheckCurrentScreen(WizardController::kUpdateScreenName);
866 EXPECT_CALL(*mock_update_screen_, Hide()).Times(1);
867 EXPECT_CALL(*mock_auto_enrollment_check_screen_, Show()).Times(1);
868 OnExit(*mock_update_screen_, BaseScreenDelegate::UPDATE_INSTALLED);
870 CheckCurrentScreen(WizardController::kAutoEnrollmentCheckScreenName);
871 EXPECT_CALL(*mock_auto_enrollment_check_screen_, Hide()).Times(1);
872 mock_auto_enrollment_check_screen_->RealShow();
874 // Wait for auto-enrollment controller to encounter the connection error.
875 WaitForAutoEnrollmentState(policy::AUTO_ENROLLMENT_STATE_CONNECTION_ERROR);
877 // The error screen shows up if device state could not be retrieved.
878 EXPECT_FALSE(StartupUtils::IsOobeCompleted());
879 EXPECT_EQ(GetErrorScreen(),
880 WizardController::default_controller()->current_screen());
881 base::DictionaryValue device_state;
882 device_state.SetString(policy::kDeviceStateRestoreMode,
883 policy::kDeviceStateRestoreModeDisabled);
884 device_state.SetString(policy::kDeviceStateDisabledMessage, kDisabledMessage);
885 g_browser_process->local_state()->Set(prefs::kServerBackedDeviceState,
886 device_state);
887 EXPECT_CALL(*device_disabled_screen_actor_,
888 UpdateMessage(kDisabledMessage)).Times(1);
889 EXPECT_CALL(*device_disabled_screen_actor_, Show()).Times(1);
890 OnExit(*mock_auto_enrollment_check_screen_,
891 BaseScreenDelegate::ENTERPRISE_AUTO_ENROLLMENT_CHECK_COMPLETED);
893 ResetAutoEnrollmentCheckScreen();
895 // Make sure the device disabled screen is shown.
896 CheckCurrentScreen(WizardController::kDeviceDisabledScreenName);
898 EXPECT_FALSE(StartupUtils::IsOobeCompleted());
901 class WizardControllerBrokenLocalStateTest : public WizardControllerTest {
902 protected:
903 WizardControllerBrokenLocalStateTest()
904 : fake_session_manager_client_(NULL) {
907 ~WizardControllerBrokenLocalStateTest() override {}
909 void SetUpInProcessBrowserTestFixture() override {
910 WizardControllerTest::SetUpInProcessBrowserTestFixture();
912 fake_session_manager_client_ = new FakeSessionManagerClient;
913 DBusThreadManager::GetSetterForTesting()->SetSessionManagerClient(
914 scoped_ptr<SessionManagerClient>(fake_session_manager_client_));
917 void SetUpOnMainThread() override {
918 base::PrefServiceFactory factory;
919 factory.set_user_prefs(make_scoped_refptr(new PrefStoreStub()));
920 local_state_ = factory.Create(new PrefRegistrySimple()).Pass();
921 WizardController::set_local_state_for_testing(local_state_.get());
923 WizardControllerTest::SetUpOnMainThread();
925 // Make sure that OOBE is run as an "official" build.
926 WizardController::default_controller()->is_official_build_ = true;
929 FakeSessionManagerClient* fake_session_manager_client() const {
930 return fake_session_manager_client_;
933 private:
934 scoped_ptr<PrefService> local_state_;
935 FakeSessionManagerClient* fake_session_manager_client_;
937 DISALLOW_COPY_AND_ASSIGN(WizardControllerBrokenLocalStateTest);
940 IN_PROC_BROWSER_TEST_F(WizardControllerBrokenLocalStateTest,
941 LocalStateCorrupted) {
942 // Checks that after wizard controller initialization error screen
943 // in the proper state is displayed.
944 ASSERT_EQ(GetErrorScreen(),
945 WizardController::default_controller()->current_screen());
946 ASSERT_EQ(NetworkError::UI_STATE_LOCAL_STATE_ERROR,
947 GetErrorScreen()->GetUIState());
949 WaitUntilJSIsReady();
951 // Checks visibility of the error message and powerwash button.
952 ASSERT_FALSE(JSExecuteBooleanExpression("$('error-message').hidden"));
953 ASSERT_TRUE(JSExecuteBooleanExpression(
954 "$('error-message').classList.contains('ui-state-local-state-error')"));
955 ASSERT_TRUE(JSExecuteBooleanExpression("$('progress-dots').hidden"));
956 ASSERT_TRUE(JSExecuteBooleanExpression("$('login-header-bar').hidden"));
958 // Emulates user click on the "Restart and Powerwash" button.
959 ASSERT_EQ(0, fake_session_manager_client()->start_device_wipe_call_count());
960 ASSERT_TRUE(content::ExecuteScript(
961 GetWebContents(),
962 "$('error-message-restart-and-powerwash-button').click();"));
963 ASSERT_EQ(1, fake_session_manager_client()->start_device_wipe_call_count());
966 class WizardControllerProxyAuthOnSigninTest : public WizardControllerTest {
967 protected:
968 WizardControllerProxyAuthOnSigninTest()
969 : proxy_server_(net::SpawnedTestServer::TYPE_BASIC_AUTH_PROXY,
970 net::SpawnedTestServer::kLocalhost,
971 base::FilePath()) {
973 ~WizardControllerProxyAuthOnSigninTest() override {}
975 // Overridden from WizardControllerTest:
976 void SetUp() override {
977 ASSERT_TRUE(proxy_server_.Start());
978 WizardControllerTest::SetUp();
981 void SetUpOnMainThread() override {
982 WizardControllerTest::SetUpOnMainThread();
983 WizardController::default_controller()->AdvanceToScreen(
984 WizardController::kNetworkScreenName);
987 void SetUpCommandLine(base::CommandLine* command_line) override {
988 command_line->AppendSwitchASCII(::switches::kProxyServer,
989 proxy_server_.host_port_pair().ToString());
992 net::SpawnedTestServer& proxy_server() { return proxy_server_; }
994 private:
995 net::SpawnedTestServer proxy_server_;
997 DISALLOW_COPY_AND_ASSIGN(WizardControllerProxyAuthOnSigninTest);
1000 // Disabled, see https://crbug.com/504928.
1001 IN_PROC_BROWSER_TEST_F(WizardControllerProxyAuthOnSigninTest,
1002 DISABLED_ProxyAuthDialogOnSigninScreen) {
1003 content::WindowedNotificationObserver auth_needed_waiter(
1004 chrome::NOTIFICATION_AUTH_NEEDED,
1005 content::NotificationService::AllSources());
1007 CheckCurrentScreen(WizardController::kNetworkScreenName);
1009 LoginDisplayHostImpl::default_host()->StartSignInScreen(LoginScreenContext());
1010 auth_needed_waiter.Wait();
1013 class WizardControllerKioskFlowTest : public WizardControllerFlowTest {
1014 protected:
1015 WizardControllerKioskFlowTest() {}
1017 // Overridden from InProcessBrowserTest:
1018 void SetUpCommandLine(base::CommandLine* command_line) override {
1019 base::FilePath test_data_dir;
1020 ASSERT_TRUE(chromeos::test_utils::GetTestDataPath(
1021 "app_mode", "kiosk_manifest", &test_data_dir));
1022 command_line->AppendSwitchPath(
1023 switches::kAppOemManifestFile,
1024 test_data_dir.AppendASCII("kiosk_manifest.json"));
1027 private:
1028 DISALLOW_COPY_AND_ASSIGN(WizardControllerKioskFlowTest);
1031 IN_PROC_BROWSER_TEST_F(WizardControllerKioskFlowTest,
1032 ControlFlowKioskForcedEnrollment) {
1033 EXPECT_CALL(*mock_enrollment_screen_->actor(),
1034 SetParameters(mock_enrollment_screen_,
1035 EnrollmentModeMatches(
1036 policy::EnrollmentConfig::MODE_LOCAL_FORCED)))
1037 .Times(1);
1038 CheckCurrentScreen(WizardController::kNetworkScreenName);
1039 EXPECT_CALL(*mock_network_screen_, Hide()).Times(1);
1040 EXPECT_CALL(*mock_eula_screen_, Show()).Times(1);
1041 OnExit(*mock_network_screen_, BaseScreenDelegate::NETWORK_CONNECTED);
1043 CheckCurrentScreen(WizardController::kEulaScreenName);
1044 EXPECT_CALL(*mock_eula_screen_, Hide()).Times(1);
1045 EXPECT_CALL(*mock_update_screen_, StartNetworkCheck()).Times(1);
1046 EXPECT_CALL(*mock_update_screen_, Show()).Times(1);
1047 OnExit(*mock_eula_screen_, BaseScreenDelegate::EULA_ACCEPTED);
1049 // Let update screen smooth time process (time = 0ms).
1050 content::RunAllPendingInMessageLoop();
1052 CheckCurrentScreen(WizardController::kUpdateScreenName);
1053 EXPECT_CALL(*mock_update_screen_, Hide()).Times(1);
1054 EXPECT_CALL(*mock_auto_enrollment_check_screen_, Show()).Times(1);
1055 OnExit(*mock_update_screen_, BaseScreenDelegate::UPDATE_INSTALLED);
1057 CheckCurrentScreen(WizardController::kAutoEnrollmentCheckScreenName);
1058 EXPECT_CALL(*mock_auto_enrollment_check_screen_, Hide()).Times(1);
1059 EXPECT_CALL(*mock_enrollment_screen_, Show()).Times(1);
1060 OnExit(*mock_auto_enrollment_check_screen_,
1061 BaseScreenDelegate::ENTERPRISE_AUTO_ENROLLMENT_CHECK_COMPLETED);
1063 EXPECT_FALSE(StartupUtils::IsOobeCompleted());
1065 // Make sure enterprise enrollment page shows up right after update screen.
1066 CheckCurrentScreen(WizardController::kEnrollmentScreenName);
1067 OnExit(*mock_enrollment_screen_,
1068 BaseScreenDelegate::ENTERPRISE_ENROLLMENT_COMPLETED);
1070 EXPECT_TRUE(StartupUtils::IsOobeCompleted());
1073 IN_PROC_BROWSER_TEST_F(WizardControllerKioskFlowTest,
1074 ControlFlowEnrollmentBack) {
1075 EXPECT_CALL(*mock_enrollment_screen_->actor(),
1076 SetParameters(mock_enrollment_screen_,
1077 EnrollmentModeMatches(
1078 policy::EnrollmentConfig::MODE_LOCAL_FORCED)))
1079 .Times(1);
1081 CheckCurrentScreen(WizardController::kNetworkScreenName);
1082 EXPECT_CALL(*mock_network_screen_, Hide()).Times(1);
1083 EXPECT_CALL(*mock_eula_screen_, Show()).Times(1);
1084 OnExit(*mock_network_screen_, BaseScreenDelegate::NETWORK_CONNECTED);
1086 CheckCurrentScreen(WizardController::kEulaScreenName);
1087 EXPECT_CALL(*mock_eula_screen_, Hide()).Times(1);
1088 EXPECT_CALL(*mock_update_screen_, StartNetworkCheck()).Times(1);
1089 EXPECT_CALL(*mock_update_screen_, Show()).Times(1);
1090 OnExit(*mock_eula_screen_, BaseScreenDelegate::EULA_ACCEPTED);
1092 // Let update screen smooth time process (time = 0ms).
1093 content::RunAllPendingInMessageLoop();
1095 CheckCurrentScreen(WizardController::kUpdateScreenName);
1096 EXPECT_CALL(*mock_update_screen_, Hide()).Times(1);
1097 EXPECT_CALL(*mock_auto_enrollment_check_screen_, Show()).Times(1);
1098 OnExit(*mock_update_screen_, BaseScreenDelegate::UPDATE_INSTALLED);
1100 CheckCurrentScreen(WizardController::kAutoEnrollmentCheckScreenName);
1101 EXPECT_CALL(*mock_auto_enrollment_check_screen_, Hide()).Times(1);
1102 EXPECT_CALL(*mock_enrollment_screen_, Show()).Times(1);
1103 EXPECT_CALL(*mock_enrollment_screen_, Hide()).Times(1);
1104 OnExit(*mock_auto_enrollment_check_screen_,
1105 BaseScreenDelegate::ENTERPRISE_AUTO_ENROLLMENT_CHECK_COMPLETED);
1107 EXPECT_FALSE(StartupUtils::IsOobeCompleted());
1109 // Make sure enterprise enrollment page shows up right after update screen.
1110 CheckCurrentScreen(WizardController::kEnrollmentScreenName);
1111 EXPECT_CALL(*mock_auto_enrollment_check_screen_, Show()).Times(1);
1112 OnExit(*mock_enrollment_screen_,
1113 BaseScreenDelegate::ENTERPRISE_ENROLLMENT_BACK);
1115 CheckCurrentScreen(WizardController::kAutoEnrollmentCheckScreenName);
1116 EXPECT_FALSE(StartupUtils::IsOobeCompleted());
1120 class WizardControllerEnableDebuggingTest : public WizardControllerFlowTest {
1121 protected:
1122 WizardControllerEnableDebuggingTest() {}
1124 // Overridden from InProcessBrowserTest:
1125 void SetUpCommandLine(base::CommandLine* command_line) override {
1126 WizardControllerFlowTest::SetUpCommandLine(command_line);
1127 command_line->AppendSwitch(chromeos::switches::kSystemDevMode);
1130 private:
1131 DISALLOW_COPY_AND_ASSIGN(WizardControllerEnableDebuggingTest);
1134 IN_PROC_BROWSER_TEST_F(WizardControllerEnableDebuggingTest,
1135 ShowAndCancelEnableDebugging) {
1136 CheckCurrentScreen(WizardController::kNetworkScreenName);
1137 WaitUntilJSIsReady();
1139 EXPECT_CALL(*mock_network_screen_, Hide()).Times(1);
1140 EXPECT_CALL(*mock_enable_debugging_screen_, Show()).Times(1);
1142 ASSERT_TRUE(JSExecute("$('connect-debugging-features-link').click()"));
1144 // Let update screen smooth time process (time = 0ms).
1145 content::RunAllPendingInMessageLoop();
1147 CheckCurrentScreen(WizardController::kEnableDebuggingScreenName);
1148 EXPECT_CALL(*mock_enable_debugging_screen_, Hide()).Times(1);
1149 EXPECT_CALL(*mock_network_screen_, Show()).Times(1);
1151 OnExit(*mock_enable_debugging_screen_,
1152 BaseScreenDelegate::ENABLE_DEBUGGING_CANCELED);
1154 // Let update screen smooth time process (time = 0ms).
1155 content::RunAllPendingInMessageLoop();
1157 CheckCurrentScreen(WizardController::kNetworkScreenName);
1160 class WizardControllerOobeResumeTest : public WizardControllerTest {
1161 protected:
1162 WizardControllerOobeResumeTest() {}
1163 // Overriden from InProcessBrowserTest:
1164 void SetUpOnMainThread() override {
1165 WizardControllerTest::SetUpOnMainThread();
1167 // Make sure that OOBE is run as an "official" build.
1168 WizardController::default_controller()->is_official_build_ = true;
1170 // Clear portal list (as it is by default in OOBE).
1171 NetworkHandler::Get()->network_state_handler()->SetCheckPortalList("");
1173 // Set up the mocks for all screens.
1174 MOCK_WITH_DELEGATE(mock_network_screen_, kNetworkScreenName,
1175 MockNetworkScreen, MockNetworkView);
1176 MOCK(mock_enrollment_screen_,
1177 kEnrollmentScreenName,
1178 MockEnrollmentScreen,
1179 MockEnrollmentScreenActor);
1182 void OnExit(BaseScreen& screen, BaseScreenDelegate::ExitCodes exit_code) {
1183 WizardController::default_controller()->OnExit(screen, exit_code,
1184 nullptr /* context */);
1187 std::string GetFirstScreenName() {
1188 return WizardController::default_controller()->first_screen_name();
1191 MockOutShowHide<MockNetworkScreen, MockNetworkView>* mock_network_screen_;
1192 MockOutShowHide<MockEnrollmentScreen,
1193 MockEnrollmentScreenActor>* mock_enrollment_screen_;
1195 private:
1196 DISALLOW_COPY_AND_ASSIGN(WizardControllerOobeResumeTest);
1199 IN_PROC_BROWSER_TEST_F(WizardControllerOobeResumeTest,
1200 PRE_ControlFlowResumeInterruptedOobe) {
1201 // Switch to the initial screen.
1202 EXPECT_CALL(*mock_network_screen_, Show()).Times(1);
1203 WizardController::default_controller()->AdvanceToScreen(
1204 WizardController::kNetworkScreenName);
1205 CheckCurrentScreen(WizardController::kNetworkScreenName);
1206 EXPECT_CALL(*mock_enrollment_screen_->actor(),
1207 SetParameters(
1208 mock_enrollment_screen_,
1209 EnrollmentModeMatches(policy::EnrollmentConfig::MODE_MANUAL)))
1210 .Times(1);
1211 EXPECT_CALL(*mock_enrollment_screen_, Show()).Times(1);
1212 EXPECT_CALL(*mock_network_screen_, Hide()).Times(1);
1214 WizardController::default_controller()->AdvanceToScreen(
1215 WizardController::kEnrollmentScreenName);
1216 CheckCurrentScreen(WizardController::kEnrollmentScreenName);
1219 IN_PROC_BROWSER_TEST_F(WizardControllerOobeResumeTest,
1220 ControlFlowResumeInterruptedOobe) {
1221 EXPECT_EQ(WizardController::kEnrollmentScreenName, GetFirstScreenName());
1224 // TODO(dzhioev): Add test emaulating device with wrong HWID.
1226 // TODO(nkostylev): Add test for WebUI accelerators http://crosbug.com/22571
1228 // TODO(merkulova): Add tests for bluetooth HID detection screen variations when
1229 // UI and logic is ready. http://crbug.com/127016
1231 // TODO(dzhioev): Add tests for controller/host pairing flow.
1232 // http://crbug.com/375191
1234 static_assert(BaseScreenDelegate::EXIT_CODES_COUNT == 24,
1235 "tests for new control flow are missing");
1237 } // namespace chromeos