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

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

Issue 10855253: Convert the autofill pyauto tests to browser tests, and remove all the supporting automation hooks … (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: review comments 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 11 matching lines...) Expand all
22 #include "base/stringprintf.h" 22 #include "base/stringprintf.h"
23 #include "base/threading/thread_restrictions.h" 23 #include "base/threading/thread_restrictions.h"
24 #include "base/time.h" 24 #include "base/time.h"
25 #include "base/utf_string_conversions.h" 25 #include "base/utf_string_conversions.h"
26 #include "chrome/app/chrome_command_ids.h" 26 #include "chrome/app/chrome_command_ids.h"
27 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" 27 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h"
28 #include "chrome/browser/api/infobars/link_infobar_delegate.h" 28 #include "chrome/browser/api/infobars/link_infobar_delegate.h"
29 #include "chrome/browser/autocomplete/autocomplete_controller.h" 29 #include "chrome/browser/autocomplete/autocomplete_controller.h"
30 #include "chrome/browser/autocomplete/autocomplete_match.h" 30 #include "chrome/browser/autocomplete/autocomplete_match.h"
31 #include "chrome/browser/autocomplete/autocomplete_result.h" 31 #include "chrome/browser/autocomplete/autocomplete_result.h"
32 #include "chrome/browser/autofill/autofill_manager.h"
33 #include "chrome/browser/autofill/credit_card.h"
34 #include "chrome/browser/autofill/personal_data_manager.h"
35 #include "chrome/browser/autofill/personal_data_manager_factory.h"
36 #include "chrome/browser/automation/automation_browser_tracker.h" 32 #include "chrome/browser/automation/automation_browser_tracker.h"
37 #include "chrome/browser/automation/automation_provider_json.h" 33 #include "chrome/browser/automation/automation_provider_json.h"
38 #include "chrome/browser/automation/automation_provider_list.h" 34 #include "chrome/browser/automation/automation_provider_list.h"
39 #include "chrome/browser/automation/automation_provider_observers.h" 35 #include "chrome/browser/automation/automation_provider_observers.h"
40 #include "chrome/browser/automation/automation_tab_tracker.h" 36 #include "chrome/browser/automation/automation_tab_tracker.h"
41 #include "chrome/browser/automation/automation_util.h" 37 #include "chrome/browser/automation/automation_util.h"
42 #include "chrome/browser/automation/automation_window_tracker.h" 38 #include "chrome/browser/automation/automation_window_tracker.h"
43 #include "chrome/browser/bookmarks/bookmark_model.h" 39 #include "chrome/browser/bookmarks/bookmark_model.h"
44 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 40 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
45 #include "chrome/browser/bookmarks/bookmark_storage.h" 41 #include "chrome/browser/bookmarks/bookmark_storage.h"
(...skipping 1909 matching lines...) Expand 10 before | Expand all | Expand 10 after
1955 browser_handler_map_["GetThemeInfo"] = 1951 browser_handler_map_["GetThemeInfo"] =
1956 &TestingAutomationProvider::GetThemeInfo; 1952 &TestingAutomationProvider::GetThemeInfo;
1957 1953
1958 browser_handler_map_["FindInPage"] = &TestingAutomationProvider::FindInPage; 1954 browser_handler_map_["FindInPage"] = &TestingAutomationProvider::FindInPage;
1959 1955
1960 browser_handler_map_["SelectTranslateOption"] = 1956 browser_handler_map_["SelectTranslateOption"] =
1961 &TestingAutomationProvider::SelectTranslateOption; 1957 &TestingAutomationProvider::SelectTranslateOption;
1962 browser_handler_map_["GetTranslateInfo"] = 1958 browser_handler_map_["GetTranslateInfo"] =
1963 &TestingAutomationProvider::GetTranslateInfo; 1959 &TestingAutomationProvider::GetTranslateInfo;
1964 1960
1965 browser_handler_map_["GetAutofillProfile"] =
1966 &TestingAutomationProvider::GetAutofillProfile;
1967 browser_handler_map_["FillAutofillProfile"] =
1968 &TestingAutomationProvider::FillAutofillProfile;
1969 browser_handler_map_["SubmitAutofillForm"] =
1970 &TestingAutomationProvider::SubmitAutofillForm;
1971 browser_handler_map_["AutofillTriggerSuggestions"] =
1972 &TestingAutomationProvider::AutofillTriggerSuggestions;
1973 browser_handler_map_["AutofillHighlightSuggestion"] =
1974 &TestingAutomationProvider::AutofillHighlightSuggestion;
1975 browser_handler_map_["AutofillAcceptSelection"] =
1976 &TestingAutomationProvider::AutofillAcceptSelection;
1977
1978 browser_handler_map_["GetAllNotifications"] = 1961 browser_handler_map_["GetAllNotifications"] =
1979 &TestingAutomationProvider::GetAllNotifications; 1962 &TestingAutomationProvider::GetAllNotifications;
1980 browser_handler_map_["CloseNotification"] = 1963 browser_handler_map_["CloseNotification"] =
1981 &TestingAutomationProvider::CloseNotification; 1964 &TestingAutomationProvider::CloseNotification;
1982 browser_handler_map_["WaitForNotificationCount"] = 1965 browser_handler_map_["WaitForNotificationCount"] =
1983 &TestingAutomationProvider::WaitForNotificationCount; 1966 &TestingAutomationProvider::WaitForNotificationCount;
1984 1967
1985 browser_handler_map_["SignInToSync"] = 1968 browser_handler_map_["SignInToSync"] =
1986 &TestingAutomationProvider::SignInToSync; 1969 &TestingAutomationProvider::SignInToSync;
1987 browser_handler_map_["GetSyncInfo"] = 1970 browser_handler_map_["GetSyncInfo"] =
(...skipping 2692 matching lines...) Expand 10 before | Expand all | Expand 10 after
4680 if (!args->GetString("switch", &switch_name) || 4663 if (!args->GetString("switch", &switch_name) ||
4681 !args->GetString("value", &switch_value)) { 4664 !args->GetString("value", &switch_value)) {
4682 reply.SendError("Missing or invalid command line switch"); 4665 reply.SendError("Missing or invalid command line switch");
4683 return; 4666 return;
4684 } 4667 }
4685 CommandLine::ForCurrentProcess()->AppendSwitchASCII(switch_name, 4668 CommandLine::ForCurrentProcess()->AppendSwitchASCII(switch_name,
4686 switch_value); 4669 switch_value);
4687 reply.SendSuccess(NULL); 4670 reply.SendSuccess(NULL);
4688 } 4671 }
4689 4672
4690 // Sample json input:
4691 // { "command": "GetAutofillProfile" }
4692 // Refer to GetAutofillProfile() in chrome/test/pyautolib/pyauto.py for sample
4693 // json output.
4694 void TestingAutomationProvider::GetAutofillProfile(
4695 Browser* browser,
4696 DictionaryValue* args,
4697 IPC::Message* reply_message) {
4698 AutomationJSONReply reply(this, reply_message);
4699 // Get the AutofillProfiles currently in the database.
4700 int tab_index = 0;
4701 if (!args->GetInteger("tab_index", &tab_index)) {
4702 reply.SendError("Invalid or missing tab_index integer value.");
4703 return;
4704 }
4705
4706 TabContents* tab_contents = chrome::GetTabContentsAt(browser, tab_index);
4707 if (tab_contents) {
4708 PersonalDataManager* pdm = PersonalDataManagerFactory::GetForProfile(
4709 tab_contents->profile()->GetOriginalProfile());
4710 if (pdm) {
4711 std::vector<AutofillProfile*> autofill_profiles = pdm->profiles();
4712 std::vector<CreditCard*> credit_cards = pdm->credit_cards();
4713
4714 ListValue* profiles = GetListFromAutofillProfiles(autofill_profiles);
4715 ListValue* cards = GetListFromCreditCards(credit_cards);
4716
4717 scoped_ptr<DictionaryValue> return_value(new DictionaryValue);
4718
4719 return_value->Set("profiles", profiles);
4720 return_value->Set("credit_cards", cards);
4721 reply.SendSuccess(return_value.get());
4722 } else {
4723 reply.SendError("No PersonalDataManager.");
4724 return;
4725 }
4726 } else {
4727 reply.SendError("No tab at that index.");
4728 return;
4729 }
4730 }
4731
4732 // Refer to FillAutofillProfile() in chrome/test/pyautolib/pyauto.py for sample
4733 // json input.
4734 // Sample json output: {}
4735 void TestingAutomationProvider::FillAutofillProfile(
4736 Browser* browser,
4737 DictionaryValue* args,
4738 IPC::Message* reply_message) {
4739 ListValue* profiles = NULL;
4740 ListValue* cards = NULL;
4741
4742 // It's ok for profiles/credit_cards elements to be missing.
4743 args->GetList("profiles", &profiles);
4744 args->GetList("credit_cards", &cards);
4745
4746 std::string error_mesg;
4747
4748 std::vector<AutofillProfile> autofill_profiles;
4749 std::vector<CreditCard> credit_cards;
4750 // Create an AutofillProfile for each of the dictionary profiles.
4751 if (profiles) {
4752 autofill_profiles = GetAutofillProfilesFromList(*profiles, &error_mesg);
4753 }
4754 // Create a CreditCard for each of the dictionary values.
4755 if (cards) {
4756 credit_cards = GetCreditCardsFromList(*cards, &error_mesg);
4757 }
4758 if (!error_mesg.empty()) {
4759 AutomationJSONReply(this, reply_message).SendError(error_mesg);
4760 return;
4761 }
4762
4763 // Save the AutofillProfiles.
4764 int tab_index = 0;
4765 if (!args->GetInteger("tab_index", &tab_index)) {
4766 AutomationJSONReply(this, reply_message).SendError(
4767 "Invalid or missing tab_index integer");
4768 return;
4769 }
4770
4771 TabContents* tab_contents = chrome::GetTabContentsAt(browser, tab_index);
4772
4773 if (tab_contents) {
4774 PersonalDataManager* pdm =
4775 PersonalDataManagerFactory::GetForProfile(tab_contents->profile());
4776 if (pdm) {
4777 if (profiles || cards) {
4778 // This observer will delete itself.
4779 AutofillChangedObserver* observer = new AutofillChangedObserver(
4780 this, reply_message, autofill_profiles.size(), credit_cards.size());
4781 observer->Init();
4782
4783 if (profiles)
4784 pdm->SetProfiles(&autofill_profiles);
4785 if (cards)
4786 pdm->SetCreditCards(&credit_cards);
4787
4788 return;
4789 }
4790 } else {
4791 AutomationJSONReply(this, reply_message).SendError(
4792 "No PersonalDataManager.");
4793 return;
4794 }
4795 } else {
4796 AutomationJSONReply(this, reply_message).SendError("No tab at that index.");
4797 return;
4798 }
4799 AutomationJSONReply(this, reply_message).SendSuccess(NULL);
4800 }
4801
4802 void TestingAutomationProvider::SubmitAutofillForm(
4803 Browser* browser,
4804 DictionaryValue* args,
4805 IPC::Message* reply_message) {
4806 if (SendErrorIfModalDialogActive(this, reply_message))
4807 return;
4808
4809 int tab_index;
4810 if (!args->GetInteger("tab_index", &tab_index)) {
4811 AutomationJSONReply(this, reply_message)
4812 .SendError("'tab_index' missing or invalid.");
4813 return;
4814 }
4815 TabContents* tab_contents = chrome::GetTabContentsAt(browser, tab_index);
4816 if (!tab_contents) {
4817 AutomationJSONReply(this, reply_message).SendError(
4818 StringPrintf("No such tab at index %d", tab_index));
4819 return;
4820 }
4821
4822 string16 frame_xpath, javascript;
4823 if (!args->GetString("frame_xpath", &frame_xpath)) {
4824 AutomationJSONReply(this, reply_message)
4825 .SendError("'frame_xpath' missing or invalid.");
4826 return;
4827 }
4828 if (!args->GetString("javascript", &javascript)) {
4829 AutomationJSONReply(this, reply_message)
4830 .SendError("'javascript' missing or invalid.");
4831 return;
4832 }
4833
4834 PersonalDataManager* pdm = PersonalDataManagerFactory::GetForProfile(
4835 tab_contents->profile()->GetOriginalProfile());
4836 if (!pdm) {
4837 AutomationJSONReply(this, reply_message)
4838 .SendError("No PersonalDataManager.");
4839 return;
4840 }
4841
4842 // This observer will delete itself.
4843 new AutofillFormSubmittedObserver(this, reply_message, pdm);
4844
4845 // Set the routing id of this message with the controller.
4846 // This routing id needs to be remembered for the reverse
4847 // communication while sending back the response of
4848 // this javascript execution.
4849 std::string set_automation_id;
4850 base::SStringPrintf(&set_automation_id,
4851 "window.domAutomationController.setAutomationId(%d);",
4852 reply_message->routing_id());
4853 tab_contents->web_contents()->GetRenderViewHost()->
4854 ExecuteJavascriptInWebFrame(frame_xpath, UTF8ToUTF16(set_automation_id));
4855 tab_contents->web_contents()->GetRenderViewHost()->
4856 ExecuteJavascriptInWebFrame(frame_xpath, javascript);
4857 }
4858
4859 void TestingAutomationProvider::AutofillTriggerSuggestions(
4860 Browser* browser,
4861 DictionaryValue* args,
4862 IPC::Message* reply_message) {
4863 int tab_index;
4864 if (!args->GetInteger("tab_index", &tab_index)) {
4865 AutomationJSONReply(this, reply_message).SendError(
4866 "Invalid or missing args");
4867 return;
4868 }
4869
4870 WebContents* web_contents = chrome::GetWebContentsAt(browser, tab_index);
4871 if (!web_contents) {
4872 AutomationJSONReply(this, reply_message).SendError(
4873 StringPrintf("No such tab at index %d", tab_index));
4874 return;
4875 }
4876
4877 new AutofillDisplayedObserver(
4878 chrome::NOTIFICATION_AUTOFILL_DID_SHOW_SUGGESTIONS,
4879 web_contents->GetRenderViewHost(), this, reply_message);
4880 SendWebKeyPressEventAsync(ui::VKEY_DOWN, web_contents);
4881 }
4882
4883 void TestingAutomationProvider::AutofillHighlightSuggestion(
4884 Browser* browser,
4885 DictionaryValue* args,
4886 IPC::Message* reply_message) {
4887 int tab_index;
4888 if (!args->GetInteger("tab_index", &tab_index)) {
4889 AutomationJSONReply(this, reply_message).SendError(
4890 "Invalid or missing args");
4891 return;
4892 }
4893
4894 WebContents* web_contents = chrome::GetWebContentsAt(browser, tab_index);
4895 if (!web_contents) {
4896 AutomationJSONReply(this, reply_message).SendError(
4897 StringPrintf("No such tab at index %d", tab_index));
4898 return;
4899 }
4900
4901 std::string direction;
4902 if (!args->GetString("direction", &direction) || (direction != "up" &&
4903 direction != "down")) {
4904 AutomationJSONReply(this, reply_message).SendError(
4905 "Must specify a direction of either 'up' or 'down'.");
4906 return;
4907 }
4908 int key_code = (direction == "up") ? ui::VKEY_UP : ui::VKEY_DOWN;
4909
4910 new AutofillDisplayedObserver(
4911 chrome::NOTIFICATION_AUTOFILL_DID_FILL_FORM_DATA,
4912 web_contents->GetRenderViewHost(), this, reply_message);
4913 SendWebKeyPressEventAsync(key_code, web_contents);
4914 }
4915
4916 void TestingAutomationProvider::AutofillAcceptSelection(
4917 Browser* browser,
4918 DictionaryValue* args,
4919 IPC::Message* reply_message) {
4920 int tab_index;
4921 if (!args->GetInteger("tab_index", &tab_index)) {
4922 AutomationJSONReply(this, reply_message).SendError(
4923 "Invalid or missing args");
4924 return;
4925 }
4926
4927 WebContents* web_contents = chrome::GetWebContentsAt(browser, tab_index);
4928 if (!web_contents) {
4929 AutomationJSONReply(this, reply_message).SendError(
4930 StringPrintf("No such tab at index %d", tab_index));
4931 return;
4932 }
4933
4934 new AutofillDisplayedObserver(
4935 chrome::NOTIFICATION_AUTOFILL_DID_FILL_FORM_DATA,
4936 web_contents->GetRenderViewHost(), this, reply_message);
4937 SendWebKeyPressEventAsync(ui::VKEY_RETURN, web_contents);
4938 }
4939
4940 // Sample json output: { "success": true } 4673 // Sample json output: { "success": true }
4941 void TestingAutomationProvider::SignInToSync(Browser* browser, 4674 void TestingAutomationProvider::SignInToSync(Browser* browser,
4942 DictionaryValue* args, 4675 DictionaryValue* args,
4943 IPC::Message* reply_message) { 4676 IPC::Message* reply_message) {
4944 AutomationJSONReply reply(this, reply_message); 4677 AutomationJSONReply reply(this, reply_message);
4945 std::string username; 4678 std::string username;
4946 std::string password; 4679 std::string password;
4947 if (!args->GetString("username", &username) || 4680 if (!args->GetString("username", &username) ||
4948 !args->GetString("password", &password)) { 4681 !args->GetString("password", &password)) {
4949 reply.SendError("Invalid or missing args"); 4682 reply.SendError("Invalid or missing args");
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
5161 sync_waiter_->DisableSyncForDatatype(datatype); 4894 sync_waiter_->DisableSyncForDatatype(datatype);
5162 sync_waiter_->AwaitFullSyncCompletion(StringPrintf( 4895 sync_waiter_->AwaitFullSyncCompletion(StringPrintf(
5163 "Disabling datatype: %s", datatype_string.c_str())); 4896 "Disabling datatype: %s", datatype_string.c_str()));
5164 } 4897 }
5165 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); 4898 scoped_ptr<DictionaryValue> return_value(new DictionaryValue);
5166 return_value->SetBoolean("success", true); 4899 return_value->SetBoolean("success", true);
5167 reply.SendSuccess(return_value.get()); 4900 reply.SendSuccess(return_value.get());
5168 } 4901 }
5169 } 4902 }
5170 4903
5171 /* static */
5172 ListValue* TestingAutomationProvider::GetListFromAutofillProfiles(
5173 const std::vector<AutofillProfile*>& autofill_profiles) {
5174 ListValue* profiles = new ListValue;
5175
5176 std::map<AutofillFieldType, std::string> autofill_type_to_string
5177 = GetAutofillFieldToStringMap();
5178
5179 // For each AutofillProfile, transform it to a dictionary object to return.
5180 for (std::vector<AutofillProfile*>::const_iterator it =
5181 autofill_profiles.begin();
5182 it != autofill_profiles.end(); ++it) {
5183 AutofillProfile* profile = *it;
5184 DictionaryValue* profile_info = new DictionaryValue;
5185 // For each of the types, if it has one or more values, add those values
5186 // to the dictionary.
5187 for (std::map<AutofillFieldType, std::string>::iterator
5188 type_it = autofill_type_to_string.begin();
5189 type_it != autofill_type_to_string.end(); ++type_it) {
5190 std::vector<string16> value_list;
5191 profile->GetMultiInfo(type_it->first, &value_list);
5192 ListValue* values_to_return = new ListValue;
5193 for (std::vector<string16>::iterator value_it = value_list.begin();
5194 value_it != value_list.end(); ++value_it) {
5195 string16 value = *value_it;
5196 if (value.length()) // If there was something stored for that value.
5197 values_to_return->Append(new StringValue(value));
5198 }
5199 if (!values_to_return->empty())
5200 profile_info->Set(type_it->second, values_to_return);
5201 }
5202 profiles->Append(profile_info);
5203 }
5204 return profiles;
5205 }
5206
5207 /* static */
5208 ListValue* TestingAutomationProvider::GetListFromCreditCards(
5209 const std::vector<CreditCard*>& credit_cards) {
5210 ListValue* cards = new ListValue;
5211
5212 std::map<AutofillFieldType, std::string> credit_card_type_to_string =
5213 GetCreditCardFieldToStringMap();
5214
5215 // For each AutofillProfile, transform it to a dictionary object to return.
5216 for (std::vector<CreditCard*>::const_iterator it =
5217 credit_cards.begin();
5218 it != credit_cards.end(); ++it) {
5219 CreditCard* card = *it;
5220 DictionaryValue* card_info = new DictionaryValue;
5221 // For each of the types, if it has a value, add it to the dictionary.
5222 for (std::map<AutofillFieldType, std::string>::iterator type_it =
5223 credit_card_type_to_string.begin();
5224 type_it != credit_card_type_to_string.end(); ++type_it) {
5225 string16 value = card->GetInfo(type_it->first);
5226 // If there was something stored for that value.
5227 if (value.length()) {
5228 card_info->SetString(type_it->second, value);
5229 }
5230 }
5231 cards->Append(card_info);
5232 }
5233 return cards;
5234 }
5235
5236 /* static */
5237 std::vector<AutofillProfile>
5238 TestingAutomationProvider::GetAutofillProfilesFromList(
5239 const ListValue& profiles, std::string* error_message) {
5240 std::vector<AutofillProfile> autofill_profiles;
5241 const DictionaryValue* profile_info = NULL;
5242 const ListValue* current_value = NULL;
5243
5244 std::map<AutofillFieldType, std::string> autofill_type_to_string =
5245 GetAutofillFieldToStringMap();
5246
5247 int num_profiles = profiles.GetSize();
5248 for (int i = 0; i < num_profiles; i++) {
5249 profiles.GetDictionary(i, &profile_info);
5250 AutofillProfile profile;
5251 // Loop through the possible profile types and add those provided.
5252 for (std::map<AutofillFieldType, std::string>::iterator type_it =
5253 autofill_type_to_string.begin();
5254 type_it != autofill_type_to_string.end(); ++type_it) {
5255 if (profile_info->HasKey(type_it->second)) {
5256 if (profile_info->GetList(type_it->second, &current_value)) {
5257 std::vector<string16> value_list;
5258 for (ListValue::const_iterator list_it = current_value->begin();
5259 list_it != current_value->end(); ++list_it) {
5260 string16 value;
5261 if ((*list_it)->GetAsString(&value)) {
5262 value_list.insert(value_list.end(), value);
5263 } else {
5264 *error_message = "All list values must be strings";
5265 return autofill_profiles;
5266 }
5267 }
5268 profile.SetMultiInfo(type_it->first, value_list);
5269 } else {
5270 *error_message= "All values must be lists";
5271 return autofill_profiles;
5272 }
5273 }
5274 }
5275 autofill_profiles.push_back(profile);
5276 }
5277 return autofill_profiles;
5278 }
5279
5280 /* static */
5281 std::vector<CreditCard> TestingAutomationProvider::GetCreditCardsFromList(
5282 const ListValue& cards, std::string* error_message) {
5283 std::vector<CreditCard> credit_cards;
5284 const DictionaryValue* card_info = NULL;
5285 string16 current_value;
5286
5287 std::map<AutofillFieldType, std::string> credit_card_type_to_string =
5288 GetCreditCardFieldToStringMap();
5289
5290 int num_credit_cards = cards.GetSize();
5291 for (int i = 0; i < num_credit_cards; i++) {
5292 if (!cards.GetDictionary(i, &card_info))
5293 continue;
5294 CreditCard card;
5295 // Loop through the possible credit card fields and add those provided.
5296 for (std::map<AutofillFieldType, std::string>::iterator type_it =
5297 credit_card_type_to_string.begin();
5298 type_it != credit_card_type_to_string.end(); ++type_it) {
5299 if (card_info->HasKey(type_it->second)) {
5300 if (card_info->GetString(type_it->second, &current_value)) {
5301 card.SetInfo(type_it->first, current_value);
5302 } else {
5303 *error_message= "All values must be strings";
5304 break;
5305 }
5306 }
5307 }
5308 credit_cards.push_back(card);
5309 }
5310 return credit_cards;
5311 }
5312
5313 /* static */
5314 std::map<AutofillFieldType, std::string>
5315 TestingAutomationProvider::GetAutofillFieldToStringMap() {
5316 std::map<AutofillFieldType, std::string> autofill_type_to_string;
5317 // Strings ordered by order of fields when adding a profile in Autofill prefs.
5318 autofill_type_to_string[NAME_FIRST] = "NAME_FIRST";
5319 autofill_type_to_string[NAME_MIDDLE] = "NAME_MIDDLE";
5320 autofill_type_to_string[NAME_LAST] = "NAME_LAST";
5321 autofill_type_to_string[COMPANY_NAME] = "COMPANY_NAME";
5322 autofill_type_to_string[EMAIL_ADDRESS] = "EMAIL_ADDRESS";
5323 autofill_type_to_string[ADDRESS_HOME_LINE1] = "ADDRESS_HOME_LINE1";
5324 autofill_type_to_string[ADDRESS_HOME_LINE2] = "ADDRESS_HOME_LINE2";
5325 autofill_type_to_string[ADDRESS_HOME_CITY] = "ADDRESS_HOME_CITY";
5326 autofill_type_to_string[ADDRESS_HOME_STATE] = "ADDRESS_HOME_STATE";
5327 autofill_type_to_string[ADDRESS_HOME_ZIP] = "ADDRESS_HOME_ZIP";
5328 autofill_type_to_string[ADDRESS_HOME_COUNTRY] = "ADDRESS_HOME_COUNTRY";
5329 autofill_type_to_string[PHONE_HOME_COUNTRY_CODE] =
5330 "PHONE_HOME_COUNTRY_CODE";
5331 autofill_type_to_string[PHONE_HOME_CITY_CODE] = "PHONE_HOME_CITY_CODE";
5332 autofill_type_to_string[PHONE_HOME_WHOLE_NUMBER] =
5333 "PHONE_HOME_WHOLE_NUMBER";
5334 return autofill_type_to_string;
5335 }
5336
5337 /* static */
5338 std::map<AutofillFieldType, std::string>
5339 TestingAutomationProvider::GetCreditCardFieldToStringMap() {
5340 std::map<AutofillFieldType, std::string> credit_card_type_to_string;
5341 credit_card_type_to_string[CREDIT_CARD_NAME] = "CREDIT_CARD_NAME";
5342 credit_card_type_to_string[CREDIT_CARD_NUMBER] = "CREDIT_CARD_NUMBER";
5343 credit_card_type_to_string[CREDIT_CARD_EXP_MONTH] = "CREDIT_CARD_EXP_MONTH";
5344 credit_card_type_to_string[CREDIT_CARD_EXP_4_DIGIT_YEAR] =
5345 "CREDIT_CARD_EXP_4_DIGIT_YEAR";
5346 return credit_card_type_to_string;
5347 }
5348
5349 // Refer to GetAllNotifications() in chrome/test/pyautolib/pyauto.py for 4904 // Refer to GetAllNotifications() in chrome/test/pyautolib/pyauto.py for
5350 // sample json input/output. 4905 // sample json input/output.
5351 void TestingAutomationProvider::GetAllNotifications( 4906 void TestingAutomationProvider::GetAllNotifications(
5352 Browser* browser, 4907 Browser* browser,
5353 DictionaryValue* args, 4908 DictionaryValue* args,
5354 IPC::Message* reply_message) { 4909 IPC::Message* reply_message) {
5355 new GetAllNotificationsObserver(this, reply_message); 4910 new GetAllNotificationsObserver(this, reply_message);
5356 } 4911 }
5357 4912
5358 // Refer to CloseNotification() in chrome/test/pyautolib/pyauto.py for 4913 // Refer to CloseNotification() in chrome/test/pyautolib/pyauto.py for
(...skipping 1888 matching lines...) Expand 10 before | Expand all | Expand 10 after
7247 void TestingAutomationProvider::OnRemoveProvider() { 6802 void TestingAutomationProvider::OnRemoveProvider() {
7248 if (g_browser_process) 6803 if (g_browser_process)
7249 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); 6804 g_browser_process->GetAutomationProviderList()->RemoveProvider(this);
7250 } 6805 }
7251 6806
7252 void TestingAutomationProvider::EnsureTabSelected(Browser* browser, 6807 void TestingAutomationProvider::EnsureTabSelected(Browser* browser,
7253 WebContents* tab) { 6808 WebContents* tab) {
7254 if (chrome::GetActiveWebContents(browser) != tab) 6809 if (chrome::GetActiveWebContents(browser) != tab)
7255 chrome::ActivateTabAt(browser, chrome::GetIndexOfTab(browser, tab), true); 6810 chrome::ActivateTabAt(browser, chrome::GetIndexOfTab(browser, tab), true);
7256 } 6811 }
OLDNEW
« no previous file with comments | « chrome/browser/automation/testing_automation_provider.h ('k') | chrome/browser/sync/test/integration/autofill_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698