Index: chrome/browser/automation/testing_automation_provider.cc |
diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc |
index c2aa4ec623e7de3d4c138d2d2dd39ffa00b346a4..c729893a493b4964a2f08c7b9a00716741d5c092 100644 |
--- a/chrome/browser/automation/testing_automation_provider.cc |
+++ b/chrome/browser/automation/testing_automation_provider.cc |
@@ -931,9 +931,9 @@ void TestingAutomationProvider::WebkitMouseClick(DictionaryValue* args, |
if (SendErrorIfModalDialogActive(this, reply_message)) |
return; |
- TabContents* tab_contents; |
+ RenderViewHost* view; |
std::string error; |
- if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { |
+ if (!GetRenderViewFromJSONArgs(args, profile(), &view, &error)) { |
AutomationJSONReply(this, reply_message).SendError(error); |
return; |
} |
@@ -967,12 +967,12 @@ void TestingAutomationProvider::WebkitMouseClick(DictionaryValue* args, |
mouse_event.type = WebKit::WebInputEvent::MouseDown; |
mouse_event.clickCount = 1; |
- tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); |
+ view->ForwardMouseEvent(mouse_event); |
mouse_event.type = WebKit::WebInputEvent::MouseUp; |
new InputEventAckNotificationObserver(this, reply_message, mouse_event.type, |
1); |
- tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); |
+ view->ForwardMouseEvent(mouse_event); |
} |
void TestingAutomationProvider::WebkitMouseMove( |
@@ -980,9 +980,9 @@ void TestingAutomationProvider::WebkitMouseMove( |
if (SendErrorIfModalDialogActive(this, reply_message)) |
return; |
- TabContents* tab_contents; |
+ RenderViewHost* view; |
std::string error; |
- if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { |
+ if (!GetRenderViewFromJSONArgs(args, profile(), &view, &error)) { |
AutomationJSONReply(this, reply_message).SendError(error); |
return; |
} |
@@ -998,7 +998,7 @@ void TestingAutomationProvider::WebkitMouseMove( |
mouse_event.type = WebKit::WebInputEvent::MouseMove; |
new InputEventAckNotificationObserver(this, reply_message, mouse_event.type, |
1); |
- tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); |
+ view->ForwardMouseEvent(mouse_event); |
} |
void TestingAutomationProvider::WebkitMouseDrag(DictionaryValue* args, |
@@ -1006,9 +1006,9 @@ void TestingAutomationProvider::WebkitMouseDrag(DictionaryValue* args, |
if (SendErrorIfModalDialogActive(this, reply_message)) |
return; |
- TabContents* tab_contents; |
+ RenderViewHost* view; |
std::string error; |
- if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { |
+ if (!GetRenderViewFromJSONArgs(args, profile(), &view, &error)) { |
AutomationJSONReply(this, reply_message).SendError(error); |
return; |
} |
@@ -1028,29 +1028,27 @@ void TestingAutomationProvider::WebkitMouseDrag(DictionaryValue* args, |
// Step 1- Move the mouse to the start position. |
mouse_event.x = start_x; |
mouse_event.y = start_y; |
- tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); |
+ view->ForwardMouseEvent(mouse_event); |
// Step 2- Left click mouse down, the mouse button is fixed. |
mouse_event.type = WebKit::WebInputEvent::MouseDown; |
mouse_event.button = WebKit::WebMouseEvent::ButtonLeft; |
mouse_event.clickCount = 1; |
- tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); |
+ view->ForwardMouseEvent(mouse_event); |
// Step 3 - Move the mouse to the end position. |
- // TODO(JMikhail): See if we should simulate the by not making such |
- // a drastic jump by placing incrmental stops along the way. |
mouse_event.type = WebKit::WebInputEvent::MouseMove; |
mouse_event.x = end_x; |
mouse_event.y = end_y; |
mouse_event.clickCount = 0; |
- tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); |
+ view->ForwardMouseEvent(mouse_event); |
// Step 4 - Release the left mouse button. |
mouse_event.type = WebKit::WebInputEvent::MouseUp; |
mouse_event.clickCount = 1; |
new InputEventAckNotificationObserver(this, reply_message, mouse_event.type, |
1); |
- tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); |
+ view->ForwardMouseEvent(mouse_event); |
} |
void TestingAutomationProvider::WebkitMouseButtonDown( |
@@ -1058,9 +1056,9 @@ void TestingAutomationProvider::WebkitMouseButtonDown( |
if (SendErrorIfModalDialogActive(this, reply_message)) |
return; |
- TabContents* tab_contents; |
+ RenderViewHost* view; |
std::string error; |
- if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { |
+ if (!GetRenderViewFromJSONArgs(args, profile(), &view, &error)) { |
AutomationJSONReply(this, reply_message).SendError(error); |
return; |
} |
@@ -1078,7 +1076,7 @@ void TestingAutomationProvider::WebkitMouseButtonDown( |
mouse_event.clickCount = 1; |
new InputEventAckNotificationObserver(this, reply_message, mouse_event.type, |
1); |
- tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); |
+ view->ForwardMouseEvent(mouse_event); |
} |
void TestingAutomationProvider::WebkitMouseButtonUp( |
@@ -1086,9 +1084,9 @@ void TestingAutomationProvider::WebkitMouseButtonUp( |
if (SendErrorIfModalDialogActive(this, reply_message)) |
return; |
- TabContents* tab_contents; |
+ RenderViewHost* view; |
std::string error; |
- if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { |
+ if (!GetRenderViewFromJSONArgs(args, profile(), &view, &error)) { |
AutomationJSONReply(this, reply_message).SendError(error); |
return; |
} |
@@ -1106,7 +1104,7 @@ void TestingAutomationProvider::WebkitMouseButtonUp( |
mouse_event.clickCount = 1; |
new InputEventAckNotificationObserver(this, reply_message, mouse_event.type, |
1); |
- tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); |
+ view->ForwardMouseEvent(mouse_event); |
} |
void TestingAutomationProvider::WebkitMouseDoubleClick( |
@@ -1114,9 +1112,9 @@ void TestingAutomationProvider::WebkitMouseDoubleClick( |
if (SendErrorIfModalDialogActive(this, reply_message)) |
return; |
- TabContents* tab_contents; |
+ RenderViewHost* view; |
std::string error; |
- if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { |
+ if (!GetRenderViewFromJSONArgs(args, profile(), &view, &error)) { |
AutomationJSONReply(this, reply_message).SendError(error); |
return; |
} |
@@ -1132,19 +1130,19 @@ void TestingAutomationProvider::WebkitMouseDoubleClick( |
mouse_event.type = WebKit::WebInputEvent::MouseDown; |
mouse_event.button = WebKit::WebMouseEvent::ButtonLeft; |
mouse_event.clickCount = 1; |
- tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); |
+ view->ForwardMouseEvent(mouse_event); |
mouse_event.type = WebKit::WebInputEvent::MouseUp; |
new InputEventAckNotificationObserver(this, reply_message, mouse_event.type, |
2); |
- tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); |
+ view->ForwardMouseEvent(mouse_event); |
mouse_event.type = WebKit::WebInputEvent::MouseDown; |
mouse_event.clickCount = 2; |
- tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); |
+ view->ForwardMouseEvent(mouse_event); |
mouse_event.type = WebKit::WebInputEvent::MouseUp; |
- tab_contents->render_view_host()->ForwardMouseEvent(mouse_event); |
+ view->ForwardMouseEvent(mouse_event); |
} |
void TestingAutomationProvider::DragAndDropFilePaths( |
@@ -1152,9 +1150,9 @@ void TestingAutomationProvider::DragAndDropFilePaths( |
if (SendErrorIfModalDialogActive(this, reply_message)) |
return; |
- TabContents* tab_contents; |
+ RenderViewHost* view; |
std::string error; |
- if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { |
+ if (!GetRenderViewFromJSONArgs(args, profile(), &view, &error)) { |
AutomationJSONReply(this, reply_message).SendError(error); |
return; |
} |
@@ -1196,12 +1194,11 @@ void TestingAutomationProvider::DragAndDropFilePaths( |
operations |= WebKit::WebDragOperationLink; |
operations |= WebKit::WebDragOperationMove; |
- RenderViewHost* host = tab_contents->render_view_host(); |
- host->DragTargetDragEnter( |
+ view->DragTargetDragEnter( |
drop_data, client, screen, |
static_cast<WebKit::WebDragOperationsMask>(operations)); |
new DragTargetDropAckNotificationObserver(this, reply_message); |
- host->DragTargetDrop(client, screen); |
+ view->DragTargetDrop(client, screen); |
} |
void TestingAutomationProvider::GetTabCount(int handle, int* tab_count) { |
@@ -2262,10 +2259,6 @@ void TestingAutomationProvider::SendJSONRequest(int handle, |
&TestingAutomationProvider::GoBack; |
handler_map["Reload"] = |
&TestingAutomationProvider::ReloadJSON; |
- handler_map["GetTabURL"] = |
- &TestingAutomationProvider::GetTabURLJSON; |
- handler_map["GetTabTitle"] = |
- &TestingAutomationProvider::GetTabTitleJSON; |
handler_map["CaptureEntirePage"] = |
&TestingAutomationProvider::CaptureEntirePageJSON; |
handler_map["GetCookies"] = |
@@ -2276,8 +2269,12 @@ void TestingAutomationProvider::SendJSONRequest(int handle, |
&TestingAutomationProvider::SetCookieJSON; |
handler_map["GetTabIds"] = |
&TestingAutomationProvider::GetTabIds; |
+ handler_map["GetViews"] = |
+ &TestingAutomationProvider::GetViews; |
handler_map["IsTabIdValid"] = |
&TestingAutomationProvider::IsTabIdValid; |
+ handler_map["DoesViewExist"] = |
+ &TestingAutomationProvider::DoesViewExist; |
handler_map["CloseTab"] = |
&TestingAutomationProvider::CloseTabJSON; |
handler_map["WebkitMouseMove"] = |
@@ -2326,6 +2323,10 @@ void TestingAutomationProvider::SendJSONRequest(int handle, |
&TestingAutomationProvider::InstallExtension; |
handler_map["GetExtensionsInfo"] = |
&TestingAutomationProvider::GetExtensionsInfo; |
+ handler_map["UninstallExtensionById"] = |
+ &TestingAutomationProvider::UninstallExtensionById; |
+ handler_map["SetExtensionStateById"] = |
+ &TestingAutomationProvider::SetExtensionStateById; |
handler_map["RefreshPolicies"] = |
&TestingAutomationProvider::RefreshPolicies; |
handler_map["TriggerPageActionById"] = |
@@ -2474,11 +2475,6 @@ void TestingAutomationProvider::SendJSONRequest(int handle, |
browser_handler_map["GetThemeInfo"] = |
&TestingAutomationProvider::GetThemeInfo; |
- browser_handler_map["UninstallExtensionById"] = |
- &TestingAutomationProvider::UninstallExtensionById; |
- browser_handler_map["SetExtensionStateById"] = |
- &TestingAutomationProvider::SetExtensionStateById; |
- |
browser_handler_map["FindInPage"] = &TestingAutomationProvider::FindInPage; |
browser_handler_map["SelectTranslateOption"] = |
@@ -4409,10 +4405,11 @@ void TestingAutomationProvider::GetExtensionsInfo( |
extension_value->Set("effective_host_permissions", |
GetHostPermissions(extension, true)); |
extension_value->Set("api_permissions", GetAPIPermissions(extension)); |
+ Extension::Location location = extension->location(); |
extension_value->SetBoolean("is_component", |
- extension->location() == Extension::COMPONENT); |
- extension_value->SetBoolean("is_internal", |
- extension->location() == Extension::INTERNAL); |
+ location == Extension::COMPONENT); |
+ extension_value->SetBoolean("is_user_installed", |
dennis_jeffrey
2011/12/03 00:19:37
there's a reference to "is_internal" in pyauto.py
kkania
2011/12/03 00:34:31
Whoops. I'm going to add both.
|
+ location == Extension::INTERNAL || location == Extension::LOAD); |
dennis_jeffrey
2011/12/03 00:19:37
if the location is Extension::INTERNAL, does that
kkania
2011/12/03 00:34:31
INTERNAL means its from the internal extensions di
|
extension_value->SetBoolean("is_enabled", service->IsExtensionEnabled(id)); |
extension_value->SetBoolean("allowed_in_incognito", |
service->IsIncognitoEnabled(id)); |
@@ -4426,7 +4423,6 @@ void TestingAutomationProvider::GetExtensionsInfo( |
// json input. |
// Sample json output: {} |
void TestingAutomationProvider::UninstallExtensionById( |
- Browser* browser, |
DictionaryValue* args, |
IPC::Message* reply_message) { |
std::string id; |
@@ -4460,37 +4456,41 @@ void TestingAutomationProvider::UninstallExtensionById( |
// See SetExtensionStateById() in chrome/test/pyautolib/pyauto.py |
// for sample json input. |
void TestingAutomationProvider::SetExtensionStateById( |
- Browser* browser, |
DictionaryValue* args, |
IPC::Message* reply_message) { |
- AutomationJSONReply reply(this, reply_message); |
std::string id; |
if (!args->GetString("id", &id)) { |
- reply.SendError("Missing or invalid key: id"); |
+ AutomationJSONReply(this, reply_message) |
+ .SendError("Missing or invalid key: id"); |
return; |
} |
bool enable; |
if (!args->GetBoolean("enable", &enable)) { |
- reply.SendError("Missing or invalid key: enable"); |
+ AutomationJSONReply(this, reply_message) |
+ .SendError("Missing or invalid key: enable"); |
return; |
} |
bool allow_in_incognito; |
if (!args->GetBoolean("allow_in_incognito", &allow_in_incognito)) { |
- reply.SendError("Missing or invalid key: allow_in_incognito"); |
+ AutomationJSONReply(this, reply_message) |
+ .SendError("Missing or invalid key: allow_in_incognito"); |
return; |
} |
if (allow_in_incognito && !enable) { |
- reply.SendError("Invalid state: Disabled extension " |
+ AutomationJSONReply(this, reply_message) |
+ .SendError("Invalid state: Disabled extension " |
"cannot be allowed in incognito mode."); |
return; |
} |
ExtensionService* service = profile()->GetExtensionService(); |
+ ExtensionProcessManager* manager = profile()->GetExtensionProcessManager(); |
if (!service) { |
- reply.SendError("No extensions service."); |
+ AutomationJSONReply(this, reply_message) |
+ .SendError("No extensions service or process manager."); |
return; |
} |
@@ -4498,18 +4498,28 @@ void TestingAutomationProvider::SetExtensionStateById( |
!service->GetTerminatedExtension(id)) { |
// The extension ID does not correspond to any extension, whether crashed |
// or not. |
- reply.SendError(base::StringPrintf("Extension does not exist: %s.", |
- id.c_str())); |
+ AutomationJSONReply(this, reply_message).SendError( |
+ base::StringPrintf("Extension does not exist: %s.", id.c_str())); |
return; |
} |
- if (enable) |
- service->EnableExtension(id); |
- else |
- service->DisableExtension(id); |
- |
service->SetIsIncognitoEnabled(id, allow_in_incognito); |
- reply.SendSuccess(NULL); |
+ |
+ if (enable) { |
+ if (!service->IsExtensionEnabled(id)) { |
+ new ExtensionReadyNotificationObserver( |
+ manager, |
+ service, |
+ this, |
+ reply_message); |
+ service->EnableExtension(id); |
+ } else { |
+ AutomationJSONReply(this, reply_message).SendSuccess(NULL); |
+ } |
+ } else { |
+ service->DisableExtension(id); |
+ AutomationJSONReply(this, reply_message).SendSuccess(NULL); |
+ } |
} |
// See TriggerPageActionById() in chrome/test/pyautolib/pyauto.py |
@@ -5631,13 +5641,13 @@ void TestingAutomationProvider::SendWebkitKeyEvent( |
return; |
} |
- TabContents* tab_contents; |
- if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { |
+ RenderViewHost* view; |
+ if (!GetRenderViewFromJSONArgs(args, profile(), &view, &error)) { |
AutomationJSONReply(this, reply_message).SendError(error); |
return; |
} |
new InputEventAckNotificationObserver(this, reply_message, event.type, 1); |
- tab_contents->render_view_host()->ForwardKeyboardEvent(event); |
+ view->ForwardKeyboardEvent(event); |
} |
void TestingAutomationProvider::SendOSLevelKeyEventToTab( |
@@ -6063,8 +6073,8 @@ void TestingAutomationProvider::ExecuteJavascriptJSON( |
string16 frame_xpath, javascript; |
std::string error; |
- TabContents* tab_contents; |
- if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { |
+ RenderViewHost* render_view; |
+ if (!GetRenderViewFromJSONArgs(args, profile(), &render_view, &error)) { |
AutomationJSONReply(this, reply_message).SendError(error); |
return; |
} |
@@ -6081,7 +6091,7 @@ void TestingAutomationProvider::ExecuteJavascriptJSON( |
new DomOperationMessageSender(this, reply_message, true); |
ExecuteJavascriptInRenderViewFrame(frame_xpath, javascript, reply_message, |
- tab_contents->render_view_host()); |
+ render_view); |
} |
void TestingAutomationProvider::ExecuteJavascriptInRenderView( |
@@ -6190,36 +6200,6 @@ void TestingAutomationProvider::ReloadJSON( |
controller.Reload(false); |
} |
-void TestingAutomationProvider::GetTabURLJSON( |
- DictionaryValue* args, |
- IPC::Message* reply_message) { |
- AutomationJSONReply reply(this, reply_message); |
- TabContents* tab_contents; |
- std::string error; |
- if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { |
- reply.SendError(error); |
- return; |
- } |
- DictionaryValue dict; |
- dict.SetString("url", tab_contents->GetURL().possibly_invalid_spec()); |
- reply.SendSuccess(&dict); |
-} |
- |
-void TestingAutomationProvider::GetTabTitleJSON( |
- DictionaryValue* args, |
- IPC::Message* reply_message) { |
- AutomationJSONReply reply(this, reply_message); |
- TabContents* tab_contents; |
- std::string error; |
- if (!GetTabFromJSONArgs(args, &tab_contents, &error)) { |
- reply.SendError(error); |
- return; |
- } |
- DictionaryValue dict; |
- dict.SetString("title", tab_contents->GetTitle()); |
- reply.SendSuccess(&dict); |
-} |
- |
void TestingAutomationProvider::CaptureEntirePageJSON( |
DictionaryValue* args, |
IPC::Message* reply_message) { |
@@ -6287,6 +6267,48 @@ void TestingAutomationProvider::GetTabIds( |
AutomationJSONReply(this, reply_message).SendSuccess(&dict); |
} |
+void TestingAutomationProvider::GetViews( |
+ DictionaryValue* args, IPC::Message* reply_message) { |
+ ListValue* view_list = new ListValue(); |
+ BrowserList::const_iterator browser_iter = BrowserList::begin(); |
+ for (; browser_iter != BrowserList::end(); ++browser_iter) { |
+ Browser* browser = *browser_iter; |
+ for (int i = 0; i < browser->tab_count(); ++i) { |
+ DictionaryValue* dict = new DictionaryValue(); |
+ AutomationId id = automation_util::GetIdForTab( |
+ browser->GetTabContentsWrapperAt(i)); |
+ dict->Set("view_id", id.ToValue()); |
+ view_list->Append(dict); |
+ } |
+ } |
+ |
+ ExtensionProcessManager* extension_mgr = |
+ profile()->GetExtensionProcessManager(); |
+ ExtensionProcessManager::const_iterator iter; |
+ for (iter = extension_mgr->begin(); iter != extension_mgr->end(); |
+ ++iter) { |
+ ExtensionHost* host = *iter; |
+ DictionaryValue* dict = new DictionaryValue(); |
+ AutomationId id = automation_util::GetIdForExtensionView(host); |
+ if (!id.is_valid()) |
+ continue; |
+ dict->Set("view_id", id.ToValue()); |
+ dict->Set("extension_id", automation_util::GetIdForExtension( |
+ host->extension()).ToValue()); |
+ if (host->host_contents()) { |
+ TabContentsWrapper* wrapper = |
+ TabContentsWrapper::GetCurrentWrapperForContents( |
+ host->host_contents()); |
+ if (wrapper) |
+ dict->Set("host_id", automation_util::GetIdForTab(wrapper).ToValue()); |
+ } |
+ view_list->Append(dict); |
+ } |
+ DictionaryValue dict; |
dennis_jeffrey
2011/12/03 00:19:37
Some other functions use this mechanism for sendin
kkania
2011/12/03 00:34:31
This one is better because its one less heap alloc
|
+ dict.Set("views", view_list); |
+ AutomationJSONReply(this, reply_message).SendSuccess(&dict); |
+} |
+ |
void TestingAutomationProvider::IsTabIdValid( |
DictionaryValue* args, IPC::Message* reply_message) { |
AutomationJSONReply reply(this, reply_message); |
@@ -6312,17 +6334,32 @@ void TestingAutomationProvider::IsTabIdValid( |
reply.SendSuccess(&dict); |
} |
+void TestingAutomationProvider::DoesViewExist( |
+ DictionaryValue* args, IPC::Message* reply_message) { |
+ AutomationJSONReply reply(this, reply_message); |
+ AutomationId id; |
+ std::string error_msg; |
+ if (!GetAutomationIdFromJSONArgs(args, "view_id", &id, &error_msg)) { |
+ reply.SendError(error_msg); |
+ return; |
+ } |
+ DictionaryValue dict; |
+ dict.SetBoolean( |
+ "does_exist", |
+ automation_util::DoesObjectWithIdExist(id, profile())); |
+ reply.SendSuccess(&dict); |
+} |
+ |
void TestingAutomationProvider::CloseTabJSON( |
DictionaryValue* args, IPC::Message* reply_message) { |
AutomationJSONReply reply(this, reply_message); |
- Browser* browser; |
- TabContents* tab_contents; |
+ RenderViewHost* view; |
std::string error; |
- if (!GetBrowserAndTabFromJSONArgs(args, &browser, &tab_contents, &error)) { |
+ if (!GetRenderViewFromJSONArgs(args, profile(), &view, &error)) { |
reply.SendError(error); |
return; |
} |
- browser->CloseTabContents(tab_contents); |
+ view->ClosePage(); |
reply.SendSuccess(NULL); |
} |