| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <string.h> | 5 #include <string.h> |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/memory/scoped_vector.h" | 8 #include "base/memory/scoped_vector.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/test/base/chrome_render_view_test.h" | 10 #include "chrome/test/base/chrome_render_view_test.h" |
| 11 #include "components/autofill/content/renderer/password_generation_agent.h" | 11 #include "components/autofill/content/renderer/password_generation_agent.h" |
| 12 #include "components/autofill/core/common/autofill_messages.h" | 12 #include "components/autofill/core/common/autofill_messages.h" |
| 13 #include "components/autofill/core/common/form_data.h" | 13 #include "components/autofill/core/common/form_data.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "third_party/WebKit/public/platform/WebString.h" | 15 #include "third_party/WebKit/public/platform/WebString.h" |
| 16 #include "third_party/WebKit/public/web/WebDocument.h" | 16 #include "third_party/WebKit/public/web/WebDocument.h" |
| 17 #include "third_party/WebKit/public/web/WebWidget.h" | 17 #include "third_party/WebKit/public/web/WebWidget.h" |
| 18 | 18 |
| 19 using WebKit::WebDocument; | 19 using blink::WebDocument; |
| 20 using WebKit::WebElement; | 20 using blink::WebElement; |
| 21 using WebKit::WebInputElement; | 21 using blink::WebInputElement; |
| 22 using WebKit::WebNode; | 22 using blink::WebNode; |
| 23 using WebKit::WebString; | 23 using blink::WebString; |
| 24 | 24 |
| 25 namespace autofill { | 25 namespace autofill { |
| 26 | 26 |
| 27 class TestPasswordGenerationAgent : public PasswordGenerationAgent { | 27 class TestPasswordGenerationAgent : public PasswordGenerationAgent { |
| 28 public: | 28 public: |
| 29 explicit TestPasswordGenerationAgent(content::RenderView* view) | 29 explicit TestPasswordGenerationAgent(content::RenderView* view) |
| 30 : PasswordGenerationAgent(view) {} | 30 : PasswordGenerationAgent(view) {} |
| 31 virtual ~TestPasswordGenerationAgent() {} | 31 virtual ~TestPasswordGenerationAgent() {} |
| 32 | 32 |
| 33 // Make this public | 33 // Make this public |
| 34 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { | 34 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { |
| 35 return PasswordGenerationAgent::OnMessageReceived(message); | 35 return PasswordGenerationAgent::OnMessageReceived(message); |
| 36 } | 36 } |
| 37 | 37 |
| 38 const std::vector<IPC::Message*>& messages() { | 38 const std::vector<IPC::Message*>& messages() { |
| 39 return messages_.get(); | 39 return messages_.get(); |
| 40 } | 40 } |
| 41 | 41 |
| 42 void ClearMessages() { | 42 void ClearMessages() { |
| 43 messages_.clear(); | 43 messages_.clear(); |
| 44 } | 44 } |
| 45 | 45 |
| 46 protected: | 46 protected: |
| 47 virtual bool ShouldAnalyzeDocument(const WebKit::WebDocument& document) const | 47 virtual bool ShouldAnalyzeDocument(const blink::WebDocument& document) const |
| 48 OVERRIDE { | 48 OVERRIDE { |
| 49 return true; | 49 return true; |
| 50 } | 50 } |
| 51 | 51 |
| 52 virtual bool Send(IPC::Message* message) OVERRIDE { | 52 virtual bool Send(IPC::Message* message) OVERRIDE { |
| 53 messages_.push_back(message); | 53 messages_.push_back(message); |
| 54 return true; | 54 return true; |
| 55 } | 55 } |
| 56 | 56 |
| 57 private: | 57 private: |
| (...skipping 13 matching lines...) Expand all Loading... |
| 71 ChromeRenderViewTest::SetUp(); | 71 ChromeRenderViewTest::SetUp(); |
| 72 generation_manager_.reset(new TestPasswordGenerationAgent(view_)); | 72 generation_manager_.reset(new TestPasswordGenerationAgent(view_)); |
| 73 } | 73 } |
| 74 | 74 |
| 75 virtual void TearDown() { | 75 virtual void TearDown() { |
| 76 LoadHTML(""); | 76 LoadHTML(""); |
| 77 generation_manager_.reset(); | 77 generation_manager_.reset(); |
| 78 ChromeRenderViewTest::TearDown(); | 78 ChromeRenderViewTest::TearDown(); |
| 79 } | 79 } |
| 80 | 80 |
| 81 void SimulateClickOnDecoration(WebKit::WebInputElement* input_element) { | 81 void SimulateClickOnDecoration(blink::WebInputElement* input_element) { |
| 82 generation_manager_->ClearMessages(); | 82 generation_manager_->ClearMessages(); |
| 83 WebKit::WebElement decoration = | 83 blink::WebElement decoration = |
| 84 input_element->decorationElementFor(generation_manager_.get()); | 84 input_element->decorationElementFor(generation_manager_.get()); |
| 85 decoration.simulateClick(); | 85 decoration.simulateClick(); |
| 86 } | 86 } |
| 87 | 87 |
| 88 bool DecorationIsVisible(WebKit::WebInputElement* input_element) { | 88 bool DecorationIsVisible(blink::WebInputElement* input_element) { |
| 89 WebKit::WebElement decoration = | 89 blink::WebElement decoration = |
| 90 input_element->decorationElementFor(generation_manager_.get()); | 90 input_element->decorationElementFor(generation_manager_.get()); |
| 91 return decoration.hasNonEmptyBoundingBox(); | 91 return decoration.hasNonEmptyBoundingBox(); |
| 92 } | 92 } |
| 93 | 93 |
| 94 void SetNotBlacklistedMessage(const char* form_str) { | 94 void SetNotBlacklistedMessage(const char* form_str) { |
| 95 autofill::PasswordForm form; | 95 autofill::PasswordForm form; |
| 96 form.origin = | 96 form.origin = |
| 97 GURL(base::StringPrintf("data:text/html;charset=utf-8,%s", form_str)); | 97 GURL(base::StringPrintf("data:text/html;charset=utf-8,%s", form_str)); |
| 98 AutofillMsg_FormNotBlacklisted msg(0, form); | 98 AutofillMsg_FormNotBlacklisted msg(0, form); |
| 99 generation_manager_->OnMessageReceived(msg); | 99 generation_manager_->OnMessageReceived(msg); |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 | 271 |
| 272 // Receive the account creation forms detected message. Show password | 272 // Receive the account creation forms detected message. Show password |
| 273 // generation icon. | 273 // generation icon. |
| 274 LoadHTML(kAccountCreationFormHTML); | 274 LoadHTML(kAccountCreationFormHTML); |
| 275 SetNotBlacklistedMessage(kAccountCreationFormHTML); | 275 SetNotBlacklistedMessage(kAccountCreationFormHTML); |
| 276 SetAccountCreationFormsDetectedMessage(kAccountCreationFormHTML); | 276 SetAccountCreationFormsDetectedMessage(kAccountCreationFormHTML); |
| 277 ExpectPasswordGenerationIconShown("first_password", true); | 277 ExpectPasswordGenerationIconShown("first_password", true); |
| 278 } | 278 } |
| 279 | 279 |
| 280 } // namespace autofill | 280 } // namespace autofill |
| OLD | NEW |