summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornirnimesh@chromium.org <nirnimesh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-13 19:44:14 +0000
committernirnimesh@chromium.org <nirnimesh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-13 19:44:14 +0000
commitcb37d4830e2ab67e9151bba115bf05c11cf1da42 (patch)
treece6ce00523ff7b7e7f8d73890321f3a66c3c62d5
parenta6a1ee832e13ea90790da610ef1a884854e96e01 (diff)
downloadchromium_src-cb37d4830e2ab67e9151bba115bf05c11cf1da42.zip
chromium_src-cb37d4830e2ab67e9151bba115bf05c11cf1da42.tar.gz
chromium_src-cb37d4830e2ab67e9151bba115bf05c11cf1da42.tar.bz2
PyAuto automation support for blocked popups
Add PyAuto automation hooks for fetching info about blocked popups in a tab, and launching a blocked popup. BUG=55889 TEST=popups.py Review URL: http://codereview.chromium.org/3688004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@62435 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/automation/testing_automation_provider.cc71
-rw-r--r--chrome/browser/automation/testing_automation_provider.h12
-rw-r--r--chrome/test/functional/PYAUTO_TESTS1
-rw-r--r--chrome/test/functional/popups.py54
-rw-r--r--chrome/test/pyautolib/pyauto.py31
5 files changed, 169 insertions, 0 deletions
diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc
index f62535d..4b28aad 100644
--- a/chrome/browser/automation/testing_automation_provider.cc
+++ b/chrome/browser/automation/testing_automation_provider.cc
@@ -2069,6 +2069,11 @@ void TestingAutomationProvider::SendJSONRequest(int handle,
handler_map["ClearBrowsingData"] =
&TestingAutomationProvider::ClearBrowsingData;
+ handler_map["GetBlockedPopupsInfo"] =
+ &TestingAutomationProvider::GetBlockedPopupsInfo;
+ handler_map["UnblockAndLaunchBlockedPopup"] =
+ &TestingAutomationProvider::UnblockAndLaunchBlockedPopup;
+
// SetTheme() implemented using InstallExtension().
handler_map["GetThemeInfo"] = &TestingAutomationProvider::GetThemeInfo;
@@ -3577,6 +3582,72 @@ void TestingAutomationProvider::SelectTranslateOption(
}
}
+// Sample json input: { "command": "GetBlockedPopupsInfo",
+// "tab_index": 1 }
+// Refer GetBlockedPopupsInfo() in pyauto.py for sample output.
+void TestingAutomationProvider::GetBlockedPopupsInfo(
+ Browser* browser,
+ DictionaryValue* args,
+ IPC::Message* reply_message) {
+ AutomationJSONReply reply(this, reply_message);
+ std::string error_message;
+ TabContents* tab_contents = GetTabContentsFromDict(
+ browser, args, &error_message);
+ if (!tab_contents) {
+ reply.SendError(error_message);
+ return;
+ }
+ scoped_ptr<DictionaryValue> return_value(new DictionaryValue);
+ BlockedPopupContainer* popup_container =
+ tab_contents->blocked_popup_container();
+ ListValue* blocked_popups_list = new ListValue;
+ if (popup_container) {
+ BlockedPopupContainer::BlockedContents blocked_contents;
+ popup_container->GetBlockedContents(&blocked_contents);
+ for (BlockedPopupContainer::BlockedContents::const_iterator it =
+ blocked_contents.begin(); it != blocked_contents.end(); ++it) {
+ DictionaryValue* item = new DictionaryValue;
+ item->SetString("url", (*it)->GetURL().spec());
+ item->SetString("title", (*it)->GetTitle());
+ blocked_popups_list->Append(item);
+ }
+ }
+ return_value->Set("blocked_popups", blocked_popups_list);
+ reply.SendSuccess(return_value.get());
+}
+
+// Refer UnblockAndLaunchBlockedPopup() in pyauto.py for sample input.
+void TestingAutomationProvider::UnblockAndLaunchBlockedPopup(
+ Browser* browser,
+ DictionaryValue* args,
+ IPC::Message* reply_message) {
+ AutomationJSONReply reply(this, reply_message);
+ std::string error_message;
+ TabContents* tab_contents = GetTabContentsFromDict(
+ browser, args, &error_message);
+ if (!tab_contents) {
+ reply.SendError(error_message);
+ return;
+ }
+ int popup_index;
+ if (!args->GetInteger("popup_index", &popup_index)) {
+ reply.SendError("Need popup_index arg");
+ return;
+ }
+ scoped_ptr<DictionaryValue> return_value(new DictionaryValue);
+ BlockedPopupContainer* popup_container =
+ tab_contents->blocked_popup_container();
+ if (!popup_container ||
+ popup_index >= (int)popup_container->GetBlockedPopupCount()) {
+ reply.SendError(StringPrintf("No popup at index %d", popup_index));
+ return;
+ }
+ BlockedPopupContainer::BlockedContents blocked_contents;
+ popup_container->GetBlockedContents(&blocked_contents);
+ popup_container->LaunchPopupForContents(blocked_contents[popup_index]);
+ reply.SendSuccess(NULL);
+}
+
// Sample json input: { "command": "GetThemeInfo" }
// Refer GetThemeInfo() in chrome/test/pyautolib/pyauto.py for sample output.
void TestingAutomationProvider::GetThemeInfo(
diff --git a/chrome/browser/automation/testing_automation_provider.h b/chrome/browser/automation/testing_automation_provider.h
index e0a505e..838a079 100644
--- a/chrome/browser/automation/testing_automation_provider.h
+++ b/chrome/browser/automation/testing_automation_provider.h
@@ -553,6 +553,18 @@ class TestingAutomationProvider : public AutomationProvider,
DictionaryValue* args,
IPC::Message* reply_message);
+ // Get info about blocked popups in a tab.
+ // Uses the JSON interface for input/output.
+ void GetBlockedPopupsInfo(Browser* browser,
+ DictionaryValue* args,
+ IPC::Message* reply_message);
+
+ // Launch a blocked popup.
+ // Uses the JSON interface for input/output.
+ void UnblockAndLaunchBlockedPopup(Browser* browser,
+ DictionaryValue* args,
+ IPC::Message* reply_message);
+
// Get info about theme.
// Uses the JSON interface for input/output.
void GetThemeInfo(Browser* browser,
diff --git a/chrome/test/functional/PYAUTO_TESTS b/chrome/test/functional/PYAUTO_TESTS
index e7b3f7a..b4078b0 100644
--- a/chrome/test/functional/PYAUTO_TESTS
+++ b/chrome/test/functional/PYAUTO_TESTS
@@ -40,6 +40,7 @@
'omnibox',
'passwords',
'plugins',
+ 'popups',
'prefs',
'search_engines',
'special_tabs',
diff --git a/chrome/test/functional/popups.py b/chrome/test/functional/popups.py
new file mode 100644
index 0000000..48b9831
--- /dev/null
+++ b/chrome/test/functional/popups.py
@@ -0,0 +1,54 @@
+#!/usr/bin/python
+
+# Copyright (c) 2010 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import os
+
+import pyauto_functional # Must be imported before pyauto
+import pyauto
+
+
+class PopupsTest(pyauto.PyUITest):
+ """TestCase for Popup blocking."""
+
+ def Debug(self):
+ """Test method for experimentation.
+
+ This method will not run automatically.
+ """
+ import pprint
+ pp = pprint.PrettyPrinter(indent=2)
+ while True:
+ raw_input('Interact with the browser and hit <enter>')
+ pp.pprint(self.GetBlockedPopupsInfo())
+
+ def testPopupBlockerEnabled(self):
+ """Verify popup blocking is enabled."""
+ self.assertFalse(self.GetBlockedPopupsInfo(),
+ msg='Should have no blocked popups on startup')
+ file_url = self.GetFileURLForPath(os.path.join(
+ self.DataDir(), 'popup_blocker', 'popup-blocked-to-post-blank.html'))
+ self.NavigateToURL(file_url)
+ blocked_popups = self.GetBlockedPopupsInfo()
+ self.assertEqual(1, len(blocked_popups), msg='Popup not blocked')
+ self.assertEqual('Popup Success!', blocked_popups[0]['title'])
+
+ def testLaunchBlockedPopup(self):
+ """Verify that a blocked popup can be unblocked."""
+ file_url = self.GetFileURLForPath(os.path.join(
+ self.DataDir(), 'popup_blocker', 'popup-blocked-to-post-blank.html'))
+ self.NavigateToURL(file_url)
+ self.assertEqual(1, len(self.GetBlockedPopupsInfo()))
+ self.UnblockAndLaunchBlockedPopup(0)
+ # Verify that no more popups are blocked
+ self.assertFalse(self.GetBlockedPopupsInfo())
+ # Verify that popup window was created
+ self.assertEqual(2, self.GetBrowserWindowCount(),
+ msg='Popup could not be launched');
+ self.assertEqual('Popup Success!', self.GetActiveTabTitle(1))
+
+
+if __name__ == '__main__':
+ pyauto_functional.Main()
diff --git a/chrome/test/pyautolib/pyauto.py b/chrome/test/pyautolib/pyauto.py
index 80d08c76..8103795 100644
--- a/chrome/test/pyautolib/pyauto.py
+++ b/chrome/test/pyautolib/pyauto.py
@@ -1392,6 +1392,37 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase):
}
return self._GetResultFromJSONRequest(cmd_dict)['passwords']
+ def GetBlockedPopupsInfo(self, tab_index=0, windex=0):
+ """Get info about blocked popups in a tab.
+
+ Args:
+ tab_index: 0-based tab index. Default: 0
+ windex: 0-based window index. Default: 0
+
+ Returns:
+ [a list of property dictionaries for each blocked popup]
+ Property dictionary contains: title, url
+ """
+ cmd_dict = {
+ 'command': 'GetBlockedPopupsInfo',
+ 'tab_index': tab_index,
+ }
+ return self._GetResultFromJSONRequest(cmd_dict,
+ windex=windex)['blocked_popups']
+
+ def UnblockAndLaunchBlockedPopup(self, popup_index, tab_index=0, windex=0):
+ """Unblock/launch a poup at the given index.
+
+ This is equivalent to clicking on a blocked popup in the UI available
+ from the omnibox.
+ """
+ cmd_dict = {
+ 'command': 'UnblockAndLaunchBlockedPopup',
+ 'popup_index': popup_index,
+ 'tab_index': tab_index,
+ }
+ self._GetResultFromJSONRequest(cmd_dict, windex=windex)
+
def SetTheme(self, crx_file_path):
"""Installs the given theme synchronously.