Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(376)

Unified Diff: chrome/browser/automation/testing_automation_provider.cc

Issue 3477001: Add pyauto hook for getting and manipulating the data underneath the NTP.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/automation/testing_automation_provider.h ('k') | chrome/browser/dom_ui/new_tab_ui.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/automation/testing_automation_provider.cc
===================================================================
--- chrome/browser/automation/testing_automation_provider.cc (revision 61074)
+++ chrome/browser/automation/testing_automation_provider.cc (working copy)
@@ -37,6 +37,7 @@
#include "chrome/browser/extensions/extension_host.h"
#include "chrome/browser/extensions/extensions_service.h"
#include "chrome/browser/find_bar.h"
+#include "chrome/browser/history/top_sites.h"
#include "chrome/browser/location_bar.h"
#include "chrome/browser/login_prompt.h"
#include "chrome/browser/native_app_modal_dialog.h"
@@ -2108,6 +2109,17 @@
handler_map["FillAutoFillProfile"] =
&TestingAutomationProvider::FillAutoFillProfile;
+ handler_map["GetNTPInfo"] =
+ &TestingAutomationProvider::GetNTPInfo;
+ handler_map["MoveNTPMostVisitedThumbnail"] =
+ &TestingAutomationProvider::MoveNTPMostVisitedThumbnail;
+ handler_map["RemoveNTPMostVisitedThumbnail"] =
+ &TestingAutomationProvider::RemoveNTPMostVisitedThumbnail;
+ handler_map["UnpinNTPMostVisitedThumbnail"] =
+ &TestingAutomationProvider::UnpinNTPMostVisitedThumbnail;
+ handler_map["RestoreAllNTPMostVisitedThumbnails"] =
+ &TestingAutomationProvider::RestoreAllNTPMostVisitedThumbnails;
+
if (handler_map.find(std::string(command)) != handler_map.end()) {
(this->*handler_map[command])(browser, dict_value, reply_message);
} else {
@@ -3764,6 +3776,102 @@
return credit_card_type_to_string;
}
+// Sample JSON input: { "command": "GetNTPInfo" }
+// For output, refer to chrome/test/pyautolib/ntp_model.py.
+void TestingAutomationProvider::GetNTPInfo(
+ Browser* browser,
+ DictionaryValue* args,
+ IPC::Message* reply_message) {
+ // This observer will delete itself.
+ new NTPInfoObserver(this, reply_message, &consumer_);
+}
+
+void TestingAutomationProvider::MoveNTPMostVisitedThumbnail(
+ Browser* browser,
+ DictionaryValue* args,
+ IPC::Message* reply_message) {
+ AutomationJSONReply reply(this, reply_message);
+ std::string url, error;
+ int index, old_index;
+ if (!args->GetString("url", &url)) {
+ reply.SendError("No 'url' key.");
+ return;
+ }
+ if (!args->GetInteger("index", &index)) {
+ reply.SendError("No 'index' key.");
+ return;
+ }
+ if (!args->GetInteger("old_index", &old_index)) {
+ reply.SendError("No 'old_index' key");
+ return;
+ }
+ history::TopSites* top_sites = browser->profile()->GetTopSites();
+ if (!top_sites) {
+ reply.SendError("No TopSites.");
+ return;
+ }
+ GURL swapped;
+ // If thumbnail A is switching positions with a pinned thumbnail B, B
+ // should be pinned in the old index of A.
+ if (top_sites->GetPinnedURLAtIndex(index, &swapped)) {
+ top_sites->AddPinnedURL(swapped, old_index);
+ }
+ top_sites->AddPinnedURL(GURL(url), index);
+ reply.SendSuccess(NULL);
+}
+
+void TestingAutomationProvider::RemoveNTPMostVisitedThumbnail(
+ Browser* browser,
+ DictionaryValue* args,
+ IPC::Message* reply_message) {
+ AutomationJSONReply reply(this, reply_message);
+ std::string url;
+ if (!args->GetString("url", &url)) {
+ reply.SendError("No 'url' key.");
+ return;
+ }
+ history::TopSites* top_sites = browser->profile()->GetTopSites();
+ if (!top_sites) {
+ reply.SendError("No TopSites.");
+ return;
+ }
+ top_sites->AddBlacklistedURL(GURL(url));
+ reply.SendSuccess(NULL);
+}
+
+void TestingAutomationProvider::UnpinNTPMostVisitedThumbnail(
+ Browser* browser,
+ DictionaryValue* args,
+ IPC::Message* reply_message) {
+ AutomationJSONReply reply(this, reply_message);
+ std::string url;
+ if (!args->GetString("url", &url)) {
+ reply.SendError("No 'url' key.");
+ return;
+ }
+ history::TopSites* top_sites = browser->profile()->GetTopSites();
+ if (!top_sites) {
+ reply.SendError("No TopSites.");
+ return;
+ }
+ top_sites->RemovePinnedURL(GURL(url));
+ reply.SendSuccess(NULL);
+}
+
+void TestingAutomationProvider::RestoreAllNTPMostVisitedThumbnails(
+ Browser* browser,
+ DictionaryValue* args,
+ IPC::Message* reply_message) {
+ AutomationJSONReply reply(this, reply_message);
+ history::TopSites* top_sites = browser->profile()->GetTopSites();
+ if (!top_sites) {
+ reply.SendError("No TopSites.");
+ return;
+ }
+ top_sites->ClearBlacklistedURLs();
+ reply.SendSuccess(NULL);
+}
+
void TestingAutomationProvider::WaitForTabCountToBecome(
int browser_handle,
int target_tab_count,
« no previous file with comments | « chrome/browser/automation/testing_automation_provider.h ('k') | chrome/browser/dom_ui/new_tab_ui.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698