summaryrefslogtreecommitdiffstats
path: root/chrome/browser/automation
diff options
context:
space:
mode:
authorkkania@chromium.org <kkania@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-26 20:18:45 +0000
committerkkania@chromium.org <kkania@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-26 20:18:45 +0000
commitac43f703a731d232ea095c28a5367f2cdd2bd7b2 (patch)
treeac0c6932285989054cea2c5c8445f31c89364b6e /chrome/browser/automation
parent248e199c68b9e77b20450ef6851676bd43f8394c (diff)
downloadchromium_src-ac43f703a731d232ea095c28a5367f2cdd2bd7b2.zip
chromium_src-ac43f703a731d232ea095c28a5367f2cdd2bd7b2.tar.gz
chromium_src-ac43f703a731d232ea095c28a5367f2cdd2bd7b2.tar.bz2
Add pyauto hook for HTML5 notifications, tests, and helpers.
BUG=55125 TEST=none Review URL: http://codereview.chromium.org/3822001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@63935 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/automation')
-rw-r--r--chrome/browser/automation/automation_provider_observers.cc24
-rw-r--r--chrome/browser/automation/automation_provider_observers.h22
-rw-r--r--chrome/browser/automation/testing_automation_provider.cc88
-rw-r--r--chrome/browser/automation/testing_automation_provider.h18
4 files changed, 152 insertions, 0 deletions
diff --git a/chrome/browser/automation/automation_provider_observers.cc b/chrome/browser/automation/automation_provider_observers.cc
index 5bc5f1c..aeabd00 100644
--- a/chrome/browser/automation/automation_provider_observers.cc
+++ b/chrome/browser/automation/automation_provider_observers.cc
@@ -4,7 +4,10 @@
#include "chrome/browser/automation/automation_provider_observers.h"
+#include <deque>
+
#include "base/basictypes.h"
+#include "base/callback.h"
#include "base/json/json_writer.h"
#include "base/scoped_ptr.h"
#include "base/string_util.h"
@@ -23,6 +26,8 @@
#include "chrome/browser/extensions/extension_updater.h"
#include "chrome/browser/login_prompt.h"
#include "chrome/browser/metrics/metric_event_duration_details.h"
+#include "chrome/browser/notifications/balloon.h"
+#include "chrome/browser/notifications/balloon_collection.h"
#include "chrome/browser/printing/print_job.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/search_engines/template_url_model.h"
@@ -1346,3 +1351,22 @@ void AutocompleteEditFocusedObserver::Observe(
delete this;
}
+OnNotificationBalloonCountObserver::OnNotificationBalloonCountObserver(
+ AutomationProvider* provider,
+ IPC::Message* reply_message,
+ BalloonCollection* collection,
+ int count)
+ : reply_(provider, reply_message),
+ collection_(collection),
+ count_(count) {
+ collection->set_on_collection_changed_callback(NewCallback(
+ this, &OnNotificationBalloonCountObserver::OnBalloonCollectionChanged));
+}
+
+void OnNotificationBalloonCountObserver::OnBalloonCollectionChanged() {
+ if (static_cast<int>(collection_->GetActiveBalloons().size()) == count_) {
+ collection_->set_on_collection_changed_callback(NULL);
+ reply_.SendSuccess(NULL);
+ delete this;
+ }
+}
diff --git a/chrome/browser/automation/automation_provider_observers.h b/chrome/browser/automation/automation_provider_observers.h
index 5c7b77b..de20990 100644
--- a/chrome/browser/automation/automation_provider_observers.h
+++ b/chrome/browser/automation/automation_provider_observers.h
@@ -10,6 +10,7 @@
#include <map>
#include <set>
+#include "chrome/browser/automation/automation_provider_json.h"
#include "chrome/browser/bookmarks/bookmark_model_observer.h"
#include "chrome/browser/browsing_data_remover.h"
#include "chrome/browser/download/download_item.h"
@@ -27,6 +28,7 @@
class AutocompleteEditModel;
class AutomationProvider;
+class BalloonCollection;
class Browser;
class Extension;
class ExtensionProcessManager;
@@ -888,4 +890,24 @@ class AutocompleteEditFocusedObserver : public NotificationObserver {
DISALLOW_COPY_AND_ASSIGN(AutocompleteEditFocusedObserver);
};
+// Allows the automation provider to wait for a given number of
+// notification balloons.
+class OnNotificationBalloonCountObserver {
+ public:
+ OnNotificationBalloonCountObserver(AutomationProvider* provider,
+ IPC::Message* reply_message,
+ BalloonCollection* collection,
+ int count);
+
+ void OnBalloonCollectionChanged();
+
+ private:
+ AutomationJSONReply reply_;
+ BalloonCollection* collection_;
+ int count_;
+
+ DISALLOW_COPY_AND_ASSIGN(OnNotificationBalloonCountObserver);
+};
+
+
#endif // CHROME_BROWSER_AUTOMATION_AUTOMATION_PROVIDER_OBSERVERS_H_
diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc
index 75e064f..e62caae 100644
--- a/chrome/browser/automation/testing_automation_provider.cc
+++ b/chrome/browser/automation/testing_automation_provider.cc
@@ -59,6 +59,10 @@
#include "chrome/common/net/url_request_context_getter.h"
#include "chrome/common/notification_service.h"
#include "chrome/common/url_constants.h"
+#include "chrome/browser/notifications/balloon.h"
+#include "chrome/browser/notifications/balloon_collection.h"
+#include "chrome/browser/notifications/notification.h"
+#include "chrome/browser/notifications/notification_ui_manager.h"
#include "chrome/test/automation/automation_messages.h"
#include "net/base/cookie_store.h"
#include "net/url_request/url_request_context.h"
@@ -2096,6 +2100,13 @@ void TestingAutomationProvider::SendJSONRequest(int handle,
handler_map["FillAutoFillProfile"] =
&TestingAutomationProvider::FillAutoFillProfile;
+ handler_map["GetActiveNotifications"] =
+ &TestingAutomationProvider::GetActiveNotifications;
+ handler_map["CloseNotification"] =
+ &TestingAutomationProvider::CloseNotification;
+ handler_map["WaitForNotificationCount"] =
+ &TestingAutomationProvider::WaitForNotificationCount;
+
if (handler_map.find(std::string(command)) != handler_map.end()) {
(this->*handler_map[command])(browser, dict_value, reply_message);
} else {
@@ -3971,6 +3982,83 @@ std::map<AutoFillFieldType, std::wstring>
return credit_card_type_to_string;
}
+// Refer to GetActiveNotifications() in chrome/test/pyautolib/pyauto.py for
+// sample json input/output.
+void TestingAutomationProvider::GetActiveNotifications(
+ Browser* browser,
+ DictionaryValue* args,
+ IPC::Message* reply_message) {
+ NotificationUIManager* manager = g_browser_process->notification_ui_manager();
+ const BalloonCollection::Balloons& balloons =
+ manager->balloon_collection()->GetActiveBalloons();
+ scoped_ptr<DictionaryValue> return_value(new DictionaryValue);
+ ListValue* list = new ListValue;
+ return_value->Set("notifications", list);
+ BalloonCollection::Balloons::const_iterator iter;
+ for (iter = balloons.begin(); iter != balloons.end(); ++iter) {
+ const Notification& notification = (*iter)->notification();
+ DictionaryValue* balloon = new DictionaryValue;
+ balloon->SetString("content_url", notification.content_url().spec());
+ balloon->SetString("origin_url", notification.origin_url().spec());
+ balloon->SetString("display_source", notification.display_source());
+ list->Append(balloon);
+ }
+ AutomationJSONReply(this, reply_message).SendSuccess(return_value.get());
+}
+
+// Refer to CloseNotification() in chrome/test/pyautolib/pyauto.py for
+// sample json input.
+// Returns empty json message.
+void TestingAutomationProvider::CloseNotification(
+ Browser* browser,
+ DictionaryValue* args,
+ IPC::Message* reply_message) {
+ int index;
+ if (!args->GetInteger("index", &index)) {
+ AutomationJSONReply(this, reply_message).SendError(
+ "'index' missing or invalid.");
+ return;
+ }
+ NotificationUIManager* manager = g_browser_process->notification_ui_manager();
+ BalloonCollection* collection = manager->balloon_collection();
+ const BalloonCollection::Balloons& balloons = collection->GetActiveBalloons();
+ int balloon_count = static_cast<int>(balloons.size());
+ if (index < 0 || index >= balloon_count) {
+ AutomationJSONReply(this, reply_message).SendError(
+ StringPrintf("No notification at index %d", index));
+ return;
+ }
+ // This will delete itself when finished.
+ new OnNotificationBalloonCountObserver(
+ this, reply_message, collection, balloon_count - 1);
+ manager->Cancel(balloons[index]->notification());
+}
+
+// Refer to WaitForNotificationCount() in chrome/test/pyautolib/pyauto.py for
+// sample json input.
+// Returns empty json message.
+void TestingAutomationProvider::WaitForNotificationCount(
+ Browser* browser,
+ DictionaryValue* args,
+ IPC::Message* reply_message) {
+ int count;
+ if (!args->GetInteger("count", &count)) {
+ AutomationJSONReply(this, reply_message).SendError(
+ "'count' missing or invalid.");
+ return;
+ }
+ NotificationUIManager* manager = g_browser_process->notification_ui_manager();
+ BalloonCollection* collection = manager->balloon_collection();
+ const BalloonCollection::Balloons& balloons = collection->GetActiveBalloons();
+ if (static_cast<int>(balloons.size()) == count) {
+ AutomationJSONReply(this, reply_message).SendSuccess(NULL);
+ return;
+ }
+ // This will delete itself when finished.
+ new OnNotificationBalloonCountObserver(
+ this, reply_message, collection, count);
+}
+
void TestingAutomationProvider::WaitForTabCountToBecome(
int browser_handle,
int target_tab_count,
diff --git a/chrome/browser/automation/testing_automation_provider.h b/chrome/browser/automation/testing_automation_provider.h
index 9a0dec8..dc76603 100644
--- a/chrome/browser/automation/testing_automation_provider.h
+++ b/chrome/browser/automation/testing_automation_provider.h
@@ -637,6 +637,24 @@ class TestingAutomationProvider : public AutomationProvider,
static std::map<AutoFillFieldType, std::wstring>
GetCreditCardFieldToStringMap();
+ // Get a list of active HTML5 notifications.
+ // Uses the JSON interface for input/output.
+ void GetActiveNotifications(Browser* browser,
+ DictionaryValue* args,
+ IPC::Message* reply_message);
+
+ // Close an active HTML5 notification.
+ // Uses the JSON interface for input/output.
+ void CloseNotification(Browser* browser,
+ DictionaryValue* args,
+ IPC::Message* reply_message);
+
+ // Waits for the number of active HTML5 notifications to reach a given count.
+ // Uses the JSON interface for input/output.
+ void WaitForNotificationCount(Browser* browser,
+ DictionaryValue* args,
+ IPC::Message* reply_message);
+
void WaitForTabCountToBecome(int browser_handle,
int target_tab_count,
IPC::Message* reply_message);