Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 96 const char kPrefetchAuthPage[] = "/login/prefetch.html"; | 96 const char kPrefetchAuthPage[] = "/login/prefetch.html"; |
| 97 | 97 |
| 98 const char kMultiRealmTestPage[] = "/login/multi_realm.html"; | 98 const char kMultiRealmTestPage[] = "/login/multi_realm.html"; |
| 99 const int kMultiRealmTestRealmCount = 2; | 99 const int kMultiRealmTestRealmCount = 2; |
| 100 | 100 |
| 101 const char kSingleRealmTestPage[] = "/login/single_realm.html"; | 101 const char kSingleRealmTestPage[] = "/login/single_realm.html"; |
| 102 | 102 |
| 103 const char kAuthBasicPage[] = "/auth-basic"; | 103 const char kAuthBasicPage[] = "/auth-basic"; |
| 104 const char kAuthDigestPage[] = "/auth-digest"; | 104 const char kAuthDigestPage[] = "/auth-digest"; |
| 105 | 105 |
| 106 // It does not matter what pages are selected as no-auth, as long as they exist. | |
| 107 // Navigating to non-existing pages caused flakes in the past | |
| 108 // (http://crbug.com/636875). | |
|
meacer
2016/08/12 17:23:27
Very tiny nit: https://crbug.com :)
vabr (Chromium)
2016/08/12 19:40:08
Done.
| |
| 109 const char kNoAuthPage1[] = "/simple.html"; | |
| 110 const char kNoAuthPage2[] = "/form.html"; | |
| 111 | |
| 106 base::string16 ExpectedTitleFromAuth(const base::string16& username, | 112 base::string16 ExpectedTitleFromAuth(const base::string16& username, |
| 107 const base::string16& password) { | 113 const base::string16& password) { |
| 108 // The TestServer sets the title to username/password on successful login. | 114 // The TestServer sets the title to username/password on successful login. |
| 109 return username + base::UTF8ToUTF16("/") + password; | 115 return username + base::UTF8ToUTF16("/") + password; |
| 110 } | 116 } |
| 111 | 117 |
| 112 // Confirm that <link rel="prefetch"> targetting an auth required | 118 // Confirm that <link rel="prefetch"> targetting an auth required |
| 113 // resource does not provide a login dialog. These types of requests | 119 // resource does not provide a login dialog. These types of requests |
| 114 // should instead just cancel the auth. | 120 // should instead just cancel the auth. |
| 115 | 121 |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 341 auth_cancelled_waiter.Wait(); | 347 auth_cancelled_waiter.Wait(); |
| 342 load_stop_waiter.Wait(); | 348 load_stop_waiter.Wait(); |
| 343 EXPECT_TRUE(observer.handlers().empty()); | 349 EXPECT_TRUE(observer.handlers().empty()); |
| 344 } | 350 } |
| 345 } | 351 } |
| 346 | 352 |
| 347 // Test login prompt cancellation on navigation to a new page. | 353 // Test login prompt cancellation on navigation to a new page. |
| 348 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, TestCancelAuth_OnNavigation) { | 354 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, TestCancelAuth_OnNavigation) { |
| 349 ASSERT_TRUE(embedded_test_server()->Start()); | 355 ASSERT_TRUE(embedded_test_server()->Start()); |
| 350 const GURL auth_page = embedded_test_server()->GetURL(kAuthBasicPage); | 356 const GURL auth_page = embedded_test_server()->GetURL(kAuthBasicPage); |
| 351 const GURL no_auth_page = embedded_test_server()->GetURL("/b"); | 357 const GURL no_auth_page = embedded_test_server()->GetURL(kNoAuthPage1); |
| 352 | 358 |
| 353 NavigationController* controller = | 359 NavigationController* controller = |
| 354 &browser()->tab_strip_model()->GetActiveWebContents()->GetController(); | 360 &browser()->tab_strip_model()->GetActiveWebContents()->GetController(); |
| 355 | 361 |
| 356 LoginPromptBrowserTestObserver observer; | 362 LoginPromptBrowserTestObserver observer; |
| 357 observer.Register(content::Source<NavigationController>(controller)); | 363 observer.Register(content::Source<NavigationController>(controller)); |
| 358 | 364 |
| 359 // Navigating while auth is requested is the same as cancelling. | 365 // Navigating while auth is requested is the same as cancelling. |
| 360 { | 366 { |
| 361 // One LOAD_STOP event for auth_page and one for no_auth_page. | 367 // One LOAD_STOP event for auth_page and one for no_auth_page. |
| 362 const int kLoadStopEvents = 2; | 368 const int kLoadStopEvents = 2; |
| 363 WindowedLoadStopObserver load_stop_waiter(controller, kLoadStopEvents); | 369 WindowedLoadStopObserver load_stop_waiter(controller, kLoadStopEvents); |
| 364 WindowedAuthNeededObserver auth_needed_waiter(controller); | 370 WindowedAuthNeededObserver auth_needed_waiter(controller); |
| 365 browser()->OpenURL(OpenURLParams(auth_page, Referrer(), CURRENT_TAB, | 371 browser()->OpenURL(OpenURLParams(auth_page, Referrer(), CURRENT_TAB, |
| 366 ui::PAGE_TRANSITION_TYPED, false)); | 372 ui::PAGE_TRANSITION_TYPED, false)); |
| 367 auth_needed_waiter.Wait(); | 373 auth_needed_waiter.Wait(); |
| 368 WindowedAuthCancelledObserver auth_cancelled_waiter(controller); | 374 WindowedAuthCancelledObserver auth_cancelled_waiter(controller); |
| 369 browser()->OpenURL(OpenURLParams(no_auth_page, Referrer(), CURRENT_TAB, | 375 browser()->OpenURL(OpenURLParams(no_auth_page, Referrer(), CURRENT_TAB, |
| 370 ui::PAGE_TRANSITION_TYPED, false)); | 376 ui::PAGE_TRANSITION_TYPED, false)); |
| 371 auth_cancelled_waiter.Wait(); | 377 auth_cancelled_waiter.Wait(); |
| 372 load_stop_waiter.Wait(); | 378 load_stop_waiter.Wait(); |
| 373 EXPECT_TRUE(observer.handlers().empty()); | 379 EXPECT_TRUE(observer.handlers().empty()); |
| 374 } | 380 } |
| 375 } | 381 } |
| 376 | 382 |
| 377 // Test login prompt cancellation on navigation to back. | 383 // Test login prompt cancellation on navigation to back. |
| 378 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, TestCancelAuth_OnBack) { | 384 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, TestCancelAuth_OnBack) { |
| 379 ASSERT_TRUE(embedded_test_server()->Start()); | 385 ASSERT_TRUE(embedded_test_server()->Start()); |
| 380 const GURL auth_page = embedded_test_server()->GetURL(kAuthBasicPage); | 386 const GURL auth_page = embedded_test_server()->GetURL(kAuthBasicPage); |
| 381 const GURL no_auth_page = embedded_test_server()->GetURL("/a"); | 387 const GURL no_auth_page = embedded_test_server()->GetURL(kNoAuthPage1); |
| 382 | 388 |
| 383 NavigationController* controller = | 389 NavigationController* controller = |
| 384 &browser()->tab_strip_model()->GetActiveWebContents()->GetController(); | 390 &browser()->tab_strip_model()->GetActiveWebContents()->GetController(); |
| 385 | 391 |
| 386 LoginPromptBrowserTestObserver observer; | 392 LoginPromptBrowserTestObserver observer; |
| 387 observer.Register(content::Source<NavigationController>(controller)); | 393 observer.Register(content::Source<NavigationController>(controller)); |
| 388 | 394 |
| 389 // First navigate to an unauthenticated page so we have something to | 395 // First navigate to an unauthenticated page so we have something to |
| 390 // go back to. | 396 // go back to. |
| 391 ui_test_utils::NavigateToURL(browser(), no_auth_page); | 397 ui_test_utils::NavigateToURL(browser(), no_auth_page); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 402 WindowedAuthCancelledObserver auth_cancelled_waiter(controller); | 408 WindowedAuthCancelledObserver auth_cancelled_waiter(controller); |
| 403 ASSERT_TRUE(controller->CanGoBack()); | 409 ASSERT_TRUE(controller->CanGoBack()); |
| 404 controller->GoBack(); | 410 controller->GoBack(); |
| 405 auth_cancelled_waiter.Wait(); | 411 auth_cancelled_waiter.Wait(); |
| 406 load_stop_waiter.Wait(); | 412 load_stop_waiter.Wait(); |
| 407 EXPECT_TRUE(observer.handlers().empty()); | 413 EXPECT_TRUE(observer.handlers().empty()); |
| 408 } | 414 } |
| 409 } | 415 } |
| 410 | 416 |
| 411 // Test login prompt cancellation on navigation to forward. | 417 // Test login prompt cancellation on navigation to forward. |
| 412 // TODO(crbug.com/636875) Flaky on Mac and Linux at least. | 418 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, TestCancelAuth_OnForward) { |
| 413 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, | |
| 414 DISABLED_TestCancelAuth_OnForward) { | |
| 415 ASSERT_TRUE(embedded_test_server()->Start()); | 419 ASSERT_TRUE(embedded_test_server()->Start()); |
| 416 const GURL auth_page = embedded_test_server()->GetURL(kAuthBasicPage); | 420 const GURL auth_page = embedded_test_server()->GetURL(kAuthBasicPage); |
| 417 const GURL no_auth_page_1 = embedded_test_server()->GetURL("/a"); | 421 const GURL no_auth_page_1 = embedded_test_server()->GetURL(kNoAuthPage1); |
| 418 const GURL no_auth_page_2 = embedded_test_server()->GetURL("/c"); | 422 const GURL no_auth_page_2 = embedded_test_server()->GetURL(kNoAuthPage2); |
| 419 | 423 |
| 420 NavigationController* controller = | 424 NavigationController* controller = |
| 421 &browser()->tab_strip_model()->GetActiveWebContents()->GetController(); | 425 &browser()->tab_strip_model()->GetActiveWebContents()->GetController(); |
| 422 | 426 |
| 423 LoginPromptBrowserTestObserver observer; | 427 LoginPromptBrowserTestObserver observer; |
| 424 observer.Register(content::Source<NavigationController>(controller)); | 428 observer.Register(content::Source<NavigationController>(controller)); |
| 425 | 429 |
| 426 ui_test_utils::NavigateToURL(browser(), no_auth_page_1); | 430 ui_test_utils::NavigateToURL(browser(), no_auth_page_1); |
| 427 | 431 |
| 428 // Now add a page and go back, so we have something to go forward to. | 432 // Now add a page and go back, so we have something to go forward to. |
| (...skipping 1077 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1506 // out. | 1510 // out. |
| 1507 EXPECT_TRUE( | 1511 EXPECT_TRUE( |
| 1508 WaitForRenderFrameReady(contents->GetInterstitialPage()->GetMainFrame())); | 1512 WaitForRenderFrameReady(contents->GetInterstitialPage()->GetMainFrame())); |
| 1509 EXPECT_TRUE(contents->ShowingInterstitialPage()); | 1513 EXPECT_TRUE(contents->ShowingInterstitialPage()); |
| 1510 EXPECT_EQ(SSLBlockingPage::kTypeForTesting, contents->GetInterstitialPage() | 1514 EXPECT_EQ(SSLBlockingPage::kTypeForTesting, contents->GetInterstitialPage() |
| 1511 ->GetDelegateForTesting() | 1515 ->GetDelegateForTesting() |
| 1512 ->GetTypeForTesting()); | 1516 ->GetTypeForTesting()); |
| 1513 } | 1517 } |
| 1514 | 1518 |
| 1515 } // namespace | 1519 } // namespace |
| OLD | NEW |