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.
4
5 #include "base/basictypes.h"
6 #include "base/command_line.h"
7 #include "base/path_service.h"
8 #include "base/run_loop.h"
9 #include "chrome/browser/chromeos/login/enrollment/enrollment_screen.h"
10 #include "chrome/browser/chromeos/login/screens/mock_screen_observer.h"
11 #include "chrome/browser/chromeos/login/startup_utils.h"
12 #include "chrome/browser/chromeos/login/test/wizard_in_process_browser_test.h"
13 #include "chrome/browser/chromeos/login/wizard_controller.h"
14 #include "chrome/test/base/ui_test_utils.h"
15 #include "chromeos/chromeos_switches.h"
16 #include "chromeos/chromeos_test_utils.h"
17 #include "content/public/test/test_utils.h"
18 #include "testing/gmock/include/gmock/gmock.h"
19 #include "testing/gtest/include/gtest/gtest.h"
20
21 using testing::InvokeWithoutArgs;
22 using testing::Mock;
23
24 namespace chromeos {
25
26 class EnrollmentScreenTest : public WizardInProcessBrowserTest {
27 public:
EnrollmentScreenTest()28 EnrollmentScreenTest()
29 : WizardInProcessBrowserTest(
30 WizardController::kEnrollmentScreenName) {}
31
32 private:
33 DISALLOW_COPY_AND_ASSIGN(EnrollmentScreenTest);
34 };
35
IN_PROC_BROWSER_TEST_F(EnrollmentScreenTest,TestCancel)36 IN_PROC_BROWSER_TEST_F(EnrollmentScreenTest, TestCancel) {
37 ASSERT_TRUE(WizardController::default_controller() != NULL);
38
39 EnrollmentScreen* enrollment_screen =
40 WizardController::default_controller()->GetEnrollmentScreen();
41 ASSERT_TRUE(enrollment_screen != NULL);
42
43 base::RunLoop run_loop;
44 MockScreenObserver mock_screen_observer;
45 static_cast<WizardScreen*>(enrollment_screen)->screen_observer_ =
46 &mock_screen_observer;
47
48 ASSERT_EQ(WizardController::default_controller()->current_screen(),
49 enrollment_screen);
50
51 EXPECT_CALL(mock_screen_observer,
52 OnExit(ScreenObserver::ENTERPRISE_ENROLLMENT_COMPLETED))
53 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
54 enrollment_screen->OnCancel();
55 content::RunThisRunLoop(&run_loop);
56 Mock::VerifyAndClearExpectations(&mock_screen_observer);
57
58 static_cast<WizardScreen*>(enrollment_screen)->screen_observer_ =
59 WizardController::default_controller();
60 }
61
IN_PROC_BROWSER_TEST_F(EnrollmentScreenTest,TestSuccess)62 IN_PROC_BROWSER_TEST_F(EnrollmentScreenTest, TestSuccess) {
63 ASSERT_TRUE(WizardController::default_controller() != NULL);
64 EXPECT_FALSE(StartupUtils::IsOobeCompleted());
65
66 EnrollmentScreen* enrollment_screen =
67 WizardController::default_controller()->GetEnrollmentScreen();
68 ASSERT_TRUE(enrollment_screen != NULL);
69
70 base::RunLoop run_loop;
71 MockScreenObserver mock_screen_observer;
72 static_cast<WizardScreen*>(enrollment_screen)->screen_observer_ =
73 &mock_screen_observer;
74
75 ASSERT_EQ(WizardController::default_controller()->current_screen(),
76 enrollment_screen);
77
78 enrollment_screen->ReportEnrollmentStatus(policy::EnrollmentStatus::ForStatus(
79 policy::EnrollmentStatus::STATUS_SUCCESS));
80 run_loop.RunUntilIdle();
81 EXPECT_TRUE(StartupUtils::IsOobeCompleted());
82
83 static_cast<WizardScreen*>(enrollment_screen)->screen_observer_ =
84 WizardController::default_controller();
85 }
86
87 class ProvisionedEnrollmentScreenTest : public EnrollmentScreenTest {
88 public:
ProvisionedEnrollmentScreenTest()89 ProvisionedEnrollmentScreenTest() {}
90
91 private:
92 // Overridden from InProcessBrowserTest:
SetUpCommandLine(CommandLine * command_line)93 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
94 base::FilePath test_data_dir;
95 ASSERT_TRUE(chromeos::test_utils::GetTestDataPath(
96 "app_mode", "kiosk_manifest", &test_data_dir));
97 command_line->AppendSwitchPath(
98 switches::kAppOemManifestFile,
99 test_data_dir.AppendASCII("kiosk_manifest.json"));
100 }
101
102 DISALLOW_COPY_AND_ASSIGN(ProvisionedEnrollmentScreenTest);
103 };
104
IN_PROC_BROWSER_TEST_F(ProvisionedEnrollmentScreenTest,TestBackButton)105 IN_PROC_BROWSER_TEST_F(ProvisionedEnrollmentScreenTest, TestBackButton) {
106 ASSERT_TRUE(WizardController::default_controller() != NULL);
107
108 EnrollmentScreen* enrollment_screen =
109 WizardController::default_controller()->GetEnrollmentScreen();
110 ASSERT_TRUE(enrollment_screen != NULL);
111
112 base::RunLoop run_loop;
113 MockScreenObserver mock_screen_observer;
114 static_cast<WizardScreen*>(enrollment_screen)->screen_observer_ =
115 &mock_screen_observer;
116
117 ASSERT_EQ(WizardController::default_controller()->current_screen(),
118 enrollment_screen);
119
120 EXPECT_CALL(mock_screen_observer,
121 OnExit(ScreenObserver::ENTERPRISE_ENROLLMENT_BACK))
122 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
123 enrollment_screen->OnCancel();
124 content::RunThisRunLoop(&run_loop);
125 Mock::VerifyAndClearExpectations(&mock_screen_observer);
126
127 static_cast<WizardScreen*>(enrollment_screen)->screen_observer_ =
128 WizardController::default_controller();
129 }
130
131 } // namespace chromeos
132