summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/login/enrollment/enrollment_screen_browsertest.cc
blob: ea3ff85527ac2bc45bb00695e6e0185f9a356b2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/basictypes.h"
#include "base/command_line.h"
#include "base/path_service.h"
#include "base/run_loop.h"
#include "chrome/browser/chromeos/login/enrollment/enrollment_screen.h"
#include "chrome/browser/chromeos/login/screens/mock_screen_observer.h"
#include "chrome/browser/chromeos/login/startup_utils.h"
#include "chrome/browser/chromeos/login/test/wizard_in_process_browser_test.h"
#include "chrome/browser/chromeos/login/wizard_controller.h"
#include "chrome/test/base/ui_test_utils.h"
#include "chromeos/chromeos_switches.h"
#include "chromeos/chromeos_test_utils.h"
#include "content/public/test/test_utils.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

using testing::InvokeWithoutArgs;
using testing::Mock;

namespace chromeos {

class EnrollmentScreenTest : public WizardInProcessBrowserTest {
 public:
  EnrollmentScreenTest()
      : WizardInProcessBrowserTest(
            WizardController::kEnrollmentScreenName) {}

 private:
  DISALLOW_COPY_AND_ASSIGN(EnrollmentScreenTest);
};

IN_PROC_BROWSER_TEST_F(EnrollmentScreenTest, TestCancel) {
  ASSERT_TRUE(WizardController::default_controller() != NULL);

  EnrollmentScreen* enrollment_screen =
      EnrollmentScreen::Get(WizardController::default_controller());
  ASSERT_TRUE(enrollment_screen != NULL);

  base::RunLoop run_loop;
  MockScreenObserver mock_screen_observer;
  static_cast<WizardScreen*>(enrollment_screen)->screen_observer_ =
      &mock_screen_observer;

  ASSERT_EQ(WizardController::default_controller()->current_screen(),
            enrollment_screen);

  EXPECT_CALL(mock_screen_observer,
              OnExit(ScreenObserver::ENTERPRISE_ENROLLMENT_COMPLETED))
      .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
  enrollment_screen->OnCancel();
  content::RunThisRunLoop(&run_loop);
  Mock::VerifyAndClearExpectations(&mock_screen_observer);

  static_cast<WizardScreen*>(enrollment_screen)->screen_observer_ =
      WizardController::default_controller();
}

// Flaky test: crbug.com/394069
IN_PROC_BROWSER_TEST_F(EnrollmentScreenTest, DISABLED_TestSuccess) {
  ASSERT_TRUE(WizardController::default_controller() != NULL);
  EXPECT_FALSE(StartupUtils::IsOobeCompleted());

  EnrollmentScreen* enrollment_screen =
      EnrollmentScreen::Get(WizardController::default_controller());
  ASSERT_TRUE(enrollment_screen != NULL);

  base::RunLoop run_loop;
  MockScreenObserver mock_screen_observer;
  static_cast<WizardScreen*>(enrollment_screen)->screen_observer_ =
      &mock_screen_observer;

  ASSERT_EQ(WizardController::default_controller()->current_screen(),
            enrollment_screen);

  enrollment_screen->ReportEnrollmentStatus(policy::EnrollmentStatus::ForStatus(
      policy::EnrollmentStatus::STATUS_SUCCESS));
  run_loop.RunUntilIdle();
  EXPECT_TRUE(StartupUtils::IsOobeCompleted());

  static_cast<WizardScreen*>(enrollment_screen)->screen_observer_ =
      WizardController::default_controller();
}

class ProvisionedEnrollmentScreenTest : public EnrollmentScreenTest {
 public:
  ProvisionedEnrollmentScreenTest() {}

 private:
  // Overridden from InProcessBrowserTest:
  virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
    base::FilePath test_data_dir;
    ASSERT_TRUE(chromeos::test_utils::GetTestDataPath(
                    "app_mode", "kiosk_manifest", &test_data_dir));
    command_line->AppendSwitchPath(
        switches::kAppOemManifestFile,
        test_data_dir.AppendASCII("kiosk_manifest.json"));
  }

  DISALLOW_COPY_AND_ASSIGN(ProvisionedEnrollmentScreenTest);
};

IN_PROC_BROWSER_TEST_F(ProvisionedEnrollmentScreenTest, TestBackButton) {
  ASSERT_TRUE(WizardController::default_controller() != NULL);

  EnrollmentScreen* enrollment_screen =
      EnrollmentScreen::Get(WizardController::default_controller());
  ASSERT_TRUE(enrollment_screen != NULL);

  base::RunLoop run_loop;
  MockScreenObserver mock_screen_observer;
  static_cast<WizardScreen*>(enrollment_screen)->screen_observer_ =
      &mock_screen_observer;

  ASSERT_EQ(WizardController::default_controller()->current_screen(),
            enrollment_screen);

  EXPECT_CALL(mock_screen_observer,
              OnExit(ScreenObserver::ENTERPRISE_ENROLLMENT_BACK))
      .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
  enrollment_screen->OnCancel();
  content::RunThisRunLoop(&run_loop);
  Mock::VerifyAndClearExpectations(&mock_screen_observer);

  static_cast<WizardScreen*>(enrollment_screen)->screen_observer_ =
      WizardController::default_controller();
}

}  // namespace chromeos