Chromium Code Reviews| 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 9 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 10 #include "components/autofill/content/browser/autofill_driver_impl.h" | 10 #include "components/autofill/content/browser/autofill_driver_impl.h" |
| 11 #include "components/autofill/core/browser/autofill_common_test.h" | |
| 11 #include "components/autofill/core/browser/autofill_external_delegate.h" | 12 #include "components/autofill/core/browser/autofill_external_delegate.h" |
| 12 #include "components/autofill/core/browser/autofill_manager.h" | 13 #include "components/autofill/core/browser/autofill_manager.h" |
| 13 #include "components/autofill/core/browser/test_autofill_manager_delegate.h" | 14 #include "components/autofill/core/browser/test_autofill_manager_delegate.h" |
| 15 #include "components/autofill/core/common/autofill_messages.h" | |
| 14 #include "content/public/browser/navigation_details.h" | 16 #include "content/public/browser/navigation_details.h" |
| 15 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
| 16 #include "content/public/common/frame_navigate_params.h" | 18 #include "content/public/common/frame_navigate_params.h" |
| 19 #include "content/public/test/mock_render_process_host.h" | |
| 20 #include "ipc/ipc_test_sink.h" | |
| 17 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 23 |
| 20 namespace autofill { | 24 namespace autofill { |
| 21 | 25 |
| 22 namespace { | 26 namespace { |
| 23 | 27 |
| 24 const std::string kAppLocale = "en-US"; | 28 const std::string kAppLocale = "en-US"; |
| 25 const AutofillManager::AutofillDownloadManagerState kDownloadState = | 29 const AutofillManager::AutofillDownloadManagerState kDownloadState = |
| 26 AutofillManager::DISABLE_AUTOFILL_DOWNLOAD_MANAGER; | 30 AutofillManager::DISABLE_AUTOFILL_DOWNLOAD_MANAGER; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 67 } | 71 } |
| 68 | 72 |
| 69 virtual void TearDown() OVERRIDE { | 73 virtual void TearDown() OVERRIDE { |
| 70 // Reset the driver now to cause all pref observers to be removed and avoid | 74 // Reset the driver now to cause all pref observers to be removed and avoid |
| 71 // crashes that otherwise occur in the destructor. | 75 // crashes that otherwise occur in the destructor. |
| 72 driver_.reset(); | 76 driver_.reset(); |
| 73 ChromeRenderViewHostTestHarness::TearDown(); | 77 ChromeRenderViewHostTestHarness::TearDown(); |
| 74 } | 78 } |
| 75 | 79 |
| 76 protected: | 80 protected: |
| 81 bool GetAutofillFormDataFilledMessage(int* page_id, FormData* results) { | |
|
Ilya Sherman
2013/06/26 22:54:58
nit: Docs, please.
blundell
2013/06/27 21:58:27
Done.
| |
| 82 const uint32 kMsgID = AutofillMsg_FormDataFilled::ID; | |
| 83 const IPC::Message* message = | |
| 84 process()->sink().GetFirstMessageMatching(kMsgID); | |
| 85 if (!message) | |
| 86 return false; | |
| 87 Tuple2<int, FormData> autofill_param; | |
| 88 AutofillMsg_FormDataFilled::Read(message, &autofill_param); | |
| 89 if (page_id) | |
| 90 *page_id = autofill_param.a; | |
| 91 if (results) | |
| 92 *results = autofill_param.b; | |
| 93 | |
| 94 process()->sink().ClearMessages(); | |
| 95 return true; | |
| 96 } | |
| 97 | |
| 77 scoped_ptr<TestAutofillManagerDelegate> test_manager_delegate_; | 98 scoped_ptr<TestAutofillManagerDelegate> test_manager_delegate_; |
| 78 scoped_ptr<TestAutofillDriverImpl> driver_; | 99 scoped_ptr<TestAutofillDriverImpl> driver_; |
| 79 }; | 100 }; |
| 80 | 101 |
| 81 TEST_F(AutofillDriverImplTest, NavigatedToDifferentPage) { | 102 TEST_F(AutofillDriverImplTest, NavigatedToDifferentPage) { |
| 82 EXPECT_CALL(*driver_->mock_autofill_manager(), Reset()); | 103 EXPECT_CALL(*driver_->mock_autofill_manager(), Reset()); |
| 83 content::LoadCommittedDetails details = content::LoadCommittedDetails(); | 104 content::LoadCommittedDetails details = content::LoadCommittedDetails(); |
| 84 details.is_main_frame = true; | 105 details.is_main_frame = true; |
| 85 details.is_in_page = false; | 106 details.is_in_page = false; |
| 86 ASSERT_TRUE(details.is_navigation_to_different_page()); | 107 ASSERT_TRUE(details.is_navigation_to_different_page()); |
| 87 content::FrameNavigateParams params = content::FrameNavigateParams(); | 108 content::FrameNavigateParams params = content::FrameNavigateParams(); |
| 88 driver_->DidNavigateMainFrame(details, params); | 109 driver_->DidNavigateMainFrame(details, params); |
| 89 } | 110 } |
| 90 | 111 |
| 91 TEST_F(AutofillDriverImplTest, NavigatedWithinSamePage) { | 112 TEST_F(AutofillDriverImplTest, NavigatedWithinSamePage) { |
| 92 EXPECT_CALL(*driver_->mock_autofill_manager(), Reset()).Times(0); | 113 EXPECT_CALL(*driver_->mock_autofill_manager(), Reset()).Times(0); |
| 93 content::LoadCommittedDetails details = content::LoadCommittedDetails(); | 114 content::LoadCommittedDetails details = content::LoadCommittedDetails(); |
| 94 details.is_main_frame = false; | 115 details.is_main_frame = false; |
| 95 ASSERT_TRUE(!details.is_navigation_to_different_page()); | 116 ASSERT_TRUE(!details.is_navigation_to_different_page()); |
| 96 content::FrameNavigateParams params = content::FrameNavigateParams(); | 117 content::FrameNavigateParams params = content::FrameNavigateParams(); |
| 97 driver_->DidNavigateMainFrame(details, params); | 118 driver_->DidNavigateMainFrame(details, params); |
| 98 } | 119 } |
| 99 | 120 |
| 121 TEST_F(AutofillDriverImplTest, FormDataSentToRenderer) { | |
| 122 int input_page_id = 42; | |
| 123 FormData input_form_data; | |
| 124 test::CreateTestAddressFormData(&input_form_data); | |
| 125 driver_->SendFormDataToRenderer(input_page_id, input_form_data); | |
| 126 | |
| 127 int output_page_id = 0; | |
| 128 FormData output_form_data; | |
| 129 EXPECT_TRUE(GetAutofillFormDataFilledMessage(&output_page_id, | |
| 130 &output_form_data)); | |
| 131 EXPECT_EQ(input_page_id, output_page_id); | |
| 132 EXPECT_EQ(input_form_data, output_form_data); | |
| 133 } | |
| 134 | |
| 100 } // namespace autofill | 135 } // namespace autofill |
| OLD | NEW |