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

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

Issue 8587004: Add PyAuto tests for triggering browser/page action. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added extension data files Created 9 years, 1 month 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) 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 #include "chrome/browser/bookmarks/bookmark_model.h" 42 #include "chrome/browser/bookmarks/bookmark_model.h"
43 #include "chrome/browser/bookmarks/bookmark_storage.h" 43 #include "chrome/browser/bookmarks/bookmark_storage.h"
44 #include "chrome/browser/browser_process.h" 44 #include "chrome/browser/browser_process.h"
45 #include "chrome/browser/browser_shutdown.h" 45 #include "chrome/browser/browser_shutdown.h"
46 #include "chrome/browser/content_settings/host_content_settings_map.h" 46 #include "chrome/browser/content_settings/host_content_settings_map.h"
47 #include "chrome/browser/debugger/devtools_window.h" 47 #include "chrome/browser/debugger/devtools_window.h"
48 #include "chrome/browser/download/download_prefs.h" 48 #include "chrome/browser/download/download_prefs.h"
49 #include "chrome/browser/download/download_service.h" 49 #include "chrome/browser/download/download_service.h"
50 #include "chrome/browser/download/download_service_factory.h" 50 #include "chrome/browser/download/download_service_factory.h"
51 #include "chrome/browser/download/save_package_file_picker.h" 51 #include "chrome/browser/download/save_package_file_picker.h"
52 #include "chrome/browser/extensions/browser_action_test_util.h"
52 #include "chrome/browser/extensions/extension_browser_event_router.h" 53 #include "chrome/browser/extensions/extension_browser_event_router.h"
53 #include "chrome/browser/extensions/extension_host.h" 54 #include "chrome/browser/extensions/extension_host.h"
54 #include "chrome/browser/extensions/extension_process_manager.h" 55 #include "chrome/browser/extensions/extension_process_manager.h"
55 #include "chrome/browser/extensions/extension_service.h" 56 #include "chrome/browser/extensions/extension_service.h"
57 #include "chrome/browser/extensions/extension_tab_util.h"
56 #include "chrome/browser/extensions/extension_updater.h" 58 #include "chrome/browser/extensions/extension_updater.h"
57 #include "chrome/browser/history/top_sites.h" 59 #include "chrome/browser/history/top_sites.h"
58 #include "chrome/browser/importer/importer_host.h" 60 #include "chrome/browser/importer/importer_host.h"
59 #include "chrome/browser/importer/importer_list.h" 61 #include "chrome/browser/importer/importer_list.h"
60 #include "chrome/browser/infobars/infobar_tab_helper.h" 62 #include "chrome/browser/infobars/infobar_tab_helper.h"
61 #include "chrome/browser/instant/instant_controller.h" 63 #include "chrome/browser/instant/instant_controller.h"
62 #include "chrome/browser/notifications/balloon.h" 64 #include "chrome/browser/notifications/balloon.h"
63 #include "chrome/browser/notifications/balloon_collection.h" 65 #include "chrome/browser/notifications/balloon_collection.h"
64 #include "chrome/browser/notifications/notification.h" 66 #include "chrome/browser/notifications/notification.h"
65 #include "chrome/browser/notifications/notification_ui_manager.h" 67 #include "chrome/browser/notifications/notification_ui_manager.h"
(...skipping 2256 matching lines...) Expand 10 before | Expand all | Expand 10 after
2322 handler_map["OpenNewBrowserWindowWithNewProfile"] = 2324 handler_map["OpenNewBrowserWindowWithNewProfile"] =
2323 &TestingAutomationProvider::OpenNewBrowserWindowWithNewProfile; 2325 &TestingAutomationProvider::OpenNewBrowserWindowWithNewProfile;
2324 handler_map["GetMultiProfileInfo"] = 2326 handler_map["GetMultiProfileInfo"] =
2325 &TestingAutomationProvider::GetMultiProfileInfo; 2327 &TestingAutomationProvider::GetMultiProfileInfo;
2326 handler_map["GetProcessInfo"] = 2328 handler_map["GetProcessInfo"] =
2327 &TestingAutomationProvider::GetProcessInfo; 2329 &TestingAutomationProvider::GetProcessInfo;
2328 handler_map["SetPolicies"] = 2330 handler_map["SetPolicies"] =
2329 &TestingAutomationProvider::SetPolicies; 2331 &TestingAutomationProvider::SetPolicies;
2330 handler_map["GetPolicyDefinitionList"] = 2332 handler_map["GetPolicyDefinitionList"] =
2331 &TestingAutomationProvider::GetPolicyDefinitionList; 2333 &TestingAutomationProvider::GetPolicyDefinitionList;
2334 handler_map["TriggerPageActionById"] =
kkania 2011/11/21 18:53:58 thanks!
2335 &TestingAutomationProvider::TriggerPageActionById;
2336 handler_map["TriggerBrowserActionById"] =
2337 &TestingAutomationProvider::TriggerBrowserActionById;
2332 #if defined(OS_CHROMEOS) 2338 #if defined(OS_CHROMEOS)
2333 handler_map["GetLoginInfo"] = &TestingAutomationProvider::GetLoginInfo; 2339 handler_map["GetLoginInfo"] = &TestingAutomationProvider::GetLoginInfo;
2334 handler_map["ShowCreateAccountUI"] = 2340 handler_map["ShowCreateAccountUI"] =
2335 &TestingAutomationProvider::ShowCreateAccountUI; 2341 &TestingAutomationProvider::ShowCreateAccountUI;
2336 handler_map["LoginAsGuest"] = &TestingAutomationProvider::LoginAsGuest; 2342 handler_map["LoginAsGuest"] = &TestingAutomationProvider::LoginAsGuest;
2337 handler_map["Login"] = &TestingAutomationProvider::Login; 2343 handler_map["Login"] = &TestingAutomationProvider::Login;
2338 2344
2339 handler_map["LockScreen"] = &TestingAutomationProvider::LockScreen; 2345 handler_map["LockScreen"] = &TestingAutomationProvider::LockScreen;
2340 handler_map["UnlockScreen"] = &TestingAutomationProvider::UnlockScreen; 2346 handler_map["UnlockScreen"] = &TestingAutomationProvider::UnlockScreen;
2341 handler_map["SignoutInScreenLocker"] = 2347 handler_map["SignoutInScreenLocker"] =
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
2471 2477
2472 // SetTheme() implemented using InstallExtension(). 2478 // SetTheme() implemented using InstallExtension().
2473 browser_handler_map["GetThemeInfo"] = 2479 browser_handler_map["GetThemeInfo"] =
2474 &TestingAutomationProvider::GetThemeInfo; 2480 &TestingAutomationProvider::GetThemeInfo;
2475 2481
2476 // InstallExtension() present in pyauto.py. 2482 // InstallExtension() present in pyauto.py.
2477 browser_handler_map["GetExtensionsInfo"] = 2483 browser_handler_map["GetExtensionsInfo"] =
2478 &TestingAutomationProvider::GetExtensionsInfo; 2484 &TestingAutomationProvider::GetExtensionsInfo;
2479 browser_handler_map["UninstallExtensionById"] = 2485 browser_handler_map["UninstallExtensionById"] =
2480 &TestingAutomationProvider::UninstallExtensionById; 2486 &TestingAutomationProvider::UninstallExtensionById;
2481
2482 browser_handler_map["SetExtensionStateById"] = 2487 browser_handler_map["SetExtensionStateById"] =
2483 &TestingAutomationProvider::SetExtensionStateById; 2488 &TestingAutomationProvider::SetExtensionStateById;
2484 2489
2485 browser_handler_map["FindInPage"] = &TestingAutomationProvider::FindInPage; 2490 browser_handler_map["FindInPage"] = &TestingAutomationProvider::FindInPage;
2486 2491
2487 browser_handler_map["SelectTranslateOption"] = 2492 browser_handler_map["SelectTranslateOption"] =
2488 &TestingAutomationProvider::SelectTranslateOption; 2493 &TestingAutomationProvider::SelectTranslateOption;
2489 browser_handler_map["GetTranslateInfo"] = 2494 browser_handler_map["GetTranslateInfo"] =
2490 &TestingAutomationProvider::GetTranslateInfo; 2495 &TestingAutomationProvider::GetTranslateInfo;
2491 2496
(...skipping 1957 matching lines...) Expand 10 before | Expand all | Expand 10 after
4449 4454
4450 if (enable) 4455 if (enable)
4451 service->EnableExtension(id); 4456 service->EnableExtension(id);
4452 else 4457 else
4453 service->DisableExtension(id); 4458 service->DisableExtension(id);
4454 4459
4455 service->SetIsIncognitoEnabled(id, allow_in_incognito); 4460 service->SetIsIncognitoEnabled(id, allow_in_incognito);
4456 reply.SendSuccess(NULL); 4461 reply.SendSuccess(NULL);
4457 } 4462 }
4458 4463
4464 // See TriggerPageActionById() in chrome/test/pyautolib/pyauto.py
4465 // for sample json input.
4466 void TestingAutomationProvider::TriggerPageActionById(
4467 DictionaryValue* args,
4468 IPC::Message* reply_message) {
4469 AutomationJSONReply reply(this, reply_message);
4470
4471 std::string error;
4472 Browser* browser;
4473 if (!GetBrowserFromJSONArgs(args, &browser, &error)) {
4474 reply.SendError(error);
4475 return;
4476 }
4477 std::string id;
4478 if (!args->GetString("id", &id)) {
4479 reply.SendError("Missing or invalid key: id");
4480 return;
4481 }
4482
4483 ExtensionService* service = browser->profile()->GetExtensionService();
4484 if (!service) {
4485 reply.SendError("No extensions service.");
4486 return;
4487 }
4488 if (!service->GetInstalledExtension(id)) {
4489 // The extension ID does not correspond to any extension, whether crashed
4490 // or not.
4491 reply.SendError(base::StringPrintf("Extension does not exist: %s.",
kkania 2011/11/21 18:53:58 how about 'Extension %s is not installed'?
frankf 2011/11/22 22:26:10 Done.
4492 id.c_str()));
4493 return;
4494 }
4495 const Extension* extension = service->GetExtensionById(id, false);
4496 if (!extension) {
4497 reply.SendError("Extension is disabled or has crashed.");
4498 return;
4499 }
4500
4501 if (ExtensionAction* page_action = extension->page_action()) {
4502 LocationBarTesting* loc_bar =
4503 browser->window()->GetLocationBar()->GetLocationBarForTesting();
4504 size_t page_action_visible_count =
4505 static_cast<size_t>(loc_bar->PageActionVisibleCount());
4506 for (size_t i = 0; i < page_action_visible_count; i++) {
4507 if (loc_bar->GetVisiblePageAction(i) == page_action) {
4508 loc_bar->TestPageActionPressed(i);
4509 reply.SendSuccess(NULL);
4510 return;
4511 }
4512 }
4513 reply.SendError("Extension doesn't have any visible page action icon.");
4514 } else {
4515 reply.SendError("Extension doesn't have any page action.");
4516 }
4517 }
4518
4519 // See TriggerBrowserActionById() in chrome/test/pyautolib/pyauto.py
4520 // for sample json input.
4521 void TestingAutomationProvider::TriggerBrowserActionById(
4522 DictionaryValue* args,
4523 IPC::Message* reply_message) {
4524 AutomationJSONReply reply(this, reply_message);
4525
4526 std::string error;
4527 Browser* browser;
4528 if (!GetBrowserFromJSONArgs(args, &browser, &error)) {
4529 reply.SendError(error);
4530 return;
4531 }
4532 std::string id;
kkania 2011/11/21 18:53:58 Maybe move this and below to GetEnabledExtensionFr
frankf 2011/11/22 22:26:10 Have to revisit in a different CL for refactoring
4533 if (!args->GetString("id", &id)) {
4534 reply.SendError("Missing or invalid key: id");
4535 return;
4536 }
4537
4538 ExtensionService* service = browser->profile()->GetExtensionService();
4539 if (!service) {
4540 reply.SendError("No extensions service.");
4541 return;
4542 }
4543 if (!service->GetInstalledExtension(id)) {
4544 // The extension ID does not correspond to any extension, whether crashed
4545 // or not.
4546 reply.SendError(base::StringPrintf("Extension does not exist: %s.",
4547 id.c_str()));
4548 return;
4549 }
4550 const Extension* extension = service->GetExtensionById(id, false);
4551 if (!extension) {
4552 reply.SendError("Extension is disabled or has crashed.");
4553 return;
4554 }
4555
4556 if (extension->browser_action()) {
4557 BrowserActionTestUtil browser_actions(browser);
4558 int num_browser_actions = browser_actions.NumberOfBrowserActions();
4559 // TODO: Implement the platform-specific GetExtensionId() in
4560 // BrowserActionTestUtil
4561 if (num_browser_actions != 1) {
4562 reply.SendError(StringPrintf(
4563 "Found %d browser actions. Only one browser action can be active.",
4564 num_browser_actions));
4565 return;
4566 }
4567 browser_actions.Press(0);
4568 reply.SendSuccess(NULL);
4569 return;
4570 } else {
4571 reply.SendError("Extension doesn't have any browser action.");
4572 return;
4573 }
4574 }
4575
4459 // Sample json input: 4576 // Sample json input:
4460 // { "command": "GetAutofillProfile" } 4577 // { "command": "GetAutofillProfile" }
4461 // Refer to GetAutofillProfile() in chrome/test/pyautolib/pyauto.py for sample 4578 // Refer to GetAutofillProfile() in chrome/test/pyautolib/pyauto.py for sample
4462 // json output. 4579 // json output.
4463 void TestingAutomationProvider::GetAutofillProfile( 4580 void TestingAutomationProvider::GetAutofillProfile(
4464 Browser* browser, 4581 Browser* browser,
4465 DictionaryValue* args, 4582 DictionaryValue* args,
4466 IPC::Message* reply_message) { 4583 IPC::Message* reply_message) {
4467 AutomationJSONReply reply(this, reply_message); 4584 AutomationJSONReply reply(this, reply_message);
4468 // Get the AutofillProfiles currently in the database. 4585 // Get the AutofillProfiles currently in the database.
(...skipping 1915 matching lines...) Expand 10 before | Expand all | Expand 10 after
6384 6501
6385 Send(reply_message_); 6502 Send(reply_message_);
6386 redirect_query_ = 0; 6503 redirect_query_ = 0;
6387 reply_message_ = NULL; 6504 reply_message_ = NULL;
6388 } 6505 }
6389 6506
6390 void TestingAutomationProvider::OnRemoveProvider() { 6507 void TestingAutomationProvider::OnRemoveProvider() {
6391 if (g_browser_process) 6508 if (g_browser_process)
6392 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); 6509 g_browser_process->GetAutomationProviderList()->RemoveProvider(this);
6393 } 6510 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698