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

Side by Side Diff: chrome/browser/chromeos/login/enable_debugging_browsertest.cc

Issue 539273002: Added UI to enable debugging features on CrOS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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
OLDNEW
(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 <string>
6
7 #include "base/prefs/pref_service.h"
8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/chromeos/login/login_manager_test.h"
10 #include "chrome/browser/chromeos/login/startup_utils.h"
11 #include "chrome/browser/chromeos/login/test/oobe_screen_waiter.h"
12 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h"
13 #include "chrome/browser/chromeos/login/ui/oobe_display.h"
14 #include "chrome/browser/chromeos/login/ui/webui_login_view.h"
15 #include "chrome/common/chrome_switches.h"
16 #include "chrome/common/pref_names.h"
17 #include "chromeos/chromeos_switches.h"
18 #include "chromeos/dbus/dbus_thread_manager.h"
19 #include "chromeos/dbus/fake_debug_daemon_client.h"
20 #include "chromeos/dbus/fake_power_manager_client.h"
21 #include "chromeos/dbus/fake_update_engine_client.h"
22 #include "content/public/test/browser_test_utils.h"
23 #include "content/public/test/test_utils.h"
24
25 namespace chromeos {
26
27 class TestDebugDaemonClient : public FakeDebugDaemonClient {
28 public:
29 TestDebugDaemonClient()
30 : got_reply_(false),
31 num_query_debugging_features_(0),
32 num_enable_debugging_features_(0),
33 num_remove_protection_(0) {
34 }
35
36 virtual ~TestDebugDaemonClient() {
37 }
38
39 void ResetWait() {
40 got_reply_ = false;
41 num_query_debugging_features_ = 0;
42 num_enable_debugging_features_ = 0;
43 num_remove_protection_ = 0;
44 }
45
46 int num_query_debugging_features() {
47 return num_query_debugging_features_;
48 }
49
50 int num_enable_debugging_features() {
51 return num_enable_debugging_features_;
52 }
53
54 int num_remove_protection() {
55 return num_remove_protection_;
56 }
57
58 virtual void SetDebuggingFeaturesStatus(int featues_mask) override {
59 ResetWait();
60 FakeDebugDaemonClient::SetDebuggingFeaturesStatus(featues_mask);
61 }
62
63 void WaitUntilCalled() {
64 if (got_reply_)
65 return;
66
67 runner_ = new content::MessageLoopRunner;
68 runner_->Run();
69 }
70
71 virtual void EnableDebuggingFeatures(
72 const std::string& password,
73 const EnableDebuggingCallback& callback) override {
74 FakeDebugDaemonClient::EnableDebuggingFeatures(
75 password,
76 base::Bind(&TestDebugDaemonClient::OnEnableDebuggingFeatures,
77 base::Unretained(this),
78 callback));
79 }
80
81 virtual void RemoveRootfsVerification(
82 const DebugDaemonClient::EnableDebuggingCallback& callback) override {
83 FakeDebugDaemonClient::RemoveRootfsVerification(
84 base::Bind(&TestDebugDaemonClient::OnRemoveRootfsVerification,
85 base::Unretained(this),
86 callback));
87 }
88
89 virtual void QueryDebuggingFeatures(
90 const DebugDaemonClient::QueryDevFeaturesCallback& callback) override {
91 LOG(WARNING) << "QueryDebuggingFeatures";
92 FakeDebugDaemonClient::QueryDebuggingFeatures(
93 base::Bind(&TestDebugDaemonClient::OnQueryDebuggingFeatures,
94 base::Unretained(this),
95 callback));
96 }
97
98 void OnRemoveRootfsVerification(
99 const DebugDaemonClient::EnableDebuggingCallback& original_callback,
100 bool succeeded) {
101 LOG(WARNING) << "OnRemoveRootfsVerification: succeeded = " << succeeded;
102 base::MessageLoop::current()->PostTask(
103 FROM_HERE,
104 base::Bind(original_callback, succeeded));
105 if (runner_.get())
106 runner_->Quit();
107 else
108 got_reply_ = true;
109
110 num_remove_protection_++;
111 }
112
113 void OnQueryDebuggingFeatures(
114 const DebugDaemonClient::QueryDevFeaturesCallback& original_callback,
115 bool succeeded,
116 int feature_mask) {
117 LOG(WARNING) << "OnQueryDebuggingFeatures: succeeded = " << succeeded
118 << ", feature_mask = " << feature_mask;
119 base::MessageLoop::current()->PostTask(
120 FROM_HERE,
121 base::Bind(original_callback, succeeded, feature_mask));
122 if (runner_.get())
123 runner_->Quit();
124 else
125 got_reply_ = true;
126
127 num_query_debugging_features_++;
128 }
129
130 void OnEnableDebuggingFeatures(
131 const DebugDaemonClient::EnableDebuggingCallback& original_callback,
132 bool succeeded) {
133 LOG(WARNING) << "OnEnableDebuggingFeatures: succeeded = " << succeeded
134 << ", feature_mask = ";
135 base::MessageLoop::current()->PostTask(
136 FROM_HERE,
137 base::Bind(original_callback, succeeded));
138 if (runner_.get())
139 runner_->Quit();
140 else
141 got_reply_ = true;
142
143 num_enable_debugging_features_++;
144 }
145
146 private:
147 scoped_refptr<content::MessageLoopRunner> runner_;
148 bool got_reply_;
149 int num_query_debugging_features_;
150 int num_enable_debugging_features_;
151 int num_remove_protection_;
152 };
153
154 class EnableDebuggingTest : public LoginManagerTest {
155 public:
156 EnableDebuggingTest() : LoginManagerTest(false),
157 debug_daemon_client_(NULL),
158 power_manager_client_(NULL) {
159 }
160 virtual ~EnableDebuggingTest() {}
161
162 virtual void SetUpCommandLine(base::CommandLine* command_line) override {
163 LoginManagerTest::SetUpCommandLine(command_line);
164 command_line->AppendSwitch(chromeos::switches::kSystemDevMode);
165 }
166
167 // LoginManagerTest overrides:
168 virtual void SetUpInProcessBrowserTestFixture() override {
169 scoped_ptr<DBusThreadManagerSetter> dbus_setter =
170 chromeos::DBusThreadManager::GetSetterForTesting();
171 power_manager_client_ = new FakePowerManagerClient;
172 dbus_setter->SetPowerManagerClient(
173 scoped_ptr<PowerManagerClient>(power_manager_client_));
174 debug_daemon_client_ = new TestDebugDaemonClient;
175 dbus_setter->SetDebugDaemonClient(
176 scoped_ptr<DebugDaemonClient>(debug_daemon_client_));
177
178 LoginManagerTest::SetUpInProcessBrowserTestFixture();
179 }
180
181 bool JSExecuted(const std::string& script) {
182 return content::ExecuteScript(web_contents(), script);
183 }
184
185 void WaitUntilJSIsReady() {
186 LoginDisplayHostImpl* host = static_cast<LoginDisplayHostImpl*>(
187 LoginDisplayHostImpl::default_host());
188 if (!host)
189 return;
190 chromeos::OobeUI* oobe_ui = host->GetOobeUI();
191 if (!oobe_ui)
192 return;
193 base::RunLoop run_loop;
194 const bool oobe_ui_ready = oobe_ui->IsJSReady(run_loop.QuitClosure());
195 if (!oobe_ui_ready)
196 run_loop.Run();
197 }
198
199 void InvokeEnableDebuggingScreen() {
200 ASSERT_TRUE(JSExecuted("cr.ui.Oobe.handleAccelerator('debugging');"));
201 OobeScreenWaiter(OobeDisplay::SCREEN_OOBE_ENABLE_DEBUGGING).Wait();
202 }
203
204 void CloseEnableDebuggingScreen() {
205 ASSERT_TRUE(JSExecuted("$('debugging-cancel-button').click();"));
206 }
207
208 void ClickRemoveProtectionButton() {
209 ASSERT_TRUE(JSExecuted("$('debugging-remove-protection-button').click();"));
210 }
211
212 void ClickEnableButton() {
213 ASSERT_TRUE(JSExecuted("$('debugging-enable-button').click();"));
214 }
215
216 void ClickOKButton() {
217 ASSERT_TRUE(JSExecuted("$('debugging-ok-button').click();"));
218 }
219
220 void ShowRemoveProtectionScreen() {
221 debug_daemon_client_->SetDebuggingFeaturesStatus(
222 DebugDaemonClient::DEV_FEATURE_NONE);
223 WaitUntilJSIsReady();
224 JSExpect("!!document.querySelector('#debugging.hidden')");
225 InvokeEnableDebuggingScreen();
226 JSExpect("!document.querySelector('#debugging.hidden')");
227 debug_daemon_client_->WaitUntilCalled();
228 base::MessageLoop::current()->RunUntilIdle();
229 JSExpect("!!document.querySelector('#debugging.remove-protection-view')");
230 JSExpect("!document.querySelector('#debugging.setup-view')");
231 JSExpect("!document.querySelector('#debugging.done-view')");
232 JSExpect("!document.querySelector('#debugging.wait-view')");
233 }
234
235 void ShowSetupScreen() {
236 debug_daemon_client_->SetDebuggingFeaturesStatus(
237 DebugDaemonClient::DEV_FEATURE_ROOTFS_VERIFICATION_REMOVED);
238 WaitUntilJSIsReady();
239 JSExpect("!!document.querySelector('#debugging.hidden')");
240 InvokeEnableDebuggingScreen();
241 JSExpect("!document.querySelector('#debugging.hidden')");
242 debug_daemon_client_->WaitUntilCalled();
243 base::MessageLoop::current()->RunUntilIdle();
244 JSExpect("!document.querySelector('#debugging.remove-protection-view')");
245 JSExpect("!!document.querySelector('#debugging.setup-view')");
246 JSExpect("!document.querySelector('#debugging.done-view')");
247 JSExpect("!document.querySelector('#debugging.wait-view')");
248 }
249
250 TestDebugDaemonClient* debug_daemon_client_;
251 FakePowerManagerClient* power_manager_client_;
252 };
253
254 // Show remove protection screen, click on [Cancel] button.
255 IN_PROC_BROWSER_TEST_F(EnableDebuggingTest, ShowAndCancelRemoveProtection) {
256 ShowRemoveProtectionScreen();
257 CloseEnableDebuggingScreen();
258 JSExpect("!!document.querySelector('#debugging.hidden')");
259
260 EXPECT_EQ(debug_daemon_client_->num_query_debugging_features(), 1);
261 EXPECT_EQ(debug_daemon_client_->num_enable_debugging_features(), 0);
262 EXPECT_EQ(debug_daemon_client_->num_remove_protection(), 0);
263 }
264
265 // Show remove protection, click on [Remove protection] button and wait for
266 // reboot.
267 IN_PROC_BROWSER_TEST_F(EnableDebuggingTest, ShowAndRemoveProtection) {
268 ShowRemoveProtectionScreen();
269 debug_daemon_client_->ResetWait();
270 ClickRemoveProtectionButton();
271 debug_daemon_client_->WaitUntilCalled();
272 JSExpect("!!document.querySelector('#debugging.wait-view')");
273 // Check if we have rebooted after enabling.
274 base::MessageLoop::current()->RunUntilIdle();
275 EXPECT_EQ(debug_daemon_client_->num_remove_protection(), 1);
276 EXPECT_EQ(debug_daemon_client_->num_enable_debugging_features(), 0);
277 EXPECT_EQ(power_manager_client_->num_request_restart_calls(), 1);
278
279 }
280
281 // Show setup screen. Click on [Enable] button. Wait until done screen is shown.
282 IN_PROC_BROWSER_TEST_F(EnableDebuggingTest, ShowSetup) {
283 ShowSetupScreen();
284 debug_daemon_client_->ResetWait();
285 ClickEnableButton();
286 debug_daemon_client_->WaitUntilCalled();
287 base::MessageLoop::current()->RunUntilIdle();
288 JSExpect("!!document.querySelector('#debugging.done-view')");
289 EXPECT_EQ(debug_daemon_client_->num_enable_debugging_features(), 1);
290 EXPECT_EQ(debug_daemon_client_->num_remove_protection(), 0);
291 }
292
293 class EnableDebuggingNonDevTest : public EnableDebuggingTest {
294 public:
295 EnableDebuggingNonDevTest() {
296 }
297
298 virtual void SetUpCommandLine(base::CommandLine* command_line) override {
299 // Skip EnableDebuggingTest::SetUpCommandLine().
300 LoginManagerTest::SetUpCommandLine(command_line);
301 }
302
303 // LoginManagerTest overrides:
304 virtual void SetUpInProcessBrowserTestFixture() override {
305 scoped_ptr<DBusThreadManagerSetter> dbus_setter =
306 chromeos::DBusThreadManager::GetSetterForTesting();
307 dbus_setter->SetDebugDaemonClient(
308 scoped_ptr<DebugDaemonClient>(new FakeDebugDaemonClient));
309 LoginManagerTest::SetUpInProcessBrowserTestFixture();
310 }
311 };
312
313 // Try to show enable debugging dialog, we should see error screen here.
314 IN_PROC_BROWSER_TEST_F(EnableDebuggingNonDevTest, NoShowInNonDevMode) {
315 JSExpect("!!document.querySelector('#debugging.hidden')");
316 InvokeEnableDebuggingScreen();
317 JSExpect("!document.querySelector('#debugging.hidden')");
318 base::MessageLoop::current()->RunUntilIdle();
319 JSExpect("!!document.querySelector('#debugging.error-view')");
320 JSExpect("!document.querySelector('#debugging.remove-protection-view')");
321 JSExpect("!document.querySelector('#debugging.setup-view')");
322 JSExpect("!document.querySelector('#debugging.done-view')");
323 JSExpect("!document.querySelector('#debugging.wait-view')");
324 }
325
326 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/app_launch_signin_screen.cc ('k') | chrome/browser/chromeos/login/existing_user_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698