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