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

Side by Side Diff: chrome/browser/password_manager/password_generation_interactive_uitest.cc

Issue 147533005: [Password Generation] Update UI to match final mocks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@replace_password_generation_ui
Patch Set: Created 6 years, 10 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
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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "chrome/browser/password_manager/password_generation_manager.h" 6 #include "chrome/browser/password_manager/password_generation_manager.h"
7 #include "chrome/browser/profiles/profile.h" 7 #include "chrome/browser/profiles/profile.h"
8 #include "chrome/browser/ui/autofill/password_generation_popup_observer.h" 8 #include "chrome/browser/ui/autofill/password_generation_popup_observer.h"
9 #include "chrome/browser/ui/browser.h" 9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/browser/ui/tabs/tab_strip_model.h" 10 #include "chrome/browser/ui/tabs/tab_strip_model.h"
11 #include "chrome/test/base/in_process_browser_test.h" 11 #include "chrome/test/base/in_process_browser_test.h"
12 #include "chrome/test/base/ui_test_utils.h" 12 #include "chrome/test/base/ui_test_utils.h"
13 #include "components/autofill/core/browser/autofill_test_utils.h" 13 #include "components/autofill/core/browser/autofill_test_utils.h"
14 #include "components/autofill/core/common/autofill_switches.h" 14 #include "components/autofill/core/common/autofill_switches.h"
15 #include "content/public/browser/render_view_host.h" 15 #include "content/public/browser/render_view_host.h"
16 #include "content/public/browser/web_contents.h" 16 #include "content/public/browser/web_contents.h"
17 #include "content/public/test/browser_test_utils.h" 17 #include "content/public/test/browser_test_utils.h"
18 #include "net/test/embedded_test_server/embedded_test_server.h" 18 #include "net/test/embedded_test_server/embedded_test_server.h"
19 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
20 #include "ui/events/keycodes/keyboard_codes.h" 20 #include "ui/events/keycodes/keyboard_codes.h"
21 21
22 namespace { 22 namespace {
23 23
24 class TestPopupObserver : public autofill::PasswordGenerationPopupObserver { 24 class TestPopupObserver : public autofill::PasswordGenerationPopupObserver {
25 public: 25 public:
26 TestPopupObserver() 26 TestPopupObserver()
27 : popup_showing_(false) {} 27 : popup_showing_(false),
28 password_visible_(false) {}
28 virtual ~TestPopupObserver() {} 29 virtual ~TestPopupObserver() {}
29 30
30 virtual void OnPopupShown() OVERRIDE { 31 virtual void OnPopupShown(bool password_visible) OVERRIDE {
31 popup_showing_ = true; 32 popup_showing_ = true;
33 password_visible_ = password_visible;
32 } 34 }
33 35
34 virtual void OnPopupHidden() OVERRIDE { 36 virtual void OnPopupHidden() OVERRIDE {
35 popup_showing_ = false; 37 popup_showing_ = false;
36 } 38 }
37 39
38 bool popup_showing() { return popup_showing_; } 40 bool popup_showing() { return popup_showing_; }
41 bool password_visible() { return password_visible_; }
39 42
40 private: 43 private:
41 bool popup_showing_; 44 bool popup_showing_;
45 bool password_visible_;
42 }; 46 };
43 47
44 } // namespace 48 } // namespace
45 49
46 class PasswordGenerationInteractiveTest : public InProcessBrowserTest { 50 class PasswordGenerationInteractiveTest : public InProcessBrowserTest {
47 public: 51 public:
48 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 52 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
49 // Make sure the feature is enabled. 53 // Make sure the feature is enabled.
50 command_line->AppendSwitch(autofill::switches::kEnablePasswordGeneration); 54 command_line->AppendSwitch(autofill::switches::kEnablePasswordGeneration);
51 55
52 // Don't require ping from autofill or blacklist checking. 56 // Don't require ping from autofill or blacklist checking.
53 command_line->AppendSwitch( 57 command_line->AppendSwitch(
54 autofill::switches::kLocalHeuristicsOnlyForPasswordGeneration); 58 autofill::switches::kLocalHeuristicsOnlyForPasswordGeneration);
55 } 59 }
56 60
57 virtual void SetUpOnMainThread() OVERRIDE { 61 virtual void SetUpOnMainThread() OVERRIDE {
58 // Disable Autofill requesting access to AddressBook data. This will cause 62 // Disable Autofill requesting access to AddressBook data. This will cause
59 // test tests to hang on Mac. 63 // the tests to hang on Mac.
60 autofill::test::DisableSystemServices(browser()->profile()); 64 autofill::test::DisableSystemServices(browser()->profile());
61 65
62 // Set observer for popup. 66 // Set observer for popup.
63 PasswordGenerationManager* generation_manager = 67 PasswordGenerationManager* generation_manager =
64 PasswordGenerationManager::FromWebContents(GetWebContents()); 68 PasswordGenerationManager::FromWebContents(GetWebContents());
65 generation_manager->SetTestObserver(&observer_); 69 generation_manager->SetTestObserver(&observer_);
66 70
67 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 71 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
68 GURL url = embedded_test_server()->GetURL("/password/signup_form.html"); 72 GURL url = embedded_test_server()->GetURL("/password/signup_form.html");
69 ui_test_utils::NavigateToURL(browser(), url); 73 ui_test_utils::NavigateToURL(browser(), url);
70 } 74 }
71 75
72 virtual void CleanUpOnMainThread() OVERRIDE { 76 virtual void CleanUpOnMainThread() OVERRIDE {
73 // Cleanup UI. 77 // Clean up UI.
74 PasswordGenerationManager* generation_manager = 78 PasswordGenerationManager* generation_manager =
75 PasswordGenerationManager::FromWebContents(GetWebContents()); 79 PasswordGenerationManager::FromWebContents(GetWebContents());
76 generation_manager->HidePopup(); 80 generation_manager->HidePopup();
77 } 81 }
78 82
79 content::WebContents* GetWebContents() { 83 content::WebContents* GetWebContents() {
80 return browser()->tab_strip_model()->GetActiveWebContents(); 84 return browser()->tab_strip_model()->GetActiveWebContents();
81 } 85 }
82 86
83 content::RenderViewHost* GetRenderViewHost() { 87 content::RenderViewHost* GetRenderViewHost() {
84 return GetWebContents()->GetRenderViewHost(); 88 return GetWebContents()->GetRenderViewHost();
85 } 89 }
86 90
87 std::string GetFieldValue(const std::string& field_id) { 91 std::string GetFieldValue(const std::string& field_id) {
88 std::string value; 92 std::string value;
89 EXPECT_TRUE(content::ExecuteScriptAndExtractString( 93 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
90 GetRenderViewHost(), 94 GetRenderViewHost(),
91 "window.domAutomationController.send(" 95 "window.domAutomationController.send("
92 " document.getElementById('" + field_id + "').value);", 96 " document.getElementById('" + field_id + "').value);",
93 &value)); 97 &value));
94 return value; 98 return value;
95 } 99 }
96 100
101 std::string GetFocusedElement() {
102 std::string focused_element;
103 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
104 GetRenderViewHost(),
105 "window.domAutomationController.send("
106 " document.activeElement.id)",
107 &focused_element));
108 return focused_element;
109 }
110
97 void FocusPasswordField() { 111 void FocusPasswordField() {
98 ASSERT_TRUE(content::ExecuteScript( 112 ASSERT_TRUE(content::ExecuteScript(
99 GetRenderViewHost(), 113 GetRenderViewHost(),
100 "document.getElementById('password_field').focus()")); 114 "document.getElementById('password_field').focus()"));
101 } 115 }
102 116
103 void SendKeyToPopup(ui::KeyboardCode key) { 117 void SendKeyToPopup(ui::KeyboardCode key) {
104 content::NativeWebKeyboardEvent event; 118 content::NativeWebKeyboardEvent event;
105 event.windowsKeyCode = key; 119 event.windowsKeyCode = key;
106 event.type = blink::WebKeyboardEvent::RawKeyDown; 120 event.type = blink::WebKeyboardEvent::RawKeyDown;
107 GetRenderViewHost()->ForwardKeyboardEvent(event); 121 GetRenderViewHost()->ForwardKeyboardEvent(event);
108 } 122 }
109 123
110 bool popup_showing() { 124 bool GenerationPopupShowing() {
111 return observer_.popup_showing(); 125 return observer_.popup_showing() && observer_.password_visible();
126 }
127
128 bool EditingPopupShowing() {
129 return observer_.popup_showing() && !observer_.password_visible();
112 } 130 }
113 131
114 private: 132 private:
115 TestPopupObserver observer_; 133 TestPopupObserver observer_;
116 }; 134 };
117 135
118 #if defined(USE_AURA) 136 #if defined(USE_AURA)
119 // Enabled on these platforms 137 // Enabled on these platforms.
120 #define MAYBE_PopupShownAndPasswordSelected PopupShownAndPasswordSelected 138 #define MAYBE_PopupShownAndPasswordSelected PopupShownAndPasswordSelected
121 #define MAYBE_PopupShownAndDismissed PopupShownAndDismissed 139 #define MAYBE_PopupShownAndDismissed PopupShownAndDismissed
122 #else 140 #else
123 // Popup not enabled for these platforms yet. 141 // Popup not enabled for these platforms yet.
124 #define MAYBE_PopupShownAndPasswordSelected DISABLED_PopupShownAndPasswordSelect ed 142 #define MAYBE_PopupShownAndPasswordSelected DISABLED_PopupShownAndPasswordSelect ed
125 #define MAYBE_PopupShownAndDismissed DISABLED_PopupShownAndDismissed 143 #define MAYBE_PopupShownAndDismissed DISABLED_PopupShownAndDismissed
126 #endif 144 #endif
127 145
128 IN_PROC_BROWSER_TEST_F(PasswordGenerationInteractiveTest, 146 IN_PROC_BROWSER_TEST_F(PasswordGenerationInteractiveTest,
129 MAYBE_PopupShownAndPasswordSelected) { 147 MAYBE_PopupShownAndPasswordSelected) {
130 FocusPasswordField(); 148 FocusPasswordField();
131 EXPECT_TRUE(popup_showing()); 149 EXPECT_TRUE(GenerationPopupShowing());
132 SendKeyToPopup(ui::VKEY_DOWN); 150 SendKeyToPopup(ui::VKEY_DOWN);
133 SendKeyToPopup(ui::VKEY_RETURN); 151 SendKeyToPopup(ui::VKEY_RETURN);
134 152
153 // Selecting the password should fill the field and move focus to the
154 // submit button.
135 EXPECT_FALSE(GetFieldValue("password_field").empty()); 155 EXPECT_FALSE(GetFieldValue("password_field").empty());
156 EXPECT_FALSE(GenerationPopupShowing());
157 EXPECT_FALSE(EditingPopupShowing());
158 EXPECT_EQ("input_submit_button", GetFocusedElement());
159
160 // Re-focusing the password field should show the editing popup.
161 FocusPasswordField();
162 EXPECT_TRUE(EditingPopupShowing());
136 } 163 }
137 164
138 IN_PROC_BROWSER_TEST_F(PasswordGenerationInteractiveTest, 165 IN_PROC_BROWSER_TEST_F(PasswordGenerationInteractiveTest,
139 MAYBE_PopupShownAndDismissed) { 166 MAYBE_PopupShownAndDismissed) {
140 FocusPasswordField(); 167 FocusPasswordField();
141 EXPECT_TRUE(popup_showing()); 168 EXPECT_TRUE(GenerationPopupShowing());
142 169
143 SendKeyToPopup(ui::VKEY_ESCAPE); 170 SendKeyToPopup(ui::VKEY_ESCAPE);
144 171
145 // Popup is dismissed. 172 // Popup is dismissed.
146 EXPECT_FALSE(popup_showing()); 173 EXPECT_FALSE(GenerationPopupShowing());
147 } 174 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698