| 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/metrics/histogram_samples.h" |
| 9 #include "base/metrics/statistics_recorder.h" |
| 8 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
| 9 #include "chrome/browser/infobars/confirm_infobar_delegate.h" | 11 #include "chrome/browser/infobars/confirm_infobar_delegate.h" |
| 10 #include "chrome/browser/infobars/infobar_service.h" | 12 #include "chrome/browser/infobars/infobar_service.h" |
| 11 #include "chrome/browser/password_manager/password_store_factory.h" | 13 #include "chrome/browser/password_manager/password_store_factory.h" |
| 12 #include "chrome/browser/password_manager/test_password_store.h" | 14 #include "chrome/browser/password_manager/test_password_store.h" |
| 13 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 15 #include "chrome/test/base/in_process_browser_test.h" | 17 #include "chrome/test/base/in_process_browser_test.h" |
| 16 #include "chrome/test/base/test_switches.h" | 18 #include "chrome/test/base/test_switches.h" |
| 17 #include "chrome/test/base/ui_test_utils.h" | 19 #include "chrome/test/base/ui_test_utils.h" |
| 20 #include "components/autofill/core/browser/autofill_common_test.h" |
| 18 #include "content/public/browser/notification_observer.h" | 21 #include "content/public/browser/notification_observer.h" |
| 19 #include "content/public/browser/notification_registrar.h" | 22 #include "content/public/browser/notification_registrar.h" |
| 20 #include "content/public/browser/notification_service.h" | 23 #include "content/public/browser/notification_service.h" |
| 21 #include "content/public/browser/render_view_host.h" | 24 #include "content/public/browser/render_view_host.h" |
| 22 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
| 23 #include "content/public/browser/web_contents_observer.h" | 26 #include "content/public/browser/web_contents_observer.h" |
| 24 #include "content/public/test/browser_test_utils.h" | 27 #include "content/public/test/browser_test_utils.h" |
| 25 #include "content/public/test/test_utils.h" | 28 #include "content/public/test/test_utils.h" |
| 26 #include "net/test/embedded_test_server/embedded_test_server.h" | 29 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 30 #include "net/url_request/test_url_fetcher_factory.h" |
| 27 #include "testing/gmock/include/gmock/gmock.h" | 31 #include "testing/gmock/include/gmock/gmock.h" |
| 28 #include "ui/events/keycodes/keyboard_codes.h" | 32 #include "ui/events/keycodes/keyboard_codes.h" |
| 29 | 33 |
| 30 | 34 |
| 31 // NavigationObserver --------------------------------------------------------- | 35 // NavigationObserver --------------------------------------------------------- |
| 32 | 36 |
| 33 namespace { | 37 namespace { |
| 34 | 38 |
| 35 // Observer that waits for navigation to complete and for the password infobar | 39 // Observer that waits for navigation to complete and for the password infobar |
| 36 // to be shown. | 40 // to be shown. |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 content::RenderViewHost* RenderViewHost() { | 127 content::RenderViewHost* RenderViewHost() { |
| 124 return WebContents()->GetRenderViewHost(); | 128 return WebContents()->GetRenderViewHost(); |
| 125 } | 129 } |
| 126 | 130 |
| 127 // Wrapper around ui_test_utils::NavigateToURL that waits until | 131 // Wrapper around ui_test_utils::NavigateToURL that waits until |
| 128 // DidFinishLoad() fires. Normally this function returns after | 132 // DidFinishLoad() fires. Normally this function returns after |
| 129 // DidStopLoading(), which caused flakiness as the NavigationObserver | 133 // DidStopLoading(), which caused flakiness as the NavigationObserver |
| 130 // would sometimes see the DidFinishLoad event from a previous navigation and | 134 // would sometimes see the DidFinishLoad event from a previous navigation and |
| 131 // return immediately. | 135 // return immediately. |
| 132 void NavigateToFile(const std::string& path) { | 136 void NavigateToFile(const std::string& path) { |
| 133 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 137 if (!embedded_test_server()->Started()) |
| 138 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 134 | 139 |
| 135 NavigationObserver observer(WebContents()); | 140 NavigationObserver observer(WebContents()); |
| 136 GURL url = embedded_test_server()->GetURL(path); | 141 GURL url = embedded_test_server()->GetURL(path); |
| 137 ui_test_utils::NavigateToURL(browser(), url); | 142 ui_test_utils::NavigateToURL(browser(), url); |
| 138 observer.Wait(); | 143 observer.Wait(); |
| 139 } | 144 } |
| 140 | 145 |
| 141 private: | 146 private: |
| 142 DISALLOW_COPY_AND_ASSIGN(PasswordManagerBrowserTest); | 147 DISALLOW_COPY_AND_ASSIGN(PasswordManagerBrowserTest); |
| 143 }; | 148 }; |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 // cases where the element that users click on isn't a submit button. | 290 // cases where the element that users click on isn't a submit button. |
| 286 NavigationObserver observer(WebContents()); | 291 NavigationObserver observer(WebContents()); |
| 287 std::string fill_and_navigate = | 292 std::string fill_and_navigate = |
| 288 "document.getElementById('username_field').value = 'temp';" | 293 "document.getElementById('username_field').value = 'temp';" |
| 289 "document.getElementById('password_field').value = 'random';" | 294 "document.getElementById('password_field').value = 'random';" |
| 290 "send_xhr()"; | 295 "send_xhr()"; |
| 291 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_navigate)); | 296 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_navigate)); |
| 292 observer.Wait(); | 297 observer.Wait(); |
| 293 EXPECT_FALSE(observer.infobar_shown()); | 298 EXPECT_FALSE(observer.infobar_shown()); |
| 294 } | 299 } |
| 300 |
| 301 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| 302 VerifyPasswordGenerationUpload) { |
| 303 // Prevent Autofill requests from actually going over the wire. |
| 304 net::TestURLFetcherFactory factory; |
| 305 // Disable Autofill requesting access to AddressBook data. This causes |
| 306 // the test to hang on Mac. |
| 307 autofill::test::DisableSystemServices(browser()->profile()); |
| 308 |
| 309 // Visit a signup form. |
| 310 NavigateToFile("/password/signup_form.html"); |
| 311 |
| 312 // Enter a password and save it. |
| 313 NavigationObserver first_observer(WebContents()); |
| 314 std::string fill_and_submit = |
| 315 "document.getElementById('other_info').value = 'stuff';" |
| 316 "document.getElementById('username_field').value = 'my_username';" |
| 317 "document.getElementById('password_field').value = 'password';" |
| 318 "document.getElementById('input_submit_button').click()"; |
| 319 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
| 320 |
| 321 first_observer.Wait(); |
| 322 ASSERT_TRUE(first_observer.infobar_shown()); |
| 323 |
| 324 // Now navigate to a login form that has similar HTML markup. |
| 325 NavigateToFile("/password/password_form.html"); |
| 326 |
| 327 // The form should be filled with the previously submitted username. |
| 328 std::string get_username = |
| 329 "window.domAutomationController.send(" |
| 330 "document.getElementById('username_field').value);"; |
| 331 std::string actual_username; |
| 332 ASSERT_TRUE(content::ExecuteScriptAndExtractString(RenderViewHost(), |
| 333 get_username, |
| 334 &actual_username)); |
| 335 ASSERT_EQ("my_username", actual_username); |
| 336 |
| 337 // Submit the form and verify that there is no infobar (as the password |
| 338 // has already been saved). |
| 339 NavigationObserver second_observer(WebContents()); |
| 340 std::string submit_form = |
| 341 "document.getElementById('input_submit_button').click()"; |
| 342 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), submit_form)); |
| 343 second_observer.Wait(); |
| 344 EXPECT_FALSE(second_observer.infobar_shown()); |
| 345 |
| 346 // Verify that we sent a ping to Autofill saying that the original form |
| 347 // was likely an account creation form since it has more than 2 text input |
| 348 // fields and was used for the first time on a different form. |
| 349 base::HistogramBase* upload_histogram = |
| 350 base::StatisticsRecorder::FindHistogram( |
| 351 "PasswordGeneration.UploadStarted"); |
| 352 scoped_ptr<base::HistogramSamples> snapshot = |
| 353 upload_histogram->SnapshotSamples(); |
| 354 EXPECT_EQ(0, snapshot->GetCount(0 /* failure */)); |
| 355 EXPECT_EQ(1, snapshot->GetCount(1 /* success */)); |
| 356 } |
| OLD | NEW |