| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
| 9 #include "chrome/browser/view_ids.h" | 9 #include "chrome/browser/view_ids.h" |
| 10 #include "chrome/common/chrome_constants.h" | 10 #include "chrome/common/chrome_constants.h" |
| 11 #include "chrome/test/automation/automation_constants.h" | 11 #include "chrome/test/automation/automation_constants.h" |
| 12 #include "chrome/test/automation/browser_proxy.h" | 12 #include "chrome/test/automation/browser_proxy.h" |
| 13 #include "chrome/test/automation/constrained_window_proxy.h" | 13 #include "chrome/test/automation/constrained_window_proxy.h" |
| 14 #include "chrome/test/automation/tab_proxy.h" | 14 #include "chrome/test/automation/tab_proxy.h" |
| 15 #include "chrome/test/automation/window_proxy.h" | 15 #include "chrome/test/automation/window_proxy.h" |
| 16 #include "chrome/test/ui/ui_test.h" | 16 #include "chrome/test/ui/ui_test.h" |
| 17 #include "grit/generated_resources.h" | 17 #include "grit/generated_resources.h" |
| 18 #include "net/base/net_util.h" | 18 #include "net/base/net_util.h" |
| 19 #include "views/event.h" | 19 #include "views/event.h" |
| 20 | 20 |
| 21 class InteractiveConstrainedWindowTest : public UITest { | 21 class InteractiveConstrainedWindowTest : public UITest { |
| 22 protected: | 22 protected: |
| 23 InteractiveConstrainedWindowTest() { | 23 InteractiveConstrainedWindowTest() { |
| 24 show_window_ = true; | 24 show_window_ = true; |
| 25 } | 25 } |
| 26 | 26 |
| 27 virtual void SetUp() { | 27 virtual void SetUp() { |
| 28 UITest::SetUp(); | 28 UITest::SetUp(); |
| 29 | 29 |
| 30 browser_.reset(automation()->GetBrowserWindow(0)); | 30 browser_ = automation()->GetBrowserWindow(0); |
| 31 ASSERT_TRUE(browser_.get()); | 31 ASSERT_TRUE(browser_.get()); |
| 32 | 32 |
| 33 window_.reset(browser_->GetWindow()); | 33 window_ = browser_->GetWindow(); |
| 34 ASSERT_TRUE(window_.get()); | 34 ASSERT_TRUE(window_.get()); |
| 35 | 35 |
| 36 tab_.reset(browser_->GetTab(0)); | 36 tab_ = browser_->GetTab(0); |
| 37 ASSERT_TRUE(tab_.get()); | 37 ASSERT_TRUE(tab_.get()); |
| 38 } | 38 } |
| 39 | 39 |
| 40 void NavigateMainTabTo(const std::wstring& file_name) { | 40 void NavigateMainTabTo(const std::wstring& file_name) { |
| 41 FilePath filename(test_data_directory_); | 41 FilePath filename(test_data_directory_); |
| 42 filename = filename.AppendASCII("constrained_files"); | 42 filename = filename.AppendASCII("constrained_files"); |
| 43 filename = filename.Append(FilePath::FromWStringHack(file_name)); | 43 filename = filename.Append(FilePath::FromWStringHack(file_name)); |
| 44 ASSERT_TRUE(tab_->NavigateToURL(net::FilePathToFileURL(filename))); | 44 ASSERT_TRUE(tab_->NavigateToURL(net::FilePathToFileURL(filename))); |
| 45 } | 45 } |
| 46 | 46 |
| 47 void SimulateClickInCenterOf(const scoped_ptr<WindowProxy>& window) { | 47 void SimulateClickInCenterOf(const scoped_refptr<WindowProxy>& window) { |
| 48 gfx::Rect tab_view_bounds; | 48 gfx::Rect tab_view_bounds; |
| 49 ASSERT_TRUE(window->GetViewBounds(VIEW_ID_TAB_CONTAINER, | 49 ASSERT_TRUE(window->GetViewBounds(VIEW_ID_TAB_CONTAINER, |
| 50 &tab_view_bounds, true)); | 50 &tab_view_bounds, true)); |
| 51 | 51 |
| 52 // Simulate a click of the actual link to force user_gesture to be | 52 // Simulate a click of the actual link to force user_gesture to be |
| 53 // true; if we don't, the resulting popup will be constrained, which | 53 // true; if we don't, the resulting popup will be constrained, which |
| 54 // isn't what we want to test. | 54 // isn't what we want to test. |
| 55 POINT link_point(tab_view_bounds.CenterPoint().ToPOINT()); | 55 POINT link_point(tab_view_bounds.CenterPoint().ToPOINT()); |
| 56 ASSERT_TRUE(window->SimulateOSClick(link_point, | 56 ASSERT_TRUE(window->SimulateOSClick(link_point, |
| 57 views::Event::EF_LEFT_BUTTON_DOWN)); | 57 views::Event::EF_LEFT_BUTTON_DOWN)); |
| 58 } | 58 } |
| 59 | 59 |
| 60 scoped_ptr<BrowserProxy> browser_; | 60 scoped_refptr<BrowserProxy> browser_; |
| 61 scoped_ptr<WindowProxy> window_; | 61 scoped_refptr<WindowProxy> window_; |
| 62 scoped_ptr<TabProxy> tab_; | 62 scoped_refptr<TabProxy> tab_; |
| 63 }; | 63 }; |
| 64 | 64 |
| 65 TEST_F(InteractiveConstrainedWindowTest, TestOpenAndResizeTo) { | 65 TEST_F(InteractiveConstrainedWindowTest, TestOpenAndResizeTo) { |
| 66 NavigateMainTabTo(L"constrained_window_onload_resizeto.html"); | 66 NavigateMainTabTo(L"constrained_window_onload_resizeto.html"); |
| 67 SimulateClickInCenterOf(window_); | 67 SimulateClickInCenterOf(window_); |
| 68 | 68 |
| 69 ASSERT_TRUE(automation()->WaitForWindowCountToBecome(2, 1000)); | 69 ASSERT_TRUE(automation()->WaitForWindowCountToBecome(2, 1000)); |
| 70 | 70 |
| 71 scoped_ptr<BrowserProxy> popup_browser(automation()->GetBrowserWindow(1)); | 71 scoped_refptr<BrowserProxy> popup_browser(automation()->GetBrowserWindow(1)); |
| 72 ASSERT_TRUE(popup_browser != NULL); | 72 ASSERT_TRUE(popup_browser != NULL); |
| 73 scoped_ptr<WindowProxy> popup_window(popup_browser->GetWindow()); | 73 scoped_refptr<WindowProxy> popup_window(popup_browser->GetWindow()); |
| 74 ASSERT_TRUE(popup_window != NULL); | 74 ASSERT_TRUE(popup_window != NULL); |
| 75 | 75 |
| 76 // Make sure we were created with the correct width and height. | 76 // Make sure we were created with the correct width and height. |
| 77 gfx::Rect rect; | 77 gfx::Rect rect; |
| 78 bool is_timeout = false; | 78 bool is_timeout = false; |
| 79 ASSERT_TRUE(popup_window->GetViewBoundsWithTimeout( | 79 ASSERT_TRUE(popup_window->GetViewBoundsWithTimeout( |
| 80 VIEW_ID_TAB_CONTAINER, &rect, false, 1000, &is_timeout)); | 80 VIEW_ID_TAB_CONTAINER, &rect, false, 1000, &is_timeout)); |
| 81 ASSERT_FALSE(is_timeout); | 81 ASSERT_FALSE(is_timeout); |
| 82 ASSERT_EQ(300, rect.width()); | 82 ASSERT_EQ(300, rect.width()); |
| 83 ASSERT_EQ(320, rect.height()); | 83 ASSERT_EQ(320, rect.height()); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 } | 120 } |
| 121 | 121 |
| 122 // Tests that in the window.open() equivalent of a fork bomb, we stop building | 122 // Tests that in the window.open() equivalent of a fork bomb, we stop building |
| 123 // windows. | 123 // windows. |
| 124 TEST_F(InteractiveConstrainedWindowTest, DontSpawnEndlessPopups) { | 124 TEST_F(InteractiveConstrainedWindowTest, DontSpawnEndlessPopups) { |
| 125 NavigateMainTabTo(L"infinite_popups.html"); | 125 NavigateMainTabTo(L"infinite_popups.html"); |
| 126 SimulateClickInCenterOf(window_); | 126 SimulateClickInCenterOf(window_); |
| 127 | 127 |
| 128 ASSERT_TRUE(automation()->WaitForWindowCountToBecome(2, 1000)); | 128 ASSERT_TRUE(automation()->WaitForWindowCountToBecome(2, 1000)); |
| 129 | 129 |
| 130 scoped_ptr<BrowserProxy> popup_browser(automation()->GetBrowserWindow(1)); | 130 scoped_refptr<BrowserProxy> popup_browser(automation()->GetBrowserWindow(1)); |
| 131 ASSERT_TRUE(popup_browser.get()); | 131 ASSERT_TRUE(popup_browser.get()); |
| 132 scoped_ptr<TabProxy> popup_tab(popup_browser->GetTab(0)); | 132 scoped_refptr<TabProxy> popup_tab(popup_browser->GetTab(0)); |
| 133 ASSERT_TRUE(popup_tab.get()); | 133 ASSERT_TRUE(popup_tab.get()); |
| 134 | 134 |
| 135 int constrained_window_count = 0; | 135 int constrained_window_count = 0; |
| 136 ASSERT_TRUE(popup_tab->WaitForChildWindowCountToChange( | 136 ASSERT_TRUE(popup_tab->WaitForChildWindowCountToChange( |
| 137 0, &constrained_window_count, 10000)); | 137 0, &constrained_window_count, 10000)); |
| 138 ASSERT_EQ(1, constrained_window_count); | 138 ASSERT_EQ(1, constrained_window_count); |
| 139 scoped_ptr<ConstrainedWindowProxy> constrained_window( | 139 scoped_refptr<ConstrainedWindowProxy> constrained_window( |
| 140 popup_tab->GetConstrainedWindow(0)); | 140 popup_tab->GetConstrainedWindow(0)); |
| 141 ASSERT_TRUE(constrained_window.get()); | 141 ASSERT_TRUE(constrained_window.get()); |
| 142 | 142 |
| 143 // And now we spin, waiting to make sure that we don't spawn popup | 143 // And now we spin, waiting to make sure that we don't spawn popup |
| 144 // windows endlessly. The current limit is 25, so allowing for possible race | 144 // windows endlessly. The current limit is 25, so allowing for possible race |
| 145 // conditions and one off errors, don't break out until we go over 30 popup | 145 // conditions and one off errors, don't break out until we go over 30 popup |
| 146 // windows (in which case we are bork bork bork). | 146 // windows (in which case we are bork bork bork). |
| 147 const int kMaxPopupWindows = 30; | 147 const int kMaxPopupWindows = 30; |
| 148 | 148 |
| 149 int popup_window_count = 0; | 149 int popup_window_count = 0; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 176 // displayed. | 176 // displayed. |
| 177 TEST_F(InteractiveConstrainedWindowTest, WindowOpenWindowClosePopup) { | 177 TEST_F(InteractiveConstrainedWindowTest, WindowOpenWindowClosePopup) { |
| 178 NavigateMainTabTo(L"openclose_main.html"); | 178 NavigateMainTabTo(L"openclose_main.html"); |
| 179 SimulateClickInCenterOf(window_); | 179 SimulateClickInCenterOf(window_); |
| 180 | 180 |
| 181 ASSERT_TRUE(automation()->WaitForWindowCountToBecome(2, 5000)); | 181 ASSERT_TRUE(automation()->WaitForWindowCountToBecome(2, 5000)); |
| 182 | 182 |
| 183 PlatformThread::Sleep(1000); | 183 PlatformThread::Sleep(1000); |
| 184 | 184 |
| 185 // Make sure we have a blocked popup notification | 185 // Make sure we have a blocked popup notification |
| 186 scoped_ptr<BrowserProxy> popup_browser(automation()->GetBrowserWindow(1)); | 186 scoped_refptr<BrowserProxy> popup_browser(automation()->GetBrowserWindow(1)); |
| 187 ASSERT_TRUE(popup_browser.get()); | 187 ASSERT_TRUE(popup_browser.get()); |
| 188 scoped_ptr<WindowProxy> popup_window(popup_browser->GetWindow()); | 188 scoped_refptr<WindowProxy> popup_window(popup_browser->GetWindow()); |
| 189 ASSERT_TRUE(popup_window.get()); | 189 ASSERT_TRUE(popup_window.get()); |
| 190 scoped_ptr<TabProxy> popup_tab(popup_browser->GetTab(0)); | 190 scoped_refptr<TabProxy> popup_tab(popup_browser->GetTab(0)); |
| 191 ASSERT_TRUE(popup_tab.get()); | 191 ASSERT_TRUE(popup_tab.get()); |
| 192 scoped_ptr<ConstrainedWindowProxy> popup_notification( | 192 scoped_refptr<ConstrainedWindowProxy> popup_notification( |
| 193 popup_tab->GetConstrainedWindow(0)); | 193 popup_tab->GetConstrainedWindow(0)); |
| 194 ASSERT_TRUE(popup_notification.get()); | 194 ASSERT_TRUE(popup_notification.get()); |
| 195 std::wstring title; | 195 std::wstring title; |
| 196 ASSERT_TRUE(popup_notification->GetTitle(&title)); | 196 ASSERT_TRUE(popup_notification->GetTitle(&title)); |
| 197 int count = 0; | 197 int count = 0; |
| 198 ASSERT_TRUE(ParseCountOutOfTitle(title, &count)); | 198 ASSERT_TRUE(ParseCountOutOfTitle(title, &count)); |
| 199 ASSERT_EQ(1, count); | 199 ASSERT_EQ(1, count); |
| 200 | 200 |
| 201 // Ensure we didn't close the first popup window. | 201 // Ensure we didn't close the first popup window. |
| 202 ASSERT_FALSE(automation()->WaitForWindowCountToBecome(1, 3000)); | 202 ASSERT_FALSE(automation()->WaitForWindowCountToBecome(1, 3000)); |
| 203 } | 203 } |
| 204 | 204 |
| 205 TEST_F(InteractiveConstrainedWindowTest, BlockAlertFromBlockedPopup) { | 205 TEST_F(InteractiveConstrainedWindowTest, BlockAlertFromBlockedPopup) { |
| 206 NavigateMainTabTo(L"block_alert.html"); | 206 NavigateMainTabTo(L"block_alert.html"); |
| 207 | 207 |
| 208 // Wait for there to be an app modal dialog (and fail if it's shown). | 208 // Wait for there to be an app modal dialog (and fail if it's shown). |
| 209 ASSERT_FALSE(automation()->WaitForAppModalDialog(4000)); | 209 ASSERT_FALSE(automation()->WaitForAppModalDialog(4000)); |
| 210 | 210 |
| 211 // Ensure one browser window. | 211 // Ensure one browser window. |
| 212 int browser_window_count; | 212 int browser_window_count; |
| 213 ASSERT_TRUE(automation()->GetBrowserWindowCount(&browser_window_count)); | 213 ASSERT_TRUE(automation()->GetBrowserWindowCount(&browser_window_count)); |
| 214 ASSERT_EQ(1, browser_window_count); | 214 ASSERT_EQ(1, browser_window_count); |
| 215 | 215 |
| 216 // Ensure one blocked popup window: the popup didn't escape. | 216 // Ensure one blocked popup window: the popup didn't escape. |
| 217 scoped_ptr<ConstrainedWindowProxy> popup_notification( | 217 scoped_refptr<ConstrainedWindowProxy> popup_notification( |
| 218 tab_->GetConstrainedWindow(0)); | 218 tab_->GetConstrainedWindow(0)); |
| 219 ASSERT_TRUE(popup_notification.get()); | 219 ASSERT_TRUE(popup_notification.get()); |
| 220 std::wstring title; | 220 std::wstring title; |
| 221 ASSERT_TRUE(popup_notification->GetTitle(&title)); | 221 ASSERT_TRUE(popup_notification->GetTitle(&title)); |
| 222 int popup_count = 0; | 222 int popup_count = 0; |
| 223 ASSERT_TRUE(ParseCountOutOfTitle(title, &popup_count)); | 223 ASSERT_TRUE(ParseCountOutOfTitle(title, &popup_count)); |
| 224 ASSERT_EQ(1, popup_count); | 224 ASSERT_EQ(1, popup_count); |
| 225 } | 225 } |
| 226 | 226 |
| 227 TEST_F(InteractiveConstrainedWindowTest, ShowAlertFromNormalPopup) { | 227 TEST_F(InteractiveConstrainedWindowTest, ShowAlertFromNormalPopup) { |
| 228 NavigateMainTabTo(L"show_alert.html"); | 228 NavigateMainTabTo(L"show_alert.html"); |
| 229 SimulateClickInCenterOf(window_); | 229 SimulateClickInCenterOf(window_); |
| 230 | 230 |
| 231 ASSERT_TRUE(automation()->WaitForWindowCountToBecome(2, 5000)); | 231 ASSERT_TRUE(automation()->WaitForWindowCountToBecome(2, 5000)); |
| 232 | 232 |
| 233 scoped_ptr<BrowserProxy> popup_browser(automation()->GetBrowserWindow(1)); | 233 scoped_refptr<BrowserProxy> popup_browser(automation()->GetBrowserWindow(1)); |
| 234 ASSERT_TRUE(popup_browser.get()); | 234 ASSERT_TRUE(popup_browser.get()); |
| 235 scoped_ptr<WindowProxy> popup_window(popup_browser->GetWindow()); | 235 scoped_refptr<WindowProxy> popup_window(popup_browser->GetWindow()); |
| 236 ASSERT_TRUE(popup_window.get()); | 236 ASSERT_TRUE(popup_window.get()); |
| 237 scoped_ptr<TabProxy> popup_tab(popup_browser->GetTab(0)); | 237 scoped_refptr<TabProxy> popup_tab(popup_browser->GetTab(0)); |
| 238 ASSERT_TRUE(popup_tab.get()); | 238 ASSERT_TRUE(popup_tab.get()); |
| 239 | 239 |
| 240 SimulateClickInCenterOf(popup_window); | 240 SimulateClickInCenterOf(popup_window); |
| 241 | 241 |
| 242 // Wait for there to be an app modal dialog. | 242 // Wait for there to be an app modal dialog. |
| 243 ASSERT_TRUE(automation()->WaitForAppModalDialog(5000)); | 243 ASSERT_TRUE(automation()->WaitForAppModalDialog(5000)); |
| 244 } | 244 } |
| 245 | 245 |
| 246 // Make sure that window focus works while creating a popup window so that we | 246 // Make sure that window focus works while creating a popup window so that we |
| 247 // don't | 247 // don't |
| 248 TEST_F(InteractiveConstrainedWindowTest, DontBreakOnBlur) { | 248 TEST_F(InteractiveConstrainedWindowTest, DontBreakOnBlur) { |
| 249 NavigateMainTabTo(L"window_blur_test.html"); | 249 NavigateMainTabTo(L"window_blur_test.html"); |
| 250 SimulateClickInCenterOf(window_); | 250 SimulateClickInCenterOf(window_); |
| 251 | 251 |
| 252 // Wait for the popup window to open. | 252 // Wait for the popup window to open. |
| 253 ASSERT_TRUE(automation()->WaitForWindowCountToBecome(2, 1000)); | 253 ASSERT_TRUE(automation()->WaitForWindowCountToBecome(2, 1000)); |
| 254 | 254 |
| 255 // We popup shouldn't be closed by the onblur handler. | 255 // We popup shouldn't be closed by the onblur handler. |
| 256 ASSERT_FALSE(automation()->WaitForWindowCountToBecome(1, 1500)); | 256 ASSERT_FALSE(automation()->WaitForWindowCountToBecome(1, 1500)); |
| 257 } | 257 } |
| OLD | NEW |