15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/app/chrome_command_ids.h" 67dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "chrome/browser/chrome_notification_types.h" 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/browser.h" 82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/tabs/tab_strip_model.h" 9558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch#include "chrome/common/net/url_fixer_upper.h" 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/url_constants.h" 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/test/base/in_process_browser_test.h" 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/test/base/ui_test_utils.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/test/ui/ui_test.h" 1490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "components/web_modal/web_contents_modal_dialog_manager.h" 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/navigation_controller.h" 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/web_contents.h" 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/test/test_navigation_observer.h" 18b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)#include "net/test/spawned_test_server/spawned_test_server.h" 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)using web_modal::WebContentsModalDialogManager; 2190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef InProcessBrowserTest RepostFormWarningTest; 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// If becomes flaky, disable on Windows and use http://crbug.com/47228 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(RepostFormWarningTest, TestDoubleReload) { 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(test_server()->Start()); 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Load a form. 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui_test_utils::NavigateToURL( 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) browser(), test_server()->GetURL("files/form.html")); 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Submit it. 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui_test_utils::NavigateToURL( 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) browser(), 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL("javascript:document.getElementById('form').submit()")); 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Try to reload it twice, checking for repost. 372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::WebContents* web_contents = 382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser()->tab_strip_model()->GetActiveWebContents(); 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) web_contents->GetController().Reload(true); 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) web_contents->GetController().Reload(true); 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // There should only be one dialog open. 432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) WebContentsModalDialogManager* web_contents_modal_dialog_manager = 442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) WebContentsModalDialogManager::FromWebContents(web_contents); 4558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) EXPECT_TRUE(web_contents_modal_dialog_manager->IsDialogActive()); 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Navigate away from the page (this is when the test usually crashes). 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui_test_utils::NavigateToURL(browser(), test_server()->GetURL("bar")); 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The dialog should've been closed. 5158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) EXPECT_FALSE(web_contents_modal_dialog_manager->IsDialogActive()); 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// If becomes flaky, disable on Windows and use http://crbug.com/47228 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(RepostFormWarningTest, TestLoginAfterRepost) { 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(test_server()->Start()); 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Load a form. 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui_test_utils::NavigateToURL( 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) browser(), test_server()->GetURL("files/form.html")); 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Submit it. 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui_test_utils::NavigateToURL( 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) browser(), 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL("javascript:document.getElementById('form').submit()")); 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Try to reload it, checking for repost. 672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::WebContents* web_contents = 682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser()->tab_strip_model()->GetActiveWebContents(); 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) web_contents->GetController().Reload(true); 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Navigate to a page that requires authentication, bringing up another 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // tab-modal sheet. 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::NavigationController& controller = web_contents->GetController(); 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::WindowedNotificationObserver observer( 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) chrome::NOTIFICATION_AUTH_NEEDED, 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::Source<content::NavigationController>(&controller)); 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) browser()->OpenURL(content::OpenURLParams( 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) test_server()->GetURL("auth-basic"), content::Referrer(), CURRENT_TAB, 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::PAGE_TRANSITION_TYPED, false)); 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) observer.Wait(); 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Try to reload it again. 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) web_contents->GetController().Reload(true); 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Navigate away from the page. We can't use ui_test_utils:NavigateToURL 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // because that waits for the current page to stop loading first, which won't 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // happen while the auth dialog is up. 88868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) content::TestNavigationObserver navigation_observer(web_contents); 895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) browser()->OpenURL(content::OpenURLParams( 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) test_server()->GetURL("bar"), content::Referrer(), CURRENT_TAB, 915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::PAGE_TRANSITION_TYPED, false)); 925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) navigation_observer.Wait(); 935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 94