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

Side by Side Diff: chrome/renderer/autofill/password_generation_manager_browsertest.cc

Issue 10449099: Use shadow DOM API to show icon for password generation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 8 years, 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "base/memory/scoped_vector.h" 6 #include "base/memory/scoped_vector.h"
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/common/autofill_messages.h" 8 #include "chrome/common/autofill_messages.h"
9 #include "chrome/renderer/autofill/password_generation_manager.h" 9 #include "chrome/renderer/autofill/password_generation_manager.h"
10 #include "chrome/test/base/chrome_render_view_test.h" 10 #include "chrome/test/base/chrome_render_view_test.h"
(...skipping 19 matching lines...) Expand all
30 // Make this public 30 // Make this public
31 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { 31 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE {
32 return PasswordGenerationManager::OnMessageReceived(message); 32 return PasswordGenerationManager::OnMessageReceived(message);
33 } 33 }
34 34
35 const std::vector<IPC::Message*>& messages() { 35 const std::vector<IPC::Message*>& messages() {
36 return messages_.get(); 36 return messages_.get();
37 } 37 }
38 38
39 protected: 39 protected:
40 virtual bool ShouldAnalyzeFrame(const WebKit::WebFrame& frame) const 40 virtual bool ShouldAnalyzeDocument(const WebKit::WebDocument& document) const
41 OVERRIDE { 41 OVERRIDE {
42 return true; 42 return true;
43 } 43 }
44 44
45 virtual bool Send(IPC::Message* message) OVERRIDE { 45 virtual bool Send(IPC::Message* message) OVERRIDE {
46 messages_.push_back(message); 46 messages_.push_back(message);
47 return true; 47 return true;
48 } 48 }
49 49
50 private: 50 private:
51 ScopedVector<IPC::Message> messages_; 51 ScopedVector<IPC::Message> messages_;
52 52
53 DISALLOW_COPY_AND_ASSIGN(TestPasswordGenerationManager); 53 DISALLOW_COPY_AND_ASSIGN(TestPasswordGenerationManager);
54 }; 54 };
55 55
56 class PasswordGenerationManagerTest : public ChromeRenderViewTest { 56 class PasswordGenerationManagerTest : public ChromeRenderViewTest {
57 public: 57 public:
58 PasswordGenerationManagerTest() {} 58 PasswordGenerationManagerTest() {}
59 59
60 virtual void SetUp() { 60 virtual void SetUp() {
61 // We don't actually create a PasswordGenerationManager during 61 // We don't actually create a PasswordGenerationManager during
62 // ChromeRenderViewTest::SetUp because it's behind a flag. Since we want 62 // ChromeRenderViewTest::SetUp because it's behind a flag. Since we want
63 // to use a test manager anyway, we just create out own. 63 // to use a test manager anyway, we just create out own.
64 ChromeRenderViewTest::SetUp(); 64 ChromeRenderViewTest::SetUp();
65 generation_manager_.reset(new TestPasswordGenerationManager(view_)); 65 generation_manager_.reset(new TestPasswordGenerationManager(view_));
66 } 66 }
67 67
68 void SimulateClickOnDecoration(WebKit::WebInputElement& input_element) {
Ilya Sherman 2012/06/01 02:57:16 nit: Please pass either by const-reference or as a
69 WebKit::WebElement decoration =
70 input_element.decorationElementFor(generation_manager_.get());
71 decoration.simulateClick();
72 }
73
74 bool DecorationIsVisible(WebKit::WebInputElement& input_element) {
Ilya Sherman 2012/06/01 02:57:16 nit: Please pass either by const-reference or as a
75 WebKit::WebElement decoration =
76 input_element.decorationElementFor(generation_manager_.get());
77 return decoration.hasNonEmptyBoundingBox();
78 }
79
68 protected: 80 protected:
69 scoped_ptr<TestPasswordGenerationManager> generation_manager_; 81 scoped_ptr<TestPasswordGenerationManager> generation_manager_;
70 82
71 private: 83 private:
72 DISALLOW_COPY_AND_ASSIGN(PasswordGenerationManagerTest); 84 DISALLOW_COPY_AND_ASSIGN(PasswordGenerationManagerTest);
73 }; 85 };
74 86
75 const char kSigninFormHTML[] = 87 const char kSigninFormHTML[] =
76 "<FORM name = 'blah' action = 'http://www.random.com/'> " 88 "<FORM name = 'blah' action = 'http://www.random.com/'> "
77 " <INPUT type = 'text' id = 'username'/> " 89 " <INPUT type = 'text' id = 'username'/> "
(...skipping 10 matching lines...) Expand all
88 "</FORM>"; 100 "</FORM>";
89 101
90 TEST_F(PasswordGenerationManagerTest, DetectionTest) { 102 TEST_F(PasswordGenerationManagerTest, DetectionTest) {
91 LoadHTML(kSigninFormHTML); 103 LoadHTML(kSigninFormHTML);
92 104
93 WebDocument document = GetMainFrame()->document(); 105 WebDocument document = GetMainFrame()->document();
94 WebElement element = 106 WebElement element =
95 document.getElementById(WebString::fromUTF8("password")); 107 document.getElementById(WebString::fromUTF8("password"));
96 ASSERT_FALSE(element.isNull()); 108 ASSERT_FALSE(element.isNull());
97 WebInputElement password_element = element.to<WebInputElement>(); 109 WebInputElement password_element = element.to<WebInputElement>();
98 EXPECT_EQ(0u, generation_manager_->messages().size()); 110 EXPECT_FALSE(DecorationIsVisible(password_element));
99 111
100 LoadHTML(kAccountCreationFormHTML); 112 LoadHTML(kAccountCreationFormHTML);
101 113
102 // We don't do anything yet because the feature is disabled. 114 // We don't show the decoration yet because the feature isn't enabled.
103 document = GetMainFrame()->document(); 115 document = GetMainFrame()->document();
104 element = document.getElementById(WebString::fromUTF8("first_password")); 116 element = document.getElementById(WebString::fromUTF8("first_password"));
105 ASSERT_FALSE(element.isNull()); 117 ASSERT_FALSE(element.isNull());
106 WebInputElement first_password_element = element.to<WebInputElement>(); 118 WebInputElement first_password_element = element.to<WebInputElement>();
107 EXPECT_EQ(0u, generation_manager_->messages().size());
108 element = document.getElementById(WebString::fromUTF8("second_password")); 119 element = document.getElementById(WebString::fromUTF8("second_password"));
109 ASSERT_FALSE(element.isNull()); 120 ASSERT_FALSE(element.isNull());
110 WebInputElement second_password_element = element.to<WebInputElement>(); 121 WebInputElement second_password_element = element.to<WebInputElement>();
111 EXPECT_EQ(0u, generation_manager_->messages().size()); 122 EXPECT_FALSE(DecorationIsVisible(first_password_element));
112 SetFocused(first_password_element.to<WebNode>());
113 EXPECT_EQ(0u, generation_manager_->messages().size());
114 123
115 // Pretend like password generation was enabled. 124 // Pretend like password generation was enabled.
116 AutofillMsg_PasswordGenerationEnabled msg(0, true); 125 AutofillMsg_PasswordGenerationEnabled msg(0, true);
117 generation_manager_->OnMessageReceived(msg); 126 generation_manager_->OnMessageReceived(msg);
118 127
119 // Now we will send a message once the first password feld is focused. 128 // Now check that the decoration is visible on the first password field and
129 // that we send a message after the decoration is clicked.
120 LoadHTML(kAccountCreationFormHTML); 130 LoadHTML(kAccountCreationFormHTML);
121 document = GetMainFrame()->document(); 131 document = GetMainFrame()->document();
122 element = document.getElementById(WebString::fromUTF8("first_password")); 132 element = document.getElementById(WebString::fromUTF8("first_password"));
123 ASSERT_FALSE(element.isNull()); 133 ASSERT_FALSE(element.isNull());
124 first_password_element = element.to<WebInputElement>(); 134 first_password_element = element.to<WebInputElement>();
125 EXPECT_EQ(0u, generation_manager_->messages().size());
126 element = document.getElementById(WebString::fromUTF8("second_password")); 135 element = document.getElementById(WebString::fromUTF8("second_password"));
127 ASSERT_FALSE(element.isNull()); 136 ASSERT_FALSE(element.isNull());
128 second_password_element = element.to<WebInputElement>(); 137 second_password_element = element.to<WebInputElement>();
129 EXPECT_EQ(0u, generation_manager_->messages().size()); 138 EXPECT_TRUE(DecorationIsVisible(first_password_element));
130 SetFocused(first_password_element.to<WebNode>()); 139 SimulateClickOnDecoration(first_password_element);
131 EXPECT_EQ(1u, generation_manager_->messages().size()); 140 EXPECT_EQ(1u, generation_manager_->messages().size());
132 EXPECT_EQ(AutofillHostMsg_ShowPasswordGenerationPopup::ID, 141 EXPECT_EQ(AutofillHostMsg_ShowPasswordGenerationPopup::ID,
133 generation_manager_->messages()[0]->type()); 142 generation_manager_->messages()[0]->type());
134 } 143 }
135 144
136 TEST_F(PasswordGenerationManagerTest, FillTest) { 145 TEST_F(PasswordGenerationManagerTest, FillTest) {
137 // Make sure that we are enabled before loading HTML. 146 // Make sure that we are enabled before loading HTML.
138 AutofillMsg_PasswordGenerationEnabled enabled_msg(0, true); 147 AutofillMsg_PasswordGenerationEnabled enabled_msg(0, true);
139 generation_manager_->OnMessageReceived(enabled_msg); 148 generation_manager_->OnMessageReceived(enabled_msg);
140 LoadHTML(kAccountCreationFormHTML); 149 LoadHTML(kAccountCreationFormHTML);
(...skipping 16 matching lines...) Expand all
157 generation_manager_->OnMessageReceived(msg); 166 generation_manager_->OnMessageReceived(msg);
158 167
159 // Password fields are filled out and set as being autofilled. 168 // Password fields are filled out and set as being autofilled.
160 EXPECT_EQ(password, first_password_element.value()); 169 EXPECT_EQ(password, first_password_element.value());
161 EXPECT_EQ(password, second_password_element.value()); 170 EXPECT_EQ(password, second_password_element.value());
162 EXPECT_TRUE(first_password_element.isAutofilled()); 171 EXPECT_TRUE(first_password_element.isAutofilled());
163 EXPECT_TRUE(second_password_element.isAutofilled()); 172 EXPECT_TRUE(second_password_element.isAutofilled());
164 } 173 }
165 174
166 } // namespace autofill 175 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/renderer/autofill/password_generation_manager.cc ('k') | webkit/glue/resources/password_generation.png » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698