diff options
author | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-10 19:21:45 +0000 |
---|---|---|
committer | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-10 19:21:45 +0000 |
commit | 297117029c8cd44b92d8529bc9b29eeb8e5fffb9 (patch) | |
tree | 250472d7bedab6fb40d74a417cbc200f503a8c72 | |
parent | 82a1c3cd33415ba89df563d73c34137507294611 (diff) | |
download | chromium_src-297117029c8cd44b92d8529bc9b29eeb8e5fffb9.zip chromium_src-297117029c8cd44b92d8529bc9b29eeb8e5fffb9.tar.gz chromium_src-297117029c8cd44b92d8529bc9b29eeb8e5fffb9.tar.bz2 |
Make sure that we deny javascript window.close() requests when we are showing
a blocked popup notification.
Review URL: http://codereview.chromium.org/9709
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@5115 0039d316-1c4b-4281-b951-d872f2087c98
4 files changed, 85 insertions, 0 deletions
diff --git a/chrome/browser/views/constrained_window_impl_interactive_uitest.cc b/chrome/browser/views/constrained_window_impl_interactive_uitest.cc index 58e504b..e528f1d 100644 --- a/chrome/browser/views/constrained_window_impl_interactive_uitest.cc +++ b/chrome/browser/views/constrained_window_impl_interactive_uitest.cc @@ -193,3 +193,56 @@ TEST_F(InteractiveConstrainedWindowTest, DontSpawnEndlessPopups) { popup_window_count = new_popup_window_count; } } + +// Make sure that we refuse to close windows when a constrained popup is displayed. +TEST_F(InteractiveConstrainedWindowTest, WindowOpenWindowClosePopup) { + scoped_ptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); + ASSERT_TRUE(browser.get()); + + scoped_ptr<WindowProxy> window( + automation()->GetWindowForBrowser(browser.get())); + ASSERT_TRUE(window.get()); + + scoped_ptr<TabProxy> tab(browser->GetTab(0)); + ASSERT_TRUE(tab.get()); + + std::wstring filename(test_data_directory_); + file_util::AppendToPath(&filename, L"constrained_files"); + file_util::AppendToPath(&filename, L"openclose_main.html"); + ASSERT_TRUE(tab->NavigateToURL(net::FilePathToFileURL(filename))); + + gfx::Rect tab_view_bounds; + ASSERT_TRUE(window->GetViewBounds(VIEW_ID_TAB_CONTAINER, + &tab_view_bounds, true)); + + // Simulate a click of the actual link to force user_gesture to be + // true; if we don't, the resulting popup will be constrained, which + // isn't what we want to test. + POINT link_point(tab_view_bounds.CenterPoint().ToPOINT()); + ASSERT_TRUE(window->SimulateOSClick(link_point, + views::Event::EF_LEFT_BUTTON_DOWN)); + + ASSERT_TRUE(automation()->WaitForWindowCountToBecome(2, 5000)); + + Sleep(1000); + + // Make sure we have a blocked popup notification + scoped_ptr<BrowserProxy> popup_browser(automation()->GetBrowserWindow(1)); + ASSERT_TRUE(popup_browser.get()); + scoped_ptr<WindowProxy> popup_window( + automation()->GetWindowForBrowser(popup_browser.get())); + ASSERT_TRUE(popup_window.get()); + scoped_ptr<TabProxy> popup_tab(popup_browser->GetTab(0)); + ASSERT_TRUE(popup_tab.get()); + scoped_ptr<ConstrainedWindowProxy> popup_notification( + popup_tab->GetConstrainedWindow(0)); + ASSERT_TRUE(popup_notification.get()); + std::wstring title; + ASSERT_TRUE(popup_notification->GetTitle(&title)); + int count = 0; + ASSERT_TRUE(ParseCountOutOfTitle(title, &count)); + ASSERT_EQ(1, count); + + // Ensure we didn't close the first popup window. + ASSERT_FALSE(automation()->WaitForWindowCountToBecome(1, 3000)); +} diff --git a/chrome/test/data/constrained_files/openclose_main.html b/chrome/test/data/constrained_files/openclose_main.html new file mode 100644 index 0000000..ab29af8 --- /dev/null +++ b/chrome/test/data/constrained_files/openclose_main.html @@ -0,0 +1,9 @@ +<html>
+<head>
+<title>Main</title>
+</head>
+
+<body onClick="window.open('openclose_one.html', 'mywindow', 'status=0,toolbar=0');">
+<h1>Click me</h1>
+</body>
+</html>
diff --git a/chrome/test/data/constrained_files/openclose_one.html b/chrome/test/data/constrained_files/openclose_one.html new file mode 100644 index 0000000..1bb8a80 --- /dev/null +++ b/chrome/test/data/constrained_files/openclose_one.html @@ -0,0 +1,14 @@ +<html>
+ <head>
+ <title>One</title>
+ <script>
+ function createDifferentWindow() {
+ window.open('openclose_two.html', 'window2', 'status=0,toolbar=0');
+ window.close();
+ }
+ </script>
+ </head>
+
+<body onLoad="createDifferentWindow();">
+</body>
+</html>
diff --git a/chrome/test/data/constrained_files/openclose_two.html b/chrome/test/data/constrained_files/openclose_two.html new file mode 100644 index 0000000..6c85e18 --- /dev/null +++ b/chrome/test/data/constrained_files/openclose_two.html @@ -0,0 +1,9 @@ +<html>
+ <head>
+ <title>Destination</title>
+ </head>
+
+<body>
+ <h1>It's here!</h1>
+</body>
+</html>
|