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

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

Issue 10790055: Convert more PyAuto proxy calls to the JSON interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Ensure the returned Python string is of type str, not unicode, before passing to GURL. Created 8 years, 5 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 1641 matching lines...) Expand 10 before | Expand all | Expand 10 after
1652 } 1652 }
1653 1653
1654 void TestingAutomationProvider::BuildJSONHandlerMaps() { 1654 void TestingAutomationProvider::BuildJSONHandlerMaps() {
1655 // Map json commands to their handlers. 1655 // Map json commands to their handlers.
1656 handler_map_["ApplyAccelerator"] = 1656 handler_map_["ApplyAccelerator"] =
1657 &TestingAutomationProvider::ExecuteBrowserCommandAsyncJSON; 1657 &TestingAutomationProvider::ExecuteBrowserCommandAsyncJSON;
1658 handler_map_["RunCommand"] = 1658 handler_map_["RunCommand"] =
1659 &TestingAutomationProvider::ExecuteBrowserCommandJSON; 1659 &TestingAutomationProvider::ExecuteBrowserCommandJSON;
1660 handler_map_["IsMenuCommandEnabled"] = 1660 handler_map_["IsMenuCommandEnabled"] =
1661 &TestingAutomationProvider::IsMenuCommandEnabledJSON; 1661 &TestingAutomationProvider::IsMenuCommandEnabledJSON;
1662 handler_map_["ActivateTab"] =
1663 &TestingAutomationProvider::ActivateTabJSON;
1664 handler_map_["BringBrowserToFront"] =
1665 &TestingAutomationProvider::BringBrowserToFrontJSON;
1662 handler_map_["WaitForAllTabsToStopLoading"] = 1666 handler_map_["WaitForAllTabsToStopLoading"] =
1663 &TestingAutomationProvider::WaitForAllViewsToStopLoading; 1667 &TestingAutomationProvider::WaitForAllViewsToStopLoading;
1664 handler_map_["GetIndicesFromTab"] = 1668 handler_map_["GetIndicesFromTab"] =
1665 &TestingAutomationProvider::GetIndicesFromTab; 1669 &TestingAutomationProvider::GetIndicesFromTab;
1666 handler_map_["NavigateToURL"] = 1670 handler_map_["NavigateToURL"] =
1667 &TestingAutomationProvider::NavigateToURL; 1671 &TestingAutomationProvider::NavigateToURL;
1668 handler_map_["GetActiveTabIndex"] = 1672 handler_map_["GetActiveTabIndex"] =
1669 &TestingAutomationProvider::GetActiveTabIndexJSON; 1673 &TestingAutomationProvider::GetActiveTabIndexJSON;
1670 handler_map_["AppendTab"] = 1674 handler_map_["AppendTab"] =
1671 &TestingAutomationProvider::AppendTabJSON; 1675 &TestingAutomationProvider::AppendTabJSON;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1744 handler_map_["AcceptOrDismissAppModalDialog"] = 1748 handler_map_["AcceptOrDismissAppModalDialog"] =
1745 &TestingAutomationProvider::AcceptOrDismissAppModalDialog; 1749 &TestingAutomationProvider::AcceptOrDismissAppModalDialog;
1746 handler_map_["GetChromeDriverAutomationVersion"] = 1750 handler_map_["GetChromeDriverAutomationVersion"] =
1747 &TestingAutomationProvider::GetChromeDriverAutomationVersion; 1751 &TestingAutomationProvider::GetChromeDriverAutomationVersion;
1748 handler_map_["IsPageActionVisible"] = 1752 handler_map_["IsPageActionVisible"] =
1749 &TestingAutomationProvider::IsPageActionVisible; 1753 &TestingAutomationProvider::IsPageActionVisible;
1750 handler_map_["CreateNewAutomationProvider"] = 1754 handler_map_["CreateNewAutomationProvider"] =
1751 &TestingAutomationProvider::CreateNewAutomationProvider; 1755 &TestingAutomationProvider::CreateNewAutomationProvider;
1752 handler_map_["GetBrowserInfo"] = 1756 handler_map_["GetBrowserInfo"] =
1753 &TestingAutomationProvider::GetBrowserInfo; 1757 &TestingAutomationProvider::GetBrowserInfo;
1758 handler_map_["GetTabInfo"] =
1759 &TestingAutomationProvider::GetTabInfo;
1760 handler_map_["GetTabCount"] =
1761 &TestingAutomationProvider::GetTabCountJSON;
1754 handler_map_["OpenNewBrowserWindowWithNewProfile"] = 1762 handler_map_["OpenNewBrowserWindowWithNewProfile"] =
1755 &TestingAutomationProvider::OpenNewBrowserWindowWithNewProfile; 1763 &TestingAutomationProvider::OpenNewBrowserWindowWithNewProfile;
1756 handler_map_["GetMultiProfileInfo"] = 1764 handler_map_["GetMultiProfileInfo"] =
1757 &TestingAutomationProvider::GetMultiProfileInfo; 1765 &TestingAutomationProvider::GetMultiProfileInfo;
1758 handler_map_["OpenProfileWindow"] = 1766 handler_map_["OpenProfileWindow"] =
1759 &TestingAutomationProvider::OpenProfileWindow; 1767 &TestingAutomationProvider::OpenProfileWindow;
1760 handler_map_["GetProcessInfo"] = 1768 handler_map_["GetProcessInfo"] =
1761 &TestingAutomationProvider::GetProcessInfo; 1769 &TestingAutomationProvider::GetProcessInfo;
1762 handler_map_["GetPolicyDefinitionList"] = 1770 handler_map_["GetPolicyDefinitionList"] =
1763 &TestingAutomationProvider::GetPolicyDefinitionList; 1771 &TestingAutomationProvider::GetPolicyDefinitionList;
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
2126 error_string += it->first + ", "; 2134 error_string += it->first + ", ";
2127 } 2135 }
2128 for (std::map<std::string, BrowserJsonHandler>::const_iterator it = 2136 for (std::map<std::string, BrowserJsonHandler>::const_iterator it =
2129 browser_handler_map_.begin(); it != browser_handler_map_.end(); ++it) { 2137 browser_handler_map_.begin(); it != browser_handler_map_.end(); ++it) {
2130 error_string += it->first + ", "; 2138 error_string += it->first + ", ";
2131 } 2139 }
2132 AutomationJSONReply(this, reply_message).SendError(error_string); 2140 AutomationJSONReply(this, reply_message).SendError(error_string);
2133 } 2141 }
2134 } 2142 }
2135 2143
2144 void TestingAutomationProvider::BringBrowserToFrontJSON(
2145 DictionaryValue* args,
2146 IPC::Message* reply_message) {
2147 AutomationJSONReply reply(this, reply_message);
2148 Browser* browser;
2149 std::string error_msg;
2150 if (!GetBrowserFromJSONArgs(args, &browser, &error_msg)) {
2151 reply.SendError(error_msg);
2152 return;
2153 }
2154 browser->window()->Activate();
2155 reply.SendSuccess(NULL);
2156 }
2157
2136 // Sample json input: { "command": "SetWindowDimensions", 2158 // Sample json input: { "command": "SetWindowDimensions",
2137 // "x": 20, # optional 2159 // "x": 20, # optional
2138 // "y": 20, # optional 2160 // "y": 20, # optional
2139 // "width": 800, # optional 2161 // "width": 800, # optional
2140 // "height": 600 } # optional 2162 // "height": 600 } # optional
2141 void TestingAutomationProvider::SetWindowDimensions( 2163 void TestingAutomationProvider::SetWindowDimensions(
2142 Browser* browser, 2164 Browser* browser,
2143 DictionaryValue* args, 2165 DictionaryValue* args,
2144 IPC::Message* reply_message) { 2166 IPC::Message* reply_message) {
2145 gfx::Rect rect = browser->window()->GetRestoredBounds(); 2167 gfx::Rect rect = browser->window()->GetRestoredBounds();
(...skipping 4330 matching lines...) Expand 10 before | Expand all | Expand 10 after
6476 if (!args->GetInteger("accelerator", &command)) { 6498 if (!args->GetInteger("accelerator", &command)) {
6477 AutomationJSONReply(this, reply_message).SendError( 6499 AutomationJSONReply(this, reply_message).SendError(
6478 "'accelerator' missing or invalid."); 6500 "'accelerator' missing or invalid.");
6479 return; 6501 return;
6480 } 6502 }
6481 DictionaryValue dict; 6503 DictionaryValue dict;
6482 dict.SetBoolean("enabled", chrome::IsCommandEnabled(browser, command)); 6504 dict.SetBoolean("enabled", chrome::IsCommandEnabled(browser, command));
6483 AutomationJSONReply(this, reply_message).SendSuccess(&dict); 6505 AutomationJSONReply(this, reply_message).SendSuccess(&dict);
6484 } 6506 }
6485 6507
6508 void TestingAutomationProvider::GetTabInfo(
6509 DictionaryValue* args,
6510 IPC::Message* reply_message) {
6511 AutomationJSONReply reply(this, reply_message);
6512 Browser* browser;
6513 WebContents* tab;
6514 std::string error;
6515 if (GetBrowserAndTabFromJSONArgs(args, &browser, &tab, &error)) {
6516 NavigationEntry* entry = tab->GetController().GetActiveEntry();
6517 DictionaryValue dict;
6518 dict.SetString("title", entry->GetTitleForDisplay(""));
6519 dict.SetString("url", entry->GetVirtualURL().spec());
6520 reply.SendSuccess(&dict);
6521 } else {
6522 reply.SendError(error);
6523 }
6524 }
6525
6526 void TestingAutomationProvider::GetTabCountJSON(
6527 DictionaryValue* args,
6528 IPC::Message* reply_message) {
6529 AutomationJSONReply reply(this, reply_message);
6530 Browser* browser;
6531 std::string error;
6532 if (!GetBrowserFromJSONArgs(args, &browser, &error)) {
6533 reply.SendError(error);
6534 return;
6535 }
6536 DictionaryValue dict;
6537 dict.SetInteger("tab_count", browser->tab_count());
6538 reply.SendSuccess(&dict);
6539 }
6540
6486 void TestingAutomationProvider::GoBack( 6541 void TestingAutomationProvider::GoBack(
6487 DictionaryValue* args, 6542 DictionaryValue* args,
6488 IPC::Message* reply_message) { 6543 IPC::Message* reply_message) {
6489 if (SendErrorIfModalDialogActive(this, reply_message)) 6544 if (SendErrorIfModalDialogActive(this, reply_message))
6490 return; 6545 return;
6491 6546
6492 WebContents* web_contents; 6547 WebContents* web_contents;
6493 std::string error; 6548 std::string error;
6494 if (!GetTabFromJSONArgs(args, &web_contents, &error)) { 6549 if (!GetTabFromJSONArgs(args, &web_contents, &error)) {
6495 AutomationJSONReply(this, reply_message).SendError(error); 6550 AutomationJSONReply(this, reply_message).SendError(error);
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
6904 void TestingAutomationProvider::OnRemoveProvider() { 6959 void TestingAutomationProvider::OnRemoveProvider() {
6905 if (g_browser_process) 6960 if (g_browser_process)
6906 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); 6961 g_browser_process->GetAutomationProviderList()->RemoveProvider(this);
6907 } 6962 }
6908 6963
6909 void TestingAutomationProvider::EnsureTabSelected(Browser* browser, 6964 void TestingAutomationProvider::EnsureTabSelected(Browser* browser,
6910 WebContents* tab) { 6965 WebContents* tab) {
6911 if (chrome::GetActiveWebContents(browser) != tab) 6966 if (chrome::GetActiveWebContents(browser) != tab)
6912 chrome::ActivateTabAt(browser, chrome::GetIndexOfTab(browser, tab), true); 6967 chrome::ActivateTabAt(browser, chrome::GetIndexOfTab(browser, tab), true);
6913 } 6968 }
OLDNEW
« no previous file with comments | « chrome/browser/automation/testing_automation_provider.h ('k') | chrome/test/functional/popups.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698