| 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 const char kNoAuthPage1[] = "/a"; |
| 107 const char kNoAuthPage2[] = "/b"; |
| 108 |
| 106 base::string16 ExpectedTitleFromAuth(const base::string16& username, | 109 base::string16 ExpectedTitleFromAuth(const base::string16& username, |
| 107 const base::string16& password) { | 110 const base::string16& password) { |
| 108 // The TestServer sets the title to username/password on successful login. | 111 // The TestServer sets the title to username/password on successful login. |
| 109 return username + base::UTF8ToUTF16("/") + password; | 112 return username + base::UTF8ToUTF16("/") + password; |
| 110 } | 113 } |
| 111 | 114 |
| 112 // Confirm that <link rel="prefetch"> targetting an auth required | 115 // Confirm that <link rel="prefetch"> targetting an auth required |
| 113 // resource does not provide a login dialog. These types of requests | 116 // resource does not provide a login dialog. These types of requests |
| 114 // should instead just cancel the auth. | 117 // should instead just cancel the auth. |
| 115 | 118 |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 | 313 |
| 311 handler1->SetAuth(base::UTF8ToUTF16(username_basic_), | 314 handler1->SetAuth(base::UTF8ToUTF16(username_basic_), |
| 312 base::UTF8ToUTF16(password_)); | 315 base::UTF8ToUTF16(password_)); |
| 313 handler2->SetAuth(base::UTF8ToUTF16(username_digest_), | 316 handler2->SetAuth(base::UTF8ToUTF16(username_digest_), |
| 314 base::UTF8ToUTF16(password_)); | 317 base::UTF8ToUTF16(password_)); |
| 315 | 318 |
| 316 EXPECT_EQ(expected_title1, title_watcher1.WaitAndGetTitle()); | 319 EXPECT_EQ(expected_title1, title_watcher1.WaitAndGetTitle()); |
| 317 EXPECT_EQ(expected_title2, title_watcher2.WaitAndGetTitle()); | 320 EXPECT_EQ(expected_title2, title_watcher2.WaitAndGetTitle()); |
| 318 } | 321 } |
| 319 | 322 |
| 320 // Test login prompt cancellation. | 323 // Test manual login prompt cancellation. |
| 321 // Flaky on Mac crbug.com/636875 | 324 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, TestCancelAuth_Manual) { |
| 322 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, DISABLED_TestCancelAuth) { | |
| 323 ASSERT_TRUE(embedded_test_server()->Start()); | 325 ASSERT_TRUE(embedded_test_server()->Start()); |
| 324 GURL auth_page = embedded_test_server()->GetURL(kAuthBasicPage); | 326 const GURL kAuthURL = 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 | 327 |
| 329 content::WebContents* contents = | 328 NavigationController* controller = |
| 330 browser()->tab_strip_model()->GetActiveWebContents(); | 329 &browser()->tab_strip_model()->GetActiveWebContents()->GetController(); |
| 331 NavigationController* controller = &contents->GetController(); | 330 |
| 331 LoginPromptBrowserTestObserver observer; |
| 332 observer.Register(content::Source<NavigationController>(controller)); |
| 333 |
| 334 WindowedLoadStopObserver load_stop_waiter(controller, 1); |
| 335 WindowedAuthNeededObserver auth_needed_waiter(controller); |
| 336 browser()->OpenURL(OpenURLParams(kAuthURL, Referrer(), CURRENT_TAB, |
| 337 ui::PAGE_TRANSITION_TYPED, false)); |
| 338 auth_needed_waiter.Wait(); |
| 339 WindowedAuthCancelledObserver auth_cancelled_waiter(controller); |
| 340 LoginHandler* handler = *observer.handlers().begin(); |
| 341 ASSERT_TRUE(handler); |
| 342 handler->CancelAuth(); |
| 343 auth_cancelled_waiter.Wait(); |
| 344 load_stop_waiter.Wait(); |
| 345 EXPECT_TRUE(observer.handlers().empty()); |
| 346 } |
| 347 |
| 348 // Test login prompt cancellation on navigation to a new page. |
| 349 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, TestCancelAuth_OnNavigation) { |
| 350 ASSERT_TRUE(embedded_test_server()->Start()); |
| 351 const GURL kAuthURL = embedded_test_server()->GetURL(kAuthBasicPage); |
| 352 const GURL kNoAuthURL = embedded_test_server()->GetURL(kNoAuthPage1); |
| 353 |
| 354 NavigationController* controller = |
| 355 &browser()->tab_strip_model()->GetActiveWebContents()->GetController(); |
| 356 |
| 357 LoginPromptBrowserTestObserver observer; |
| 358 observer.Register(content::Source<NavigationController>(controller)); |
| 359 |
| 360 // One LOAD_STOP event for kAuthURL and one for kNoAuthURL. |
| 361 const int kLoadStopEvents = 2; |
| 362 WindowedLoadStopObserver load_stop_waiter(controller, kLoadStopEvents); |
| 363 WindowedAuthNeededObserver auth_needed_waiter(controller); |
| 364 browser()->OpenURL(OpenURLParams(kAuthURL, Referrer(), CURRENT_TAB, |
| 365 ui::PAGE_TRANSITION_TYPED, false)); |
| 366 auth_needed_waiter.Wait(); |
| 367 WindowedAuthCancelledObserver auth_cancelled_waiter(controller); |
| 368 // Navigating while auth is requested is the same as cancelling. |
| 369 browser()->OpenURL(OpenURLParams(kNoAuthURL, 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 // Test login prompt cancellation on navigation to back. |
| 377 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, TestCancelAuth_OnBack) { |
| 378 ASSERT_TRUE(embedded_test_server()->Start()); |
| 379 const GURL kAuthURL = embedded_test_server()->GetURL(kAuthBasicPage); |
| 380 const GURL kNoAuthURL = embedded_test_server()->GetURL(kNoAuthPage1); |
| 381 |
| 382 NavigationController* controller = |
| 383 &browser()->tab_strip_model()->GetActiveWebContents()->GetController(); |
| 332 | 384 |
| 333 LoginPromptBrowserTestObserver observer; | 385 LoginPromptBrowserTestObserver observer; |
| 334 observer.Register(content::Source<NavigationController>(controller)); | 386 observer.Register(content::Source<NavigationController>(controller)); |
| 335 | 387 |
| 336 // First navigate to an unauthenticated page so we have something to | 388 // First navigate to an unauthenticated page so we have something to |
| 337 // go back to. | 389 // go back to. |
| 338 ui_test_utils::NavigateToURL(browser(), no_auth_page_1); | 390 ui_test_utils::NavigateToURL(browser(), kNoAuthURL); |
| 339 | 391 |
| 340 // Navigating while auth is requested is the same as cancelling. | 392 // One LOAD_STOP event for kAuthURL and one for kNoAuthURL. |
| 341 { | 393 const int kLoadStopEvents = 2; |
| 342 // We need to wait for two LOAD_STOP events. One for auth_page and one for | 394 WindowedLoadStopObserver load_stop_waiter(controller, kLoadStopEvents); |
| 343 // no_auth_page_2. | 395 WindowedAuthNeededObserver auth_needed_waiter(controller); |
| 344 WindowedLoadStopObserver load_stop_waiter(controller, 2); | 396 browser()->OpenURL(OpenURLParams(kAuthURL, Referrer(), CURRENT_TAB, |
| 345 WindowedAuthNeededObserver auth_needed_waiter(controller); | 397 ui::PAGE_TRANSITION_TYPED, false)); |
| 346 browser()->OpenURL(OpenURLParams( | 398 auth_needed_waiter.Wait(); |
| 347 auth_page, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, | 399 WindowedAuthCancelledObserver auth_cancelled_waiter(controller); |
| 348 false)); | 400 // Navigating back while auth is requested is the same as cancelling. |
| 349 auth_needed_waiter.Wait(); | 401 ASSERT_TRUE(controller->CanGoBack()); |
| 350 WindowedAuthCancelledObserver auth_cancelled_waiter(controller); | 402 controller->GoBack(); |
| 351 browser()->OpenURL(OpenURLParams( | 403 auth_cancelled_waiter.Wait(); |
| 352 no_auth_page_2, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, | 404 load_stop_waiter.Wait(); |
| 353 false)); | 405 EXPECT_TRUE(observer.handlers().empty()); |
| 354 auth_cancelled_waiter.Wait(); | 406 } |
| 355 load_stop_waiter.Wait(); | |
| 356 EXPECT_TRUE(observer.handlers().empty()); | |
| 357 } | |
| 358 | 407 |
| 359 // Try navigating backwards. | 408 // Test login prompt cancellation on navigation to forward. |
| 360 { | 409 // TODO(crbug.com/636875) Flaky on Mac and Linux at least. |
| 361 // As above, we wait for two LOAD_STOP events; one for each navigation. | 410 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, |
| 362 WindowedLoadStopObserver load_stop_waiter(controller, 2); | 411 DISABLED_TestCancelAuth_OnForward) { |
| 363 WindowedAuthNeededObserver auth_needed_waiter(controller); | 412 ASSERT_TRUE(embedded_test_server()->Start()); |
| 364 browser()->OpenURL(OpenURLParams( | 413 const GURL kAuthURL = embedded_test_server()->GetURL(kAuthBasicPage); |
| 365 auth_page, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, | 414 const GURL kNoAuthURL1 = embedded_test_server()->GetURL(kNoAuthPage1); |
| 366 false)); | 415 const GURL kNoAuthURL2 = embedded_test_server()->GetURL(kNoAuthPage2); |
| 367 auth_needed_waiter.Wait(); | 416 |
| 368 WindowedAuthCancelledObserver auth_cancelled_waiter(controller); | 417 NavigationController* controller = |
| 369 ASSERT_TRUE(chrome::CanGoBack(browser())); | 418 &browser()->tab_strip_model()->GetActiveWebContents()->GetController(); |
| 370 chrome::GoBack(browser(), CURRENT_TAB); | 419 |
| 371 auth_cancelled_waiter.Wait(); | 420 LoginPromptBrowserTestObserver observer; |
| 372 load_stop_waiter.Wait(); | 421 observer.Register(content::Source<NavigationController>(controller)); |
| 373 EXPECT_TRUE(observer.handlers().empty()); | 422 |
| 374 } | 423 ui_test_utils::NavigateToURL(browser(), kNoAuthURL1); |
| 375 | 424 |
| 376 // Now add a page and go back, so we have something to go forward to. | 425 // 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); | 426 ui_test_utils::NavigateToURL(browser(), kNoAuthURL2); |
| 378 { | 427 { |
| 379 WindowedLoadStopObserver load_stop_waiter(controller, 1); | 428 WindowedLoadStopObserver load_stop_waiter(controller, 1); |
| 380 chrome::GoBack(browser(), CURRENT_TAB); // Should take us to page 1 | 429 ASSERT_TRUE(controller->CanGoBack()); |
| 430 controller->GoBack(); |
| 381 load_stop_waiter.Wait(); | 431 load_stop_waiter.Wait(); |
| 382 } | 432 } |
| 383 | 433 |
| 384 { | 434 // One LOAD_STOP event for kAuthURL and one for kNoAuthURL. |
| 385 // We wait for two LOAD_STOP events; one for each navigation. | 435 const int kLoadStopEvents = 2; |
| 386 WindowedLoadStopObserver load_stop_waiter(controller, 2); | 436 WindowedLoadStopObserver load_stop_waiter(controller, kLoadStopEvents); |
| 387 WindowedAuthNeededObserver auth_needed_waiter(controller); | 437 WindowedAuthNeededObserver auth_needed_waiter(controller); |
| 388 browser()->OpenURL(OpenURLParams( | 438 browser()->OpenURL(OpenURLParams(kAuthURL, Referrer(), CURRENT_TAB, |
| 389 auth_page, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, | 439 ui::PAGE_TRANSITION_TYPED, false)); |
| 390 false)); | 440 auth_needed_waiter.Wait(); |
| 391 auth_needed_waiter.Wait(); | 441 WindowedAuthCancelledObserver auth_cancelled_waiter(controller); |
| 392 WindowedAuthCancelledObserver auth_cancelled_waiter(controller); | 442 ASSERT_TRUE(controller->CanGoForward()); |
| 393 ASSERT_TRUE(chrome::CanGoForward(browser())); | 443 controller->GoForward(); |
| 394 chrome::GoForward(browser(), CURRENT_TAB); // Should take us to page 3 | 444 auth_cancelled_waiter.Wait(); |
| 395 auth_cancelled_waiter.Wait(); | 445 load_stop_waiter.Wait(); |
| 396 load_stop_waiter.Wait(); | 446 EXPECT_TRUE(observer.handlers().empty()); |
| 397 EXPECT_TRUE(observer.handlers().empty()); | |
| 398 } | |
| 399 | |
| 400 // Now test that cancelling works as expected. | |
| 401 { | |
| 402 WindowedLoadStopObserver load_stop_waiter(controller, 1); | |
| 403 WindowedAuthNeededObserver auth_needed_waiter(controller); | |
| 404 browser()->OpenURL(OpenURLParams( | |
| 405 auth_page, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, | |
| 406 false)); | |
| 407 auth_needed_waiter.Wait(); | |
| 408 WindowedAuthCancelledObserver auth_cancelled_waiter(controller); | |
| 409 LoginHandler* handler = *observer.handlers().begin(); | |
| 410 ASSERT_TRUE(handler); | |
| 411 handler->CancelAuth(); | |
| 412 auth_cancelled_waiter.Wait(); | |
| 413 load_stop_waiter.Wait(); | |
| 414 EXPECT_TRUE(observer.handlers().empty()); | |
| 415 } | |
| 416 } | 447 } |
| 417 | 448 |
| 418 // Test handling of resources that require authentication even though | 449 // Test handling of resources that require authentication even though |
| 419 // the page they are included on doesn't. In this case we should only | 450 // the page they are included on doesn't. In this case we should only |
| 420 // present the minimal number of prompts necessary for successfully | 451 // present the minimal number of prompts necessary for successfully |
| 421 // displaying the page. First we check whether cancelling works as | 452 // displaying the page. First we check whether cancelling works as |
| 422 // expected. | 453 // expected. |
| 423 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, MultipleRealmCancellation) { | 454 IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, MultipleRealmCancellation) { |
| 424 ASSERT_TRUE(embedded_test_server()->Start()); | 455 ASSERT_TRUE(embedded_test_server()->Start()); |
| 425 GURL test_page = embedded_test_server()->GetURL(kMultiRealmTestPage); | 456 GURL test_page = embedded_test_server()->GetURL(kMultiRealmTestPage); |
| (...skipping 1044 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1470 // out. | 1501 // out. |
| 1471 EXPECT_TRUE( | 1502 EXPECT_TRUE( |
| 1472 WaitForRenderFrameReady(contents->GetInterstitialPage()->GetMainFrame())); | 1503 WaitForRenderFrameReady(contents->GetInterstitialPage()->GetMainFrame())); |
| 1473 EXPECT_TRUE(contents->ShowingInterstitialPage()); | 1504 EXPECT_TRUE(contents->ShowingInterstitialPage()); |
| 1474 EXPECT_EQ(SSLBlockingPage::kTypeForTesting, contents->GetInterstitialPage() | 1505 EXPECT_EQ(SSLBlockingPage::kTypeForTesting, contents->GetInterstitialPage() |
| 1475 ->GetDelegateForTesting() | 1506 ->GetDelegateForTesting() |
| 1476 ->GetTypeForTesting()); | 1507 ->GetTypeForTesting()); |
| 1477 } | 1508 } |
| 1478 | 1509 |
| 1479 } // namespace | 1510 } // namespace |
| OLD | NEW |