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

Side by Side Diff: chrome/browser/ui/login/login_handler_browsertest.cc

Issue 2244643002: Split LoginPromptBrowserTest.TestCancelAuth (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <algorithm> 5 #include <algorithm>
6 #include <list> 6 #include <list>
7 #include <map> 7 #include <map>
8 8
9 #include "base/metrics/field_trial.h" 9 #include "base/metrics/field_trial.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 310
311 handler1->SetAuth(base::UTF8ToUTF16(username_basic_), 311 handler1->SetAuth(base::UTF8ToUTF16(username_basic_),
312 base::UTF8ToUTF16(password_)); 312 base::UTF8ToUTF16(password_));
313 handler2->SetAuth(base::UTF8ToUTF16(username_digest_), 313 handler2->SetAuth(base::UTF8ToUTF16(username_digest_),
314 base::UTF8ToUTF16(password_)); 314 base::UTF8ToUTF16(password_));
315 315
316 EXPECT_EQ(expected_title1, title_watcher1.WaitAndGetTitle()); 316 EXPECT_EQ(expected_title1, title_watcher1.WaitAndGetTitle());
317 EXPECT_EQ(expected_title2, title_watcher2.WaitAndGetTitle()); 317 EXPECT_EQ(expected_title2, title_watcher2.WaitAndGetTitle());
318 } 318 }
319 319
320 // Test login prompt cancellation. 320 // Test manual login prompt cancellation.
321 // Flaky on Mac crbug.com/636875 321 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, TestCancelAuth_Manual) {
322 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, DISABLED_TestCancelAuth) {
323 ASSERT_TRUE(embedded_test_server()->Start()); 322 ASSERT_TRUE(embedded_test_server()->Start());
324 GURL auth_page = embedded_test_server()->GetURL(kAuthBasicPage); 323 const GURL auth_page = embedded_test_server()->GetURL(kAuthBasicPage);
325 GURL no_auth_page_1 = embedded_test_server()->GetURL("/a");
326 GURL no_auth_page_2 = embedded_test_server()->GetURL("/b");
327 GURL no_auth_page_3 = embedded_test_server()->GetURL("/c");
328 324
329 content::WebContents* contents = 325 NavigationController* controller =
330 browser()->tab_strip_model()->GetActiveWebContents(); 326 &browser()->tab_strip_model()->GetActiveWebContents()->GetController();
331 NavigationController* controller = &contents->GetController();
332 327
333 LoginPromptBrowserTestObserver observer; 328 LoginPromptBrowserTestObserver observer;
334 observer.Register(content::Source<NavigationController>(controller)); 329 observer.Register(content::Source<NavigationController>(controller));
335 330
336 // First navigate to an unauthenticated page so we have something to
337 // go back to.
338 ui_test_utils::NavigateToURL(browser(), no_auth_page_1);
339
340 // Navigating while auth is requested is the same as cancelling.
341 {
342 // We need to wait for two LOAD_STOP events. One for auth_page and one for
343 // no_auth_page_2.
344 WindowedLoadStopObserver load_stop_waiter(controller, 2);
345 WindowedAuthNeededObserver auth_needed_waiter(controller);
346 browser()->OpenURL(OpenURLParams(
347 auth_page, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_TYPED,
348 false));
349 auth_needed_waiter.Wait();
350 WindowedAuthCancelledObserver auth_cancelled_waiter(controller);
351 browser()->OpenURL(OpenURLParams(
352 no_auth_page_2, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_TYPED,
353 false));
354 auth_cancelled_waiter.Wait();
355 load_stop_waiter.Wait();
356 EXPECT_TRUE(observer.handlers().empty());
357 }
358
359 // Try navigating backwards.
360 {
361 // As above, we wait for two LOAD_STOP events; one for each navigation.
362 WindowedLoadStopObserver load_stop_waiter(controller, 2);
363 WindowedAuthNeededObserver auth_needed_waiter(controller);
364 browser()->OpenURL(OpenURLParams(
365 auth_page, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_TYPED,
366 false));
367 auth_needed_waiter.Wait();
368 WindowedAuthCancelledObserver auth_cancelled_waiter(controller);
369 ASSERT_TRUE(chrome::CanGoBack(browser()));
370 chrome::GoBack(browser(), CURRENT_TAB);
371 auth_cancelled_waiter.Wait();
372 load_stop_waiter.Wait();
373 EXPECT_TRUE(observer.handlers().empty());
374 }
375
376 // Now add a page and go back, so we have something to go forward to.
377 ui_test_utils::NavigateToURL(browser(), no_auth_page_3);
378 {
379 WindowedLoadStopObserver load_stop_waiter(controller, 1);
380 chrome::GoBack(browser(), CURRENT_TAB); // Should take us to page 1
381 load_stop_waiter.Wait();
382 }
383
384 {
385 // We wait for two LOAD_STOP events; one for each navigation.
386 WindowedLoadStopObserver load_stop_waiter(controller, 2);
387 WindowedAuthNeededObserver auth_needed_waiter(controller);
388 browser()->OpenURL(OpenURLParams(
389 auth_page, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_TYPED,
390 false));
391 auth_needed_waiter.Wait();
392 WindowedAuthCancelledObserver auth_cancelled_waiter(controller);
393 ASSERT_TRUE(chrome::CanGoForward(browser()));
394 chrome::GoForward(browser(), CURRENT_TAB); // Should take us to page 3
395 auth_cancelled_waiter.Wait();
396 load_stop_waiter.Wait();
397 EXPECT_TRUE(observer.handlers().empty());
398 }
399
400 // Now test that cancelling works as expected.
401 { 331 {
meacer 2016/08/12 17:45:06 No need for braces anymore.
vabr (Chromium) 2016/08/12 19:39:37 Done.
402 WindowedLoadStopObserver load_stop_waiter(controller, 1); 332 WindowedLoadStopObserver load_stop_waiter(controller, 1);
403 WindowedAuthNeededObserver auth_needed_waiter(controller); 333 WindowedAuthNeededObserver auth_needed_waiter(controller);
404 browser()->OpenURL(OpenURLParams( 334 browser()->OpenURL(OpenURLParams(auth_page, Referrer(), CURRENT_TAB,
405 auth_page, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, 335 ui::PAGE_TRANSITION_TYPED, false));
406 false));
407 auth_needed_waiter.Wait(); 336 auth_needed_waiter.Wait();
408 WindowedAuthCancelledObserver auth_cancelled_waiter(controller); 337 WindowedAuthCancelledObserver auth_cancelled_waiter(controller);
409 LoginHandler* handler = *observer.handlers().begin(); 338 LoginHandler* handler = *observer.handlers().begin();
410 ASSERT_TRUE(handler); 339 ASSERT_TRUE(handler);
411 handler->CancelAuth(); 340 handler->CancelAuth();
412 auth_cancelled_waiter.Wait(); 341 auth_cancelled_waiter.Wait();
413 load_stop_waiter.Wait(); 342 load_stop_waiter.Wait();
414 EXPECT_TRUE(observer.handlers().empty()); 343 EXPECT_TRUE(observer.handlers().empty());
344 }
345 }
346
347 // Test login prompt cancellation on navigation to a new page.
348 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, TestCancelAuth_OnNavigation) {
349 ASSERT_TRUE(embedded_test_server()->Start());
350 const GURL auth_page = embedded_test_server()->GetURL(kAuthBasicPage);
351 const GURL no_auth_page = embedded_test_server()->GetURL("/b");
meacer 2016/08/12 17:45:05 You might want to use kNoAuthPage here too, instea
vabr (Chromium) 2016/08/12 19:39:37 Done.
352
353 NavigationController* controller =
354 &browser()->tab_strip_model()->GetActiveWebContents()->GetController();
355
356 LoginPromptBrowserTestObserver observer;
357 observer.Register(content::Source<NavigationController>(controller));
358
359 // Navigating while auth is requested is the same as cancelling.
360 {
meacer 2016/08/12 17:45:06 No need for braces.
vabr (Chromium) 2016/08/12 19:39:37 Done. Also, I moved the comment from line 359 near
361 // One LOAD_STOP event for auth_page and one for no_auth_page.
362 const int kLoadStopEvents = 2;
363 WindowedLoadStopObserver load_stop_waiter(controller, kLoadStopEvents);
364 WindowedAuthNeededObserver auth_needed_waiter(controller);
365 browser()->OpenURL(OpenURLParams(auth_page, Referrer(), CURRENT_TAB,
366 ui::PAGE_TRANSITION_TYPED, false));
367 auth_needed_waiter.Wait();
368 WindowedAuthCancelledObserver auth_cancelled_waiter(controller);
369 browser()->OpenURL(OpenURLParams(no_auth_page, Referrer(), CURRENT_TAB,
370 ui::PAGE_TRANSITION_TYPED, false));
371 auth_cancelled_waiter.Wait();
372 load_stop_waiter.Wait();
373 EXPECT_TRUE(observer.handlers().empty());
374 }
375 }
376
377 // Test login prompt cancellation on navigation to back.
378 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, TestCancelAuth_OnBack) {
379 ASSERT_TRUE(embedded_test_server()->Start());
380 const GURL auth_page = embedded_test_server()->GetURL(kAuthBasicPage);
381 const GURL no_auth_page = embedded_test_server()->GetURL("/a");
meacer 2016/08/12 17:45:05 Same here (kNoAuthPage)
vabr (Chromium) 2016/08/12 19:39:37 Done.
382
383 NavigationController* controller =
384 &browser()->tab_strip_model()->GetActiveWebContents()->GetController();
385
386 LoginPromptBrowserTestObserver observer;
387 observer.Register(content::Source<NavigationController>(controller));
388
389 // First navigate to an unauthenticated page so we have something to
390 // go back to.
391 ui_test_utils::NavigateToURL(browser(), no_auth_page);
392
393 // Navigating back while auth is requested is the same as cancelling.
meacer 2016/08/12 17:45:06 nit: No braces
vabr (Chromium) 2016/08/12 19:39:37 Done.
394 {
395 // One LOAD_STOP event for auth_page and one for no_auth_page.
396 const int kLoadStopEvents = 2;
397 WindowedLoadStopObserver load_stop_waiter(controller, kLoadStopEvents);
398 WindowedAuthNeededObserver auth_needed_waiter(controller);
399 browser()->OpenURL(OpenURLParams(auth_page, Referrer(), CURRENT_TAB,
400 ui::PAGE_TRANSITION_TYPED, false));
401 auth_needed_waiter.Wait();
402 WindowedAuthCancelledObserver auth_cancelled_waiter(controller);
403 ASSERT_TRUE(controller->CanGoBack());
404 controller->GoBack();
405 auth_cancelled_waiter.Wait();
406 load_stop_waiter.Wait();
407 EXPECT_TRUE(observer.handlers().empty());
408 }
409 }
410
411 // Test login prompt cancellation on navigation to forward.
412 // TODO(crbug.com/636875) Flaky on Mac and Linux at least.
413 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest,
414 DISABLED_TestCancelAuth_OnForward) {
415 ASSERT_TRUE(embedded_test_server()->Start());
416 const GURL auth_page = embedded_test_server()->GetURL(kAuthBasicPage);
417 const GURL no_auth_page_1 = embedded_test_server()->GetURL("/a");
meacer 2016/08/12 17:45:06 nit: Seems like these could be named kNoAuthURL1 a
vabr (Chromium) 2016/08/12 19:39:37 Done.
418 const GURL no_auth_page_2 = embedded_test_server()->GetURL("/c");
meacer 2016/08/12 17:45:06 And here.
vabr (Chromium) 2016/08/12 19:39:37 Done.
419
420 NavigationController* controller =
421 &browser()->tab_strip_model()->GetActiveWebContents()->GetController();
422
423 LoginPromptBrowserTestObserver observer;
424 observer.Register(content::Source<NavigationController>(controller));
425
426 ui_test_utils::NavigateToURL(browser(), no_auth_page_1);
427
428 // Now add a page and go back, so we have something to go forward to.
429 ui_test_utils::NavigateToURL(browser(), no_auth_page_2);
430 {
431 WindowedLoadStopObserver load_stop_waiter(controller, 1);
432 ASSERT_TRUE(controller->CanGoBack());
433 controller->GoBack();
434 load_stop_waiter.Wait();
435 }
436
437 {
438 // One LOAD_STOP event for auth_page and one for no_auth_page.
439 const int kLoadStopEvents = 2;
440 WindowedLoadStopObserver load_stop_waiter(controller, kLoadStopEvents);
441 WindowedAuthNeededObserver auth_needed_waiter(controller);
442 browser()->OpenURL(OpenURLParams(auth_page, Referrer(), CURRENT_TAB,
443 ui::PAGE_TRANSITION_TYPED, false));
444 auth_needed_waiter.Wait();
445 WindowedAuthCancelledObserver auth_cancelled_waiter(controller);
446 ASSERT_TRUE(controller->CanGoForward());
447 controller->GoForward();
448 auth_cancelled_waiter.Wait();
449 load_stop_waiter.Wait();
450 EXPECT_TRUE(observer.handlers().empty());
415 } 451 }
416 } 452 }
417 453
418 // Test handling of resources that require authentication even though 454 // Test handling of resources that require authentication even though
419 // the page they are included on doesn't. In this case we should only 455 // the page they are included on doesn't. In this case we should only
420 // present the minimal number of prompts necessary for successfully 456 // present the minimal number of prompts necessary for successfully
421 // displaying the page. First we check whether cancelling works as 457 // displaying the page. First we check whether cancelling works as
422 // expected. 458 // expected.
423 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, MultipleRealmCancellation) { 459 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, MultipleRealmCancellation) {
424 ASSERT_TRUE(embedded_test_server()->Start()); 460 ASSERT_TRUE(embedded_test_server()->Start());
(...skipping 1045 matching lines...) Expand 10 before | Expand all | Expand 10 after
1470 // out. 1506 // out.
1471 EXPECT_TRUE( 1507 EXPECT_TRUE(
1472 WaitForRenderFrameReady(contents->GetInterstitialPage()->GetMainFrame())); 1508 WaitForRenderFrameReady(contents->GetInterstitialPage()->GetMainFrame()));
1473 EXPECT_TRUE(contents->ShowingInterstitialPage()); 1509 EXPECT_TRUE(contents->ShowingInterstitialPage());
1474 EXPECT_EQ(SSLBlockingPage::kTypeForTesting, contents->GetInterstitialPage() 1510 EXPECT_EQ(SSLBlockingPage::kTypeForTesting, contents->GetInterstitialPage()
1475 ->GetDelegateForTesting() 1511 ->GetDelegateForTesting()
1476 ->GetTypeForTesting()); 1512 ->GetTypeForTesting());
1477 } 1513 }
1478 1514
1479 } // namespace 1515 } // namespace
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698