Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(304)

Side by Side Diff: chrome/browser/chromeos/system/device_disabling_browsertest.cc

Issue 2843513002: Added a test for crash in DeviceDisabledScreen (Closed)
Patch Set: Nits Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 && wizard_controller->current_screen() ==
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_;
81
82 private:
72 FakeSessionManagerClient* fake_session_manager_client_; 83 FakeSessionManagerClient* fake_session_manager_client_;
73 policy::DevicePolicyCrosTestHelper test_helper_; 84 policy::DevicePolicyCrosTestHelper test_helper_;
74 85
75 DISALLOW_COPY_AND_ASSIGN(DeviceDisablingTest); 86 DISALLOW_COPY_AND_ASSIGN(DeviceDisablingTest);
76 }; 87 };
77 88
78 89
79 DeviceDisablingTest::DeviceDisablingTest() 90 DeviceDisablingTest::DeviceDisablingTest()
80 : fake_session_manager_client_(new FakeSessionManagerClient) { 91 : fake_session_manager_client_(new FakeSessionManagerClient) {
81 } 92 }
82 93
94 void DeviceDisablingTest::SetDeviceDisabledPolicy() {
95 // Prepare a policy fetch response that indicates the device is disabled.
96 test_helper_.device_policy()->policy_data().mutable_device_state()->
97 set_device_mode(enterprise_management::DeviceState::DEVICE_MODE_DISABLED);
98 test_helper_.device_policy()->Build();
99 fake_session_manager_client_->set_device_policy(
100 test_helper_.device_policy()->GetBlob());
101 }
102
83 void DeviceDisablingTest::MarkDisabledAndWaitForPolicyFetch() { 103 void DeviceDisablingTest::MarkDisabledAndWaitForPolicyFetch() {
84 base::RunLoop run_loop; 104 base::RunLoop run_loop;
85 // Set up an |observer| that will wait for the disabled setting to change. 105 // Set up an |observer| that will wait for the disabled setting to change.
86 std::unique_ptr<CrosSettings::ObserverSubscription> observer = 106 std::unique_ptr<CrosSettings::ObserverSubscription> observer =
87 CrosSettings::Get()->AddSettingsObserver(kDeviceDisabled, 107 CrosSettings::Get()->AddSettingsObserver(kDeviceDisabled,
88 run_loop.QuitClosure()); 108 run_loop.QuitClosure());
89 // Prepare a policy fetch response that indicates the device is disabled. 109 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. 110 // Trigger a policy fetch.
96 fake_session_manager_client_->OnPropertyChangeComplete(true); 111 fake_session_manager_client_->OnPropertyChangeComplete(true);
97 // Wait for the policy fetch to complete and the disabled setting to change. 112 // Wait for the policy fetch to complete and the disabled setting to change.
98 run_loop.Run(); 113 run_loop.Run();
99 } 114 }
100 115
101 std::string DeviceDisablingTest::GetCurrentScreenName( 116 std::string DeviceDisablingTest::GetCurrentScreenName(
102 content::WebContents* web_contents ) { 117 content::WebContents* web_contents ) {
103 std::string screen_name; 118 std::string screen_name;
104 if (!content::ExecuteScriptAndExtractString( 119 if (!content::ExecuteScriptAndExtractString(
(...skipping 23 matching lines...) Expand all
128 // Set up fake networks. 143 // Set up fake networks.
129 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> 144 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()->
130 SetupDefaultEnvironment(); 145 SetupDefaultEnvironment();
131 } 146 }
132 147
133 void DeviceDisablingTest::UpdateState(NetworkError::ErrorReason reason) { 148 void DeviceDisablingTest::UpdateState(NetworkError::ErrorReason reason) {
134 network_state_change_wait_run_loop_->Quit(); 149 network_state_change_wait_run_loop_->Quit();
135 } 150 }
136 151
137 IN_PROC_BROWSER_TEST_F(DeviceDisablingTest, DisableDuringNormalOperation) { 152 IN_PROC_BROWSER_TEST_F(DeviceDisablingTest, DisableDuringNormalOperation) {
138 // Mark the device as disabled and wait until cros settings update.
139 MarkDisabledAndWaitForPolicyFetch(); 153 MarkDisabledAndWaitForPolicyFetch();
140 154 EXPECT_TRUE(DeviceDisabledScreenShown());
141 // Verify that the device disabled screen is being shown.
142 WizardController* const wizard_controller =
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 } 155 }
148 156
149 // Verifies that device disabling works when the ephemeral users policy is 157 // Verifies that device disabling works when the ephemeral users policy is
150 // enabled. This case warrants its own test because the UI behaves somewhat 158 // 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 159 // 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 160 // 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 161 // be ensured that the login screen does not show and does not clobber the
154 // disabled screen. 162 // disabled screen.
155 IN_PROC_BROWSER_TEST_F(DeviceDisablingTest, DisableWithEphemeralUsers) { 163 IN_PROC_BROWSER_TEST_F(DeviceDisablingTest, DisableWithEphemeralUsers) {
156 // Connect to the fake Ethernet network. This ensures that Chrome OS will not 164 // 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
210 network_state_change_wait_run_loop_->Run(); 218 network_state_change_wait_run_loop_->Run();
211 network_state_informer->RemoveObserver(this); 219 network_state_informer->RemoveObserver(this);
212 base::RunLoop().RunUntilIdle(); 220 base::RunLoop().RunUntilIdle();
213 221
214 // Verify that the offline error screen was not shown and the device disabled 222 // Verify that the offline error screen was not shown and the device disabled
215 // screen is still being shown instead. 223 // screen is still being shown instead.
216 EXPECT_EQ(GetOobeScreenName(OobeScreen::SCREEN_DEVICE_DISABLED), 224 EXPECT_EQ(GetOobeScreenName(OobeScreen::SCREEN_DEVICE_DISABLED),
217 GetCurrentScreenName(web_contents)); 225 GetCurrentScreenName(web_contents));
218 } 226 }
219 227
228 // Sets the device disabled policy before the browser is started.
229 class PresetPolicyDeviceDisablingTest : public DeviceDisablingTest {
230 public:
231 PresetPolicyDeviceDisablingTest() {}
232
233 protected:
234 // DeviceDisablingTest:
235 void SetUpInProcessBrowserTestFixture() override {
236 DeviceDisablingTest::SetUpInProcessBrowserTestFixture();
237 SetDeviceDisabledPolicy();
238 }
239
240 private:
241 DISALLOW_COPY_AND_ASSIGN(PresetPolicyDeviceDisablingTest);
242 };
243
244 // Same test as the one in DeviceDisablingTest, except the policy is being set
245 // before Chrome process is started. This test covers a crash (crbug.com/709518)
246 // in DeviceDisabledScreen where it would try to access DeviceDisablingManager
247 // even though it wasn't yet constructed fully.
248 IN_PROC_BROWSER_TEST_F(PresetPolicyDeviceDisablingTest,
249 DisableBeforeStartup) {
250 EXPECT_TRUE(DeviceDisabledScreenShown());
251 }
252
220 } // namespace system 253 } // namespace system
221 } // namespace chromeos 254 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698