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 "base/base_switches.h" | 5 #include "base/base_switches.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 11 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
14 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
15 #include "chrome/test/base/in_process_browser_test.h" | 15 #include "chrome/test/base/in_process_browser_test.h" |
16 #include "chrome/test/base/ui_test_utils.h" | 16 #include "chrome/test/base/ui_test_utils.h" |
17 #include "components/autofill/core/browser/autofill_profile.h" | 17 #include "components/autofill/core/browser/autofill_profile.h" |
18 #include "components/autofill/core/browser/autofill_test_utils.h" | 18 #include "components/autofill/core/browser/autofill_test_utils.h" |
19 #include "components/autofill/core/browser/personal_data_manager.h" | 19 #include "components/autofill/core/browser/personal_data_manager.h" |
20 #include "components/autofill/core/browser/personal_data_manager_observer.h" | 20 #include "components/autofill/core/browser/personal_data_manager_observer.h" |
21 #include "content/public/test/browser_test_utils.h" | 21 #include "content/public/test/browser_test_utils.h" |
22 #include "content/public/test/test_utils.h" | 22 #include "content/public/test/test_utils.h" |
23 #include "net/url_request/test_url_fetcher_factory.h" | 23 #include "net/url_request/test_url_fetcher_factory.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
25 #include "third_party/zlib/google/compression_utils.h" | |
26 | 25 |
27 namespace autofill { | 26 namespace autofill { |
28 namespace { | 27 namespace { |
29 | 28 |
30 // TODO(bondd): PdmChangeWaiter in autofill_uitest_util.cc is a replacement for | 29 // TODO(bondd): PdmChangeWaiter in autofill_uitest_util.cc is a replacement for |
31 // this class. Remove this class and use helper functions in that file instead. | 30 // this class. Remove this class and use helper functions in that file instead. |
32 class WindowedPersonalDataManagerObserver : public PersonalDataManagerObserver { | 31 class WindowedPersonalDataManagerObserver : public PersonalDataManagerObserver { |
33 public: | 32 public: |
34 explicit WindowedPersonalDataManagerObserver(Profile* profile) | 33 explicit WindowedPersonalDataManagerObserver(Profile* profile) |
35 : profile_(profile), | 34 : profile_(profile), |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 private: | 82 private: |
84 // Mocks out network requests. | 83 // Mocks out network requests. |
85 scoped_ptr<net::TestURLFetcherFactory> factory_; | 84 scoped_ptr<net::TestURLFetcherFactory> factory_; |
86 | 85 |
87 const std::string expected_upload_data_; | 86 const std::string expected_upload_data_; |
88 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | 87 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
89 | 88 |
90 DISALLOW_COPY_AND_ASSIGN(WindowedNetworkObserver); | 89 DISALLOW_COPY_AND_ASSIGN(WindowedNetworkObserver); |
91 }; | 90 }; |
92 | 91 |
93 // Compresses |data| and returns the result. | |
94 std::string Compress(const std::string& data) { | |
95 std::string compressed_data; | |
96 EXPECT_TRUE(compression::GzipCompress(data, &compressed_data)); | |
97 return compressed_data; | |
98 } | |
99 | |
100 } // namespace | 92 } // namespace |
101 | 93 |
102 class AutofillServerTest : public InProcessBrowserTest { | 94 class AutofillServerTest : public InProcessBrowserTest { |
103 public: | 95 public: |
104 void SetUpCommandLine(base::CommandLine* command_line) override { | 96 void SetUpCommandLine(base::CommandLine* command_line) override { |
105 // Enable finch experiment for sending field metadata. | 97 // Enable finch experiment for sending field metadata. |
106 command_line->AppendSwitchASCII( | 98 command_line->AppendSwitchASCII( |
107 ::switches::kForceFieldTrials, "AutofillFieldMetadata/Enabled/"); | 99 ::switches::kForceFieldTrials, "AutofillFieldMetadata/Enabled/"); |
108 } | 100 } |
109 }; | 101 }; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 test::FillQueryField(query_form->add_field(), 2750915947U, "two", "text", | 137 test::FillQueryField(query_form->add_field(), 2750915947U, "two", "text", |
146 nullptr); | 138 nullptr); |
147 test::FillQueryField(query_form->add_field(), 3494787134U, "three", "text", | 139 test::FillQueryField(query_form->add_field(), 3494787134U, "three", "text", |
148 nullptr); | 140 nullptr); |
149 test::FillQueryField(query_form->add_field(), 1236501728U, "four", "text", | 141 test::FillQueryField(query_form->add_field(), 1236501728U, "four", "text", |
150 nullptr); | 142 nullptr); |
151 | 143 |
152 std::string expected_query_string; | 144 std::string expected_query_string; |
153 ASSERT_TRUE(query.SerializeToString(&expected_query_string)); | 145 ASSERT_TRUE(query.SerializeToString(&expected_query_string)); |
154 | 146 |
155 WindowedNetworkObserver query_network_observer( | 147 WindowedNetworkObserver query_network_observer(expected_query_string); |
156 Compress(expected_query_string)); | |
157 | 148 |
158 ui_test_utils::NavigateToURL( | 149 ui_test_utils::NavigateToURL( |
159 browser(), GURL(std::string(kDataURIPrefix) + kFormHtml)); | 150 browser(), GURL(std::string(kDataURIPrefix) + kFormHtml)); |
160 query_network_observer.Wait(); | 151 query_network_observer.Wait(); |
161 | 152 |
162 // Submit the form, using a simulated mouse click because form submissions not | 153 // Submit the form, using a simulated mouse click because form submissions not |
163 // triggered by user gestures are ignored. Expect an upload request upon form | 154 // triggered by user gestures are ignored. Expect an upload request upon form |
164 // submission, with form fields matching those from the query request. | 155 // submission, with form fields matching those from the query request. |
165 AutofillUploadContents upload; | 156 AutofillUploadContents upload; |
166 upload.set_submission(true); | 157 upload.set_submission(true); |
167 upload.set_client_version("6.1.1715.1442/en (GGLL)"); | 158 upload.set_client_version("6.1.1715.1442/en (GGLL)"); |
168 upload.set_form_signature(15916856893790176210U); | 159 upload.set_form_signature(15916856893790176210U); |
169 upload.set_autofill_used(false); | 160 upload.set_autofill_used(false); |
170 upload.set_data_present("1f7e0003780000080004"); | 161 upload.set_data_present("1f7e0003780000080004"); |
171 upload.set_action_signature(15724779818122431245U); | 162 upload.set_action_signature(15724779818122431245U); |
172 upload.set_form_name("test_form"); | 163 upload.set_form_name("test_form"); |
173 | 164 |
174 test::FillUploadField(upload.add_field(), 2594484045U, "one", "text", nullptr, | 165 test::FillUploadField(upload.add_field(), 2594484045U, "one", "text", nullptr, |
175 nullptr, 2U); | 166 nullptr, 2U); |
176 test::FillUploadField(upload.add_field(), 2750915947U, "two", "text", nullptr, | 167 test::FillUploadField(upload.add_field(), 2750915947U, "two", "text", nullptr, |
177 "off", 2U); | 168 "off", 2U); |
178 test::FillUploadField(upload.add_field(), 3494787134U, "three", "text", | 169 test::FillUploadField(upload.add_field(), 3494787134U, "three", "text", |
179 nullptr, nullptr, 2U); | 170 nullptr, nullptr, 2U); |
180 test::FillUploadField(upload.add_field(), 1236501728U, "four", "text", | 171 test::FillUploadField(upload.add_field(), 1236501728U, "four", "text", |
181 nullptr, "off", 2U); | 172 nullptr, "off", 2U); |
182 | 173 |
183 std::string expected_upload_string; | 174 std::string expected_upload_string; |
184 ASSERT_TRUE(upload.SerializeToString(&expected_upload_string)); | 175 ASSERT_TRUE(upload.SerializeToString(&expected_upload_string)); |
185 | 176 |
186 WindowedNetworkObserver upload_network_observer( | 177 WindowedNetworkObserver upload_network_observer(expected_upload_string); |
187 Compress(expected_upload_string)); | |
188 content::WebContents* web_contents = | 178 content::WebContents* web_contents = |
189 browser()->tab_strip_model()->GetActiveWebContents(); | 179 browser()->tab_strip_model()->GetActiveWebContents(); |
190 content::SimulateMouseClick( | 180 content::SimulateMouseClick( |
191 web_contents, 0, blink::WebMouseEvent::ButtonLeft); | 181 web_contents, 0, blink::WebMouseEvent::ButtonLeft); |
192 upload_network_observer.Wait(); | 182 upload_network_observer.Wait(); |
193 } | 183 } |
194 | 184 |
195 // Verify that a site with password fields will query even in the presence | 185 // Verify that a site with password fields will query even in the presence |
196 // of user defined autocomplete types. | 186 // of user defined autocomplete types. |
197 IN_PROC_BROWSER_TEST_F(AutofillServerTest, | 187 IN_PROC_BROWSER_TEST_F(AutofillServerTest, |
(...skipping 16 matching lines...) Expand all Loading... |
214 test::FillQueryField(query_form->add_field(), 2594484045U, "one", "text", | 204 test::FillQueryField(query_form->add_field(), 2594484045U, "one", "text", |
215 nullptr); | 205 nullptr); |
216 test::FillQueryField(query_form->add_field(), 2750915947U, "two", "text", | 206 test::FillQueryField(query_form->add_field(), 2750915947U, "two", "text", |
217 nullptr); | 207 nullptr); |
218 test::FillQueryField(query_form->add_field(), 116843943U, "three", "password", | 208 test::FillQueryField(query_form->add_field(), 116843943U, "three", "password", |
219 nullptr); | 209 nullptr); |
220 | 210 |
221 std::string expected_query_string; | 211 std::string expected_query_string; |
222 ASSERT_TRUE(query.SerializeToString(&expected_query_string)); | 212 ASSERT_TRUE(query.SerializeToString(&expected_query_string)); |
223 | 213 |
224 WindowedNetworkObserver query_network_observer( | 214 WindowedNetworkObserver query_network_observer(expected_query_string); |
225 Compress(expected_query_string)); | |
226 ui_test_utils::NavigateToURL( | 215 ui_test_utils::NavigateToURL( |
227 browser(), GURL(std::string(kDataURIPrefix) + kFormHtml)); | 216 browser(), GURL(std::string(kDataURIPrefix) + kFormHtml)); |
228 query_network_observer.Wait(); | 217 query_network_observer.Wait(); |
229 } | 218 } |
230 | 219 |
231 } // namespace autofill | 220 } // namespace autofill |
OLD | NEW |