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