OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 2224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2235 dict_value = static_cast<DictionaryValue*>(values.get()); | 2235 dict_value = static_cast<DictionaryValue*>(values.get()); |
2236 if (!dict_value->GetStringASCII(std::string("command"), &command)) { | 2236 if (!dict_value->GetStringASCII(std::string("command"), &command)) { |
2237 AutomationJSONReply(this, reply_message) | 2237 AutomationJSONReply(this, reply_message) |
2238 .SendError("no command key in dict or not a string command"); | 2238 .SendError("no command key in dict or not a string command"); |
2239 return; | 2239 return; |
2240 } | 2240 } |
2241 | 2241 |
2242 // Map json commands to their handlers. | 2242 // Map json commands to their handlers. |
2243 std::map<std::string, JsonHandler> handler_map; | 2243 std::map<std::string, JsonHandler> handler_map; |
2244 handler_map["WaitForAllTabsToStopLoading"] = | 2244 handler_map["WaitForAllTabsToStopLoading"] = |
2245 &TestingAutomationProvider::WaitForAllTabsToStopLoading; | 2245 &TestingAutomationProvider::WaitForAllViewsToStopLoading; |
2246 handler_map["GetIndicesFromTab"] = | 2246 handler_map["GetIndicesFromTab"] = |
2247 &TestingAutomationProvider::GetIndicesFromTab; | 2247 &TestingAutomationProvider::GetIndicesFromTab; |
2248 handler_map["NavigateToURL"] = | 2248 handler_map["NavigateToURL"] = |
2249 &TestingAutomationProvider::NavigateToURL; | 2249 &TestingAutomationProvider::NavigateToURL; |
2250 handler_map["GetLocalStatePrefsInfo"] = | 2250 handler_map["GetLocalStatePrefsInfo"] = |
2251 &TestingAutomationProvider::GetLocalStatePrefsInfo; | 2251 &TestingAutomationProvider::GetLocalStatePrefsInfo; |
2252 handler_map["SetLocalStatePrefs"] = | 2252 handler_map["SetLocalStatePrefs"] = |
2253 &TestingAutomationProvider::SetLocalStatePrefs; | 2253 &TestingAutomationProvider::SetLocalStatePrefs; |
2254 handler_map["ExecuteJavascript"] = | 2254 handler_map["ExecuteJavascript"] = |
2255 &TestingAutomationProvider::ExecuteJavascriptJSON; | 2255 &TestingAutomationProvider::ExecuteJavascriptJSON; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2300 handler_map["ActivateTab"] = | 2300 handler_map["ActivateTab"] = |
2301 &TestingAutomationProvider::ActivateTabJSON; | 2301 &TestingAutomationProvider::ActivateTabJSON; |
2302 handler_map["GetAppModalDialogMessage"] = | 2302 handler_map["GetAppModalDialogMessage"] = |
2303 &TestingAutomationProvider::GetAppModalDialogMessage; | 2303 &TestingAutomationProvider::GetAppModalDialogMessage; |
2304 handler_map["AcceptOrDismissAppModalDialog"] = | 2304 handler_map["AcceptOrDismissAppModalDialog"] = |
2305 &TestingAutomationProvider::AcceptOrDismissAppModalDialog; | 2305 &TestingAutomationProvider::AcceptOrDismissAppModalDialog; |
2306 handler_map["GetChromeDriverAutomationVersion"] = | 2306 handler_map["GetChromeDriverAutomationVersion"] = |
2307 &TestingAutomationProvider::GetChromeDriverAutomationVersion; | 2307 &TestingAutomationProvider::GetChromeDriverAutomationVersion; |
2308 handler_map["UpdateExtensionsNow"] = | 2308 handler_map["UpdateExtensionsNow"] = |
2309 &TestingAutomationProvider::UpdateExtensionsNow; | 2309 &TestingAutomationProvider::UpdateExtensionsNow; |
| 2310 handler_map["IsPageActionVisible"] = |
| 2311 &TestingAutomationProvider::IsPageActionVisible; |
2310 handler_map["CreateNewAutomationProvider"] = | 2312 handler_map["CreateNewAutomationProvider"] = |
2311 &TestingAutomationProvider::CreateNewAutomationProvider; | 2313 &TestingAutomationProvider::CreateNewAutomationProvider; |
2312 handler_map["GetBrowserInfo"] = | 2314 handler_map["GetBrowserInfo"] = |
2313 &TestingAutomationProvider::GetBrowserInfo; | 2315 &TestingAutomationProvider::GetBrowserInfo; |
2314 handler_map["OpenNewBrowserWindowWithNewProfile"] = | 2316 handler_map["OpenNewBrowserWindowWithNewProfile"] = |
2315 &TestingAutomationProvider::OpenNewBrowserWindowWithNewProfile; | 2317 &TestingAutomationProvider::OpenNewBrowserWindowWithNewProfile; |
2316 handler_map["GetMultiProfileInfo"] = | 2318 handler_map["GetMultiProfileInfo"] = |
2317 &TestingAutomationProvider::GetMultiProfileInfo; | 2319 &TestingAutomationProvider::GetMultiProfileInfo; |
2318 handler_map["GetProcessInfo"] = | 2320 handler_map["GetProcessInfo"] = |
2319 &TestingAutomationProvider::GetProcessInfo; | 2321 &TestingAutomationProvider::GetProcessInfo; |
(...skipping 2089 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4409 extension_value->Set("api_permissions", GetAPIPermissions(extension)); | 4411 extension_value->Set("api_permissions", GetAPIPermissions(extension)); |
4410 Extension::Location location = extension->location(); | 4412 Extension::Location location = extension->location(); |
4411 extension_value->SetBoolean("is_component", | 4413 extension_value->SetBoolean("is_component", |
4412 location == Extension::COMPONENT); | 4414 location == Extension::COMPONENT); |
4413 extension_value->SetBoolean("is_internal", location == Extension::INTERNAL); | 4415 extension_value->SetBoolean("is_internal", location == Extension::INTERNAL); |
4414 extension_value->SetBoolean("is_user_installed", | 4416 extension_value->SetBoolean("is_user_installed", |
4415 location == Extension::INTERNAL || location == Extension::LOAD); | 4417 location == Extension::INTERNAL || location == Extension::LOAD); |
4416 extension_value->SetBoolean("is_enabled", service->IsExtensionEnabled(id)); | 4418 extension_value->SetBoolean("is_enabled", service->IsExtensionEnabled(id)); |
4417 extension_value->SetBoolean("allowed_in_incognito", | 4419 extension_value->SetBoolean("allowed_in_incognito", |
4418 service->IsIncognitoEnabled(id)); | 4420 service->IsIncognitoEnabled(id)); |
| 4421 extension_value->SetBoolean("has_page_action", |
| 4422 extension->page_action() != NULL); |
4419 extensions_values->Append(extension_value); | 4423 extensions_values->Append(extension_value); |
4420 } | 4424 } |
4421 return_value->Set("extensions", extensions_values); | 4425 return_value->Set("extensions", extensions_values); |
4422 reply.SendSuccess(return_value.get()); | 4426 reply.SendSuccess(return_value.get()); |
4423 } | 4427 } |
4424 | 4428 |
4425 // See UninstallExtensionById() in chrome/test/pyautolib/pyauto.py for sample | 4429 // See UninstallExtensionById() in chrome/test/pyautolib/pyauto.py for sample |
4426 // json input. | 4430 // json input. |
4427 // Sample json output: {} | 4431 // Sample json output: {} |
4428 void TestingAutomationProvider::UninstallExtensionById( | 4432 void TestingAutomationProvider::UninstallExtensionById( |
4429 DictionaryValue* args, | 4433 DictionaryValue* args, |
4430 IPC::Message* reply_message) { | 4434 IPC::Message* reply_message) { |
4431 std::string id; | 4435 const Extension* extension; |
4432 if (!args->GetString("id", &id)) { | 4436 std::string error; |
4433 AutomationJSONReply(this, reply_message).SendError( | 4437 if (!GetExtensionFromJSONArgs(args, "id", profile(), &extension, &error)) { |
4434 "Must include string id."); | 4438 AutomationJSONReply(this, reply_message).SendError(error); |
4435 return; | 4439 return; |
4436 } | 4440 } |
4437 ExtensionService* service = profile()->GetExtensionService(); | 4441 ExtensionService* service = profile()->GetExtensionService(); |
4438 if (!service) { | 4442 if (!service) { |
4439 AutomationJSONReply(this, reply_message).SendError( | 4443 AutomationJSONReply(this, reply_message).SendError( |
4440 "No extensions service."); | 4444 "No extensions service."); |
4441 return; | 4445 return; |
4442 } | 4446 } |
4443 | 4447 |
4444 if (!service->GetExtensionById(id, true) && | |
4445 !service->GetTerminatedExtension(id)) { | |
4446 // The extension ID does not correspond to any extension, whether crashed | |
4447 // or not. | |
4448 AutomationJSONReply(this, reply_message).SendError(base::StringPrintf( | |
4449 "Extension does not exist: %s.", id.c_str())); | |
4450 return; | |
4451 } | |
4452 | |
4453 // Wait for a notification indicating that the extension with the given ID | 4448 // Wait for a notification indicating that the extension with the given ID |
4454 // has been uninstalled. This observer will delete itself. | 4449 // has been uninstalled. This observer will delete itself. |
4455 new ExtensionUninstallObserver(this, reply_message, id); | 4450 new ExtensionUninstallObserver(this, reply_message, extension->id()); |
4456 service->UninstallExtension(id, false, NULL); | 4451 service->UninstallExtension(extension->id(), false, NULL); |
4457 } | 4452 } |
4458 | 4453 |
4459 // See SetExtensionStateById() in chrome/test/pyautolib/pyauto.py | 4454 // See SetExtensionStateById() in chrome/test/pyautolib/pyauto.py |
4460 // for sample json input. | 4455 // for sample json input. |
4461 void TestingAutomationProvider::SetExtensionStateById( | 4456 void TestingAutomationProvider::SetExtensionStateById( |
4462 DictionaryValue* args, | 4457 DictionaryValue* args, |
4463 IPC::Message* reply_message) { | 4458 IPC::Message* reply_message) { |
4464 std::string id; | 4459 const Extension* extension; |
4465 if (!args->GetString("id", &id)) { | 4460 std::string error; |
4466 AutomationJSONReply(this, reply_message) | 4461 if (!GetExtensionFromJSONArgs(args, "id", profile(), &extension, &error)) { |
4467 .SendError("Missing or invalid key: id"); | 4462 AutomationJSONReply(this, reply_message).SendError(error); |
4468 return; | 4463 return; |
4469 } | 4464 } |
4470 | 4465 |
4471 bool enable; | 4466 bool enable; |
4472 if (!args->GetBoolean("enable", &enable)) { | 4467 if (!args->GetBoolean("enable", &enable)) { |
4473 AutomationJSONReply(this, reply_message) | 4468 AutomationJSONReply(this, reply_message) |
4474 .SendError("Missing or invalid key: enable"); | 4469 .SendError("Missing or invalid key: enable"); |
4475 return; | 4470 return; |
4476 } | 4471 } |
4477 | 4472 |
(...skipping 12 matching lines...) Expand all Loading... |
4490 } | 4485 } |
4491 | 4486 |
4492 ExtensionService* service = profile()->GetExtensionService(); | 4487 ExtensionService* service = profile()->GetExtensionService(); |
4493 ExtensionProcessManager* manager = profile()->GetExtensionProcessManager(); | 4488 ExtensionProcessManager* manager = profile()->GetExtensionProcessManager(); |
4494 if (!service) { | 4489 if (!service) { |
4495 AutomationJSONReply(this, reply_message) | 4490 AutomationJSONReply(this, reply_message) |
4496 .SendError("No extensions service or process manager."); | 4491 .SendError("No extensions service or process manager."); |
4497 return; | 4492 return; |
4498 } | 4493 } |
4499 | 4494 |
4500 if (!service->GetExtensionById(id, true) && | |
4501 !service->GetTerminatedExtension(id)) { | |
4502 // The extension ID does not correspond to any extension, whether crashed | |
4503 // or not. | |
4504 AutomationJSONReply(this, reply_message).SendError( | |
4505 base::StringPrintf("Extension does not exist: %s.", id.c_str())); | |
4506 return; | |
4507 } | |
4508 | |
4509 service->SetIsIncognitoEnabled(id, allow_in_incognito); | |
4510 | |
4511 if (enable) { | 4495 if (enable) { |
4512 if (!service->IsExtensionEnabled(id)) { | 4496 if (!service->IsExtensionEnabled(extension->id())) { |
4513 new ExtensionReadyNotificationObserver( | 4497 new ExtensionReadyNotificationObserver( |
4514 manager, | 4498 manager, |
4515 service, | 4499 service, |
4516 this, | 4500 this, |
4517 reply_message); | 4501 reply_message); |
4518 service->EnableExtension(id); | 4502 service->EnableExtension(extension->id()); |
4519 } else { | 4503 } else { |
4520 AutomationJSONReply(this, reply_message).SendSuccess(NULL); | 4504 AutomationJSONReply(this, reply_message).SendSuccess(NULL); |
4521 } | 4505 } |
4522 } else { | 4506 } else { |
4523 service->DisableExtension(id); | 4507 service->DisableExtension(extension->id()); |
4524 AutomationJSONReply(this, reply_message).SendSuccess(NULL); | 4508 AutomationJSONReply(this, reply_message).SendSuccess(NULL); |
4525 } | 4509 } |
| 4510 |
| 4511 service->SetIsIncognitoEnabled(extension->id(), allow_in_incognito); |
4526 } | 4512 } |
4527 | 4513 |
| 4514 namespace { |
| 4515 |
| 4516 // Selects the given |browser| and |tab| if not selected already. |
| 4517 void EnsureTabSelected(Browser* browser, TabContents* tab) { |
| 4518 TabContentsWrapper* active = |
| 4519 browser->tabstrip_model()->GetActiveTabContents(); |
| 4520 if (!active || active->tab_contents() != tab || |
| 4521 browser != BrowserList::GetLastActive()) { |
| 4522 browser->ActivateTabAt( |
| 4523 browser->tabstrip_model()->GetIndexOfController(&tab->controller()), |
| 4524 true /* user_gesture */); |
| 4525 } |
| 4526 } |
| 4527 |
| 4528 } // namespace |
| 4529 |
4528 // See TriggerPageActionById() in chrome/test/pyautolib/pyauto.py | 4530 // See TriggerPageActionById() in chrome/test/pyautolib/pyauto.py |
4529 // for sample json input. | 4531 // for sample json input. |
4530 void TestingAutomationProvider::TriggerPageActionById( | 4532 void TestingAutomationProvider::TriggerPageActionById( |
4531 DictionaryValue* args, | 4533 DictionaryValue* args, |
4532 IPC::Message* reply_message) { | 4534 IPC::Message* reply_message) { |
4533 AutomationJSONReply reply(this, reply_message); | |
4534 | |
4535 std::string error; | 4535 std::string error; |
4536 Browser* browser; | 4536 Browser* browser; |
4537 if (!GetBrowserFromJSONArgs(args, &browser, &error)) { | 4537 TabContents* tab; |
4538 reply.SendError(error); | 4538 if (!GetBrowserAndTabFromJSONArgs(args, &browser, &tab, &error)) { |
| 4539 AutomationJSONReply(this, reply_message).SendError(error); |
4539 return; | 4540 return; |
4540 } | 4541 } |
4541 std::string id; | 4542 const Extension* extension; |
4542 if (!args->GetString("id", &id)) { | 4543 if (!GetEnabledExtensionFromJSONArgs( |
4543 reply.SendError("Missing or invalid key: id"); | 4544 args, "id", profile(), &extension, &error)) { |
| 4545 AutomationJSONReply(this, reply_message).SendError(error); |
| 4546 return; |
| 4547 } |
| 4548 ExtensionAction* page_action = extension->page_action(); |
| 4549 if (!page_action) { |
| 4550 AutomationJSONReply(this, reply_message).SendError( |
| 4551 "Extension doesn't have any page action."); |
| 4552 return; |
| 4553 } |
| 4554 EnsureTabSelected(browser, tab); |
| 4555 |
| 4556 bool pressed = false; |
| 4557 LocationBarTesting* loc_bar = |
| 4558 browser->window()->GetLocationBar()->GetLocationBarForTesting(); |
| 4559 size_t page_action_visible_count = |
| 4560 static_cast<size_t>(loc_bar->PageActionVisibleCount()); |
| 4561 for (size_t i = 0; i < page_action_visible_count; ++i) { |
| 4562 if (loc_bar->GetVisiblePageAction(i) == page_action) { |
| 4563 loc_bar->TestPageActionPressed(i); |
| 4564 pressed = true; |
| 4565 break; |
| 4566 } |
| 4567 } |
| 4568 if (!pressed) { |
| 4569 AutomationJSONReply(this, reply_message).SendError( |
| 4570 "Extension's page action is not visible."); |
4544 return; | 4571 return; |
4545 } | 4572 } |
4546 | 4573 |
4547 ExtensionService* service = browser->profile()->GetExtensionService(); | 4574 if (page_action->HasPopup(ExtensionTabUtil::GetTabId(tab))) { |
4548 if (!service) { | 4575 // This observer will delete itself. |
4549 reply.SendError("No extensions service."); | 4576 new ExtensionPopupObserver( |
4550 return; | 4577 this, reply_message, extension->id()); |
4551 } | |
4552 if (!service->GetInstalledExtension(id)) { | |
4553 // The extension ID does not correspond to any extension, whether crashed | |
4554 // or not. | |
4555 reply.SendError(base::StringPrintf("Extension %s is not installed.", | |
4556 id.c_str())); | |
4557 return; | |
4558 } | |
4559 const Extension* extension = service->GetExtensionById(id, false); | |
4560 if (!extension) { | |
4561 reply.SendError("Extension is disabled or has crashed."); | |
4562 return; | |
4563 } | |
4564 | |
4565 if (ExtensionAction* page_action = extension->page_action()) { | |
4566 LocationBarTesting* loc_bar = | |
4567 browser->window()->GetLocationBar()->GetLocationBarForTesting(); | |
4568 size_t page_action_visible_count = | |
4569 static_cast<size_t>(loc_bar->PageActionVisibleCount()); | |
4570 for (size_t i = 0; i < page_action_visible_count; ++i) { | |
4571 if (loc_bar->GetVisiblePageAction(i) == page_action) { | |
4572 loc_bar->TestPageActionPressed(i); | |
4573 reply.SendSuccess(NULL); | |
4574 return; | |
4575 } | |
4576 } | |
4577 reply.SendError("Extension doesn't have any visible page action icon."); | |
4578 } else { | 4578 } else { |
4579 reply.SendError("Extension doesn't have any page action."); | 4579 AutomationJSONReply(this, reply_message).SendSuccess(NULL); |
4580 } | 4580 } |
4581 } | 4581 } |
4582 | 4582 |
4583 // See TriggerBrowserActionById() in chrome/test/pyautolib/pyauto.py | 4583 // See TriggerBrowserActionById() in chrome/test/pyautolib/pyauto.py |
4584 // for sample json input. | 4584 // for sample json input. |
4585 void TestingAutomationProvider::TriggerBrowserActionById( | 4585 void TestingAutomationProvider::TriggerBrowserActionById( |
4586 DictionaryValue* args, | 4586 DictionaryValue* args, |
4587 IPC::Message* reply_message) { | 4587 IPC::Message* reply_message) { |
4588 AutomationJSONReply reply(this, reply_message); | |
4589 | |
4590 std::string error; | 4588 std::string error; |
4591 Browser* browser; | 4589 Browser* browser; |
4592 if (!GetBrowserFromJSONArgs(args, &browser, &error)) { | 4590 TabContents* tab; |
4593 reply.SendError(error); | 4591 if (!GetBrowserAndTabFromJSONArgs(args, &browser, &tab, &error)) { |
| 4592 AutomationJSONReply(this, reply_message).SendError(error); |
4594 return; | 4593 return; |
4595 } | 4594 } |
4596 std::string id; | 4595 const Extension* extension; |
4597 if (!args->GetString("id", &id)) { | 4596 if (!GetEnabledExtensionFromJSONArgs( |
4598 reply.SendError("Missing or invalid key: id"); | 4597 args, "id", profile(), &extension, &error)) { |
| 4598 AutomationJSONReply(this, reply_message).SendError(error); |
4599 return; | 4599 return; |
4600 } | 4600 } |
4601 | 4601 ExtensionAction* action = extension->browser_action(); |
4602 ExtensionService* service = browser->profile()->GetExtensionService(); | 4602 if (!action) { |
4603 if (!service) { | 4603 AutomationJSONReply(this, reply_message).SendError( |
4604 reply.SendError("No extensions service."); | 4604 "Extension doesn't have any browser action."); |
4605 return; | 4605 return; |
4606 } | 4606 } |
4607 if (!service->GetInstalledExtension(id)) { | 4607 EnsureTabSelected(browser, tab); |
4608 // The extension ID does not correspond to any extension, whether crashed | 4608 |
4609 // or not. | 4609 BrowserActionTestUtil browser_actions(browser); |
4610 reply.SendError(base::StringPrintf("Extension %s is not installed.", | 4610 int num_browser_actions = browser_actions.NumberOfBrowserActions(); |
4611 id.c_str())); | 4611 int action_index = -1; |
| 4612 #if defined(TOOLKIT_VIEWS) |
| 4613 for (int i = 0; i < num_browser_actions; ++i) { |
| 4614 if (extension->id() == browser_actions.GetExtensionId(i)) { |
| 4615 action_index = i; |
| 4616 break; |
| 4617 } |
| 4618 } |
| 4619 #else |
| 4620 // TODO(kkania): Implement the platform-specific GetExtensionId() in |
| 4621 // BrowserActionTestUtil. |
| 4622 if (num_browser_actions != 1) { |
| 4623 AutomationJSONReply(this, reply_message).SendError(StringPrintf( |
| 4624 "Found %d browser actions. Only one browser action must be active.", |
| 4625 num_browser_actions)); |
4612 return; | 4626 return; |
4613 } | 4627 } |
4614 const Extension* extension = service->GetExtensionById(id, false); | 4628 // This extension has a browser action, and there's only one action, so this |
4615 if (!extension) { | 4629 // must be the first one. |
4616 reply.SendError("Extension is disabled or has crashed."); | 4630 action_index = 0; |
| 4631 #endif |
| 4632 if (action_index == -1) { |
| 4633 AutomationJSONReply(this, reply_message).SendError( |
| 4634 "Extension's browser action is not visible."); |
4617 return; | 4635 return; |
4618 } | 4636 } |
| 4637 browser_actions.Press(action_index); |
4619 | 4638 |
4620 if (extension->browser_action()) { | 4639 if (action->HasPopup(ExtensionTabUtil::GetTabId(tab))) { |
4621 BrowserActionTestUtil browser_actions(browser); | 4640 // This observer will delete itself. |
4622 int num_browser_actions = browser_actions.NumberOfBrowserActions(); | 4641 new ExtensionPopupObserver( |
4623 // TODO: Implement the platform-specific GetExtensionId() in | 4642 this, reply_message, extension->id()); |
4624 // BrowserActionTestUtil. | |
4625 if (num_browser_actions != 1) { | |
4626 reply.SendError(StringPrintf( | |
4627 "Found %d browser actions. Only one browser action must be active.", | |
4628 num_browser_actions)); | |
4629 return; | |
4630 } | |
4631 browser_actions.Press(0); | |
4632 reply.SendSuccess(NULL); | |
4633 return; | |
4634 } else { | 4643 } else { |
4635 reply.SendError("Extension doesn't have any browser action."); | 4644 AutomationJSONReply(this, reply_message).SendSuccess(NULL); |
4636 return; | |
4637 } | 4645 } |
4638 } | 4646 } |
4639 | 4647 |
4640 // Sample json input: | 4648 // Sample json input: |
4641 // { "command": "GetAutofillProfile" } | 4649 // { "command": "GetAutofillProfile" } |
4642 // Refer to GetAutofillProfile() in chrome/test/pyautolib/pyauto.py for sample | 4650 // Refer to GetAutofillProfile() in chrome/test/pyautolib/pyauto.py for sample |
4643 // json output. | 4651 // json output. |
4644 void TestingAutomationProvider::GetAutofillProfile( | 4652 void TestingAutomationProvider::GetAutofillProfile( |
4645 Browser* browser, | 4653 Browser* browser, |
4646 DictionaryValue* args, | 4654 DictionaryValue* args, |
(...skipping 1224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5871 } else { | 5879 } else { |
5872 reply.SendError( | 5880 reply.SendError( |
5873 StringPrintf("Unexpected launch type '%s'.", launch_type_str.c_str())); | 5881 StringPrintf("Unexpected launch type '%s'.", launch_type_str.c_str())); |
5874 return; | 5882 return; |
5875 } | 5883 } |
5876 | 5884 |
5877 service->extension_prefs()->SetLaunchType(extension->id(), launch_type); | 5885 service->extension_prefs()->SetLaunchType(extension->id(), launch_type); |
5878 reply.SendSuccess(NULL); | 5886 reply.SendSuccess(NULL); |
5879 } | 5887 } |
5880 | 5888 |
5881 void TestingAutomationProvider::WaitForAllTabsToStopLoading( | 5889 void TestingAutomationProvider::WaitForAllViewsToStopLoading( |
5882 DictionaryValue* args, | 5890 DictionaryValue* args, |
5883 IPC::Message* reply_message) { | 5891 IPC::Message* reply_message) { |
5884 if (AppModalDialogQueue::GetInstance()->HasActiveDialog()) { | 5892 if (AppModalDialogQueue::GetInstance()->HasActiveDialog()) { |
5885 AutomationJSONReply(this, reply_message).SendSuccess(NULL); | 5893 AutomationJSONReply(this, reply_message).SendSuccess(NULL); |
5886 return; | 5894 return; |
5887 } | 5895 } |
5888 | 5896 |
5889 // This class will send the message immediately if no tab is loading. | 5897 // This class will send the message immediately if no tab is loading. |
5890 new AllTabsStoppedLoadingObserver(this, reply_message); | 5898 new AllViewsStoppedLoadingObserver( |
| 5899 this, reply_message, profile()->GetExtensionProcessManager()); |
5891 } | 5900 } |
5892 | 5901 |
5893 void TestingAutomationProvider::SetPolicies( | 5902 void TestingAutomationProvider::SetPolicies( |
5894 DictionaryValue* args, | 5903 DictionaryValue* args, |
5895 IPC::Message* reply_message) { | 5904 IPC::Message* reply_message) { |
5896 scoped_ptr<AutomationJSONReply> reply( | 5905 scoped_ptr<AutomationJSONReply> reply( |
5897 new AutomationJSONReply(this, reply_message)); | 5906 new AutomationJSONReply(this, reply_message)); |
5898 | 5907 |
5899 #if !defined(ENABLE_CONFIGURATION_POLICY) || defined(OFFICIAL_BUILD) | 5908 #if !defined(ENABLE_CONFIGURATION_POLICY) || defined(OFFICIAL_BUILD) |
5900 reply->SendError("Configuration Policy disabled"); | 5909 reply->SendError("Configuration Policy disabled"); |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6289 profile()->GetExtensionProcessManager(); | 6298 profile()->GetExtensionProcessManager(); |
6290 ExtensionProcessManager::const_iterator iter; | 6299 ExtensionProcessManager::const_iterator iter; |
6291 for (iter = extension_mgr->begin(); iter != extension_mgr->end(); | 6300 for (iter = extension_mgr->begin(); iter != extension_mgr->end(); |
6292 ++iter) { | 6301 ++iter) { |
6293 ExtensionHost* host = *iter; | 6302 ExtensionHost* host = *iter; |
6294 DictionaryValue* dict = new DictionaryValue(); | 6303 DictionaryValue* dict = new DictionaryValue(); |
6295 AutomationId id = automation_util::GetIdForExtensionView(host); | 6304 AutomationId id = automation_util::GetIdForExtensionView(host); |
6296 if (!id.is_valid()) | 6305 if (!id.is_valid()) |
6297 continue; | 6306 continue; |
6298 dict->Set("auto_id", id.ToValue()); | 6307 dict->Set("auto_id", id.ToValue()); |
6299 dict->Set("extension_id", automation_util::GetIdForExtension( | 6308 dict->SetString("extension_id", host->extension_id()); |
6300 host->extension()).ToValue()); | |
6301 view_list->Append(dict); | 6309 view_list->Append(dict); |
6302 } | 6310 } |
6303 DictionaryValue dict; | 6311 DictionaryValue dict; |
6304 dict.Set("views", view_list); | 6312 dict.Set("views", view_list); |
6305 AutomationJSONReply(this, reply_message).SendSuccess(&dict); | 6313 AutomationJSONReply(this, reply_message).SendSuccess(&dict); |
6306 } | 6314 } |
6307 | 6315 |
6308 void TestingAutomationProvider::IsTabIdValid( | 6316 void TestingAutomationProvider::IsTabIdValid( |
6309 DictionaryValue* args, IPC::Message* reply_message) { | 6317 DictionaryValue* args, IPC::Message* reply_message) { |
6310 AutomationJSONReply reply(this, reply_message); | 6318 AutomationJSONReply reply(this, reply_message); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6404 return; | 6412 return; |
6405 } | 6413 } |
6406 | 6414 |
6407 // Create a new observer that waits until the extensions have been fully | 6415 // Create a new observer that waits until the extensions have been fully |
6408 // updated (we should not send the reply until after all extensions have | 6416 // updated (we should not send the reply until after all extensions have |
6409 // been updated). This observer will delete itself. | 6417 // been updated). This observer will delete itself. |
6410 new ExtensionsUpdatedObserver(manager, this, reply_message); | 6418 new ExtensionsUpdatedObserver(manager, this, reply_message); |
6411 updater->CheckNow(); | 6419 updater->CheckNow(); |
6412 } | 6420 } |
6413 | 6421 |
| 6422 void TestingAutomationProvider::IsPageActionVisible( |
| 6423 base::DictionaryValue* args, |
| 6424 IPC::Message* reply_message) { |
| 6425 AutomationJSONReply reply(this, reply_message); |
| 6426 |
| 6427 TabContents* tab; |
| 6428 std::string error; |
| 6429 if (!GetTabFromJSONArgs(args, &tab, &error)) { |
| 6430 reply.SendError(error); |
| 6431 return; |
| 6432 } |
| 6433 const Extension* extension; |
| 6434 if (!GetEnabledExtensionFromJSONArgs( |
| 6435 args, "extension_id", profile(), &extension, &error)) { |
| 6436 reply.SendError(error); |
| 6437 return; |
| 6438 } |
| 6439 ExtensionAction* page_action = extension->page_action(); |
| 6440 if (!page_action) { |
| 6441 reply.SendError("Extension doesn't have any page action"); |
| 6442 return; |
| 6443 } |
| 6444 Browser* browser = automation_util::GetBrowserForTab(tab); |
| 6445 if (!browser) { |
| 6446 reply.SendError("Tab does not belong to an open browser"); |
| 6447 return; |
| 6448 } |
| 6449 EnsureTabSelected(browser, tab); |
| 6450 |
| 6451 bool is_visible = false; |
| 6452 LocationBarTesting* loc_bar = |
| 6453 browser->window()->GetLocationBar()->GetLocationBarForTesting(); |
| 6454 size_t page_action_visible_count = |
| 6455 static_cast<size_t>(loc_bar->PageActionVisibleCount()); |
| 6456 for (size_t i = 0; i < page_action_visible_count; ++i) { |
| 6457 if (loc_bar->GetVisiblePageAction(i) == page_action) { |
| 6458 is_visible = true; |
| 6459 break; |
| 6460 } |
| 6461 } |
| 6462 DictionaryValue dict; |
| 6463 dict.SetBoolean("is_visible", is_visible); |
| 6464 reply.SendSuccess(&dict); |
| 6465 } |
| 6466 |
6414 void TestingAutomationProvider::GetChromeDriverAutomationVersion( | 6467 void TestingAutomationProvider::GetChromeDriverAutomationVersion( |
6415 DictionaryValue* args, | 6468 DictionaryValue* args, |
6416 IPC::Message* reply_message) { | 6469 IPC::Message* reply_message) { |
6417 DictionaryValue reply_dict; | 6470 DictionaryValue reply_dict; |
6418 reply_dict.SetInteger("version", automation::kChromeDriverAutomationVersion); | 6471 reply_dict.SetInteger("version", automation::kChromeDriverAutomationVersion); |
6419 AutomationJSONReply(this, reply_message).SendSuccess(&reply_dict); | 6472 AutomationJSONReply(this, reply_message).SendSuccess(&reply_dict); |
6420 } | 6473 } |
6421 | 6474 |
6422 void TestingAutomationProvider::CreateNewAutomationProvider( | 6475 void TestingAutomationProvider::CreateNewAutomationProvider( |
6423 DictionaryValue* args, | 6476 DictionaryValue* args, |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6593 | 6646 |
6594 Send(reply_message_); | 6647 Send(reply_message_); |
6595 redirect_query_ = 0; | 6648 redirect_query_ = 0; |
6596 reply_message_ = NULL; | 6649 reply_message_ = NULL; |
6597 } | 6650 } |
6598 | 6651 |
6599 void TestingAutomationProvider::OnRemoveProvider() { | 6652 void TestingAutomationProvider::OnRemoveProvider() { |
6600 if (g_browser_process) | 6653 if (g_browser_process) |
6601 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); | 6654 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); |
6602 } | 6655 } |
OLD | NEW |