blob: ff0be0d1aeeded81141cc8995d85baf1fc69393a [file] [log] [blame]
[email protected]5973b962012-04-09 21:17:181// 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"
[email protected]fdf40f3e2013-07-11 23:55:466#include "chrome/browser/chrome_notification_types.h"
[email protected]5973b962012-04-09 21:17:187#include "chrome/browser/ui/browser.h"
[email protected]cc872372013-01-28 21:57:078#include "chrome/browser/ui/tabs/tab_strip_model.h"
[email protected]4f3b4462013-07-27 19:20:189#include "chrome/common/net/url_fixer_upper.h"
[email protected]5973b962012-04-09 21:17:1810#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"
[email protected]e41d0082013-05-16 04:37:5414#include "components/web_modal/web_contents_modal_dialog_manager.h"
[email protected]5973b962012-04-09 21:17:1815#include "content/public/browser/navigation_controller.h"
16#include "content/public/browser/web_contents.h"
[email protected]5b8ff1c2012-06-02 20:42:2017#include "content/public/test/test_navigation_observer.h"
[email protected]89b32522013-05-07 20:04:2118#include "net/test/spawned_test_server/spawned_test_server.h"
[email protected]5973b962012-04-09 21:17:1819
[email protected]e41d0082013-05-16 04:37:5420using web_modal::WebContentsModalDialogManager;
21
[email protected]5973b962012-04-09 21:17:1822typedef InProcessBrowserTest RepostFormWarningTest;
23
24// If becomes flaky, disable on Windows and use http://crbug.com/47228
25IN_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.
[email protected]cc872372013-01-28 21:57:0737 content::WebContents* web_contents =
38 browser()->tab_strip_model()->GetActiveWebContents();
[email protected]5973b962012-04-09 21:17:1839 web_contents->GetController().Reload(true);
40 web_contents->GetController().Reload(true);
41
42 // There should only be one dialog open.
[email protected]6473adc042013-01-12 16:56:4143 WebContentsModalDialogManager* web_contents_modal_dialog_manager =
[email protected]d2b16572013-01-03 00:41:5844 WebContentsModalDialogManager::FromWebContents(web_contents);
[email protected]93a38c4e2013-09-10 17:19:1245 EXPECT_TRUE(web_contents_modal_dialog_manager->IsDialogActive());
[email protected]5973b962012-04-09 21:17:1846
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.
[email protected]93a38c4e2013-09-10 17:19:1251 EXPECT_FALSE(web_contents_modal_dialog_manager->IsDialogActive());
[email protected]5973b962012-04-09 21:17:1852}
53
54// If becomes flaky, disable on Windows and use http://crbug.com/47228
55IN_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.
[email protected]cc872372013-01-28 21:57:0767 content::WebContents* web_contents =
68 browser()->tab_strip_model()->GetActiveWebContents();
[email protected]5973b962012-04-09 21:17:1869 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();
[email protected]a7fe9112012-07-20 02:34:4574 content::WindowedNotificationObserver observer(
[email protected]5973b962012-04-09 21:17:1875 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.
[email protected]cbb1ef592013-06-05 19:49:4688 content::TestNavigationObserver navigation_observer(web_contents);
[email protected]5973b962012-04-09 21:17:1889 browser()->OpenURL(content::OpenURLParams(
90 test_server()->GetURL("bar"), content::Referrer(), CURRENT_TAB,
91 content::PAGE_TRANSITION_TYPED, false));
92 navigation_observer.Wait();
93}