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 // Searches for an |AutofillMsg_FormDataFilled| message in the queue of sent | |
| 82 // IPC messages. If none is present, returns false. Otherwise, Extracts the | |
|
Ilya Sherman
2013/06/27 23:13:02
nit: "Extracts" -> "extracts"
blundell
2013/06/28 08:25:58
Done.
| |
| 83 // first |AutofillMsg_FormDataFilled| message, fills the output parameters | |
| 84 // with the values of the message's parameters, and clears the queue of sent | |
| 85 // messages. | |
| 86 bool GetAutofillFormDataFilledMessage(int* page_id, FormData* results) { | |
| 87 const uint32 kMsgID = AutofillMsg_FormDataFilled::ID; | |
| 88 const IPC::Message* message = | |
| 89 process()->sink().GetFirstMessageMatching(kMsgID); | |
| 90 if (!message) | |
| 91 return false; | |
| 92 Tuple2<int, FormData> autofill_param; | |
| 93 AutofillMsg_FormDataFilled::Read(message, &autofill_param); | |
| 94 if (page_id) | |
| 95 *page_id = autofill_param.a; | |
| 96 if (results) | |
| 97 *results = autofill_param.b; | |
| 98 | |
| 99 process()->sink().ClearMessages(); | |
| 100 return true; | |
| 101 } | |
| 102 | |
| 77 scoped_ptr<TestAutofillManagerDelegate> test_manager_delegate_; | 103 scoped_ptr<TestAutofillManagerDelegate> test_manager_delegate_; |
| 78 scoped_ptr<TestAutofillDriverImpl> driver_; | 104 scoped_ptr<TestAutofillDriverImpl> driver_; |
| 79 }; | 105 }; |
| 80 | 106 |
| 81 TEST_F(AutofillDriverImplTest, NavigatedToDifferentPage) { | 107 TEST_F(AutofillDriverImplTest, NavigatedToDifferentPage) { |
| 82 EXPECT_CALL(*driver_->mock_autofill_manager(), Reset()); | 108 EXPECT_CALL(*driver_->mock_autofill_manager(), Reset()); |
| 83 content::LoadCommittedDetails details = content::LoadCommittedDetails(); | 109 content::LoadCommittedDetails details = content::LoadCommittedDetails(); |
| 84 details.is_main_frame = true; | 110 details.is_main_frame = true; |
| 85 details.is_in_page = false; | 111 details.is_in_page = false; |
| 86 ASSERT_TRUE(details.is_navigation_to_different_page()); | 112 ASSERT_TRUE(details.is_navigation_to_different_page()); |
| 87 content::FrameNavigateParams params = content::FrameNavigateParams(); | 113 content::FrameNavigateParams params = content::FrameNavigateParams(); |
| 88 driver_->DidNavigateMainFrame(details, params); | 114 driver_->DidNavigateMainFrame(details, params); |
| 89 } | 115 } |
| 90 | 116 |
| 91 TEST_F(AutofillDriverImplTest, NavigatedWithinSamePage) { | 117 TEST_F(AutofillDriverImplTest, NavigatedWithinSamePage) { |
| 92 EXPECT_CALL(*driver_->mock_autofill_manager(), Reset()).Times(0); | 118 EXPECT_CALL(*driver_->mock_autofill_manager(), Reset()).Times(0); |
| 93 content::LoadCommittedDetails details = content::LoadCommittedDetails(); | 119 content::LoadCommittedDetails details = content::LoadCommittedDetails(); |
| 94 details.is_main_frame = false; | 120 details.is_main_frame = false; |
| 95 ASSERT_TRUE(!details.is_navigation_to_different_page()); | 121 ASSERT_TRUE(!details.is_navigation_to_different_page()); |
| 96 content::FrameNavigateParams params = content::FrameNavigateParams(); | 122 content::FrameNavigateParams params = content::FrameNavigateParams(); |
| 97 driver_->DidNavigateMainFrame(details, params); | 123 driver_->DidNavigateMainFrame(details, params); |
| 98 } | 124 } |
| 99 | 125 |
| 126 TEST_F(AutofillDriverImplTest, FormDataSentToRenderer) { | |
| 127 int input_page_id = 42; | |
| 128 FormData input_form_data; | |
| 129 test::CreateTestAddressFormData(&input_form_data); | |
| 130 driver_->SendFormDataToRenderer(input_page_id, input_form_data); | |
| 131 | |
| 132 int output_page_id = 0; | |
| 133 FormData output_form_data; | |
| 134 EXPECT_TRUE(GetAutofillFormDataFilledMessage(&output_page_id, | |
| 135 &output_form_data)); | |
| 136 EXPECT_EQ(input_page_id, output_page_id); | |
| 137 EXPECT_EQ(input_form_data, output_form_data); | |
| 138 } | |
| 139 | |
| 100 } // namespace autofill | 140 } // namespace autofill |
| OLD | NEW |