Home | History | Annotate | Download | only in browser
      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
      3 // found in the LICENSE file.
      4 
      5 #include "chrome/app/chrome_command_ids.h"
      6 #include "chrome/browser/chrome_notification_types.h"
      7 #include "chrome/browser/ui/browser.h"
      8 #include "chrome/browser/ui/tabs/tab_strip_model.h"
      9 #include "chrome/common/net/url_fixer_upper.h"
     10 #include "chrome/common/url_constants.h"
     11 #include "chrome/test/base/in_process_browser_test.h"
     12 #include "chrome/test/base/ui_test_utils.h"
     13 #include "chrome/test/ui/ui_test.h"
     14 #include "components/web_modal/web_contents_modal_dialog_manager.h"
     15 #include "content/public/browser/navigation_controller.h"
     16 #include "content/public/browser/web_contents.h"
     17 #include "content/public/test/test_navigation_observer.h"
     18 #include "net/test/spawned_test_server/spawned_test_server.h"
     19 
     20 using web_modal::WebContentsModalDialogManager;
     21 
     22 typedef InProcessBrowserTest RepostFormWarningTest;
     23 
     24 // If becomes flaky, disable on Windows and use http://crbug.com/47228
     25 IN_PROC_BROWSER_TEST_F(RepostFormWarningTest, TestDoubleReload) {
     26   ASSERT_TRUE(test_server()->Start());
     27 
     28   // Load a form.
     29   ui_test_utils::NavigateToURL(
     30       browser(), test_server()->GetURL("files/form.html"));
     31   // Submit it.
     32   ui_test_utils::NavigateToURL(
     33       browser(),
     34       GURL("javascript:document.getElementById('form').submit()"));
     35 
     36   // Try to reload it twice, checking for repost.
     37   content::WebContents* web_contents =
     38       browser()->tab_strip_model()->GetActiveWebContents();
     39   web_contents->GetController().Reload(true);
     40   web_contents->GetController().Reload(true);
     41 
     42   // There should only be one dialog open.
     43   WebContentsModalDialogManager* web_contents_modal_dialog_manager =
     44       WebContentsModalDialogManager::FromWebContents(web_contents);
     45   EXPECT_TRUE(web_contents_modal_dialog_manager->IsShowingDialog());
     46 
     47   // Navigate away from the page (this is when the test usually crashes).
     48   ui_test_utils::NavigateToURL(browser(), test_server()->GetURL("bar"));
     49 
     50   // The dialog should've been closed.
     51   EXPECT_FALSE(web_contents_modal_dialog_manager->IsShowingDialog());
     52 }
     53 
     54 // If becomes flaky, disable on Windows and use http://crbug.com/47228
     55 IN_PROC_BROWSER_TEST_F(RepostFormWarningTest, TestLoginAfterRepost) {
     56   ASSERT_TRUE(test_server()->Start());
     57 
     58   // Load a form.
     59   ui_test_utils::NavigateToURL(
     60       browser(), test_server()->GetURL("files/form.html"));
     61   // Submit it.
     62   ui_test_utils::NavigateToURL(
     63       browser(),
     64       GURL("javascript:document.getElementById('form').submit()"));
     65 
     66   // Try to reload it, checking for repost.
     67   content::WebContents* web_contents =
     68       browser()->tab_strip_model()->GetActiveWebContents();
     69   web_contents->GetController().Reload(true);
     70 
     71   // Navigate to a page that requires authentication, bringing up another
     72   // tab-modal sheet.
     73   content::NavigationController& controller = web_contents->GetController();
     74   content::WindowedNotificationObserver observer(
     75       chrome::NOTIFICATION_AUTH_NEEDED,
     76       content::Source<content::NavigationController>(&controller));
     77   browser()->OpenURL(content::OpenURLParams(
     78         test_server()->GetURL("auth-basic"), content::Referrer(), CURRENT_TAB,
     79         content::PAGE_TRANSITION_TYPED, false));
     80   observer.Wait();
     81 
     82   // Try to reload it again.
     83   web_contents->GetController().Reload(true);
     84 
     85   // Navigate away from the page. We can't use ui_test_utils:NavigateToURL
     86   // because that waits for the current page to stop loading first, which won't
     87   // happen while the auth dialog is up.
     88   content::TestNavigationObserver navigation_observer(web_contents);
     89   browser()->OpenURL(content::OpenURLParams(
     90         test_server()->GetURL("bar"), content::Referrer(), CURRENT_TAB,
     91         content::PAGE_TRANSITION_TYPED, false));
     92   navigation_observer.Wait();
     93 }
     94