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 <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" | 8 #include "base/metrics/histogram_samples.h" |
| 9 #include "base/metrics/statistics_recorder.h" | 9 #include "base/metrics/statistics_recorder.h" |
| 10 #include "base/path_service.h" | |
| 10 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 11 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 12 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 14 #include "chrome/browser/chrome_notification_types.h" | 15 #include "chrome/browser/chrome_notification_types.h" |
| 15 #include "chrome/browser/infobars/infobar_service.h" | 16 #include "chrome/browser/infobars/infobar_service.h" |
| 16 #include "chrome/browser/password_manager/chrome_password_manager_client.h" | 17 #include "chrome/browser/password_manager/chrome_password_manager_client.h" |
| 17 #include "chrome/browser/password_manager/password_store_factory.h" | 18 #include "chrome/browser/password_manager/password_store_factory.h" |
| 18 #include "chrome/browser/password_manager/test_password_store_service.h" | 19 #include "chrome/browser/password_manager/test_password_store_service.h" |
| 19 #include "chrome/browser/ui/browser.h" | 20 #include "chrome/browser/ui/browser.h" |
| 20 #include "chrome/browser/ui/login/login_prompt.h" | 21 #include "chrome/browser/ui/login/login_prompt.h" |
| 21 #include "chrome/browser/ui/login/login_prompt_test_utils.h" | 22 #include "chrome/browser/ui/login/login_prompt_test_utils.h" |
| 22 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" | 23 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" |
| 23 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 24 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 25 #include "chrome/common/chrome_paths.h" | |
| 24 #include "chrome/common/chrome_switches.h" | 26 #include "chrome/common/chrome_switches.h" |
| 25 #include "chrome/common/chrome_version_info.h" | 27 #include "chrome/common/chrome_version_info.h" |
| 26 #include "chrome/test/base/in_process_browser_test.h" | 28 #include "chrome/test/base/in_process_browser_test.h" |
| 27 #include "chrome/test/base/test_switches.h" | 29 #include "chrome/test/base/test_switches.h" |
| 28 #include "chrome/test/base/ui_test_utils.h" | 30 #include "chrome/test/base/ui_test_utils.h" |
| 29 #include "components/autofill/core/browser/autofill_test_utils.h" | 31 #include "components/autofill/core/browser/autofill_test_utils.h" |
| 30 #include "components/infobars/core/confirm_infobar_delegate.h" | 32 #include "components/infobars/core/confirm_infobar_delegate.h" |
| 31 #include "components/infobars/core/infobar.h" | 33 #include "components/infobars/core/infobar.h" |
| 32 #include "components/infobars/core/infobar_manager.h" | 34 #include "components/infobars/core/infobar_manager.h" |
| 33 #include "components/password_manager/core/browser/test_password_store.h" | 35 #include "components/password_manager/core/browser/test_password_store.h" |
| 34 #include "components/password_manager/core/common/password_manager_switches.h" | 36 #include "components/password_manager/core/common/password_manager_switches.h" |
| 35 #include "content/public/browser/navigation_controller.h" | 37 #include "content/public/browser/navigation_controller.h" |
| 36 #include "content/public/browser/notification_service.h" | 38 #include "content/public/browser/notification_service.h" |
| 37 #include "content/public/browser/render_frame_host.h" | 39 #include "content/public/browser/render_frame_host.h" |
| 38 #include "content/public/browser/render_view_host.h" | 40 #include "content/public/browser/render_view_host.h" |
| 39 #include "content/public/browser/web_contents.h" | 41 #include "content/public/browser/web_contents.h" |
| 40 #include "content/public/browser/web_contents_observer.h" | 42 #include "content/public/browser/web_contents_observer.h" |
| 41 #include "content/public/common/content_switches.h" | 43 #include "content/public/common/content_switches.h" |
| 42 #include "content/public/test/browser_test_utils.h" | 44 #include "content/public/test/browser_test_utils.h" |
| 43 #include "content/public/test/test_utils.h" | 45 #include "content/public/test/test_utils.h" |
| 46 #include "net/base/filename_util.h" | |
| 44 #include "net/test/embedded_test_server/embedded_test_server.h" | 47 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 45 #include "net/test/embedded_test_server/http_request.h" | 48 #include "net/test/embedded_test_server/http_request.h" |
| 46 #include "net/test/embedded_test_server/http_response.h" | 49 #include "net/test/embedded_test_server/http_response.h" |
| 47 #include "net/test/spawned_test_server/spawned_test_server.h" | 50 #include "net/test/spawned_test_server/spawned_test_server.h" |
| 48 #include "net/url_request/test_url_fetcher_factory.h" | 51 #include "net/url_request/test_url_fetcher_factory.h" |
| 49 #include "testing/gmock/include/gmock/gmock.h" | 52 #include "testing/gmock/include/gmock/gmock.h" |
| 50 #include "third_party/WebKit/public/web/WebInputEvent.h" | 53 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 51 #include "ui/events/keycodes/keyboard_codes.h" | 54 #include "ui/events/keycodes/keyboard_codes.h" |
| 52 #include "ui/gfx/geometry/point.h" | 55 #include "ui/gfx/geometry/point.h" |
| 53 | 56 |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 264 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 267 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 265 ASSERT_FALSE(CommandLine::ForCurrentProcess()->HasSwitch( | 268 ASSERT_FALSE(CommandLine::ForCurrentProcess()->HasSwitch( |
| 266 password_manager::switches::kEnableAutomaticPasswordSaving)); | 269 password_manager::switches::kEnableAutomaticPasswordSaving)); |
| 267 } | 270 } |
| 268 | 271 |
| 269 virtual void TearDownOnMainThread() OVERRIDE { | 272 virtual void TearDownOnMainThread() OVERRIDE { |
| 270 ASSERT_TRUE(embedded_test_server()->ShutdownAndWaitUntilComplete()); | 273 ASSERT_TRUE(embedded_test_server()->ShutdownAndWaitUntilComplete()); |
| 271 } | 274 } |
| 272 | 275 |
| 273 protected: | 276 protected: |
| 277 static GURL GetURL(const char* filename) { | |
|
vabr (Chromium)
2014/09/25 08:48:02
nit: indenting
(I strongly suggest running git cl
vabr (Chromium)
2014/09/25 08:48:02
This function has nothing to with the test class.
Sunil Ratnu
2014/09/25 10:14:23
Done.
Sunil Ratnu
2014/09/25 10:14:24
Done.
| |
| 278 base::FilePath path; | |
| 279 PathService::Get(chrome::DIR_TEST_DATA, &path); | |
| 280 path = path.AppendASCII("password").AppendASCII(filename); | |
| 281 CHECK(base::PathExists(path)); | |
| 282 return net::FilePathToFileURL(path); | |
| 283 } | |
| 284 | |
| 274 content::WebContents* WebContents() { | 285 content::WebContents* WebContents() { |
| 275 return browser()->tab_strip_model()->GetActiveWebContents(); | 286 return browser()->tab_strip_model()->GetActiveWebContents(); |
| 276 } | 287 } |
| 277 | 288 |
| 278 content::RenderViewHost* RenderViewHost() { | 289 content::RenderViewHost* RenderViewHost() { |
| 279 return WebContents()->GetRenderViewHost(); | 290 return WebContents()->GetRenderViewHost(); |
| 280 } | 291 } |
| 281 | 292 |
| 282 // Wrapper around ui_test_utils::NavigateToURL that waits until | 293 // Wrapper around ui_test_utils::NavigateToURL that waits until |
| 283 // DidFinishLoad() fires. Normally this function returns after | 294 // DidFinishLoad() fires. Normally this function returns after |
| (...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 818 "var username = form.children[0];" | 829 "var username = form.children[0];" |
| 819 "username.value = 'temp';" | 830 "username.value = 'temp';" |
| 820 "var password = form.children[1];" | 831 "var password = form.children[1];" |
| 821 "password.value = 'random';" | 832 "password.value = 'random';" |
| 822 "form.children[2].click()"; // form.children[2] is the submit button. | 833 "form.children[2].click()"; // form.children[2] is the submit button. |
| 823 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); | 834 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
| 824 observer.Wait(); | 835 observer.Wait(); |
| 825 EXPECT_FALSE(prompt_observer->IsShowingPrompt()); | 836 EXPECT_FALSE(prompt_observer->IsShowingPrompt()); |
| 826 } | 837 } |
| 827 | 838 |
| 839 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, | |
| 840 NoPromptForNonWebbyURLs) { | |
| 841 // Check that no prompt is shown for non webby URLs such as file://. | |
|
vabr (Chromium)
2014/09/25 08:48:02
Please simplify the comment to:
// Check that no p
Sunil Ratnu
2014/09/25 10:14:23
Done.
| |
| 842 NavigationObserver observer(WebContents()); | |
|
vabr (Chromium)
2014/09/25 08:48:02
Move the definition of the observer below, just be
Sunil Ratnu
2014/09/25 10:14:23
Done.
| |
| 843 GURL url = GetURL("password_form.html"); | |
| 844 ui_test_utils::NavigateToURL(browser(), url); | |
| 845 observer.Wait(); | |
|
vabr (Chromium)
2014/09/25 08:48:02
Don't Wait() here, NavigateToURL waits for that al
Sunil Ratnu
2014/09/25 10:14:24
Done.
| |
| 846 | |
| 847 scoped_ptr<PromptObserver> prompt_observer( | |
| 848 PromptObserver::Create(WebContents())); | |
| 849 std::string fill_and_submit = | |
| 850 "document.getElementById('username_field').value = 'temp';" | |
| 851 "document.getElementById('password_field').value = 'random';" | |
| 852 "document.getElementById('input_submit_button').click();"; | |
| 853 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); | |
| 854 observer.Wait(); | |
| 855 EXPECT_FALSE(prompt_observer->IsShowingPrompt()); | |
| 856 } | |
| 857 | |
| 828 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, DeleteFrameBeforeSubmit) { | 858 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, DeleteFrameBeforeSubmit) { |
| 829 NavigateToFile("/password/multi_frames.html"); | 859 NavigateToFile("/password/multi_frames.html"); |
| 830 | 860 |
| 831 NavigationObserver observer(WebContents()); | 861 NavigationObserver observer(WebContents()); |
| 832 // Make sure we save some password info from an iframe and then destroy it. | 862 // Make sure we save some password info from an iframe and then destroy it. |
| 833 std::string save_and_remove = | 863 std::string save_and_remove = |
| 834 "var first_frame = document.getElementById('first_frame');" | 864 "var first_frame = document.getElementById('first_frame');" |
| 835 "var frame_doc = first_frame.contentDocument;" | 865 "var frame_doc = first_frame.contentDocument;" |
| 836 "frame_doc.getElementById('username_field').value = 'temp';" | 866 "frame_doc.getElementById('username_field').value = 'temp';" |
| 837 "frame_doc.getElementById('password_field').value = 'random';" | 867 "frame_doc.getElementById('password_field').value = 'random';" |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1172 NavigationObserver observer(WebContents()); | 1202 NavigationObserver observer(WebContents()); |
| 1173 scoped_ptr<PromptObserver> prompt_observer( | 1203 scoped_ptr<PromptObserver> prompt_observer( |
| 1174 PromptObserver::Create(WebContents())); | 1204 PromptObserver::Create(WebContents())); |
| 1175 ui_test_utils::NavigateToURL(browser(), https_url); | 1205 ui_test_utils::NavigateToURL(browser(), https_url); |
| 1176 | 1206 |
| 1177 observer.SetPathToWaitFor("/password/done_and_separate_login_form.html"); | 1207 observer.SetPathToWaitFor("/password/done_and_separate_login_form.html"); |
| 1178 observer.Wait(); | 1208 observer.Wait(); |
| 1179 | 1209 |
| 1180 EXPECT_FALSE(prompt_observer->IsShowingPrompt()); | 1210 EXPECT_FALSE(prompt_observer->IsShowingPrompt()); |
| 1181 } | 1211 } |
| OLD | NEW |