OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "chrome/browser/chromeos/login/screens/device_disabled_screen.h" |
| 6 |
| 7 #include "base/command_line.h" |
| 8 #include "base/macros.h" |
| 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/prefs/scoped_user_pref_update.h" |
| 11 #include "base/prefs/testing_pref_service.h" |
| 12 #include "chrome/browser/browser_process_platform_part.h" |
| 13 #include "chrome/browser/chromeos/login/screens/mock_device_disabled_screen_acto
r.h" |
| 14 #include "chrome/browser/chromeos/login/screens/screen_observer.h" |
| 15 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| 16 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" |
| 17 #include "chrome/browser/chromeos/policy/server_backed_device_state.h" |
| 18 #include "chrome/browser/chromeos/policy/stub_enterprise_install_attributes.h" |
| 19 #include "chrome/common/pref_names.h" |
| 20 #include "chrome/test/base/testing_browser_process.h" |
| 21 #include "chromeos/chromeos_switches.h" |
| 22 #include "components/policy/core/common/cloud/cloud_policy_constants.h" |
| 23 #include "testing/gmock/include/gmock/gmock.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" |
| 25 |
| 26 using ::testing::_; |
| 27 |
| 28 namespace chromeos { |
| 29 |
| 30 namespace { |
| 31 |
| 32 const char kDisabledMessage[] = "Device disabled."; |
| 33 |
| 34 } |
| 35 |
| 36 class DeviceDisabledScreenTest : public testing::Test, public ScreenObserver { |
| 37 public: |
| 38 DeviceDisabledScreenTest(); |
| 39 ~DeviceDisabledScreenTest() override; |
| 40 |
| 41 // testing::Test: |
| 42 void SetUp() override; |
| 43 void TearDown() override; |
| 44 |
| 45 // ScreenObserver: |
| 46 MOCK_METHOD1(OnExit, void(ExitCodes)); |
| 47 void ShowCurrentScreen() override; |
| 48 void OnSetUserNamePassword(const std::string& username, |
| 49 const std::string& password) override; |
| 50 void SetUsageStatisticsReporting(bool val) override; |
| 51 bool GetUsageStatisticsReporting() const override; |
| 52 void SetHostConfiguration() override; |
| 53 void ConfigureHost(bool accepted_eula, |
| 54 const std::string& lang, |
| 55 const std::string& timezone, |
| 56 bool send_reports, |
| 57 const std::string& keyboard_layout) override; |
| 58 ErrorScreen* GetErrorScreen() override; |
| 59 void ShowErrorScreen() override; |
| 60 void HideErrorScreen(BaseScreen* parent_screen) override; |
| 61 |
| 62 void SetDeviceDisabled(bool disabled); |
| 63 void SetDeviceMode(policy::DeviceMode device_mode); |
| 64 |
| 65 void ExpectScreenToNotShow(); |
| 66 void ExpectScreenToShow(); |
| 67 |
| 68 void TryToShowScreen(); |
| 69 |
| 70 private: |
| 71 scoped_ptr<DeviceDisabledScreen> screen_; |
| 72 scoped_ptr<MockDeviceDisabledScreenActor> actor_; |
| 73 TestingPrefServiceSimple local_state_; |
| 74 policy::ScopedStubEnterpriseInstallAttributes install_attributes_; |
| 75 |
| 76 DISALLOW_COPY_AND_ASSIGN(DeviceDisabledScreenTest); |
| 77 }; |
| 78 |
| 79 DeviceDisabledScreenTest::DeviceDisabledScreenTest() |
| 80 : install_attributes_("", "", "", policy::DEVICE_MODE_NOT_SET) { |
| 81 } |
| 82 |
| 83 DeviceDisabledScreenTest::~DeviceDisabledScreenTest() { |
| 84 } |
| 85 |
| 86 void DeviceDisabledScreenTest::SetUp() { |
| 87 TestingBrowserProcess::GetGlobal()->SetLocalState(&local_state_); |
| 88 policy::DeviceCloudPolicyManagerChromeOS::RegisterPrefs( |
| 89 local_state_.registry()); |
| 90 |
| 91 actor_.reset(new MockDeviceDisabledScreenActor); |
| 92 screen_.reset(new DeviceDisabledScreen(this, actor_.get())); |
| 93 } |
| 94 |
| 95 void DeviceDisabledScreenTest::TearDown() { |
| 96 TestingBrowserProcess::GetGlobal()->SetLocalState(nullptr); |
| 97 } |
| 98 |
| 99 void DeviceDisabledScreenTest::ShowCurrentScreen() { |
| 100 } |
| 101 |
| 102 void DeviceDisabledScreenTest::OnSetUserNamePassword( |
| 103 const std::string& username, |
| 104 const std::string& password) { |
| 105 } |
| 106 |
| 107 void DeviceDisabledScreenTest::SetUsageStatisticsReporting(bool val) { |
| 108 } |
| 109 |
| 110 bool DeviceDisabledScreenTest::GetUsageStatisticsReporting() const { |
| 111 return false; |
| 112 } |
| 113 |
| 114 void DeviceDisabledScreenTest::SetHostConfiguration() { |
| 115 } |
| 116 |
| 117 void DeviceDisabledScreenTest::ConfigureHost( |
| 118 bool accepted_eula, |
| 119 const std::string& lang, |
| 120 const std::string& timezone, |
| 121 bool send_reports, |
| 122 const std::string& keyboard_layout) { |
| 123 } |
| 124 |
| 125 ErrorScreen* DeviceDisabledScreenTest::GetErrorScreen() { |
| 126 return nullptr; |
| 127 } |
| 128 |
| 129 void DeviceDisabledScreenTest::ShowErrorScreen() { |
| 130 } |
| 131 |
| 132 void DeviceDisabledScreenTest::HideErrorScreen(BaseScreen* parent_screen) { |
| 133 } |
| 134 |
| 135 void DeviceDisabledScreenTest::SetDeviceDisabled(bool disabled) { |
| 136 DictionaryPrefUpdate dict(&local_state_, prefs::kServerBackedDeviceState); |
| 137 dict->SetBoolean(policy::kDeviceStateDisabled, disabled); |
| 138 if (disabled) |
| 139 dict->SetString(policy::kDeviceStateDisabledMessage, kDisabledMessage); |
| 140 } |
| 141 |
| 142 void DeviceDisabledScreenTest::SetDeviceMode(policy::DeviceMode device_mode) { |
| 143 reinterpret_cast<policy::StubEnterpriseInstallAttributes*>( |
| 144 TestingBrowserProcess::GetGlobal()->platform_part()-> |
| 145 browser_policy_connector_chromeos()->GetInstallAttributes())-> |
| 146 SetMode(device_mode); |
| 147 } |
| 148 |
| 149 void DeviceDisabledScreenTest::ExpectScreenToNotShow() { |
| 150 EXPECT_CALL(*actor_, Show(_)).Times(0); |
| 151 EXPECT_CALL(*this, OnExit(ScreenObserver::DEVICE_NOT_DISABLED)).Times(1); |
| 152 } |
| 153 |
| 154 void DeviceDisabledScreenTest::ExpectScreenToShow() { |
| 155 EXPECT_CALL(*actor_, Show(kDisabledMessage)).Times(1); |
| 156 EXPECT_CALL(*this, OnExit(ScreenObserver::DEVICE_NOT_DISABLED)).Times(0); |
| 157 } |
| 158 |
| 159 void DeviceDisabledScreenTest::TryToShowScreen() { |
| 160 screen_->Show(); |
| 161 } |
| 162 |
| 163 // Verifies that the device disabled screen is not shown by default. |
| 164 TEST_F(DeviceDisabledScreenTest, DoNotShowByDefault) { |
| 165 ExpectScreenToNotShow(); |
| 166 TryToShowScreen(); |
| 167 } |
| 168 |
| 169 // Verifies that the device disabled screen is not shown when the device is |
| 170 // explicitly marked as not disabled. |
| 171 TEST_F(DeviceDisabledScreenTest, DoNotShowWhenNotDisabled) { |
| 172 SetDeviceDisabled(false); |
| 173 ExpectScreenToNotShow(); |
| 174 TryToShowScreen(); |
| 175 } |
| 176 |
| 177 // Verifies that the device disabled screen is not shown when device disabling |
| 178 // is turned off by flag, even if the device is marked as disabled. |
| 179 TEST_F(DeviceDisabledScreenTest, DoNotShowWhenTurnedOffByFlag) { |
| 180 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 181 switches::kDisableDeviceDisabling); |
| 182 SetDeviceDisabled(true); |
| 183 ExpectScreenToNotShow(); |
| 184 TryToShowScreen(); |
| 185 } |
| 186 |
| 187 // Verifies that the device disabled screen is not shown when the device is |
| 188 // already enrolled, even if the device is marked as disabled. |
| 189 TEST_F(DeviceDisabledScreenTest, DoNotShowWhenEnterpriseOwned) { |
| 190 SetDeviceMode(policy::DEVICE_MODE_ENTERPRISE); |
| 191 SetDeviceDisabled(true); |
| 192 ExpectScreenToNotShow(); |
| 193 TryToShowScreen(); |
| 194 } |
| 195 |
| 196 // Verifies that the device disabled screen is not shown when the device is |
| 197 // already owned by a consumer, even if the device is marked as disabled. |
| 198 TEST_F(DeviceDisabledScreenTest, DoNotShowWhenConsumerOwned) { |
| 199 SetDeviceMode(policy::DEVICE_MODE_CONSUMER); |
| 200 SetDeviceDisabled(true); |
| 201 ExpectScreenToNotShow(); |
| 202 TryToShowScreen(); |
| 203 } |
| 204 |
| 205 // Verifies that the device disabled screen is shown when the device is marked |
| 206 // as disabled, device disabling is not turned off by flag and the device is not |
| 207 // owned yet. |
| 208 TEST_F(DeviceDisabledScreenTest, ShowWhenDisabledAndNotOwned) { |
| 209 SetDeviceDisabled(true); |
| 210 ExpectScreenToShow(); |
| 211 TryToShowScreen(); |
| 212 } |
| 213 |
| 214 } // namespace chromeos |
OLD | NEW |