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

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

Issue 8804011: WebDriver extension support in TestingAutomationProvider. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: ... Created 9 years 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
OLDNEW
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 2223 matching lines...) Expand 10 before | Expand all | Expand 10 after
2234 // Ownership remains with "values" variable. 2234 // Ownership remains with "values" variable.
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"] =
dennis_jeffrey 2011/12/06 00:49:08 Do you think it's worthwhile to change the name of
kkania 2011/12/12 17:10:06 This isn't used on the python side yet, just C++.
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
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 2101 matching lines...) Expand 10 before | Expand all | Expand 10 after
4421 return_value->Set("extensions", extensions_values); 4423 return_value->Set("extensions", extensions_values);
4422 reply.SendSuccess(return_value.get()); 4424 reply.SendSuccess(return_value.get());
4423 } 4425 }
4424 4426
4425 // See UninstallExtensionById() in chrome/test/pyautolib/pyauto.py for sample 4427 // See UninstallExtensionById() in chrome/test/pyautolib/pyauto.py for sample
4426 // json input. 4428 // json input.
4427 // Sample json output: {} 4429 // Sample json output: {}
4428 void TestingAutomationProvider::UninstallExtensionById( 4430 void TestingAutomationProvider::UninstallExtensionById(
4429 DictionaryValue* args, 4431 DictionaryValue* args,
4430 IPC::Message* reply_message) { 4432 IPC::Message* reply_message) {
4431 std::string id; 4433 const Extension* extension;
4432 if (!args->GetString("id", &id)) { 4434 std::string error;
4433 AutomationJSONReply(this, reply_message).SendError( 4435 if (!GetExtensionFromJSONArgs(args, "id", profile(), &extension, &error)) {
4434 "Must include string id."); 4436 AutomationJSONReply(this, reply_message).SendError(error);
4435 return; 4437 return;
4436 } 4438 }
4437 ExtensionService* service = profile()->GetExtensionService(); 4439 ExtensionService* service = profile()->GetExtensionService();
4438 if (!service) { 4440 if (!service) {
4439 AutomationJSONReply(this, reply_message).SendError( 4441 AutomationJSONReply(this, reply_message).SendError(
4440 "No extensions service."); 4442 "No extensions service.");
4441 return; 4443 return;
4442 } 4444 }
4443 4445
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 4446 // Wait for a notification indicating that the extension with the given ID
4454 // has been uninstalled. This observer will delete itself. 4447 // has been uninstalled. This observer will delete itself.
4455 new ExtensionUninstallObserver(this, reply_message, id); 4448 new ExtensionUninstallObserver(this, reply_message, extension->id());
4456 service->UninstallExtension(id, false, NULL); 4449 service->UninstallExtension(extension->id(), false, NULL);
4457 } 4450 }
4458 4451
4459 // See SetExtensionStateById() in chrome/test/pyautolib/pyauto.py 4452 // See SetExtensionStateById() in chrome/test/pyautolib/pyauto.py
4460 // for sample json input. 4453 // for sample json input.
4461 void TestingAutomationProvider::SetExtensionStateById( 4454 void TestingAutomationProvider::SetExtensionStateById(
4462 DictionaryValue* args, 4455 DictionaryValue* args,
4463 IPC::Message* reply_message) { 4456 IPC::Message* reply_message) {
4464 std::string id; 4457 const Extension* extension;
4465 if (!args->GetString("id", &id)) { 4458 std::string error;
4466 AutomationJSONReply(this, reply_message) 4459 if (!GetExtensionFromJSONArgs(args, "id", profile(), &extension, &error)) {
4467 .SendError("Missing or invalid key: id"); 4460 AutomationJSONReply(this, reply_message).SendError(error);
4468 return; 4461 return;
4469 } 4462 }
4470 4463
4471 bool enable; 4464 bool enable;
4472 if (!args->GetBoolean("enable", &enable)) { 4465 if (!args->GetBoolean("enable", &enable)) {
4473 AutomationJSONReply(this, reply_message) 4466 AutomationJSONReply(this, reply_message)
4474 .SendError("Missing or invalid key: enable"); 4467 .SendError("Missing or invalid key: enable");
4475 return; 4468 return;
4476 } 4469 }
4477 4470
(...skipping 12 matching lines...) Expand all
4490 } 4483 }
4491 4484
4492 ExtensionService* service = profile()->GetExtensionService(); 4485 ExtensionService* service = profile()->GetExtensionService();
4493 ExtensionProcessManager* manager = profile()->GetExtensionProcessManager(); 4486 ExtensionProcessManager* manager = profile()->GetExtensionProcessManager();
4494 if (!service) { 4487 if (!service) {
4495 AutomationJSONReply(this, reply_message) 4488 AutomationJSONReply(this, reply_message)
4496 .SendError("No extensions service or process manager."); 4489 .SendError("No extensions service or process manager.");
4497 return; 4490 return;
4498 } 4491 }
4499 4492
4500 if (!service->GetExtensionById(id, true) && 4493 service->SetIsIncognitoEnabled(extension->id(), allow_in_incognito);
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 4494
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 }
4526 } 4510 }
4527 4511
4528 // See TriggerPageActionById() in chrome/test/pyautolib/pyauto.py 4512 // See TriggerPageActionById() in chrome/test/pyautolib/pyauto.py
4529 // for sample json input. 4513 // for sample json input.
4530 void TestingAutomationProvider::TriggerPageActionById( 4514 void TestingAutomationProvider::TriggerPageActionById(
4531 DictionaryValue* args, 4515 DictionaryValue* args,
4532 IPC::Message* reply_message) { 4516 IPC::Message* reply_message) {
4533 AutomationJSONReply reply(this, reply_message);
4534
4535 std::string error; 4517 std::string error;
4536 Browser* browser; 4518 Browser* browser;
4537 if (!GetBrowserFromJSONArgs(args, &browser, &error)) { 4519 TabContents* tab;
4538 reply.SendError(error); 4520 if (!GetBrowserAndTabFromJSONArgs(args, &browser, &tab, &error)) {
4521 AutomationJSONReply(this, reply_message).SendError(error);
4539 return; 4522 return;
4540 } 4523 }
4541 std::string id; 4524 const Extension* extension;
4542 if (!args->GetString("id", &id)) { 4525 if (!GetEnabledExtensionFromJSONArgs(
4543 reply.SendError("Missing or invalid key: id"); 4526 args, "id", profile(), &extension, &error)) {
4527 AutomationJSONReply(this, reply_message).SendError(error);
4528 return;
4529 }
4530 ExtensionAction* page_action = extension->page_action();
4531 if (!page_action) {
4532 AutomationJSONReply(this, reply_message).SendError(
4533 "Extension doesn't have any page action.");
4544 return; 4534 return;
4545 } 4535 }
4546 4536
4547 ExtensionService* service = browser->profile()->GetExtensionService(); 4537 bool pressed = false;
4548 if (!service) { 4538 LocationBarTesting* loc_bar =
4549 reply.SendError("No extensions service."); 4539 browser->window()->GetLocationBar()->GetLocationBarForTesting();
4550 return; 4540 size_t page_action_visible_count =
4541 static_cast<size_t>(loc_bar->PageActionVisibleCount());
4542 for (size_t i = 0; i < page_action_visible_count; ++i) {
4543 if (loc_bar->GetVisiblePageAction(i) == page_action) {
4544 loc_bar->TestPageActionPressed(i);
4545 pressed = true;
4546 break;
4547 }
4551 } 4548 }
4552 if (!service->GetInstalledExtension(id)) { 4549 if (!pressed) {
4553 // The extension ID does not correspond to any extension, whether crashed 4550 AutomationJSONReply(this, reply_message).SendError(
4554 // or not. 4551 "Extension's page action is not visible.");
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; 4552 return;
4563 } 4553 }
4564 4554
4565 if (ExtensionAction* page_action = extension->page_action()) { 4555 if (page_action->HasPopup(ExtensionTabUtil::GetTabId(tab))) {
4566 LocationBarTesting* loc_bar = 4556 new ExtensionPopupObserver(
4567 browser->window()->GetLocationBar()->GetLocationBarForTesting(); 4557 this, reply_message, extension->id());
dennis_jeffrey 2011/12/06 00:49:08 maybe add a comment to explicitly say that this ob
kkania 2011/12/12 17:10:06 Done.
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 { 4558 } else {
4579 reply.SendError("Extension doesn't have any page action."); 4559 AutomationJSONReply(this, reply_message).SendSuccess(NULL);
4580 } 4560 }
4581 } 4561 }
4582 4562
4583 // See TriggerBrowserActionById() in chrome/test/pyautolib/pyauto.py 4563 // See TriggerBrowserActionById() in chrome/test/pyautolib/pyauto.py
4584 // for sample json input. 4564 // for sample json input.
4585 void TestingAutomationProvider::TriggerBrowserActionById( 4565 void TestingAutomationProvider::TriggerBrowserActionById(
4586 DictionaryValue* args, 4566 DictionaryValue* args,
4587 IPC::Message* reply_message) { 4567 IPC::Message* reply_message) {
4588 AutomationJSONReply reply(this, reply_message);
4589
4590 std::string error; 4568 std::string error;
4591 Browser* browser; 4569 Browser* browser;
4592 if (!GetBrowserFromJSONArgs(args, &browser, &error)) { 4570 TabContents* tab;
4593 reply.SendError(error); 4571 if (!GetBrowserAndTabFromJSONArgs(args, &browser, &tab, &error)) {
4572 AutomationJSONReply(this, reply_message).SendError(error);
4594 return; 4573 return;
4595 } 4574 }
4596 std::string id; 4575 const Extension* extension;
4597 if (!args->GetString("id", &id)) { 4576 if (!GetEnabledExtensionFromJSONArgs(
4598 reply.SendError("Missing or invalid key: id"); 4577 args, "id", profile(), &extension, &error)) {
4578 AutomationJSONReply(this, reply_message).SendError(error);
4579 return;
4580 }
4581 ExtensionAction* action = extension->browser_action();
4582 if (!action) {
4583 AutomationJSONReply(this, reply_message).SendError(
4584 "Extension doesn't have any browser action.");
4599 return; 4585 return;
4600 } 4586 }
4601 4587
4602 ExtensionService* service = browser->profile()->GetExtensionService(); 4588 BrowserActionTestUtil browser_actions(browser);
4603 if (!service) { 4589 int num_browser_actions = browser_actions.NumberOfBrowserActions();
4604 reply.SendError("No extensions service."); 4590 int action_index = -1;
4591 #if defined(TOOLKIT_VIEWS)
4592 for (int i = 0; i < num_browser_actions; ++i) {
4593 if (extension->id() == browser_actions.GetExtensionId(i)) {
4594 action_index = i;
4595 break;
4596 }
4597 }
4598 #else
4599 // TODO: Implement the platform-specific GetExtensionId() in
dennis_jeffrey 2011/12/06 00:49:08 username for the TODO?
kkania 2011/12/12 17:10:06 Frank originally put this here, but I'm willing to
4600 // BrowserActionTestUtil.
4601 if (num_browser_actions != 1) {
4602 AutomationJSONReply(this, reply_message).SendError(StringPrintf(
4603 "Found %d browser actions. Only one browser action must be active.",
4604 num_browser_actions));
4605 return; 4605 return;
4606 } 4606 }
4607 if (!service->GetInstalledExtension(id)) { 4607 // This extension has a browser action, and there's only one action, so this
4608 // The extension ID does not correspond to any extension, whether crashed 4608 // must be the first one.
4609 // or not. 4609 action_index = 0;
4610 reply.SendError(base::StringPrintf("Extension %s is not installed.", 4610 #endif
4611 id.c_str())); 4611 if (action_index == -1) {
4612 AutomationJSONReply(this, reply_message).SendError(
4613 "Extension's browser action is not visible.");
4612 return; 4614 return;
4613 } 4615 }
4614 const Extension* extension = service->GetExtensionById(id, false); 4616 browser_actions.Press(action_index);
4615 if (!extension) {
4616 reply.SendError("Extension is disabled or has crashed.");
4617 return;
4618 }
4619 4617
4620 if (extension->browser_action()) { 4618 if (action->HasPopup(ExtensionTabUtil::GetTabId(tab))) {
4621 BrowserActionTestUtil browser_actions(browser); 4619 new ExtensionPopupObserver(
4622 int num_browser_actions = browser_actions.NumberOfBrowserActions(); 4620 this, reply_message, extension->id());
dennis_jeffrey 2011/12/06 00:49:08 maybe add a comment to explicitly say that this ob
kkania 2011/12/12 17:10:06 Done.
4623 // TODO: Implement the platform-specific GetExtensionId() in
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 { 4621 } else {
4635 reply.SendError("Extension doesn't have any browser action."); 4622 AutomationJSONReply(this, reply_message).SendSuccess(NULL);
4636 return;
4637 } 4623 }
4638 } 4624 }
4639 4625
4640 // Sample json input: 4626 // Sample json input:
4641 // { "command": "GetAutofillProfile" } 4627 // { "command": "GetAutofillProfile" }
4642 // Refer to GetAutofillProfile() in chrome/test/pyautolib/pyauto.py for sample 4628 // Refer to GetAutofillProfile() in chrome/test/pyautolib/pyauto.py for sample
4643 // json output. 4629 // json output.
4644 void TestingAutomationProvider::GetAutofillProfile( 4630 void TestingAutomationProvider::GetAutofillProfile(
4645 Browser* browser, 4631 Browser* browser,
4646 DictionaryValue* args, 4632 DictionaryValue* args,
(...skipping 1224 matching lines...) Expand 10 before | Expand all | Expand 10 after
5871 } else { 5857 } else {
5872 reply.SendError( 5858 reply.SendError(
5873 StringPrintf("Unexpected launch type '%s'.", launch_type_str.c_str())); 5859 StringPrintf("Unexpected launch type '%s'.", launch_type_str.c_str()));
5874 return; 5860 return;
5875 } 5861 }
5876 5862
5877 service->extension_prefs()->SetLaunchType(extension->id(), launch_type); 5863 service->extension_prefs()->SetLaunchType(extension->id(), launch_type);
5878 reply.SendSuccess(NULL); 5864 reply.SendSuccess(NULL);
5879 } 5865 }
5880 5866
5881 void TestingAutomationProvider::WaitForAllTabsToStopLoading( 5867 void TestingAutomationProvider::WaitForAllViewsToStopLoading(
5882 DictionaryValue* args, 5868 DictionaryValue* args,
5883 IPC::Message* reply_message) { 5869 IPC::Message* reply_message) {
5884 if (AppModalDialogQueue::GetInstance()->HasActiveDialog()) { 5870 if (AppModalDialogQueue::GetInstance()->HasActiveDialog()) {
5885 AutomationJSONReply(this, reply_message).SendSuccess(NULL); 5871 AutomationJSONReply(this, reply_message).SendSuccess(NULL);
5886 return; 5872 return;
5887 } 5873 }
5888 5874
5889 // This class will send the message immediately if no tab is loading. 5875 // This class will send the message immediately if no tab is loading.
5890 new AllTabsStoppedLoadingObserver(this, reply_message); 5876 new AllViewsStoppedLoadingObserver(
5877 this, reply_message, profile()->GetExtensionProcessManager());
5891 } 5878 }
5892 5879
5893 void TestingAutomationProvider::SetPolicies( 5880 void TestingAutomationProvider::SetPolicies(
5894 DictionaryValue* args, 5881 DictionaryValue* args,
5895 IPC::Message* reply_message) { 5882 IPC::Message* reply_message) {
5896 scoped_ptr<AutomationJSONReply> reply( 5883 scoped_ptr<AutomationJSONReply> reply(
5897 new AutomationJSONReply(this, reply_message)); 5884 new AutomationJSONReply(this, reply_message));
5898 5885
5899 #if !defined(ENABLE_CONFIGURATION_POLICY) || defined(OFFICIAL_BUILD) 5886 #if !defined(ENABLE_CONFIGURATION_POLICY) || defined(OFFICIAL_BUILD)
5900 reply->SendError("Configuration Policy disabled"); 5887 reply->SendError("Configuration Policy disabled");
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
6289 profile()->GetExtensionProcessManager(); 6276 profile()->GetExtensionProcessManager();
6290 ExtensionProcessManager::const_iterator iter; 6277 ExtensionProcessManager::const_iterator iter;
6291 for (iter = extension_mgr->begin(); iter != extension_mgr->end(); 6278 for (iter = extension_mgr->begin(); iter != extension_mgr->end();
6292 ++iter) { 6279 ++iter) {
6293 ExtensionHost* host = *iter; 6280 ExtensionHost* host = *iter;
6294 DictionaryValue* dict = new DictionaryValue(); 6281 DictionaryValue* dict = new DictionaryValue();
6295 AutomationId id = automation_util::GetIdForExtensionView(host); 6282 AutomationId id = automation_util::GetIdForExtensionView(host);
6296 if (!id.is_valid()) 6283 if (!id.is_valid())
6297 continue; 6284 continue;
6298 dict->Set("auto_id", id.ToValue()); 6285 dict->Set("auto_id", id.ToValue());
6299 dict->Set("extension_id", automation_util::GetIdForExtension( 6286 dict->SetString("extension_id", host->extension_id());
6300 host->extension()).ToValue());
6301 view_list->Append(dict); 6287 view_list->Append(dict);
6302 } 6288 }
6303 DictionaryValue dict; 6289 DictionaryValue dict;
6304 dict.Set("views", view_list); 6290 dict.Set("views", view_list);
6305 AutomationJSONReply(this, reply_message).SendSuccess(&dict); 6291 AutomationJSONReply(this, reply_message).SendSuccess(&dict);
6306 } 6292 }
6307 6293
6308 void TestingAutomationProvider::IsTabIdValid( 6294 void TestingAutomationProvider::IsTabIdValid(
6309 DictionaryValue* args, IPC::Message* reply_message) { 6295 DictionaryValue* args, IPC::Message* reply_message) {
6310 AutomationJSONReply reply(this, reply_message); 6296 AutomationJSONReply reply(this, reply_message);
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
6404 return; 6390 return;
6405 } 6391 }
6406 6392
6407 // Create a new observer that waits until the extensions have been fully 6393 // 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 6394 // updated (we should not send the reply until after all extensions have
6409 // been updated). This observer will delete itself. 6395 // been updated). This observer will delete itself.
6410 new ExtensionsUpdatedObserver(manager, this, reply_message); 6396 new ExtensionsUpdatedObserver(manager, this, reply_message);
6411 updater->CheckNow(); 6397 updater->CheckNow();
6412 } 6398 }
6413 6399
6400 void TestingAutomationProvider::IsPageActionVisible(
6401 base::DictionaryValue* args,
6402 IPC::Message* reply_message) {
6403 AutomationJSONReply reply(this, reply_message);
6404
6405 TabContents* tab;
6406 std::string error;
6407 if (!GetTabFromJSONArgs(args, &tab, &error)) {
6408 reply.SendError(error);
6409 return;
6410 }
6411 const Extension* extension;
6412 if (!GetEnabledExtensionFromJSONArgs(
6413 args, "extension_id", profile(), &extension, &error)) {
6414 reply.SendError(error);
6415 return;
6416 }
6417 ExtensionAction* page_action = extension->page_action();
6418 if (!page_action) {
6419 reply.SendError("Extension doesn't have any page action");
6420 return;
6421 }
6422 Browser* browser = automation_util::GetBrowserForTab(tab);
6423 if (!browser) {
6424 reply.SendError("Tab does not belong to an open browser");
6425 return;
6426 }
6427
6428 bool is_visible = false;
6429 LocationBarTesting* loc_bar =
6430 browser->window()->GetLocationBar()->GetLocationBarForTesting();
6431 size_t page_action_visible_count =
6432 static_cast<size_t>(loc_bar->PageActionVisibleCount());
6433 for (size_t i = 0; i < page_action_visible_count; ++i) {
6434 if (loc_bar->GetVisiblePageAction(i) == page_action) {
6435 is_visible = true;
6436 break;
6437 }
6438 }
6439 DictionaryValue dict;
6440 dict.SetBoolean("is_visible", is_visible);
6441 reply.SendSuccess(&dict);
6442 }
6443
6414 void TestingAutomationProvider::GetChromeDriverAutomationVersion( 6444 void TestingAutomationProvider::GetChromeDriverAutomationVersion(
6415 DictionaryValue* args, 6445 DictionaryValue* args,
6416 IPC::Message* reply_message) { 6446 IPC::Message* reply_message) {
6417 DictionaryValue reply_dict; 6447 DictionaryValue reply_dict;
6418 reply_dict.SetInteger("version", automation::kChromeDriverAutomationVersion); 6448 reply_dict.SetInteger("version", automation::kChromeDriverAutomationVersion);
6419 AutomationJSONReply(this, reply_message).SendSuccess(&reply_dict); 6449 AutomationJSONReply(this, reply_message).SendSuccess(&reply_dict);
6420 } 6450 }
6421 6451
6422 void TestingAutomationProvider::CreateNewAutomationProvider( 6452 void TestingAutomationProvider::CreateNewAutomationProvider(
6423 DictionaryValue* args, 6453 DictionaryValue* args,
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
6593 6623
6594 Send(reply_message_); 6624 Send(reply_message_);
6595 redirect_query_ = 0; 6625 redirect_query_ = 0;
6596 reply_message_ = NULL; 6626 reply_message_ = NULL;
6597 } 6627 }
6598 6628
6599 void TestingAutomationProvider::OnRemoveProvider() { 6629 void TestingAutomationProvider::OnRemoveProvider() {
6600 if (g_browser_process) 6630 if (g_browser_process)
6601 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); 6631 g_browser_process->GetAutomationProviderList()->RemoveProvider(this);
6602 } 6632 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698