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