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 = new FormStructure(form, std::string()); | |
Ilya Sherman
2013/07/02 18:43:01
nit: If you need to heap-allocate this, please pro
blundell
2013/07/02 20:15:33
Oops, I was totally going to clean this up before
| |
169 std::vector<FormStructure*> forms(1, form_structure); | |
170 std::vector<FormDataPredictions> expected_type_predictions; | |
171 FormStructure::GetFieldTypePredictions(forms, &expected_type_predictions); | |
172 driver_->SendAutofillTypePredictionsToRenderer(forms); | |
173 EXPECT_FALSE(GetFieldTypePredictionsAvailable(NULL)); | |
174 } | |
175 | |
176 TEST_F(AutofillDriverImplTest, TypePredictionsSentToRendererWhenEnabled) { | |
177 CommandLine::ForCurrentProcess()->AppendSwitch( | |
178 switches::kShowAutofillTypePredictions); | |
179 | |
180 FormData form; | |
181 test::CreateTestAddressFormData(&form); | |
182 FormStructure* form_structure = new FormStructure(form, std::string()); | |
183 std::vector<FormStructure*> forms(1, form_structure); | |
184 std::vector<FormDataPredictions> expected_type_predictions; | |
185 FormStructure::GetFieldTypePredictions(forms, &expected_type_predictions); | |
186 driver_->SendAutofillTypePredictionsToRenderer(forms); | |
187 | |
188 std::vector<FormDataPredictions> output_type_predictions; | |
189 EXPECT_TRUE(GetFieldTypePredictionsAvailable(&output_type_predictions)); | |
190 EXPECT_EQ(expected_type_predictions, output_type_predictions); | |
191 } | |
192 | |
140 } // namespace autofill | 193 } // namespace autofill |
OLD | NEW |