| 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> |
| 11 #include <utility> | 11 #include <utility> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 17 #include "components/autofill/core/browser/autofill_external_delegate.h" | 17 #include "components/autofill/core/browser/autofill_external_delegate.h" |
| 18 #include "components/autofill/core/browser/autofill_manager.h" | 18 #include "components/autofill/core/browser/autofill_manager.h" |
| 19 #include "components/autofill/core/browser/autofill_test_utils.h" | 19 #include "components/autofill/core/browser/autofill_test_utils.h" |
| 20 #include "components/autofill/core/browser/test_autofill_client.h" | 20 #include "components/autofill/core/browser/test_autofill_client.h" |
| 21 #include "components/autofill/core/common/autofill_switches.h" | 21 #include "components/autofill/core/common/autofill_switches.h" |
| 22 #include "components/autofill/core/common/form_data_predictions.h" | 22 #include "components/autofill/core/common/form_data_predictions.h" |
| 23 #include "content/public/browser/browser_context.h" | 23 #include "content/public/browser/browser_context.h" |
| 24 #include "content/public/browser/navigation_details.h" | |
| 25 #include "content/public/browser/navigation_entry.h" | 24 #include "content/public/browser/navigation_entry.h" |
| 26 #include "content/public/browser/ssl_status.h" | 25 #include "content/public/browser/ssl_status.h" |
| 27 #include "content/public/browser/storage_partition.h" | 26 #include "content/public/browser/storage_partition.h" |
| 28 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
| 29 #include "content/public/common/frame_navigate_params.h" | |
| 30 #include "content/public/test/test_renderer_host.h" | 28 #include "content/public/test/test_renderer_host.h" |
| 31 #include "mojo/public/cpp/bindings/binding_set.h" | 29 #include "mojo/public/cpp/bindings/binding_set.h" |
| 32 #include "services/service_manager/public/cpp/interface_provider.h" | 30 #include "services/service_manager/public/cpp/interface_provider.h" |
| 33 #include "testing/gmock/include/gmock/gmock.h" | 31 #include "testing/gmock/include/gmock/gmock.h" |
| 34 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
| 35 | 33 |
| 36 namespace autofill { | 34 namespace autofill { |
| 37 | 35 |
| 38 namespace { | 36 namespace { |
| 39 | 37 |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 : ContentAutofillDriver(rfh, client, kAppLocale, kDownloadState) { | 247 : ContentAutofillDriver(rfh, client, kAppLocale, kDownloadState) { |
| 250 std::unique_ptr<AutofillManager> autofill_manager( | 248 std::unique_ptr<AutofillManager> autofill_manager( |
| 251 new MockAutofillManager(this, client)); | 249 new MockAutofillManager(this, client)); |
| 252 SetAutofillManager(std::move(autofill_manager)); | 250 SetAutofillManager(std::move(autofill_manager)); |
| 253 } | 251 } |
| 254 ~TestContentAutofillDriver() override {} | 252 ~TestContentAutofillDriver() override {} |
| 255 | 253 |
| 256 virtual MockAutofillManager* mock_autofill_manager() { | 254 virtual MockAutofillManager* mock_autofill_manager() { |
| 257 return static_cast<MockAutofillManager*>(autofill_manager()); | 255 return static_cast<MockAutofillManager*>(autofill_manager()); |
| 258 } | 256 } |
| 259 | |
| 260 using ContentAutofillDriver::DidNavigateFrame; | |
| 261 }; | 257 }; |
| 262 | 258 |
| 263 class ContentAutofillDriverTest : public content::RenderViewHostTestHarness { | 259 class ContentAutofillDriverTest : public content::RenderViewHostTestHarness { |
| 264 public: | 260 public: |
| 265 void SetUp() override { | 261 void SetUp() override { |
| 266 content::RenderViewHostTestHarness::SetUp(); | 262 content::RenderViewHostTestHarness::SetUp(); |
| 267 | 263 |
| 268 test_autofill_client_.reset(new MockAutofillClient()); | 264 test_autofill_client_.reset(new MockAutofillClient()); |
| 269 driver_.reset(new TestContentAutofillDriver(web_contents()->GetMainFrame(), | 265 driver_.reset(new TestContentAutofillDriver(web_contents()->GetMainFrame(), |
| 270 test_autofill_client_.get())); | 266 test_autofill_client_.get())); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 295 net::URLRequestContextGetter* request_context = | 291 net::URLRequestContextGetter* request_context = |
| 296 driver_->GetURLRequestContext(); | 292 driver_->GetURLRequestContext(); |
| 297 net::URLRequestContextGetter* expected_request_context = | 293 net::URLRequestContextGetter* expected_request_context = |
| 298 content::BrowserContext::GetDefaultStoragePartition( | 294 content::BrowserContext::GetDefaultStoragePartition( |
| 299 web_contents()->GetBrowserContext())->GetURLRequestContext(); | 295 web_contents()->GetBrowserContext())->GetURLRequestContext(); |
| 300 EXPECT_EQ(request_context, expected_request_context); | 296 EXPECT_EQ(request_context, expected_request_context); |
| 301 } | 297 } |
| 302 | 298 |
| 303 TEST_F(ContentAutofillDriverTest, NavigatedToDifferentPage) { | 299 TEST_F(ContentAutofillDriverTest, NavigatedToDifferentPage) { |
| 304 EXPECT_CALL(*driver_->mock_autofill_manager(), Reset()); | 300 EXPECT_CALL(*driver_->mock_autofill_manager(), Reset()); |
| 305 content::LoadCommittedDetails details = content::LoadCommittedDetails(); | 301 driver_->NavigatedToDifferentPage(); |
| 306 details.is_main_frame = true; | |
| 307 details.is_in_page = false; | |
| 308 ASSERT_TRUE(details.is_navigation_to_different_page()); | |
| 309 content::FrameNavigateParams params = content::FrameNavigateParams(); | |
| 310 driver_->DidNavigateFrame(details, params); | |
| 311 } | |
| 312 | |
| 313 TEST_F(ContentAutofillDriverTest, NavigatedWithinSamePage) { | |
| 314 EXPECT_CALL(*driver_->mock_autofill_manager(), Reset()).Times(0); | |
| 315 content::LoadCommittedDetails details = content::LoadCommittedDetails(); | |
| 316 details.is_main_frame = false; | |
| 317 ASSERT_TRUE(!details.is_navigation_to_different_page()); | |
| 318 content::FrameNavigateParams params = content::FrameNavigateParams(); | |
| 319 driver_->DidNavigateFrame(details, params); | |
| 320 } | 302 } |
| 321 | 303 |
| 322 TEST_F(ContentAutofillDriverTest, FormDataSentToRenderer_FillForm) { | 304 TEST_F(ContentAutofillDriverTest, FormDataSentToRenderer_FillForm) { |
| 323 int input_page_id = 42; | 305 int input_page_id = 42; |
| 324 FormData input_form_data; | 306 FormData input_form_data; |
| 325 test::CreateTestAddressFormData(&input_form_data); | 307 test::CreateTestAddressFormData(&input_form_data); |
| 326 base::RunLoop run_loop; | 308 base::RunLoop run_loop; |
| 327 fake_agent_.SetQuitLoopClosure(run_loop.QuitClosure()); | 309 fake_agent_.SetQuitLoopClosure(run_loop.QuitClosure()); |
| 328 driver_->SendFormDataToRenderer( | 310 driver_->SendFormDataToRenderer( |
| 329 input_page_id, AutofillDriver::FORM_DATA_ACTION_FILL, input_form_data); | 311 input_page_id, AutofillDriver::FORM_DATA_ACTION_FILL, input_form_data); |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 EXPECT_CALL(fake_agent_, FirstUserGestureObservedInTab()); | 472 EXPECT_CALL(fake_agent_, FirstUserGestureObservedInTab()); |
| 491 base::RunLoop().RunUntilIdle(); | 473 base::RunLoop().RunUntilIdle(); |
| 492 } | 474 } |
| 493 | 475 |
| 494 TEST_F(ContentAutofillDriverTest, FirstUserGestureObserved) { | 476 TEST_F(ContentAutofillDriverTest, FirstUserGestureObserved) { |
| 495 EXPECT_CALL(*test_autofill_client_, OnFirstUserGestureObserved()); | 477 EXPECT_CALL(*test_autofill_client_, OnFirstUserGestureObserved()); |
| 496 driver_->FirstUserGestureObserved(); | 478 driver_->FirstUserGestureObserved(); |
| 497 } | 479 } |
| 498 | 480 |
| 499 } // namespace autofill | 481 } // namespace autofill |
| OLD | NEW |