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 "base/basictypes.h"
6 #include "base/command_line.h"
7 #include "base/compiler_specific.h"
8 #include "base/path_service.h"
9 #include "base/prefs/pref_registry_simple.h"
10 #include "base/prefs/pref_service.h"
11 #include "base/prefs/pref_service_factory.h"
12 #include "base/prefs/testing_pref_store.h"
13 #include "base/run_loop.h"
14 #include "base/strings/utf_string_conversions.h"
15 #include "chrome/browser/browser_process.h"
16 #include "chrome/browser/browser_shutdown.h"
17 #include "chrome/browser/chrome_notification_types.h"
18 #include "chrome/browser/chromeos/base/locale_util.h"
19 #include "chrome/browser/chromeos/login/enrollment/enrollment_screen.h"
20 #include "chrome/browser/chromeos/login/enrollment/mock_enrollment_screen.h"
21 #include "chrome/browser/chromeos/login/existing_user_controller.h"
22 #include "chrome/browser/chromeos/login/login_display_host_impl.h"
23 #include "chrome/browser/chromeos/login/mock_authenticator.h"
24 #include "chrome/browser/chromeos/login/mock_login_status_consumer.h"
25 #include "chrome/browser/chromeos/login/screens/error_screen.h"
26 #include "chrome/browser/chromeos/login/screens/mock_eula_screen.h"
27 #include "chrome/browser/chromeos/login/screens/mock_network_screen.h"
28 #include "chrome/browser/chromeos/login/screens/mock_update_screen.h"
29 #include "chrome/browser/chromeos/login/screens/network_screen.h"
30 #include "chrome/browser/chromeos/login/screens/reset_screen.h"
31 #include "chrome/browser/chromeos/login/screens/user_image_screen.h"
32 #include "chrome/browser/chromeos/login/screens/wrong_hwid_screen.h"
33 #include "chrome/browser/chromeos/login/startup_utils.h"
34 #include "chrome/browser/chromeos/login/test_login_utils.h"
35 #include "chrome/browser/chromeos/login/webui_login_view.h"
36 #include "chrome/browser/chromeos/login/wizard_controller.h"
37 #include "chrome/browser/chromeos/login/wizard_in_process_browser_test.h"
38 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h"
39 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h"
40 #include "chrome/common/chrome_paths.h"
41 #include "chrome/common/chrome_switches.h"
42 #include "chrome/test/base/ui_test_utils.h"
43 #include "chromeos/chromeos_switches.h"
44 #include "chromeos/chromeos_test_utils.h"
45 #include "chromeos/dbus/dbus_thread_manager.h"
46 #include "chromeos/dbus/fake_dbus_thread_manager.h"
47 #include "chromeos/dbus/fake_session_manager_client.h"
48 #include "chromeos/network/network_state_handler.h"
49 #include "content/public/test/browser_test_utils.h"
50 #include "content/public/test/test_utils.h"
51 #include "grit/generated_resources.h"
52 #include "net/test/spawned_test_server/spawned_test_server.h"
53 #include "testing/gmock/include/gmock/gmock.h"
54 #include "testing/gtest/include/gtest/gtest.h"
55 #include "third_party/icu/source/common/unicode/locid.h"
56 #include "ui/base/accelerators/accelerator.h"
57 #include "ui/base/l10n/l10n_util.h"
59 using ::testing::Exactly
;
60 using ::testing::Return
;
65 const char kUsername
[] = "test_user@managedchrome.com";
66 const char kPassword
[] = "test_password";
68 class PrefStoreStub
: public TestingPrefStore
{
70 // TestingPrefStore overrides:
71 virtual PrefReadError
GetReadError() const OVERRIDE
{
72 return PersistentPrefStore::PREF_READ_ERROR_JSON_PARSE
;
75 virtual bool IsInitializationComplete() const OVERRIDE
{
80 virtual ~PrefStoreStub() {}
83 struct SwitchLanguageTestData
{
84 SwitchLanguageTestData() : success(false), done(false) {}
86 std::string requested_locale
;
87 std::string loaded_locale
;
92 void OnLocaleSwitched(SwitchLanguageTestData
* self
,
93 const std::string
& locale
,
94 const std::string
& loaded_locale
,
96 self
->requested_locale
= locale
;
97 self
->loaded_locale
= loaded_locale
;
98 self
->success
= success
;
102 void RunSwitchLanguageTest(const std::string
& locale
,
103 const std::string
& expected_locale
,
104 const bool expect_success
) {
105 SwitchLanguageTestData data
;
106 scoped_ptr
<locale_util::SwitchLanguageCallback
> callback(
107 new locale_util::SwitchLanguageCallback(
108 base::Bind(&OnLocaleSwitched
, base::Unretained(&data
))));
109 locale_util::SwitchLanguage(locale
, true, callback
.Pass());
111 // Token writing moves control to BlockingPool and back.
112 base::RunLoop().RunUntilIdle();
113 content::BrowserThread::GetBlockingPool()->FlushForTesting();
114 base::RunLoop().RunUntilIdle();
116 EXPECT_EQ(data
.done
, true);
117 EXPECT_EQ(data
.requested_locale
, locale
);
118 EXPECT_EQ(data
.loaded_locale
, expected_locale
);
119 EXPECT_EQ(data
.success
, expect_success
);
126 template <class T
, class H
>
127 class MockOutShowHide
: public T
{
129 template <class P
> explicit MockOutShowHide(P p
) : T(p
) {}
130 template <class P
> MockOutShowHide(P p
, H
* actor
)
131 : T(p
, actor
), actor_(actor
) {}
133 H
* actor() const { return actor_
.get(); }
135 MOCK_METHOD0(Show
, void());
136 MOCK_METHOD0(Hide
, void());
139 scoped_ptr
<H
> actor_
;
142 #define MOCK(mock_var, screen_name, mocked_class, actor_class) \
143 mock_var = new MockOutShowHide<mocked_class, actor_class>( \
144 WizardController::default_controller(), new actor_class); \
145 WizardController::default_controller()->screen_name.reset(mock_var); \
146 EXPECT_CALL(*mock_var, Show()).Times(0); \
147 EXPECT_CALL(*mock_var, Hide()).Times(0);
149 class WizardControllerTest
: public WizardInProcessBrowserTest
{
151 WizardControllerTest() : WizardInProcessBrowserTest(
152 WizardController::kTestNoScreenName
) {}
153 virtual ~WizardControllerTest() {}
156 DISALLOW_COPY_AND_ASSIGN(WizardControllerTest
);
159 IN_PROC_BROWSER_TEST_F(WizardControllerTest
, SwitchLanguage
) {
160 ASSERT_TRUE(WizardController::default_controller() != NULL
);
161 WizardController::default_controller()->AdvanceToScreen(
162 WizardController::kNetworkScreenName
);
164 // Checking the default locale. Provided that the profile is cleared in SetUp.
165 EXPECT_EQ("en-US", g_browser_process
->GetApplicationLocale());
166 EXPECT_STREQ("en", icu::Locale::getDefault().getLanguage());
167 EXPECT_FALSE(base::i18n::IsRTL());
168 const std::wstring en_str
=
169 base::UTF16ToWide(l10n_util::GetStringUTF16(IDS_NETWORK_SELECTION_TITLE
));
171 RunSwitchLanguageTest("fr", "fr", true);
172 EXPECT_EQ("fr", g_browser_process
->GetApplicationLocale());
173 EXPECT_STREQ("fr", icu::Locale::getDefault().getLanguage());
174 EXPECT_FALSE(base::i18n::IsRTL());
175 const std::wstring fr_str
=
176 base::UTF16ToWide(l10n_util::GetStringUTF16(IDS_NETWORK_SELECTION_TITLE
));
178 EXPECT_NE(en_str
, fr_str
);
180 RunSwitchLanguageTest("ar", "ar", true);
181 EXPECT_EQ("ar", g_browser_process
->GetApplicationLocale());
182 EXPECT_STREQ("ar", icu::Locale::getDefault().getLanguage());
183 EXPECT_TRUE(base::i18n::IsRTL());
184 const std::wstring ar_str
=
185 base::UTF16ToWide(l10n_util::GetStringUTF16(IDS_NETWORK_SELECTION_TITLE
));
187 EXPECT_NE(fr_str
, ar_str
);
190 class WizardControllerFlowTest
: public WizardControllerTest
{
192 WizardControllerFlowTest() {}
193 // Overriden from InProcessBrowserTest:
194 virtual void SetUpOnMainThread() OVERRIDE
{
195 WizardControllerTest::SetUpOnMainThread();
197 // Make sure that OOBE is run as an "official" build.
198 WizardController::default_controller()->is_official_build_
= true;
200 // Clear portal list (as it is by default in OOBE).
201 NetworkHandler::Get()->network_state_handler()->SetCheckPortalList("");
203 // Set up the mocks for all screens.
204 MOCK(mock_network_screen_
, network_screen_
,
205 MockNetworkScreen
, MockNetworkScreenActor
);
206 MOCK(mock_update_screen_
, update_screen_
,
207 MockUpdateScreen
, MockUpdateScreenActor
);
208 MOCK(mock_eula_screen_
, eula_screen_
, MockEulaScreen
, MockEulaScreenActor
);
209 MOCK(mock_enrollment_screen_
, enrollment_screen_
,
210 MockEnrollmentScreen
, MockEnrollmentScreenActor
);
212 // Switch to the initial screen.
213 EXPECT_EQ(NULL
, WizardController::default_controller()->current_screen());
214 EXPECT_CALL(*mock_network_screen_
, Show()).Times(1);
215 WizardController::default_controller()->AdvanceToScreen(
216 WizardController::kNetworkScreenName
);
219 void OnExit(ScreenObserver::ExitCodes exit_code
) {
220 WizardController::default_controller()->OnExit(exit_code
);
223 MockOutShowHide
<MockNetworkScreen
, MockNetworkScreenActor
>*
224 mock_network_screen_
;
225 MockOutShowHide
<MockUpdateScreen
, MockUpdateScreenActor
>* mock_update_screen_
;
226 MockOutShowHide
<MockEulaScreen
, MockEulaScreenActor
>* mock_eula_screen_
;
227 MockOutShowHide
<MockEnrollmentScreen
,
228 MockEnrollmentScreenActor
>* mock_enrollment_screen_
;
231 DISALLOW_COPY_AND_ASSIGN(WizardControllerFlowTest
);
234 IN_PROC_BROWSER_TEST_F(WizardControllerFlowTest
, ControlFlowMain
) {
235 EXPECT_TRUE(ExistingUserController::current_controller() == NULL
);
236 EXPECT_EQ(WizardController::default_controller()->GetNetworkScreen(),
237 WizardController::default_controller()->current_screen());
238 EXPECT_CALL(*mock_network_screen_
, Hide()).Times(1);
239 EXPECT_CALL(*mock_eula_screen_
, Show()).Times(1);
240 OnExit(ScreenObserver::NETWORK_CONNECTED
);
242 EXPECT_EQ(WizardController::default_controller()->GetEulaScreen(),
243 WizardController::default_controller()->current_screen());
244 EXPECT_CALL(*mock_eula_screen_
, Hide()).Times(1);
245 EXPECT_CALL(*mock_update_screen_
, StartNetworkCheck()).Times(1);
246 EXPECT_CALL(*mock_update_screen_
, Show()).Times(1);
247 OnExit(ScreenObserver::EULA_ACCEPTED
);
248 // Let update screen smooth time process (time = 0ms).
249 content::RunAllPendingInMessageLoop();
251 EXPECT_EQ(WizardController::default_controller()->GetUpdateScreen(),
252 WizardController::default_controller()->current_screen());
253 EXPECT_CALL(*mock_update_screen_
, Hide()).Times(0);
254 EXPECT_CALL(*mock_eula_screen_
, Show()).Times(0);
255 OnExit(ScreenObserver::UPDATE_INSTALLED
);
257 EXPECT_FALSE(ExistingUserController::current_controller() == NULL
);
258 EXPECT_EQ("ethernet,wifi,cellular",
259 NetworkHandler::Get()->network_state_handler()
260 ->GetCheckPortalListForTest());
263 IN_PROC_BROWSER_TEST_F(WizardControllerFlowTest
, ControlFlowErrorUpdate
) {
264 EXPECT_EQ(WizardController::default_controller()->GetNetworkScreen(),
265 WizardController::default_controller()->current_screen());
266 EXPECT_CALL(*mock_update_screen_
, StartNetworkCheck()).Times(0);
267 EXPECT_CALL(*mock_eula_screen_
, Show()).Times(1);
268 EXPECT_CALL(*mock_update_screen_
, Show()).Times(0);
269 EXPECT_CALL(*mock_network_screen_
, Hide()).Times(1);
270 OnExit(ScreenObserver::NETWORK_CONNECTED
);
272 EXPECT_EQ(WizardController::default_controller()->GetEulaScreen(),
273 WizardController::default_controller()->current_screen());
274 EXPECT_CALL(*mock_eula_screen_
, Hide()).Times(1);
275 EXPECT_CALL(*mock_update_screen_
, StartNetworkCheck()).Times(1);
276 EXPECT_CALL(*mock_update_screen_
, Show()).Times(1);
277 OnExit(ScreenObserver::EULA_ACCEPTED
);
278 // Let update screen smooth time process (time = 0ms).
279 content::RunAllPendingInMessageLoop();
281 EXPECT_EQ(WizardController::default_controller()->GetUpdateScreen(),
282 WizardController::default_controller()->current_screen());
283 EXPECT_CALL(*mock_update_screen_
, Hide()).Times(0);
284 EXPECT_CALL(*mock_eula_screen_
, Show()).Times(0);
285 EXPECT_CALL(*mock_eula_screen_
, Hide()).Times(0); // last transition
286 OnExit(ScreenObserver::UPDATE_ERROR_UPDATING
);
288 EXPECT_FALSE(ExistingUserController::current_controller() == NULL
);
291 IN_PROC_BROWSER_TEST_F(WizardControllerFlowTest
, ControlFlowSkipUpdateEnroll
) {
292 EXPECT_EQ(WizardController::default_controller()->GetNetworkScreen(),
293 WizardController::default_controller()->current_screen());
294 EXPECT_CALL(*mock_update_screen_
, StartNetworkCheck()).Times(0);
295 EXPECT_CALL(*mock_eula_screen_
, Show()).Times(1);
296 EXPECT_CALL(*mock_update_screen_
, Show()).Times(0);
297 EXPECT_CALL(*mock_network_screen_
, Hide()).Times(1);
298 OnExit(ScreenObserver::NETWORK_CONNECTED
);
300 EXPECT_EQ(WizardController::default_controller()->GetEulaScreen(),
301 WizardController::default_controller()->current_screen());
302 EXPECT_CALL(*mock_eula_screen_
, Hide()).Times(1);
303 EXPECT_CALL(*mock_update_screen_
, StartNetworkCheck()).Times(0);
304 EXPECT_CALL(*mock_update_screen_
, Show()).Times(0);
305 WizardController::default_controller()->SkipUpdateEnrollAfterEula();
306 EXPECT_CALL(*mock_enrollment_screen_
->actor(),
307 SetParameters(mock_enrollment_screen_
,
308 false, // is_auto_enrollment
309 true, // can_exit_enrollment
312 EXPECT_CALL(*mock_enrollment_screen_
, Show()).Times(1);
313 EXPECT_CALL(*mock_enrollment_screen_
, Hide()).Times(0);
314 OnExit(ScreenObserver::EULA_ACCEPTED
);
315 content::RunAllPendingInMessageLoop();
317 EXPECT_EQ(WizardController::default_controller()->GetEnrollmentScreen(),
318 WizardController::default_controller()->current_screen());
319 EXPECT_TRUE(ExistingUserController::current_controller() == NULL
);
320 EXPECT_EQ("ethernet,wifi,cellular",
321 NetworkHandler::Get()->network_state_handler()
322 ->GetCheckPortalListForTest());
325 IN_PROC_BROWSER_TEST_F(WizardControllerFlowTest
, ControlFlowEulaDeclined
) {
326 EXPECT_EQ(WizardController::default_controller()->GetNetworkScreen(),
327 WizardController::default_controller()->current_screen());
328 EXPECT_CALL(*mock_update_screen_
, StartNetworkCheck()).Times(0);
329 EXPECT_CALL(*mock_eula_screen_
, Show()).Times(1);
330 EXPECT_CALL(*mock_network_screen_
, Hide()).Times(1);
331 OnExit(ScreenObserver::NETWORK_CONNECTED
);
333 EXPECT_EQ(WizardController::default_controller()->GetEulaScreen(),
334 WizardController::default_controller()->current_screen());
335 EXPECT_CALL(*mock_eula_screen_
, Hide()).Times(1);
336 EXPECT_CALL(*mock_network_screen_
, Show()).Times(1);
337 EXPECT_CALL(*mock_network_screen_
, Hide()).Times(0); // last transition
338 OnExit(ScreenObserver::EULA_BACK
);
340 EXPECT_EQ(WizardController::default_controller()->GetNetworkScreen(),
341 WizardController::default_controller()->current_screen());
344 IN_PROC_BROWSER_TEST_F(WizardControllerFlowTest
,
345 ControlFlowEnrollmentCompleted
) {
346 EXPECT_EQ(WizardController::default_controller()->GetNetworkScreen(),
347 WizardController::default_controller()->current_screen());
348 EXPECT_CALL(*mock_update_screen_
, StartNetworkCheck()).Times(0);
349 EXPECT_CALL(*mock_enrollment_screen_
->actor(),
350 SetParameters(mock_enrollment_screen_
,
351 false, // is_auto_enrollment
352 true, // can_exit_enrollment
355 EXPECT_CALL(*mock_enrollment_screen_
, Show()).Times(1);
356 EXPECT_CALL(*mock_network_screen_
, Hide()).Times(1);
358 WizardController::default_controller()->AdvanceToScreen(
359 WizardController::kEnrollmentScreenName
);
360 EnrollmentScreen
* screen
=
361 WizardController::default_controller()->GetEnrollmentScreen();
362 EXPECT_EQ(screen
, WizardController::default_controller()->current_screen());
363 OnExit(ScreenObserver::ENTERPRISE_ENROLLMENT_COMPLETED
);
365 EXPECT_FALSE(ExistingUserController::current_controller() == NULL
);
368 IN_PROC_BROWSER_TEST_F(WizardControllerFlowTest
,
369 ControlFlowAutoEnrollmentCompleted
) {
370 WizardController::default_controller()->SkipPostLoginScreensForTesting();
371 EXPECT_EQ(WizardController::default_controller()->GetNetworkScreen(),
372 WizardController::default_controller()->current_screen());
373 EXPECT_CALL(*mock_update_screen_
, StartNetworkCheck()).Times(0);
375 LoginUtils::Set(new TestLoginUtils(kUsername
, kPassword
));
376 MockConsumer mock_consumer
;
378 // Must have a pending signin to resume after auto-enrollment:
379 LoginDisplayHostImpl::default_host()->StartSignInScreen(LoginScreenContext());
380 EXPECT_FALSE(ExistingUserController::current_controller() == NULL
);
381 ExistingUserController::current_controller()->DoAutoEnrollment();
382 ExistingUserController::current_controller()->set_login_status_consumer(
384 // This calls StartWizard, destroying the current controller() and its mocks;
385 // don't set expectations on those objects.
386 ExistingUserController::current_controller()->CompleteLogin(
387 UserContext(kUsername
, kPassword
, ""));
388 // Run the tasks posted to complete the login:
389 base::MessageLoop::current()->RunUntilIdle();
391 EnrollmentScreen
* screen
=
392 WizardController::default_controller()->GetEnrollmentScreen();
393 EXPECT_EQ(screen
, WizardController::default_controller()->current_screen());
394 // This is the main expectation: after auto-enrollment, login is resumed.
395 EXPECT_CALL(mock_consumer
, OnLoginSuccess(_
)).Times(1);
396 OnExit(ScreenObserver::ENTERPRISE_AUTO_MAGIC_ENROLLMENT_COMPLETED
);
397 // Prevent browser launch when the profile is prepared:
398 browser_shutdown::SetTryingToQuit(true);
399 // Run the tasks posted to complete the login:
400 base::MessageLoop::current()->RunUntilIdle();
403 IN_PROC_BROWSER_TEST_F(WizardControllerFlowTest
, ControlFlowResetScreen
) {
404 EXPECT_EQ(WizardController::default_controller()->GetNetworkScreen(),
405 WizardController::default_controller()->current_screen());
407 LoginDisplayHostImpl::default_host()->StartSignInScreen(LoginScreenContext());
408 EXPECT_FALSE(ExistingUserController::current_controller() == NULL
);
409 ExistingUserController::current_controller()->OnStartDeviceReset();
411 ResetScreen
* screen
=
412 WizardController::default_controller()->GetResetScreen();
413 EXPECT_EQ(screen
, WizardController::default_controller()->current_screen());
415 // After reset screen is canceled, it returns to sign-in screen.
416 // And this destroys WizardController.
417 OnExit(ScreenObserver::RESET_CANCELED
);
418 EXPECT_FALSE(ExistingUserController::current_controller() == NULL
);
421 IN_PROC_BROWSER_TEST_F(WizardControllerFlowTest
,
422 ControlFlowWrongHWIDScreenFromLogin
) {
423 EXPECT_EQ(WizardController::default_controller()->GetNetworkScreen(),
424 WizardController::default_controller()->current_screen());
426 LoginDisplayHostImpl::default_host()->StartSignInScreen(LoginScreenContext());
427 EXPECT_FALSE(ExistingUserController::current_controller() == NULL
);
428 ExistingUserController::current_controller()->ShowWrongHWIDScreen();
430 WrongHWIDScreen
* screen
=
431 WizardController::default_controller()->GetWrongHWIDScreen();
432 EXPECT_EQ(screen
, WizardController::default_controller()->current_screen());
434 // After warning is skipped, user returns to sign-in screen.
435 // And this destroys WizardController.
436 OnExit(ScreenObserver::WRONG_HWID_WARNING_SKIPPED
);
437 EXPECT_FALSE(ExistingUserController::current_controller() == NULL
);
440 class WizardControllerBrokenLocalStateTest
: public WizardControllerTest
{
442 WizardControllerBrokenLocalStateTest()
443 : fake_session_manager_client_(NULL
) {
446 virtual ~WizardControllerBrokenLocalStateTest() {}
448 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE
{
449 WizardControllerTest::SetUpInProcessBrowserTestFixture();
451 FakeDBusThreadManager
* fake_dbus_thread_manager
=
452 new FakeDBusThreadManager();
453 fake_dbus_thread_manager
->SetFakeClients();
454 fake_session_manager_client_
= new FakeSessionManagerClient
;
455 fake_dbus_thread_manager
->SetSessionManagerClient(
456 scoped_ptr
<SessionManagerClient
>(fake_session_manager_client_
));
457 DBusThreadManager::SetInstanceForTesting(fake_dbus_thread_manager
);
460 virtual void SetUpOnMainThread() OVERRIDE
{
461 base::PrefServiceFactory factory
;
462 factory
.set_user_prefs(make_scoped_refptr(new PrefStoreStub()));
463 local_state_
= factory
.Create(new PrefRegistrySimple()).Pass();
464 WizardController::set_local_state_for_testing(local_state_
.get());
466 WizardControllerTest::SetUpOnMainThread();
468 // Make sure that OOBE is run as an "official" build.
469 WizardController::default_controller()->is_official_build_
= true;
472 virtual void TearDownInProcessBrowserTestFixture() OVERRIDE
{
473 WizardControllerTest::TearDownInProcessBrowserTestFixture();
476 ErrorScreen
* GetErrorScreen() {
477 return ((ScreenObserver
*) WizardController::default_controller())->
481 content::WebContents
* GetWebContents() {
482 LoginDisplayHostImpl
* host
= static_cast<LoginDisplayHostImpl
*>(
483 LoginDisplayHostImpl::default_host());
486 WebUILoginView
* webui_login_view
= host
->GetWebUILoginView();
487 if (!webui_login_view
)
489 return webui_login_view
->GetWebContents();
492 void WaitUntilJSIsReady() {
493 LoginDisplayHostImpl
* host
= static_cast<LoginDisplayHostImpl
*>(
494 LoginDisplayHostImpl::default_host());
497 chromeos::OobeUI
* oobe_ui
= host
->GetOobeUI();
500 base::RunLoop run_loop
;
501 const bool oobe_ui_ready
= oobe_ui
->IsJSReady(run_loop
.QuitClosure());
506 bool JSExecuteBooleanExpression(const std::string
& expression
) {
508 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
510 "window.domAutomationController.send(!!(" + expression
+ "));",
515 FakeSessionManagerClient
* fake_session_manager_client() const {
516 return fake_session_manager_client_
;
520 scoped_ptr
<PrefService
> local_state_
;
521 FakeSessionManagerClient
* fake_session_manager_client_
;
523 DISALLOW_COPY_AND_ASSIGN(WizardControllerBrokenLocalStateTest
);
526 IN_PROC_BROWSER_TEST_F(WizardControllerBrokenLocalStateTest
,
527 LocalStateCorrupted
) {
528 // Checks that after wizard controller initialization error screen
529 // in the proper state is displayed.
530 ASSERT_EQ(GetErrorScreen(),
531 WizardController::default_controller()->current_screen());
532 ASSERT_EQ(ErrorScreen::UI_STATE_LOCAL_STATE_ERROR
,
533 GetErrorScreen()->GetUIState());
535 WaitUntilJSIsReady();
537 // Checks visibility of the error message and powerwash button.
538 ASSERT_FALSE(JSExecuteBooleanExpression("$('error-message').hidden"));
539 ASSERT_TRUE(JSExecuteBooleanExpression(
540 "$('error-message').classList.contains('ui-state-local-state-error')"));
541 ASSERT_TRUE(JSExecuteBooleanExpression("$('progress-dots').hidden"));
542 ASSERT_TRUE(JSExecuteBooleanExpression("$('login-header-bar').hidden"));
544 // Emulates user click on the "Restart and Powerwash" button.
545 ASSERT_EQ(0, fake_session_manager_client()->start_device_wipe_call_count());
546 ASSERT_TRUE(content::ExecuteScript(
548 "$('error-message-restart-and-powerwash-button').click();"));
549 ASSERT_EQ(1, fake_session_manager_client()->start_device_wipe_call_count());
552 class WizardControllerProxyAuthOnSigninTest
: public WizardControllerTest
{
554 WizardControllerProxyAuthOnSigninTest()
555 : proxy_server_(net::SpawnedTestServer::TYPE_BASIC_AUTH_PROXY
,
556 net::SpawnedTestServer::kLocalhost
,
559 virtual ~WizardControllerProxyAuthOnSigninTest() {}
561 // Overridden from WizardControllerTest:
562 virtual void SetUp() OVERRIDE
{
563 ASSERT_TRUE(proxy_server_
.Start());
564 WizardControllerTest::SetUp();
567 virtual void SetUpOnMainThread() OVERRIDE
{
568 WizardControllerTest::SetUpOnMainThread();
569 WizardController::default_controller()->AdvanceToScreen(
570 WizardController::kNetworkScreenName
);
573 virtual void SetUpCommandLine(CommandLine
* command_line
) OVERRIDE
{
574 command_line
->AppendSwitchASCII(::switches::kProxyServer
,
575 proxy_server_
.host_port_pair().ToString());
578 net::SpawnedTestServer
& proxy_server() { return proxy_server_
; }
581 net::SpawnedTestServer proxy_server_
;
583 DISALLOW_COPY_AND_ASSIGN(WizardControllerProxyAuthOnSigninTest
);
586 IN_PROC_BROWSER_TEST_F(WizardControllerProxyAuthOnSigninTest
,
587 ProxyAuthDialogOnSigninScreen
) {
588 content::WindowedNotificationObserver
auth_needed_waiter(
589 chrome::NOTIFICATION_AUTH_NEEDED
,
590 content::NotificationService::AllSources());
592 EXPECT_EQ(WizardController::default_controller()->GetNetworkScreen(),
593 WizardController::default_controller()->current_screen());
595 LoginDisplayHostImpl::default_host()->StartSignInScreen(LoginScreenContext());
596 auth_needed_waiter
.Wait();
599 class WizardControllerKioskFlowTest
: public WizardControllerFlowTest
{
601 WizardControllerKioskFlowTest() {}
603 // Overridden from InProcessBrowserTest:
604 virtual void SetUpCommandLine(CommandLine
* command_line
) OVERRIDE
{
605 base::FilePath test_data_dir
;
606 ASSERT_TRUE(chromeos::test_utils::GetTestDataPath(
607 "app_mode", "kiosk_manifest", &test_data_dir
));
608 command_line
->AppendSwitchPath(
609 switches::kAppOemManifestFile
,
610 test_data_dir
.AppendASCII("kiosk_manifest.json"));
614 DISALLOW_COPY_AND_ASSIGN(WizardControllerKioskFlowTest
);
617 IN_PROC_BROWSER_TEST_F(WizardControllerKioskFlowTest
,
618 ControlFlowKioskForcedEnrollment
) {
619 EXPECT_CALL(*mock_enrollment_screen_
->actor(),
620 SetParameters(mock_enrollment_screen_
,
621 false, // is_auto_enrollment
622 false, // can_exit_enrollment
626 EXPECT_TRUE(ExistingUserController::current_controller() == NULL
);
627 EXPECT_EQ(WizardController::default_controller()->GetNetworkScreen(),
628 WizardController::default_controller()->current_screen());
629 EXPECT_CALL(*mock_network_screen_
, Hide()).Times(1);
630 EXPECT_CALL(*mock_eula_screen_
, Show()).Times(1);
631 OnExit(ScreenObserver::NETWORK_CONNECTED
);
633 EXPECT_EQ(WizardController::default_controller()->GetEulaScreen(),
634 WizardController::default_controller()->current_screen());
635 EXPECT_CALL(*mock_eula_screen_
, Hide()).Times(1);
636 EXPECT_CALL(*mock_update_screen_
, StartNetworkCheck()).Times(1);
637 EXPECT_CALL(*mock_update_screen_
, Show()).Times(1);
638 OnExit(ScreenObserver::EULA_ACCEPTED
);
639 // Let update screen smooth time process (time = 0ms).
640 content::RunAllPendingInMessageLoop();
642 EXPECT_EQ(WizardController::default_controller()->GetUpdateScreen(),
643 WizardController::default_controller()->current_screen());
644 EXPECT_CALL(*mock_update_screen_
, Hide()).Times(1);
645 EXPECT_CALL(*mock_enrollment_screen_
, Show()).Times(1);
646 OnExit(ScreenObserver::UPDATE_INSTALLED
);
648 EXPECT_FALSE(StartupUtils::IsOobeCompleted());
650 // Make sure enterprise enrollment page shows up right after update screen.
651 EnrollmentScreen
* screen
=
652 WizardController::default_controller()->GetEnrollmentScreen();
653 EXPECT_EQ(screen
, WizardController::default_controller()->current_screen());
654 OnExit(ScreenObserver::ENTERPRISE_ENROLLMENT_COMPLETED
);
656 EXPECT_TRUE(StartupUtils::IsOobeCompleted());
660 IN_PROC_BROWSER_TEST_F(WizardControllerKioskFlowTest
,
661 ControlFlowEnrollmentBack
) {
663 EXPECT_CALL(*mock_enrollment_screen_
->actor(),
664 SetParameters(mock_enrollment_screen_
,
665 false, // is_auto_enrollment
666 false, // can_exit_enrollment
670 EXPECT_TRUE(ExistingUserController::current_controller() == NULL
);
671 EXPECT_EQ(WizardController::default_controller()->GetNetworkScreen(),
672 WizardController::default_controller()->current_screen());
673 EXPECT_CALL(*mock_network_screen_
, Show()).Times(1);
674 EXPECT_CALL(*mock_network_screen_
, Hide()).Times(1);
675 EXPECT_CALL(*mock_eula_screen_
, Show()).Times(1);
676 OnExit(ScreenObserver::NETWORK_CONNECTED
);
678 EXPECT_EQ(WizardController::default_controller()->GetEulaScreen(),
679 WizardController::default_controller()->current_screen());
680 EXPECT_CALL(*mock_eula_screen_
, Hide()).Times(1);
681 EXPECT_CALL(*mock_update_screen_
, StartNetworkCheck()).Times(1);
682 EXPECT_CALL(*mock_update_screen_
, Show()).Times(1);
683 OnExit(ScreenObserver::EULA_ACCEPTED
);
684 // Let update screen smooth time process (time = 0ms).
685 content::RunAllPendingInMessageLoop();
687 EXPECT_EQ(WizardController::default_controller()->GetUpdateScreen(),
688 WizardController::default_controller()->current_screen());
689 EXPECT_CALL(*mock_update_screen_
, Hide()).Times(1);
690 EXPECT_CALL(*mock_enrollment_screen_
, Show()).Times(1);
691 EXPECT_CALL(*mock_enrollment_screen_
, Hide()).Times(1);
692 OnExit(ScreenObserver::UPDATE_INSTALLED
);
694 EXPECT_FALSE(StartupUtils::IsOobeCompleted());
696 // Make sure enterprise enrollment page shows up right after update screen.
697 EnrollmentScreen
* screen
=
698 WizardController::default_controller()->GetEnrollmentScreen();
699 EXPECT_EQ(screen
, WizardController::default_controller()->current_screen());
700 OnExit(ScreenObserver::ENTERPRISE_ENROLLMENT_BACK
);
702 EXPECT_EQ(WizardController::default_controller()->GetNetworkScreen(),
703 WizardController::default_controller()->current_screen());
704 EXPECT_FALSE(StartupUtils::IsOobeCompleted());
707 // TODO(dzhioev): Add test emaulating device with wrong HWID.
709 // TODO(nkostylev): Add test for WebUI accelerators http://crosbug.com/22571
711 COMPILE_ASSERT(ScreenObserver::EXIT_CODES_COUNT
== 19,
712 add_tests_for_new_control_flow_you_just_introduced
);
714 } // namespace chromeos