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/command_line.h" |
8 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
9 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 10 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
10 #include "components/autofill/content/browser/autofill_driver_impl.h" | 11 #include "components/autofill/content/browser/autofill_driver_impl.h" |
11 #include "components/autofill/core/browser/autofill_common_test.h" | 12 #include "components/autofill/core/browser/autofill_common_test.h" |
12 #include "components/autofill/core/browser/autofill_external_delegate.h" | 13 #include "components/autofill/core/browser/autofill_external_delegate.h" |
13 #include "components/autofill/core/browser/autofill_manager.h" | 14 #include "components/autofill/core/browser/autofill_manager.h" |
14 #include "components/autofill/core/browser/test_autofill_manager_delegate.h" | 15 #include "components/autofill/core/browser/test_autofill_manager_delegate.h" |
15 #include "components/autofill/core/common/autofill_messages.h" | 16 #include "components/autofill/core/common/autofill_messages.h" |
| 17 #include "components/autofill/core/common/autofill_switches.h" |
| 18 #include "components/autofill/core/common/form_data_predictions.h" |
16 #include "content/public/browser/navigation_details.h" | 19 #include "content/public/browser/navigation_details.h" |
17 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
18 #include "content/public/common/frame_navigate_params.h" | 21 #include "content/public/common/frame_navigate_params.h" |
19 #include "content/public/test/mock_render_process_host.h" | 22 #include "content/public/test/mock_render_process_host.h" |
20 #include "ipc/ipc_test_sink.h" | 23 #include "ipc/ipc_test_sink.h" |
21 #include "testing/gmock/include/gmock/gmock.h" | 24 #include "testing/gmock/include/gmock/gmock.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
23 | 26 |
24 namespace autofill { | 27 namespace autofill { |
25 | 28 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 AutofillMsg_FormDataFilled::Read(message, &autofill_param); | 96 AutofillMsg_FormDataFilled::Read(message, &autofill_param); |
94 if (page_id) | 97 if (page_id) |
95 *page_id = autofill_param.a; | 98 *page_id = autofill_param.a; |
96 if (results) | 99 if (results) |
97 *results = autofill_param.b; | 100 *results = autofill_param.b; |
98 | 101 |
99 process()->sink().ClearMessages(); | 102 process()->sink().ClearMessages(); |
100 return true; | 103 return true; |
101 } | 104 } |
102 | 105 |
| 106 // Searches for an |AutofillMsg_FieldTypePredictionsAvailable| message in the |
| 107 // queue of sent IPC messages. If none is present, returns false. Otherwise, |
| 108 // extracts the first |AutofillMsg_FieldTypePredictionsAvailable| message, |
| 109 // fills the output parameter with the values of the message's parameter, and |
| 110 // clears the queue of sent messages. |
| 111 bool GetFieldTypePredictionsAvailable( |
| 112 std::vector<FormDataPredictions>* predictions) { |
| 113 const uint32 kMsgID = AutofillMsg_FieldTypePredictionsAvailable::ID; |
| 114 const IPC::Message* message = |
| 115 process()->sink().GetFirstMessageMatching(kMsgID); |
| 116 if (!message) |
| 117 return false; |
| 118 Tuple1<std::vector<FormDataPredictions> > autofill_param; |
| 119 AutofillMsg_FieldTypePredictionsAvailable::Read(message, &autofill_param); |
| 120 if (predictions) |
| 121 *predictions = autofill_param.a; |
| 122 |
| 123 process()->sink().ClearMessages(); |
| 124 return true; |
| 125 } |
| 126 |
| 127 |
103 scoped_ptr<TestAutofillManagerDelegate> test_manager_delegate_; | 128 scoped_ptr<TestAutofillManagerDelegate> test_manager_delegate_; |
104 scoped_ptr<TestAutofillDriverImpl> driver_; | 129 scoped_ptr<TestAutofillDriverImpl> driver_; |
105 }; | 130 }; |
106 | 131 |
107 TEST_F(AutofillDriverImplTest, NavigatedToDifferentPage) { | 132 TEST_F(AutofillDriverImplTest, NavigatedToDifferentPage) { |
108 EXPECT_CALL(*driver_->mock_autofill_manager(), Reset()); | 133 EXPECT_CALL(*driver_->mock_autofill_manager(), Reset()); |
109 content::LoadCommittedDetails details = content::LoadCommittedDetails(); | 134 content::LoadCommittedDetails details = content::LoadCommittedDetails(); |
110 details.is_main_frame = true; | 135 details.is_main_frame = true; |
111 details.is_in_page = false; | 136 details.is_in_page = false; |
112 ASSERT_TRUE(details.is_navigation_to_different_page()); | 137 ASSERT_TRUE(details.is_navigation_to_different_page()); |
(...skipping 17 matching lines...) Expand all Loading... |
130 driver_->SendFormDataToRenderer(input_page_id, input_form_data); | 155 driver_->SendFormDataToRenderer(input_page_id, input_form_data); |
131 | 156 |
132 int output_page_id = 0; | 157 int output_page_id = 0; |
133 FormData output_form_data; | 158 FormData output_form_data; |
134 EXPECT_TRUE(GetAutofillFormDataFilledMessage(&output_page_id, | 159 EXPECT_TRUE(GetAutofillFormDataFilledMessage(&output_page_id, |
135 &output_form_data)); | 160 &output_form_data)); |
136 EXPECT_EQ(input_page_id, output_page_id); | 161 EXPECT_EQ(input_page_id, output_page_id); |
137 EXPECT_EQ(input_form_data, output_form_data); | 162 EXPECT_EQ(input_form_data, output_form_data); |
138 } | 163 } |
139 | 164 |
| 165 TEST_F(AutofillDriverImplTest, TypePredictionsNotSentToRendererWhenDisabled) { |
| 166 FormData form; |
| 167 test::CreateTestAddressFormData(&form); |
| 168 FormStructure form_structure(form, std::string()); |
| 169 std::vector<FormStructure*> forms(1, &form_structure); |
| 170 driver_->SendAutofillTypePredictionsToRenderer(forms); |
| 171 EXPECT_FALSE(GetFieldTypePredictionsAvailable(NULL)); |
| 172 } |
| 173 |
| 174 TEST_F(AutofillDriverImplTest, TypePredictionsSentToRendererWhenEnabled) { |
| 175 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 176 switches::kShowAutofillTypePredictions); |
| 177 |
| 178 FormData form; |
| 179 test::CreateTestAddressFormData(&form); |
| 180 FormStructure form_structure(form, std::string()); |
| 181 std::vector<FormStructure*> forms(1, &form_structure); |
| 182 std::vector<FormDataPredictions> expected_type_predictions; |
| 183 FormStructure::GetFieldTypePredictions(forms, &expected_type_predictions); |
| 184 driver_->SendAutofillTypePredictionsToRenderer(forms); |
| 185 |
| 186 std::vector<FormDataPredictions> output_type_predictions; |
| 187 EXPECT_TRUE(GetFieldTypePredictionsAvailable(&output_type_predictions)); |
| 188 EXPECT_EQ(expected_type_predictions, output_type_predictions); |
| 189 } |
| 190 |
140 } // namespace autofill | 191 } // namespace autofill |
OLD | NEW |