Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <memory> | 5 #include <memory> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 37 namespace chromeos { | 37 namespace chromeos { |
| 38 namespace system { | 38 namespace system { |
| 39 | 39 |
| 40 namespace { | 40 namespace { |
| 41 | 41 |
| 42 void ErrorCallbackFunction(const std::string& error_name, | 42 void ErrorCallbackFunction(const std::string& error_name, |
| 43 const std::string& error_message) { | 43 const std::string& error_message) { |
| 44 LOG(ERROR) << "Shill Error: " << error_name << " : " << error_message; | 44 LOG(ERROR) << "Shill Error: " << error_name << " : " << error_message; |
| 45 } | 45 } |
| 46 | 46 |
| 47 bool DeviceDisabledScreenShown() { | |
| 48 WizardController* const wizard_controller = | |
| 49 WizardController::default_controller(); | |
| 50 EXPECT_TRUE(wizard_controller); | |
| 51 return wizard_controller->current_screen() == | |
|
emaxx
2017/04/24 16:49:34
nit: This will crash if wizard_controller is null,
Ivan Šandrk
2017/04/24 17:18:24
Done.
| |
| 52 wizard_controller->GetScreen(OobeScreen::SCREEN_DEVICE_DISABLED); | |
| 53 } | |
| 54 | |
| 47 } // namespace | 55 } // namespace |
| 48 | 56 |
| 49 class DeviceDisablingTest | 57 class DeviceDisablingTest |
| 50 : public OobeBaseTest, | 58 : public OobeBaseTest, |
| 51 public NetworkStateInformer::NetworkStateInformerObserver { | 59 public NetworkStateInformer::NetworkStateInformerObserver { |
| 52 public: | 60 public: |
| 53 DeviceDisablingTest(); | 61 DeviceDisablingTest(); |
| 54 | 62 |
| 63 // Sets up a device state blob that indicates the device is disabled. | |
| 64 void SetDeviceDisabledPolicy(); | |
| 65 | |
| 55 // Sets up a device state blob that indicates the device is disabled, triggers | 66 // Sets up a device state blob that indicates the device is disabled, triggers |
| 56 // a policy plus device state fetch and waits for it to succeed. | 67 // a policy plus device state fetch and waits for it to succeed. |
| 57 void MarkDisabledAndWaitForPolicyFetch(); | 68 void MarkDisabledAndWaitForPolicyFetch(); |
| 58 | 69 |
| 59 std::string GetCurrentScreenName(content::WebContents* web_contents); | 70 std::string GetCurrentScreenName(content::WebContents* web_contents); |
| 60 | 71 |
| 61 protected: | 72 protected: |
| 62 std::unique_ptr<base::RunLoop> network_state_change_wait_run_loop_; | |
| 63 | |
| 64 private: | |
| 65 // OobeBaseTest: | 73 // OobeBaseTest: |
| 66 void SetUpInProcessBrowserTestFixture() override; | 74 void SetUpInProcessBrowserTestFixture() override; |
| 67 void SetUpOnMainThread() override; | 75 void SetUpOnMainThread() override; |
| 68 | 76 |
| 69 // NetworkStateInformer::NetworkStateInformerObserver: | 77 // NetworkStateInformer::NetworkStateInformerObserver: |
| 70 void UpdateState(NetworkError::ErrorReason reason) override; | 78 void UpdateState(NetworkError::ErrorReason reason) override; |
| 71 | 79 |
| 80 std::unique_ptr<base::RunLoop> network_state_change_wait_run_loop_; | |
| 72 FakeSessionManagerClient* fake_session_manager_client_; | 81 FakeSessionManagerClient* fake_session_manager_client_; |
| 73 policy::DevicePolicyCrosTestHelper test_helper_; | 82 policy::DevicePolicyCrosTestHelper test_helper_; |
|
emaxx
2017/04/24 16:49:34
nit: Please make as private all members that aren'
Ivan Šandrk
2017/04/24 17:18:24
Done.
network_state_change_wait_run_loop_ is used
| |
| 74 | 83 |
| 84 private: | |
| 75 DISALLOW_COPY_AND_ASSIGN(DeviceDisablingTest); | 85 DISALLOW_COPY_AND_ASSIGN(DeviceDisablingTest); |
| 76 }; | 86 }; |
| 77 | 87 |
| 78 | 88 |
| 79 DeviceDisablingTest::DeviceDisablingTest() | 89 DeviceDisablingTest::DeviceDisablingTest() |
| 80 : fake_session_manager_client_(new FakeSessionManagerClient) { | 90 : fake_session_manager_client_(new FakeSessionManagerClient) { |
| 81 } | 91 } |
| 82 | 92 |
| 93 void DeviceDisablingTest::SetDeviceDisabledPolicy() { | |
| 94 // Prepare a policy fetch response that indicates the device is disabled. | |
| 95 test_helper_.device_policy()->policy_data().mutable_device_state()-> | |
| 96 set_device_mode(enterprise_management::DeviceState::DEVICE_MODE_DISABLED); | |
| 97 test_helper_.device_policy()->Build(); | |
| 98 fake_session_manager_client_->set_device_policy( | |
| 99 test_helper_.device_policy()->GetBlob()); | |
| 100 } | |
| 101 | |
| 83 void DeviceDisablingTest::MarkDisabledAndWaitForPolicyFetch() { | 102 void DeviceDisablingTest::MarkDisabledAndWaitForPolicyFetch() { |
| 84 base::RunLoop run_loop; | 103 base::RunLoop run_loop; |
| 85 // Set up an |observer| that will wait for the disabled setting to change. | 104 // Set up an |observer| that will wait for the disabled setting to change. |
| 86 std::unique_ptr<CrosSettings::ObserverSubscription> observer = | 105 std::unique_ptr<CrosSettings::ObserverSubscription> observer = |
| 87 CrosSettings::Get()->AddSettingsObserver(kDeviceDisabled, | 106 CrosSettings::Get()->AddSettingsObserver(kDeviceDisabled, |
| 88 run_loop.QuitClosure()); | 107 run_loop.QuitClosure()); |
| 89 // Prepare a policy fetch response that indicates the device is disabled. | 108 SetDeviceDisabledPolicy(); |
| 90 test_helper_.device_policy()->policy_data().mutable_device_state()-> | |
| 91 set_device_mode(enterprise_management::DeviceState::DEVICE_MODE_DISABLED); | |
| 92 test_helper_.device_policy()->Build(); | |
| 93 fake_session_manager_client_->set_device_policy( | |
| 94 test_helper_.device_policy()->GetBlob()); | |
| 95 // Trigger a policy fetch. | 109 // Trigger a policy fetch. |
| 96 fake_session_manager_client_->OnPropertyChangeComplete(true); | 110 fake_session_manager_client_->OnPropertyChangeComplete(true); |
| 97 // Wait for the policy fetch to complete and the disabled setting to change. | 111 // Wait for the policy fetch to complete and the disabled setting to change. |
| 98 run_loop.Run(); | 112 run_loop.Run(); |
| 99 } | 113 } |
| 100 | 114 |
| 101 std::string DeviceDisablingTest::GetCurrentScreenName( | 115 std::string DeviceDisablingTest::GetCurrentScreenName( |
| 102 content::WebContents* web_contents ) { | 116 content::WebContents* web_contents ) { |
| 103 std::string screen_name; | 117 std::string screen_name; |
| 104 if (!content::ExecuteScriptAndExtractString( | 118 if (!content::ExecuteScriptAndExtractString( |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 128 // Set up fake networks. | 142 // Set up fake networks. |
| 129 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> | 143 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> |
| 130 SetupDefaultEnvironment(); | 144 SetupDefaultEnvironment(); |
| 131 } | 145 } |
| 132 | 146 |
| 133 void DeviceDisablingTest::UpdateState(NetworkError::ErrorReason reason) { | 147 void DeviceDisablingTest::UpdateState(NetworkError::ErrorReason reason) { |
| 134 network_state_change_wait_run_loop_->Quit(); | 148 network_state_change_wait_run_loop_->Quit(); |
| 135 } | 149 } |
| 136 | 150 |
| 137 IN_PROC_BROWSER_TEST_F(DeviceDisablingTest, DisableDuringNormalOperation) { | 151 IN_PROC_BROWSER_TEST_F(DeviceDisablingTest, DisableDuringNormalOperation) { |
| 138 // Mark the device as disabled and wait until cros settings update. | 152 // Mark the device as disabled and wait until cros settings update. |
|
emaxx
2017/04/24 16:49:34
nit: I'd rather remove these comments here and in
Ivan Šandrk
2017/04/24 17:18:24
Done.
| |
| 139 MarkDisabledAndWaitForPolicyFetch(); | 153 MarkDisabledAndWaitForPolicyFetch(); |
| 140 | 154 |
| 141 // Verify that the device disabled screen is being shown. | 155 // Verify that the device disabled screen is being shown. |
| 142 WizardController* const wizard_controller = | 156 EXPECT_TRUE(DeviceDisabledScreenShown()); |
| 143 WizardController::default_controller(); | |
| 144 ASSERT_TRUE(wizard_controller); | |
| 145 EXPECT_EQ(wizard_controller->GetScreen(OobeScreen::SCREEN_DEVICE_DISABLED), | |
| 146 wizard_controller->current_screen()); | |
| 147 } | 157 } |
| 148 | 158 |
| 149 // Verifies that device disabling works when the ephemeral users policy is | 159 // Verifies that device disabling works when the ephemeral users policy is |
| 150 // enabled. This case warrants its own test because the UI behaves somewhat | 160 // enabled. This case warrants its own test because the UI behaves somewhat |
| 151 // differently when the policy is set: A background job runs on startup that | 161 // differently when the policy is set: A background job runs on startup that |
| 152 // causes the UI to try and show the login screen after some delay. It must | 162 // causes the UI to try and show the login screen after some delay. It must |
| 153 // be ensured that the login screen does not show and does not clobber the | 163 // be ensured that the login screen does not show and does not clobber the |
| 154 // disabled screen. | 164 // disabled screen. |
| 155 IN_PROC_BROWSER_TEST_F(DeviceDisablingTest, DisableWithEphemeralUsers) { | 165 IN_PROC_BROWSER_TEST_F(DeviceDisablingTest, DisableWithEphemeralUsers) { |
| 156 // Connect to the fake Ethernet network. This ensures that Chrome OS will not | 166 // Connect to the fake Ethernet network. This ensures that Chrome OS will not |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 210 network_state_change_wait_run_loop_->Run(); | 220 network_state_change_wait_run_loop_->Run(); |
| 211 network_state_informer->RemoveObserver(this); | 221 network_state_informer->RemoveObserver(this); |
| 212 base::RunLoop().RunUntilIdle(); | 222 base::RunLoop().RunUntilIdle(); |
| 213 | 223 |
| 214 // Verify that the offline error screen was not shown and the device disabled | 224 // Verify that the offline error screen was not shown and the device disabled |
| 215 // screen is still being shown instead. | 225 // screen is still being shown instead. |
| 216 EXPECT_EQ(GetOobeScreenName(OobeScreen::SCREEN_DEVICE_DISABLED), | 226 EXPECT_EQ(GetOobeScreenName(OobeScreen::SCREEN_DEVICE_DISABLED), |
| 217 GetCurrentScreenName(web_contents)); | 227 GetCurrentScreenName(web_contents)); |
| 218 } | 228 } |
| 219 | 229 |
| 230 class PresetPolicyDeviceDisablingTest : public DeviceDisablingTest { | |
|
emaxx
2017/04/24 16:49:34
nit: Please add a short comment about what is spec
Ivan Šandrk
2017/04/24 17:18:24
Done.
| |
| 231 public: | |
| 232 PresetPolicyDeviceDisablingTest() {} | |
| 233 | |
| 234 protected: | |
| 235 // DeviceDisablingTest: | |
| 236 void SetUpInProcessBrowserTestFixture() override { | |
| 237 DeviceDisablingTest::SetUpInProcessBrowserTestFixture(); | |
| 238 SetDeviceDisabledPolicy(); | |
| 239 } | |
| 240 | |
| 241 private: | |
| 242 DISALLOW_COPY_AND_ASSIGN(PresetPolicyDeviceDisablingTest); | |
| 243 }; | |
| 244 | |
| 245 // Same test as the one in DeviceDisablingTest, except the policy is being set | |
| 246 // before Chrome process is started. This test covers a crash (crbug.com/709518) | |
| 247 // in DeviceDisabledScreen where it would try to access DeviceDisablingManager | |
| 248 // even though it wasn't yet constructed fully. | |
| 249 IN_PROC_BROWSER_TEST_F(PresetPolicyDeviceDisablingTest, | |
| 250 DisableDuringNormalOperation) { | |
|
emaxx
2017/04/24 16:49:34
nit: Please find a more relevant name for the test
Ivan Šandrk
2017/04/24 17:18:24
How about DisableBeforeStartup?
| |
| 251 // Verify that the device disabled screen is being shown. | |
| 252 EXPECT_TRUE(DeviceDisabledScreenShown()); | |
| 253 } | |
| 254 | |
| 220 } // namespace system | 255 } // namespace system |
| 221 } // namespace chromeos | 256 } // namespace chromeos |
| OLD | NEW |