Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / chrome / browser / chromeos / login / reset_browsertest.cc
blobc55541aeeac8b3d2a83595d205a2ef32b1a3d620
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.
5 #include <string>
7 #include "base/command_line.h"
8 #include "base/prefs/pref_service.h"
9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/chromeos/login/login_manager_test.h"
11 #include "chrome/browser/chromeos/login/startup_utils.h"
12 #include "chrome/browser/chromeos/login/test/oobe_screen_waiter.h"
13 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h"
14 #include "chrome/browser/chromeos/login/ui/oobe_display.h"
15 #include "chrome/browser/chromeos/login/ui/webui_login_view.h"
16 #include "chrome/common/chrome_switches.h"
17 #include "chrome/common/pref_names.h"
18 #include "chromeos/chromeos_switches.h"
19 #include "chromeos/dbus/dbus_thread_manager.h"
20 #include "chromeos/dbus/fake_power_manager_client.h"
21 #include "chromeos/dbus/fake_session_manager_client.h"
22 #include "chromeos/dbus/fake_update_engine_client.h"
23 #include "content/public/test/browser_test_utils.h"
25 namespace chromeos {
27 namespace {
29 const char kTestUser1[] = "test-user1@gmail.com";
31 } // namespace
33 class ResetTest : public LoginManagerTest {
34 public:
35 ResetTest() : LoginManagerTest(false),
36 update_engine_client_(NULL),
37 session_manager_client_(NULL),
38 power_manager_client_(NULL) {
40 ~ResetTest() override {}
42 void SetUpCommandLine(base::CommandLine* command_line) override {
43 LoginManagerTest::SetUpCommandLine(command_line);
46 // LoginManagerTest overrides:
47 void SetUpInProcessBrowserTestFixture() override {
48 scoped_ptr<DBusThreadManagerSetter> dbus_setter =
49 chromeos::DBusThreadManager::GetSetterForTesting();
50 session_manager_client_ = new FakeSessionManagerClient;
51 dbus_setter->SetSessionManagerClient(
52 scoped_ptr<SessionManagerClient>(session_manager_client_));
53 power_manager_client_ = new FakePowerManagerClient;
54 dbus_setter->SetPowerManagerClient(
55 scoped_ptr<PowerManagerClient>(power_manager_client_));
56 update_engine_client_ = new FakeUpdateEngineClient;
57 dbus_setter->SetUpdateEngineClient(
58 scoped_ptr<UpdateEngineClient>(update_engine_client_));
60 LoginManagerTest::SetUpInProcessBrowserTestFixture();
63 void RegisterSomeUser() {
64 RegisterUser(kTestUser1);
65 StartupUtils::MarkOobeCompleted();
68 bool JSExecuted(const std::string& script) {
69 return content::ExecuteScript(web_contents(), script);
72 void InvokeResetScreen() {
73 ASSERT_TRUE(JSExecuted("cr.ui.Oobe.handleAccelerator('reset');"));
74 OobeScreenWaiter(OobeDisplay::SCREEN_OOBE_RESET).Wait();
77 void InvokeRollbackOption() {
78 ASSERT_TRUE(JSExecuted("cr.ui.Oobe.handleAccelerator('reset');"));
81 void HideRollbackOption() {
82 ASSERT_TRUE(JSExecuted("cr.ui.Oobe.handleAccelerator('reset');"));
85 void CloseResetScreen() {
86 ASSERT_TRUE(JSExecuted("$('reset-cancel-button').click();"));
89 void ClickResetButton() {
90 ASSERT_TRUE(JSExecuted("$('reset-confirm-commit').click();"));
93 void ClickRestartButton() {
94 ASSERT_TRUE(JSExecuted("$('reset-restart-button').click();"));
96 void ClickToConfirmButton() {
97 ASSERT_TRUE(JSExecuted("$('reset-toconfirm-button').click();"));
99 void ClickDismissConfirmationButton() {
100 ASSERT_TRUE(JSExecuted("$('reset-confirm-dismiss').click();"));
103 FakeUpdateEngineClient* update_engine_client_;
104 FakeSessionManagerClient* session_manager_client_;
105 FakePowerManagerClient* power_manager_client_;
108 class ResetFirstAfterBootTest : public ResetTest {
109 public:
110 ~ResetFirstAfterBootTest() override {}
112 void SetUpCommandLine(base::CommandLine* command_line) override {
113 LoginManagerTest::SetUpCommandLine(command_line);
114 command_line->AppendSwitch(switches::kFirstExecAfterBoot);
118 IN_PROC_BROWSER_TEST_F(ResetTest, PRE_ShowAndCancel) {
119 RegisterSomeUser();
122 IN_PROC_BROWSER_TEST_F(ResetTest, ShowAndCancel) {
123 JSExpect("!!document.querySelector('#reset.hidden')");
124 InvokeResetScreen();
125 JSExpect("!document.querySelector('#reset.hidden')");
126 CloseResetScreen();
127 JSExpect("!!document.querySelector('#reset.hidden')");
130 IN_PROC_BROWSER_TEST_F(ResetTest, PRE_RestartBeforePowerwash) {
131 RegisterSomeUser();
134 IN_PROC_BROWSER_TEST_F(ResetTest, RestartBeforePowerwash) {
135 PrefService* prefs = g_browser_process->local_state();
137 InvokeResetScreen();
138 EXPECT_EQ(0, power_manager_client_->num_request_restart_calls());
139 EXPECT_EQ(0, session_manager_client_->start_device_wipe_call_count());
140 ClickRestartButton();
141 ASSERT_EQ(1, power_manager_client_->num_request_restart_calls());
142 ASSERT_EQ(0, session_manager_client_->start_device_wipe_call_count());
144 EXPECT_TRUE(prefs->GetBoolean(prefs::kFactoryResetRequested));
147 IN_PROC_BROWSER_TEST_F(ResetFirstAfterBootTest, PRE_ViewsLogic) {
148 PrefService* prefs = g_browser_process->local_state();
149 prefs->SetBoolean(prefs::kFactoryResetRequested, true);
150 RegisterSomeUser();
151 update_engine_client_->set_can_rollback_check_result(false);
154 IN_PROC_BROWSER_TEST_F(ResetFirstAfterBootTest, ViewsLogic) {
155 PrefService* prefs = g_browser_process->local_state();
157 // Rollback unavailable. Show and cancel.
158 update_engine_client_->set_can_rollback_check_result(false);
159 JSExpect("document.querySelector('#reset').hidden");
160 JSExpect("document.querySelector('#overlay-reset').hidden");
161 InvokeResetScreen();
162 JSExpect("!document.querySelector('#reset').hidden");
163 JSExpect("document.querySelector('#overlay-reset').hidden");
164 CloseResetScreen();
165 JSExpect("document.querySelector('#reset').hidden");
167 // Go to confirmation phase, cancel from there in 2 steps.
168 prefs->SetBoolean(prefs::kFactoryResetRequested, true);
169 InvokeResetScreen();
170 JSExpect("document.querySelector('#overlay-reset').hidden");
171 ClickToConfirmButton();
172 JSExpect("!document.querySelector('#overlay-reset').hidden");
173 ClickDismissConfirmationButton();
174 JSExpect("document.querySelector('#overlay-reset').hidden");
175 JSExpect("!document.querySelector('#reset').hidden");
176 CloseResetScreen();
177 JSExpect("document.querySelector('#reset').hidden");
179 // Rollback available. Show and cancel from confirmation screen.
180 update_engine_client_->set_can_rollback_check_result(true);
181 prefs->SetBoolean(prefs::kFactoryResetRequested, true);
182 InvokeResetScreen();
183 InvokeRollbackOption();
184 JSExpect("document.querySelector('#overlay-reset').hidden");
185 ClickToConfirmButton();
186 JSExpect("!document.querySelector('#overlay-reset').hidden");
187 ClickDismissConfirmationButton();
188 JSExpect("document.querySelector('#overlay-reset').hidden");
189 JSExpect("!document.querySelector('#reset').hidden");
190 CloseResetScreen();
191 JSExpect("document.querySelector('#reset').hidden");
194 IN_PROC_BROWSER_TEST_F(ResetFirstAfterBootTest, PRE_ShowAfterBootIfRequested) {
195 PrefService* prefs = g_browser_process->local_state();
196 prefs->SetBoolean(prefs::kFactoryResetRequested, true);
197 RegisterSomeUser();
200 IN_PROC_BROWSER_TEST_F(ResetFirstAfterBootTest, ShowAfterBootIfRequested) {
201 OobeScreenWaiter(OobeDisplay::SCREEN_OOBE_RESET).Wait();
202 JSExpect("!document.querySelector('#reset').hidden");
203 CloseResetScreen();
204 JSExpect("document.querySelector('#reset').hidden");
208 IN_PROC_BROWSER_TEST_F(ResetFirstAfterBootTest, PRE_RollbackUnavailable) {
209 PrefService* prefs = g_browser_process->local_state();
210 prefs->SetBoolean(prefs::kFactoryResetRequested, true);
211 RegisterSomeUser();
214 IN_PROC_BROWSER_TEST_F(ResetFirstAfterBootTest, RollbackUnavailable) {
215 update_engine_client_->set_can_rollback_check_result(false);
217 InvokeResetScreen();
218 EXPECT_EQ(0, power_manager_client_->num_request_restart_calls());
219 EXPECT_EQ(0, session_manager_client_->start_device_wipe_call_count());
220 EXPECT_EQ(0, update_engine_client_->rollback_call_count());
221 InvokeRollbackOption(); // No changes
222 ClickToConfirmButton();
223 ClickResetButton();
224 EXPECT_EQ(0, power_manager_client_->num_request_restart_calls());
225 EXPECT_EQ(1, session_manager_client_->start_device_wipe_call_count());
226 EXPECT_EQ(0, update_engine_client_->rollback_call_count());
227 CloseResetScreen();
228 OobeScreenWaiter(OobeDisplay::SCREEN_ACCOUNT_PICKER).Wait();
230 // Next invocation leads to rollback view.
231 PrefService* prefs = g_browser_process->local_state();
232 prefs->SetBoolean(prefs::kFactoryResetRequested, true);
233 InvokeResetScreen();
234 ClickToConfirmButton();
235 ClickResetButton();
236 EXPECT_EQ(0, power_manager_client_->num_request_restart_calls());
237 EXPECT_EQ(2, session_manager_client_->start_device_wipe_call_count());
238 EXPECT_EQ(0, update_engine_client_->rollback_call_count());
239 CloseResetScreen();
242 IN_PROC_BROWSER_TEST_F(ResetFirstAfterBootTest, PRE_RollbackAvailable) {
243 PrefService* prefs = g_browser_process->local_state();
244 prefs->SetBoolean(prefs::kFactoryResetRequested, true);
245 RegisterSomeUser();
248 IN_PROC_BROWSER_TEST_F(ResetFirstAfterBootTest, RollbackAvailable) {
249 update_engine_client_->set_can_rollback_check_result(true);
250 PrefService* prefs = g_browser_process->local_state();
252 InvokeResetScreen();
253 EXPECT_EQ(0, power_manager_client_->num_request_restart_calls());
254 EXPECT_EQ(0, session_manager_client_->start_device_wipe_call_count());
255 EXPECT_EQ(0, update_engine_client_->rollback_call_count());
256 ClickToConfirmButton();
257 ClickResetButton();
258 EXPECT_EQ(0, power_manager_client_->num_request_restart_calls());
259 EXPECT_EQ(1, session_manager_client_->start_device_wipe_call_count());
260 EXPECT_EQ(0, update_engine_client_->rollback_call_count());
261 CloseResetScreen();
262 OobeScreenWaiter(OobeDisplay::SCREEN_ACCOUNT_PICKER).Wait();
264 // Next invocation leads to simple reset, not rollback view.
265 prefs->SetBoolean(prefs::kFactoryResetRequested, true);
266 InvokeResetScreen();
267 InvokeRollbackOption(); // Shows rollback.
268 ClickDismissConfirmationButton();
269 CloseResetScreen();
270 InvokeResetScreen();
271 ClickToConfirmButton();
272 ClickResetButton();
273 EXPECT_EQ(0, power_manager_client_->num_request_restart_calls());
274 EXPECT_EQ(2, session_manager_client_->start_device_wipe_call_count());
275 EXPECT_EQ(0, update_engine_client_->rollback_call_count());
276 CloseResetScreen();
277 OobeScreenWaiter(OobeDisplay::SCREEN_ACCOUNT_PICKER).Wait();
279 prefs->SetBoolean(prefs::kFactoryResetRequested, true);
280 InvokeResetScreen();
281 InvokeRollbackOption(); // Shows rollback.
282 ClickToConfirmButton();
283 ClickResetButton();
284 EXPECT_EQ(0, power_manager_client_->num_request_restart_calls());
285 EXPECT_EQ(2, session_manager_client_->start_device_wipe_call_count());
286 EXPECT_EQ(1, update_engine_client_->rollback_call_count());
289 IN_PROC_BROWSER_TEST_F(ResetFirstAfterBootTest, PRE_ErrorOnRollbackRequested) {
290 PrefService* prefs = g_browser_process->local_state();
291 prefs->SetBoolean(prefs::kFactoryResetRequested, true);
292 RegisterSomeUser();
295 IN_PROC_BROWSER_TEST_F(ResetFirstAfterBootTest, ErrorOnRollbackRequested) {
296 update_engine_client_->set_can_rollback_check_result(true);
297 OobeScreenWaiter(OobeDisplay::SCREEN_OOBE_RESET).Wait();
298 EXPECT_EQ(0, power_manager_client_->num_request_restart_calls());
299 EXPECT_EQ(0, session_manager_client_->start_device_wipe_call_count());
300 EXPECT_EQ(0, update_engine_client_->rollback_call_count());
301 JSExpect("!$('reset').classList.contains('revert-promise-view')");
302 InvokeRollbackOption();
303 ClickToConfirmButton();
304 ClickResetButton();
305 EXPECT_EQ(0, power_manager_client_->num_request_restart_calls());
306 EXPECT_EQ(0, session_manager_client_->start_device_wipe_call_count());
307 EXPECT_EQ(1, update_engine_client_->rollback_call_count());
308 JSExpect("$('reset').classList.contains('revert-promise-view')");
309 UpdateEngineClient::Status error_update_status;
310 error_update_status.status = UpdateEngineClient::UPDATE_STATUS_ERROR;
311 update_engine_client_->NotifyObserversThatStatusChanged(
312 error_update_status);
313 OobeScreenWaiter(OobeDisplay::SCREEN_ERROR_MESSAGE).Wait();
316 IN_PROC_BROWSER_TEST_F(ResetFirstAfterBootTest, PRE_RevertAfterCancel) {
317 PrefService* prefs = g_browser_process->local_state();
318 prefs->SetBoolean(prefs::kFactoryResetRequested, true);
319 RegisterSomeUser();
322 IN_PROC_BROWSER_TEST_F(ResetFirstAfterBootTest, RevertAfterCancel) {
323 update_engine_client_->set_can_rollback_check_result(true);
324 OobeScreenWaiter(OobeDisplay::SCREEN_OOBE_RESET).Wait();
325 EXPECT_EQ(0, power_manager_client_->num_request_restart_calls());
326 EXPECT_EQ(0, session_manager_client_->start_device_wipe_call_count());
327 EXPECT_EQ(0, update_engine_client_->rollback_call_count());
328 JSExpect("!$('reset').classList.contains('rollback-proposal-view')");
329 InvokeRollbackOption();
330 JSExpect("$('reset').classList.contains('rollback-proposal-view')");
331 CloseResetScreen();
332 InvokeResetScreen();
333 OobeScreenWaiter(OobeDisplay::SCREEN_OOBE_RESET).Wait();
334 InvokeRollbackOption();
335 JSExpect("$('reset').classList.contains('rollback-proposal-view')");
338 } // namespace chromeos