Chromium Code Reviews| Index: chrome/renderer/autofill/password_generation_manager_browsertest.cc |
| diff --git a/chrome/renderer/autofill/password_generation_manager_browsertest.cc b/chrome/renderer/autofill/password_generation_manager_browsertest.cc |
| index ce9367f31ba69f56bf31ea3ca5d8814fb25bf4e5..7338e8b9540500dd7f1d17f022ba7fc19a3ba970 100644 |
| --- a/chrome/renderer/autofill/password_generation_manager_browsertest.cc |
| +++ b/chrome/renderer/autofill/password_generation_manager_browsertest.cc |
| @@ -37,7 +37,7 @@ class TestPasswordGenerationManager : public PasswordGenerationManager { |
| } |
| protected: |
| - virtual bool ShouldAnalyzeFrame(const WebKit::WebFrame& frame) const |
| + virtual bool ShouldAnalyzeDocument(const WebKit::WebDocument& document) const |
| OVERRIDE { |
| return true; |
| } |
| @@ -65,6 +65,18 @@ class PasswordGenerationManagerTest : public ChromeRenderViewTest { |
| generation_manager_.reset(new TestPasswordGenerationManager(view_)); |
| } |
| + void SimulateClickOnDecoration(WebKit::WebInputElement& input_element) { |
|
Ilya Sherman
2012/06/01 02:57:16
nit: Please pass either by const-reference or as a
|
| + WebKit::WebElement decoration = |
| + input_element.decorationElementFor(generation_manager_.get()); |
| + decoration.simulateClick(); |
| + } |
| + |
| + bool DecorationIsVisible(WebKit::WebInputElement& input_element) { |
|
Ilya Sherman
2012/06/01 02:57:16
nit: Please pass either by const-reference or as a
|
| + WebKit::WebElement decoration = |
| + input_element.decorationElementFor(generation_manager_.get()); |
| + return decoration.hasNonEmptyBoundingBox(); |
| + } |
| + |
| protected: |
| scoped_ptr<TestPasswordGenerationManager> generation_manager_; |
| @@ -95,39 +107,36 @@ TEST_F(PasswordGenerationManagerTest, DetectionTest) { |
| document.getElementById(WebString::fromUTF8("password")); |
| ASSERT_FALSE(element.isNull()); |
| WebInputElement password_element = element.to<WebInputElement>(); |
| - EXPECT_EQ(0u, generation_manager_->messages().size()); |
| + EXPECT_FALSE(DecorationIsVisible(password_element)); |
| LoadHTML(kAccountCreationFormHTML); |
| - // We don't do anything yet because the feature is disabled. |
| + // We don't show the decoration yet because the feature isn't enabled. |
| document = GetMainFrame()->document(); |
| element = document.getElementById(WebString::fromUTF8("first_password")); |
| ASSERT_FALSE(element.isNull()); |
| WebInputElement first_password_element = element.to<WebInputElement>(); |
| - 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_EQ(0u, generation_manager_->messages().size()); |
| - SetFocused(first_password_element.to<WebNode>()); |
| - EXPECT_EQ(0u, generation_manager_->messages().size()); |
| + EXPECT_FALSE(DecorationIsVisible(first_password_element)); |
| // Pretend like password generation was enabled. |
| AutofillMsg_PasswordGenerationEnabled msg(0, true); |
| generation_manager_->OnMessageReceived(msg); |
| - // Now we will send a message once the first password feld is focused. |
| + // Now check that the decoration is visible on the first password field and |
| + // that we send a message after the decoration is clicked. |
| LoadHTML(kAccountCreationFormHTML); |
| document = GetMainFrame()->document(); |
| element = document.getElementById(WebString::fromUTF8("first_password")); |
| ASSERT_FALSE(element.isNull()); |
| first_password_element = element.to<WebInputElement>(); |
| - EXPECT_EQ(0u, generation_manager_->messages().size()); |
| element = document.getElementById(WebString::fromUTF8("second_password")); |
| ASSERT_FALSE(element.isNull()); |
| second_password_element = element.to<WebInputElement>(); |
| - EXPECT_EQ(0u, generation_manager_->messages().size()); |
| - SetFocused(first_password_element.to<WebNode>()); |
| + EXPECT_TRUE(DecorationIsVisible(first_password_element)); |
| + SimulateClickOnDecoration(first_password_element); |
| EXPECT_EQ(1u, generation_manager_->messages().size()); |
| EXPECT_EQ(AutofillHostMsg_ShowPasswordGenerationPopup::ID, |
| generation_manager_->messages()[0]->type()); |