summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorojan@google.com <ojan@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-11 23:03:32 +0000
committerojan@google.com <ojan@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-11 23:03:32 +0000
commit51afbeda5420a5ffe4b2481181450388ea019975 (patch)
treedb6effb2b158b75f6af7995a8aab57e7a30efa7c /chrome
parent0a0ed3fed8087979a870721eced93aeca5ddbe28 (diff)
downloadchromium_src-51afbeda5420a5ffe4b2481181450388ea019975.zip
chromium_src-51afbeda5420a5ffe4b2481181450388ea019975.tar.gz
chromium_src-51afbeda5420a5ffe4b2481181450388ea019975.tar.bz2
Move to using data URLs for unload tests and generally
cleanup the unload tests in preparation for adding in tests for beforeunload. Review URL: http://codereview.chromium.org/14017 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6839 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/browser_uitest.cc47
-rw-r--r--chrome/browser/unload_uitest.cc123
-rw-r--r--chrome/test/data/unload/beforeunloadlooping.html12
-rw-r--r--chrome/test/data/unload/nolisteners.html7
-rw-r--r--chrome/test/data/unload/unload.html11
-rw-r--r--chrome/test/data/unload/unloadlooping.html12
-rw-r--r--chrome/test/data/unload/unloadloopingalert.html13
-rw-r--r--chrome/test/data/unload/unloadloopingtwosecondsalert.html14
8 files changed, 95 insertions, 144 deletions
diff --git a/chrome/browser/browser_uitest.cc b/chrome/browser/browser_uitest.cc
index 740b2ea..e6a5033e 100644
--- a/chrome/browser/browser_uitest.cc
+++ b/chrome/browser/browser_uitest.cc
@@ -47,20 +47,6 @@ class BrowserTest : public UITest {
::GetWindowText(window_handle, WriteInto(&result, length), length);
return result;
}
-
- void LoadUnloadPageAndQuitBrowser(const std::wstring& test_filename) {
- scoped_ptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
-
- std::wstring test_file = test_data_directory_;
- file_util::AppendToPath(&test_file, L"unload");
- file_util::AppendToPath(&test_file, test_filename);
-
- NavigateToURL(net::FilePathToFileURL(test_file));
- Sleep(kWaitForActionMsec);
-
- bool application_closed = false;
- EXPECT_TRUE(CloseBrowser(browser.get(), &application_closed));
- }
};
class VisibleBrowserTest : public UITest {
@@ -99,39 +85,6 @@ TEST_F(BrowserTest, Title) {
EXPECT_EQ(test_title, GetActiveTabTitle());
}
-// Tests closing the browser on a page with no unload listeners registered.
-TEST_F(BrowserTest, BrowserCloseNoUnloadListeners) {
- LoadUnloadPageAndQuitBrowser(L"nolisteners.html");
-}
-
-// Tests closing the browser on a page with an unload listener registered.
-TEST_F(BrowserTest, BrowserCloseUnload) {
- LoadUnloadPageAndQuitBrowser(L"unload.html");
-}
-
-// Tests closing the browser on a page with an unload listener registered where
-// the unload handler has an infinite loop.
-TEST_F(BrowserTest, BrowserCloseUnloadLooping) {
- LoadUnloadPageAndQuitBrowser(L"unloadlooping.html");
-}
-
-// Tests closing the browser on a page with an unload listener registered where
-// the unload handler has an infinite loop followed by an alert.
-TEST_F(BrowserTest, BrowserCloseUnloadLoopingAlert) {
- LoadUnloadPageAndQuitBrowser(L"unloadloopingalert.html");
-}
-
-// Tests closing the browser on a page with an unload listener registered where
-// the unload handler has an 2 second long loop followed by an alert.
-TEST_F(BrowserTest, BrowserCloseUnloadLoopingTwoSecondsAlert) {
- LoadUnloadPageAndQuitBrowser(L"unloadloopingtwosecondsalert.html");
-}
-
-// TODO(ojan): Test popping up an alert in the unload handler and test
-// beforeunload. In addition add tests where we open all of these pages
-// in the browser and then close it, as well as having two windows and
-// closing only one of them.
-
// The browser should quit quickly if it receives a WM_ENDSESSION message.
TEST_F(BrowserTest, WindowsSessionEnd) {
std::wstring test_file = test_data_directory_;
diff --git a/chrome/browser/unload_uitest.cc b/chrome/browser/unload_uitest.cc
index cf7be84..9db22f3 100644
--- a/chrome/browser/unload_uitest.cc
+++ b/chrome/browser/unload_uitest.cc
@@ -10,6 +10,38 @@
#include "chrome/test/ui/ui_test.h"
#include "net/url_request/url_request_unittest.h"
+const std::string NOLISTENERS_HTML =
+ "<html><head><title>nolisteners</title></head><body></body></html>";
+
+const std::string UNLOAD_HTML =
+ "<html><head><title>unload</title></head><body>"
+ "<script>window.onunload=function(e){}</script></body></html>";
+
+const std::string 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 =
+ "<html><head><title>infinitebeforeunload</title></head><body>"
+ "<script>window.onunload=function(e){while(true){}}</script>"
+ "</body></html>";
+
+const std::string 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 TWO_SECOND_UNLOAD_ALERT_HTML =
+ "<html><head><title>twosecondunloadalert</title></head><body>"
+ "<script>window.onunload=function(e){"
+ "var start = new Date().getTime();"
+ "while(new Date().getTime() - start < 2000) {}"
+ "alert('foo');"
+ "}</script></body></html>";
+
class UnloadTest : public UITest {
public:
void CheckTitle(const std::wstring& expected_title) {
@@ -25,27 +57,19 @@ class UnloadTest : public UITest {
EXPECT_EQ(expected_title, GetActiveTabTitle());
}
- void NavigateToUnloadFileUsingTestServer(const std::wstring& test_filename,
- const std::wstring& expected_title) {
- const wchar_t kDocRoot[] = L"chrome/test/data";
- TestServer server(kDocRoot);
-
- std::wstring test_file = L"files/unload/";
- file_util::AppendToPath(&test_file, test_filename);
-
- GURL url(server.TestServerPageW(test_file));
- NavigateToURL(url);
-
+ 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(L"unload/nolisteners.html"));
- CheckTitle(L"nolisteners");
- NavigateToURL(
- URLRequestMockHTTPJob::GetMockUrl(L"unload/nolisteners.html"));
- CheckTitle(L"nolisteners");
+ NavigateToURL(
+ URLRequestMockHTTPJob::GetMockUrl(L"title2.html"));
+ CheckTitle(L"Title Of Awesomeness");
+ NavigateToURL(
+ URLRequestMockHTTPJob::GetMockUrl(L"title2.html"));
+ CheckTitle(L"Title Of Awesomeness");
}
// Navigates to a URL asynchronously, then again synchronously. The first
@@ -55,13 +79,21 @@ class UnloadTest : public UITest {
// TODO(ojan): We hit a DCHECK in RenderViewHost::OnMsgShouldCloseACK
// if we don't sleep here.
Sleep(400);
- NavigateToURLAsync(
- URLRequestMockHTTPJob::GetMockUrl(L"unload/nolisteners.html"));
+ NavigateToURLAsync(
+ URLRequestMockHTTPJob::GetMockUrl(L"title2.html"));
Sleep(400);
- NavigateToURL(
- URLRequestMockHTTPJob::GetMockUrl(L"unload/nolisteners.html"));
+ NavigateToURLAsync(
+ URLRequestMockHTTPJob::GetMockUrl(L"title2.html"));
- CheckTitle(L"nolisteners");
+ CheckTitle(L"Title Of Awesomeness");
+ }
+
+ void LoadUrlAndQuitBrowser(const std::string& html_content,
+ const std::wstring& expected_title = L"") {
+ scoped_ptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
+ NavigateToDataURL(html_content, expected_title);
+ bool application_closed = false;
+ EXPECT_TRUE(CloseBrowser(browser.get(), &application_closed));
}
};
@@ -73,7 +105,8 @@ TEST_F(UnloadTest, CrossSiteInfiniteUnloadAsync) {
if (CommandLine().HasSwitch(switches::kSingleProcess))
return;
- NavigateToUnloadFileUsingTestServer(L"unloadlooping.html", L"unloadlooping");
+ NavigateToDataURL(INFINITE_UNLOAD_HTML, L"infiniteunload");
+ // Must navigate to a non-data URL to trigger cross-site codepath.
NavigateToNolistenersFileTwiceAsync();
ASSERT_TRUE(IsBrowserRunning());
}
@@ -86,7 +119,8 @@ TEST_F(UnloadTest, CrossSiteInfiniteUnloadSync) {
if (CommandLine().HasSwitch(switches::kSingleProcess))
return;
- NavigateToUnloadFileUsingTestServer(L"unloadlooping.html", L"unloadlooping");
+ NavigateToDataURL(INFINITE_UNLOAD_HTML, L"infiniteunload");
+ // Must navigate to a non-data URL to trigger cross-site codepath.
NavigateToNolistenersFileTwice();
ASSERT_TRUE(IsBrowserRunning());
}
@@ -99,8 +133,8 @@ TEST_F(UnloadTest, CrossSiteInfiniteBeforeUnloadAsync) {
if (CommandLine().HasSwitch(switches::kSingleProcess))
return;
- NavigateToUnloadFileUsingTestServer(L"beforeunloadlooping.html",
- L"beforeunloadlooping");
+ NavigateToDataURL(INFINITE_BEFORE_UNLOAD_HTML, L"infinitebeforeunload");
+ // Must navigate to a non-data URL to trigger cross-site codepath.
NavigateToNolistenersFileTwiceAsync();
ASSERT_TRUE(IsBrowserRunning());
}
@@ -113,8 +147,41 @@ TEST_F(UnloadTest, CrossSiteInfiniteBeforeUnloadSync) {
if (CommandLine().HasSwitch(switches::kSingleProcess))
return;
- NavigateToUnloadFileUsingTestServer(L"beforeunloadlooping.html",
- L"beforeunloadlooping");
+ NavigateToDataURL(INFINITE_BEFORE_UNLOAD_HTML, L"infinitebeforeunload");
+ // Must navigate to a non-data URL to trigger cross-site codepath.
NavigateToNolistenersFileTwice();
ASSERT_TRUE(IsBrowserRunning());
}
+
+// Tests closing the browser on a page with no unload listeners registered.
+TEST_F(UnloadTest, BrowserCloseNoUnloadListeners) {
+ LoadUrlAndQuitBrowser(NOLISTENERS_HTML, L"nolisteners");
+}
+
+// Tests closing the browser on a page with an unload listener registered.
+TEST_F(UnloadTest, BrowserCloseUnload) {
+ LoadUrlAndQuitBrowser(UNLOAD_HTML, L"unload");
+}
+
+// Tests closing the browser on a page with an unload listener registered where
+// the unload handler has an infinite loop.
+TEST_F(UnloadTest, BrowserCloseInfiniteUnload) {
+ LoadUrlAndQuitBrowser(INFINITE_UNLOAD_HTML, L"infiniteunload");
+}
+
+// Tests closing the browser on a page with an unload listener registered where
+// the unload handler has an infinite loop followed by an alert.
+TEST_F(UnloadTest, BrowserCloseInfiniteUnloadAlert) {
+ LoadUrlAndQuitBrowser(INFINITE_UNLOAD_ALERT_HTML, L"infiniteunloadalert");
+}
+
+// Tests closing the browser on a page with an unload listener registered where
+// the unload handler has an 2 second long loop followed by an alert.
+TEST_F(UnloadTest, BrowserCloseTwoSecondUnloadAlert) {
+ LoadUrlAndQuitBrowser(TWO_SECOND_UNLOAD_ALERT_HTML, L"twosecondunloadalert");
+}
+
+// TODO(ojan): Test popping up an alert in the unload handler and test
+// beforeunload. In addition add tests where we open all of these pages
+// in the browser and then close it, as well as having two windows and
+// closing only one of them.
diff --git a/chrome/test/data/unload/beforeunloadlooping.html b/chrome/test/data/unload/beforeunloadlooping.html
deleted file mode 100644
index ca82c87..0000000
--- a/chrome/test/data/unload/beforeunloadlooping.html
+++ /dev/null
@@ -1,12 +0,0 @@
-<html>
-<head>
-<title>beforeunloadlooping</title>
-</head>
-<body>
-<script>
-window.onbeforeunload = function(e) {
- while(true) {}
-}
-</script>
-</body>
-</html> \ No newline at end of file
diff --git a/chrome/test/data/unload/nolisteners.html b/chrome/test/data/unload/nolisteners.html
deleted file mode 100644
index ea59143..0000000
--- a/chrome/test/data/unload/nolisteners.html
+++ /dev/null
@@ -1,7 +0,0 @@
-<html>
-<head>
-<title>nolisteners</title>
-</head>
-<body>
-</body>
-</html> \ No newline at end of file
diff --git a/chrome/test/data/unload/unload.html b/chrome/test/data/unload/unload.html
deleted file mode 100644
index eb34941..0000000
--- a/chrome/test/data/unload/unload.html
+++ /dev/null
@@ -1,11 +0,0 @@
-<html>
-<head>
-<title>unload</title>
-</head>
-<body>
-<script>
-window.onunload = function(e) {
-}
-</script>
-</body>
-</html> \ No newline at end of file
diff --git a/chrome/test/data/unload/unloadlooping.html b/chrome/test/data/unload/unloadlooping.html
deleted file mode 100644
index 443b99a..0000000
--- a/chrome/test/data/unload/unloadlooping.html
+++ /dev/null
@@ -1,12 +0,0 @@
-<html>
-<head>
-<title>unloadlooping</title>
-</head>
-<body>
-<script>
-window.onunload = function(e) {
- while(true) {}
-}
-</script>
-</body>
-</html> \ No newline at end of file
diff --git a/chrome/test/data/unload/unloadloopingalert.html b/chrome/test/data/unload/unloadloopingalert.html
deleted file mode 100644
index c43e295..0000000
--- a/chrome/test/data/unload/unloadloopingalert.html
+++ /dev/null
@@ -1,13 +0,0 @@
-<html>
-<head>
-<title>unloadloopingalert</title>
-</head>
-<body>
-<script>
-window.onunload = function(e) {
- while(true) {}
- alert('foo');
-}
-</script>
-</body>
-</html> \ No newline at end of file
diff --git a/chrome/test/data/unload/unloadloopingtwosecondsalert.html b/chrome/test/data/unload/unloadloopingtwosecondsalert.html
deleted file mode 100644
index 8a1aa36..0000000
--- a/chrome/test/data/unload/unloadloopingtwosecondsalert.html
+++ /dev/null
@@ -1,14 +0,0 @@
-<html>
-<head>
-<title>unloadloopingtwosecondsalert</title>
-</head>
-<body>
-<script>
-window.onunload = function(e) {
- var start = new Date().getTime();
- while(new Date().getTime() - start < 2000) {}
- alert('foo');
-}
-</script>
-</body>
-</html> \ No newline at end of file