diff options
Diffstat (limited to 'chrome/browser/extensions')
-rw-r--r-- | chrome/browser/extensions/extension_browsertests_misc.cc | 38 | ||||
-rw-r--r-- | chrome/browser/extensions/extensions_ui.cc | 22 | ||||
-rw-r--r-- | chrome/browser/extensions/extensions_ui.h | 3 |
3 files changed, 63 insertions, 0 deletions
diff --git a/chrome/browser/extensions/extension_browsertests_misc.cc b/chrome/browser/extensions/extension_browsertests_misc.cc index 63530b3..10d33c3 100644 --- a/chrome/browser/extensions/extension_browsertests_misc.cc +++ b/chrome/browser/extensions/extension_browsertests_misc.cc @@ -788,3 +788,41 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, AutoUpdate) { ASSERT_EQ("2.0", extensions->at(0)->VersionString()); } +// Used to simulate a click on the first button named 'Options'. +static const wchar_t* jscript_click_option_button = + L"(function() { " + L" var button = document.evaluate(\"//button[text()='Options']\"," + L" document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE," + L" null).snapshotItem(0);" + L" button.click();" + L" window.domAutomationController.send(0);" + L"})();"; + +// Test that an extension with an options page makes an 'Options' button appear +// on chrome://extensions, and that clicking the button opens a new tab with the +// extension's options page. +IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, OptionsPage) { + // Install an extension with an options page. + ASSERT_TRUE(InstallExtension(test_data_dir_.AppendASCII("options.crx"), 1)); + ExtensionsService* service = browser()->profile()->GetExtensionsService(); + const ExtensionList* extensions = service->extensions(); + ASSERT_EQ(1u, extensions->size()); + Extension* extension = extensions->at(0); + + // Go to the chrome://extensions page and click the Options button. + ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIExtensionsURL)); + TabStripModel* tab_strip = browser()->tabstrip_model(); + TabContents* extensions_tab = browser()->GetSelectedTabContents(); + ui_test_utils::ExecuteJavaScript(extensions_tab->render_view_host(), L"", + jscript_click_option_button); + + // If the options page hasn't already come up, wait for it. + if (tab_strip->count() == 1) { + ui_test_utils::WaitForNewTab(browser()); + } + ASSERT_EQ(2, tab_strip->count()); + + EXPECT_EQ(extension->GetResourceURL("options.html"), + tab_strip->GetTabContentsAt(1)->GetURL()); +} + diff --git a/chrome/browser/extensions/extensions_ui.cc b/chrome/browser/extensions/extensions_ui.cc index b77a751..752a47d 100644 --- a/chrome/browser/extensions/extensions_ui.cc +++ b/chrome/browser/extensions/extensions_ui.cc @@ -8,6 +8,7 @@ #include "app/resource_bundle.h" #include "base/string_util.h" #include "base/thread.h" +#include "chrome/browser/browser.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/chrome_thread.h" #include "chrome/browser/debugger/devtools_manager.h" @@ -95,6 +96,8 @@ void ExtensionsDOMHandler::RegisterMessages() { NewCallback(this, &ExtensionsDOMHandler::HandleEnableMessage)); dom_ui_->RegisterMessageCallback("uninstall", NewCallback(this, &ExtensionsDOMHandler::HandleUninstallMessage)); + dom_ui_->RegisterMessageCallback("options", + NewCallback(this, &ExtensionsDOMHandler::HandleOptionsMessage)); dom_ui_->RegisterMessageCallback("load", NewCallback(this, &ExtensionsDOMHandler::HandleLoadMessage)); dom_ui_->RegisterMessageCallback("pack", @@ -198,6 +201,22 @@ void ExtensionsDOMHandler::HandleUninstallMessage(const Value* value) { extensions_service_->UninstallExtension(extension_id, false); } +void ExtensionsDOMHandler::HandleOptionsMessage(const Value* value) { + CHECK(value->IsType(Value::TYPE_LIST)); + const ListValue* list = static_cast<const ListValue*>(value); + CHECK(list->GetSize() == 1); + std::string extension_id; + CHECK(list->GetString(0, &extension_id)); + Extension *extension = extensions_service_->GetExtensionById(extension_id); + if (!extension || extension->options_url().is_empty()) { + return; + } + Browser* browser = Browser::GetOrCreateTabbedBrowser(dom_ui_->GetProfile()); + CHECK(browser); + browser->OpenURL(extension->options_url(), GURL(), NEW_FOREGROUND_TAB, + PageTransition::LINK); +} + void ExtensionsDOMHandler::HandleLoadMessage(const Value* value) { std::string string_path; CHECK(value->IsType(Value::TYPE_LIST)); @@ -399,6 +418,9 @@ DictionaryValue* ExtensionsDOMHandler::CreateExtensionDetailValue( extension_data->SetString(L"description", extension->description()); extension_data->SetString(L"version", extension->version()->GetString()); extension_data->SetBoolean(L"enabled", enabled); + if (!extension->options_url().is_empty()) { + extension_data->SetString(L"options_url", extension->options_url().spec()); + } // Add list of content_script detail DictionaryValues ListValue *content_script_list = new ListValue(); diff --git a/chrome/browser/extensions/extensions_ui.h b/chrome/browser/extensions/extensions_ui.h index 908c9f3..90c0e92 100644 --- a/chrome/browser/extensions/extensions_ui.h +++ b/chrome/browser/extensions/extensions_ui.h @@ -95,6 +95,9 @@ class ExtensionsDOMHandler // Callback for "uninstall" message. void HandleUninstallMessage(const Value* value); + // Callback for "options" message. + void HandleOptionsMessage(const Value* value); + // Callback for "load" message. void HandleLoadMessage(const Value* value); |