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/path_service.h" |
11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "chrome/browser/chrome_notification_types.h" | 15 #include "chrome/browser/chrome_notification_types.h" |
16 #include "chrome/browser/password_manager/chrome_password_manager_client.h" | 16 #include "chrome/browser/password_manager/chrome_password_manager_client.h" |
17 #include "chrome/browser/password_manager/password_manager_test_base.h" | 17 #include "chrome/browser/password_manager/password_manager_test_base.h" |
18 #include "chrome/browser/password_manager/password_store_factory.h" | 18 #include "chrome/browser/password_manager/password_store_factory.h" |
19 #include "chrome/browser/password_manager/test_password_store_service.h" | 19 #include "chrome/browser/password_manager/test_password_store_service.h" |
20 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
21 #include "chrome/browser/ui/browser.h" | 21 #include "chrome/browser/ui/browser.h" |
22 #include "chrome/browser/ui/login/login_prompt.h" | 22 #include "chrome/browser/ui/login/login_prompt.h" |
23 #include "chrome/browser/ui/login/login_prompt_test_utils.h" | 23 #include "chrome/browser/ui/login/login_prompt_test_utils.h" |
24 #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" | 25 #include "chrome/common/chrome_paths.h" |
26 #include "chrome/common/chrome_switches.h" | 26 #include "chrome/common/chrome_switches.h" |
27 #include "chrome/common/chrome_version_info.h" | 27 #include "chrome/common/chrome_version_info.h" |
28 #include "chrome/test/base/test_switches.h" | 28 #include "chrome/test/base/test_switches.h" |
29 #include "chrome/test/base/ui_test_utils.h" | 29 #include "chrome/test/base/ui_test_utils.h" |
30 #include "components/autofill/content/common/autofill_messages.h" | |
30 #include "components/autofill/core/browser/autofill_test_utils.h" | 31 #include "components/autofill/core/browser/autofill_test_utils.h" |
31 #include "components/autofill/core/browser/test_autofill_client.h" | 32 #include "components/autofill/core/browser/test_autofill_client.h" |
33 #include "components/autofill/core/common/password_form.h" | |
32 #include "components/password_manager/content/browser/content_password_manager_d river.h" | 34 #include "components/password_manager/content/browser/content_password_manager_d river.h" |
33 #include "components/password_manager/content/browser/content_password_manager_d river_factory.h" | 35 #include "components/password_manager/content/browser/content_password_manager_d river_factory.h" |
34 #include "components/password_manager/core/browser/test_password_store.h" | 36 #include "components/password_manager/core/browser/test_password_store.h" |
35 #include "components/password_manager/core/common/password_manager_switches.h" | 37 #include "components/password_manager/core/common/password_manager_switches.h" |
36 #include "content/public/browser/navigation_controller.h" | 38 #include "content/public/browser/navigation_controller.h" |
37 #include "content/public/browser/notification_service.h" | 39 #include "content/public/browser/notification_service.h" |
38 #include "content/public/browser/render_frame_host.h" | 40 #include "content/public/browser/render_frame_host.h" |
41 #include "content/public/browser/render_process_host.h" | |
39 #include "content/public/browser/render_view_host.h" | 42 #include "content/public/browser/render_view_host.h" |
40 #include "content/public/browser/web_contents.h" | 43 #include "content/public/browser/web_contents.h" |
41 #include "content/public/browser/web_contents_observer.h" | 44 #include "content/public/browser/web_contents_observer.h" |
42 #include "content/public/common/content_switches.h" | 45 #include "content/public/common/content_switches.h" |
43 #include "content/public/test/browser_test_utils.h" | 46 #include "content/public/test/browser_test_utils.h" |
44 #include "content/public/test/test_utils.h" | 47 #include "content/public/test/test_utils.h" |
48 #include "ipc/ipc_security_test_util.h" | |
45 #include "net/base/filename_util.h" | 49 #include "net/base/filename_util.h" |
46 #include "net/dns/mock_host_resolver.h" | 50 #include "net/dns/mock_host_resolver.h" |
47 #include "net/test/embedded_test_server/embedded_test_server.h" | 51 #include "net/test/embedded_test_server/embedded_test_server.h" |
48 #include "net/test/embedded_test_server/http_request.h" | 52 #include "net/test/embedded_test_server/http_request.h" |
49 #include "net/test/embedded_test_server/http_response.h" | 53 #include "net/test/embedded_test_server/http_response.h" |
50 #include "net/test/spawned_test_server/spawned_test_server.h" | 54 #include "net/test/spawned_test_server/spawned_test_server.h" |
51 #include "net/url_request/test_url_fetcher_factory.h" | 55 #include "net/url_request/test_url_fetcher_factory.h" |
52 #include "testing/gmock/include/gmock/gmock.h" | 56 #include "testing/gmock/include/gmock/gmock.h" |
53 #include "third_party/WebKit/public/web/WebInputEvent.h" | 57 #include "third_party/WebKit/public/web/WebInputEvent.h" |
54 #include "ui/events/keycodes/keyboard_codes.h" | 58 #include "ui/events/keycodes/keyboard_codes.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
109 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | 113 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
110 | 114 |
111 DISALLOW_COPY_AND_ASSIGN(ObservingAutofillClient); | 115 DISALLOW_COPY_AND_ASSIGN(ObservingAutofillClient); |
112 }; | 116 }; |
113 | 117 |
114 } // namespace | 118 } // namespace |
115 | 119 |
116 namespace password_manager { | 120 namespace password_manager { |
117 | 121 |
118 // Actual tests --------------------------------------------------------------- | 122 // Actual tests --------------------------------------------------------------- |
119 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, PromptForNormalSubmit) { | 123 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, PromptForNormalSubmit) { |
ncarter (slow)
2015/07/16 18:04:10
Would it be better to just do:
using PasswordMana
lfg
2015/07/16 18:33:14
The tests are already renamed upstream. I should'v
ncarter (slow)
2015/07/16 18:55:08
Ah, sorry!
| |
120 NavigateToFile("/password/password_form.html"); | 124 NavigateToFile("/password/password_form.html"); |
121 | 125 |
122 // Fill a form and submit through a <input type="submit"> button. Nothing | 126 // Fill a form and submit through a <input type="submit"> button. Nothing |
123 // special. | 127 // special. |
124 NavigationObserver observer(WebContents()); | 128 NavigationObserver observer(WebContents()); |
125 scoped_ptr<PromptObserver> prompt_observer( | 129 scoped_ptr<PromptObserver> prompt_observer( |
126 PromptObserver::Create(WebContents())); | 130 PromptObserver::Create(WebContents())); |
127 std::string fill_and_submit = | 131 std::string fill_and_submit = |
128 "document.getElementById('username_field').value = 'temp';" | 132 "document.getElementById('username_field').value = 'temp';" |
129 "document.getElementById('password_field').value = 'random';" | 133 "document.getElementById('password_field').value = 'random';" |
(...skipping 1823 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1953 WebContents(), 0, blink::WebMouseEvent::ButtonLeft, gfx::Point(left + 1, | 1957 WebContents(), 0, blink::WebMouseEvent::ButtonLeft, gfx::Point(left + 1, |
1954 top + 1)); | 1958 top + 1)); |
1955 // Verify password has been autofilled | 1959 // Verify password has been autofilled |
1956 WaitForElementValue("iframe", "password_field", "pa55w0rd"); | 1960 WaitForElementValue("iframe", "password_field", "pa55w0rd"); |
1957 | 1961 |
1958 // Verify username has been autofilled | 1962 // Verify username has been autofilled |
1959 CheckElementValue("iframe", "username_field", "temp"); | 1963 CheckElementValue("iframe", "username_field", "temp"); |
1960 | 1964 |
1961 } | 1965 } |
1962 | 1966 |
1967 // The password manager driver will kill processes when they try to access | |
1968 // passwords of sites other than the site the process is dedicated to, under | |
1969 // site isolation. | |
1970 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, | |
1971 CrossSitePasswordEnforcement) { | |
1972 // The code under test is only active under site isolation. | |
1973 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | |
1974 ::switches::kSitePerProcess)) { | |
1975 return; | |
1976 } | |
1977 | |
1978 // Setup the mock host resolver | |
1979 host_resolver()->AddRule("*", "127.0.0.1"); | |
1980 | |
1981 // Navigate the main frame. | |
1982 GURL main_frame_url = embedded_test_server()->GetURL( | |
1983 "/password/password_form_in_crosssite_iframe.html"); | |
1984 NavigationObserver observer(WebContents()); | |
1985 ui_test_utils::NavigateToURL(browser(), main_frame_url); | |
1986 observer.Wait(); | |
1987 | |
1988 // Create an iframe and navigate cross-site. | |
1989 NavigationObserver iframe_observer(WebContents()); | |
1990 iframe_observer.SetPathToWaitFor("/password/crossite_iframe_content.html"); | |
1991 GURL iframe_url = embedded_test_server()->GetURL( | |
1992 "foo.com", "/password/crossite_iframe_content.html"); | |
1993 std::string create_iframe = | |
1994 base::StringPrintf("create_iframe('%s');", iframe_url.spec().c_str()); | |
1995 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), create_iframe)); | |
1996 iframe_observer.Wait(); | |
1997 | |
1998 // The iframe should get its own process. | |
1999 content::RenderFrameHost* main_frame = WebContents()->GetMainFrame(); | |
2000 content::RenderFrameHost* iframe = iframe_observer.render_frame_host(); | |
2001 content::SiteInstance* main_site_instance = main_frame->GetSiteInstance(); | |
2002 content::SiteInstance* iframe_site_instance = iframe->GetSiteInstance(); | |
2003 EXPECT_NE(main_site_instance, iframe_site_instance); | |
2004 EXPECT_NE(main_frame->GetProcess(), iframe->GetProcess()); | |
2005 | |
2006 // Try to get cross-site passwords from the subframe's process and wait for it | |
2007 // to be killed. | |
2008 std::vector<autofill::PasswordForm> password_forms; | |
2009 password_forms.push_back(autofill::PasswordForm()); | |
2010 password_forms.back().origin = main_frame_url; | |
2011 AutofillHostMsg_PasswordFormsParsed illegal_forms_parsed( | |
2012 iframe->GetRoutingID(), password_forms); | |
2013 | |
2014 content::RenderProcessHostWatcher iframe_killed( | |
2015 iframe->GetProcess(), | |
2016 content::RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); | |
2017 | |
2018 IPC::IpcSecurityTestUtil::PwnMessageReceived( | |
2019 iframe->GetProcess()->GetChannel(), illegal_forms_parsed); | |
2020 | |
2021 iframe_killed.Wait(); | |
2022 } | |
2023 | |
1963 } // namespace password_manager | 2024 } // namespace password_manager |
2025 | |
OLD | NEW |