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

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

Issue 8772068: Add PyAuto tests for triggering browser/page action. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
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 | 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
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/crx_installer.h" 52 #include "chrome/browser/extensions/crx_installer.h"
53 #include "chrome/browser/extensions/extension_browser_event_router.h" 53 #include "chrome/browser/extensions/browser_action_test_util.h"
54 #include "chrome/browser/extensions/extension_host.h" 54 #include "chrome/browser/extensions/extension_host.h"
55 #include "chrome/browser/extensions/extension_process_manager.h" 55 #include "chrome/browser/extensions/extension_process_manager.h"
56 #include "chrome/browser/extensions/extension_service.h" 56 #include "chrome/browser/extensions/extension_service.h"
57 #include "chrome/browser/extensions/extension_tab_util.h"
57 #include "chrome/browser/extensions/extension_updater.h" 58 #include "chrome/browser/extensions/extension_updater.h"
58 #include "chrome/browser/extensions/unpacked_installer.h" 59 #include "chrome/browser/extensions/unpacked_installer.h"
59 #include "chrome/browser/history/top_sites.h" 60 #include "chrome/browser/history/top_sites.h"
60 #include "chrome/browser/importer/importer_host.h" 61 #include "chrome/browser/importer/importer_host.h"
61 #include "chrome/browser/importer/importer_list.h" 62 #include "chrome/browser/importer/importer_list.h"
62 #include "chrome/browser/infobars/infobar_tab_helper.h" 63 #include "chrome/browser/infobars/infobar_tab_helper.h"
63 #include "chrome/browser/instant/instant_controller.h" 64 #include "chrome/browser/instant/instant_controller.h"
64 #include "chrome/browser/notifications/balloon.h" 65 #include "chrome/browser/notifications/balloon.h"
65 #include "chrome/browser/notifications/balloon_collection.h" 66 #include "chrome/browser/notifications/balloon_collection.h"
66 #include "chrome/browser/notifications/notification.h" 67 #include "chrome/browser/notifications/notification.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 #include "chrome/browser/ui/omnibox/omnibox_view.h" 101 #include "chrome/browser/ui/omnibox/omnibox_view.h"
101 #include "chrome/browser/ui/search_engines/keyword_editor_controller.h" 102 #include "chrome/browser/ui/search_engines/keyword_editor_controller.h"
102 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 103 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
103 #include "chrome/common/automation_messages.h" 104 #include "chrome/common/automation_messages.h"
104 #include "chrome/common/chrome_constants.h" 105 #include "chrome/common/chrome_constants.h"
105 #include "chrome/common/chrome_notification_types.h" 106 #include "chrome/common/chrome_notification_types.h"
106 #include "chrome/common/chrome_paths.h" 107 #include "chrome/common/chrome_paths.h"
107 #include "chrome/common/chrome_switches.h" 108 #include "chrome/common/chrome_switches.h"
108 #include "chrome/common/chrome_view_type.h" 109 #include "chrome/common/chrome_view_type.h"
109 #include "chrome/common/extensions/extension.h" 110 #include "chrome/common/extensions/extension.h"
111 #include "chrome/common/extensions/extension_action.h"
110 #include "chrome/common/extensions/url_pattern.h" 112 #include "chrome/common/extensions/url_pattern.h"
111 #include "chrome/common/extensions/url_pattern_set.h" 113 #include "chrome/common/extensions/url_pattern_set.h"
112 #include "chrome/common/pref_names.h" 114 #include "chrome/common/pref_names.h"
113 #include "chrome/common/render_messages.h" 115 #include "chrome/common/render_messages.h"
114 #include "chrome/common/url_constants.h" 116 #include "chrome/common/url_constants.h"
115 #include "content/browser/plugin_service.h" 117 #include "content/browser/plugin_service.h"
116 #include "content/browser/renderer_host/render_view_host.h" 118 #include "content/browser/renderer_host/render_view_host.h"
117 #include "content/browser/tab_contents/interstitial_page.h" 119 #include "content/browser/tab_contents/interstitial_page.h"
118 #include "content/common/child_process_host.h" 120 #include "content/common/child_process_host.h"
119 #include "content/public/browser/notification_service.h" 121 #include "content/public/browser/notification_service.h"
(...skipping 2199 matching lines...) Expand 10 before | Expand all | Expand 10 after
2319 handler_map["SetPolicies"] = 2321 handler_map["SetPolicies"] =
2320 &TestingAutomationProvider::SetPolicies; 2322 &TestingAutomationProvider::SetPolicies;
2321 handler_map["GetPolicyDefinitionList"] = 2323 handler_map["GetPolicyDefinitionList"] =
2322 &TestingAutomationProvider::GetPolicyDefinitionList; 2324 &TestingAutomationProvider::GetPolicyDefinitionList;
2323 handler_map["InstallExtension"] = 2325 handler_map["InstallExtension"] =
2324 &TestingAutomationProvider::InstallExtension; 2326 &TestingAutomationProvider::InstallExtension;
2325 handler_map["GetExtensionsInfo"] = 2327 handler_map["GetExtensionsInfo"] =
2326 &TestingAutomationProvider::GetExtensionsInfo; 2328 &TestingAutomationProvider::GetExtensionsInfo;
2327 handler_map["RefreshPolicies"] = 2329 handler_map["RefreshPolicies"] =
2328 &TestingAutomationProvider::RefreshPolicies; 2330 &TestingAutomationProvider::RefreshPolicies;
2331 handler_map["TriggerPageActionById"] =
2332 &TestingAutomationProvider::TriggerPageActionById;
2333 handler_map["TriggerBrowserActionById"] =
2334 &TestingAutomationProvider::TriggerBrowserActionById;
2329 #if defined(OS_CHROMEOS) 2335 #if defined(OS_CHROMEOS)
2330 handler_map["GetLoginInfo"] = &TestingAutomationProvider::GetLoginInfo; 2336 handler_map["GetLoginInfo"] = &TestingAutomationProvider::GetLoginInfo;
2331 handler_map["ShowCreateAccountUI"] = 2337 handler_map["ShowCreateAccountUI"] =
2332 &TestingAutomationProvider::ShowCreateAccountUI; 2338 &TestingAutomationProvider::ShowCreateAccountUI;
2333 handler_map["LoginAsGuest"] = &TestingAutomationProvider::LoginAsGuest; 2339 handler_map["LoginAsGuest"] = &TestingAutomationProvider::LoginAsGuest;
2334 handler_map["Login"] = &TestingAutomationProvider::Login; 2340 handler_map["Login"] = &TestingAutomationProvider::Login;
2335 2341
2336 handler_map["LockScreen"] = &TestingAutomationProvider::LockScreen; 2342 handler_map["LockScreen"] = &TestingAutomationProvider::LockScreen;
2337 handler_map["UnlockScreen"] = &TestingAutomationProvider::UnlockScreen; 2343 handler_map["UnlockScreen"] = &TestingAutomationProvider::UnlockScreen;
2338 handler_map["SignoutInScreenLocker"] = 2344 handler_map["SignoutInScreenLocker"] =
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
2463 &TestingAutomationProvider::GetBlockedPopupsInfo; 2469 &TestingAutomationProvider::GetBlockedPopupsInfo;
2464 browser_handler_map["UnblockAndLaunchBlockedPopup"] = 2470 browser_handler_map["UnblockAndLaunchBlockedPopup"] =
2465 &TestingAutomationProvider::UnblockAndLaunchBlockedPopup; 2471 &TestingAutomationProvider::UnblockAndLaunchBlockedPopup;
2466 2472
2467 // SetTheme() implemented using InstallExtension(). 2473 // SetTheme() implemented using InstallExtension().
2468 browser_handler_map["GetThemeInfo"] = 2474 browser_handler_map["GetThemeInfo"] =
2469 &TestingAutomationProvider::GetThemeInfo; 2475 &TestingAutomationProvider::GetThemeInfo;
2470 2476
2471 browser_handler_map["UninstallExtensionById"] = 2477 browser_handler_map["UninstallExtensionById"] =
2472 &TestingAutomationProvider::UninstallExtensionById; 2478 &TestingAutomationProvider::UninstallExtensionById;
2473
2474 browser_handler_map["SetExtensionStateById"] = 2479 browser_handler_map["SetExtensionStateById"] =
2475 &TestingAutomationProvider::SetExtensionStateById; 2480 &TestingAutomationProvider::SetExtensionStateById;
2476 2481
2477 browser_handler_map["FindInPage"] = &TestingAutomationProvider::FindInPage; 2482 browser_handler_map["FindInPage"] = &TestingAutomationProvider::FindInPage;
2478 2483
2479 browser_handler_map["SelectTranslateOption"] = 2484 browser_handler_map["SelectTranslateOption"] =
2480 &TestingAutomationProvider::SelectTranslateOption; 2485 &TestingAutomationProvider::SelectTranslateOption;
2481 browser_handler_map["GetTranslateInfo"] = 2486 browser_handler_map["GetTranslateInfo"] =
2482 &TestingAutomationProvider::GetTranslateInfo; 2487 &TestingAutomationProvider::GetTranslateInfo;
2483 2488
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
2789 Browser* browser = *it; 2794 Browser* browser = *it;
2790 browser_item->SetInteger("index", windex); 2795 browser_item->SetInteger("index", windex);
2791 // Window properties 2796 // Window properties
2792 gfx::Rect rect = browser->window()->GetRestoredBounds(); 2797 gfx::Rect rect = browser->window()->GetRestoredBounds();
2793 browser_item->SetInteger("x", rect.x()); 2798 browser_item->SetInteger("x", rect.x());
2794 browser_item->SetInteger("y", rect.y()); 2799 browser_item->SetInteger("y", rect.y());
2795 browser_item->SetInteger("width", rect.width()); 2800 browser_item->SetInteger("width", rect.width());
2796 browser_item->SetInteger("height", rect.height()); 2801 browser_item->SetInteger("height", rect.height());
2797 browser_item->SetBoolean("fullscreen", 2802 browser_item->SetBoolean("fullscreen",
2798 browser->window()->IsFullscreen()); 2803 browser->window()->IsFullscreen());
2804 ListValue* visible_page_actions = new ListValue;
2805 LocationBarTesting* loc_bar =
2806 browser->window()->GetLocationBar()->GetLocationBarForTesting();
2807 size_t page_action_visible_count =
2808 static_cast<size_t>(loc_bar->PageActionVisibleCount());
2809 for (size_t i = 0; i < page_action_visible_count; ++i) {
2810 StringValue* extension_id = new StringValue(
2811 loc_bar->GetVisiblePageAction(i)->extension_id());
2812 visible_page_actions->Append(extension_id);
2813 }
2814 browser_item->Set("visible_page_actions", visible_page_actions);
2799 browser_item->SetInteger("selected_tab", browser->active_index()); 2815 browser_item->SetInteger("selected_tab", browser->active_index());
2800 browser_item->SetBoolean("incognito", 2816 browser_item->SetBoolean("incognito",
2801 browser->profile()->IsOffTheRecord()); 2817 browser->profile()->IsOffTheRecord());
2802 browser_item->SetString("profile_path", 2818 browser_item->SetString("profile_path",
2803 browser->profile()->GetPath().BaseName().MaybeAsASCII()); 2819 browser->profile()->GetPath().BaseName().MaybeAsASCII());
2804 std::string type; 2820 std::string type;
2805 switch (browser->type()) { 2821 switch (browser->type()) {
2806 case Browser::TYPE_TABBED: 2822 case Browser::TYPE_TABBED:
2807 type = "tabbed"; 2823 type = "tabbed";
2808 break; 2824 break;
(...skipping 1680 matching lines...) Expand 10 before | Expand all | Expand 10 after
4489 4505
4490 if (enable) 4506 if (enable)
4491 service->EnableExtension(id); 4507 service->EnableExtension(id);
4492 else 4508 else
4493 service->DisableExtension(id); 4509 service->DisableExtension(id);
4494 4510
4495 service->SetIsIncognitoEnabled(id, allow_in_incognito); 4511 service->SetIsIncognitoEnabled(id, allow_in_incognito);
4496 reply.SendSuccess(NULL); 4512 reply.SendSuccess(NULL);
4497 } 4513 }
4498 4514
4515 // See TriggerPageActionById() in chrome/test/pyautolib/pyauto.py
4516 // for sample json input.
4517 void TestingAutomationProvider::TriggerPageActionById(
4518 DictionaryValue* args,
4519 IPC::Message* reply_message) {
4520 AutomationJSONReply reply(this, reply_message);
4521
4522 std::string error;
4523 Browser* browser;
4524 if (!GetBrowserFromJSONArgs(args, &browser, &error)) {
4525 reply.SendError(error);
4526 return;
4527 }
4528 std::string id;
4529 if (!args->GetString("id", &id)) {
4530 reply.SendError("Missing or invalid key: id");
4531 return;
4532 }
4533
4534 ExtensionService* service = browser->profile()->GetExtensionService();
4535 if (!service) {
4536 reply.SendError("No extensions service.");
4537 return;
4538 }
4539 if (!service->GetInstalledExtension(id)) {
4540 // The extension ID does not correspond to any extension, whether crashed
4541 // or not.
4542 reply.SendError(base::StringPrintf("Extension %s is not installed.",
4543 id.c_str()));
4544 return;
4545 }
4546 const Extension* extension = service->GetExtensionById(id, false);
4547 if (!extension) {
4548 reply.SendError("Extension is disabled or has crashed.");
4549 return;
4550 }
4551
4552 if (ExtensionAction* page_action = extension->page_action()) {
4553 LocationBarTesting* loc_bar =
4554 browser->window()->GetLocationBar()->GetLocationBarForTesting();
4555 size_t page_action_visible_count =
4556 static_cast<size_t>(loc_bar->PageActionVisibleCount());
4557 for (size_t i = 0; i < page_action_visible_count; ++i) {
4558 if (loc_bar->GetVisiblePageAction(i) == page_action) {
4559 loc_bar->TestPageActionPressed(i);
4560 reply.SendSuccess(NULL);
4561 return;
4562 }
4563 }
4564 reply.SendError("Extension doesn't have any visible page action icon.");
4565 } else {
4566 reply.SendError("Extension doesn't have any page action.");
4567 }
4568 }
4569
4570 // See TriggerBrowserActionById() in chrome/test/pyautolib/pyauto.py
4571 // for sample json input.
4572 void TestingAutomationProvider::TriggerBrowserActionById(
4573 DictionaryValue* args,
4574 IPC::Message* reply_message) {
4575 AutomationJSONReply reply(this, reply_message);
4576
4577 std::string error;
4578 Browser* browser;
4579 if (!GetBrowserFromJSONArgs(args, &browser, &error)) {
4580 reply.SendError(error);
4581 return;
4582 }
4583 std::string id;
4584 if (!args->GetString("id", &id)) {
4585 reply.SendError("Missing or invalid key: id");
4586 return;
4587 }
4588
4589 ExtensionService* service = browser->profile()->GetExtensionService();
4590 if (!service) {
4591 reply.SendError("No extensions service.");
4592 return;
4593 }
4594 if (!service->GetInstalledExtension(id)) {
4595 // The extension ID does not correspond to any extension, whether crashed
4596 // or not.
4597 reply.SendError(base::StringPrintf("Extension %s is not installed.",
4598 id.c_str()));
4599 return;
4600 }
4601 const Extension* extension = service->GetExtensionById(id, false);
4602 if (!extension) {
4603 reply.SendError("Extension is disabled or has crashed.");
4604 return;
4605 }
4606
4607 if (extension->browser_action()) {
4608 BrowserActionTestUtil browser_actions(browser);
4609 int num_browser_actions = browser_actions.NumberOfBrowserActions();
4610 // TODO: Implement the platform-specific GetExtensionId() in
4611 // BrowserActionTestUtil.
4612 if (num_browser_actions != 1) {
4613 reply.SendError(StringPrintf(
4614 "Found %d browser actions. Only one browser action must be active.",
4615 num_browser_actions));
4616 return;
4617 }
4618 browser_actions.Press(0);
4619 reply.SendSuccess(NULL);
4620 return;
4621 } else {
4622 reply.SendError("Extension doesn't have any browser action.");
4623 return;
4624 }
4625 }
4626
4499 // Sample json input: 4627 // Sample json input:
4500 // { "command": "GetAutofillProfile" } 4628 // { "command": "GetAutofillProfile" }
4501 // Refer to GetAutofillProfile() in chrome/test/pyautolib/pyauto.py for sample 4629 // Refer to GetAutofillProfile() in chrome/test/pyautolib/pyauto.py for sample
4502 // json output. 4630 // json output.
4503 void TestingAutomationProvider::GetAutofillProfile( 4631 void TestingAutomationProvider::GetAutofillProfile(
4504 Browser* browser, 4632 Browser* browser,
4505 DictionaryValue* args, 4633 DictionaryValue* args,
4506 IPC::Message* reply_message) { 4634 IPC::Message* reply_message) {
4507 AutomationJSONReply reply(this, reply_message); 4635 AutomationJSONReply reply(this, reply_message);
4508 // Get the AutofillProfiles currently in the database. 4636 // Get the AutofillProfiles currently in the database.
(...skipping 1923 matching lines...) Expand 10 before | Expand all | Expand 10 after
6432 6560
6433 Send(reply_message_); 6561 Send(reply_message_);
6434 redirect_query_ = 0; 6562 redirect_query_ = 0;
6435 reply_message_ = NULL; 6563 reply_message_ = NULL;
6436 } 6564 }
6437 6565
6438 void TestingAutomationProvider::OnRemoveProvider() { 6566 void TestingAutomationProvider::OnRemoveProvider() {
6439 if (g_browser_process) 6567 if (g_browser_process)
6440 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); 6568 g_browser_process->GetAutomationProviderList()->RemoveProvider(this);
6441 } 6569 }
OLDNEW
« no previous file with comments | « chrome/browser/automation/testing_automation_provider.h ('k') | chrome/browser/extensions/browser_action_test_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698