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/json/json_file_value_serializer.h"
11 #include "base/path_service.h"
12 #include "base/prefs/pref_registry_simple.h"
13 #include "base/prefs/pref_service.h"
14 #include "base/prefs/pref_service_factory.h"
15 #include "base/prefs/testing_pref_store.h"
16 #include "base/run_loop.h"
17 #include "base/strings/string_util.h"
18 #include "base/strings/utf_string_conversions.h"
19 #include "chrome/browser/browser_process.h"
20 #include "chrome/browser/browser_shutdown.h"
21 #include "chrome/browser/chrome_notification_types.h"
22 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
23 #include "chrome/browser/chromeos/base/locale_util.h"
24 #include "chrome/browser/chromeos/login/enrollment/enrollment_screen.h"
25 #include "chrome/browser/chromeos/login/enrollment/enterprise_enrollment_helper.h"
26 #include "chrome/browser/chromeos/login/enrollment/mock_auto_enrollment_check_screen.h"
27 #include "chrome/browser/chromeos/login/enrollment/mock_enrollment_screen.h"
28 #include "chrome/browser/chromeos/login/existing_user_controller.h"
29 #include "chrome/browser/chromeos/login/screens/device_disabled_screen.h"
30 #include "chrome/browser/chromeos/login/screens/error_screen.h"
31 #include "chrome/browser/chromeos/login/screens/hid_detection_screen.h"
32 #include "chrome/browser/chromeos/login/screens/mock_device_disabled_screen_actor.h"
33 #include "chrome/browser/chromeos/login/screens/mock_enable_debugging_screen.h"
34 #include "chrome/browser/chromeos/login/screens/mock_eula_screen.h"
35 #include "chrome/browser/chromeos/login/screens/mock_network_screen.h"
36 #include "chrome/browser/chromeos/login/screens/mock_update_screen.h"
37 #include "chrome/browser/chromeos/login/screens/mock_wrong_hwid_screen.h"
38 #include "chrome/browser/chromeos/login/screens/network_screen.h"
39 #include "chrome/browser/chromeos/login/screens/reset_screen.h"
40 #include "chrome/browser/chromeos/login/screens/user_image_screen.h"
41 #include "chrome/browser/chromeos/login/screens/wrong_hwid_screen.h"
42 #include "chrome/browser/chromeos/login/startup_utils.h"
43 #include "chrome/browser/chromeos/login/test/wizard_in_process_browser_test.h"
44 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h"
45 #include "chrome/browser/chromeos/login/ui/webui_login_view.h"
46 #include "chrome/browser/chromeos/net/network_portal_detector_test_impl.h"
47 #include "chrome/browser/chromeos/policy/enrollment_config.h"
48 #include "chrome/browser/chromeos/policy/server_backed_device_state.h"
49 #include "chrome/browser/chromeos/policy/stub_enterprise_install_attributes.h"
50 #include "chrome/browser/chromeos/profiles/profile_helper.h"
51 #include "chrome/browser/profiles/profile_manager.h"
52 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h"
53 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h"
54 #include "chrome/common/chrome_constants.h"
55 #include "chrome/common/chrome_paths.h"
56 #include "chrome/common/chrome_switches.h"
57 #include "chrome/common/pref_names.h"
58 #include "chrome/grit/generated_resources.h"
59 #include "chromeos/audio/cras_audio_handler.h"
60 #include "chromeos/chromeos_switches.h"
61 #include "chromeos/chromeos_test_utils.h"
62 #include "chromeos/dbus/dbus_thread_manager.h"
63 #include "chromeos/dbus/fake_session_manager_client.h"
64 #include "chromeos/geolocation/simple_geolocation_provider.h"
65 #include "chromeos/network/network_state.h"
66 #include "chromeos/network/network_state_handler.h"
67 #include "chromeos/settings/timezone_settings.h"
68 #include "chromeos/system/fake_statistics_provider.h"
69 #include "chromeos/system/statistics_provider.h"
70 #include "chromeos/timezone/timezone_request.h"
71 #include "components/policy/core/common/cloud/cloud_policy_constants.h"
72 #include "content/public/test/browser_test_utils.h"
73 #include "content/public/test/test_utils.h"
74 #include "net/test/spawned_test_server/spawned_test_server.h"
75 #include "net/url_request/test_url_fetcher_factory.h"
76 #include "net/url_request/url_fetcher_impl.h"
77 #include "testing/gmock/include/gmock/gmock.h"
78 #include "testing/gtest/include/gtest/gtest.h"
79 #include "third_party/icu/source/common/unicode/locid.h"
80 #include "ui/base/accelerators/accelerator.h"
81 #include "ui/base/l10n/l10n_util.h"
83 using ::testing::Exactly
;
84 using ::testing::Invoke
;
85 using ::testing::Mock
;
86 using ::testing::Return
;
92 const char kGeolocationResponseBody
[] =
98 " \"accuracy\": 1200.4\n"
101 // Timezone should not match kGeolocationResponseBody to check that exactly
102 // this value will be used.
103 const char kTimezoneResponseBody
[] =
105 " \"dstOffset\" : 0.0,\n"
106 " \"rawOffset\" : -32400.0,\n"
107 " \"status\" : \"OK\",\n"
108 " \"timeZoneId\" : \"America/Anchorage\",\n"
109 " \"timeZoneName\" : \"Pacific Standard Time\"\n"
112 const char kDisabledMessage
[] = "This device has been disabled.";
114 // Matches on the mode parameter of an EnrollmentConfig object.
115 MATCHER_P(EnrollmentModeMatches
, mode
, "") {
116 return arg
.mode
== mode
;
119 class PrefStoreStub
: public TestingPrefStore
{
121 // TestingPrefStore overrides:
122 PrefReadError
GetReadError() const override
{
123 return PersistentPrefStore::PREF_READ_ERROR_JSON_PARSE
;
126 bool IsInitializationComplete() const override
{ return true; }
129 ~PrefStoreStub() override
{}
132 struct SwitchLanguageTestData
{
133 SwitchLanguageTestData() : result("", "", false), done(false) {}
135 locale_util::LanguageSwitchResult result
;
139 void OnLocaleSwitched(SwitchLanguageTestData
* self
,
140 const locale_util::LanguageSwitchResult
& result
) {
141 self
->result
= result
;
145 void RunSwitchLanguageTest(const std::string
& locale
,
146 const std::string
& expected_locale
,
147 const bool expect_success
) {
148 SwitchLanguageTestData data
;
149 locale_util::SwitchLanguageCallback
callback(
150 base::Bind(&OnLocaleSwitched
, base::Unretained(&data
)));
151 locale_util::SwitchLanguage(locale
, true, false, callback
,
152 ProfileManager::GetActiveUserProfile());
154 // Token writing moves control to BlockingPool and back.
155 content::RunAllBlockingPoolTasksUntilIdle();
157 EXPECT_EQ(data
.done
, true);
158 EXPECT_EQ(data
.result
.requested_locale
, locale
);
159 EXPECT_EQ(data
.result
.loaded_locale
, expected_locale
);
160 EXPECT_EQ(data
.result
.success
, expect_success
);
163 void SetUpCrasAndEnableChromeVox(int volume_percent
, bool mute_on
) {
164 AccessibilityManager
* a11y
= AccessibilityManager::Get();
165 CrasAudioHandler
* cras
= CrasAudioHandler::Get();
167 // Audio output is at |volume_percent| and |mute_on|. Spoken feedback
169 cras
->SetOutputVolumePercent(volume_percent
);
170 cras
->SetOutputMute(mute_on
);
171 a11y
->EnableSpokenFeedback(false, ui::A11Y_NOTIFICATION_NONE
);
173 // Spoken feedback is enabled.
174 a11y
->EnableSpokenFeedback(true, ui::A11Y_NOTIFICATION_NONE
);
175 base::RunLoop().RunUntilIdle();
178 void QuitLoopOnAutoEnrollmentProgress(
179 policy::AutoEnrollmentState expected_state
,
181 policy::AutoEnrollmentState actual_state
) {
182 if (expected_state
== actual_state
)
186 void WaitForAutoEnrollmentState(policy::AutoEnrollmentState state
) {
188 AutoEnrollmentController
* auto_enrollment_controller
=
189 LoginDisplayHostImpl::default_host()->GetAutoEnrollmentController();
190 scoped_ptr
<AutoEnrollmentController::ProgressCallbackList::Subscription
>
191 progress_subscription(
192 auto_enrollment_controller
->RegisterProgressCallback(
193 base::Bind(&QuitLoopOnAutoEnrollmentProgress
, state
, &loop
)));
201 template <class T
, class H
>
202 class MockOutShowHide
: public T
{
204 template <class P
> explicit MockOutShowHide(P p
) : T(p
) {}
205 template <class P
> MockOutShowHide(P p
, H
* actor
)
206 : T(p
, actor
), actor_(actor
) {}
207 template <class P
, class Q
>
208 MockOutShowHide(P p
, Q q
, H
* actor
)
209 : T(p
, q
, actor
), actor_(actor
) {}
211 H
* actor() const { return actor_
.get(); }
213 MOCK_METHOD0(Show
, void());
214 MOCK_METHOD0(Hide
, void());
225 scoped_ptr
<H
> actor_
;
228 #define MOCK(mock_var, screen_name, mocked_class, actor_class) \
229 mock_var = new MockOutShowHide<mocked_class, actor_class>( \
230 WizardController::default_controller(), new actor_class); \
231 WizardController::default_controller() \
232 ->screens_[WizardController::screen_name] = make_linked_ptr(mock_var); \
233 EXPECT_CALL(*mock_var, Show()).Times(0); \
234 EXPECT_CALL(*mock_var, Hide()).Times(0);
236 #define MOCK_WITH_DELEGATE(mock_var, screen_name, mocked_class, actor_class) \
237 mock_var = new MockOutShowHide<mocked_class, actor_class>( \
238 WizardController::default_controller(), \
239 WizardController::default_controller(), \
241 WizardController::default_controller() \
242 ->screens_[WizardController::screen_name] = make_linked_ptr(mock_var); \
243 EXPECT_CALL(*mock_var, Show()).Times(0); \
244 EXPECT_CALL(*mock_var, Hide()).Times(0);
246 class WizardControllerTest
: public WizardInProcessBrowserTest
{
248 WizardControllerTest() : WizardInProcessBrowserTest(
249 WizardController::kTestNoScreenName
) {}
250 ~WizardControllerTest() override
{}
252 void SetUpOnMainThread() override
{
253 AccessibilityManager::Get()->
254 SetProfileForTest(ProfileHelper::GetSigninProfile());
255 WizardInProcessBrowserTest::SetUpOnMainThread();
258 ErrorScreen
* GetErrorScreen() {
259 return static_cast<BaseScreenDelegate
*>(
260 WizardController::default_controller())->GetErrorScreen();
263 OobeUI
* GetOobeUI() {
264 OobeUI
* oobe_ui
= static_cast<LoginDisplayHostImpl
*>(
265 LoginDisplayHostImpl::default_host())->GetOobeUI();
269 content::WebContents
* GetWebContents() {
270 LoginDisplayHostImpl
* host
= static_cast<LoginDisplayHostImpl
*>(
271 LoginDisplayHostImpl::default_host());
274 WebUILoginView
* webui_login_view
= host
->GetWebUILoginView();
275 if (!webui_login_view
)
277 return webui_login_view
->GetWebContents();
280 void WaitUntilJSIsReady() {
281 LoginDisplayHostImpl
* host
= static_cast<LoginDisplayHostImpl
*>(
282 LoginDisplayHostImpl::default_host());
285 chromeos::OobeUI
* oobe_ui
= host
->GetOobeUI();
288 base::RunLoop run_loop
;
289 const bool oobe_ui_ready
= oobe_ui
->IsJSReady(run_loop
.QuitClosure());
294 bool JSExecute(const std::string
& expression
) {
295 return content::ExecuteScript(
297 "window.domAutomationController.send(!!(" + expression
+ "));");
300 bool JSExecuteBooleanExpression(const std::string
& expression
) {
302 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
304 "window.domAutomationController.send(!!(" + expression
+ "));",
309 void CheckCurrentScreen(const std::string
& screen_name
) {
310 EXPECT_EQ(WizardController::default_controller()->GetScreen(screen_name
),
311 WizardController::default_controller()->current_screen());
315 DISALLOW_COPY_AND_ASSIGN(WizardControllerTest
);
318 IN_PROC_BROWSER_TEST_F(WizardControllerTest
, SwitchLanguage
) {
319 ASSERT_TRUE(WizardController::default_controller() != NULL
);
320 WizardController::default_controller()->AdvanceToScreen(
321 WizardController::kNetworkScreenName
);
323 // Checking the default locale. Provided that the profile is cleared in SetUp.
324 EXPECT_EQ("en-US", g_browser_process
->GetApplicationLocale());
325 EXPECT_STREQ("en", icu::Locale::getDefault().getLanguage());
326 EXPECT_FALSE(base::i18n::IsRTL());
327 const base::string16 en_str
=
328 l10n_util::GetStringUTF16(IDS_NETWORK_SELECTION_TITLE
);
330 RunSwitchLanguageTest("fr", "fr", true);
331 EXPECT_EQ("fr", g_browser_process
->GetApplicationLocale());
332 EXPECT_STREQ("fr", icu::Locale::getDefault().getLanguage());
333 EXPECT_FALSE(base::i18n::IsRTL());
334 const base::string16 fr_str
=
335 l10n_util::GetStringUTF16(IDS_NETWORK_SELECTION_TITLE
);
337 EXPECT_NE(en_str
, fr_str
);
339 RunSwitchLanguageTest("ar", "ar", true);
340 EXPECT_EQ("ar", g_browser_process
->GetApplicationLocale());
341 EXPECT_STREQ("ar", icu::Locale::getDefault().getLanguage());
342 EXPECT_TRUE(base::i18n::IsRTL());
343 const base::string16 ar_str
=
344 l10n_util::GetStringUTF16(IDS_NETWORK_SELECTION_TITLE
);
346 EXPECT_NE(fr_str
, ar_str
);
349 IN_PROC_BROWSER_TEST_F(WizardControllerTest
, VolumeIsChangedForChromeVox
) {
350 SetUpCrasAndEnableChromeVox(75 /* volume_percent */, true /* mute_on */);
352 // Check that output is unmuted now and at some level.
353 CrasAudioHandler
* cras
= CrasAudioHandler::Get();
354 ASSERT_FALSE(cras
->IsOutputMuted());
355 ASSERT_EQ(WizardController::kMinAudibleOutputVolumePercent
,
356 cras
->GetOutputVolumePercent());
359 IN_PROC_BROWSER_TEST_F(WizardControllerTest
, VolumeIsUnchangedForChromeVox
) {
360 SetUpCrasAndEnableChromeVox(75 /* volume_percent */, false /* mute_on */);
362 // Check that output is unmuted now and at some level.
363 CrasAudioHandler
* cras
= CrasAudioHandler::Get();
364 ASSERT_FALSE(cras
->IsOutputMuted());
365 ASSERT_EQ(75, cras
->GetOutputVolumePercent());
368 IN_PROC_BROWSER_TEST_F(WizardControllerTest
, VolumeIsAdjustedForChromeVox
) {
369 SetUpCrasAndEnableChromeVox(5 /* volume_percent */, false /* mute_on */);
371 // Check that output is unmuted now and at some level.
372 CrasAudioHandler
* cras
= CrasAudioHandler::Get();
373 ASSERT_FALSE(cras
->IsOutputMuted());
374 ASSERT_EQ(WizardController::kMinAudibleOutputVolumePercent
,
375 cras
->GetOutputVolumePercent());
378 class WizardControllerTestURLFetcherFactory
379 : public net::TestURLFetcherFactory
{
381 scoped_ptr
<net::URLFetcher
> CreateURLFetcher(
384 net::URLFetcher::RequestType request_type
,
385 net::URLFetcherDelegate
* d
) override
{
386 if (base::StartsWith(
388 SimpleGeolocationProvider::DefaultGeolocationProviderURL().spec(),
389 base::CompareCase::SENSITIVE
)) {
390 return scoped_ptr
<net::URLFetcher
>(new net::FakeURLFetcher(
391 url
, d
, std::string(kGeolocationResponseBody
), net::HTTP_OK
,
392 net::URLRequestStatus::SUCCESS
));
394 if (base::StartsWith(url
.spec(),
395 chromeos::DefaultTimezoneProviderURL().spec(),
396 base::CompareCase::SENSITIVE
)) {
397 return scoped_ptr
<net::URLFetcher
>(new net::FakeURLFetcher(
398 url
, d
, std::string(kTimezoneResponseBody
), net::HTTP_OK
,
399 net::URLRequestStatus::SUCCESS
));
401 return net::TestURLFetcherFactory::CreateURLFetcher(
402 id
, url
, request_type
, d
);
404 ~WizardControllerTestURLFetcherFactory() override
{}
407 class TimeZoneTestRunner
{
409 void OnResolved() { loop_
.Quit(); }
410 void Run() { loop_
.Run(); }
416 class WizardControllerFlowTest
: public WizardControllerTest
{
418 WizardControllerFlowTest() {}
419 // Overriden from InProcessBrowserTest:
420 void SetUpOnMainThread() override
{
421 WizardControllerTest::SetUpOnMainThread();
423 // Make sure that OOBE is run as an "official" build.
424 WizardController
* wizard_controller
=
425 WizardController::default_controller();
426 wizard_controller
->is_official_build_
= true;
428 // Clear portal list (as it is by default in OOBE).
429 NetworkHandler::Get()->network_state_handler()->SetCheckPortalList("");
431 // Set up the mocks for all screens.
432 mock_network_screen_
.reset(new MockNetworkScreen(
433 WizardController::default_controller(),
434 WizardController::default_controller(), GetOobeUI()->GetNetworkView()));
435 mock_network_screen_
->Initialize(nullptr /* context */);
436 WizardController::default_controller()
437 ->screens_
[WizardController::kNetworkScreenName
] = mock_network_screen_
;
438 EXPECT_CALL(*mock_network_screen_
, Show()).Times(0);
439 EXPECT_CALL(*mock_network_screen_
, Hide()).Times(0);
441 MOCK(mock_update_screen_
, kUpdateScreenName
, MockUpdateScreen
,
443 MOCK_WITH_DELEGATE(mock_eula_screen_
, kEulaScreenName
, MockEulaScreen
,
445 MOCK(mock_enrollment_screen_
,
446 kEnrollmentScreenName
,
447 MockEnrollmentScreen
,
448 MockEnrollmentScreenActor
);
449 MOCK(mock_auto_enrollment_check_screen_
,
450 kAutoEnrollmentCheckScreenName
,
451 MockAutoEnrollmentCheckScreen
,
452 MockAutoEnrollmentCheckScreenActor
);
453 MOCK(mock_wrong_hwid_screen_
, kWrongHWIDScreenName
, MockWrongHWIDScreen
,
454 MockWrongHWIDScreenActor
);
455 MOCK(mock_enable_debugging_screen_
,
456 kEnableDebuggingScreenName
,
457 MockEnableDebuggingScreen
,
458 MockEnableDebuggingScreenActor
);
459 device_disabled_screen_actor_
.reset(new MockDeviceDisabledScreenActor
);
460 wizard_controller
->screens_
[WizardController::kDeviceDisabledScreenName
] =
461 make_linked_ptr(new DeviceDisabledScreen(
463 device_disabled_screen_actor_
.get()));
464 EXPECT_CALL(*device_disabled_screen_actor_
, Show()).Times(0);
466 // Switch to the initial screen.
467 EXPECT_EQ(NULL
, wizard_controller
->current_screen());
468 EXPECT_CALL(*mock_network_screen_
, Show()).Times(1);
469 wizard_controller
->AdvanceToScreen(WizardController::kNetworkScreenName
);
472 void TearDownOnMainThread() override
{
473 mock_network_screen_
.reset();
474 device_disabled_screen_actor_
.reset();
475 WizardControllerTest::TearDownOnMainThread();
478 void TearDown() override
{
479 if (fallback_fetcher_factory_
) {
480 fetcher_factory_
.reset();
481 net::URLFetcherImpl::set_factory(fallback_fetcher_factory_
.get());
482 fallback_fetcher_factory_
.reset();
486 void InitTimezoneResolver() {
487 fallback_fetcher_factory_
.reset(new WizardControllerTestURLFetcherFactory
);
488 net::URLFetcherImpl::set_factory(NULL
);
489 fetcher_factory_
.reset(
490 new net::FakeURLFetcherFactory(fallback_fetcher_factory_
.get()));
492 network_portal_detector_
= new NetworkPortalDetectorTestImpl();
493 NetworkPortalDetector::InitializeForTesting(network_portal_detector_
);
495 NetworkPortalDetector::CaptivePortalState online_state
;
496 online_state
.status
= NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE
;
497 online_state
.response_code
= 204;
499 // Default detworks happens to be usually "eth1" in tests.
500 const NetworkState
* default_network
=
501 NetworkHandler::Get()->network_state_handler()->DefaultNetwork();
503 network_portal_detector_
->SetDefaultNetworkForTesting(
504 default_network
->guid());
505 network_portal_detector_
->SetDetectionResultsForTesting(
506 default_network
->guid(),
510 void OnExit(BaseScreen
& screen
, BaseScreenDelegate::ExitCodes exit_code
) {
511 WizardController::default_controller()->OnExit(screen
, exit_code
,
512 nullptr /* context */);
515 chromeos::SimpleGeolocationProvider
* GetGeolocationProvider() {
516 return WizardController::default_controller()->geolocation_provider_
.get();
519 void WaitUntilTimezoneResolved() {
520 scoped_ptr
<TimeZoneTestRunner
> runner(new TimeZoneTestRunner
);
521 if (!WizardController::default_controller()
522 ->SetOnTimeZoneResolvedForTesting(
523 base::Bind(&TimeZoneTestRunner::OnResolved
,
524 base::Unretained(runner
.get()))))
530 void ResetAutoEnrollmentCheckScreen() {
531 WizardController::default_controller()->screens_
.erase(
532 WizardController::kAutoEnrollmentCheckScreenName
);
535 linked_ptr
<MockNetworkScreen
> mock_network_screen_
;
536 MockOutShowHide
<MockUpdateScreen
, MockUpdateView
>* mock_update_screen_
;
537 MockOutShowHide
<MockEulaScreen
, MockEulaView
>* mock_eula_screen_
;
538 MockOutShowHide
<MockEnrollmentScreen
,
539 MockEnrollmentScreenActor
>* mock_enrollment_screen_
;
540 MockOutShowHide
<MockAutoEnrollmentCheckScreen
,
541 MockAutoEnrollmentCheckScreenActor
>* mock_auto_enrollment_check_screen_
;
542 MockOutShowHide
<MockWrongHWIDScreen
, MockWrongHWIDScreenActor
>*
543 mock_wrong_hwid_screen_
;
544 MockOutShowHide
<MockEnableDebuggingScreen
,
545 MockEnableDebuggingScreenActor
>* mock_enable_debugging_screen_
;
546 scoped_ptr
<MockDeviceDisabledScreenActor
> device_disabled_screen_actor_
;
549 NetworkPortalDetectorTestImpl
* network_portal_detector_
;
551 // Use a test factory as a fallback so we don't have to deal with other
553 scoped_ptr
<WizardControllerTestURLFetcherFactory
> fallback_fetcher_factory_
;
554 scoped_ptr
<net::FakeURLFetcherFactory
> fetcher_factory_
;
556 DISALLOW_COPY_AND_ASSIGN(WizardControllerFlowTest
);
559 IN_PROC_BROWSER_TEST_F(WizardControllerFlowTest
, ControlFlowMain
) {
560 CheckCurrentScreen(WizardController::kNetworkScreenName
);
562 WaitUntilJSIsReady();
564 // Check visibility of the header bar.
565 ASSERT_FALSE(JSExecuteBooleanExpression("$('login-header-bar').hidden"));
567 EXPECT_CALL(*mock_network_screen_
, Hide()).Times(1);
568 EXPECT_CALL(*mock_eula_screen_
, Show()).Times(1);
569 OnExit(*mock_network_screen_
, BaseScreenDelegate::NETWORK_CONNECTED
);
571 CheckCurrentScreen(WizardController::kEulaScreenName
);
573 // Header bar should still be visible.
574 ASSERT_FALSE(JSExecuteBooleanExpression("$('login-header-bar').hidden"));
576 EXPECT_CALL(*mock_eula_screen_
, Hide()).Times(1);
577 EXPECT_CALL(*mock_update_screen_
, StartNetworkCheck()).Times(1);
578 EXPECT_CALL(*mock_update_screen_
, Show()).Times(1);
579 // Enable TimeZone resolve
580 InitTimezoneResolver();
581 OnExit(*mock_eula_screen_
, BaseScreenDelegate::EULA_ACCEPTED
);
582 EXPECT_TRUE(GetGeolocationProvider());
584 // Let update screen smooth time process (time = 0ms).
585 content::RunAllPendingInMessageLoop();
587 CheckCurrentScreen(WizardController::kUpdateScreenName
);
588 EXPECT_CALL(*mock_update_screen_
, Hide()).Times(1);
589 EXPECT_CALL(*mock_auto_enrollment_check_screen_
, Show()).Times(1);
590 OnExit(*mock_update_screen_
, BaseScreenDelegate::UPDATE_INSTALLED
);
592 CheckCurrentScreen(WizardController::kAutoEnrollmentCheckScreenName
);
593 EXPECT_CALL(*mock_auto_enrollment_check_screen_
, Hide()).Times(0);
594 EXPECT_CALL(*mock_eula_screen_
, Show()).Times(0);
595 OnExit(*mock_auto_enrollment_check_screen_
,
596 BaseScreenDelegate::ENTERPRISE_AUTO_ENROLLMENT_CHECK_COMPLETED
);
598 EXPECT_FALSE(ExistingUserController::current_controller() == NULL
);
599 EXPECT_EQ("ethernet,wifi,cellular",
600 NetworkHandler::Get()->network_state_handler()
601 ->GetCheckPortalListForTest());
603 WaitUntilTimezoneResolved();
604 EXPECT_EQ("America/Anchorage",
605 base::UTF16ToUTF8(chromeos::system::TimezoneSettings::GetInstance()
606 ->GetCurrentTimezoneID()));
609 IN_PROC_BROWSER_TEST_F(WizardControllerFlowTest
, ControlFlowErrorUpdate
) {
610 CheckCurrentScreen(WizardController::kNetworkScreenName
);
611 EXPECT_CALL(*mock_update_screen_
, StartNetworkCheck()).Times(0);
612 EXPECT_CALL(*mock_eula_screen_
, Show()).Times(1);
613 EXPECT_CALL(*mock_update_screen_
, Show()).Times(0);
614 EXPECT_CALL(*mock_network_screen_
, Hide()).Times(1);
615 OnExit(*mock_network_screen_
, BaseScreenDelegate::NETWORK_CONNECTED
);
617 CheckCurrentScreen(WizardController::kEulaScreenName
);
618 EXPECT_CALL(*mock_eula_screen_
, Hide()).Times(1);
619 EXPECT_CALL(*mock_update_screen_
, StartNetworkCheck()).Times(1);
620 EXPECT_CALL(*mock_update_screen_
, Show()).Times(1);
621 OnExit(*mock_eula_screen_
, BaseScreenDelegate::EULA_ACCEPTED
);
623 // Let update screen smooth time process (time = 0ms).
624 content::RunAllPendingInMessageLoop();
626 CheckCurrentScreen(WizardController::kUpdateScreenName
);
627 EXPECT_CALL(*mock_update_screen_
, Hide()).Times(1);
628 EXPECT_CALL(*mock_auto_enrollment_check_screen_
, Show()).Times(1);
629 OnExit(*mock_update_screen_
, BaseScreenDelegate::UPDATE_ERROR_UPDATING
);
631 CheckCurrentScreen(WizardController::kAutoEnrollmentCheckScreenName
);
632 EXPECT_CALL(*mock_auto_enrollment_check_screen_
, Hide()).Times(0);
633 EXPECT_CALL(*mock_eula_screen_
, Show()).Times(0);
634 OnExit(*mock_auto_enrollment_check_screen_
,
635 BaseScreenDelegate::ENTERPRISE_AUTO_ENROLLMENT_CHECK_COMPLETED
);
637 EXPECT_FALSE(ExistingUserController::current_controller() == NULL
);
640 IN_PROC_BROWSER_TEST_F(WizardControllerFlowTest
, ControlFlowSkipUpdateEnroll
) {
641 CheckCurrentScreen(WizardController::kNetworkScreenName
);
642 EXPECT_CALL(*mock_update_screen_
, StartNetworkCheck()).Times(0);
643 EXPECT_CALL(*mock_eula_screen_
, Show()).Times(1);
644 EXPECT_CALL(*mock_update_screen_
, Show()).Times(0);
645 EXPECT_CALL(*mock_network_screen_
, Hide()).Times(1);
646 OnExit(*mock_network_screen_
, BaseScreenDelegate::NETWORK_CONNECTED
);
648 CheckCurrentScreen(WizardController::kEulaScreenName
);
649 EXPECT_CALL(*mock_eula_screen_
, Hide()).Times(1);
650 EXPECT_CALL(*mock_update_screen_
, StartNetworkCheck()).Times(0);
651 EXPECT_CALL(*mock_update_screen_
, Show()).Times(0);
652 WizardController::default_controller()->SkipUpdateEnrollAfterEula();
653 EXPECT_CALL(*mock_enrollment_screen_
->actor(),
655 mock_enrollment_screen_
,
656 EnrollmentModeMatches(policy::EnrollmentConfig::MODE_MANUAL
)))
658 EXPECT_CALL(*mock_auto_enrollment_check_screen_
, Show()).Times(1);
659 OnExit(*mock_eula_screen_
, BaseScreenDelegate::EULA_ACCEPTED
);
660 content::RunAllPendingInMessageLoop();
662 CheckCurrentScreen(WizardController::kAutoEnrollmentCheckScreenName
);
663 EXPECT_CALL(*mock_auto_enrollment_check_screen_
, Hide()).Times(1);
664 EXPECT_CALL(*mock_enrollment_screen_
, Show()).Times(1);
665 EXPECT_CALL(*mock_enrollment_screen_
, Hide()).Times(0);
666 OnExit(*mock_auto_enrollment_check_screen_
,
667 BaseScreenDelegate::ENTERPRISE_AUTO_ENROLLMENT_CHECK_COMPLETED
);
668 content::RunAllPendingInMessageLoop();
670 CheckCurrentScreen(WizardController::kEnrollmentScreenName
);
671 EXPECT_EQ("ethernet,wifi,cellular",
672 NetworkHandler::Get()->network_state_handler()
673 ->GetCheckPortalListForTest());
676 IN_PROC_BROWSER_TEST_F(WizardControllerFlowTest
, ControlFlowEulaDeclined
) {
677 CheckCurrentScreen(WizardController::kNetworkScreenName
);
678 EXPECT_CALL(*mock_update_screen_
, StartNetworkCheck()).Times(0);
679 EXPECT_CALL(*mock_eula_screen_
, Show()).Times(1);
680 EXPECT_CALL(*mock_network_screen_
, Hide()).Times(1);
681 OnExit(*mock_network_screen_
, BaseScreenDelegate::NETWORK_CONNECTED
);
683 CheckCurrentScreen(WizardController::kEulaScreenName
);
684 EXPECT_CALL(*mock_eula_screen_
, Hide()).Times(1);
685 EXPECT_CALL(*mock_network_screen_
, Show()).Times(1);
686 EXPECT_CALL(*mock_network_screen_
, Hide()).Times(0); // last transition
687 OnExit(*mock_eula_screen_
, BaseScreenDelegate::EULA_BACK
);
689 CheckCurrentScreen(WizardController::kNetworkScreenName
);
692 IN_PROC_BROWSER_TEST_F(WizardControllerFlowTest
,
693 ControlFlowEnrollmentCompleted
) {
694 CheckCurrentScreen(WizardController::kNetworkScreenName
);
695 EXPECT_CALL(*mock_update_screen_
, StartNetworkCheck()).Times(0);
696 EXPECT_CALL(*mock_enrollment_screen_
->actor(),
698 mock_enrollment_screen_
,
699 EnrollmentModeMatches(policy::EnrollmentConfig::MODE_MANUAL
)))
701 EXPECT_CALL(*mock_enrollment_screen_
, Show()).Times(1);
702 EXPECT_CALL(*mock_network_screen_
, Hide()).Times(1);
704 WizardController::default_controller()->AdvanceToScreen(
705 WizardController::kEnrollmentScreenName
);
706 CheckCurrentScreen(WizardController::kEnrollmentScreenName
);
707 OnExit(*mock_enrollment_screen_
,
708 BaseScreenDelegate::ENTERPRISE_ENROLLMENT_COMPLETED
);
710 EXPECT_FALSE(ExistingUserController::current_controller() == NULL
);
713 IN_PROC_BROWSER_TEST_F(WizardControllerFlowTest
,
714 ControlFlowWrongHWIDScreenFromLogin
) {
715 CheckCurrentScreen(WizardController::kNetworkScreenName
);
717 LoginDisplayHostImpl::default_host()->StartSignInScreen(LoginScreenContext());
718 EXPECT_FALSE(ExistingUserController::current_controller() == NULL
);
719 ExistingUserController::current_controller()->ShowWrongHWIDScreen();
721 CheckCurrentScreen(WizardController::kWrongHWIDScreenName
);
723 // After warning is skipped, user returns to sign-in screen.
724 // And this destroys WizardController.
725 OnExit(*mock_wrong_hwid_screen_
,
726 BaseScreenDelegate::WRONG_HWID_WARNING_SKIPPED
);
727 EXPECT_FALSE(ExistingUserController::current_controller() == NULL
);
730 class WizardControllerDeviceStateTest
: public WizardControllerFlowTest
{
732 WizardControllerDeviceStateTest()
733 : install_attributes_(std::string(),
736 policy::DEVICE_MODE_NOT_SET
) {
737 fake_statistics_provider_
.SetMachineStatistic("serial_number", "test");
738 fake_statistics_provider_
.SetMachineStatistic(system::kActivateDateKey
,
742 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
743 WizardControllerFlowTest::SetUpCommandLine(command_line
);
745 command_line
->AppendSwitchASCII(
746 switches::kEnterpriseEnableForcedReEnrollment
,
747 chromeos::AutoEnrollmentController::kForcedReEnrollmentAlways
);
748 command_line
->AppendSwitchASCII(
749 switches::kEnterpriseEnrollmentInitialModulus
, "1");
750 command_line
->AppendSwitchASCII(
751 switches::kEnterpriseEnrollmentModulusLimit
, "2");
754 system::ScopedFakeStatisticsProvider fake_statistics_provider_
;
757 policy::ScopedStubEnterpriseInstallAttributes install_attributes_
;
759 DISALLOW_COPY_AND_ASSIGN(WizardControllerDeviceStateTest
);
762 IN_PROC_BROWSER_TEST_F(WizardControllerDeviceStateTest
,
763 ControlFlowForcedReEnrollment
) {
764 CheckCurrentScreen(WizardController::kNetworkScreenName
);
765 EXPECT_CALL(*mock_network_screen_
, Hide()).Times(1);
766 EXPECT_CALL(*mock_eula_screen_
, Show()).Times(1);
767 OnExit(*mock_network_screen_
, BaseScreenDelegate::NETWORK_CONNECTED
);
769 CheckCurrentScreen(WizardController::kEulaScreenName
);
770 EXPECT_CALL(*mock_eula_screen_
, Hide()).Times(1);
771 EXPECT_CALL(*mock_update_screen_
, StartNetworkCheck()).Times(1);
772 EXPECT_CALL(*mock_update_screen_
, Show()).Times(1);
773 OnExit(*mock_eula_screen_
, BaseScreenDelegate::EULA_ACCEPTED
);
775 // Let update screen smooth time process (time = 0ms).
776 content::RunAllPendingInMessageLoop();
778 CheckCurrentScreen(WizardController::kUpdateScreenName
);
779 EXPECT_CALL(*mock_update_screen_
, Hide()).Times(1);
780 EXPECT_CALL(*mock_auto_enrollment_check_screen_
, Show()).Times(1);
781 OnExit(*mock_update_screen_
, BaseScreenDelegate::UPDATE_INSTALLED
);
783 CheckCurrentScreen(WizardController::kAutoEnrollmentCheckScreenName
);
784 EXPECT_CALL(*mock_auto_enrollment_check_screen_
, Hide()).Times(1);
785 mock_auto_enrollment_check_screen_
->RealShow();
787 // Wait for auto-enrollment controller to encounter the connection error.
788 WaitForAutoEnrollmentState(policy::AUTO_ENROLLMENT_STATE_CONNECTION_ERROR
);
790 // The error screen shows up if there's no auto-enrollment decision.
791 EXPECT_FALSE(StartupUtils::IsOobeCompleted());
792 EXPECT_EQ(GetErrorScreen(),
793 WizardController::default_controller()->current_screen());
794 base::DictionaryValue device_state
;
795 device_state
.SetString(policy::kDeviceStateRestoreMode
,
796 policy::kDeviceStateRestoreModeReEnrollmentEnforced
);
797 g_browser_process
->local_state()->Set(prefs::kServerBackedDeviceState
,
799 EXPECT_CALL(*mock_enrollment_screen_
, Show()).Times(1);
800 EXPECT_CALL(*mock_enrollment_screen_
->actor(),
801 SetParameters(mock_enrollment_screen_
,
802 EnrollmentModeMatches(
803 policy::EnrollmentConfig::MODE_SERVER_FORCED
)))
805 OnExit(*mock_auto_enrollment_check_screen_
,
806 BaseScreenDelegate::ENTERPRISE_AUTO_ENROLLMENT_CHECK_COMPLETED
);
808 ResetAutoEnrollmentCheckScreen();
810 // Make sure enterprise enrollment page shows up.
811 CheckCurrentScreen(WizardController::kEnrollmentScreenName
);
812 OnExit(*mock_enrollment_screen_
,
813 BaseScreenDelegate::ENTERPRISE_ENROLLMENT_COMPLETED
);
815 EXPECT_TRUE(StartupUtils::IsOobeCompleted());
818 IN_PROC_BROWSER_TEST_F(WizardControllerDeviceStateTest
,
819 ControlFlowNoForcedReEnrollmentOnFirstBoot
) {
820 fake_statistics_provider_
.ClearMachineStatistic(system::kActivateDateKey
);
821 EXPECT_NE(policy::AUTO_ENROLLMENT_STATE_NO_ENROLLMENT
,
822 LoginDisplayHostImpl::default_host()
823 ->GetAutoEnrollmentController()
826 CheckCurrentScreen(WizardController::kNetworkScreenName
);
827 EXPECT_CALL(*mock_network_screen_
, Hide()).Times(1);
828 EXPECT_CALL(*mock_eula_screen_
, Show()).Times(1);
829 OnExit(*mock_network_screen_
, BaseScreenDelegate::NETWORK_CONNECTED
);
831 CheckCurrentScreen(WizardController::kEulaScreenName
);
832 EXPECT_CALL(*mock_eula_screen_
, Hide()).Times(1);
833 EXPECT_CALL(*mock_update_screen_
, StartNetworkCheck()).Times(1);
834 EXPECT_CALL(*mock_update_screen_
, Show()).Times(1);
835 OnExit(*mock_eula_screen_
, BaseScreenDelegate::EULA_ACCEPTED
);
837 // Let update screen smooth time process (time = 0ms).
838 content::RunAllPendingInMessageLoop();
840 CheckCurrentScreen(WizardController::kUpdateScreenName
);
841 EXPECT_CALL(*mock_update_screen_
, Hide()).Times(1);
842 EXPECT_CALL(*mock_auto_enrollment_check_screen_
, Show()).Times(1);
843 OnExit(*mock_update_screen_
, BaseScreenDelegate::UPDATE_INSTALLED
);
845 CheckCurrentScreen(WizardController::kAutoEnrollmentCheckScreenName
);
846 mock_auto_enrollment_check_screen_
->RealShow();
847 EXPECT_EQ(policy::AUTO_ENROLLMENT_STATE_NO_ENROLLMENT
,
848 LoginDisplayHostImpl::default_host()
849 ->GetAutoEnrollmentController()
853 IN_PROC_BROWSER_TEST_F(WizardControllerDeviceStateTest
,
854 ControlFlowDeviceDisabled
) {
855 CheckCurrentScreen(WizardController::kNetworkScreenName
);
856 EXPECT_CALL(*mock_network_screen_
, Hide()).Times(1);
857 EXPECT_CALL(*mock_eula_screen_
, Show()).Times(1);
858 OnExit(*mock_network_screen_
, BaseScreenDelegate::NETWORK_CONNECTED
);
860 CheckCurrentScreen(WizardController::kEulaScreenName
);
861 EXPECT_CALL(*mock_eula_screen_
, Hide()).Times(1);
862 EXPECT_CALL(*mock_update_screen_
, StartNetworkCheck()).Times(1);
863 EXPECT_CALL(*mock_update_screen_
, Show()).Times(1);
864 OnExit(*mock_eula_screen_
, BaseScreenDelegate::EULA_ACCEPTED
);
866 // Let update screen smooth time process (time = 0ms).
867 content::RunAllPendingInMessageLoop();
869 CheckCurrentScreen(WizardController::kUpdateScreenName
);
870 EXPECT_CALL(*mock_update_screen_
, Hide()).Times(1);
871 EXPECT_CALL(*mock_auto_enrollment_check_screen_
, Show()).Times(1);
872 OnExit(*mock_update_screen_
, BaseScreenDelegate::UPDATE_INSTALLED
);
874 CheckCurrentScreen(WizardController::kAutoEnrollmentCheckScreenName
);
875 EXPECT_CALL(*mock_auto_enrollment_check_screen_
, Hide()).Times(1);
876 mock_auto_enrollment_check_screen_
->RealShow();
878 // Wait for auto-enrollment controller to encounter the connection error.
879 WaitForAutoEnrollmentState(policy::AUTO_ENROLLMENT_STATE_CONNECTION_ERROR
);
881 // The error screen shows up if device state could not be retrieved.
882 EXPECT_FALSE(StartupUtils::IsOobeCompleted());
883 EXPECT_EQ(GetErrorScreen(),
884 WizardController::default_controller()->current_screen());
885 base::DictionaryValue device_state
;
886 device_state
.SetString(policy::kDeviceStateRestoreMode
,
887 policy::kDeviceStateRestoreModeDisabled
);
888 device_state
.SetString(policy::kDeviceStateDisabledMessage
, kDisabledMessage
);
889 g_browser_process
->local_state()->Set(prefs::kServerBackedDeviceState
,
891 EXPECT_CALL(*device_disabled_screen_actor_
,
892 UpdateMessage(kDisabledMessage
)).Times(1);
893 EXPECT_CALL(*device_disabled_screen_actor_
, Show()).Times(1);
894 OnExit(*mock_auto_enrollment_check_screen_
,
895 BaseScreenDelegate::ENTERPRISE_AUTO_ENROLLMENT_CHECK_COMPLETED
);
897 ResetAutoEnrollmentCheckScreen();
899 // Make sure the device disabled screen is shown.
900 CheckCurrentScreen(WizardController::kDeviceDisabledScreenName
);
902 EXPECT_FALSE(StartupUtils::IsOobeCompleted());
905 class WizardControllerBrokenLocalStateTest
: public WizardControllerTest
{
907 WizardControllerBrokenLocalStateTest()
908 : fake_session_manager_client_(NULL
) {
911 ~WizardControllerBrokenLocalStateTest() override
{}
913 void SetUpInProcessBrowserTestFixture() override
{
914 WizardControllerTest::SetUpInProcessBrowserTestFixture();
916 fake_session_manager_client_
= new FakeSessionManagerClient
;
917 DBusThreadManager::GetSetterForTesting()->SetSessionManagerClient(
918 scoped_ptr
<SessionManagerClient
>(fake_session_manager_client_
));
921 void SetUpOnMainThread() override
{
922 base::PrefServiceFactory factory
;
923 factory
.set_user_prefs(make_scoped_refptr(new PrefStoreStub()));
924 local_state_
= factory
.Create(new PrefRegistrySimple()).Pass();
925 WizardController::set_local_state_for_testing(local_state_
.get());
927 WizardControllerTest::SetUpOnMainThread();
929 // Make sure that OOBE is run as an "official" build.
930 WizardController::default_controller()->is_official_build_
= true;
933 FakeSessionManagerClient
* fake_session_manager_client() const {
934 return fake_session_manager_client_
;
938 scoped_ptr
<PrefService
> local_state_
;
939 FakeSessionManagerClient
* fake_session_manager_client_
;
941 DISALLOW_COPY_AND_ASSIGN(WizardControllerBrokenLocalStateTest
);
944 IN_PROC_BROWSER_TEST_F(WizardControllerBrokenLocalStateTest
,
945 LocalStateCorrupted
) {
946 // Checks that after wizard controller initialization error screen
947 // in the proper state is displayed.
948 ASSERT_EQ(GetErrorScreen(),
949 WizardController::default_controller()->current_screen());
950 ASSERT_EQ(NetworkError::UI_STATE_LOCAL_STATE_ERROR
,
951 GetErrorScreen()->GetUIState());
953 WaitUntilJSIsReady();
955 // Checks visibility of the error message and powerwash button.
956 ASSERT_FALSE(JSExecuteBooleanExpression("$('error-message').hidden"));
957 ASSERT_TRUE(JSExecuteBooleanExpression(
958 "$('error-message').classList.contains('ui-state-local-state-error')"));
959 ASSERT_TRUE(JSExecuteBooleanExpression("$('progress-dots').hidden"));
960 ASSERT_TRUE(JSExecuteBooleanExpression("$('login-header-bar').hidden"));
962 // Emulates user click on the "Restart and Powerwash" button.
963 ASSERT_EQ(0, fake_session_manager_client()->start_device_wipe_call_count());
964 ASSERT_TRUE(content::ExecuteScript(
966 "$('error-message-restart-and-powerwash-button').click();"));
967 ASSERT_EQ(1, fake_session_manager_client()->start_device_wipe_call_count());
970 // Boolean parameter is used to run this test for webview (true) and for
971 // iframe (false) GAIA sign in.
972 class WizardControllerProxyAuthOnSigninTest
973 : public WizardControllerTest
,
974 public testing::WithParamInterface
<bool> {
976 WizardControllerProxyAuthOnSigninTest()
977 : proxy_server_(net::SpawnedTestServer::TYPE_BASIC_AUTH_PROXY
,
978 net::SpawnedTestServer::kLocalhost
,
981 ~WizardControllerProxyAuthOnSigninTest() override
{}
983 // Overridden from WizardControllerTest:
984 void SetUp() override
{
985 ASSERT_TRUE(proxy_server_
.Start());
986 WizardControllerTest::SetUp();
989 void SetUpOnMainThread() override
{
990 WizardControllerTest::SetUpOnMainThread();
991 WizardController::default_controller()->AdvanceToScreen(
992 WizardController::kNetworkScreenName
);
995 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
996 command_line
->AppendSwitchASCII(::switches::kProxyServer
,
997 proxy_server_
.host_port_pair().ToString());
1000 bool SetUpUserDataDirectory() override
{
1001 base::FilePath user_data_dir
;
1002 CHECK(PathService::Get(chrome::DIR_USER_DATA
, &user_data_dir
));
1003 base::FilePath local_state_path
=
1004 user_data_dir
.Append(chrome::kLocalStateFilename
);
1006 // Set webview disabled flag only when local state file does not exist.
1007 // Otherwise, we break PRE tests that leave state in it.
1008 if (!base::PathExists(local_state_path
)) {
1009 base::DictionaryValue local_state_dict
;
1012 local_state_dict
.SetBoolean(prefs::kWebviewSigninDisabled
, true);
1014 CHECK(JSONFileValueSerializer(local_state_path
)
1015 .Serialize(local_state_dict
));
1018 return WizardControllerTest::SetUpUserDataDirectory();
1021 net::SpawnedTestServer
& proxy_server() { return proxy_server_
; }
1024 net::SpawnedTestServer proxy_server_
;
1026 DISALLOW_COPY_AND_ASSIGN(WizardControllerProxyAuthOnSigninTest
);
1029 // Disabled, see https://crbug.com/504928.
1030 IN_PROC_BROWSER_TEST_P(WizardControllerProxyAuthOnSigninTest
,
1031 DISABLED_ProxyAuthDialogOnSigninScreen
) {
1032 content::WindowedNotificationObserver
auth_needed_waiter(
1033 chrome::NOTIFICATION_AUTH_NEEDED
,
1034 content::NotificationService::AllSources());
1036 CheckCurrentScreen(WizardController::kNetworkScreenName
);
1038 LoginDisplayHostImpl::default_host()->StartSignInScreen(LoginScreenContext());
1039 auth_needed_waiter
.Wait();
1042 INSTANTIATE_TEST_CASE_P(WizardControllerProxyAuthOnSigninSuite
,
1043 WizardControllerProxyAuthOnSigninTest
,
1046 class WizardControllerKioskFlowTest
: public WizardControllerFlowTest
{
1048 WizardControllerKioskFlowTest() {}
1050 // Overridden from InProcessBrowserTest:
1051 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
1052 base::FilePath test_data_dir
;
1053 ASSERT_TRUE(chromeos::test_utils::GetTestDataPath(
1054 "app_mode", "kiosk_manifest", &test_data_dir
));
1055 command_line
->AppendSwitchPath(
1056 switches::kAppOemManifestFile
,
1057 test_data_dir
.AppendASCII("kiosk_manifest.json"));
1061 DISALLOW_COPY_AND_ASSIGN(WizardControllerKioskFlowTest
);
1064 IN_PROC_BROWSER_TEST_F(WizardControllerKioskFlowTest
,
1065 ControlFlowKioskForcedEnrollment
) {
1066 EXPECT_CALL(*mock_enrollment_screen_
->actor(),
1067 SetParameters(mock_enrollment_screen_
,
1068 EnrollmentModeMatches(
1069 policy::EnrollmentConfig::MODE_LOCAL_FORCED
)))
1071 CheckCurrentScreen(WizardController::kNetworkScreenName
);
1072 EXPECT_CALL(*mock_network_screen_
, Hide()).Times(1);
1073 EXPECT_CALL(*mock_eula_screen_
, Show()).Times(1);
1074 OnExit(*mock_network_screen_
, BaseScreenDelegate::NETWORK_CONNECTED
);
1076 CheckCurrentScreen(WizardController::kEulaScreenName
);
1077 EXPECT_CALL(*mock_eula_screen_
, Hide()).Times(1);
1078 EXPECT_CALL(*mock_update_screen_
, StartNetworkCheck()).Times(1);
1079 EXPECT_CALL(*mock_update_screen_
, Show()).Times(1);
1080 OnExit(*mock_eula_screen_
, BaseScreenDelegate::EULA_ACCEPTED
);
1082 // Let update screen smooth time process (time = 0ms).
1083 content::RunAllPendingInMessageLoop();
1085 CheckCurrentScreen(WizardController::kUpdateScreenName
);
1086 EXPECT_CALL(*mock_update_screen_
, Hide()).Times(1);
1087 EXPECT_CALL(*mock_auto_enrollment_check_screen_
, Show()).Times(1);
1088 OnExit(*mock_update_screen_
, BaseScreenDelegate::UPDATE_INSTALLED
);
1090 CheckCurrentScreen(WizardController::kAutoEnrollmentCheckScreenName
);
1091 EXPECT_CALL(*mock_auto_enrollment_check_screen_
, Hide()).Times(1);
1092 EXPECT_CALL(*mock_enrollment_screen_
, Show()).Times(1);
1093 OnExit(*mock_auto_enrollment_check_screen_
,
1094 BaseScreenDelegate::ENTERPRISE_AUTO_ENROLLMENT_CHECK_COMPLETED
);
1096 EXPECT_FALSE(StartupUtils::IsOobeCompleted());
1098 // Make sure enterprise enrollment page shows up right after update screen.
1099 CheckCurrentScreen(WizardController::kEnrollmentScreenName
);
1100 OnExit(*mock_enrollment_screen_
,
1101 BaseScreenDelegate::ENTERPRISE_ENROLLMENT_COMPLETED
);
1103 EXPECT_TRUE(StartupUtils::IsOobeCompleted());
1106 IN_PROC_BROWSER_TEST_F(WizardControllerKioskFlowTest
,
1107 ControlFlowEnrollmentBack
) {
1108 EXPECT_CALL(*mock_enrollment_screen_
->actor(),
1109 SetParameters(mock_enrollment_screen_
,
1110 EnrollmentModeMatches(
1111 policy::EnrollmentConfig::MODE_LOCAL_FORCED
)))
1114 CheckCurrentScreen(WizardController::kNetworkScreenName
);
1115 EXPECT_CALL(*mock_network_screen_
, Hide()).Times(1);
1116 EXPECT_CALL(*mock_eula_screen_
, Show()).Times(1);
1117 OnExit(*mock_network_screen_
, BaseScreenDelegate::NETWORK_CONNECTED
);
1119 CheckCurrentScreen(WizardController::kEulaScreenName
);
1120 EXPECT_CALL(*mock_eula_screen_
, Hide()).Times(1);
1121 EXPECT_CALL(*mock_update_screen_
, StartNetworkCheck()).Times(1);
1122 EXPECT_CALL(*mock_update_screen_
, Show()).Times(1);
1123 OnExit(*mock_eula_screen_
, BaseScreenDelegate::EULA_ACCEPTED
);
1125 // Let update screen smooth time process (time = 0ms).
1126 content::RunAllPendingInMessageLoop();
1128 CheckCurrentScreen(WizardController::kUpdateScreenName
);
1129 EXPECT_CALL(*mock_update_screen_
, Hide()).Times(1);
1130 EXPECT_CALL(*mock_auto_enrollment_check_screen_
, Show()).Times(1);
1131 OnExit(*mock_update_screen_
, BaseScreenDelegate::UPDATE_INSTALLED
);
1133 CheckCurrentScreen(WizardController::kAutoEnrollmentCheckScreenName
);
1134 EXPECT_CALL(*mock_auto_enrollment_check_screen_
, Hide()).Times(1);
1135 EXPECT_CALL(*mock_enrollment_screen_
, Show()).Times(1);
1136 EXPECT_CALL(*mock_enrollment_screen_
, Hide()).Times(1);
1137 OnExit(*mock_auto_enrollment_check_screen_
,
1138 BaseScreenDelegate::ENTERPRISE_AUTO_ENROLLMENT_CHECK_COMPLETED
);
1140 EXPECT_FALSE(StartupUtils::IsOobeCompleted());
1142 // Make sure enterprise enrollment page shows up right after update screen.
1143 CheckCurrentScreen(WizardController::kEnrollmentScreenName
);
1144 EXPECT_CALL(*mock_auto_enrollment_check_screen_
, Show()).Times(1);
1145 OnExit(*mock_enrollment_screen_
,
1146 BaseScreenDelegate::ENTERPRISE_ENROLLMENT_BACK
);
1148 CheckCurrentScreen(WizardController::kAutoEnrollmentCheckScreenName
);
1149 EXPECT_FALSE(StartupUtils::IsOobeCompleted());
1153 class WizardControllerEnableDebuggingTest
: public WizardControllerFlowTest
{
1155 WizardControllerEnableDebuggingTest() {}
1157 // Overridden from InProcessBrowserTest:
1158 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
1159 WizardControllerFlowTest::SetUpCommandLine(command_line
);
1160 command_line
->AppendSwitch(chromeos::switches::kSystemDevMode
);
1164 DISALLOW_COPY_AND_ASSIGN(WizardControllerEnableDebuggingTest
);
1167 IN_PROC_BROWSER_TEST_F(WizardControllerEnableDebuggingTest
,
1168 ShowAndCancelEnableDebugging
) {
1169 CheckCurrentScreen(WizardController::kNetworkScreenName
);
1170 WaitUntilJSIsReady();
1172 EXPECT_CALL(*mock_network_screen_
, Hide()).Times(1);
1173 EXPECT_CALL(*mock_enable_debugging_screen_
, Show()).Times(1);
1175 ASSERT_TRUE(JSExecute("$('connect-debugging-features-link').click()"));
1177 // Let update screen smooth time process (time = 0ms).
1178 content::RunAllPendingInMessageLoop();
1180 CheckCurrentScreen(WizardController::kEnableDebuggingScreenName
);
1181 EXPECT_CALL(*mock_enable_debugging_screen_
, Hide()).Times(1);
1182 EXPECT_CALL(*mock_network_screen_
, Show()).Times(1);
1184 OnExit(*mock_enable_debugging_screen_
,
1185 BaseScreenDelegate::ENABLE_DEBUGGING_CANCELED
);
1187 // Let update screen smooth time process (time = 0ms).
1188 content::RunAllPendingInMessageLoop();
1190 CheckCurrentScreen(WizardController::kNetworkScreenName
);
1193 class WizardControllerOobeResumeTest
: public WizardControllerTest
{
1195 WizardControllerOobeResumeTest() {}
1196 // Overriden from InProcessBrowserTest:
1197 void SetUpOnMainThread() override
{
1198 WizardControllerTest::SetUpOnMainThread();
1200 // Make sure that OOBE is run as an "official" build.
1201 WizardController::default_controller()->is_official_build_
= true;
1203 // Clear portal list (as it is by default in OOBE).
1204 NetworkHandler::Get()->network_state_handler()->SetCheckPortalList("");
1206 // Set up the mocks for all screens.
1207 MOCK_WITH_DELEGATE(mock_network_screen_
, kNetworkScreenName
,
1208 MockNetworkScreen
, MockNetworkView
);
1209 MOCK(mock_enrollment_screen_
,
1210 kEnrollmentScreenName
,
1211 MockEnrollmentScreen
,
1212 MockEnrollmentScreenActor
);
1215 void OnExit(BaseScreen
& screen
, BaseScreenDelegate::ExitCodes exit_code
) {
1216 WizardController::default_controller()->OnExit(screen
, exit_code
,
1217 nullptr /* context */);
1220 std::string
GetFirstScreenName() {
1221 return WizardController::default_controller()->first_screen_name();
1224 MockOutShowHide
<MockNetworkScreen
, MockNetworkView
>* mock_network_screen_
;
1225 MockOutShowHide
<MockEnrollmentScreen
,
1226 MockEnrollmentScreenActor
>* mock_enrollment_screen_
;
1229 DISALLOW_COPY_AND_ASSIGN(WizardControllerOobeResumeTest
);
1232 IN_PROC_BROWSER_TEST_F(WizardControllerOobeResumeTest
,
1233 PRE_ControlFlowResumeInterruptedOobe
) {
1234 // Switch to the initial screen.
1235 EXPECT_CALL(*mock_network_screen_
, Show()).Times(1);
1236 WizardController::default_controller()->AdvanceToScreen(
1237 WizardController::kNetworkScreenName
);
1238 CheckCurrentScreen(WizardController::kNetworkScreenName
);
1239 EXPECT_CALL(*mock_enrollment_screen_
->actor(),
1241 mock_enrollment_screen_
,
1242 EnrollmentModeMatches(policy::EnrollmentConfig::MODE_MANUAL
)))
1244 EXPECT_CALL(*mock_enrollment_screen_
, Show()).Times(1);
1245 EXPECT_CALL(*mock_network_screen_
, Hide()).Times(1);
1247 WizardController::default_controller()->AdvanceToScreen(
1248 WizardController::kEnrollmentScreenName
);
1249 CheckCurrentScreen(WizardController::kEnrollmentScreenName
);
1252 IN_PROC_BROWSER_TEST_F(WizardControllerOobeResumeTest
,
1253 ControlFlowResumeInterruptedOobe
) {
1254 EXPECT_EQ(WizardController::kEnrollmentScreenName
, GetFirstScreenName());
1257 // TODO(dzhioev): Add test emaulating device with wrong HWID.
1259 // TODO(nkostylev): Add test for WebUI accelerators http://crosbug.com/22571
1261 // TODO(merkulova): Add tests for bluetooth HID detection screen variations when
1262 // UI and logic is ready. http://crbug.com/127016
1264 // TODO(dzhioev): Add tests for controller/host pairing flow.
1265 // http://crbug.com/375191
1267 static_assert(BaseScreenDelegate::EXIT_CODES_COUNT
== 24,
1268 "tests for new control flow are missing");
1270 } // namespace chromeos