diff options
-rw-r--r-- | chrome/browser/automation/automation_provider.cc | 8 | ||||
-rw-r--r-- | chrome/browser/automation/automation_provider.h | 2 | ||||
-rw-r--r-- | chrome/browser/views/constrained_window_impl_interactive_uitest.cc | 169 | ||||
-rw-r--r-- | chrome/browser/web_contents.cc | 3 | ||||
-rw-r--r-- | chrome/test/automation/automation_messages_internal.h | 9 | ||||
-rw-r--r-- | chrome/test/automation/automation_proxy.cc | 47 | ||||
-rw-r--r-- | chrome/test/automation/automation_proxy.h | 9 | ||||
-rw-r--r-- | chrome/test/data/constrained_files/block_alert.html | 17 | ||||
-rw-r--r-- | chrome/test/data/constrained_files/show_alert.html | 15 | ||||
-rw-r--r-- | chrome/test/data/constrained_files/show_alert_2.html | 8 |
10 files changed, 198 insertions, 89 deletions
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc index 8e572ab..b9bd059 100644 --- a/chrome/browser/automation/automation_provider.cc +++ b/chrome/browser/automation/automation_provider.cc @@ -801,6 +801,8 @@ void AutomationProvider::OnMessageReceived(const IPC::Message& message) { WaitForNavigation) IPC_MESSAGE_HANDLER(AutomationMsg_SetIntPreferenceRequest, SetIntPreference) + IPC_MESSAGE_HANDLER(AutomationMsg_ShowingAppModalDialogRequest, + GetShowingAppModalDialog) IPC_END_MESSAGE_MAP() } @@ -1063,6 +1065,12 @@ void AutomationProvider::GetBrowserWindowCount(const IPC::Message& message) { message.routing_id(), static_cast<int>(BrowserList::size()))); } +void AutomationProvider::GetShowingAppModalDialog(const IPC::Message& message) { + Send(new AutomationMsg_ShowingAppModalDialogResponse( + message.routing_id(), + static_cast<bool>(BrowserList::IsShowingAppModalDialog()))); +} + void AutomationProvider::GetBrowserWindow(const IPC::Message& message, int index) { int handle = 0; diff --git a/chrome/browser/automation/automation_provider.h b/chrome/browser/automation/automation_provider.h index aaeb5bc..cb9ff00 100644 --- a/chrome/browser/automation/automation_provider.h +++ b/chrome/browser/automation/automation_provider.h @@ -105,6 +105,7 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>, const std::string value, int handle); void GetBrowserWindowCount(const IPC::Message& message); + void GetShowingAppModalDialog(const IPC::Message& message); void GetBrowserWindow(const IPC::Message& message, int index); void GetLastActiveBrowserWindow(const IPC::Message& message); void GetActiveWindow(const IPC::Message& message); @@ -411,4 +412,3 @@ class TestingAutomationProvider : public AutomationProvider, void OnRemoveProvider(); // Called via PostTask }; #endif // CHROME_BROWSER_AUTOMATION_AUTOMATION_PROVIDER_H_ - diff --git a/chrome/browser/views/constrained_window_impl_interactive_uitest.cc b/chrome/browser/views/constrained_window_impl_interactive_uitest.cc index e528f1d..3e6dc88 100644 --- a/chrome/browser/views/constrained_window_impl_interactive_uitest.cc +++ b/chrome/browser/views/constrained_window_impl_interactive_uitest.cc @@ -19,43 +19,53 @@ #include "generated_resources.h" -const int kRightCloseButtonOffset = 55; -const int kBottomCloseButtonOffset = 20; - class InteractiveConstrainedWindowTest : public UITest { protected: InteractiveConstrainedWindowTest() { show_window_ = true; } -}; -TEST_F(InteractiveConstrainedWindowTest, TestOpenAndResizeTo) { - scoped_ptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); - ASSERT_TRUE(browser.get()); + virtual void SetUp() { + UITest::SetUp(); - scoped_ptr<WindowProxy> window( - automation()->GetWindowForBrowser(browser.get())); - ASSERT_TRUE(window.get()); + browser_.reset(automation()->GetBrowserWindow(0)); + ASSERT_TRUE(browser_.get()); - scoped_ptr<TabProxy> tab(browser->GetTab(0)); - ASSERT_TRUE(tab.get()); + window_.reset(automation()->GetWindowForBrowser(browser_.get())); + ASSERT_TRUE(window_.get()); - std::wstring filename(test_data_directory_); - file_util::AppendToPath(&filename, L"constrained_files"); - file_util::AppendToPath(&filename, - L"constrained_window_onload_resizeto.html"); - ASSERT_TRUE(tab->NavigateToURL(net::FilePathToFileURL(filename))); + tab_.reset(browser_->GetTab(0)); + ASSERT_TRUE(tab_.get()); + } - gfx::Rect tab_view_bounds; - ASSERT_TRUE(window->GetViewBounds(VIEW_ID_TAB_CONTAINER, - &tab_view_bounds, true)); + void NavigateMainTabTo(const std::wstring& file_name) { + std::wstring filename(test_data_directory_); + file_util::AppendToPath(&filename, L"constrained_files"); + file_util::AppendToPath(&filename, file_name); + ASSERT_TRUE(tab_->NavigateToURL(net::FilePathToFileURL(filename))); + } - // 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)); + void SimulateClickInCenterOf(const scoped_ptr<WindowProxy>& window) { + 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)); + } + + scoped_ptr<BrowserProxy> browser_; + scoped_ptr<WindowProxy> window_; + scoped_ptr<TabProxy> tab_; +}; + +TEST_F(InteractiveConstrainedWindowTest, TestOpenAndResizeTo) { + NavigateMainTabTo(L"constrained_window_onload_resizeto.html"); + SimulateClickInCenterOf(window_); ASSERT_TRUE(automation()->WaitForWindowCountToBecome(2, 1000)); @@ -74,12 +84,7 @@ TEST_F(InteractiveConstrainedWindowTest, TestOpenAndResizeTo) { ASSERT_EQ(300, rect.width()); ASSERT_EQ(320, rect.height()); - // Send a click to the popup window to test resizeTo. - ASSERT_TRUE(popup_window->GetViewBounds(VIEW_ID_TAB_CONTAINER, - &tab_view_bounds, true)); - POINT popup_link_point(tab_view_bounds.CenterPoint().ToPOINT()); - ASSERT_TRUE(popup_window->SimulateOSClick( - popup_link_point, views::Event::EF_LEFT_BUTTON_DOWN)); + SimulateClickInCenterOf(popup_window); // No idea how to wait here other then sleeping. This timeout used to be // lower, then we started hitting it before it was done. :( @@ -120,32 +125,8 @@ bool ParseCountOutOfTitle(const std::wstring& title, int* output) // Tests that in the window.open() equivalent of a fork bomb, we stop building // windows. TEST_F(InteractiveConstrainedWindowTest, DontSpawnEndlessPopups) { - 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"infinite_popups.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)); + NavigateMainTabTo(L"infinite_popups.html"); + SimulateClickInCenterOf(window_); ASSERT_TRUE(automation()->WaitForWindowCountToBecome(2, 1000)); @@ -194,33 +175,11 @@ TEST_F(InteractiveConstrainedWindowTest, DontSpawnEndlessPopups) { } } -// Make sure that we refuse to close windows when a constrained popup is displayed. +// 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)); + NavigateMainTabTo(L"openclose_main.html"); + SimulateClickInCenterOf(window_); ASSERT_TRUE(automation()->WaitForWindowCountToBecome(2, 5000)); @@ -246,3 +205,45 @@ TEST_F(InteractiveConstrainedWindowTest, WindowOpenWindowClosePopup) { // Ensure we didn't close the first popup window. ASSERT_FALSE(automation()->WaitForWindowCountToBecome(1, 3000)); } + +TEST_F(InteractiveConstrainedWindowTest, BlockAlertFromBlockedPopup) { + NavigateMainTabTo(L"block_alert.html"); + + // Wait for there to be an app modal dialog (and fail if it's shown). + ASSERT_FALSE(automation()->WaitForAppModalDialog(4000)); + + // Ensure one browser window. + int browser_window_count; + ASSERT_TRUE(automation()->GetBrowserWindowCount(&browser_window_count)); + ASSERT_EQ(1, browser_window_count); + + // Ensure one blocked popup window: the popup didn't escape. + scoped_ptr<ConstrainedWindowProxy> popup_notification( + tab_->GetConstrainedWindow(0)); + ASSERT_TRUE(popup_notification.get()); + std::wstring title; + ASSERT_TRUE(popup_notification->GetTitle(&title)); + int popup_count = 0; + ASSERT_TRUE(ParseCountOutOfTitle(title, &popup_count)); + ASSERT_EQ(1, popup_count); +} + +TEST_F(InteractiveConstrainedWindowTest, ShowAlertFromNormalPopup) { + NavigateMainTabTo(L"show_alert.html"); + SimulateClickInCenterOf(window_); + + ASSERT_TRUE(automation()->WaitForWindowCountToBecome(2, 5000)); + + 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()); + + SimulateClickInCenterOf(popup_window); + + // Wait for there to be an app modal dialog. + ASSERT_TRUE(automation()->WaitForAppModalDialog(5000)); +} diff --git a/chrome/browser/web_contents.cc b/chrome/browser/web_contents.cc index acd9338..e936aac 100644 --- a/chrome/browser/web_contents.cc +++ b/chrome/browser/web_contents.cc @@ -1082,7 +1082,8 @@ void WebContents::RunJavaScriptMessage( // constrained window jail). bool suppress_this_message = suppress_javascript_messages_; if (delegate()) - suppress_this_message |= delegate()->IsPopup(this); + suppress_this_message |= + (delegate()->GetConstrainingContents(this) != NULL); *did_suppress_message = suppress_this_message; diff --git a/chrome/test/automation/automation_messages_internal.h b/chrome/test/automation/automation_messages_internal.h index d6a321a8..4d19a89 100644 --- a/chrome/test/automation/automation_messages_internal.h +++ b/chrome/test/automation/automation_messages_internal.h @@ -795,11 +795,16 @@ IPC_BEGIN_MESSAGES(Automation, 0) // This messages sets an int-value preference. IPC_MESSAGE_ROUTED3(AutomationMsg_SetIntPreferenceRequest, - int /* browser handle */, + int /* browser handle */, std::wstring /* pref name */, int /* value */) IPC_MESSAGE_ROUTED1(AutomationMsg_SetIntPreferenceResponse, bool /* success */) -IPC_END_MESSAGES(Automation) + // Queries whether an app modal dialog is currently being shown. (i.e. a + // javascript alert). + IPC_MESSAGE_ROUTED0(AutomationMsg_ShowingAppModalDialogRequest) + IPC_MESSAGE_ROUTED1(AutomationMsg_ShowingAppModalDialogResponse, + bool /* showing dialog */) +IPC_END_MESSAGES(Automation) diff --git a/chrome/test/automation/automation_proxy.cc b/chrome/test/automation/automation_proxy.cc index 5588ea8..348ce0f 100644 --- a/chrome/test/automation/automation_proxy.cc +++ b/chrome/test/automation/automation_proxy.cc @@ -302,6 +302,53 @@ bool AutomationProxy::WaitForWindowCountToBecome(int count, return false; } +bool AutomationProxy::GetShowingAppModalDialog(bool* showing_app_modal_dialog) { + if (!showing_app_modal_dialog) { + NOTREACHED(); + return false; + } + + IPC::Message* response = NULL; + bool is_timeout = true; + bool succeeded = SendAndWaitForResponseWithTimeout( + new AutomationMsg_ShowingAppModalDialogRequest(0), &response, + AutomationMsg_ShowingAppModalDialogResponse::ID, + kMaxCommandExecutionTime, &is_timeout); + if (!succeeded) + return false; + + if (is_timeout) { + DLOG(ERROR) << "ShowingAppModalDialog did not complete in a timely fashion"; + return false; + } + + void* iter = NULL; + if (!response->ReadBool(&iter, showing_app_modal_dialog)) { + succeeded = false; + } + + delete response; + return succeeded; +} + +bool AutomationProxy::WaitForAppModalDialog(int wait_timeout) { + const TimeTicks start = TimeTicks::Now(); + const TimeDelta timeout = TimeDelta::FromMilliseconds(wait_timeout); + while (TimeTicks::Now() - start < timeout) { + bool dialog_shown = false; + bool succeeded = GetShowingAppModalDialog(&dialog_shown); + if (!succeeded) { + // Try again next round, but log it. + DLOG(ERROR) << "GetShowingAppModalDialog returned false"; + } else if (dialog_shown) { + return true; + } + Sleep(automation::kSleepTime); + } + // Dialog never shown. + return false; +} + bool AutomationProxy::SetFilteredInet(bool enabled) { return Send(new AutomationMsg_SetFilteredInet(0, enabled)); } diff --git a/chrome/test/automation/automation_proxy.h b/chrome/test/automation/automation_proxy.h index 8491832..5621b011 100644 --- a/chrome/test/automation/automation_proxy.h +++ b/chrome/test/automation/automation_proxy.h @@ -108,6 +108,14 @@ class AutomationProxy : public IPC::Channel::Listener, // Returns true on success. bool WaitForWindowCountToBecome(int target_count, int wait_timeout); + // Returns whether an app modal dialog window is showing right now (i.e., a + // javascript alert). + bool GetShowingAppModalDialog(bool* showing_app_modal_dialog); + + // Block the thread until a modal dialog is displayed. Returns true on + // success. + bool WaitForAppModalDialog(int wait_timeout); + // Returns the BrowserProxy for the browser window at the given index, // transferring ownership of the pointer to the caller. // On failure, returns NULL. @@ -217,4 +225,3 @@ class AutomationProxy : public IPC::Channel::Listener, }; #endif // CHROME_TEST_AUTOMATION_AUTOMATION_PROXY_H__ - diff --git a/chrome/test/data/constrained_files/block_alert.html b/chrome/test/data/constrained_files/block_alert.html new file mode 100644 index 0000000..063d972 --- /dev/null +++ b/chrome/test/data/constrained_files/block_alert.html @@ -0,0 +1,17 @@ +<html>
+ <head>
+ <title>Block alert from blocked popup?</title>
+ <script>
+ if (location.search.indexOf("popup") != -1) {
+ document.write("This should still be inside the tab, but it is now " +
+ "in a new window!");
+ alert("The popup has been \"popped out\" of the tab");
+ } else {
+ window.open("?popup");
+ }
+ </script>
+ </head>
+<body>
+<h1>Block alert from blocked popup?</h1>
+</body>
+</html>
diff --git a/chrome/test/data/constrained_files/show_alert.html b/chrome/test/data/constrained_files/show_alert.html new file mode 100644 index 0000000..742271e --- /dev/null +++ b/chrome/test/data/constrained_files/show_alert.html @@ -0,0 +1,15 @@ +<html>
+ <head>
+ <title>Must show alert to pass!</title>
+ <script type="text/javascript" language="JavaScript">
+ function openTestWin(){
+ wintest = window.open("show_alert_2.html","wintest",
+ "width=864,height=600");
+ wintest.focus();
+ }
+ </script>
+ </head>
+<body onClick="openTestWin();">
+<h1>Must show alert to pass!</h1>
+</body>
+</html>
diff --git a/chrome/test/data/constrained_files/show_alert_2.html b/chrome/test/data/constrained_files/show_alert_2.html new file mode 100644 index 0000000..3fbc795 --- /dev/null +++ b/chrome/test/data/constrained_files/show_alert_2.html @@ -0,0 +1,8 @@ +<html>
+ <head>
+ <title>Must show alert to pass!</title>
+ </head>
+ <body onClick="alert('Alert running');">
+ <h1>Must show alert to pass!</h1>
+ </body>
+</html>
|