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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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/extension_browser_event_router.h" | 52 #include "chrome/browser/extensions/browser_action_test_util.h" |
53 #include "chrome/browser/extensions/extension_host.h" | 53 #include "chrome/browser/extensions/extension_host.h" |
54 #include "chrome/browser/extensions/extension_process_manager.h" | 54 #include "chrome/browser/extensions/extension_process_manager.h" |
55 #include "chrome/browser/extensions/extension_service.h" | 55 #include "chrome/browser/extensions/extension_service.h" |
56 #include "chrome/browser/extensions/extension_tab_util.h" | |
56 #include "chrome/browser/extensions/extension_updater.h" | 57 #include "chrome/browser/extensions/extension_updater.h" |
57 #include "chrome/browser/history/top_sites.h" | 58 #include "chrome/browser/history/top_sites.h" |
58 #include "chrome/browser/importer/importer_host.h" | 59 #include "chrome/browser/importer/importer_host.h" |
59 #include "chrome/browser/importer/importer_list.h" | 60 #include "chrome/browser/importer/importer_list.h" |
60 #include "chrome/browser/infobars/infobar_tab_helper.h" | 61 #include "chrome/browser/infobars/infobar_tab_helper.h" |
61 #include "chrome/browser/instant/instant_controller.h" | 62 #include "chrome/browser/instant/instant_controller.h" |
62 #include "chrome/browser/notifications/balloon.h" | 63 #include "chrome/browser/notifications/balloon.h" |
63 #include "chrome/browser/notifications/balloon_collection.h" | 64 #include "chrome/browser/notifications/balloon_collection.h" |
64 #include "chrome/browser/notifications/notification.h" | 65 #include "chrome/browser/notifications/notification.h" |
65 #include "chrome/browser/notifications/notification_ui_manager.h" | 66 #include "chrome/browser/notifications/notification_ui_manager.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
98 #include "chrome/browser/ui/omnibox/omnibox_view.h" | 99 #include "chrome/browser/ui/omnibox/omnibox_view.h" |
99 #include "chrome/browser/ui/search_engines/keyword_editor_controller.h" | 100 #include "chrome/browser/ui/search_engines/keyword_editor_controller.h" |
100 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 101 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
101 #include "chrome/common/automation_messages.h" | 102 #include "chrome/common/automation_messages.h" |
102 #include "chrome/common/chrome_constants.h" | 103 #include "chrome/common/chrome_constants.h" |
103 #include "chrome/common/chrome_notification_types.h" | 104 #include "chrome/common/chrome_notification_types.h" |
104 #include "chrome/common/chrome_paths.h" | 105 #include "chrome/common/chrome_paths.h" |
105 #include "chrome/common/chrome_switches.h" | 106 #include "chrome/common/chrome_switches.h" |
106 #include "chrome/common/chrome_view_types.h" | 107 #include "chrome/common/chrome_view_types.h" |
107 #include "chrome/common/extensions/extension.h" | 108 #include "chrome/common/extensions/extension.h" |
109 #include "chrome/common/extensions/extension_action.h" | |
108 #include "chrome/common/extensions/url_pattern.h" | 110 #include "chrome/common/extensions/url_pattern.h" |
109 #include "chrome/common/extensions/url_pattern_set.h" | 111 #include "chrome/common/extensions/url_pattern_set.h" |
110 #include "chrome/common/pref_names.h" | 112 #include "chrome/common/pref_names.h" |
111 #include "chrome/common/render_messages.h" | 113 #include "chrome/common/render_messages.h" |
112 #include "chrome/common/url_constants.h" | 114 #include "chrome/common/url_constants.h" |
113 #include "content/browser/plugin_service.h" | 115 #include "content/browser/plugin_service.h" |
114 #include "content/browser/renderer_host/render_process_host.h" | 116 #include "content/browser/renderer_host/render_process_host.h" |
115 #include "content/browser/renderer_host/render_view_host.h" | 117 #include "content/browser/renderer_host/render_view_host.h" |
116 #include "content/browser/tab_contents/interstitial_page.h" | 118 #include "content/browser/tab_contents/interstitial_page.h" |
117 #include "content/public/browser/notification_service.h" | 119 #include "content/public/browser/notification_service.h" |
(...skipping 2204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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"] = | |
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 Loading... | |
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 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2798 Browser* browser = *it; | 2803 Browser* browser = *it; |
2799 browser_item->SetInteger("index", windex); | 2804 browser_item->SetInteger("index", windex); |
2800 // Window properties | 2805 // Window properties |
2801 gfx::Rect rect = browser->window()->GetRestoredBounds(); | 2806 gfx::Rect rect = browser->window()->GetRestoredBounds(); |
2802 browser_item->SetInteger("x", rect.x()); | 2807 browser_item->SetInteger("x", rect.x()); |
2803 browser_item->SetInteger("y", rect.y()); | 2808 browser_item->SetInteger("y", rect.y()); |
2804 browser_item->SetInteger("width", rect.width()); | 2809 browser_item->SetInteger("width", rect.width()); |
2805 browser_item->SetInteger("height", rect.height()); | 2810 browser_item->SetInteger("height", rect.height()); |
2806 browser_item->SetBoolean("fullscreen", | 2811 browser_item->SetBoolean("fullscreen", |
2807 browser->window()->IsFullscreen()); | 2812 browser->window()->IsFullscreen()); |
2813 ListValue* visible_page_actions = new ListValue; | |
2814 LocationBarTesting* loc_bar = | |
2815 browser->window()->GetLocationBar()->GetLocationBarForTesting(); | |
2816 size_t page_action_visible_count = | |
2817 static_cast<size_t>(loc_bar->PageActionVisibleCount()); | |
2818 for (size_t i = 0; i < page_action_visible_count; i++) { | |
dennis_jeffrey
2011/11/23 21:54:54
nit: other chrome code generally uses '++i' in the
| |
2819 StringValue* extension_id = new StringValue( | |
2820 loc_bar->GetVisiblePageAction(i)->extension_id()); | |
2821 visible_page_actions->Append(extension_id); | |
2822 } | |
2823 browser_item->Set("visible_page_actions", visible_page_actions); | |
2808 browser_item->SetInteger("selected_tab", browser->active_index()); | 2824 browser_item->SetInteger("selected_tab", browser->active_index()); |
2809 browser_item->SetBoolean("incognito", | 2825 browser_item->SetBoolean("incognito", |
2810 browser->profile()->IsOffTheRecord()); | 2826 browser->profile()->IsOffTheRecord()); |
2811 browser_item->SetString("profile_path", | 2827 browser_item->SetString("profile_path", |
2812 browser->profile()->GetPath().BaseName().MaybeAsASCII()); | 2828 browser->profile()->GetPath().BaseName().MaybeAsASCII()); |
2813 std::string type; | 2829 std::string type; |
2814 switch (browser->type()) { | 2830 switch (browser->type()) { |
2815 case Browser::TYPE_TABBED: | 2831 case Browser::TYPE_TABBED: |
2816 type = "tabbed"; | 2832 type = "tabbed"; |
2817 break; | 2833 break; |
(...skipping 1631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4449 | 4465 |
4450 if (enable) | 4466 if (enable) |
4451 service->EnableExtension(id); | 4467 service->EnableExtension(id); |
4452 else | 4468 else |
4453 service->DisableExtension(id); | 4469 service->DisableExtension(id); |
4454 | 4470 |
4455 service->SetIsIncognitoEnabled(id, allow_in_incognito); | 4471 service->SetIsIncognitoEnabled(id, allow_in_incognito); |
4456 reply.SendSuccess(NULL); | 4472 reply.SendSuccess(NULL); |
4457 } | 4473 } |
4458 | 4474 |
4475 // See TriggerPageActionById() in chrome/test/pyautolib/pyauto.py | |
4476 // for sample json input. | |
4477 void TestingAutomationProvider::TriggerPageActionById( | |
4478 DictionaryValue* args, | |
4479 IPC::Message* reply_message) { | |
4480 AutomationJSONReply reply(this, reply_message); | |
4481 | |
4482 std::string error; | |
4483 Browser* browser; | |
4484 if (!GetBrowserFromJSONArgs(args, &browser, &error)) { | |
4485 reply.SendError(error); | |
4486 return; | |
4487 } | |
4488 std::string id; | |
4489 if (!args->GetString("id", &id)) { | |
4490 reply.SendError("Missing or invalid key: id"); | |
4491 return; | |
4492 } | |
4493 | |
4494 ExtensionService* service = browser->profile()->GetExtensionService(); | |
4495 if (!service) { | |
4496 reply.SendError("No extensions service."); | |
4497 return; | |
4498 } | |
4499 if (!service->GetInstalledExtension(id)) { | |
4500 // The extension ID does not correspond to any extension, whether crashed | |
4501 // or not. | |
4502 reply.SendError(base::StringPrintf("Extension %s is not installed.", | |
4503 id.c_str())); | |
4504 return; | |
4505 } | |
4506 const Extension* extension = service->GetExtensionById(id, false); | |
4507 if (!extension) { | |
4508 reply.SendError("Extension is disabled or has crashed."); | |
4509 return; | |
4510 } | |
4511 | |
4512 if (ExtensionAction* page_action = extension->page_action()) { | |
4513 LocationBarTesting* loc_bar = | |
4514 browser->window()->GetLocationBar()->GetLocationBarForTesting(); | |
4515 size_t page_action_visible_count = | |
4516 static_cast<size_t>(loc_bar->PageActionVisibleCount()); | |
4517 for (size_t i = 0; i < page_action_visible_count; i++) { | |
dennis_jeffrey
2011/11/23 21:54:54
nit: '++i' instead of 'i++'
| |
4518 if (loc_bar->GetVisiblePageAction(i) == page_action) { | |
4519 loc_bar->TestPageActionPressed(i); | |
4520 reply.SendSuccess(NULL); | |
4521 return; | |
4522 } | |
4523 } | |
4524 reply.SendError("Extension doesn't have any visible page action icon."); | |
4525 } else { | |
4526 reply.SendError("Extension doesn't have any page action."); | |
4527 } | |
4528 } | |
4529 | |
4530 // See TriggerBrowserActionById() in chrome/test/pyautolib/pyauto.py | |
4531 // for sample json input. | |
4532 void TestingAutomationProvider::TriggerBrowserActionById( | |
4533 DictionaryValue* args, | |
4534 IPC::Message* reply_message) { | |
4535 AutomationJSONReply reply(this, reply_message); | |
4536 | |
4537 std::string error; | |
4538 Browser* browser; | |
4539 if (!GetBrowserFromJSONArgs(args, &browser, &error)) { | |
4540 reply.SendError(error); | |
4541 return; | |
4542 } | |
4543 std::string id; | |
4544 if (!args->GetString("id", &id)) { | |
4545 reply.SendError("Missing or invalid key: id"); | |
4546 return; | |
4547 } | |
4548 | |
4549 ExtensionService* service = browser->profile()->GetExtensionService(); | |
4550 if (!service) { | |
4551 reply.SendError("No extensions service."); | |
4552 return; | |
4553 } | |
4554 if (!service->GetInstalledExtension(id)) { | |
4555 // The extension ID does not correspond to any extension, whether crashed | |
4556 // or not. | |
4557 reply.SendError(base::StringPrintf("Extension %s is not installed.", | |
4558 id.c_str())); | |
4559 return; | |
4560 } | |
4561 const Extension* extension = service->GetExtensionById(id, false); | |
4562 if (!extension) { | |
4563 reply.SendError("Extension is disabled or has crashed."); | |
4564 return; | |
4565 } | |
4566 | |
4567 if (extension->browser_action()) { | |
4568 BrowserActionTestUtil browser_actions(browser); | |
kkania
2011/11/29 19:25:03
fix indent
| |
4569 int num_browser_actions = browser_actions.NumberOfBrowserActions(); | |
4570 // TODO: Implement the platform-specific GetExtensionId() in | |
4571 // BrowserActionTestUtil | |
dennis_jeffrey
2011/11/23 21:54:54
nit: period at end of sentence
| |
4572 if (num_browser_actions != 1) { | |
4573 reply.SendError(StringPrintf( | |
4574 "Found %d browser actions. Only one browser action must be active.", | |
4575 num_browser_actions)); | |
4576 return; | |
4577 } | |
4578 browser_actions.Press(0); | |
4579 reply.SendSuccess(NULL); | |
4580 return; | |
4581 } else { | |
4582 reply.SendError("Extension doesn't have any browser action."); | |
4583 return; | |
4584 } | |
4585 } | |
4586 | |
4459 // Sample json input: | 4587 // Sample json input: |
4460 // { "command": "GetAutofillProfile" } | 4588 // { "command": "GetAutofillProfile" } |
4461 // Refer to GetAutofillProfile() in chrome/test/pyautolib/pyauto.py for sample | 4589 // Refer to GetAutofillProfile() in chrome/test/pyautolib/pyauto.py for sample |
4462 // json output. | 4590 // json output. |
4463 void TestingAutomationProvider::GetAutofillProfile( | 4591 void TestingAutomationProvider::GetAutofillProfile( |
4464 Browser* browser, | 4592 Browser* browser, |
4465 DictionaryValue* args, | 4593 DictionaryValue* args, |
4466 IPC::Message* reply_message) { | 4594 IPC::Message* reply_message) { |
4467 AutomationJSONReply reply(this, reply_message); | 4595 AutomationJSONReply reply(this, reply_message); |
4468 // Get the AutofillProfiles currently in the database. | 4596 // Get the AutofillProfiles currently in the database. |
(...skipping 1915 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6384 | 6512 |
6385 Send(reply_message_); | 6513 Send(reply_message_); |
6386 redirect_query_ = 0; | 6514 redirect_query_ = 0; |
6387 reply_message_ = NULL; | 6515 reply_message_ = NULL; |
6388 } | 6516 } |
6389 | 6517 |
6390 void TestingAutomationProvider::OnRemoveProvider() { | 6518 void TestingAutomationProvider::OnRemoveProvider() { |
6391 if (g_browser_process) | 6519 if (g_browser_process) |
6392 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); | 6520 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); |
6393 } | 6521 } |
OLD | NEW |