summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormaruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-19 15:38:12 +0000
committermaruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-19 15:38:12 +0000
commitf334f8d30107123ed660c88d9271ed1404b96785 (patch)
tree93e5528922a8d639d01a5e188ca26971b98a25e9
parent7a2d4971bfdcf80d55ae574412c283c9409a491a (diff)
downloadchromium_src-f334f8d30107123ed660c88d9271ed1404b96785.zip
chromium_src-f334f8d30107123ed660c88d9271ed1404b96785.tar.gz
chromium_src-f334f8d30107123ed660c88d9271ed1404b96785.tar.bz2
Move tests that simulate mouse clicks to interactive_ui_tests
Created two new test files. Patch contributed by Charles Lee. Review URL: http://codereview.chromium.org/7569013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@97464 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/history/history_interactive_uitest.cc47
-rw-r--r--chrome/browser/history/history_uitest.cc (renamed from chrome/test/ui/history_uitest.cc)58
-rw-r--r--chrome/browser/history/history_uitest.h31
-rw-r--r--chrome/browser/unload_interactive_uitest.cc62
-rw-r--r--chrome/browser/unload_uitest.cc169
-rw-r--r--chrome/browser/unload_uitest.h98
-rw-r--r--chrome/chrome_tests.gypi5
7 files changed, 257 insertions, 213 deletions
diff --git a/chrome/browser/history/history_interactive_uitest.cc b/chrome/browser/history/history_interactive_uitest.cc
new file mode 100644
index 0000000..682ffb3
--- /dev/null
+++ b/chrome/browser/history/history_interactive_uitest.cc
@@ -0,0 +1,47 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// History interactive UI tests
+
+#include "chrome/browser/history/history_uitest.h"
+
+namespace {
+
+const char kTestCompleteCookie[] = "status";
+const char kTestCompleteSuccess[] = "OK";
+const FilePath::CharType* const kHistoryDir = FILE_PATH_LITERAL("History");
+
+} // namespace
+
+TEST_F(HistoryTester, ConsiderRedirectAfterGestureAsUserInitiated) {
+ // Test the history length for the following page transition.
+ //
+ // -open-> Page 11 -slow_redirect-> Page 12.
+ //
+ // If redirect occurs after a user gesture, e.g., mouse click, the
+ // redirect is more likely to be user-initiated rather than automatic.
+ // Therefore, Page 11 should be in the history in addition to Page 12.
+
+ const FilePath test_case(
+ FILE_PATH_LITERAL("history_length_test_page_11.html"));
+ GURL url = ui_test_utils::GetTestUrl(FilePath(kHistoryDir), test_case);
+ NavigateToURL(url);
+ WaitForFinish("History_Length_Test_11", "1", url, kTestCompleteCookie,
+ kTestCompleteSuccess, TestTimeouts::action_max_timeout_ms());
+
+ // Simulate click. This only works for Windows.
+ scoped_refptr<BrowserProxy> browser = automation()->GetBrowserWindow(0);
+ ASSERT_TRUE(browser.get());
+ scoped_refptr<WindowProxy> window = browser->GetWindow();
+ ASSERT_TRUE(window.get());
+ gfx::Rect tab_view_bounds;
+ ASSERT_TRUE(window->GetViewBounds(VIEW_ID_TAB_CONTAINER, &tab_view_bounds,
+ true));
+ ASSERT_TRUE(window->SimulateOSClick(tab_view_bounds.CenterPoint(),
+ ui::EF_LEFT_BUTTON_DOWN));
+
+ NavigateToURL(GURL("javascript:redirectToPage12()"));
+ WaitForFinish("History_Length_Test_12", "1", url, kTestCompleteCookie,
+ kTestCompleteSuccess, TestTimeouts::action_max_timeout_ms());
+}
diff --git a/chrome/test/ui/history_uitest.cc b/chrome/browser/history/history_uitest.cc
index ea08d20..aa0b59e1 100644
--- a/chrome/test/ui/history_uitest.cc
+++ b/chrome/browser/history/history_uitest.cc
@@ -4,36 +4,16 @@
// History UI tests
-#include "base/file_path.h"
-#include "base/test/test_timeouts.h"
-#include "chrome/browser/ui/view_ids.h"
-#include "chrome/test/automation/automation_proxy.h"
-#include "chrome/test/automation/browser_proxy.h"
-#include "chrome/test/automation/tab_proxy.h"
-#include "chrome/test/automation/window_proxy.h"
-#include "chrome/test/base/ui_test_utils.h"
-#include "chrome/test/ui/ui_test.h"
-#include "ui/base/events.h"
-#include "ui/gfx/rect.h"
+#include "chrome/browser/history/history_uitest.h"
namespace {
const char kTestCompleteCookie[] = "status";
const char kTestCompleteSuccess[] = "OK";
-const FilePath::CharType* kHistoryDir = FILE_PATH_LITERAL("History");
+const FilePath::CharType* const kHistoryDir = FILE_PATH_LITERAL("History");
} // namespace
-class HistoryTester : public UITest {
- protected:
- HistoryTester() : UITest() { }
-
- virtual void SetUp() {
- show_window_ = true;
- UITest::SetUp();
- }
-};
-
TEST_F(HistoryTester, VerifyHistoryLength1) {
// Test the history length for the following page transitions.
// -open-> Page 1.
@@ -85,40 +65,6 @@ TEST_F(HistoryTester, VerifyHistoryLength3) {
kTestCompleteSuccess, TestTimeouts::action_max_timeout_ms());
}
-#if !defined(OS_MACOSX)
-TEST_F(HistoryTester, ConsiderRedirectAfterGestureAsUserInitiated) {
- // Test the history length for the following page transition.
- //
- // -open-> Page 11 -slow_redirect-> Page 12.
- //
- // If redirect occurs after a user gesture, e.g., mouse click, the
- // redirect is more likely to be user-initiated rather than automatic.
- // Therefore, Page 11 should be in the history in addition to Page 12.
-
- const FilePath test_case(
- FILE_PATH_LITERAL("history_length_test_page_11.html"));
- GURL url = ui_test_utils::GetTestUrl(FilePath(kHistoryDir), test_case);
- NavigateToURL(url);
- WaitForFinish("History_Length_Test_11", "1", url, kTestCompleteCookie,
- kTestCompleteSuccess, TestTimeouts::action_max_timeout_ms());
-
- // Simulate click. This only works for Windows.
- scoped_refptr<BrowserProxy> browser = automation()->GetBrowserWindow(0);
- ASSERT_TRUE(browser.get());
- scoped_refptr<WindowProxy> window = browser->GetWindow();
- ASSERT_TRUE(window.get());
- gfx::Rect tab_view_bounds;
- ASSERT_TRUE(window->GetViewBounds(VIEW_ID_TAB_CONTAINER, &tab_view_bounds,
- true));
- ASSERT_TRUE(window->SimulateOSClick(tab_view_bounds.CenterPoint(),
- ui::EF_LEFT_BUTTON_DOWN));
-
- NavigateToURL(GURL("javascript:redirectToPage12()"));
- WaitForFinish("History_Length_Test_12", "1", url, kTestCompleteCookie,
- kTestCompleteSuccess, TestTimeouts::action_max_timeout_ms());
-}
-#endif // !defined(OS_MACOSX)
-
TEST_F(HistoryTester, ConsiderSlowRedirectAsUserInitiated) {
// Test the history length for the following page transition.
//
diff --git a/chrome/browser/history/history_uitest.h b/chrome/browser/history/history_uitest.h
new file mode 100644
index 0000000..8bdb09ee
--- /dev/null
+++ b/chrome/browser/history/history_uitest.h
@@ -0,0 +1,31 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_HISTORY_HISTORY_UITEST_H_
+#define CHROME_BROWSER_HISTORY_HISTORY_UITEST_H_
+#pragma once
+
+#include "base/file_path.h"
+#include "base/test/test_timeouts.h"
+#include "chrome/browser/ui/view_ids.h"
+#include "chrome/test/automation/automation_proxy.h"
+#include "chrome/test/automation/browser_proxy.h"
+#include "chrome/test/automation/tab_proxy.h"
+#include "chrome/test/automation/window_proxy.h"
+#include "chrome/test/base/ui_test_utils.h"
+#include "chrome/test/ui/ui_test.h"
+#include "ui/base/events.h"
+#include "ui/gfx/rect.h"
+
+class HistoryTester : public UITest {
+ protected:
+ HistoryTester() : UITest() { }
+
+ virtual void SetUp() {
+ show_window_ = true;
+ UITest::SetUp();
+ }
+};
+
+#endif // CHROME_BROWSER_HISTORY_HISTORY_UITEST_H_
diff --git a/chrome/browser/unload_interactive_uitest.cc b/chrome/browser/unload_interactive_uitest.cc
new file mode 100644
index 0000000..79a8412
--- /dev/null
+++ b/chrome/browser/unload_interactive_uitest.cc
@@ -0,0 +1,62 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/unload_uitest.h"
+
+const char CLOSE_TAB_WHEN_OTHER_TAB_HAS_LISTENER[] =
+ "<html><head><title>only_one_unload</title></head>"
+ "<body onclick=\"window.open('data:text/html,"
+ "<html><head><title>popup</title></head></body>')\" "
+ "onbeforeunload='return;'>"
+ "</body></html>";
+
+#if defined(OS_MACOSX)
+// http://crbug.com/45162
+#define MAYBE_BrowserCloseTabWhenOtherTabHasListener \
+ DISABLED_BrowserCloseTabWhenOtherTabHasListener
+#elif defined(OS_WIN)
+// http://crbug.com/45281
+#define MAYBE_BrowserCloseTabWhenOtherTabHasListener \
+ DISABLED_BrowserCloseTabWhenOtherTabHasListener
+#elif defined(OS_CHROMEOS)
+// http://crbug.com/86769
+#define MAYBE_BrowserCloseTabWhenOtherTabHasListener \
+ FLAKY_BrowserCloseTabWhenOtherTabHasListener
+#else
+#define MAYBE_BrowserCloseTabWhenOtherTabHasListener \
+ BrowserCloseTabWhenOtherTabHasListener
+#endif
+
+// Tests that if there's a renderer process with two tabs, one of which has an
+// unload handler, and the other doesn't, the tab that doesn't have an unload
+// handler can be closed.
+TEST_F(UnloadTest, MAYBE_BrowserCloseTabWhenOtherTabHasListener) {
+ NavigateToDataURL(CLOSE_TAB_WHEN_OTHER_TAB_HAS_LISTENER, L"only_one_unload");
+
+ scoped_refptr<BrowserProxy> browser = automation()->GetBrowserWindow(0);
+ ASSERT_TRUE(browser.get());
+ scoped_refptr<WindowProxy> window = browser->GetWindow();
+ ASSERT_TRUE(window.get());
+
+ gfx::Rect tab_view_bounds;
+ ASSERT_TRUE(window->GetViewBounds(VIEW_ID_TAB_CONTAINER,
+ &tab_view_bounds, true));
+ // Simulate a click to force user_gesture to true; if we don't, the resulting
+ // popup will be constrained, which isn't what we want to test.
+ ASSERT_TRUE(window->SimulateOSClick(tab_view_bounds.CenterPoint(),
+ ui::EF_LEFT_BUTTON_DOWN));
+ ASSERT_TRUE(browser->WaitForTabCountToBecome(2));
+
+ CheckTitle(L"popup");
+ scoped_refptr<TabProxy> popup_tab(browser->GetActiveTab());
+ ASSERT_TRUE(popup_tab.get());
+ EXPECT_TRUE(popup_tab->Close(true));
+
+ ASSERT_TRUE(browser->WaitForTabCountToBecome(1));
+ scoped_refptr<TabProxy> main_tab(browser->GetActiveTab());
+ ASSERT_TRUE(main_tab.get());
+ std::wstring main_title;
+ EXPECT_TRUE(main_tab->GetTabTitle(&main_title));
+ EXPECT_EQ(std::wstring(L"only_one_unload"), main_title);
+}
diff --git a/chrome/browser/unload_uitest.cc b/chrome/browser/unload_uitest.cc
index 95e869b..11348b2 100644
--- a/chrome/browser/unload_uitest.cc
+++ b/chrome/browser/unload_uitest.cc
@@ -2,33 +2,21 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "base/file_util.h"
-#include "base/test/test_timeouts.h"
-#include "chrome/browser/ui/view_ids.h"
-#include "chrome/common/chrome_switches.h"
-#include "chrome/test/automation/automation_proxy.h"
-#include "chrome/test/automation/browser_proxy.h"
-#include "chrome/test/automation/tab_proxy.h"
-#include "chrome/test/automation/window_proxy.h"
-#include "chrome/test/ui/ui_test.h"
-#include "content/browser/net/url_request_mock_http_job.h"
-#include "net/url_request/url_request_test_util.h"
-#include "ui/base/events.h"
-#include "ui/base/message_box_flags.h"
-
-const std::string NOLISTENERS_HTML =
+#include "chrome/browser/unload_uitest.h"
+
+const char NOLISTENERS_HTML[] =
"<html><head><title>nolisteners</title></head><body></body></html>";
-const std::string UNLOAD_HTML =
+const char UNLOAD_HTML[] =
"<html><head><title>unload</title></head><body>"
"<script>window.onunload=function(e){}</script></body></html>";
-const std::string BEFORE_UNLOAD_HTML =
+const char BEFORE_UNLOAD_HTML[] =
"<html><head><title>beforeunload</title></head><body>"
"<script>window.onbeforeunload=function(e){return 'foo'}</script>"
"</body></html>";
-const std::string INNER_FRAME_WITH_FOCUS_HTML =
+const char INNER_FRAME_WITH_FOCUS_HTML[] =
"<html><head><title>innerframewithfocus</title></head><body>"
"<script>window.onbeforeunload=function(e){return 'foo'}</script>"
"<iframe src=\"data:text/html,<html><head><script>window.onload="
@@ -36,7 +24,7 @@ const std::string INNER_FRAME_WITH_FOCUS_HTML =
"<body><input id='box'></input></body></html>\"></iframe>"
"</body></html>";
-const std::string TWO_SECOND_BEFORE_UNLOAD_HTML =
+const char TWO_SECOND_BEFORE_UNLOAD_HTML[] =
"<html><head><title>twosecondbeforeunload</title></head><body>"
"<script>window.onbeforeunload=function(e){"
"var start = new Date().getTime();"
@@ -44,31 +32,31 @@ const std::string TWO_SECOND_BEFORE_UNLOAD_HTML =
"return 'foo';"
"}</script></body></html>";
-const std::string INFINITE_UNLOAD_HTML =
+const char INFINITE_UNLOAD_HTML[] =
"<html><head><title>infiniteunload</title></head><body>"
"<script>window.onunload=function(e){while(true){}}</script>"
"</body></html>";
-const std::string INFINITE_BEFORE_UNLOAD_HTML =
+const char INFINITE_BEFORE_UNLOAD_HTML[] =
"<html><head><title>infinitebeforeunload</title></head><body>"
"<script>window.onbeforeunload=function(e){while(true){}}</script>"
"</body></html>";
-const std::string INFINITE_UNLOAD_ALERT_HTML =
+const char INFINITE_UNLOAD_ALERT_HTML[] =
"<html><head><title>infiniteunloadalert</title></head><body>"
"<script>window.onunload=function(e){"
"while(true){}"
"alert('foo');"
"}</script></body></html>";
-const std::string INFINITE_BEFORE_UNLOAD_ALERT_HTML =
+const char INFINITE_BEFORE_UNLOAD_ALERT_HTML[] =
"<html><head><title>infinitebeforeunloadalert</title></head><body>"
"<script>window.onbeforeunload=function(e){"
"while(true){}"
"alert('foo');"
"}</script></body></html>";
-const std::string TWO_SECOND_UNLOAD_ALERT_HTML =
+const char TWO_SECOND_UNLOAD_ALERT_HTML[] =
"<html><head><title>twosecondunloadalert</title></head><body>"
"<script>window.onunload=function(e){"
"var start = new Date().getTime();"
@@ -76,7 +64,7 @@ const std::string TWO_SECOND_UNLOAD_ALERT_HTML =
"alert('foo');"
"}</script></body></html>";
-const std::string TWO_SECOND_BEFORE_UNLOAD_ALERT_HTML =
+const char TWO_SECOND_BEFORE_UNLOAD_ALERT_HTML[] =
"<html><head><title>twosecondbeforeunloadalert</title></head><body>"
"<script>window.onbeforeunload=function(e){"
"var start = new Date().getTime();"
@@ -84,87 +72,6 @@ const std::string TWO_SECOND_BEFORE_UNLOAD_ALERT_HTML =
"alert('foo');"
"}</script></body></html>";
-const std::string CLOSE_TAB_WHEN_OTHER_TAB_HAS_LISTENER =
- "<html><head><title>only_one_unload</title></head>"
- "<body onclick=\"window.open('data:text/html,"
- "<html><head><title>popup</title></head></body>')\" "
- "onbeforeunload='return;'>"
- "</body></html>";
-
-class UnloadTest : public UITest {
- public:
- virtual void SetUp() {
- const testing::TestInfo* const test_info =
- testing::UnitTest::GetInstance()->current_test_info();
- if (strcmp(test_info->name(),
- "BrowserCloseTabWhenOtherTabHasListener") == 0) {
- launch_arguments_.AppendSwitch(switches::kDisablePopupBlocking);
- }
-
- UITest::SetUp();
- }
-
- void CheckTitle(const std::wstring& expected_title) {
- const int kCheckDelayMs = 100;
- for (int max_wait_time = TestTimeouts::action_max_timeout_ms();
- max_wait_time > 0; max_wait_time -= kCheckDelayMs) {
- if (expected_title == GetActiveTabTitle())
- break;
- base::PlatformThread::Sleep(kCheckDelayMs);
- }
-
- EXPECT_EQ(expected_title, GetActiveTabTitle());
- }
-
- void NavigateToDataURL(const std::string& html_content,
- const std::wstring& expected_title) {
- NavigateToURL(GURL("data:text/html," + html_content));
- CheckTitle(expected_title);
- }
-
- void NavigateToNolistenersFileTwice() {
- NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(
- FilePath(FILE_PATH_LITERAL("title2.html"))));
- CheckTitle(L"Title Of Awesomeness");
- NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(
- FilePath(FILE_PATH_LITERAL("title2.html"))));
- CheckTitle(L"Title Of Awesomeness");
- }
-
- // Navigates to a URL asynchronously, then again synchronously. The first
- // load is purposely async to test the case where the user loads another
- // page without waiting for the first load to complete.
- void NavigateToNolistenersFileTwiceAsync() {
- NavigateToURLAsync(
- URLRequestMockHTTPJob::GetMockUrl(
- FilePath(FILE_PATH_LITERAL("title2.html"))));
- NavigateToURL(
- URLRequestMockHTTPJob::GetMockUrl(
- FilePath(FILE_PATH_LITERAL("title2.html"))));
-
- CheckTitle(L"Title Of Awesomeness");
- }
-
- void LoadUrlAndQuitBrowser(const std::string& html_content,
- const std::wstring& expected_title = L"") {
- scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
- ASSERT_TRUE(browser.get());
- NavigateToDataURL(html_content, expected_title);
- bool application_closed = false;
- EXPECT_TRUE(CloseBrowser(browser.get(), &application_closed));
- }
-
- void ClickModalDialogButton(ui::MessageBoxFlags::DialogButton button) {
- bool modal_dialog_showing = false;
- ui::MessageBoxFlags::DialogButton available_buttons;
- EXPECT_TRUE(automation()->WaitForAppModalDialog());
- EXPECT_TRUE(automation()->GetShowingAppModalDialog(&modal_dialog_showing,
- &available_buttons));
- ASSERT_TRUE(modal_dialog_showing);
- EXPECT_TRUE((button & available_buttons) != 0);
- EXPECT_TRUE(automation()->ClickAppModalDialogButton(button));
- }
-};
// Navigate to a page with an infinite unload handler.
// Then two async crosssite requests to ensure
@@ -420,55 +327,5 @@ TEST_F(UnloadTest, BrowserCloseTwoSecondBeforeUnloadAlert) {
L"twosecondbeforeunloadalert");
}
-#if defined(OS_MACOSX)
-// http://crbug.com/45162
-#define MAYBE_BrowserCloseTabWhenOtherTabHasListener \
- DISABLED_BrowserCloseTabWhenOtherTabHasListener
-#elif defined(OS_WIN)
-// http://crbug.com/45281
-#define MAYBE_BrowserCloseTabWhenOtherTabHasListener \
- DISABLED_BrowserCloseTabWhenOtherTabHasListener
-#elif defined(OS_CHROMEOS)
-// http://crbug.com/86769
-#define MAYBE_BrowserCloseTabWhenOtherTabHasListener \
- FLAKY_BrowserCloseTabWhenOtherTabHasListener
-#else
-#define MAYBE_BrowserCloseTabWhenOtherTabHasListener \
- BrowserCloseTabWhenOtherTabHasListener
-#endif
-
-// Tests that if there's a renderer process with two tabs, one of which has an
-// unload handler, and the other doesn't, the tab that doesn't have an unload
-// handler can be closed.
-TEST_F(UnloadTest, MAYBE_BrowserCloseTabWhenOtherTabHasListener) {
- NavigateToDataURL(CLOSE_TAB_WHEN_OTHER_TAB_HAS_LISTENER, L"only_one_unload");
-
- scoped_refptr<BrowserProxy> browser = automation()->GetBrowserWindow(0);
- ASSERT_TRUE(browser.get());
- scoped_refptr<WindowProxy> window = browser->GetWindow();
- ASSERT_TRUE(window.get());
-
- gfx::Rect tab_view_bounds;
- ASSERT_TRUE(window->GetViewBounds(VIEW_ID_TAB_CONTAINER,
- &tab_view_bounds, true));
- // Simulate a click to force user_gesture to true; if we don't, the resulting
- // popup will be constrained, which isn't what we want to test.
- ASSERT_TRUE(window->SimulateOSClick(tab_view_bounds.CenterPoint(),
- ui::EF_LEFT_BUTTON_DOWN));
- ASSERT_TRUE(browser->WaitForTabCountToBecome(2));
-
- CheckTitle(L"popup");
- scoped_refptr<TabProxy> popup_tab(browser->GetActiveTab());
- ASSERT_TRUE(popup_tab.get());
- EXPECT_TRUE(popup_tab->Close(true));
-
- ASSERT_TRUE(browser->WaitForTabCountToBecome(1));
- scoped_refptr<TabProxy> main_tab(browser->GetActiveTab());
- ASSERT_TRUE(main_tab.get());
- std::wstring main_title;
- EXPECT_TRUE(main_tab->GetTabTitle(&main_title));
- EXPECT_EQ(std::wstring(L"only_one_unload"), main_title);
-}
-
// TODO(ojan): Add tests for unload/beforeunload that have multiple tabs
// and multiple windows.
diff --git a/chrome/browser/unload_uitest.h b/chrome/browser/unload_uitest.h
new file mode 100644
index 0000000..63a4d61
--- /dev/null
+++ b/chrome/browser/unload_uitest.h
@@ -0,0 +1,98 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_UNLOAD_UITEST_H_
+#define CHROME_BROWSER_UNLOAD_UITEST_H_
+#pragma once
+
+#include "base/file_util.h"
+#include "base/test/test_timeouts.h"
+#include "chrome/browser/ui/view_ids.h"
+#include "chrome/common/chrome_switches.h"
+#include "chrome/test/automation/automation_proxy.h"
+#include "chrome/test/automation/browser_proxy.h"
+#include "chrome/test/automation/tab_proxy.h"
+#include "chrome/test/automation/window_proxy.h"
+#include "chrome/test/ui/ui_test.h"
+#include "content/browser/net/url_request_mock_http_job.h"
+#include "net/url_request/url_request_test_util.h"
+#include "ui/base/events.h"
+#include "ui/base/message_box_flags.h"
+
+class UnloadTest : public UITest {
+ public:
+ virtual void SetUp() {
+ const testing::TestInfo* const test_info =
+ testing::UnitTest::GetInstance()->current_test_info();
+ if (strcmp(test_info->name(),
+ "BrowserCloseTabWhenOtherTabHasListener") == 0) {
+ launch_arguments_.AppendSwitch(switches::kDisablePopupBlocking);
+ }
+
+ UITest::SetUp();
+ }
+
+ void CheckTitle(const std::wstring& expected_title) {
+ const int kCheckDelayMs = 100;
+ for (int max_wait_time = TestTimeouts::action_max_timeout_ms();
+ max_wait_time > 0; max_wait_time -= kCheckDelayMs) {
+ if (expected_title == GetActiveTabTitle())
+ break;
+ base::PlatformThread::Sleep(kCheckDelayMs);
+ }
+
+ EXPECT_EQ(expected_title, GetActiveTabTitle());
+ }
+
+ void NavigateToDataURL(const std::string& html_content,
+ const std::wstring& expected_title) {
+ NavigateToURL(GURL("data:text/html," + html_content));
+ CheckTitle(expected_title);
+ }
+
+ void NavigateToNolistenersFileTwice() {
+ NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(
+ FilePath(FILE_PATH_LITERAL("title2.html"))));
+ CheckTitle(L"Title Of Awesomeness");
+ NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(
+ FilePath(FILE_PATH_LITERAL("title2.html"))));
+ CheckTitle(L"Title Of Awesomeness");
+ }
+
+ // Navigates to a URL asynchronously, then again synchronously. The first
+ // load is purposely async to test the case where the user loads another
+ // page without waiting for the first load to complete.
+ void NavigateToNolistenersFileTwiceAsync() {
+ NavigateToURLAsync(
+ URLRequestMockHTTPJob::GetMockUrl(
+ FilePath(FILE_PATH_LITERAL("title2.html"))));
+ NavigateToURL(
+ URLRequestMockHTTPJob::GetMockUrl(
+ FilePath(FILE_PATH_LITERAL("title2.html"))));
+
+ CheckTitle(L"Title Of Awesomeness");
+ }
+
+ void LoadUrlAndQuitBrowser(const std::string& html_content,
+ const std::wstring& expected_title = L"") {
+ scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
+ ASSERT_TRUE(browser.get());
+ NavigateToDataURL(html_content, expected_title);
+ bool application_closed = false;
+ EXPECT_TRUE(CloseBrowser(browser.get(), &application_closed));
+ }
+
+ void ClickModalDialogButton(ui::MessageBoxFlags::DialogButton button) {
+ bool modal_dialog_showing = false;
+ ui::MessageBoxFlags::DialogButton available_buttons;
+ EXPECT_TRUE(automation()->WaitForAppModalDialog());
+ EXPECT_TRUE(automation()->GetShowingAppModalDialog(&modal_dialog_showing,
+ &available_buttons));
+ ASSERT_TRUE(modal_dialog_showing);
+ EXPECT_TRUE((button & available_buttons) != 0);
+ EXPECT_TRUE(automation()->ClickAppModalDialogButton(button));
+ }
+};
+
+#endif // CHROME_BROWSER_UNLOAD_UITEST_H_
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index 5aaf31f..21e2fe5 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -503,6 +503,7 @@
'browser/browser_keyevents_browsertest.cc',
'browser/collected_cookies_uitest.cc',
'browser/debugger/devtools_sanity_unittest.cc',
+ 'browser/history/history_interactive_uitest.cc',
'browser/instant/instant_browsertest.cc',
'browser/keyboard_access_uitest.cc',
'browser/mouseleave_interactive_uitest.cc',
@@ -519,6 +520,7 @@
'browser/ui/views/ssl_client_certificate_selector_browsertest.cc',
'browser/ui/views/tabs/tab_dragging_test.cc',
'browser/ui/webui/workers_ui_browsertest.cc',
+ 'browser/unload_interactive_uitest.cc',
'test/base/out_of_proc_test_runner.cc',
'test/base/view_event_test_base.cc',
'test/base/view_event_test_base.h',
@@ -563,6 +565,7 @@
['OS=="mac"', {
'sources!': [
# TODO(port)
+ 'browser/history/history_interactive_uitest.cc',
'browser/npapi_interactive_test.cc',
'browser/ui/views/bookmarks/bookmark_bar_view_test.cc',
'browser/ui/views/button_dropdown_test.cc',
@@ -693,6 +696,7 @@
'browser/default_plugin_uitest.cc',
'browser/fast_shutdown_uitest.cc',
'browser/gpu_uitest.cc',
+ 'browser/history/history_uitest.cc',
'browser/history/multipart_uitest.cc',
'browser/history/redirect_uitest.cc',
'browser/iframe_uitest.cc',
@@ -726,7 +730,6 @@
'test/automation/extension_proxy_uitest.cc',
'test/automated_ui_tests/automated_ui_test_test.cc',
'test/base/chrome_process_util_uitest.cc',
- 'test/ui/history_uitest.cc',
'test/ui/layout_plugin_uitest.cc',
'test/ui/named_interface_uitest.cc',
'test/ui/npapi_uitest.cc',