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

Side by Side 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, 2 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "chrome/browser/automation/testing_automation_provider.h" 5 #include "chrome/browser/automation/testing_automation_provider.h"
6 6
7 #include "app/message_box_flags.h" 7 #include "app/message_box_flags.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/json/json_reader.h" 9 #include "base/json/json_reader.h"
10 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
(...skipping 19 matching lines...) Expand all
30 #include "chrome/browser/blocked_popup_container.h" 30 #include "chrome/browser/blocked_popup_container.h"
31 #include "chrome/browser/browser_process.h" 31 #include "chrome/browser/browser_process.h"
32 #include "chrome/browser/browser_shutdown.h" 32 #include "chrome/browser/browser_shutdown.h"
33 #include "chrome/browser/browser_window.h" 33 #include "chrome/browser/browser_window.h"
34 #include "chrome/browser/debugger/devtools_manager.h" 34 #include "chrome/browser/debugger/devtools_manager.h"
35 #include "chrome/browser/download/download_prefs.h" 35 #include "chrome/browser/download/download_prefs.h"
36 #include "chrome/browser/download/download_shelf.h" 36 #include "chrome/browser/download/download_shelf.h"
37 #include "chrome/browser/extensions/extension_host.h" 37 #include "chrome/browser/extensions/extension_host.h"
38 #include "chrome/browser/extensions/extensions_service.h" 38 #include "chrome/browser/extensions/extensions_service.h"
39 #include "chrome/browser/find_bar.h" 39 #include "chrome/browser/find_bar.h"
40 #include "chrome/browser/history/top_sites.h"
40 #include "chrome/browser/location_bar.h" 41 #include "chrome/browser/location_bar.h"
41 #include "chrome/browser/login_prompt.h" 42 #include "chrome/browser/login_prompt.h"
42 #include "chrome/browser/native_app_modal_dialog.h" 43 #include "chrome/browser/native_app_modal_dialog.h"
43 #include "chrome/browser/profile.h" 44 #include "chrome/browser/profile.h"
44 #include "chrome/browser/platform_util.h" 45 #include "chrome/browser/platform_util.h"
45 #include "chrome/browser/prefs/pref_service.h" 46 #include "chrome/browser/prefs/pref_service.h"
46 #include "chrome/browser/profile_manager.h" 47 #include "chrome/browser/profile_manager.h"
47 #include "chrome/browser/renderer_host/render_process_host.h" 48 #include "chrome/browser/renderer_host/render_process_host.h"
48 #include "chrome/browser/renderer_host/render_view_host.h" 49 #include "chrome/browser/renderer_host/render_view_host.h"
49 #include "chrome/browser/search_engines/template_url.h" 50 #include "chrome/browser/search_engines/template_url.h"
(...skipping 2051 matching lines...) Expand 10 before | Expand all | Expand 10 after
2101 handler_map["SelectTranslateOption"] = 2102 handler_map["SelectTranslateOption"] =
2102 &TestingAutomationProvider::SelectTranslateOption; 2103 &TestingAutomationProvider::SelectTranslateOption;
2103 handler_map["GetTranslateInfo"] = 2104 handler_map["GetTranslateInfo"] =
2104 &TestingAutomationProvider::GetTranslateInfo; 2105 &TestingAutomationProvider::GetTranslateInfo;
2105 2106
2106 handler_map["GetAutoFillProfile"] = 2107 handler_map["GetAutoFillProfile"] =
2107 &TestingAutomationProvider::GetAutoFillProfile; 2108 &TestingAutomationProvider::GetAutoFillProfile;
2108 handler_map["FillAutoFillProfile"] = 2109 handler_map["FillAutoFillProfile"] =
2109 &TestingAutomationProvider::FillAutoFillProfile; 2110 &TestingAutomationProvider::FillAutoFillProfile;
2110 2111
2112 handler_map["GetNTPInfo"] =
2113 &TestingAutomationProvider::GetNTPInfo;
2114 handler_map["MoveNTPMostVisitedThumbnail"] =
2115 &TestingAutomationProvider::MoveNTPMostVisitedThumbnail;
2116 handler_map["RemoveNTPMostVisitedThumbnail"] =
2117 &TestingAutomationProvider::RemoveNTPMostVisitedThumbnail;
2118 handler_map["UnpinNTPMostVisitedThumbnail"] =
2119 &TestingAutomationProvider::UnpinNTPMostVisitedThumbnail;
2120 handler_map["RestoreAllNTPMostVisitedThumbnails"] =
2121 &TestingAutomationProvider::RestoreAllNTPMostVisitedThumbnails;
2122
2111 if (handler_map.find(std::string(command)) != handler_map.end()) { 2123 if (handler_map.find(std::string(command)) != handler_map.end()) {
2112 (this->*handler_map[command])(browser, dict_value, reply_message); 2124 (this->*handler_map[command])(browser, dict_value, reply_message);
2113 } else { 2125 } else {
2114 std::string error_string = "Unknown command. Options: "; 2126 std::string error_string = "Unknown command. Options: ";
2115 for (std::map<std::string, JsonHandler>::const_iterator it = 2127 for (std::map<std::string, JsonHandler>::const_iterator it =
2116 handler_map.begin(); it != handler_map.end(); ++it) { 2128 handler_map.begin(); it != handler_map.end(); ++it) {
2117 error_string += it->first + ", "; 2129 error_string += it->first + ", ";
2118 } 2130 }
2119 AutomationJSONReply(this, reply_message).SendError(error_string); 2131 AutomationJSONReply(this, reply_message).SendError(error_string);
2120 } 2132 }
(...skipping 1636 matching lines...) Expand 10 before | Expand all | Expand 10 after
3757 TestingAutomationProvider::GetCreditCardFieldToStringMap() { 3769 TestingAutomationProvider::GetCreditCardFieldToStringMap() {
3758 std::map<AutoFillFieldType, std::wstring> credit_card_type_to_string; 3770 std::map<AutoFillFieldType, std::wstring> credit_card_type_to_string;
3759 credit_card_type_to_string[CREDIT_CARD_NAME] = L"CREDIT_CARD_NAME"; 3771 credit_card_type_to_string[CREDIT_CARD_NAME] = L"CREDIT_CARD_NAME";
3760 credit_card_type_to_string[CREDIT_CARD_NUMBER] = L"CREDIT_CARD_NUMBER"; 3772 credit_card_type_to_string[CREDIT_CARD_NUMBER] = L"CREDIT_CARD_NUMBER";
3761 credit_card_type_to_string[CREDIT_CARD_EXP_MONTH] = L"CREDIT_CARD_EXP_MONTH"; 3773 credit_card_type_to_string[CREDIT_CARD_EXP_MONTH] = L"CREDIT_CARD_EXP_MONTH";
3762 credit_card_type_to_string[CREDIT_CARD_EXP_4_DIGIT_YEAR] = 3774 credit_card_type_to_string[CREDIT_CARD_EXP_4_DIGIT_YEAR] =
3763 L"CREDIT_CARD_EXP_4_DIGIT_YEAR"; 3775 L"CREDIT_CARD_EXP_4_DIGIT_YEAR";
3764 return credit_card_type_to_string; 3776 return credit_card_type_to_string;
3765 } 3777 }
3766 3778
3779 // Sample JSON input: { "command": "GetNTPInfo" }
3780 // For output, refer to chrome/test/pyautolib/ntp_model.py.
3781 void TestingAutomationProvider::GetNTPInfo(
3782 Browser* browser,
3783 DictionaryValue* args,
3784 IPC::Message* reply_message) {
3785 // This observer will delete itself.
3786 new NTPInfoObserver(this, reply_message, &consumer_);
3787 }
3788
3789 void TestingAutomationProvider::MoveNTPMostVisitedThumbnail(
3790 Browser* browser,
3791 DictionaryValue* args,
3792 IPC::Message* reply_message) {
3793 AutomationJSONReply reply(this, reply_message);
3794 std::string url, error;
3795 int index, old_index;
3796 if (!args->GetString("url", &url)) {
3797 reply.SendError("No 'url' key.");
3798 return;
3799 }
3800 if (!args->GetInteger("index", &index)) {
3801 reply.SendError("No 'index' key.");
3802 return;
3803 }
3804 if (!args->GetInteger("old_index", &old_index)) {
3805 reply.SendError("No 'old_index' key");
3806 return;
3807 }
3808 history::TopSites* top_sites = browser->profile()->GetTopSites();
3809 if (!top_sites) {
3810 reply.SendError("No TopSites.");
3811 return;
3812 }
3813 GURL swapped;
3814 // If thumbnail A is switching positions with a pinned thumbnail B, B
3815 // should be pinned in the old index of A.
3816 if (top_sites->GetPinnedURLAtIndex(index, &swapped)) {
3817 top_sites->AddPinnedURL(swapped, old_index);
3818 }
3819 top_sites->AddPinnedURL(GURL(url), index);
3820 reply.SendSuccess(NULL);
3821 }
3822
3823 void TestingAutomationProvider::RemoveNTPMostVisitedThumbnail(
3824 Browser* browser,
3825 DictionaryValue* args,
3826 IPC::Message* reply_message) {
3827 AutomationJSONReply reply(this, reply_message);
3828 std::string url;
3829 if (!args->GetString("url", &url)) {
3830 reply.SendError("No 'url' key.");
3831 return;
3832 }
3833 history::TopSites* top_sites = browser->profile()->GetTopSites();
3834 if (!top_sites) {
3835 reply.SendError("No TopSites.");
3836 return;
3837 }
3838 top_sites->AddBlacklistedURL(GURL(url));
3839 reply.SendSuccess(NULL);
3840 }
3841
3842 void TestingAutomationProvider::UnpinNTPMostVisitedThumbnail(
3843 Browser* browser,
3844 DictionaryValue* args,
3845 IPC::Message* reply_message) {
3846 AutomationJSONReply reply(this, reply_message);
3847 std::string url;
3848 if (!args->GetString("url", &url)) {
3849 reply.SendError("No 'url' key.");
3850 return;
3851 }
3852 history::TopSites* top_sites = browser->profile()->GetTopSites();
3853 if (!top_sites) {
3854 reply.SendError("No TopSites.");
3855 return;
3856 }
3857 top_sites->RemovePinnedURL(GURL(url));
3858 reply.SendSuccess(NULL);
3859 }
3860
3861 void TestingAutomationProvider::RestoreAllNTPMostVisitedThumbnails(
3862 Browser* browser,
3863 DictionaryValue* args,
3864 IPC::Message* reply_message) {
3865 AutomationJSONReply reply(this, reply_message);
3866 history::TopSites* top_sites = browser->profile()->GetTopSites();
3867 if (!top_sites) {
3868 reply.SendError("No TopSites.");
3869 return;
3870 }
3871 top_sites->ClearBlacklistedURLs();
3872 reply.SendSuccess(NULL);
3873 }
3874
3767 void TestingAutomationProvider::WaitForTabCountToBecome( 3875 void TestingAutomationProvider::WaitForTabCountToBecome(
3768 int browser_handle, 3876 int browser_handle,
3769 int target_tab_count, 3877 int target_tab_count,
3770 IPC::Message* reply_message) { 3878 IPC::Message* reply_message) {
3771 if (!browser_tracker_->ContainsHandle(browser_handle)) { 3879 if (!browser_tracker_->ContainsHandle(browser_handle)) {
3772 AutomationMsg_WaitForTabCountToBecome::WriteReplyParams(reply_message, 3880 AutomationMsg_WaitForTabCountToBecome::WriteReplyParams(reply_message,
3773 false); 3881 false);
3774 Send(reply_message); 3882 Send(reply_message);
3775 return; 3883 return;
3776 } 3884 }
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
3897 DCHECK(type == NotificationType::SESSION_END); 4005 DCHECK(type == NotificationType::SESSION_END);
3898 // OnBrowserRemoving does a ReleaseLater. When session end is received we exit 4006 // OnBrowserRemoving does a ReleaseLater. When session end is received we exit
3899 // before the task runs resulting in this object not being deleted. This 4007 // before the task runs resulting in this object not being deleted. This
3900 // Release balance out the Release scheduled by OnBrowserRemoving. 4008 // Release balance out the Release scheduled by OnBrowserRemoving.
3901 Release(); 4009 Release();
3902 } 4010 }
3903 4011
3904 void TestingAutomationProvider::OnRemoveProvider() { 4012 void TestingAutomationProvider::OnRemoveProvider() {
3905 AutomationProviderList::GetInstance()->RemoveProvider(this); 4013 AutomationProviderList::GetInstance()->RemoveProvider(this);
3906 } 4014 }
OLDNEW
« 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