1 // Copyright 2014 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/command_line.h"
6 #include "base/memory/scoped_ptr.h"
7 #include "base/run_loop.h"
8 #include "chrome/browser/chromeos/login/wizard_controller.h"
9 #include "chrome/browser/chromeos/policy/device_policy_builder.h"
10 #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h"
11 #include "chrome/browser/chromeos/settings/cros_settings.h"
12 #include "chrome/test/base/in_process_browser_test.h"
13 #include "chromeos/chromeos_switches.h"
14 #include "chromeos/dbus/dbus_thread_manager.h"
15 #include "chromeos/dbus/fake_session_manager_client.h"
16 #include "chromeos/settings/cros_settings_names.h"
17 #include "policy/proto/device_management_backend.pb.h"
22 class DeviceDisablingTest
: public InProcessBrowserTest
{
24 DeviceDisablingTest();
26 // Device policy is updated in two steps:
27 // - First, set up the policy builder that GetDevicePolicyBuilder() returns.
28 // - Second, call SimulatePolicyFetch() to build and flush the resulting
29 // policy blob to the browser.
30 policy::DevicePolicyBuilder
* GetDevicePolicyBuilder();
31 void SimulatePolicyFetch();
34 // InProcessBrowserTest:
35 void SetUpInProcessBrowserTestFixture() override
;
36 void SetUpCommandLine(CommandLine
* command_line
) override
;
38 FakeSessionManagerClient
* fake_session_manager_client_
;
39 policy::DevicePolicyCrosTestHelper test_helper_
;
41 DISALLOW_COPY_AND_ASSIGN(DeviceDisablingTest
);
45 DeviceDisablingTest::DeviceDisablingTest()
46 : fake_session_manager_client_(new FakeSessionManagerClient
) {
49 policy::DevicePolicyBuilder
* DeviceDisablingTest::GetDevicePolicyBuilder() {
50 return test_helper_
.device_policy();
53 void DeviceDisablingTest::SimulatePolicyFetch() {
54 GetDevicePolicyBuilder()->Build();
55 fake_session_manager_client_
->set_device_policy(
56 GetDevicePolicyBuilder()->GetBlob());
57 fake_session_manager_client_
->OnPropertyChangeComplete(true);
60 void DeviceDisablingTest::SetUpInProcessBrowserTestFixture() {
61 DBusThreadManager::GetSetterForTesting()->SetSessionManagerClient(
62 scoped_ptr
<SessionManagerClient
>(fake_session_manager_client_
));
64 test_helper_
.InstallOwnerKey();
65 test_helper_
.MarkAsEnterpriseOwned();
68 void DeviceDisablingTest::SetUpCommandLine(CommandLine
* command_line
) {
69 command_line
->AppendSwitch(switches::kLoginManager
);
70 command_line
->AppendSwitch(switches::kForceLoginManagerInTests
);
73 IN_PROC_BROWSER_TEST_F(DeviceDisablingTest
, DisableDuringNormalOperation
) {
74 // Mark the device as disabled and wait until cros settings update.
75 base::RunLoop run_loop
;
76 scoped_ptr
<CrosSettings::ObserverSubscription
> observer
=
77 CrosSettings::Get()->AddSettingsObserver(
79 run_loop
.QuitClosure());
80 GetDevicePolicyBuilder()->policy_data().mutable_device_state()->
81 set_device_mode(enterprise_management::DeviceState::DEVICE_MODE_DISABLED
);
82 SimulatePolicyFetch();
85 // Verify that the device disabled screen is being shown.
86 WizardController
* wizard_controller
= WizardController::default_controller();
87 ASSERT_TRUE(wizard_controller
);
88 EXPECT_EQ(wizard_controller
->GetScreen(
89 WizardController::kDeviceDisabledScreenName
),
90 wizard_controller
->current_screen());
94 } // namespace chromeos