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

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

Issue 10168017: Only enable password generation if password manager and autofill are both (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More comments Created 8 years, 8 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
« no previous file with comments | « chrome/renderer/autofill/password_generation_manager.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 WebInputElement first_password_element = element.to<WebInputElement>(); 106 WebInputElement first_password_element = element.to<WebInputElement>();
107 EXPECT_EQ(0u, generation_manager_->messages().size()); 107 EXPECT_EQ(0u, generation_manager_->messages().size());
108 element = document.getElementById(WebString::fromUTF8("second_password")); 108 element = document.getElementById(WebString::fromUTF8("second_password"));
109 ASSERT_FALSE(element.isNull()); 109 ASSERT_FALSE(element.isNull());
110 WebInputElement second_password_element = element.to<WebInputElement>(); 110 WebInputElement second_password_element = element.to<WebInputElement>();
111 EXPECT_EQ(0u, generation_manager_->messages().size()); 111 EXPECT_EQ(0u, generation_manager_->messages().size());
112 SetFocused(first_password_element.to<WebNode>()); 112 SetFocused(first_password_element.to<WebNode>());
113 EXPECT_EQ(0u, generation_manager_->messages().size()); 113 EXPECT_EQ(0u, generation_manager_->messages().size());
114 114
115 // Pretend like sync was enabled. 115 // Pretend like sync was enabled.
116 AutofillMsg_PasswordSyncEnabled msg(0, true); 116 AutofillMsg_PasswordGenerationEnabled msg(0, true);
117 generation_manager_->OnMessageReceived(msg); 117 generation_manager_->OnMessageReceived(msg);
118 118
119 // Now we will send a message once the first password feld is focused. 119 // Now we will send a message once the first password feld is focused.
120 LoadHTML(kAccountCreationFormHTML); 120 LoadHTML(kAccountCreationFormHTML);
121 document = GetMainFrame()->document(); 121 document = GetMainFrame()->document();
122 element = document.getElementById(WebString::fromUTF8("first_password")); 122 element = document.getElementById(WebString::fromUTF8("first_password"));
123 ASSERT_FALSE(element.isNull()); 123 ASSERT_FALSE(element.isNull());
124 first_password_element = element.to<WebInputElement>(); 124 first_password_element = element.to<WebInputElement>();
125 EXPECT_EQ(0u, generation_manager_->messages().size()); 125 EXPECT_EQ(0u, generation_manager_->messages().size());
126 element = document.getElementById(WebString::fromUTF8("second_password")); 126 element = document.getElementById(WebString::fromUTF8("second_password"));
127 ASSERT_FALSE(element.isNull()); 127 ASSERT_FALSE(element.isNull());
128 second_password_element = element.to<WebInputElement>(); 128 second_password_element = element.to<WebInputElement>();
129 EXPECT_EQ(0u, generation_manager_->messages().size()); 129 EXPECT_EQ(0u, generation_manager_->messages().size());
130 SetFocused(first_password_element.to<WebNode>()); 130 SetFocused(first_password_element.to<WebNode>());
131 EXPECT_EQ(1u, generation_manager_->messages().size()); 131 EXPECT_EQ(1u, generation_manager_->messages().size());
132 EXPECT_EQ(AutofillHostMsg_ShowPasswordGenerationPopup::ID, 132 EXPECT_EQ(AutofillHostMsg_ShowPasswordGenerationPopup::ID,
133 generation_manager_->messages()[0]->type()); 133 generation_manager_->messages()[0]->type());
134 } 134 }
135 135
136 TEST_F(PasswordGenerationManagerTest, FillTest) { 136 TEST_F(PasswordGenerationManagerTest, FillTest) {
137 // Make sure that we are enabled before loading HTML. 137 // Make sure that we are enabled before loading HTML.
138 AutofillMsg_PasswordSyncEnabled enabled_msg(0, true); 138 AutofillMsg_PasswordGenerationEnabled enabled_msg(0, true);
139 generation_manager_->OnMessageReceived(enabled_msg); 139 generation_manager_->OnMessageReceived(enabled_msg);
140 LoadHTML(kAccountCreationFormHTML); 140 LoadHTML(kAccountCreationFormHTML);
141 141
142 WebDocument document = GetMainFrame()->document(); 142 WebDocument document = GetMainFrame()->document();
143 WebElement element = 143 WebElement element =
144 document.getElementById(WebString::fromUTF8("first_password")); 144 document.getElementById(WebString::fromUTF8("first_password"));
145 ASSERT_FALSE(element.isNull()); 145 ASSERT_FALSE(element.isNull());
146 WebInputElement first_password_element = element.to<WebInputElement>(); 146 WebInputElement first_password_element = element.to<WebInputElement>();
147 element = document.getElementById(WebString::fromUTF8("second_password")); 147 element = document.getElementById(WebString::fromUTF8("second_password"));
148 ASSERT_FALSE(element.isNull()); 148 ASSERT_FALSE(element.isNull());
149 WebInputElement second_password_element = element.to<WebInputElement>(); 149 WebInputElement second_password_element = element.to<WebInputElement>();
150 150
151 // Both password fields should be empty. 151 // Both password fields should be empty.
152 EXPECT_TRUE(first_password_element.value().isNull()); 152 EXPECT_TRUE(first_password_element.value().isNull());
153 EXPECT_TRUE(second_password_element.value().isNull()); 153 EXPECT_TRUE(second_password_element.value().isNull());
154 154
155 string16 password = ASCIIToUTF16("random_password"); 155 string16 password = ASCIIToUTF16("random_password");
156 AutofillMsg_GeneratedPasswordAccepted msg(0, password); 156 AutofillMsg_GeneratedPasswordAccepted msg(0, password);
157 generation_manager_->OnMessageReceived(msg); 157 generation_manager_->OnMessageReceived(msg);
158 158
159 // Password fields are filled out and set as being autofilled. 159 // Password fields are filled out and set as being autofilled.
160 EXPECT_EQ(password, first_password_element.value()); 160 EXPECT_EQ(password, first_password_element.value());
161 EXPECT_EQ(password, second_password_element.value()); 161 EXPECT_EQ(password, second_password_element.value());
162 EXPECT_TRUE(first_password_element.isAutofilled()); 162 EXPECT_TRUE(first_password_element.isAutofilled());
163 EXPECT_TRUE(second_password_element.isAutofilled()); 163 EXPECT_TRUE(second_password_element.isAutofilled());
164 } 164 }
165 165
166 } // namespace autofill 166 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/renderer/autofill/password_generation_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698