diff options
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/browser_uitest.cc | 47 | ||||
-rw-r--r-- | chrome/test/data/unload/nolisteners.html | 1 | ||||
-rw-r--r-- | chrome/test/data/unload/unload.html | 8 | ||||
-rw-r--r-- | chrome/test/data/unload/unloadlooping.html | 9 | ||||
-rw-r--r-- | chrome/test/data/unload/unloadloopingalert.html | 10 | ||||
-rw-r--r-- | chrome/test/data/unload/unloadloopingtwosecondsalert.html | 11 |
6 files changed, 86 insertions, 0 deletions
diff --git a/chrome/browser/browser_uitest.cc b/chrome/browser/browser_uitest.cc index 470d2a5..84d01430 100644 --- a/chrome/browser/browser_uitest.cc +++ b/chrome/browser/browser_uitest.cc @@ -72,6 +72,20 @@ 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 { @@ -110,6 +124,39 @@ 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/test/data/unload/nolisteners.html b/chrome/test/data/unload/nolisteners.html new file mode 100644 index 0000000..42682b4 --- /dev/null +++ b/chrome/test/data/unload/nolisteners.html @@ -0,0 +1 @@ +<html><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 new file mode 100644 index 0000000..4ce7f78 --- /dev/null +++ b/chrome/test/data/unload/unload.html @@ -0,0 +1,8 @@ +<html> +<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 new file mode 100644 index 0000000..134ce30 --- /dev/null +++ b/chrome/test/data/unload/unloadlooping.html @@ -0,0 +1,9 @@ +<html> +<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 new file mode 100644 index 0000000..dacd9b5 --- /dev/null +++ b/chrome/test/data/unload/unloadloopingalert.html @@ -0,0 +1,10 @@ +<html> +<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 new file mode 100644 index 0000000..ec796f9 --- /dev/null +++ b/chrome/test/data/unload/unloadloopingtwosecondsalert.html @@ -0,0 +1,11 @@ +<html> +<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 |