| 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 <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 InvokeEnableDebuggingScreen() { |
| 186 ASSERT_TRUE(JSExecuted("cr.ui.Oobe.handleAccelerator('debugging');")); |
| 187 OobeScreenWaiter(OobeDisplay::SCREEN_OOBE_ENABLE_DEBUGGING).Wait(); |
| 188 } |
| 189 |
| 190 void CloseEnableDebuggingScreen() { |
| 191 ASSERT_TRUE(JSExecuted("$('debugging-cancel-button').click();")); |
| 192 } |
| 193 |
| 194 void ClickRemoveProtectionButton() { |
| 195 ASSERT_TRUE(JSExecuted("$('debugging-remove-protection-button').click();")); |
| 196 } |
| 197 |
| 198 void ClickEnableButton() { |
| 199 ASSERT_TRUE(JSExecuted("$('debugging-enable-button').click();")); |
| 200 } |
| 201 |
| 202 void ClickOKButton() { |
| 203 ASSERT_TRUE(JSExecuted("$('debugging-ok-button').click();")); |
| 204 } |
| 205 |
| 206 void ShowRemoveProtectionScreen() { |
| 207 debug_daemon_client_->SetDebuggingFeaturesStatus( |
| 208 DebugDaemonClient::DEV_FEATURE_NONE); |
| 209 JSExpect("!!document.querySelector('#debugging.hidden')"); |
| 210 InvokeEnableDebuggingScreen(); |
| 211 JSExpect("!document.querySelector('#debugging.hidden')"); |
| 212 debug_daemon_client_->WaitUntilCalled(); |
| 213 base::MessageLoop::current()->RunUntilIdle(); |
| 214 JSExpect("!!document.querySelector('#debugging.remove-protection-view')"); |
| 215 JSExpect("!document.querySelector('#debugging.setup-view')"); |
| 216 JSExpect("!document.querySelector('#debugging.done-view')"); |
| 217 JSExpect("!document.querySelector('#debugging.wait-view')"); |
| 218 } |
| 219 |
| 220 void ShowSetupScreen() { |
| 221 debug_daemon_client_->SetDebuggingFeaturesStatus( |
| 222 DebugDaemonClient::DEV_FEATURE_ROOTFS_VERIFICATION_REMOVED); |
| 223 JSExpect("!!document.querySelector('#debugging.hidden')"); |
| 224 InvokeEnableDebuggingScreen(); |
| 225 JSExpect("!document.querySelector('#debugging.hidden')"); |
| 226 debug_daemon_client_->WaitUntilCalled(); |
| 227 base::MessageLoop::current()->RunUntilIdle(); |
| 228 JSExpect("!document.querySelector('#debugging.remove-protection-view')"); |
| 229 JSExpect("!!document.querySelector('#debugging.setup-view')"); |
| 230 JSExpect("!document.querySelector('#debugging.done-view')"); |
| 231 JSExpect("!document.querySelector('#debugging.wait-view')"); |
| 232 } |
| 233 |
| 234 TestDebugDaemonClient* debug_daemon_client_; |
| 235 FakePowerManagerClient* power_manager_client_; |
| 236 }; |
| 237 |
| 238 // Show remove protection screen, click on [Cancel] button. |
| 239 IN_PROC_BROWSER_TEST_F(EnableDebuggingTest, ShowAndCancelRemoveProtection) { |
| 240 ShowRemoveProtectionScreen(); |
| 241 CloseEnableDebuggingScreen(); |
| 242 JSExpect("!!document.querySelector('#debugging.hidden')"); |
| 243 |
| 244 EXPECT_EQ(debug_daemon_client_->num_query_debugging_features(), 1); |
| 245 EXPECT_EQ(debug_daemon_client_->num_enable_debugging_features(), 0); |
| 246 EXPECT_EQ(debug_daemon_client_->num_remove_protection(), 0); |
| 247 } |
| 248 |
| 249 // Show remove protection, click on [Remove protection] button and wait for |
| 250 // reboot. |
| 251 IN_PROC_BROWSER_TEST_F(EnableDebuggingTest, ShowAndRemoveProtection) { |
| 252 ShowRemoveProtectionScreen(); |
| 253 debug_daemon_client_->ResetWait(); |
| 254 ClickRemoveProtectionButton(); |
| 255 debug_daemon_client_->WaitUntilCalled(); |
| 256 JSExpect("!!document.querySelector('#debugging.wait-view')"); |
| 257 // Check if we have rebooted after enabling. |
| 258 base::MessageLoop::current()->RunUntilIdle(); |
| 259 EXPECT_EQ(debug_daemon_client_->num_remove_protection(), 1); |
| 260 EXPECT_EQ(debug_daemon_client_->num_enable_debugging_features(), 0); |
| 261 EXPECT_EQ(power_manager_client_->num_request_restart_calls(), 1); |
| 262 |
| 263 } |
| 264 |
| 265 // Show setup screen. Click on [Enable] button. Wait until done screen is shown. |
| 266 IN_PROC_BROWSER_TEST_F(EnableDebuggingTest, ShowSetup) { |
| 267 ShowSetupScreen(); |
| 268 debug_daemon_client_->ResetWait(); |
| 269 ClickEnableButton(); |
| 270 debug_daemon_client_->WaitUntilCalled(); |
| 271 base::MessageLoop::current()->RunUntilIdle(); |
| 272 JSExpect("!!document.querySelector('#debugging.done-view')"); |
| 273 EXPECT_EQ(debug_daemon_client_->num_enable_debugging_features(), 1); |
| 274 EXPECT_EQ(debug_daemon_client_->num_remove_protection(), 0); |
| 275 } |
| 276 |
| 277 class EnableDebuggingNonDevTest : public EnableDebuggingTest { |
| 278 public: |
| 279 EnableDebuggingNonDevTest() { |
| 280 } |
| 281 |
| 282 virtual void SetUpCommandLine(base::CommandLine* command_line) override { |
| 283 // Skip EnableDebuggingTest::SetUpCommandLine(). |
| 284 LoginManagerTest::SetUpCommandLine(command_line); |
| 285 } |
| 286 |
| 287 // LoginManagerTest overrides: |
| 288 virtual void SetUpInProcessBrowserTestFixture() override { |
| 289 scoped_ptr<DBusThreadManagerSetter> dbus_setter = |
| 290 chromeos::DBusThreadManager::GetSetterForTesting(); |
| 291 dbus_setter->SetDebugDaemonClient( |
| 292 scoped_ptr<DebugDaemonClient>(new FakeDebugDaemonClient)); |
| 293 LoginManagerTest::SetUpInProcessBrowserTestFixture(); |
| 294 } |
| 295 }; |
| 296 |
| 297 // Try to show enable debugging dialog, we should see error screen here. |
| 298 IN_PROC_BROWSER_TEST_F(EnableDebuggingNonDevTest, NoShowInNonDevMode) { |
| 299 JSExpect("!!document.querySelector('#debugging.hidden')"); |
| 300 InvokeEnableDebuggingScreen(); |
| 301 JSExpect("!document.querySelector('#debugging.hidden')"); |
| 302 base::MessageLoop::current()->RunUntilIdle(); |
| 303 JSExpect("!!document.querySelector('#debugging.error-view')"); |
| 304 JSExpect("!document.querySelector('#debugging.remove-protection-view')"); |
| 305 JSExpect("!document.querySelector('#debugging.setup-view')"); |
| 306 JSExpect("!document.querySelector('#debugging.done-view')"); |
| 307 JSExpect("!document.querySelector('#debugging.wait-view')"); |
| 308 } |
| 309 |
| 310 } // namespace chromeos |
| OLD | NEW |