OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "chrome/browser/chrome_notification_types.h" | 5 #include "chrome/browser/chrome_notification_types.h" |
6 #include "chrome/browser/chromeos/login/test/oobe_base_test.h" | 6 #include "chrome/browser/chromeos/login/test/oobe_base_test.h" |
7 #include "chrome/browser/chromeos/login/ui/webui_login_display.h" | 7 #include "chrome/browser/chromeos/login/ui/webui_login_display.h" |
8 #include "chromeos/chromeos_switches.h" | 8 #include "chromeos/chromeos_switches.h" |
9 #include "content/public/test/browser_test_utils.h" | 9 #include "content/public/test/browser_test_utils.h" |
10 #include "content/public/test/test_utils.h" | 10 #include "content/public/test/test_utils.h" |
11 | 11 |
12 namespace chromeos { | 12 namespace chromeos { |
| 13 namespace { |
| 14 const char kFakeUserEmail[] = "fake-email@gmail.com"; |
| 15 const char kFakeUserPassword[] = "fake-password"; |
| 16 const char kFakeSIDCookie[] = "fake-SID-cookie"; |
| 17 const char kFakeLSIDCookie[] = "fake-LSID-cookie"; |
| 18 } |
13 | 19 |
14 class WebviewLoginTest : public OobeBaseTest { | 20 class WebviewLoginTest : public OobeBaseTest { |
15 public: | 21 public: |
16 WebviewLoginTest() { set_use_webview(true); } | 22 WebviewLoginTest() { use_webview_ = true; } |
17 ~WebviewLoginTest() override {} | 23 ~WebviewLoginTest() override {} |
18 | 24 |
| 25 void SetUpOnMainThread() override { |
| 26 fake_gaia_->SetFakeMergeSessionParams(kFakeUserEmail, kFakeSIDCookie, |
| 27 kFakeLSIDCookie); |
| 28 |
| 29 OobeBaseTest::SetUpOnMainThread(); |
| 30 } |
| 31 |
19 void SetUpCommandLine(base::CommandLine* command_line) override { | 32 void SetUpCommandLine(base::CommandLine* command_line) override { |
20 command_line->AppendSwitch(switches::kOobeSkipPostLogin); | 33 command_line->AppendSwitch(switches::kOobeSkipPostLogin); |
21 OobeBaseTest::SetUpCommandLine(command_line); | 34 OobeBaseTest::SetUpCommandLine(command_line); |
22 } | 35 } |
23 | 36 |
| 37 void WaitForGaiaPageLoaded() { |
| 38 WaitForSigninScreen(); |
| 39 |
| 40 ASSERT_TRUE(content::ExecuteScript( |
| 41 GetLoginUI()->GetWebContents(), |
| 42 "$('gaia-signin').gaiaAuthHost_.addEventListener('ready'," |
| 43 "function() {" |
| 44 "window.domAutomationController.setAutomationId(0);" |
| 45 "window.domAutomationController.send('GaiaReady');" |
| 46 "});")); |
| 47 |
| 48 content::DOMMessageQueue message_queue; |
| 49 std::string message; |
| 50 ASSERT_TRUE(message_queue.WaitForMessage(&message)); |
| 51 EXPECT_EQ("\"GaiaReady\"", message); |
| 52 } |
| 53 |
24 private: | 54 private: |
25 DISALLOW_COPY_AND_ASSIGN(WebviewLoginTest); | 55 DISALLOW_COPY_AND_ASSIGN(WebviewLoginTest); |
26 }; | 56 }; |
27 | 57 |
28 IN_PROC_BROWSER_TEST_F(WebviewLoginTest, Basic) { | 58 IN_PROC_BROWSER_TEST_F(WebviewLoginTest, Basic) { |
29 WaitForGaiaPageLoad(); | 59 WaitForGaiaPageLoaded(); |
30 | 60 |
31 JsExpect("$('close-button-item').hidden"); | 61 JsExpect("$('close-button-item').hidden"); |
32 | 62 |
33 SetSignFormField("identifier", OobeBaseTest::kFakeUserEmail); | 63 SetSignFormField("identifier", kFakeUserEmail); |
34 ExecuteJsInSigninFrame("document.getElementById('nextButton').click();"); | 64 ExecuteJsInSigninFrame("document.getElementById('nextButton').click();"); |
35 | 65 |
36 JsExpect("$('close-button-item').hidden"); | 66 JsExpect("$('close-button-item').hidden"); |
37 | 67 |
38 content::WindowedNotificationObserver session_start_waiter( | 68 content::WindowedNotificationObserver session_start_waiter( |
39 chrome::NOTIFICATION_SESSION_STARTED, | 69 chrome::NOTIFICATION_SESSION_STARTED, |
40 content::NotificationService::AllSources()); | 70 content::NotificationService::AllSources()); |
41 | 71 |
42 SetSignFormField("password", OobeBaseTest::kFakeUserPassword); | 72 SetSignFormField("password", kFakeUserPassword); |
43 ExecuteJsInSigninFrame("document.getElementById('nextButton').click();"); | 73 ExecuteJsInSigninFrame("document.getElementById('nextButton').click();"); |
44 | 74 |
45 session_start_waiter.Wait(); | 75 session_start_waiter.Wait(); |
46 } | 76 } |
47 | 77 |
48 IN_PROC_BROWSER_TEST_F(WebviewLoginTest, BackButton) { | 78 IN_PROC_BROWSER_TEST_F(WebviewLoginTest, BackButton) { |
49 WaitForGaiaPageLoad(); | 79 WaitForGaiaPageLoaded(); |
50 | 80 |
51 // Start: no back button, first page. | 81 // Start: no back button, first page. |
52 JsExpect("$('back-button-item').hidden"); | 82 JsExpect("$('back-button-item').hidden"); |
53 JsExpect("$('signin-frame').src.indexOf('#identifier') != -1"); | 83 JsExpect("$('signin-frame').src.indexOf('#identifier') != -1"); |
54 | 84 |
55 // Next step: back button active, second page. | 85 // Next step: back button active, second page. |
56 SetSignFormField("identifier", OobeBaseTest::kFakeUserEmail); | 86 SetSignFormField("identifier", kFakeUserEmail); |
57 ExecuteJsInSigninFrame("document.getElementById('nextButton').click();"); | 87 ExecuteJsInSigninFrame("document.getElementById('nextButton').click();"); |
58 JsExpect("!$('back-button-item').hidden"); | 88 JsExpect("!$('back-button-item').hidden"); |
59 JsExpect("$('signin-frame').src.indexOf('#challengepassword') != -1"); | 89 JsExpect("$('signin-frame').src.indexOf('#challengepassword') != -1"); |
60 | 90 |
61 // One step back: no back button, first page. | 91 // One step back: no back button, first page. |
62 ASSERT_TRUE(content::ExecuteScript(GetLoginUI()->GetWebContents(), | 92 ASSERT_TRUE(content::ExecuteScript(GetLoginUI()->GetWebContents(), |
63 "$('back-button-item').click();")); | 93 "$('back-button-item').click();")); |
64 JsExpect("$('back-button-item').hidden"); | 94 JsExpect("$('back-button-item').hidden"); |
65 JsExpect("$('signin-frame').src.indexOf('#identifier') != -1"); | 95 JsExpect("$('signin-frame').src.indexOf('#identifier') != -1"); |
66 | 96 |
67 // Next step (again): back button active, second page, user id remembered. | 97 // Next step (again): back button active, second page, user id remembered. |
68 ExecuteJsInSigninFrame("document.getElementById('nextButton').click();"); | 98 ExecuteJsInSigninFrame("document.getElementById('nextButton').click();"); |
69 JsExpect("!$('back-button-item').hidden"); | 99 JsExpect("!$('back-button-item').hidden"); |
70 JsExpect("$('signin-frame').src.indexOf('#challengepassword') != -1"); | 100 JsExpect("$('signin-frame').src.indexOf('#challengepassword') != -1"); |
71 | 101 |
72 content::WindowedNotificationObserver session_start_waiter( | 102 content::WindowedNotificationObserver session_start_waiter( |
73 chrome::NOTIFICATION_SESSION_STARTED, | 103 chrome::NOTIFICATION_SESSION_STARTED, |
74 content::NotificationService::AllSources()); | 104 content::NotificationService::AllSources()); |
75 | 105 |
76 SetSignFormField("password", OobeBaseTest::kFakeUserPassword); | 106 SetSignFormField("password", kFakeUserPassword); |
77 ExecuteJsInSigninFrame("document.getElementById('nextButton').click();"); | 107 ExecuteJsInSigninFrame("document.getElementById('nextButton').click();"); |
78 | 108 |
79 session_start_waiter.Wait(); | 109 session_start_waiter.Wait(); |
80 } | 110 } |
81 | 111 |
82 } // namespace chromeos | 112 } // namespace chromeos |
OLD | NEW |