ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / chrome / browser / chromeos / login / wizard_controller_browsertest.cc
blob658a78a6965d947c9ca10b7823379c636485e5e9
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/ui/webui/chromeos/login/oobe_ui.h"
50 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h"
51 #include "chrome/common/chrome_paths.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);
149 // Token writing moves control to BlockingPool and back.
150 content::RunAllBlockingPoolTasksUntilIdle();
152 EXPECT_EQ(data.done, true);
153 EXPECT_EQ(data.result.requested_locale, locale);
154 EXPECT_EQ(data.result.loaded_locale, expected_locale);
155 EXPECT_EQ(data.result.success, expect_success);
158 void SetUpCrasAndEnableChromeVox(int volume_percent, bool mute_on) {
159 AccessibilityManager* a11y = AccessibilityManager::Get();
160 CrasAudioHandler* cras = CrasAudioHandler::Get();
162 // Audio output is at |volume_percent| and |mute_on|. Spoken feedback
163 // is disabled.
164 cras->SetOutputVolumePercent(volume_percent);
165 cras->SetOutputMute(mute_on);
166 a11y->EnableSpokenFeedback(false, ui::A11Y_NOTIFICATION_NONE);
168 // Spoken feedback is enabled.
169 a11y->EnableSpokenFeedback(true, ui::A11Y_NOTIFICATION_NONE);
170 base::RunLoop().RunUntilIdle();
173 void QuitLoopOnAutoEnrollmentProgress(
174 policy::AutoEnrollmentState expected_state,
175 base::RunLoop* loop,
176 policy::AutoEnrollmentState actual_state) {
177 if (expected_state == actual_state)
178 loop->Quit();
181 void WaitForAutoEnrollmentState(policy::AutoEnrollmentState state) {
182 base::RunLoop loop;
183 AutoEnrollmentController* auto_enrollment_controller =
184 LoginDisplayHostImpl::default_host()->GetAutoEnrollmentController();
185 scoped_ptr<AutoEnrollmentController::ProgressCallbackList::Subscription>
186 progress_subscription(
187 auto_enrollment_controller->RegisterProgressCallback(
188 base::Bind(&QuitLoopOnAutoEnrollmentProgress, state, &loop)));
189 loop.Run();
192 } // namespace
194 using ::testing::_;
196 template <class T, class H>
197 class MockOutShowHide : public T {
198 public:
199 template <class P> explicit MockOutShowHide(P p) : T(p) {}
200 template <class P> MockOutShowHide(P p, H* actor)
201 : T(p, actor), actor_(actor) {}
202 template <class P, class Q>
203 MockOutShowHide(P p, Q q, H* actor)
204 : T(p, q, actor), actor_(actor) {}
206 H* actor() const { return actor_.get(); }
208 MOCK_METHOD0(Show, void());
209 MOCK_METHOD0(Hide, void());
211 void RealShow() {
212 T::Show();
215 void RealHide() {
216 T::Hide();
219 private:
220 scoped_ptr<H> actor_;
223 #define MOCK(mock_var, screen_name, mocked_class, actor_class) \
224 mock_var = new MockOutShowHide<mocked_class, actor_class>( \
225 WizardController::default_controller(), new actor_class); \
226 WizardController::default_controller() \
227 ->screens_[WizardController::screen_name] = make_linked_ptr(mock_var); \
228 EXPECT_CALL(*mock_var, Show()).Times(0); \
229 EXPECT_CALL(*mock_var, Hide()).Times(0);
231 #define MOCK_WITH_DELEGATE(mock_var, screen_name, mocked_class, actor_class) \
232 mock_var = new MockOutShowHide<mocked_class, actor_class>( \
233 WizardController::default_controller(), \
234 WizardController::default_controller(), \
235 new actor_class); \
236 WizardController::default_controller() \
237 ->screens_[WizardController::screen_name] = make_linked_ptr(mock_var); \
238 EXPECT_CALL(*mock_var, Show()).Times(0); \
239 EXPECT_CALL(*mock_var, Hide()).Times(0);
241 class WizardControllerTest : public WizardInProcessBrowserTest {
242 protected:
243 WizardControllerTest() : WizardInProcessBrowserTest(
244 WizardController::kTestNoScreenName) {}
245 ~WizardControllerTest() override {}
247 void SetUpOnMainThread() override {
248 AccessibilityManager::Get()->
249 SetProfileForTest(ProfileHelper::GetSigninProfile());
250 WizardInProcessBrowserTest::SetUpOnMainThread();
253 ErrorScreen* GetErrorScreen() {
254 return static_cast<BaseScreenDelegate*>(
255 WizardController::default_controller())->GetErrorScreen();
258 OobeUI* GetOobeUI() {
259 OobeUI* oobe_ui = static_cast<LoginDisplayHostImpl*>(
260 LoginDisplayHostImpl::default_host())->GetOobeUI();
261 return oobe_ui;
264 content::WebContents* GetWebContents() {
265 LoginDisplayHostImpl* host = static_cast<LoginDisplayHostImpl*>(
266 LoginDisplayHostImpl::default_host());
267 if (!host)
268 return NULL;
269 WebUILoginView* webui_login_view = host->GetWebUILoginView();
270 if (!webui_login_view)
271 return NULL;
272 return webui_login_view->GetWebContents();
275 void WaitUntilJSIsReady() {
276 LoginDisplayHostImpl* host = static_cast<LoginDisplayHostImpl*>(
277 LoginDisplayHostImpl::default_host());
278 if (!host)
279 return;
280 chromeos::OobeUI* oobe_ui = host->GetOobeUI();
281 if (!oobe_ui)
282 return;
283 base::RunLoop run_loop;
284 const bool oobe_ui_ready = oobe_ui->IsJSReady(run_loop.QuitClosure());
285 if (!oobe_ui_ready)
286 run_loop.Run();
289 bool JSExecute(const std::string& expression) {
290 return content::ExecuteScript(
291 GetWebContents(),
292 "window.domAutomationController.send(!!(" + expression + "));");
295 bool JSExecuteBooleanExpression(const std::string& expression) {
296 bool result;
297 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
298 GetWebContents(),
299 "window.domAutomationController.send(!!(" + expression + "));",
300 &result));
301 return result;
304 void CheckCurrentScreen(const std::string& screen_name) {
305 EXPECT_EQ(WizardController::default_controller()->GetScreen(screen_name),
306 WizardController::default_controller()->current_screen());
309 private:
310 DISALLOW_COPY_AND_ASSIGN(WizardControllerTest);
313 IN_PROC_BROWSER_TEST_F(WizardControllerTest, SwitchLanguage) {
314 ASSERT_TRUE(WizardController::default_controller() != NULL);
315 WizardController::default_controller()->AdvanceToScreen(
316 WizardController::kNetworkScreenName);
318 // Checking the default locale. Provided that the profile is cleared in SetUp.
319 EXPECT_EQ("en-US", g_browser_process->GetApplicationLocale());
320 EXPECT_STREQ("en", icu::Locale::getDefault().getLanguage());
321 EXPECT_FALSE(base::i18n::IsRTL());
322 const base::string16 en_str =
323 l10n_util::GetStringUTF16(IDS_NETWORK_SELECTION_TITLE);
325 RunSwitchLanguageTest("fr", "fr", true);
326 EXPECT_EQ("fr", g_browser_process->GetApplicationLocale());
327 EXPECT_STREQ("fr", icu::Locale::getDefault().getLanguage());
328 EXPECT_FALSE(base::i18n::IsRTL());
329 const base::string16 fr_str =
330 l10n_util::GetStringUTF16(IDS_NETWORK_SELECTION_TITLE);
332 EXPECT_NE(en_str, fr_str);
334 RunSwitchLanguageTest("ar", "ar", true);
335 EXPECT_EQ("ar", g_browser_process->GetApplicationLocale());
336 EXPECT_STREQ("ar", icu::Locale::getDefault().getLanguage());
337 EXPECT_TRUE(base::i18n::IsRTL());
338 const base::string16 ar_str =
339 l10n_util::GetStringUTF16(IDS_NETWORK_SELECTION_TITLE);
341 EXPECT_NE(fr_str, ar_str);
344 IN_PROC_BROWSER_TEST_F(WizardControllerTest, VolumeIsChangedForChromeVox) {
345 SetUpCrasAndEnableChromeVox(75 /* volume_percent */, true /* mute_on */);
347 // Check that output is unmuted now and at some level.
348 CrasAudioHandler* cras = CrasAudioHandler::Get();
349 ASSERT_FALSE(cras->IsOutputMuted());
350 ASSERT_EQ(WizardController::kMinAudibleOutputVolumePercent,
351 cras->GetOutputVolumePercent());
354 IN_PROC_BROWSER_TEST_F(WizardControllerTest, VolumeIsUnchangedForChromeVox) {
355 SetUpCrasAndEnableChromeVox(75 /* volume_percent */, false /* mute_on */);
357 // Check that output is unmuted now and at some level.
358 CrasAudioHandler* cras = CrasAudioHandler::Get();
359 ASSERT_FALSE(cras->IsOutputMuted());
360 ASSERT_EQ(75, cras->GetOutputVolumePercent());
363 IN_PROC_BROWSER_TEST_F(WizardControllerTest, VolumeIsAdjustedForChromeVox) {
364 SetUpCrasAndEnableChromeVox(5 /* volume_percent */, false /* mute_on */);
366 // Check that output is unmuted now and at some level.
367 CrasAudioHandler* cras = CrasAudioHandler::Get();
368 ASSERT_FALSE(cras->IsOutputMuted());
369 ASSERT_EQ(WizardController::kMinAudibleOutputVolumePercent,
370 cras->GetOutputVolumePercent());
373 class WizardControllerTestURLFetcherFactory
374 : public net::TestURLFetcherFactory {
375 public:
376 net::URLFetcher* CreateURLFetcher(int id,
377 const GURL& url,
378 net::URLFetcher::RequestType request_type,
379 net::URLFetcherDelegate* d) override {
380 if (StartsWithASCII(
381 url.spec(),
382 SimpleGeolocationProvider::DefaultGeolocationProviderURL().spec(),
383 true)) {
384 return new net::FakeURLFetcher(url,
386 std::string(kGeolocationResponseBody),
387 net::HTTP_OK,
388 net::URLRequestStatus::SUCCESS);
390 if (StartsWithASCII(url.spec(),
391 chromeos::DefaultTimezoneProviderURL().spec(),
392 true)) {
393 return new net::FakeURLFetcher(url,
395 std::string(kTimezoneResponseBody),
396 net::HTTP_OK,
397 net::URLRequestStatus::SUCCESS);
399 return net::TestURLFetcherFactory::CreateURLFetcher(
400 id, url, request_type, d);
402 ~WizardControllerTestURLFetcherFactory() override {}
405 class TimeZoneTestRunner {
406 public:
407 void OnResolved() { loop_.Quit(); }
408 void Run() { loop_.Run(); }
410 private:
411 base::RunLoop loop_;
414 class WizardControllerFlowTest : public WizardControllerTest {
415 protected:
416 WizardControllerFlowTest() {}
417 // Overriden from InProcessBrowserTest:
418 void SetUpOnMainThread() override {
419 WizardControllerTest::SetUpOnMainThread();
421 // Make sure that OOBE is run as an "official" build.
422 WizardController* wizard_controller =
423 WizardController::default_controller();
424 wizard_controller->is_official_build_ = true;
426 // Clear portal list (as it is by default in OOBE).
427 NetworkHandler::Get()->network_state_handler()->SetCheckPortalList("");
429 // Set up the mocks for all screens.
430 mock_network_screen_.reset(new MockNetworkScreen(
431 WizardController::default_controller(),
432 WizardController::default_controller(), GetOobeUI()->GetNetworkView()));
433 mock_network_screen_->Initialize(nullptr /* context */);
434 WizardController::default_controller()
435 ->screens_[WizardController::kNetworkScreenName] = mock_network_screen_;
436 EXPECT_CALL(*mock_network_screen_, Show()).Times(0);
437 EXPECT_CALL(*mock_network_screen_, Hide()).Times(0);
439 MOCK(mock_update_screen_, kUpdateScreenName, MockUpdateScreen,
440 MockUpdateView);
441 MOCK_WITH_DELEGATE(mock_eula_screen_, kEulaScreenName, MockEulaScreen,
442 MockEulaView);
443 MOCK(mock_enrollment_screen_,
444 kEnrollmentScreenName,
445 MockEnrollmentScreen,
446 MockEnrollmentScreenActor);
447 MOCK(mock_auto_enrollment_check_screen_,
448 kAutoEnrollmentCheckScreenName,
449 MockAutoEnrollmentCheckScreen,
450 MockAutoEnrollmentCheckScreenActor);
451 MOCK(mock_wrong_hwid_screen_, kWrongHWIDScreenName, MockWrongHWIDScreen,
452 MockWrongHWIDScreenActor);
453 MOCK(mock_enable_debugging_screen_,
454 kEnableDebuggingScreenName,
455 MockEnableDebuggingScreen,
456 MockEnableDebuggingScreenActor);
457 device_disabled_screen_actor_.reset(new MockDeviceDisabledScreenActor);
458 wizard_controller->screens_[WizardController::kDeviceDisabledScreenName] =
459 make_linked_ptr(new DeviceDisabledScreen(
460 wizard_controller,
461 device_disabled_screen_actor_.get()));
462 EXPECT_CALL(*device_disabled_screen_actor_, Show()).Times(0);
464 // Switch to the initial screen.
465 EXPECT_EQ(NULL, wizard_controller->current_screen());
466 EXPECT_CALL(*mock_network_screen_, Show()).Times(1);
467 wizard_controller->AdvanceToScreen(WizardController::kNetworkScreenName);
470 void TearDownOnMainThread() override {
471 mock_network_screen_.reset();
472 device_disabled_screen_actor_.reset();
473 WizardControllerTest::TearDownOnMainThread();
476 void TearDown() override {
477 if (fallback_fetcher_factory_) {
478 fetcher_factory_.reset();
479 net::URLFetcherImpl::set_factory(fallback_fetcher_factory_.get());
480 fallback_fetcher_factory_.reset();
484 void InitTimezoneResolver() {
485 fallback_fetcher_factory_.reset(new WizardControllerTestURLFetcherFactory);
486 net::URLFetcherImpl::set_factory(NULL);
487 fetcher_factory_.reset(
488 new net::FakeURLFetcherFactory(fallback_fetcher_factory_.get()));
490 network_portal_detector_ = new NetworkPortalDetectorTestImpl();
491 NetworkPortalDetector::InitializeForTesting(network_portal_detector_);
493 NetworkPortalDetector::CaptivePortalState online_state;
494 online_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE;
495 online_state.response_code = 204;
497 // Default detworks happens to be usually "eth1" in tests.
498 const NetworkState* default_network =
499 NetworkHandler::Get()->network_state_handler()->DefaultNetwork();
501 network_portal_detector_->SetDefaultNetworkForTesting(
502 default_network->guid());
503 network_portal_detector_->SetDetectionResultsForTesting(
504 default_network->guid(),
505 online_state);
508 void OnExit(BaseScreen& screen, BaseScreenDelegate::ExitCodes exit_code) {
509 WizardController::default_controller()->OnExit(screen, exit_code,
510 nullptr /* context */);
513 chromeos::SimpleGeolocationProvider* GetGeolocationProvider() {
514 return WizardController::default_controller()->geolocation_provider_.get();
517 void WaitUntilTimezoneResolved() {
518 scoped_ptr<TimeZoneTestRunner> runner(new TimeZoneTestRunner);
519 if (!WizardController::default_controller()
520 ->SetOnTimeZoneResolvedForTesting(
521 base::Bind(&TimeZoneTestRunner::OnResolved,
522 base::Unretained(runner.get()))))
523 return;
525 runner->Run();
528 void ResetAutoEnrollmentCheckScreen() {
529 WizardController::default_controller()->screens_.erase(
530 WizardController::kAutoEnrollmentCheckScreenName);
533 linked_ptr<MockNetworkScreen> mock_network_screen_;
534 MockOutShowHide<MockUpdateScreen, MockUpdateView>* mock_update_screen_;
535 MockOutShowHide<MockEulaScreen, MockEulaView>* mock_eula_screen_;
536 MockOutShowHide<MockEnrollmentScreen,
537 MockEnrollmentScreenActor>* mock_enrollment_screen_;
538 MockOutShowHide<MockAutoEnrollmentCheckScreen,
539 MockAutoEnrollmentCheckScreenActor>* mock_auto_enrollment_check_screen_;
540 MockOutShowHide<MockWrongHWIDScreen, MockWrongHWIDScreenActor>*
541 mock_wrong_hwid_screen_;
542 MockOutShowHide<MockEnableDebuggingScreen,
543 MockEnableDebuggingScreenActor>* mock_enable_debugging_screen_;
544 scoped_ptr<MockDeviceDisabledScreenActor> device_disabled_screen_actor_;
546 private:
547 NetworkPortalDetectorTestImpl* network_portal_detector_;
549 // Use a test factory as a fallback so we don't have to deal with other
550 // requests.
551 scoped_ptr<WizardControllerTestURLFetcherFactory> fallback_fetcher_factory_;
552 scoped_ptr<net::FakeURLFetcherFactory> fetcher_factory_;
554 DISALLOW_COPY_AND_ASSIGN(WizardControllerFlowTest);
557 IN_PROC_BROWSER_TEST_F(WizardControllerFlowTest, ControlFlowMain) {
558 CheckCurrentScreen(WizardController::kNetworkScreenName);
560 WaitUntilJSIsReady();
562 // Check visibility of the header bar.
563 ASSERT_FALSE(JSExecuteBooleanExpression("$('login-header-bar').hidden"));
565 EXPECT_CALL(*mock_network_screen_, Hide()).Times(1);
566 EXPECT_CALL(*mock_eula_screen_, Show()).Times(1);
567 OnExit(*mock_network_screen_, BaseScreenDelegate::NETWORK_CONNECTED);
569 CheckCurrentScreen(WizardController::kEulaScreenName);
571 // Header bar should still be visible.
572 ASSERT_FALSE(JSExecuteBooleanExpression("$('login-header-bar').hidden"));
574 EXPECT_CALL(*mock_eula_screen_, Hide()).Times(1);
575 EXPECT_CALL(*mock_update_screen_, StartNetworkCheck()).Times(1);
576 EXPECT_CALL(*mock_update_screen_, Show()).Times(1);
577 // Enable TimeZone resolve
578 InitTimezoneResolver();
579 OnExit(*mock_eula_screen_, BaseScreenDelegate::EULA_ACCEPTED);
580 EXPECT_TRUE(GetGeolocationProvider());
582 // Let update screen smooth time process (time = 0ms).
583 content::RunAllPendingInMessageLoop();
585 CheckCurrentScreen(WizardController::kUpdateScreenName);
586 EXPECT_CALL(*mock_update_screen_, Hide()).Times(1);
587 EXPECT_CALL(*mock_auto_enrollment_check_screen_, Show()).Times(1);
588 OnExit(*mock_update_screen_, BaseScreenDelegate::UPDATE_INSTALLED);
590 CheckCurrentScreen(WizardController::kAutoEnrollmentCheckScreenName);
591 EXPECT_CALL(*mock_auto_enrollment_check_screen_, Hide()).Times(0);
592 EXPECT_CALL(*mock_eula_screen_, Show()).Times(0);
593 OnExit(*mock_auto_enrollment_check_screen_,
594 BaseScreenDelegate::ENTERPRISE_AUTO_ENROLLMENT_CHECK_COMPLETED);
596 EXPECT_FALSE(ExistingUserController::current_controller() == NULL);
597 EXPECT_EQ("ethernet,wifi,cellular",
598 NetworkHandler::Get()->network_state_handler()
599 ->GetCheckPortalListForTest());
601 WaitUntilTimezoneResolved();
602 EXPECT_EQ("America/Anchorage",
603 base::UTF16ToUTF8(chromeos::system::TimezoneSettings::GetInstance()
604 ->GetCurrentTimezoneID()));
607 IN_PROC_BROWSER_TEST_F(WizardControllerFlowTest, ControlFlowErrorUpdate) {
608 CheckCurrentScreen(WizardController::kNetworkScreenName);
609 EXPECT_CALL(*mock_update_screen_, StartNetworkCheck()).Times(0);
610 EXPECT_CALL(*mock_eula_screen_, Show()).Times(1);
611 EXPECT_CALL(*mock_update_screen_, Show()).Times(0);
612 EXPECT_CALL(*mock_network_screen_, Hide()).Times(1);
613 OnExit(*mock_network_screen_, BaseScreenDelegate::NETWORK_CONNECTED);
615 CheckCurrentScreen(WizardController::kEulaScreenName);
616 EXPECT_CALL(*mock_eula_screen_, Hide()).Times(1);
617 EXPECT_CALL(*mock_update_screen_, StartNetworkCheck()).Times(1);
618 EXPECT_CALL(*mock_update_screen_, Show()).Times(1);
619 OnExit(*mock_eula_screen_, BaseScreenDelegate::EULA_ACCEPTED);
621 // Let update screen smooth time process (time = 0ms).
622 content::RunAllPendingInMessageLoop();
624 CheckCurrentScreen(WizardController::kUpdateScreenName);
625 EXPECT_CALL(*mock_update_screen_, Hide()).Times(1);
626 EXPECT_CALL(*mock_auto_enrollment_check_screen_, Show()).Times(1);
627 OnExit(*mock_update_screen_, BaseScreenDelegate::UPDATE_ERROR_UPDATING);
629 CheckCurrentScreen(WizardController::kAutoEnrollmentCheckScreenName);
630 EXPECT_CALL(*mock_auto_enrollment_check_screen_, Hide()).Times(0);
631 EXPECT_CALL(*mock_eula_screen_, Show()).Times(0);
632 OnExit(*mock_auto_enrollment_check_screen_,
633 BaseScreenDelegate::ENTERPRISE_AUTO_ENROLLMENT_CHECK_COMPLETED);
635 EXPECT_FALSE(ExistingUserController::current_controller() == NULL);
638 IN_PROC_BROWSER_TEST_F(WizardControllerFlowTest, ControlFlowSkipUpdateEnroll) {
639 CheckCurrentScreen(WizardController::kNetworkScreenName);
640 EXPECT_CALL(*mock_update_screen_, StartNetworkCheck()).Times(0);
641 EXPECT_CALL(*mock_eula_screen_, Show()).Times(1);
642 EXPECT_CALL(*mock_update_screen_, Show()).Times(0);
643 EXPECT_CALL(*mock_network_screen_, Hide()).Times(1);
644 OnExit(*mock_network_screen_, BaseScreenDelegate::NETWORK_CONNECTED);
646 CheckCurrentScreen(WizardController::kEulaScreenName);
647 EXPECT_CALL(*mock_eula_screen_, Hide()).Times(1);
648 EXPECT_CALL(*mock_update_screen_, StartNetworkCheck()).Times(0);
649 EXPECT_CALL(*mock_update_screen_, Show()).Times(0);
650 WizardController::default_controller()->SkipUpdateEnrollAfterEula();
651 EXPECT_CALL(*mock_enrollment_screen_->actor(),
652 SetParameters(
653 mock_enrollment_screen_,
654 EnrollmentModeMatches(policy::EnrollmentConfig::MODE_MANUAL)))
655 .Times(1);
656 EXPECT_CALL(*mock_auto_enrollment_check_screen_, Show()).Times(1);
657 OnExit(*mock_eula_screen_, BaseScreenDelegate::EULA_ACCEPTED);
658 content::RunAllPendingInMessageLoop();
660 CheckCurrentScreen(WizardController::kAutoEnrollmentCheckScreenName);
661 EXPECT_CALL(*mock_auto_enrollment_check_screen_, Hide()).Times(1);
662 EXPECT_CALL(*mock_enrollment_screen_, Show()).Times(1);
663 EXPECT_CALL(*mock_enrollment_screen_, Hide()).Times(0);
664 OnExit(*mock_auto_enrollment_check_screen_,
665 BaseScreenDelegate::ENTERPRISE_AUTO_ENROLLMENT_CHECK_COMPLETED);
666 content::RunAllPendingInMessageLoop();
668 CheckCurrentScreen(WizardController::kEnrollmentScreenName);
669 EXPECT_EQ("ethernet,wifi,cellular",
670 NetworkHandler::Get()->network_state_handler()
671 ->GetCheckPortalListForTest());
674 IN_PROC_BROWSER_TEST_F(WizardControllerFlowTest, ControlFlowEulaDeclined) {
675 CheckCurrentScreen(WizardController::kNetworkScreenName);
676 EXPECT_CALL(*mock_update_screen_, StartNetworkCheck()).Times(0);
677 EXPECT_CALL(*mock_eula_screen_, Show()).Times(1);
678 EXPECT_CALL(*mock_network_screen_, Hide()).Times(1);
679 OnExit(*mock_network_screen_, BaseScreenDelegate::NETWORK_CONNECTED);
681 CheckCurrentScreen(WizardController::kEulaScreenName);
682 EXPECT_CALL(*mock_eula_screen_, Hide()).Times(1);
683 EXPECT_CALL(*mock_network_screen_, Show()).Times(1);
684 EXPECT_CALL(*mock_network_screen_, Hide()).Times(0); // last transition
685 OnExit(*mock_eula_screen_, BaseScreenDelegate::EULA_BACK);
687 CheckCurrentScreen(WizardController::kNetworkScreenName);
690 IN_PROC_BROWSER_TEST_F(WizardControllerFlowTest,
691 ControlFlowEnrollmentCompleted) {
692 CheckCurrentScreen(WizardController::kNetworkScreenName);
693 EXPECT_CALL(*mock_update_screen_, StartNetworkCheck()).Times(0);
694 EXPECT_CALL(*mock_enrollment_screen_->actor(),
695 SetParameters(
696 mock_enrollment_screen_,
697 EnrollmentModeMatches(policy::EnrollmentConfig::MODE_MANUAL)))
698 .Times(1);
699 EXPECT_CALL(*mock_enrollment_screen_, Show()).Times(1);
700 EXPECT_CALL(*mock_network_screen_, Hide()).Times(1);
702 WizardController::default_controller()->AdvanceToScreen(
703 WizardController::kEnrollmentScreenName);
704 CheckCurrentScreen(WizardController::kEnrollmentScreenName);
705 OnExit(*mock_enrollment_screen_,
706 BaseScreenDelegate::ENTERPRISE_ENROLLMENT_COMPLETED);
708 EXPECT_FALSE(ExistingUserController::current_controller() == NULL);
711 IN_PROC_BROWSER_TEST_F(WizardControllerFlowTest,
712 ControlFlowWrongHWIDScreenFromLogin) {
713 CheckCurrentScreen(WizardController::kNetworkScreenName);
715 LoginDisplayHostImpl::default_host()->StartSignInScreen(LoginScreenContext());
716 EXPECT_FALSE(ExistingUserController::current_controller() == NULL);
717 ExistingUserController::current_controller()->ShowWrongHWIDScreen();
719 CheckCurrentScreen(WizardController::kWrongHWIDScreenName);
721 // After warning is skipped, user returns to sign-in screen.
722 // And this destroys WizardController.
723 OnExit(*mock_wrong_hwid_screen_,
724 BaseScreenDelegate::WRONG_HWID_WARNING_SKIPPED);
725 EXPECT_FALSE(ExistingUserController::current_controller() == NULL);
728 class WizardControllerDeviceStateTest : public WizardControllerFlowTest {
729 protected:
730 WizardControllerDeviceStateTest()
731 : install_attributes_(std::string(),
732 std::string(),
733 std::string(),
734 policy::DEVICE_MODE_NOT_SET) {
735 fake_statistics_provider_.SetMachineStatistic("serial_number", "test");
736 fake_statistics_provider_.SetMachineStatistic(system::kActivateDateKey,
737 "2000-01");
740 void SetUpCommandLine(base::CommandLine* command_line) override {
741 WizardControllerFlowTest::SetUpCommandLine(command_line);
743 command_line->AppendSwitchASCII(
744 switches::kEnterpriseEnableForcedReEnrollment,
745 chromeos::AutoEnrollmentController::kForcedReEnrollmentAlways);
746 command_line->AppendSwitchASCII(
747 switches::kEnterpriseEnrollmentInitialModulus, "1");
748 command_line->AppendSwitchASCII(
749 switches::kEnterpriseEnrollmentModulusLimit, "2");
752 system::ScopedFakeStatisticsProvider fake_statistics_provider_;
754 private:
755 policy::ScopedStubEnterpriseInstallAttributes install_attributes_;
757 DISALLOW_COPY_AND_ASSIGN(WizardControllerDeviceStateTest);
760 IN_PROC_BROWSER_TEST_F(WizardControllerDeviceStateTest,
761 ControlFlowForcedReEnrollment) {
762 CheckCurrentScreen(WizardController::kNetworkScreenName);
763 EXPECT_CALL(*mock_network_screen_, Hide()).Times(1);
764 EXPECT_CALL(*mock_eula_screen_, Show()).Times(1);
765 OnExit(*mock_network_screen_, BaseScreenDelegate::NETWORK_CONNECTED);
767 CheckCurrentScreen(WizardController::kEulaScreenName);
768 EXPECT_CALL(*mock_eula_screen_, Hide()).Times(1);
769 EXPECT_CALL(*mock_update_screen_, StartNetworkCheck()).Times(1);
770 EXPECT_CALL(*mock_update_screen_, Show()).Times(1);
771 OnExit(*mock_eula_screen_, BaseScreenDelegate::EULA_ACCEPTED);
773 // Let update screen smooth time process (time = 0ms).
774 content::RunAllPendingInMessageLoop();
776 CheckCurrentScreen(WizardController::kUpdateScreenName);
777 EXPECT_CALL(*mock_update_screen_, Hide()).Times(1);
778 EXPECT_CALL(*mock_auto_enrollment_check_screen_, Show()).Times(1);
779 OnExit(*mock_update_screen_, BaseScreenDelegate::UPDATE_INSTALLED);
781 CheckCurrentScreen(WizardController::kAutoEnrollmentCheckScreenName);
782 EXPECT_CALL(*mock_auto_enrollment_check_screen_, Hide()).Times(1);
783 mock_auto_enrollment_check_screen_->RealShow();
785 // Wait for auto-enrollment controller to encounter the connection error.
786 WaitForAutoEnrollmentState(policy::AUTO_ENROLLMENT_STATE_CONNECTION_ERROR);
788 // The error screen shows up if there's no auto-enrollment decision.
789 EXPECT_FALSE(StartupUtils::IsOobeCompleted());
790 EXPECT_EQ(GetErrorScreen(),
791 WizardController::default_controller()->current_screen());
792 base::DictionaryValue device_state;
793 device_state.SetString(policy::kDeviceStateRestoreMode,
794 policy::kDeviceStateRestoreModeReEnrollmentEnforced);
795 g_browser_process->local_state()->Set(prefs::kServerBackedDeviceState,
796 device_state);
797 EXPECT_CALL(*mock_enrollment_screen_, Show()).Times(1);
798 EXPECT_CALL(*mock_enrollment_screen_->actor(),
799 SetParameters(mock_enrollment_screen_,
800 EnrollmentModeMatches(
801 policy::EnrollmentConfig::MODE_SERVER_FORCED)))
802 .Times(1);
803 OnExit(*mock_auto_enrollment_check_screen_,
804 BaseScreenDelegate::ENTERPRISE_AUTO_ENROLLMENT_CHECK_COMPLETED);
806 ResetAutoEnrollmentCheckScreen();
808 // Make sure enterprise enrollment page shows up.
809 CheckCurrentScreen(WizardController::kEnrollmentScreenName);
810 OnExit(*mock_enrollment_screen_,
811 BaseScreenDelegate::ENTERPRISE_ENROLLMENT_COMPLETED);
813 EXPECT_TRUE(StartupUtils::IsOobeCompleted());
816 IN_PROC_BROWSER_TEST_F(WizardControllerDeviceStateTest,
817 ControlFlowNoForcedReEnrollmentOnFirstBoot) {
818 fake_statistics_provider_.ClearMachineStatistic(system::kActivateDateKey);
819 EXPECT_NE(policy::AUTO_ENROLLMENT_STATE_NO_ENROLLMENT,
820 LoginDisplayHostImpl::default_host()
821 ->GetAutoEnrollmentController()
822 ->state());
824 CheckCurrentScreen(WizardController::kNetworkScreenName);
825 EXPECT_CALL(*mock_network_screen_, Hide()).Times(1);
826 EXPECT_CALL(*mock_eula_screen_, Show()).Times(1);
827 OnExit(*mock_network_screen_, BaseScreenDelegate::NETWORK_CONNECTED);
829 CheckCurrentScreen(WizardController::kEulaScreenName);
830 EXPECT_CALL(*mock_eula_screen_, Hide()).Times(1);
831 EXPECT_CALL(*mock_update_screen_, StartNetworkCheck()).Times(1);
832 EXPECT_CALL(*mock_update_screen_, Show()).Times(1);
833 OnExit(*mock_eula_screen_, BaseScreenDelegate::EULA_ACCEPTED);
835 // Let update screen smooth time process (time = 0ms).
836 content::RunAllPendingInMessageLoop();
838 CheckCurrentScreen(WizardController::kUpdateScreenName);
839 EXPECT_CALL(*mock_update_screen_, Hide()).Times(1);
840 EXPECT_CALL(*mock_auto_enrollment_check_screen_, Show()).Times(1);
841 OnExit(*mock_update_screen_, BaseScreenDelegate::UPDATE_INSTALLED);
843 CheckCurrentScreen(WizardController::kAutoEnrollmentCheckScreenName);
844 mock_auto_enrollment_check_screen_->RealShow();
845 EXPECT_EQ(policy::AUTO_ENROLLMENT_STATE_NO_ENROLLMENT,
846 LoginDisplayHostImpl::default_host()
847 ->GetAutoEnrollmentController()
848 ->state());
851 IN_PROC_BROWSER_TEST_F(WizardControllerDeviceStateTest,
852 ControlFlowDeviceDisabled) {
853 CheckCurrentScreen(WizardController::kNetworkScreenName);
854 EXPECT_CALL(*mock_network_screen_, Hide()).Times(1);
855 EXPECT_CALL(*mock_eula_screen_, Show()).Times(1);
856 OnExit(*mock_network_screen_, BaseScreenDelegate::NETWORK_CONNECTED);
858 CheckCurrentScreen(WizardController::kEulaScreenName);
859 EXPECT_CALL(*mock_eula_screen_, Hide()).Times(1);
860 EXPECT_CALL(*mock_update_screen_, StartNetworkCheck()).Times(1);
861 EXPECT_CALL(*mock_update_screen_, Show()).Times(1);
862 OnExit(*mock_eula_screen_, BaseScreenDelegate::EULA_ACCEPTED);
864 // Let update screen smooth time process (time = 0ms).
865 content::RunAllPendingInMessageLoop();
867 CheckCurrentScreen(WizardController::kUpdateScreenName);
868 EXPECT_CALL(*mock_update_screen_, Hide()).Times(1);
869 EXPECT_CALL(*mock_auto_enrollment_check_screen_, Show()).Times(1);
870 OnExit(*mock_update_screen_, BaseScreenDelegate::UPDATE_INSTALLED);
872 CheckCurrentScreen(WizardController::kAutoEnrollmentCheckScreenName);
873 EXPECT_CALL(*mock_auto_enrollment_check_screen_, Hide()).Times(1);
874 mock_auto_enrollment_check_screen_->RealShow();
876 // Wait for auto-enrollment controller to encounter the connection error.
877 WaitForAutoEnrollmentState(policy::AUTO_ENROLLMENT_STATE_CONNECTION_ERROR);
879 // The error screen shows up if device state could not be retrieved.
880 EXPECT_FALSE(StartupUtils::IsOobeCompleted());
881 EXPECT_EQ(GetErrorScreen(),
882 WizardController::default_controller()->current_screen());
883 base::DictionaryValue device_state;
884 device_state.SetString(policy::kDeviceStateRestoreMode,
885 policy::kDeviceStateRestoreModeDisabled);
886 device_state.SetString(policy::kDeviceStateDisabledMessage, kDisabledMessage);
887 g_browser_process->local_state()->Set(prefs::kServerBackedDeviceState,
888 device_state);
889 EXPECT_CALL(*device_disabled_screen_actor_,
890 UpdateMessage(kDisabledMessage)).Times(1);
891 EXPECT_CALL(*device_disabled_screen_actor_, Show()).Times(1);
892 OnExit(*mock_auto_enrollment_check_screen_,
893 BaseScreenDelegate::ENTERPRISE_AUTO_ENROLLMENT_CHECK_COMPLETED);
895 ResetAutoEnrollmentCheckScreen();
897 // Make sure the device disabled screen is shown.
898 CheckCurrentScreen(WizardController::kDeviceDisabledScreenName);
900 EXPECT_FALSE(StartupUtils::IsOobeCompleted());
903 class WizardControllerBrokenLocalStateTest : public WizardControllerTest {
904 protected:
905 WizardControllerBrokenLocalStateTest()
906 : fake_session_manager_client_(NULL) {
909 ~WizardControllerBrokenLocalStateTest() override {}
911 void SetUpInProcessBrowserTestFixture() override {
912 WizardControllerTest::SetUpInProcessBrowserTestFixture();
914 fake_session_manager_client_ = new FakeSessionManagerClient;
915 DBusThreadManager::GetSetterForTesting()->SetSessionManagerClient(
916 scoped_ptr<SessionManagerClient>(fake_session_manager_client_));
919 void SetUpOnMainThread() override {
920 base::PrefServiceFactory factory;
921 factory.set_user_prefs(make_scoped_refptr(new PrefStoreStub()));
922 local_state_ = factory.Create(new PrefRegistrySimple()).Pass();
923 WizardController::set_local_state_for_testing(local_state_.get());
925 WizardControllerTest::SetUpOnMainThread();
927 // Make sure that OOBE is run as an "official" build.
928 WizardController::default_controller()->is_official_build_ = true;
931 FakeSessionManagerClient* fake_session_manager_client() const {
932 return fake_session_manager_client_;
935 private:
936 scoped_ptr<PrefService> local_state_;
937 FakeSessionManagerClient* fake_session_manager_client_;
939 DISALLOW_COPY_AND_ASSIGN(WizardControllerBrokenLocalStateTest);
942 IN_PROC_BROWSER_TEST_F(WizardControllerBrokenLocalStateTest,
943 LocalStateCorrupted) {
944 // Checks that after wizard controller initialization error screen
945 // in the proper state is displayed.
946 ASSERT_EQ(GetErrorScreen(),
947 WizardController::default_controller()->current_screen());
948 ASSERT_EQ(NetworkError::UI_STATE_LOCAL_STATE_ERROR,
949 GetErrorScreen()->GetUIState());
951 WaitUntilJSIsReady();
953 // Checks visibility of the error message and powerwash button.
954 ASSERT_FALSE(JSExecuteBooleanExpression("$('error-message').hidden"));
955 ASSERT_TRUE(JSExecuteBooleanExpression(
956 "$('error-message').classList.contains('ui-state-local-state-error')"));
957 ASSERT_TRUE(JSExecuteBooleanExpression("$('progress-dots').hidden"));
958 ASSERT_TRUE(JSExecuteBooleanExpression("$('login-header-bar').hidden"));
960 // Emulates user click on the "Restart and Powerwash" button.
961 ASSERT_EQ(0, fake_session_manager_client()->start_device_wipe_call_count());
962 ASSERT_TRUE(content::ExecuteScript(
963 GetWebContents(),
964 "$('error-message-restart-and-powerwash-button').click();"));
965 ASSERT_EQ(1, fake_session_manager_client()->start_device_wipe_call_count());
968 class WizardControllerProxyAuthOnSigninTest : public WizardControllerTest {
969 protected:
970 WizardControllerProxyAuthOnSigninTest()
971 : proxy_server_(net::SpawnedTestServer::TYPE_BASIC_AUTH_PROXY,
972 net::SpawnedTestServer::kLocalhost,
973 base::FilePath()) {
975 ~WizardControllerProxyAuthOnSigninTest() override {}
977 // Overridden from WizardControllerTest:
978 void SetUp() override {
979 ASSERT_TRUE(proxy_server_.Start());
980 WizardControllerTest::SetUp();
983 void SetUpOnMainThread() override {
984 WizardControllerTest::SetUpOnMainThread();
985 WizardController::default_controller()->AdvanceToScreen(
986 WizardController::kNetworkScreenName);
989 void SetUpCommandLine(base::CommandLine* command_line) override {
990 command_line->AppendSwitchASCII(::switches::kProxyServer,
991 proxy_server_.host_port_pair().ToString());
994 net::SpawnedTestServer& proxy_server() { return proxy_server_; }
996 private:
997 net::SpawnedTestServer proxy_server_;
999 DISALLOW_COPY_AND_ASSIGN(WizardControllerProxyAuthOnSigninTest);
1002 IN_PROC_BROWSER_TEST_F(WizardControllerProxyAuthOnSigninTest,
1003 ProxyAuthDialogOnSigninScreen) {
1004 content::WindowedNotificationObserver auth_needed_waiter(
1005 chrome::NOTIFICATION_AUTH_NEEDED,
1006 content::NotificationService::AllSources());
1008 CheckCurrentScreen(WizardController::kNetworkScreenName);
1010 LoginDisplayHostImpl::default_host()->StartSignInScreen(LoginScreenContext());
1011 auth_needed_waiter.Wait();
1014 class WizardControllerKioskFlowTest : public WizardControllerFlowTest {
1015 protected:
1016 WizardControllerKioskFlowTest() {}
1018 // Overridden from InProcessBrowserTest:
1019 void SetUpCommandLine(base::CommandLine* command_line) override {
1020 base::FilePath test_data_dir;
1021 ASSERT_TRUE(chromeos::test_utils::GetTestDataPath(
1022 "app_mode", "kiosk_manifest", &test_data_dir));
1023 command_line->AppendSwitchPath(
1024 switches::kAppOemManifestFile,
1025 test_data_dir.AppendASCII("kiosk_manifest.json"));
1028 private:
1029 DISALLOW_COPY_AND_ASSIGN(WizardControllerKioskFlowTest);
1032 IN_PROC_BROWSER_TEST_F(WizardControllerKioskFlowTest,
1033 ControlFlowKioskForcedEnrollment) {
1034 EXPECT_CALL(*mock_enrollment_screen_->actor(),
1035 SetParameters(mock_enrollment_screen_,
1036 EnrollmentModeMatches(
1037 policy::EnrollmentConfig::MODE_LOCAL_FORCED)))
1038 .Times(1);
1039 CheckCurrentScreen(WizardController::kNetworkScreenName);
1040 EXPECT_CALL(*mock_network_screen_, Hide()).Times(1);
1041 EXPECT_CALL(*mock_eula_screen_, Show()).Times(1);
1042 OnExit(*mock_network_screen_, BaseScreenDelegate::NETWORK_CONNECTED);
1044 CheckCurrentScreen(WizardController::kEulaScreenName);
1045 EXPECT_CALL(*mock_eula_screen_, Hide()).Times(1);
1046 EXPECT_CALL(*mock_update_screen_, StartNetworkCheck()).Times(1);
1047 EXPECT_CALL(*mock_update_screen_, Show()).Times(1);
1048 OnExit(*mock_eula_screen_, BaseScreenDelegate::EULA_ACCEPTED);
1050 // Let update screen smooth time process (time = 0ms).
1051 content::RunAllPendingInMessageLoop();
1053 CheckCurrentScreen(WizardController::kUpdateScreenName);
1054 EXPECT_CALL(*mock_update_screen_, Hide()).Times(1);
1055 EXPECT_CALL(*mock_auto_enrollment_check_screen_, Show()).Times(1);
1056 OnExit(*mock_update_screen_, BaseScreenDelegate::UPDATE_INSTALLED);
1058 CheckCurrentScreen(WizardController::kAutoEnrollmentCheckScreenName);
1059 EXPECT_CALL(*mock_auto_enrollment_check_screen_, Hide()).Times(1);
1060 EXPECT_CALL(*mock_enrollment_screen_, Show()).Times(1);
1061 OnExit(*mock_auto_enrollment_check_screen_,
1062 BaseScreenDelegate::ENTERPRISE_AUTO_ENROLLMENT_CHECK_COMPLETED);
1064 EXPECT_FALSE(StartupUtils::IsOobeCompleted());
1066 // Make sure enterprise enrollment page shows up right after update screen.
1067 CheckCurrentScreen(WizardController::kEnrollmentScreenName);
1068 OnExit(*mock_enrollment_screen_,
1069 BaseScreenDelegate::ENTERPRISE_ENROLLMENT_COMPLETED);
1071 EXPECT_TRUE(StartupUtils::IsOobeCompleted());
1074 IN_PROC_BROWSER_TEST_F(WizardControllerKioskFlowTest,
1075 ControlFlowEnrollmentBack) {
1076 EXPECT_CALL(*mock_enrollment_screen_->actor(),
1077 SetParameters(mock_enrollment_screen_,
1078 EnrollmentModeMatches(
1079 policy::EnrollmentConfig::MODE_LOCAL_FORCED)))
1080 .Times(1);
1082 CheckCurrentScreen(WizardController::kNetworkScreenName);
1083 EXPECT_CALL(*mock_network_screen_, Hide()).Times(1);
1084 EXPECT_CALL(*mock_eula_screen_, Show()).Times(1);
1085 OnExit(*mock_network_screen_, BaseScreenDelegate::NETWORK_CONNECTED);
1087 CheckCurrentScreen(WizardController::kEulaScreenName);
1088 EXPECT_CALL(*mock_eula_screen_, Hide()).Times(1);
1089 EXPECT_CALL(*mock_update_screen_, StartNetworkCheck()).Times(1);
1090 EXPECT_CALL(*mock_update_screen_, Show()).Times(1);
1091 OnExit(*mock_eula_screen_, BaseScreenDelegate::EULA_ACCEPTED);
1093 // Let update screen smooth time process (time = 0ms).
1094 content::RunAllPendingInMessageLoop();
1096 CheckCurrentScreen(WizardController::kUpdateScreenName);
1097 EXPECT_CALL(*mock_update_screen_, Hide()).Times(1);
1098 EXPECT_CALL(*mock_auto_enrollment_check_screen_, Show()).Times(1);
1099 OnExit(*mock_update_screen_, BaseScreenDelegate::UPDATE_INSTALLED);
1101 CheckCurrentScreen(WizardController::kAutoEnrollmentCheckScreenName);
1102 EXPECT_CALL(*mock_auto_enrollment_check_screen_, Hide()).Times(1);
1103 EXPECT_CALL(*mock_enrollment_screen_, Show()).Times(1);
1104 EXPECT_CALL(*mock_enrollment_screen_, Hide()).Times(1);
1105 OnExit(*mock_auto_enrollment_check_screen_,
1106 BaseScreenDelegate::ENTERPRISE_AUTO_ENROLLMENT_CHECK_COMPLETED);
1108 EXPECT_FALSE(StartupUtils::IsOobeCompleted());
1110 // Make sure enterprise enrollment page shows up right after update screen.
1111 CheckCurrentScreen(WizardController::kEnrollmentScreenName);
1112 EXPECT_CALL(*mock_auto_enrollment_check_screen_, Show()).Times(1);
1113 OnExit(*mock_enrollment_screen_,
1114 BaseScreenDelegate::ENTERPRISE_ENROLLMENT_BACK);
1116 CheckCurrentScreen(WizardController::kAutoEnrollmentCheckScreenName);
1117 EXPECT_FALSE(StartupUtils::IsOobeCompleted());
1121 class WizardControllerEnableDebuggingTest : public WizardControllerFlowTest {
1122 protected:
1123 WizardControllerEnableDebuggingTest() {}
1125 // Overridden from InProcessBrowserTest:
1126 void SetUpCommandLine(base::CommandLine* command_line) override {
1127 WizardControllerFlowTest::SetUpCommandLine(command_line);
1128 command_line->AppendSwitch(chromeos::switches::kSystemDevMode);
1131 private:
1132 DISALLOW_COPY_AND_ASSIGN(WizardControllerEnableDebuggingTest);
1135 IN_PROC_BROWSER_TEST_F(WizardControllerEnableDebuggingTest,
1136 ShowAndCancelEnableDebugging) {
1137 CheckCurrentScreen(WizardController::kNetworkScreenName);
1138 WaitUntilJSIsReady();
1140 EXPECT_CALL(*mock_network_screen_, Hide()).Times(1);
1141 EXPECT_CALL(*mock_enable_debugging_screen_, Show()).Times(1);
1143 ASSERT_TRUE(JSExecute("$('connect-debugging-features-link').click()"));
1145 // Let update screen smooth time process (time = 0ms).
1146 content::RunAllPendingInMessageLoop();
1148 CheckCurrentScreen(WizardController::kEnableDebuggingScreenName);
1149 EXPECT_CALL(*mock_enable_debugging_screen_, Hide()).Times(1);
1150 EXPECT_CALL(*mock_network_screen_, Show()).Times(1);
1152 OnExit(*mock_enable_debugging_screen_,
1153 BaseScreenDelegate::ENABLE_DEBUGGING_CANCELED);
1155 // Let update screen smooth time process (time = 0ms).
1156 content::RunAllPendingInMessageLoop();
1158 CheckCurrentScreen(WizardController::kNetworkScreenName);
1161 class WizardControllerOobeResumeTest : public WizardControllerTest {
1162 protected:
1163 WizardControllerOobeResumeTest() {}
1164 // Overriden from InProcessBrowserTest:
1165 void SetUpOnMainThread() override {
1166 WizardControllerTest::SetUpOnMainThread();
1168 // Make sure that OOBE is run as an "official" build.
1169 WizardController::default_controller()->is_official_build_ = true;
1171 // Clear portal list (as it is by default in OOBE).
1172 NetworkHandler::Get()->network_state_handler()->SetCheckPortalList("");
1174 // Set up the mocks for all screens.
1175 MOCK_WITH_DELEGATE(mock_network_screen_, kNetworkScreenName,
1176 MockNetworkScreen, MockNetworkView);
1177 MOCK(mock_enrollment_screen_,
1178 kEnrollmentScreenName,
1179 MockEnrollmentScreen,
1180 MockEnrollmentScreenActor);
1183 void OnExit(BaseScreen& screen, BaseScreenDelegate::ExitCodes exit_code) {
1184 WizardController::default_controller()->OnExit(screen, exit_code,
1185 nullptr /* context */);
1188 std::string GetFirstScreenName() {
1189 return WizardController::default_controller()->first_screen_name();
1192 MockOutShowHide<MockNetworkScreen, MockNetworkView>* mock_network_screen_;
1193 MockOutShowHide<MockEnrollmentScreen,
1194 MockEnrollmentScreenActor>* mock_enrollment_screen_;
1196 private:
1197 DISALLOW_COPY_AND_ASSIGN(WizardControllerOobeResumeTest);
1200 IN_PROC_BROWSER_TEST_F(WizardControllerOobeResumeTest,
1201 PRE_ControlFlowResumeInterruptedOobe) {
1202 // Switch to the initial screen.
1203 EXPECT_CALL(*mock_network_screen_, Show()).Times(1);
1204 WizardController::default_controller()->AdvanceToScreen(
1205 WizardController::kNetworkScreenName);
1206 CheckCurrentScreen(WizardController::kNetworkScreenName);
1207 EXPECT_CALL(*mock_enrollment_screen_->actor(),
1208 SetParameters(
1209 mock_enrollment_screen_,
1210 EnrollmentModeMatches(policy::EnrollmentConfig::MODE_MANUAL)))
1211 .Times(1);
1212 EXPECT_CALL(*mock_enrollment_screen_, Show()).Times(1);
1213 EXPECT_CALL(*mock_network_screen_, Hide()).Times(1);
1215 WizardController::default_controller()->AdvanceToScreen(
1216 WizardController::kEnrollmentScreenName);
1217 CheckCurrentScreen(WizardController::kEnrollmentScreenName);
1220 IN_PROC_BROWSER_TEST_F(WizardControllerOobeResumeTest,
1221 ControlFlowResumeInterruptedOobe) {
1222 EXPECT_EQ(WizardController::kEnrollmentScreenName, GetFirstScreenName());
1225 // TODO(dzhioev): Add test emaulating device with wrong HWID.
1227 // TODO(nkostylev): Add test for WebUI accelerators http://crosbug.com/22571
1229 // TODO(merkulova): Add tests for bluetooth HID detection screen variations when
1230 // UI and logic is ready. http://crbug.com/127016
1232 // TODO(dzhioev): Add tests for controller/host pairing flow.
1233 // http://crbug.com/375191
1235 static_assert(BaseScreenDelegate::EXIT_CODES_COUNT == 24,
1236 "tests for new control flow are missing");
1238 } // namespace chromeos