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