| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/autofill/content/browser/content_autofill_driver.h" | 5 #include "components/autofill/content/browser/content_autofill_driver.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 // Returns data received via mojo interface method | 130 // Returns data received via mojo interface method |
| 131 // mojom::AutofillAent::AcceptDataListSuggestion(). | 131 // mojom::AutofillAent::AcceptDataListSuggestion(). |
| 132 bool GetString16AcceptDataListSuggestion(base::string16* value) { | 132 bool GetString16AcceptDataListSuggestion(base::string16* value) { |
| 133 if (!value_accept_data_) | 133 if (!value_accept_data_) |
| 134 return false; | 134 return false; |
| 135 if (value) | 135 if (value) |
| 136 *value = *value_accept_data_; | 136 *value = *value_accept_data_; |
| 137 return true; | 137 return true; |
| 138 } | 138 } |
| 139 | 139 |
| 140 // Mocked mojom::AutofillAgent methods: |
| 141 MOCK_METHOD0(FirstUserGestureObservedInTab, void()); |
| 142 |
| 140 private: | 143 private: |
| 141 void CallDone() { | 144 void CallDone() { |
| 142 if (!quit_closure_.is_null()) { | 145 if (!quit_closure_.is_null()) { |
| 143 quit_closure_.Run(); | 146 quit_closure_.Run(); |
| 144 quit_closure_.Reset(); | 147 quit_closure_.Reset(); |
| 145 } | 148 } |
| 146 } | 149 } |
| 147 | 150 |
| 148 // mojom::AutofillAgent methods: | 151 // mojom::AutofillAgent: |
| 149 void FirstUserGestureObservedInTab() override {} | |
| 150 | |
| 151 void FillForm(int32_t id, const FormData& form) override { | 152 void FillForm(int32_t id, const FormData& form) override { |
| 152 fill_form_id_ = id; | 153 fill_form_id_ = id; |
| 153 fill_form_form_ = form; | 154 fill_form_form_ = form; |
| 154 CallDone(); | 155 CallDone(); |
| 155 } | 156 } |
| 156 | 157 |
| 157 void PreviewForm(int32_t id, const FormData& form) override { | 158 void PreviewForm(int32_t id, const FormData& form) override { |
| 158 preview_form_id_ = id; | 159 preview_form_id_ = id; |
| 159 preview_form_form_ = form; | 160 preview_form_form_ = form; |
| 160 CallDone(); | 161 CallDone(); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 | 230 |
| 230 class MockAutofillManager : public AutofillManager { | 231 class MockAutofillManager : public AutofillManager { |
| 231 public: | 232 public: |
| 232 MockAutofillManager(AutofillDriver* driver, AutofillClient* client) | 233 MockAutofillManager(AutofillDriver* driver, AutofillClient* client) |
| 233 : AutofillManager(driver, client, kAppLocale, kDownloadState) {} | 234 : AutofillManager(driver, client, kAppLocale, kDownloadState) {} |
| 234 virtual ~MockAutofillManager() {} | 235 virtual ~MockAutofillManager() {} |
| 235 | 236 |
| 236 MOCK_METHOD0(Reset, void()); | 237 MOCK_METHOD0(Reset, void()); |
| 237 }; | 238 }; |
| 238 | 239 |
| 240 class MockAutofillClient : public TestAutofillClient { |
| 241 public: |
| 242 MOCK_METHOD0(OnFirstUserGestureObserved, void()); |
| 243 }; |
| 244 |
| 239 class TestContentAutofillDriver : public ContentAutofillDriver { | 245 class TestContentAutofillDriver : public ContentAutofillDriver { |
| 240 public: | 246 public: |
| 241 TestContentAutofillDriver(content::RenderFrameHost* rfh, | 247 TestContentAutofillDriver(content::RenderFrameHost* rfh, |
| 242 AutofillClient* client) | 248 AutofillClient* client) |
| 243 : ContentAutofillDriver(rfh, client, kAppLocale, kDownloadState) { | 249 : ContentAutofillDriver(rfh, client, kAppLocale, kDownloadState) { |
| 244 std::unique_ptr<AutofillManager> autofill_manager( | 250 std::unique_ptr<AutofillManager> autofill_manager( |
| 245 new MockAutofillManager(this, client)); | 251 new MockAutofillManager(this, client)); |
| 246 SetAutofillManager(std::move(autofill_manager)); | 252 SetAutofillManager(std::move(autofill_manager)); |
| 247 } | 253 } |
| 248 ~TestContentAutofillDriver() override {} | 254 ~TestContentAutofillDriver() override {} |
| 249 | 255 |
| 250 virtual MockAutofillManager* mock_autofill_manager() { | 256 virtual MockAutofillManager* mock_autofill_manager() { |
| 251 return static_cast<MockAutofillManager*>(autofill_manager()); | 257 return static_cast<MockAutofillManager*>(autofill_manager()); |
| 252 } | 258 } |
| 253 | 259 |
| 254 using ContentAutofillDriver::DidNavigateFrame; | 260 using ContentAutofillDriver::DidNavigateFrame; |
| 255 }; | 261 }; |
| 256 | 262 |
| 257 class ContentAutofillDriverTest : public content::RenderViewHostTestHarness { | 263 class ContentAutofillDriverTest : public content::RenderViewHostTestHarness { |
| 258 public: | 264 public: |
| 259 void SetUp() override { | 265 void SetUp() override { |
| 260 content::RenderViewHostTestHarness::SetUp(); | 266 content::RenderViewHostTestHarness::SetUp(); |
| 261 | 267 |
| 262 test_autofill_client_.reset(new TestAutofillClient()); | 268 test_autofill_client_.reset(new MockAutofillClient()); |
| 263 driver_.reset(new TestContentAutofillDriver(web_contents()->GetMainFrame(), | 269 driver_.reset(new TestContentAutofillDriver(web_contents()->GetMainFrame(), |
| 264 test_autofill_client_.get())); | 270 test_autofill_client_.get())); |
| 265 | 271 |
| 266 service_manager::InterfaceProvider* remote_interfaces = | 272 service_manager::InterfaceProvider* remote_interfaces = |
| 267 web_contents()->GetMainFrame()->GetRemoteInterfaces(); | 273 web_contents()->GetMainFrame()->GetRemoteInterfaces(); |
| 268 service_manager::InterfaceProvider::TestApi test_api(remote_interfaces); | 274 service_manager::InterfaceProvider::TestApi test_api(remote_interfaces); |
| 269 test_api.SetBinderForName(mojom::AutofillAgent::Name_, | 275 test_api.SetBinderForName(mojom::AutofillAgent::Name_, |
| 270 base::Bind(&FakeAutofillAgent::BindRequest, | 276 base::Bind(&FakeAutofillAgent::BindRequest, |
| 271 base::Unretained(&fake_agent_))); | 277 base::Unretained(&fake_agent_))); |
| 272 } | 278 } |
| 273 | 279 |
| 274 void TearDown() override { | 280 void TearDown() override { |
| 275 // Reset the driver now to cause all pref observers to be removed and avoid | 281 // Reset the driver now to cause all pref observers to be removed and avoid |
| 276 // crashes that otherwise occur in the destructor. | 282 // crashes that otherwise occur in the destructor. |
| 277 driver_.reset(); | 283 driver_.reset(); |
| 278 content::RenderViewHostTestHarness::TearDown(); | 284 content::RenderViewHostTestHarness::TearDown(); |
| 279 } | 285 } |
| 280 | 286 |
| 281 protected: | 287 protected: |
| 282 std::unique_ptr<TestAutofillClient> test_autofill_client_; | 288 std::unique_ptr<MockAutofillClient> test_autofill_client_; |
| 283 std::unique_ptr<TestContentAutofillDriver> driver_; | 289 std::unique_ptr<TestContentAutofillDriver> driver_; |
| 284 | 290 |
| 285 FakeAutofillAgent fake_agent_; | 291 FakeAutofillAgent fake_agent_; |
| 286 }; | 292 }; |
| 287 | 293 |
| 288 TEST_F(ContentAutofillDriverTest, GetURLRequestContext) { | 294 TEST_F(ContentAutofillDriverTest, GetURLRequestContext) { |
| 289 net::URLRequestContextGetter* request_context = | 295 net::URLRequestContextGetter* request_context = |
| 290 driver_->GetURLRequestContext(); | 296 driver_->GetURLRequestContext(); |
| 291 net::URLRequestContextGetter* expected_request_context = | 297 net::URLRequestContextGetter* expected_request_context = |
| 292 content::BrowserContext::GetDefaultStoragePartition( | 298 content::BrowserContext::GetDefaultStoragePartition( |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 driver_->DidInteractWithCreditCardForm(); | 478 driver_->DidInteractWithCreditCardForm(); |
| 473 | 479 |
| 474 content::NavigationEntry* entry = | 480 content::NavigationEntry* entry = |
| 475 web_contents()->GetController().GetVisibleEntry(); | 481 web_contents()->GetController().GetVisibleEntry(); |
| 476 ASSERT_TRUE(entry); | 482 ASSERT_TRUE(entry); |
| 477 EXPECT_EQ(url, entry->GetURL()); | 483 EXPECT_EQ(url, entry->GetURL()); |
| 478 EXPECT_FALSE(!!(entry->GetSSL().content_status & | 484 EXPECT_FALSE(!!(entry->GetSSL().content_status & |
| 479 content::SSLStatus::DISPLAYED_CREDIT_CARD_FIELD_ON_HTTP)); | 485 content::SSLStatus::DISPLAYED_CREDIT_CARD_FIELD_ON_HTTP)); |
| 480 } | 486 } |
| 481 | 487 |
| 488 TEST_F(ContentAutofillDriverTest, NotifyFirstUserGestureObservedInTab) { |
| 489 driver_->NotifyFirstUserGestureObservedInTab(); |
| 490 EXPECT_CALL(fake_agent_, FirstUserGestureObservedInTab()); |
| 491 base::RunLoop().RunUntilIdle(); |
| 492 } |
| 493 |
| 494 TEST_F(ContentAutofillDriverTest, FirstUserGestureObserved) { |
| 495 EXPECT_CALL(*test_autofill_client_, OnFirstUserGestureObserved()); |
| 496 driver_->FirstUserGestureObserved(); |
| 497 } |
| 498 |
| 482 } // namespace autofill | 499 } // namespace autofill |
| OLD | NEW |