1// Copyright (c) 2010 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 <string> 6 7#include "chrome/app/chrome_command_ids.h" 8#include "chrome/browser/net/url_fixer_upper.h" 9#include "chrome/common/url_constants.h" 10#include "chrome/test/automation/tab_proxy.h" 11#include "chrome/test/automation/browser_proxy.h" 12#include "chrome/test/ui/ui_test.h" 13#include "net/test/test_server.h" 14 15namespace { 16 17const FilePath::CharType kDocRoot[] = FILE_PATH_LITERAL("chrome/test/data"); 18 19} // namespace 20 21typedef UITest RepostFormWarningTest; 22 23#if defined(OS_WIN) 24// http://crbug.com/47228 25#define MAYBE_TestDoubleReload FLAKY_TestDoubleReload 26#else 27#define MAYBE_TestDoubleReload TestDoubleReload 28#endif 29 30TEST_F(RepostFormWarningTest, MAYBE_TestDoubleReload) { 31 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath(kDocRoot)); 32 ASSERT_TRUE(test_server.Start()); 33 34 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); 35 ASSERT_TRUE(browser.get()); 36 37 scoped_refptr<TabProxy> tab(browser->GetTab(0)); 38 ASSERT_TRUE(tab.get()); 39 40 // Load a form. 41 ASSERT_TRUE(tab->NavigateToURL(test_server.GetURL("files/form.html"))); 42 // Submit it. 43 ASSERT_TRUE(tab->NavigateToURL(GURL( 44 "javascript:document.getElementById('form').submit()"))); 45 46 // Try to reload it twice, checking for repost. 47 tab->ReloadAsync(); 48 tab->ReloadAsync(); 49 50 // Navigate away from the page (this is when the test usually crashes). 51 ASSERT_TRUE(tab->NavigateToURL(test_server.GetURL("bar"))); 52} 53 54#if defined(OS_WIN) 55// http://crbug.com/47228 56#define MAYBE_TestLoginAfterRepost FLAKY_TestLoginAfterRepost 57#else 58#define MAYBE_TestLoginAfterRepost TestLoginAfterRepost 59#endif 60 61TEST_F(RepostFormWarningTest, MAYBE_TestLoginAfterRepost) { 62 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath(kDocRoot)); 63 ASSERT_TRUE(test_server.Start()); 64 65 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); 66 ASSERT_TRUE(browser.get()); 67 68 scoped_refptr<TabProxy> tab(browser->GetTab(0)); 69 ASSERT_TRUE(tab.get()); 70 71 // Load a form. 72 ASSERT_TRUE(tab->NavigateToURL(test_server.GetURL("files/form.html"))); 73 // Submit it. 74 ASSERT_TRUE(tab->NavigateToURL(GURL( 75 "javascript:document.getElementById('form').submit()"))); 76 77 // Try to reload it, checking for repost. 78 tab->ReloadAsync(); 79 80 // Navigate to a page that requires authentication, bringing up another 81 // tab-modal sheet. 82 ASSERT_TRUE(tab->NavigateToURL(test_server.GetURL("auth-basic"))); 83 84 // Try to reload it again. 85 tab->ReloadAsync(); 86 87 // Navigate away from the page. 88 ASSERT_TRUE(tab->NavigateToURL(test_server.GetURL("bar"))); 89} 90