summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/autofill/password_generation_manager_browsertest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/renderer/autofill/password_generation_manager_browsertest.cc')
-rw-r--r--chrome/renderer/autofill/password_generation_manager_browsertest.cc65
1 files changed, 60 insertions, 5 deletions
diff --git a/chrome/renderer/autofill/password_generation_manager_browsertest.cc b/chrome/renderer/autofill/password_generation_manager_browsertest.cc
index f66c365..72e612b 100644
--- a/chrome/renderer/autofill/password_generation_manager_browsertest.cc
+++ b/chrome/renderer/autofill/password_generation_manager_browsertest.cc
@@ -3,6 +3,9 @@
// found in the LICENSE file.
#include "base/memory/scoped_ptr.h"
+#include "base/memory/scoped_vector.h"
+#include "base/utf_string_conversions.h"
+#include "chrome/common/autofill_messages.h"
#include "chrome/renderer/autofill/password_generation_manager.h"
#include "chrome/test/base/chrome_render_view_test.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -24,13 +27,29 @@ class TestPasswordGenerationManager : public PasswordGenerationManager {
: PasswordGenerationManager(view) {}
virtual ~TestPasswordGenerationManager() {}
+ // Make this public
+ virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE {
+ return PasswordGenerationManager::OnMessageReceived(message);
+ }
+
+ const std::vector<IPC::Message*>& messages() {
+ return messages_.get();
+ }
+
protected:
virtual bool ShouldAnalyzeFrame(const WebKit::WebFrame& frame) const
OVERRIDE {
return true;
}
+ virtual bool Send(IPC::Message* message) OVERRIDE {
+ messages_.push_back(message);
+ return true;
+ }
+
private:
+ ScopedVector<IPC::Message> messages_;
+
DISALLOW_COPY_AND_ASSIGN(TestPasswordGenerationManager);
};
@@ -46,9 +65,10 @@ class PasswordGenerationManagerTest : public ChromeRenderViewTest {
generation_manager_.reset(new TestPasswordGenerationManager(view_));
}
- private:
- scoped_ptr<PasswordGenerationManager> generation_manager_;
+ protected:
+ scoped_ptr<TestPasswordGenerationManager> generation_manager_;
+ private:
DISALLOW_COPY_AND_ASSIGN(PasswordGenerationManagerTest);
};
@@ -67,7 +87,7 @@ TEST_F(PasswordGenerationManagerTest, DetectionTest) {
document.getElementById(WebString::fromUTF8("password"));
ASSERT_FALSE(element.isNull());
WebInputElement password_element = element.to<WebInputElement>();
- EXPECT_FALSE(password_element.isAutofilled());
+ EXPECT_EQ(0u, generation_manager_->messages().size());
const char kAccountCreationFormHTML[] =
"<FORM name = 'blah' action = 'www.random.com/'> "
@@ -83,14 +103,49 @@ TEST_F(PasswordGenerationManagerTest, DetectionTest) {
element = document.getElementById(WebString::fromUTF8("first_password"));
ASSERT_FALSE(element.isNull());
WebInputElement first_password_element = element.to<WebInputElement>();
- EXPECT_FALSE(first_password_element.isAutofilled());
+ EXPECT_EQ(0u, generation_manager_->messages().size());
element = document.getElementById(WebString::fromUTF8("second_password"));
ASSERT_FALSE(element.isNull());
WebInputElement second_password_element = element.to<WebInputElement>();
- EXPECT_FALSE(second_password_element.isAutofilled());
+ EXPECT_EQ(0u, generation_manager_->messages().size());
// After first element is focused, then we autofill.
SetFocused(first_password_element.to<WebNode>());
+ EXPECT_EQ(1u, generation_manager_->messages().size());
+ EXPECT_EQ(AutofillHostMsg_ShowPasswordGenerationPopup::ID,
+ generation_manager_->messages()[0]->type());
+}
+
+TEST_F(PasswordGenerationManagerTest, FillTest) {
+ const char kAccountCreationFormHTML[] =
+ "<FORM name = 'blah' action = 'www.random.com/'> "
+ " <INPUT type = 'text' id = 'username'/> "
+ " <INPUT type = 'password' id = 'first_password'/> "
+ " <INPUT type = 'password' id = 'second_password'/> "
+ " <INPUT type = 'submit' value = 'LOGIN' />"
+ "</FORM>";
+ LoadHTML(kAccountCreationFormHTML);
+
+ WebDocument document = GetMainFrame()->document();
+ WebElement element =
+ document.getElementById(WebString::fromUTF8("first_password"));
+ ASSERT_FALSE(element.isNull());
+ WebInputElement first_password_element = element.to<WebInputElement>();
+ element = document.getElementById(WebString::fromUTF8("second_password"));
+ ASSERT_FALSE(element.isNull());
+ WebInputElement second_password_element = element.to<WebInputElement>();
+
+ // Both password fields should be empty.
+ EXPECT_TRUE(first_password_element.value().isNull());
+ EXPECT_TRUE(second_password_element.value().isNull());
+
+ string16 password = ASCIIToUTF16("random_password");
+ AutofillMsg_GeneratedPasswordAccepted msg(0, password);
+ generation_manager_->OnMessageReceived(msg);
+
+ // Password fields are filled out and set as being autofilled.
+ EXPECT_EQ(password, first_password_element.value());
+ EXPECT_EQ(password, second_password_element.value());
EXPECT_TRUE(first_password_element.isAutofilled());
EXPECT_TRUE(second_password_element.isAutofilled());
}