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/run_loop.h"
8 #include "chrome/browser/chromeos/login/enrollment/enrollment_screen.h"
9 #include "chrome/browser/chromeos/login/screens/mock_base_screen_delegate.h"
10 #include "chrome/browser/chromeos/login/startup_utils.h"
11 #include "chrome/browser/chromeos/login/test/wizard_in_process_browser_test.h"
12 #include "chrome/browser/chromeos/login/wizard_controller.h"
13 #include "chromeos/chromeos_switches.h"
14 #include "chromeos/chromeos_test_utils.h"
15 #include "content/public/test/test_utils.h"
16 #include "testing/gmock/include/gmock/gmock.h"
17 #include "testing/gtest/include/gtest/gtest.h"
19 using testing::InvokeWithoutArgs;
24 class EnrollmentScreenTest : public WizardInProcessBrowserTest {
26 EnrollmentScreenTest()
27 : WizardInProcessBrowserTest(
28 WizardController::kEnrollmentScreenName) {}
31 DISALLOW_COPY_AND_ASSIGN(EnrollmentScreenTest);
34 IN_PROC_BROWSER_TEST_F(EnrollmentScreenTest, TestCancel) {
35 ASSERT_TRUE(WizardController::default_controller() != NULL);
37 EnrollmentScreen* enrollment_screen =
38 EnrollmentScreen::Get(WizardController::default_controller());
39 ASSERT_TRUE(enrollment_screen != NULL);
41 base::RunLoop run_loop;
42 MockBaseScreenDelegate mock_base_screen_delegate;
43 static_cast<BaseScreen*>(enrollment_screen)->base_screen_delegate_ =
44 &mock_base_screen_delegate;
46 ASSERT_EQ(WizardController::default_controller()->current_screen(),
49 EXPECT_CALL(mock_base_screen_delegate,
50 OnExit(BaseScreenDelegate::ENTERPRISE_ENROLLMENT_COMPLETED))
51 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
52 enrollment_screen->OnCancel();
53 content::RunThisRunLoop(&run_loop);
54 Mock::VerifyAndClearExpectations(&mock_base_screen_delegate);
56 static_cast<BaseScreen*>(enrollment_screen)->base_screen_delegate_ =
57 WizardController::default_controller();
60 // Flaky test: crbug.com/394069
61 IN_PROC_BROWSER_TEST_F(EnrollmentScreenTest, DISABLED_TestSuccess) {
62 ASSERT_TRUE(WizardController::default_controller() != NULL);
63 EXPECT_FALSE(StartupUtils::IsOobeCompleted());
65 EnrollmentScreen* enrollment_screen =
66 EnrollmentScreen::Get(WizardController::default_controller());
67 ASSERT_TRUE(enrollment_screen != NULL);
69 base::RunLoop run_loop;
70 MockBaseScreenDelegate mock_base_screen_delegate;
71 static_cast<BaseScreen*>(enrollment_screen)->base_screen_delegate_ =
72 &mock_base_screen_delegate;
74 ASSERT_EQ(WizardController::default_controller()->current_screen(),
77 enrollment_screen->ReportEnrollmentStatus(policy::EnrollmentStatus::ForStatus(
78 policy::EnrollmentStatus::STATUS_SUCCESS));
79 run_loop.RunUntilIdle();
80 EXPECT_TRUE(StartupUtils::IsOobeCompleted());
82 static_cast<BaseScreen*>(enrollment_screen)->base_screen_delegate_ =
83 WizardController::default_controller();
86 class ProvisionedEnrollmentScreenTest : public EnrollmentScreenTest {
88 ProvisionedEnrollmentScreenTest() {}
91 // Overridden from InProcessBrowserTest:
92 virtual void SetUpCommandLine(CommandLine* command_line) override {
93 base::FilePath test_data_dir;
94 ASSERT_TRUE(chromeos::test_utils::GetTestDataPath(
95 "app_mode", "kiosk_manifest", &test_data_dir));
96 command_line->AppendSwitchPath(
97 switches::kAppOemManifestFile,
98 test_data_dir.AppendASCII("kiosk_manifest.json"));
101 DISALLOW_COPY_AND_ASSIGN(ProvisionedEnrollmentScreenTest);
104 IN_PROC_BROWSER_TEST_F(ProvisionedEnrollmentScreenTest, TestBackButton) {
105 ASSERT_TRUE(WizardController::default_controller() != NULL);
107 EnrollmentScreen* enrollment_screen =
108 EnrollmentScreen::Get(WizardController::default_controller());
109 ASSERT_TRUE(enrollment_screen != NULL);
111 base::RunLoop run_loop;
112 MockBaseScreenDelegate mock_base_screen_delegate;
113 static_cast<BaseScreen*>(enrollment_screen)->base_screen_delegate_ =
114 &mock_base_screen_delegate;
116 ASSERT_EQ(WizardController::default_controller()->current_screen(),
119 EXPECT_CALL(mock_base_screen_delegate,
120 OnExit(BaseScreenDelegate::ENTERPRISE_ENROLLMENT_BACK))
121 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
122 enrollment_screen->OnCancel();
123 content::RunThisRunLoop(&run_loop);
124 Mock::VerifyAndClearExpectations(&mock_base_screen_delegate);
126 static_cast<BaseScreen*>(enrollment_screen)->base_screen_delegate_ =
127 WizardController::default_controller();
130 } // namespace chromeos