[email protected] | 5973b96 | 2012-04-09 21:17:18 | [diff] [blame] | 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" |
[email protected] | fdf40f3e | 2013-07-11 23:55:46 | [diff] [blame] | 6 | #include "chrome/browser/chrome_notification_types.h" |
[email protected] | 5973b96 | 2012-04-09 21:17:18 | [diff] [blame] | 7 | #include "chrome/browser/ui/browser.h" |
[email protected] | cc87237 | 2013-01-28 21:57:07 | [diff] [blame] | 8 | #include "chrome/browser/ui/tabs/tab_strip_model.h" |
[email protected] | 4f3b446 | 2013-07-27 19:20:18 | [diff] [blame] | 9 | #include "chrome/common/net/url_fixer_upper.h" |
[email protected] | 5973b96 | 2012-04-09 21:17:18 | [diff] [blame] | 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" |
[email protected] | e41d008 | 2013-05-16 04:37:54 | [diff] [blame] | 14 | #include "components/web_modal/web_contents_modal_dialog_manager.h" |
[email protected] | 5973b96 | 2012-04-09 21:17:18 | [diff] [blame] | 15 | #include "content/public/browser/navigation_controller.h" |
| 16 | #include "content/public/browser/web_contents.h" |
[email protected] | 5b8ff1c | 2012-06-02 20:42:20 | [diff] [blame] | 17 | #include "content/public/test/test_navigation_observer.h" |
[email protected] | 89b3252 | 2013-05-07 20:04:21 | [diff] [blame] | 18 | #include "net/test/spawned_test_server/spawned_test_server.h" |
[email protected] | 5973b96 | 2012-04-09 21:17:18 | [diff] [blame] | 19 | |
[email protected] | e41d008 | 2013-05-16 04:37:54 | [diff] [blame] | 20 | using web_modal::WebContentsModalDialogManager; |
| 21 | |
[email protected] | 5973b96 | 2012-04-09 21:17:18 | [diff] [blame] | 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. |
[email protected] | cc87237 | 2013-01-28 21:57:07 | [diff] [blame] | 37 | content::WebContents* web_contents = |
| 38 | browser()->tab_strip_model()->GetActiveWebContents(); |
[email protected] | 5973b96 | 2012-04-09 21:17:18 | [diff] [blame] | 39 | web_contents->GetController().Reload(true); |
| 40 | web_contents->GetController().Reload(true); |
| 41 | |
| 42 | // There should only be one dialog open. |
[email protected] | 6473adc04 | 2013-01-12 16:56:41 | [diff] [blame] | 43 | WebContentsModalDialogManager* web_contents_modal_dialog_manager = |
[email protected] | d2b1657 | 2013-01-03 00:41:58 | [diff] [blame] | 44 | WebContentsModalDialogManager::FromWebContents(web_contents); |
[email protected] | 93a38c4e | 2013-09-10 17:19:12 | [diff] [blame] | 45 | EXPECT_TRUE(web_contents_modal_dialog_manager->IsDialogActive()); |
[email protected] | 5973b96 | 2012-04-09 21:17:18 | [diff] [blame] | 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. |
[email protected] | 93a38c4e | 2013-09-10 17:19:12 | [diff] [blame] | 51 | EXPECT_FALSE(web_contents_modal_dialog_manager->IsDialogActive()); |
[email protected] | 5973b96 | 2012-04-09 21:17:18 | [diff] [blame] | 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. |
[email protected] | cc87237 | 2013-01-28 21:57:07 | [diff] [blame] | 67 | content::WebContents* web_contents = |
| 68 | browser()->tab_strip_model()->GetActiveWebContents(); |
[email protected] | 5973b96 | 2012-04-09 21:17:18 | [diff] [blame] | 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(); |
[email protected] | a7fe911 | 2012-07-20 02:34:45 | [diff] [blame] | 74 | content::WindowedNotificationObserver observer( |
[email protected] | 5973b96 | 2012-04-09 21:17:18 | [diff] [blame] | 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. |
[email protected] | cbb1ef59 | 2013-06-05 19:49:46 | [diff] [blame] | 88 | content::TestNavigationObserver navigation_observer(web_contents); |
[email protected] | 5973b96 | 2012-04-09 21:17:18 | [diff] [blame] | 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 | } |