Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / chromeos / login / enrollment / enrollment_screen_browsertest.cc
blob0a6087b179163f81302dc8d6ea77c6d32f2ee2e9
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;
20 using testing::Mock;
21 using testing::_;
23 namespace chromeos {
25 class EnrollmentScreenTest : public WizardInProcessBrowserTest {
26 public:
27 EnrollmentScreenTest()
28 : WizardInProcessBrowserTest(
29 WizardController::kEnrollmentScreenName) {}
31 private:
32 DISALLOW_COPY_AND_ASSIGN(EnrollmentScreenTest);
35 IN_PROC_BROWSER_TEST_F(EnrollmentScreenTest, TestCancel) {
36 ASSERT_TRUE(WizardController::default_controller() != NULL);
38 EnrollmentScreen* enrollment_screen =
39 EnrollmentScreen::Get(WizardController::default_controller());
40 ASSERT_TRUE(enrollment_screen != NULL);
42 base::RunLoop run_loop;
43 MockBaseScreenDelegate mock_base_screen_delegate;
44 static_cast<BaseScreen*>(enrollment_screen)->base_screen_delegate_ =
45 &mock_base_screen_delegate;
47 ASSERT_EQ(WizardController::default_controller()->current_screen(),
48 enrollment_screen);
50 EXPECT_CALL(mock_base_screen_delegate,
51 OnExit(_, BaseScreenDelegate::ENTERPRISE_ENROLLMENT_COMPLETED, _))
52 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
53 enrollment_screen->OnCancel();
54 content::RunThisRunLoop(&run_loop);
55 Mock::VerifyAndClearExpectations(&mock_base_screen_delegate);
57 static_cast<BaseScreen*>(enrollment_screen)->base_screen_delegate_ =
58 WizardController::default_controller();
61 // Flaky test: crbug.com/394069
62 IN_PROC_BROWSER_TEST_F(EnrollmentScreenTest, DISABLED_TestSuccess) {
63 ASSERT_TRUE(WizardController::default_controller() != NULL);
64 EXPECT_FALSE(StartupUtils::IsOobeCompleted());
66 EnrollmentScreen* enrollment_screen =
67 EnrollmentScreen::Get(WizardController::default_controller());
68 ASSERT_TRUE(enrollment_screen != NULL);
70 base::RunLoop run_loop;
71 MockBaseScreenDelegate mock_base_screen_delegate;
72 static_cast<BaseScreen*>(enrollment_screen)->base_screen_delegate_ =
73 &mock_base_screen_delegate;
75 ASSERT_EQ(WizardController::default_controller()->current_screen(),
76 enrollment_screen);
78 enrollment_screen->OnDeviceEnrolled("");
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 {
87 public:
88 ProvisionedEnrollmentScreenTest() {}
90 private:
91 // Overridden from InProcessBrowserTest:
92 void SetUpCommandLine(base::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(),
117 enrollment_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