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

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: 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) {
69 WebKit::WebElement decoration =
70 input_element.decorationElementFor(generation_manager_.get());
71 decoration.simulateClick();
72 }
73
68 protected: 74 protected:
69 scoped_ptr<TestPasswordGenerationManager> generation_manager_; 75 scoped_ptr<TestPasswordGenerationManager> generation_manager_;
70 76
71 private: 77 private:
72 DISALLOW_COPY_AND_ASSIGN(PasswordGenerationManagerTest); 78 DISALLOW_COPY_AND_ASSIGN(PasswordGenerationManagerTest);
73 }; 79 };
74 80
75 const char kSigninFormHTML[] = 81 const char kSigninFormHTML[] =
76 "<FORM name = 'blah' action = 'http://www.random.com/'> " 82 "<FORM name = 'blah' action = 'http://www.random.com/'> "
77 " <INPUT type = 'text' id = 'username'/> " 83 " <INPUT type = 'text' id = 'username'/> "
(...skipping 10 matching lines...) Expand all
88 "</FORM>"; 94 "</FORM>";
89 95
90 TEST_F(PasswordGenerationManagerTest, DetectionTest) { 96 TEST_F(PasswordGenerationManagerTest, DetectionTest) {
91 LoadHTML(kSigninFormHTML); 97 LoadHTML(kSigninFormHTML);
92 98
93 WebDocument document = GetMainFrame()->document(); 99 WebDocument document = GetMainFrame()->document();
94 WebElement element = 100 WebElement element =
95 document.getElementById(WebString::fromUTF8("password")); 101 document.getElementById(WebString::fromUTF8("password"));
96 ASSERT_FALSE(element.isNull()); 102 ASSERT_FALSE(element.isNull());
97 WebInputElement password_element = element.to<WebInputElement>(); 103 WebInputElement password_element = element.to<WebInputElement>();
98 EXPECT_EQ(0u, generation_manager_->messages().size()); 104 EXPECT_FALSE(password_element.decorationElementFor(
105 generation_manager_.get()).hasNonEmptyBoundingBox());
Ilya Sherman 2012/06/01 00:34:31 nit: This condition is somewhat lengthy -- perhaps
Garrett Casto 2012/06/01 01:21:28 Done.
99 106
100 LoadHTML(kAccountCreationFormHTML); 107 LoadHTML(kAccountCreationFormHTML);
101 108
102 // We don't do anything yet because the feature is disabled. 109 // We don't show the decoration yet because the feature isn't enabled.
103 document = GetMainFrame()->document(); 110 document = GetMainFrame()->document();
104 element = document.getElementById(WebString::fromUTF8("first_password")); 111 element = document.getElementById(WebString::fromUTF8("first_password"));
105 ASSERT_FALSE(element.isNull()); 112 ASSERT_FALSE(element.isNull());
106 WebInputElement first_password_element = element.to<WebInputElement>(); 113 WebInputElement first_password_element = element.to<WebInputElement>();
107 EXPECT_EQ(0u, generation_manager_->messages().size());
108 element = document.getElementById(WebString::fromUTF8("second_password")); 114 element = document.getElementById(WebString::fromUTF8("second_password"));
109 ASSERT_FALSE(element.isNull()); 115 ASSERT_FALSE(element.isNull());
110 WebInputElement second_password_element = element.to<WebInputElement>(); 116 WebInputElement second_password_element = element.to<WebInputElement>();
111 EXPECT_EQ(0u, generation_manager_->messages().size()); 117 EXPECT_FALSE(first_password_element.decorationElementFor(
112 SetFocused(first_password_element.to<WebNode>()); 118 generation_manager_.get()).hasNonEmptyBoundingBox());
Ilya Sherman 2012/06/01 00:34:31 nit: Hmm, shouldn't there be an EXPECT_TRUE with t
Garrett Casto 2012/06/01 01:21:28 Yep, fixed.
113 EXPECT_EQ(0u, generation_manager_->messages().size());
114 119
115 // Pretend like password generation was enabled. 120 // Pretend like password generation was enabled.
116 AutofillMsg_PasswordGenerationEnabled msg(0, true); 121 AutofillMsg_PasswordGenerationEnabled msg(0, true);
117 generation_manager_->OnMessageReceived(msg); 122 generation_manager_->OnMessageReceived(msg);
118 123
119 // Now we will send a message once the first password feld is focused. 124 // Now check that the decoration is visible on the first password field and
125 // that we send a message after the decoration is clicked.
120 LoadHTML(kAccountCreationFormHTML); 126 LoadHTML(kAccountCreationFormHTML);
121 document = GetMainFrame()->document(); 127 document = GetMainFrame()->document();
122 element = document.getElementById(WebString::fromUTF8("first_password")); 128 element = document.getElementById(WebString::fromUTF8("first_password"));
123 ASSERT_FALSE(element.isNull()); 129 ASSERT_FALSE(element.isNull());
124 first_password_element = element.to<WebInputElement>(); 130 first_password_element = element.to<WebInputElement>();
125 EXPECT_EQ(0u, generation_manager_->messages().size()); 131 EXPECT_EQ(0u, generation_manager_->messages().size());
126 element = document.getElementById(WebString::fromUTF8("second_password")); 132 element = document.getElementById(WebString::fromUTF8("second_password"));
127 ASSERT_FALSE(element.isNull()); 133 ASSERT_FALSE(element.isNull());
128 second_password_element = element.to<WebInputElement>(); 134 second_password_element = element.to<WebInputElement>();
129 EXPECT_EQ(0u, generation_manager_->messages().size()); 135 EXPECT_EQ(0u, generation_manager_->messages().size());
130 SetFocused(first_password_element.to<WebNode>()); 136 SimulateClickOnDecoration(first_password_element);
131 EXPECT_EQ(1u, generation_manager_->messages().size()); 137 EXPECT_EQ(1u, generation_manager_->messages().size());
132 EXPECT_EQ(AutofillHostMsg_ShowPasswordGenerationPopup::ID, 138 EXPECT_EQ(AutofillHostMsg_ShowPasswordGenerationPopup::ID,
133 generation_manager_->messages()[0]->type()); 139 generation_manager_->messages()[0]->type());
134 } 140 }
135 141
136 TEST_F(PasswordGenerationManagerTest, FillTest) { 142 TEST_F(PasswordGenerationManagerTest, FillTest) {
137 // Make sure that we are enabled before loading HTML. 143 // Make sure that we are enabled before loading HTML.
138 AutofillMsg_PasswordGenerationEnabled enabled_msg(0, true); 144 AutofillMsg_PasswordGenerationEnabled enabled_msg(0, true);
139 generation_manager_->OnMessageReceived(enabled_msg); 145 generation_manager_->OnMessageReceived(enabled_msg);
140 LoadHTML(kAccountCreationFormHTML); 146 LoadHTML(kAccountCreationFormHTML);
(...skipping 16 matching lines...) Expand all
157 generation_manager_->OnMessageReceived(msg); 163 generation_manager_->OnMessageReceived(msg);
158 164
159 // Password fields are filled out and set as being autofilled. 165 // Password fields are filled out and set as being autofilled.
160 EXPECT_EQ(password, first_password_element.value()); 166 EXPECT_EQ(password, first_password_element.value());
161 EXPECT_EQ(password, second_password_element.value()); 167 EXPECT_EQ(password, second_password_element.value());
162 EXPECT_TRUE(first_password_element.isAutofilled()); 168 EXPECT_TRUE(first_password_element.isAutofilled());
163 EXPECT_TRUE(second_password_element.isAutofilled()); 169 EXPECT_TRUE(second_password_element.isAutofilled());
164 } 170 }
165 171
166 } // namespace autofill 172 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698