Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(441)

Side by Side Diff: chrome/browser/password_manager/credential_manager_browsertest.cc

Issue 2947413002: Restrict CM API interface request and message dispatch. (Closed)
Patch Set: With fix. Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/macros.h" 5 #include "base/macros.h"
6 #include "base/stl_util.h" 6 #include "base/stl_util.h"
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/password_manager/password_manager_test_base.h" 8 #include "chrome/browser/password_manager/password_manager_test_base.h"
9 #include "chrome/browser/password_manager/password_store_factory.h" 9 #include "chrome/browser/password_manager/password_store_factory.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 NavigationObserver observer(WebContents()); 238 NavigationObserver observer(WebContents());
239 observer.SetPathToWaitFor("/password/done.html"); 239 observer.SetPathToWaitFor("/password/done.html");
240 observer.Wait(); 240 observer.Wait();
241 241
242 BubbleObserver prompt_observer(WebContents()); 242 BubbleObserver prompt_observer(WebContents());
243 // The autofill password manager shouldn't react to the successful login 243 // The autofill password manager shouldn't react to the successful login
244 // because it was suppressed when the site got the credential back. 244 // because it was suppressed when the site got the credential back.
245 EXPECT_FALSE(prompt_observer.IsShowingSavePrompt()); 245 EXPECT_FALSE(prompt_observer.IsShowingSavePrompt());
246 } 246 }
247 247
248 // Regression test for https://crbug.com/736357.
249 IN_PROC_BROWSER_TEST_F(CredentialManagerBrowserTest, StoreRace) {
250 GURL example_url =
251 https_test_server().GetURL("www.example.com", "/password/other.html");
252 GURL evil_url =
253 https_test_server().GetURL("www.evil.com", "/password/other.html");
254
255 // Got to `www.example.com` and start spamming credentials.store().
256 ui_test_utils::NavigateToURL(browser(), example_url);
257 ASSERT_TRUE(content::ExecuteScript(
258 RenderViewHost(),
259 "window.setTimeout(() => {"
260 " for(;;) {"
261 " var c = new PasswordCredential({ id: 'user', password: 'hunter2' });"
262 " navigator.credentials.store(c);"
263 " }"
264 "}, 0);"));
265
266 // Navigate cross-domain to `www.evil.com`.
267 ui_test_utils::NavigateToURL(browser(), evil_url);
268 WaitForPasswordStore();
vasilii 2017/06/23 18:58:28 It's excessive.
engedy 2017/06/28 16:26:58 Reworked tests, N/A anymore.
269
270 // The Mojo pipe where the flood is coming from should be cut when the
271 // cross-origin navigation is committed, so that the last credetials.store()
272 // request process is still associated with `example.com`.
273 BubbleObserver prompt_observer(WebContents());
274 prompt_observer.WaitForSavePrompt();
275 ASSERT_TRUE(prompt_observer.IsShowingSavePrompt());
276 prompt_observer.AcceptSavePrompt();
277
278 WaitForPasswordStore();
279 password_manager::TestPasswordStore::PasswordMap stored =
280 static_cast<password_manager::TestPasswordStore*>(
281 PasswordStoreFactory::GetForProfile(
282 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS)
283 .get())
284 ->stored_passwords();
285 ASSERT_EQ(1u, stored.size());
286 autofill::PasswordForm signin_form = stored.begin()->second[0];
287 EXPECT_EQ(base::ASCIIToUTF16("user"), signin_form.username_value);
288 EXPECT_EQ(base::ASCIIToUTF16("hunter2"), signin_form.password_value);
289 EXPECT_EQ(example_url.host(), signin_form.origin.host());
vasilii 2017/06/23 18:58:28 Do I understand right that this condition is flaky
engedy 2017/06/28 16:26:58 Reworked tests -- they are not flaky anymore in an
290 }
291
248 IN_PROC_BROWSER_TEST_F(CredentialManagerBrowserTest, SaveViaAPIAndAutofill) { 292 IN_PROC_BROWSER_TEST_F(CredentialManagerBrowserTest, SaveViaAPIAndAutofill) {
249 NavigateToFile("/password/password_form.html"); 293 NavigateToFile("/password/password_form.html");
250 294
251 ASSERT_TRUE(content::ExecuteScript( 295 ASSERT_TRUE(content::ExecuteScript(
252 RenderViewHost(), 296 RenderViewHost(),
253 "document.getElementById('input_submit_button').addEventListener('click'," 297 "document.getElementById('input_submit_button').addEventListener('click',"
254 "function(event) {" 298 "function(event) {"
255 "var c = new PasswordCredential({ id: 'user', password: 'API' });" 299 "var c = new PasswordCredential({ id: 'user', password: 'API' });"
256 "navigator.credentials.store(c);" 300 "navigator.credentials.store(c);"
257 "});")); 301 "});"));
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 393
350 // Reload the page and make sure it's autofilled. 394 // Reload the page and make sure it's autofilled.
351 NavigateToFile("/password/password_form.html"); 395 NavigateToFile("/password/password_form.html");
352 WaitForElementValue("username_field", "user"); 396 WaitForElementValue("username_field", "user");
353 content::SimulateMouseClickAt( 397 content::SimulateMouseClickAt(
354 WebContents(), 0, blink::WebMouseEvent::Button::kLeft, gfx::Point(1, 1)); 398 WebContents(), 0, blink::WebMouseEvent::Button::kLeft, gfx::Point(1, 1));
355 WaitForElementValue("password_field", "12345"); 399 WaitForElementValue("password_field", "12345");
356 } 400 }
357 401
358 } // namespace 402 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698