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

Side by Side Diff: chrome/browser/automation/testing_automation_provider.cc

Issue 10866013: Convert the browsing_data pyauto tests to chrome tests. Remove the ClearBrowsingData automation cod… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix hang on mac Created 8 years, 4 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <map> 7 #include <map>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 23 matching lines...) Expand all
34 #include "chrome/browser/automation/automation_provider_list.h" 34 #include "chrome/browser/automation/automation_provider_list.h"
35 #include "chrome/browser/automation/automation_provider_observers.h" 35 #include "chrome/browser/automation/automation_provider_observers.h"
36 #include "chrome/browser/automation/automation_tab_tracker.h" 36 #include "chrome/browser/automation/automation_tab_tracker.h"
37 #include "chrome/browser/automation/automation_util.h" 37 #include "chrome/browser/automation/automation_util.h"
38 #include "chrome/browser/automation/automation_window_tracker.h" 38 #include "chrome/browser/automation/automation_window_tracker.h"
39 #include "chrome/browser/bookmarks/bookmark_model.h" 39 #include "chrome/browser/bookmarks/bookmark_model.h"
40 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 40 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
41 #include "chrome/browser/bookmarks/bookmark_storage.h" 41 #include "chrome/browser/bookmarks/bookmark_storage.h"
42 #include "chrome/browser/browser_process.h" 42 #include "chrome/browser/browser_process.h"
43 #include "chrome/browser/browser_shutdown.h" 43 #include "chrome/browser/browser_shutdown.h"
44 #include "chrome/browser/browsing_data/browsing_data_helper.h"
45 #include "chrome/browser/browsing_data/browsing_data_remover.h"
46 #include "chrome/browser/content_settings/host_content_settings_map.h" 44 #include "chrome/browser/content_settings/host_content_settings_map.h"
47 #include "chrome/browser/debugger/devtools_window.h" 45 #include "chrome/browser/debugger/devtools_window.h"
48 #include "chrome/browser/download/download_prefs.h" 46 #include "chrome/browser/download/download_prefs.h"
49 #include "chrome/browser/download/download_service.h" 47 #include "chrome/browser/download/download_service.h"
50 #include "chrome/browser/download/download_service_factory.h" 48 #include "chrome/browser/download/download_service_factory.h"
51 #include "chrome/browser/download/download_shelf.h" 49 #include "chrome/browser/download/download_shelf.h"
52 #include "chrome/browser/download/save_package_file_picker.h" 50 #include "chrome/browser/download/save_package_file_picker.h"
53 #include "chrome/browser/extensions/browser_action_test_util.h" 51 #include "chrome/browser/extensions/browser_action_test_util.h"
54 #include "chrome/browser/extensions/crx_installer.h" 52 #include "chrome/browser/extensions/crx_installer.h"
55 #include "chrome/browser/extensions/extension_host.h" 53 #include "chrome/browser/extensions/extension_host.h"
(...skipping 1874 matching lines...) Expand 10 before | Expand all | Expand 10 after
1930 browser_handler_map_["ImportSettings"] = 1928 browser_handler_map_["ImportSettings"] =
1931 &TestingAutomationProvider::ImportSettings; 1929 &TestingAutomationProvider::ImportSettings;
1932 1930
1933 browser_handler_map_["AddSavedPassword"] = 1931 browser_handler_map_["AddSavedPassword"] =
1934 &TestingAutomationProvider::AddSavedPassword; 1932 &TestingAutomationProvider::AddSavedPassword;
1935 browser_handler_map_["RemoveSavedPassword"] = 1933 browser_handler_map_["RemoveSavedPassword"] =
1936 &TestingAutomationProvider::RemoveSavedPassword; 1934 &TestingAutomationProvider::RemoveSavedPassword;
1937 browser_handler_map_["GetSavedPasswords"] = 1935 browser_handler_map_["GetSavedPasswords"] =
1938 &TestingAutomationProvider::GetSavedPasswords; 1936 &TestingAutomationProvider::GetSavedPasswords;
1939 1937
1940 browser_handler_map_["ClearBrowsingData"] =
1941 &TestingAutomationProvider::ClearBrowsingData;
1942
1943 browser_handler_map_["GetBlockedPopupsInfo"] = 1938 browser_handler_map_["GetBlockedPopupsInfo"] =
1944 &TestingAutomationProvider::GetBlockedPopupsInfo; 1939 &TestingAutomationProvider::GetBlockedPopupsInfo;
1945 browser_handler_map_["UnblockAndLaunchBlockedPopup"] = 1940 browser_handler_map_["UnblockAndLaunchBlockedPopup"] =
1946 &TestingAutomationProvider::UnblockAndLaunchBlockedPopup; 1941 &TestingAutomationProvider::UnblockAndLaunchBlockedPopup;
1947 handler_map_["ResetToDefaultTheme"] = 1942 handler_map_["ResetToDefaultTheme"] =
1948 &TestingAutomationProvider::ResetToDefaultTheme; 1943 &TestingAutomationProvider::ResetToDefaultTheme;
1949 1944
1950 // SetTheme() implemented using InstallExtension(). 1945 // SetTheme() implemented using InstallExtension().
1951 browser_handler_map_["GetThemeInfo"] = 1946 browser_handler_map_["GetThemeInfo"] =
1952 &TestingAutomationProvider::GetThemeInfo; 1947 &TestingAutomationProvider::GetThemeInfo;
(...skipping 1723 matching lines...) Expand 10 before | Expand all | Expand 10 after
3676 if (password_store == NULL) { 3671 if (password_store == NULL) {
3677 AutomationJSONReply reply(this, reply_message); 3672 AutomationJSONReply reply(this, reply_message);
3678 reply.SendError("Unable to get password store."); 3673 reply.SendError("Unable to get password store.");
3679 return; 3674 return;
3680 } 3675 }
3681 password_store->GetAutofillableLogins( 3676 password_store->GetAutofillableLogins(
3682 new AutomationProviderGetPasswordsObserver(this, reply_message)); 3677 new AutomationProviderGetPasswordsObserver(this, reply_message));
3683 // Observer deletes itself after sending the result. 3678 // Observer deletes itself after sending the result.
3684 } 3679 }
3685 3680
3686 // Refer to ClearBrowsingData() in chrome/test/pyautolib/pyauto.py for sample
3687 // json input.
3688 // Sample json output: {}
3689 void TestingAutomationProvider::ClearBrowsingData(
3690 Browser* browser,
3691 DictionaryValue* args,
3692 IPC::Message* reply_message) {
3693 std::map<std::string, BrowsingDataRemover::TimePeriod> string_to_time_period;
3694 string_to_time_period["LAST_HOUR"] = BrowsingDataRemover::LAST_HOUR;
3695 string_to_time_period["LAST_DAY"] = BrowsingDataRemover::LAST_DAY;
3696 string_to_time_period["LAST_WEEK"] = BrowsingDataRemover::LAST_WEEK;
3697 string_to_time_period["FOUR_WEEKS"] = BrowsingDataRemover::FOUR_WEEKS;
3698 string_to_time_period["EVERYTHING"] = BrowsingDataRemover::EVERYTHING;
3699
3700 std::map<std::string, int> string_to_mask_value;
3701 string_to_mask_value["HISTORY"] = BrowsingDataRemover::REMOVE_HISTORY;
3702 string_to_mask_value["DOWNLOADS"] = BrowsingDataRemover::REMOVE_DOWNLOADS;
3703 string_to_mask_value["COOKIES"] = BrowsingDataRemover::REMOVE_SITE_DATA;
3704 string_to_mask_value["PASSWORDS"] = BrowsingDataRemover::REMOVE_PASSWORDS;
3705 string_to_mask_value["FORM_DATA"] = BrowsingDataRemover::REMOVE_FORM_DATA;
3706 string_to_mask_value["CACHE"] = BrowsingDataRemover::REMOVE_CACHE;
3707
3708 std::string time_period;
3709 ListValue* to_remove;
3710 if (!args->GetString("time_period", &time_period) ||
3711 !args->GetList("to_remove", &to_remove)) {
3712 AutomationJSONReply(this, reply_message)
3713 .SendError("time_period must be a string and to_remove a list.");
3714 return;
3715 }
3716
3717 int remove_mask = 0;
3718 int num_removals = to_remove->GetSize();
3719 for (int i = 0; i < num_removals; i++) {
3720 std::string removal;
3721 // If the provided string is not part of the map, then error out.
3722 if (!to_remove->GetString(i, &removal) ||
3723 !ContainsKey(string_to_mask_value, removal)) {
3724 AutomationJSONReply(this, reply_message)
3725 .SendError("Invalid browsing data string found in to_remove.");
3726 return;
3727 }
3728 remove_mask |= string_to_mask_value[removal];
3729 }
3730
3731 if (!ContainsKey(string_to_time_period, time_period)) {
3732 AutomationJSONReply(this, reply_message)
3733 .SendError("Invalid string for time_period.");
3734 return;
3735 }
3736
3737 BrowsingDataRemover* remover = new BrowsingDataRemover(
3738 profile(), string_to_time_period[time_period], base::Time::Now());
3739
3740 remover->AddObserver(
3741 new AutomationProviderBrowsingDataObserver(this, reply_message));
3742 remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB);
3743 // BrowsingDataRemover deletes itself using DeleteHelper.
3744 // The observer also deletes itself after sending the reply.
3745 }
3746
3747 namespace { 3681 namespace {
3748 3682
3749 // Get the TabContents from a dictionary of arguments. 3683 // Get the TabContents from a dictionary of arguments.
3750 TabContents* GetTabContentsFromDict(const Browser* browser, 3684 TabContents* GetTabContentsFromDict(const Browser* browser,
3751 const DictionaryValue* args, 3685 const DictionaryValue* args,
3752 std::string* error_message) { 3686 std::string* error_message) {
3753 int tab_index; 3687 int tab_index;
3754 if (!args->GetInteger("tab_index", &tab_index)) { 3688 if (!args->GetInteger("tab_index", &tab_index)) {
3755 *error_message = "Must include tab_index."; 3689 *error_message = "Must include tab_index.";
3756 return NULL; 3690 return NULL;
(...skipping 3045 matching lines...) Expand 10 before | Expand all | Expand 10 after
6802 void TestingAutomationProvider::OnRemoveProvider() { 6736 void TestingAutomationProvider::OnRemoveProvider() {
6803 if (g_browser_process) 6737 if (g_browser_process)
6804 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); 6738 g_browser_process->GetAutomationProviderList()->RemoveProvider(this);
6805 } 6739 }
6806 6740
6807 void TestingAutomationProvider::EnsureTabSelected(Browser* browser, 6741 void TestingAutomationProvider::EnsureTabSelected(Browser* browser,
6808 WebContents* tab) { 6742 WebContents* tab) {
6809 if (chrome::GetActiveWebContents(browser) != tab) 6743 if (chrome::GetActiveWebContents(browser) != tab)
6810 chrome::ActivateTabAt(browser, chrome::GetIndexOfTab(browser, tab), true); 6744 chrome::ActivateTabAt(browser, chrome::GetIndexOfTab(browser, tab), true);
6811 } 6745 }
OLDNEW
« no previous file with comments | « chrome/browser/automation/testing_automation_provider.h ('k') | chrome/browser/browsing_data/browsing_data_remover.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698