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 21using testing::InvokeWithoutArgs; 22using testing::Mock; 23 24namespace chromeos { 25 26class EnrollmentScreenTest : public WizardInProcessBrowserTest { 27 public: 28 EnrollmentScreenTest() 29 : WizardInProcessBrowserTest( 30 WizardController::kEnrollmentScreenName) {} 31 32 private: 33 DISALLOW_COPY_AND_ASSIGN(EnrollmentScreenTest); 34}; 35 36IN_PROC_BROWSER_TEST_F(EnrollmentScreenTest, TestCancel) { 37 ASSERT_TRUE(WizardController::default_controller() != NULL); 38 39 EnrollmentScreen* enrollment_screen = 40 EnrollmentScreen::Get(WizardController::default_controller()); 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 62// Flaky test: crbug.com/394069 63IN_PROC_BROWSER_TEST_F(EnrollmentScreenTest, DISABLED_TestSuccess) { 64 ASSERT_TRUE(WizardController::default_controller() != NULL); 65 EXPECT_FALSE(StartupUtils::IsOobeCompleted()); 66 67 EnrollmentScreen* enrollment_screen = 68 EnrollmentScreen::Get(WizardController::default_controller()); 69 ASSERT_TRUE(enrollment_screen != NULL); 70 71 base::RunLoop run_loop; 72 MockScreenObserver mock_screen_observer; 73 static_cast<WizardScreen*>(enrollment_screen)->screen_observer_ = 74 &mock_screen_observer; 75 76 ASSERT_EQ(WizardController::default_controller()->current_screen(), 77 enrollment_screen); 78 79 enrollment_screen->ReportEnrollmentStatus(policy::EnrollmentStatus::ForStatus( 80 policy::EnrollmentStatus::STATUS_SUCCESS)); 81 run_loop.RunUntilIdle(); 82 EXPECT_TRUE(StartupUtils::IsOobeCompleted()); 83 84 static_cast<WizardScreen*>(enrollment_screen)->screen_observer_ = 85 WizardController::default_controller(); 86} 87 88class ProvisionedEnrollmentScreenTest : public EnrollmentScreenTest { 89 public: 90 ProvisionedEnrollmentScreenTest() {} 91 92 private: 93 // Overridden from InProcessBrowserTest: 94 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 95 base::FilePath test_data_dir; 96 ASSERT_TRUE(chromeos::test_utils::GetTestDataPath( 97 "app_mode", "kiosk_manifest", &test_data_dir)); 98 command_line->AppendSwitchPath( 99 switches::kAppOemManifestFile, 100 test_data_dir.AppendASCII("kiosk_manifest.json")); 101 } 102 103 DISALLOW_COPY_AND_ASSIGN(ProvisionedEnrollmentScreenTest); 104}; 105 106IN_PROC_BROWSER_TEST_F(ProvisionedEnrollmentScreenTest, TestBackButton) { 107 ASSERT_TRUE(WizardController::default_controller() != NULL); 108 109 EnrollmentScreen* enrollment_screen = 110 EnrollmentScreen::Get(WizardController::default_controller()); 111 ASSERT_TRUE(enrollment_screen != NULL); 112 113 base::RunLoop run_loop; 114 MockScreenObserver mock_screen_observer; 115 static_cast<WizardScreen*>(enrollment_screen)->screen_observer_ = 116 &mock_screen_observer; 117 118 ASSERT_EQ(WizardController::default_controller()->current_screen(), 119 enrollment_screen); 120 121 EXPECT_CALL(mock_screen_observer, 122 OnExit(ScreenObserver::ENTERPRISE_ENROLLMENT_BACK)) 123 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); 124 enrollment_screen->OnCancel(); 125 content::RunThisRunLoop(&run_loop); 126 Mock::VerifyAndClearExpectations(&mock_screen_observer); 127 128 static_cast<WizardScreen*>(enrollment_screen)->screen_observer_ = 129 WizardController::default_controller(); 130} 131 132} // namespace chromeos 133