diff options
author | cduvall@chromium.org <cduvall@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-19 13:08:46 +0000 |
---|---|---|
committer | cduvall@chromium.org <cduvall@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-19 13:08:46 +0000 |
commit | e28a937b1cb87e62afefb5918512ce8b9dfc49d5 (patch) | |
tree | 90cf224b7393a36ac5da6e35cb0a663c6044f023 | |
parent | 31c406b1b4fe7b0060fab563040bd3cd0d4ccf1e (diff) | |
download | chromium_src-e28a937b1cb87e62afefb5918512ce8b9dfc49d5.zip chromium_src-e28a937b1cb87e62afefb5918512ce8b9dfc49d5.tar.gz chromium_src-e28a937b1cb87e62afefb5918512ce8b9dfc49d5.tar.bz2 |
Add getters to chrome.browserAction and chrome.pageAction
Added these functions:
chrome.browserAction.getTitle
chrome.browserAction.getBadgeText
chrome.browserAction.getBadgeBackgroundColor
chrome.browserAction.getPopup
chrome.pageAction.getTitle
chrome.pageAction.getPopup
BUG=31443
TEST=BrowserActionApiTest.Getters, ExtensionApiTest.Getters
Review URL: http://codereview.chromium.org/9667033
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@127452 0039d316-1c4b-4281-b951-d872f2087c98
24 files changed, 1436 insertions, 27 deletions
diff --git a/chrome/browser/extensions/browser_action_apitest.cc b/chrome/browser/extensions/api/extension_action/browser_action_apitest.cc index e42af47..8236863f 100644 --- a/chrome/browser/extensions/browser_action_apitest.cc +++ b/chrome/browser/extensions/api/extension_action/browser_action_apitest.cc @@ -446,3 +446,23 @@ IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, BadgeBackgroundColor) { ASSERT_EQ(SkColorSetARGB(255, 255, 255, 255), action->GetBadgeBackgroundColor(ExtensionAction::kDefaultTabId)); } + +IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, Getters) { + ASSERT_TRUE(RunExtensionTest("browser_action/getters")) << message_; + const Extension* extension = GetSingleLoadedExtension(); + ASSERT_TRUE(extension) << message_; + + // Test that there is a browser action in the toolbar. + ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions()); + + // Test the getters for defaults. + ResultCatcher catcher; + ui_test_utils::NavigateToURL(browser(), + GURL(extension->GetResourceURL("update.html"))); + ASSERT_TRUE(catcher.GetNextResult()); + + // Test the getters for a specific tab. + ui_test_utils::NavigateToURL(browser(), + GURL(extension->GetResourceURL("update2.html"))); + ASSERT_TRUE(catcher.GetNextResult()); +} diff --git a/chrome/browser/extensions/api/extension_action/extension_actions_api.cc b/chrome/browser/extensions/api/extension_action/extension_actions_api.cc index 53633a1..aa18536 100644 --- a/chrome/browser/extensions/api/extension_action/extension_actions_api.cc +++ b/chrome/browser/extensions/api/extension_action/extension_actions_api.cc @@ -134,3 +134,31 @@ bool ExtensionActionFunction::SetBadgeBackgroundColor() { return true; } + +bool ExtensionActionFunction::GetTitle() { + result_.reset(Value::CreateStringValue(extension_action_->GetTitle(tab_id_))); + return true; +} + +bool ExtensionActionFunction::GetPopup() { + result_.reset(Value::CreateStringValue( + extension_action_->GetPopupUrl(tab_id_).spec())); + return true; +} + +bool ExtensionActionFunction::GetBadgeText() { + result_.reset(Value::CreateStringValue( + extension_action_->GetBadgeText(tab_id_))); + return true; +} + +bool ExtensionActionFunction::GetBadgeBackgroundColor() { + ListValue* list = new ListValue(); + SkColor color = extension_action_->GetBadgeBackgroundColor(tab_id_); + list->Append(Value::CreateIntegerValue(SkColorGetR(color))); + list->Append(Value::CreateIntegerValue(SkColorGetG(color))); + list->Append(Value::CreateIntegerValue(SkColorGetB(color))); + list->Append(Value::CreateIntegerValue(SkColorGetA(color))); + result_.reset(list); + return true; +} diff --git a/chrome/browser/extensions/api/extension_action/extension_actions_api.h b/chrome/browser/extensions/api/extension_action/extension_actions_api.h index 6fd3457..dc3d53b 100644 --- a/chrome/browser/extensions/api/extension_action/extension_actions_api.h +++ b/chrome/browser/extensions/api/extension_action/extension_actions_api.h @@ -29,6 +29,10 @@ class ExtensionActionFunction : public SyncExtensionFunction { bool SetPopup(); bool SetBadgeBackgroundColor(); bool SetBadgeText(); + bool GetTitle(); + bool GetPopup(); + bool GetBadgeBackgroundColor(); + bool GetBadgeText(); // All the browser action APIs take a single argument called details that is // a dictionary. diff --git a/chrome/browser/extensions/api/extension_action/extension_browser_actions_api.cc b/chrome/browser/extensions/api/extension_action/extension_browser_actions_api.cc index a60c150..49e8ee9 100644 --- a/chrome/browser/extensions/api/extension_action/extension_browser_actions_api.cc +++ b/chrome/browser/extensions/api/extension_action/extension_browser_actions_api.cc @@ -18,6 +18,13 @@ const char kNoBrowserActionError[] = "This extension has no browser action specified."; } +void BrowserActionFunction::FireUpdateNotification() { + content::NotificationService::current()->Notify( + chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_UPDATED, + content::Source<ExtensionAction>(extension_action_), + content::NotificationService::NoDetails()); +} + bool BrowserActionFunction::RunImpl() { ExtensionActionFunction::RunImpl(); extension_action_ = GetExtension()->browser_action(); @@ -26,32 +33,56 @@ bool BrowserActionFunction::RunImpl() { return false; } - if (!RunExtensionAction()) - return false; - - content::NotificationService::current()->Notify( - chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_UPDATED, - content::Source<ExtensionAction>(extension_action_), - content::NotificationService::NoDetails()); - return true; + return RunExtensionAction(); } bool BrowserActionSetIconFunction::RunExtensionAction() { - return SetIcon(); + if (!SetIcon()) + return false; + FireUpdateNotification(); + return true; } bool BrowserActionSetTitleFunction::RunExtensionAction() { - return SetTitle(); + if (!SetTitle()) + return false; + FireUpdateNotification(); + return true; } bool BrowserActionSetPopupFunction::RunExtensionAction() { - return SetPopup(); + if (!SetPopup()) + return false; + FireUpdateNotification(); + return true; } bool BrowserActionSetBadgeTextFunction::RunExtensionAction() { - return SetBadgeText(); + if (!SetBadgeText()) + return false; + FireUpdateNotification(); + return true; } bool BrowserActionSetBadgeBackgroundColorFunction::RunExtensionAction() { - return SetBadgeBackgroundColor(); + if (!SetBadgeBackgroundColor()) + return false; + FireUpdateNotification(); + return true; +} + +bool BrowserActionGetTitleFunction::RunExtensionAction() { + return GetTitle(); +} + +bool BrowserActionGetPopupFunction::RunExtensionAction() { + return GetPopup(); +} + +bool BrowserActionGetBadgeTextFunction::RunExtensionAction() { + return GetBadgeText(); +} + +bool BrowserActionGetBadgeBackgroundColorFunction::RunExtensionAction() { + return GetBadgeBackgroundColor(); } diff --git a/chrome/browser/extensions/api/extension_action/extension_browser_actions_api.h b/chrome/browser/extensions/api/extension_action/extension_browser_actions_api.h index 5a453fe..1ead691 100644 --- a/chrome/browser/extensions/api/extension_action/extension_browser_actions_api.h +++ b/chrome/browser/extensions/api/extension_action/extension_browser_actions_api.h @@ -15,6 +15,7 @@ class BrowserActionFunction : public ExtensionActionFunction { protected: virtual ~BrowserActionFunction() {} virtual bool RunImpl() OVERRIDE; + void FireUpdateNotification(); }; // Implement chrome.browserAction.setIcon(). @@ -53,4 +54,33 @@ class BrowserActionSetBadgeBackgroundColorFunction DECLARE_EXTENSION_FUNCTION_NAME("browserAction.setBadgeBackgroundColor") }; +// Implement chrome.browserAction.getTitle(). +class BrowserActionGetTitleFunction : public BrowserActionFunction { + virtual ~BrowserActionGetTitleFunction() {} + virtual bool RunExtensionAction() OVERRIDE; + DECLARE_EXTENSION_FUNCTION_NAME("browserAction.getTitle") +}; + +// Implement chrome.browserAction.getPopup(). +class BrowserActionGetPopupFunction : public BrowserActionFunction { + virtual ~BrowserActionGetPopupFunction() {} + virtual bool RunExtensionAction() OVERRIDE; + DECLARE_EXTENSION_FUNCTION_NAME("browserAction.getPopup") +}; + +// Implement chrome.browserAction.getBadgeText(). +class BrowserActionGetBadgeTextFunction : public BrowserActionFunction { + virtual ~BrowserActionGetBadgeTextFunction() {} + virtual bool RunExtensionAction() OVERRIDE; + DECLARE_EXTENSION_FUNCTION_NAME("browserAction.getBadgeText") +}; + +// Implement chrome.browserAction.getBadgeBackgroundColor(). +class BrowserActionGetBadgeBackgroundColorFunction + : public BrowserActionFunction { + virtual ~BrowserActionGetBadgeBackgroundColorFunction() {} + virtual bool RunExtensionAction() OVERRIDE; + DECLARE_EXTENSION_FUNCTION_NAME("browserAction.getBadgeBackgroundColor") +}; + #endif // CHROME_BROWSER_EXTENSIONS_API_EXTENSION_ACTION_EXTENSION_BROWSER_ACTIONS_API_H_ diff --git a/chrome/browser/extensions/api/extension_action/extension_page_actions_api.cc b/chrome/browser/extensions/api/extension_action/extension_page_actions_api.cc index 3b00362..81a9c2d 100644 --- a/chrome/browser/extensions/api/extension_action/extension_page_actions_api.cc +++ b/chrome/browser/extensions/api/extension_action/extension_page_actions_api.cc @@ -222,3 +222,23 @@ bool PageActionSetBadgeTextFunction::RunExtensionAction() { contents_->extension_tab_helper()->PageActionStateChanged(); return true; } + +bool PageActionGetTitleFunction::RunExtensionAction() { + return GetTitle(); +} + +bool PageActionGetPopupFunction::RunExtensionAction() { + return GetPopup(); +} + +// Not currently exposed to extensions. To re-enable, add mapping in +// extension_function_dispatcher. +bool PageActionGetBadgeBackgroundColorFunction::RunExtensionAction() { + return GetBadgeBackgroundColor(); +} + +// Not currently exposed to extensions. To re-enable, add mapping in +// extension_function_dispatcher. +bool PageActionGetBadgeTextFunction::RunExtensionAction() { + return GetBadgeText(); +} diff --git a/chrome/browser/extensions/api/extension_action/extension_page_actions_api.h b/chrome/browser/extensions/api/extension_action/extension_page_actions_api.h index 6a8e68b59..931d807 100644 --- a/chrome/browser/extensions/api/extension_action/extension_page_actions_api.h +++ b/chrome/browser/extensions/api/extension_action/extension_page_actions_api.h @@ -92,4 +92,32 @@ class PageActionSetBadgeTextFunction : public PageActionFunction { DECLARE_EXTENSION_FUNCTION_NAME("pageAction.setBadgeText") }; +// Implement chrome.pageAction.getTitle(). +class PageActionGetTitleFunction : public PageActionFunction { + virtual ~PageActionGetTitleFunction() {} + virtual bool RunExtensionAction() OVERRIDE; + DECLARE_EXTENSION_FUNCTION_NAME("pageAction.getTitle") +}; + +// Implement chrome.pageAction.getPopup(). +class PageActionGetPopupFunction : public PageActionFunction { + virtual ~PageActionGetPopupFunction() {} + virtual bool RunExtensionAction() OVERRIDE; + DECLARE_EXTENSION_FUNCTION_NAME("pageAction.getPopup") +}; + +// Implement chrome.pageAction.getBadgeText(). +class PageActionGetBadgeTextFunction : public PageActionFunction { + virtual ~PageActionGetBadgeTextFunction() {} + virtual bool RunExtensionAction() OVERRIDE; + DECLARE_EXTENSION_FUNCTION_NAME("pageAction.getBadgeText") +}; + +// Implement chrome.pageAction.getBadgeBackgroundColor(). +class PageActionGetBadgeBackgroundColorFunction : public PageActionFunction { + virtual ~PageActionGetBadgeBackgroundColorFunction() {} + virtual bool RunExtensionAction() OVERRIDE; + DECLARE_EXTENSION_FUNCTION_NAME("pageAction.getBadgeBackgroundColor") +}; + #endif // CHROME_BROWSER_EXTENSIONS_API_EXTENSION_ACTION_EXTENSION_PAGE_ACTIONS_API_H_ diff --git a/chrome/browser/extensions/page_action_apitest.cc b/chrome/browser/extensions/api/extension_action/page_action_apitest.cc index b0417af..7591077 100644 --- a/chrome/browser/extensions/page_action_apitest.cc +++ b/chrome/browser/extensions/api/extension_action/page_action_apitest.cc @@ -194,3 +194,14 @@ IN_PROC_BROWSER_TEST_F(ExtensionApiTest, TestCrash57333) { .AppendASCII("crash_57333") .AppendASCII("Extension2"))); } + +IN_PROC_BROWSER_TEST_F(ExtensionApiTest, Getters) { + ASSERT_TRUE(RunExtensionTest("page_action/getters")) << message_; + const Extension* extension = GetSingleLoadedExtension(); + ASSERT_TRUE(extension) << message_; + + ResultCatcher catcher; + ui_test_utils::NavigateToURL(browser(), + GURL(extension->GetResourceURL("update.html"))); + ASSERT_TRUE(catcher.GetNextResult()); +} diff --git a/chrome/browser/extensions/extension_function_dispatcher.cc b/chrome/browser/extensions/extension_function_dispatcher.cc index 3191929..7d04788 100644 --- a/chrome/browser/extensions/extension_function_dispatcher.cc +++ b/chrome/browser/extensions/extension_function_dispatcher.cc @@ -182,6 +182,8 @@ void FactoryRegistry::ResetFunctions() { RegisterFunction<PageActionSetIconFunction>(); RegisterFunction<PageActionSetTitleFunction>(); RegisterFunction<PageActionSetPopupFunction>(); + RegisterFunction<PageActionGetTitleFunction>(); + RegisterFunction<PageActionGetPopupFunction>(); // Browser Actions. RegisterFunction<BrowserActionSetIconFunction>(); @@ -189,6 +191,10 @@ void FactoryRegistry::ResetFunctions() { RegisterFunction<BrowserActionSetBadgeTextFunction>(); RegisterFunction<BrowserActionSetBadgeBackgroundColorFunction>(); RegisterFunction<BrowserActionSetPopupFunction>(); + RegisterFunction<BrowserActionGetTitleFunction>(); + RegisterFunction<BrowserActionGetBadgeTextFunction>(); + RegisterFunction<BrowserActionGetBadgeBackgroundColorFunction>(); + RegisterFunction<BrowserActionGetPopupFunction>(); // Browsing Data. RegisterFunction<RemoveBrowsingDataFunction>(); diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 0a80d37..a54cecf 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -2626,6 +2626,8 @@ 'browser/extensions/api/browsing_data/browsing_data_test.cc', 'browser/extensions/api/declarative/declarative_apitest.cc', 'browser/extensions/api/dns/dns_apitest.cc', + 'browser/extensions/api/extension_action/browser_action_apitest.cc', + 'browser/extensions/api/extension_action/page_action_apitest.cc', 'browser/extensions/api/permissions/permissions_apitest.cc', 'browser/extensions/api/proxy/proxy_apitest.cc', 'browser/extensions/api/serial/serial_apitest.cc', @@ -2639,7 +2641,6 @@ 'browser/extensions/autoupdate_interceptor.h', 'browser/extensions/background_page_apitest.cc', 'browser/extensions/background_scripts_apitest.cc', - 'browser/extensions/browser_action_apitest.cc', 'browser/extensions/browser_action_test_util.h', 'browser/extensions/browser_action_test_util_gtk.cc', 'browser/extensions/browser_action_test_util_mac.mm', @@ -2720,7 +2721,6 @@ 'browser/extensions/isolated_app_browsertest.cc', 'browser/extensions/lazy_background_page_apitest.cc', 'browser/extensions/notifications_apitest.cc', - 'browser/extensions/page_action_apitest.cc', 'browser/extensions/platform_app_browsertest.cc', 'browser/extensions/process_management_browsertest.cc', 'browser/extensions/settings/settings_apitest.cc', diff --git a/chrome/common/extensions/api/browserAction.json b/chrome/common/extensions/api/browserAction.json index 20768b6..5eaee46 100644 --- a/chrome/common/extensions/api/browserAction.json +++ b/chrome/common/extensions/api/browserAction.json @@ -6,7 +6,19 @@ { "namespace": "browserAction", "dependencies": [ "tabs" ], - "types": [], + "types": [ + { + "id": "ColorArray", + "type": "array", + "items": { + "type": "integer", + "minimum": 0, + "maximum": 255 + }, + "minItems": 4, + "maxItems": 4 + } + ], "functions": [ { "name": "setTitle", @@ -31,6 +43,34 @@ ] }, { + "name": "getTitle", + "type": "function", + "description": "Gets the title of the browser action.", + "parameters": [ + { + "name": "details", + "type": "object", + "properties": { + "tabId": { + "type": "integer", + "optional": true, + "description": "Specify the tab to get the title from. If no tab is specified, the non-tab-specific title is returned." + } + } + }, + { + "type": "function", + "name": "callback", + "parameters": [ + { + "name": "result", + "type": "string" + } + ] + } + ] + }, + { "name": "setIcon", "type": "function", "description": "Sets the icon for the browser action. The icon can be specified either as the path to an image file or as the pixel data from a canvas element. Either the <b>path</b> or the <b>imageData</b> property must be specified.", @@ -84,6 +124,34 @@ ] }, { + "name": "getPopup", + "type": "function", + "description": "Gets the html document set as the popup for this browser action.", + "parameters": [ + { + "name": "details", + "type": "object", + "properties": { + "tabId": { + "type": "integer", + "optional": true, + "description": "Specify the tab to get the popup from. If no tab is specified, the non-tab-specific popup is returned." + } + } + }, + { + "type": "function", + "name": "callback", + "parameters": [ + { + "name": "result", + "type": "string" + } + ] + } + ] + }, + { "name": "setBadgeText", "type": "function", "description": "Sets the badge text for the browser action. The badge is displayed on top of the icon.", @@ -106,6 +174,34 @@ ] }, { + "name": "getBadgeText", + "type": "function", + "description": "Gets the badge text of the browser action. If no tab is specified, the non-tab-specific badge text is returned.", + "parameters": [ + { + "name": "details", + "type": "object", + "properties": { + "tabId": { + "type": "integer", + "optional": true, + "description": "Specify the tab to get the badge text from. If no tab is specified, the non-tab-specific badge text is returned." + } + } + }, + { + "type": "function", + "name": "callback", + "parameters": [ + { + "name": "result", + "type": "string" + } + ] + } + ] + }, + { "name": "setBadgeBackgroundColor", "type": "function", "description": "Sets the background color for the badge.", @@ -119,15 +215,7 @@ "description": "An array of four integers in the range [0,255] that make up the RGBA color of the badge. For example, opaque red is <code>[255, 0, 0, 255]</code>. Can also be a string with a CSS value, with opaque red being <code>#FF0000</code> or <code>#F00</code>.", "choices": [ {"type": "string"}, - {"type": "array", - "items": { - "type": "integer", - "minimum": 0, - "maximum": 255 - }, - "minItems": 4, - "maxItems": 4 - } + {"$ref": "ColorArray"} ] }, "tabId": { @@ -138,6 +226,34 @@ } } ] + }, + { + "name": "getBadgeBackgroundColor", + "type": "function", + "description": "Gets the background color of the browser action.", + "parameters": [ + { + "name": "details", + "type": "object", + "properties": { + "tabId": { + "type": "integer", + "optional": true, + "description": "Specify the tab to get the badge background color from. If no tab is specified, the non-tab-specific badge background color is returned." + } + } + }, + { + "type": "function", + "name": "callback", + "parameters": [ + { + "name": "result", + "$ref": "ColorArray" + } + ] + } + ] } ], "events": [ diff --git a/chrome/common/extensions/api/pageAction.json b/chrome/common/extensions/api/pageAction.json index 9446006..c25a540 100644 --- a/chrome/common/extensions/api/pageAction.json +++ b/chrome/common/extensions/api/pageAction.json @@ -40,6 +40,33 @@ ] }, { + "name": "getTitle", + "type": "function", + "description": "Gets the title of the browser action.", + "parameters": [ + { + "name": "details", + "type": "object", + "properties": { + "tabId": { + "type": "integer", + "description": "Specify the tab to get the title from." + } + } + }, + { + "type": "function", + "name": "callback", + "parameters": [ + { + "name": "result", + "type": "string" + } + ] + } + ] + }, + { "name": "setIcon", "type": "function", "description": "Sets the icon for the page action. The icon can be specified either as the path to an image file or as the pixel data from a canvas element. Either the <b>path</b> or the <b>imageData</b> property must be specified.", @@ -88,6 +115,33 @@ } } ] + }, + { + "name": "getPopup", + "type": "function", + "description": "Gets the html document set as the popup for this browser action.", + "parameters": [ + { + "name": "details", + "type": "object", + "properties": { + "tabId": { + "type": "integer", + "description": "Specify the tab to get the popup from." + } + } + }, + { + "type": "function", + "name": "callback", + "parameters": [ + { + "name": "result", + "type": "string" + } + ] + } + ] } ], "events": [ diff --git a/chrome/common/extensions/docs/browserAction.html b/chrome/common/extensions/docs/browserAction.html index 325feb5..2147329 100644 --- a/chrome/common/extensions/docs/browserAction.html +++ b/chrome/common/extensions/docs/browserAction.html @@ -224,6 +224,14 @@ <a href="#global-methods">Methods</a> <ol> <li> + <a href="#method-getBadgeBackgroundColor">getBadgeBackgroundColor</a> + </li><li> + <a href="#method-getBadgeText">getBadgeText</a> + </li><li> + <a href="#method-getPopup">getPopup</a> + </li><li> + <a href="#method-getTitle">getTitle</a> + </li><li> <a href="#method-setBadgeBackgroundColor">setBadgeBackgroundColor</a> </li><li> <a href="#method-setBadgeText">setBadgeText</a> @@ -244,6 +252,16 @@ </li> </ol> </li> + <li> + <a href="#types">Types</a> + <ol> + <li> + <a href="#type-ColorArray">ColorArray</a> + <ol> + </ol> + </li> + </ol> + </li> </ol> </li> </ol> @@ -407,6 +425,562 @@ For other examples and for help in viewing the source code, see <h3>Methods</h3> <!-- iterates over all functions --> <div class="apiItem"> + <a name="method-getBadgeBackgroundColor"></a> <!-- method-anchor --> + <h4>getBadgeBackgroundColor</h4> + <div class="summary"> + <!-- Note: intentionally longer 80 columns --> + <span>chrome.browserAction.getBadgeBackgroundColor</span>(<span class="null"><span>object</span> + <var><span>details</span></var></span><span class="null"><span>, </span><span>function</span> + <var><span>callback</span></var></span>)</div> + <div class="description"> + <p>Gets the background color of the browser action.</p> + <!-- PARAMETERS --> + <h4>Parameters</h4> + <dl> + <div> + <div> + <dt> + <var>details</var> + <em> + <!-- TYPE --> + <div style="display:inline"> + ( + <span id="typeTemplate"> + <span> + <span>object</span> + </span> + </span> + ) + </div> + </em> + </dt> + <dd class="todo"> + Undocumented. + </dd> + <!-- OBJECT PROPERTIES --> + <dd> + <dl> + <div> + <div> + <dt> + <var>tabId</var> + <em> + <!-- TYPE --> + <div style="display:inline"> + ( + <span class="optional">optional</span> + <span id="typeTemplate"> + <span> + <span>integer</span> + </span> + </span> + ) + </div> + </em> + </dt> + <dd>Specify the tab to get the badge background color from. If no tab is specified, the non-tab-specific badge background color is returned.</dd> + <!-- OBJECT PROPERTIES --> + <!-- OBJECT METHODS --> + <!-- OBJECT EVENT FIELDS --> + <!-- FUNCTION PARAMETERS --> + </div> + </div> + </dl> + </dd> + <!-- OBJECT METHODS --> + <!-- OBJECT EVENT FIELDS --> + <!-- FUNCTION PARAMETERS --> + </div> + </div><div> + <div> + <dt> + <var>callback</var> + <em> + <!-- TYPE --> + <div style="display:inline"> + ( + <span id="typeTemplate"> + <span> + <span>function</span> + </span> + </span> + ) + </div> + </em> + </dt> + <dd class="todo"> + Undocumented. + </dd> + <!-- OBJECT PROPERTIES --> + <!-- OBJECT METHODS --> + <!-- OBJECT EVENT FIELDS --> + <!-- FUNCTION PARAMETERS --> + </div> + </div> + </dl> + <!-- RETURNS --> + <dl> + </dl> + <!-- CALLBACK --> + <div> + <div> + <h4>Callback function</h4> + <p> + The callback <em>parameter</em> should specify a function + that looks like this: + </p> + <!-- Note: intentionally longer 80 columns --> + <pre>function(<span>ColorArray result</span>) <span class="subdued">{...}</span>;</pre> + <dl> + <div> + <div> + <dt> + <var>result</var> + <em> + <!-- TYPE --> + <div style="display:inline"> + ( + <span id="typeTemplate"> + <span> + <a href="browserAction.html#type-ColorArray">ColorArray</a> + </span> + </span> + ) + </div> + </em> + </dt> + <dd class="todo"> + Undocumented. + </dd> + <!-- OBJECT PROPERTIES --> + <!-- OBJECT METHODS --> + <!-- OBJECT EVENT FIELDS --> + <!-- FUNCTION PARAMETERS --> + </div> + </div> + </dl> + </div> + </div> + <!-- MIN_VERSION --> + </div> <!-- /description --> + </div><div class="apiItem"> + <a name="method-getBadgeText"></a> <!-- method-anchor --> + <h4>getBadgeText</h4> + <div class="summary"> + <!-- Note: intentionally longer 80 columns --> + <span>chrome.browserAction.getBadgeText</span>(<span class="null"><span>object</span> + <var><span>details</span></var></span><span class="null"><span>, </span><span>function</span> + <var><span>callback</span></var></span>)</div> + <div class="description"> + <p>Gets the badge text of the browser action. If no tab is specified, the non-tab-specific badge text is returned.</p> + <!-- PARAMETERS --> + <h4>Parameters</h4> + <dl> + <div> + <div> + <dt> + <var>details</var> + <em> + <!-- TYPE --> + <div style="display:inline"> + ( + <span id="typeTemplate"> + <span> + <span>object</span> + </span> + </span> + ) + </div> + </em> + </dt> + <dd class="todo"> + Undocumented. + </dd> + <!-- OBJECT PROPERTIES --> + <dd> + <dl> + <div> + <div> + <dt> + <var>tabId</var> + <em> + <!-- TYPE --> + <div style="display:inline"> + ( + <span class="optional">optional</span> + <span id="typeTemplate"> + <span> + <span>integer</span> + </span> + </span> + ) + </div> + </em> + </dt> + <dd>Specify the tab to get the badge text from. If no tab is specified, the non-tab-specific badge text is returned.</dd> + <!-- OBJECT PROPERTIES --> + <!-- OBJECT METHODS --> + <!-- OBJECT EVENT FIELDS --> + <!-- FUNCTION PARAMETERS --> + </div> + </div> + </dl> + </dd> + <!-- OBJECT METHODS --> + <!-- OBJECT EVENT FIELDS --> + <!-- FUNCTION PARAMETERS --> + </div> + </div><div> + <div> + <dt> + <var>callback</var> + <em> + <!-- TYPE --> + <div style="display:inline"> + ( + <span id="typeTemplate"> + <span> + <span>function</span> + </span> + </span> + ) + </div> + </em> + </dt> + <dd class="todo"> + Undocumented. + </dd> + <!-- OBJECT PROPERTIES --> + <!-- OBJECT METHODS --> + <!-- OBJECT EVENT FIELDS --> + <!-- FUNCTION PARAMETERS --> + </div> + </div> + </dl> + <!-- RETURNS --> + <dl> + </dl> + <!-- CALLBACK --> + <div> + <div> + <h4>Callback function</h4> + <p> + The callback <em>parameter</em> should specify a function + that looks like this: + </p> + <!-- Note: intentionally longer 80 columns --> + <pre>function(<span>string result</span>) <span class="subdued">{...}</span>;</pre> + <dl> + <div> + <div> + <dt> + <var>result</var> + <em> + <!-- TYPE --> + <div style="display:inline"> + ( + <span id="typeTemplate"> + <span> + <span>string</span> + </span> + </span> + ) + </div> + </em> + </dt> + <dd class="todo"> + Undocumented. + </dd> + <!-- OBJECT PROPERTIES --> + <!-- OBJECT METHODS --> + <!-- OBJECT EVENT FIELDS --> + <!-- FUNCTION PARAMETERS --> + </div> + </div> + </dl> + </div> + </div> + <!-- MIN_VERSION --> + </div> <!-- /description --> + </div><div class="apiItem"> + <a name="method-getPopup"></a> <!-- method-anchor --> + <h4>getPopup</h4> + <div class="summary"> + <!-- Note: intentionally longer 80 columns --> + <span>chrome.browserAction.getPopup</span>(<span class="null"><span>object</span> + <var><span>details</span></var></span><span class="null"><span>, </span><span>function</span> + <var><span>callback</span></var></span>)</div> + <div class="description"> + <p>Gets the html document set as the popup for this browser action.</p> + <!-- PARAMETERS --> + <h4>Parameters</h4> + <dl> + <div> + <div> + <dt> + <var>details</var> + <em> + <!-- TYPE --> + <div style="display:inline"> + ( + <span id="typeTemplate"> + <span> + <span>object</span> + </span> + </span> + ) + </div> + </em> + </dt> + <dd class="todo"> + Undocumented. + </dd> + <!-- OBJECT PROPERTIES --> + <dd> + <dl> + <div> + <div> + <dt> + <var>tabId</var> + <em> + <!-- TYPE --> + <div style="display:inline"> + ( + <span class="optional">optional</span> + <span id="typeTemplate"> + <span> + <span>integer</span> + </span> + </span> + ) + </div> + </em> + </dt> + <dd>Specify the tab to get the popup from. If no tab is specified, the non-tab-specific popup is returned.</dd> + <!-- OBJECT PROPERTIES --> + <!-- OBJECT METHODS --> + <!-- OBJECT EVENT FIELDS --> + <!-- FUNCTION PARAMETERS --> + </div> + </div> + </dl> + </dd> + <!-- OBJECT METHODS --> + <!-- OBJECT EVENT FIELDS --> + <!-- FUNCTION PARAMETERS --> + </div> + </div><div> + <div> + <dt> + <var>callback</var> + <em> + <!-- TYPE --> + <div style="display:inline"> + ( + <span id="typeTemplate"> + <span> + <span>function</span> + </span> + </span> + ) + </div> + </em> + </dt> + <dd class="todo"> + Undocumented. + </dd> + <!-- OBJECT PROPERTIES --> + <!-- OBJECT METHODS --> + <!-- OBJECT EVENT FIELDS --> + <!-- FUNCTION PARAMETERS --> + </div> + </div> + </dl> + <!-- RETURNS --> + <dl> + </dl> + <!-- CALLBACK --> + <div> + <div> + <h4>Callback function</h4> + <p> + The callback <em>parameter</em> should specify a function + that looks like this: + </p> + <!-- Note: intentionally longer 80 columns --> + <pre>function(<span>string result</span>) <span class="subdued">{...}</span>;</pre> + <dl> + <div> + <div> + <dt> + <var>result</var> + <em> + <!-- TYPE --> + <div style="display:inline"> + ( + <span id="typeTemplate"> + <span> + <span>string</span> + </span> + </span> + ) + </div> + </em> + </dt> + <dd class="todo"> + Undocumented. + </dd> + <!-- OBJECT PROPERTIES --> + <!-- OBJECT METHODS --> + <!-- OBJECT EVENT FIELDS --> + <!-- FUNCTION PARAMETERS --> + </div> + </div> + </dl> + </div> + </div> + <!-- MIN_VERSION --> + </div> <!-- /description --> + </div><div class="apiItem"> + <a name="method-getTitle"></a> <!-- method-anchor --> + <h4>getTitle</h4> + <div class="summary"> + <!-- Note: intentionally longer 80 columns --> + <span>chrome.browserAction.getTitle</span>(<span class="null"><span>object</span> + <var><span>details</span></var></span><span class="null"><span>, </span><span>function</span> + <var><span>callback</span></var></span>)</div> + <div class="description"> + <p>Gets the title of the browser action.</p> + <!-- PARAMETERS --> + <h4>Parameters</h4> + <dl> + <div> + <div> + <dt> + <var>details</var> + <em> + <!-- TYPE --> + <div style="display:inline"> + ( + <span id="typeTemplate"> + <span> + <span>object</span> + </span> + </span> + ) + </div> + </em> + </dt> + <dd class="todo"> + Undocumented. + </dd> + <!-- OBJECT PROPERTIES --> + <dd> + <dl> + <div> + <div> + <dt> + <var>tabId</var> + <em> + <!-- TYPE --> + <div style="display:inline"> + ( + <span class="optional">optional</span> + <span id="typeTemplate"> + <span> + <span>integer</span> + </span> + </span> + ) + </div> + </em> + </dt> + <dd>Specify the tab to get the title from. If no tab is specified, the non-tab-specific title is returned.</dd> + <!-- OBJECT PROPERTIES --> + <!-- OBJECT METHODS --> + <!-- OBJECT EVENT FIELDS --> + <!-- FUNCTION PARAMETERS --> + </div> + </div> + </dl> + </dd> + <!-- OBJECT METHODS --> + <!-- OBJECT EVENT FIELDS --> + <!-- FUNCTION PARAMETERS --> + </div> + </div><div> + <div> + <dt> + <var>callback</var> + <em> + <!-- TYPE --> + <div style="display:inline"> + ( + <span id="typeTemplate"> + <span> + <span>function</span> + </span> + </span> + ) + </div> + </em> + </dt> + <dd class="todo"> + Undocumented. + </dd> + <!-- OBJECT PROPERTIES --> + <!-- OBJECT METHODS --> + <!-- OBJECT EVENT FIELDS --> + <!-- FUNCTION PARAMETERS --> + </div> + </div> + </dl> + <!-- RETURNS --> + <dl> + </dl> + <!-- CALLBACK --> + <div> + <div> + <h4>Callback function</h4> + <p> + The callback <em>parameter</em> should specify a function + that looks like this: + </p> + <!-- Note: intentionally longer 80 columns --> + <pre>function(<span>string result</span>) <span class="subdued">{...}</span>;</pre> + <dl> + <div> + <div> + <dt> + <var>result</var> + <em> + <!-- TYPE --> + <div style="display:inline"> + ( + <span id="typeTemplate"> + <span> + <span>string</span> + </span> + </span> + ) + </div> + </em> + </dt> + <dd class="todo"> + Undocumented. + </dd> + <!-- OBJECT PROPERTIES --> + <!-- OBJECT METHODS --> + <!-- OBJECT EVENT FIELDS --> + <!-- FUNCTION PARAMETERS --> + </div> + </div> + </dl> + </div> + </div> + <!-- MIN_VERSION --> + </div> <!-- /description --> + </div><div class="apiItem"> <a name="method-setBadgeBackgroundColor"></a> <!-- method-anchor --> <h4>setBadgeBackgroundColor</h4> <div class="summary"> @@ -451,7 +1025,7 @@ For other examples and for help in viewing the source code, see ( <span id="typeTemplate"> <span> - <span>string or array of integer</span> + <span>string or ColorArray</span> </span> </span> ) @@ -972,7 +1546,44 @@ For other examples and for help in viewing the source code, see </div> <!-- /apiItem --> </div> <!-- /apiGroup --> <!-- TYPES --> - <!-- /apiGroup --> + <div class="apiGroup"> + <a name="types"></a> + <h3 id="types">Types</h3> + <!-- iterates over all types --> + <div class="apiItem"> + <a name="type-ColorArray"></a> + <h4>ColorArray</h4> + <div> + <dt> + <em> + <!-- TYPE --> + <div style="display:inline"> + ( + <span id="typeTemplate"> + <span> + <span> + array of <span><span> + <span> + <span>integer</span> + </span> + </span></span> + </span> + </span> + </span> + ) + </div> + </em> + </dt> + <dd class="todo"> + Undocumented. + </dd> + <!-- OBJECT PROPERTIES --> + <!-- OBJECT METHODS --> + <!-- OBJECT EVENT FIELDS --> + <!-- FUNCTION PARAMETERS --> + </div> + </div> <!-- /apiItem --> + </div> <!-- /apiGroup --> </div> <!-- /apiPage --> </div> <!-- /gc-pagecontent --> </div> <!-- /g-section --> diff --git a/chrome/common/extensions/docs/pageAction.html b/chrome/common/extensions/docs/pageAction.html index 282aa3f..5bf39be 100644 --- a/chrome/common/extensions/docs/pageAction.html +++ b/chrome/common/extensions/docs/pageAction.html @@ -215,6 +215,10 @@ <a href="#global-methods">Methods</a> <ol> <li> + <a href="#method-getPopup">getPopup</a> + </li><li> + <a href="#method-getTitle">getTitle</a> + </li><li> <a href="#method-hide">hide</a> </li><li> <a href="#method-setIcon">setIcon</a> @@ -346,6 +350,282 @@ For other examples and for help in viewing the source code, see <h3>Methods</h3> <!-- iterates over all functions --> <div class="apiItem"> + <a name="method-getPopup"></a> <!-- method-anchor --> + <h4>getPopup</h4> + <div class="summary"> + <!-- Note: intentionally longer 80 columns --> + <span>chrome.pageAction.getPopup</span>(<span class="null"><span>object</span> + <var><span>details</span></var></span><span class="null"><span>, </span><span>function</span> + <var><span>callback</span></var></span>)</div> + <div class="description"> + <p>Gets the html document set as the popup for this browser action.</p> + <!-- PARAMETERS --> + <h4>Parameters</h4> + <dl> + <div> + <div> + <dt> + <var>details</var> + <em> + <!-- TYPE --> + <div style="display:inline"> + ( + <span id="typeTemplate"> + <span> + <span>object</span> + </span> + </span> + ) + </div> + </em> + </dt> + <dd class="todo"> + Undocumented. + </dd> + <!-- OBJECT PROPERTIES --> + <dd> + <dl> + <div> + <div> + <dt> + <var>tabId</var> + <em> + <!-- TYPE --> + <div style="display:inline"> + ( + <span id="typeTemplate"> + <span> + <span>integer</span> + </span> + </span> + ) + </div> + </em> + </dt> + <dd>Specify the tab to get the popup from.</dd> + <!-- OBJECT PROPERTIES --> + <!-- OBJECT METHODS --> + <!-- OBJECT EVENT FIELDS --> + <!-- FUNCTION PARAMETERS --> + </div> + </div> + </dl> + </dd> + <!-- OBJECT METHODS --> + <!-- OBJECT EVENT FIELDS --> + <!-- FUNCTION PARAMETERS --> + </div> + </div><div> + <div> + <dt> + <var>callback</var> + <em> + <!-- TYPE --> + <div style="display:inline"> + ( + <span id="typeTemplate"> + <span> + <span>function</span> + </span> + </span> + ) + </div> + </em> + </dt> + <dd class="todo"> + Undocumented. + </dd> + <!-- OBJECT PROPERTIES --> + <!-- OBJECT METHODS --> + <!-- OBJECT EVENT FIELDS --> + <!-- FUNCTION PARAMETERS --> + </div> + </div> + </dl> + <!-- RETURNS --> + <dl> + </dl> + <!-- CALLBACK --> + <div> + <div> + <h4>Callback function</h4> + <p> + The callback <em>parameter</em> should specify a function + that looks like this: + </p> + <!-- Note: intentionally longer 80 columns --> + <pre>function(<span>string result</span>) <span class="subdued">{...}</span>;</pre> + <dl> + <div> + <div> + <dt> + <var>result</var> + <em> + <!-- TYPE --> + <div style="display:inline"> + ( + <span id="typeTemplate"> + <span> + <span>string</span> + </span> + </span> + ) + </div> + </em> + </dt> + <dd class="todo"> + Undocumented. + </dd> + <!-- OBJECT PROPERTIES --> + <!-- OBJECT METHODS --> + <!-- OBJECT EVENT FIELDS --> + <!-- FUNCTION PARAMETERS --> + </div> + </div> + </dl> + </div> + </div> + <!-- MIN_VERSION --> + </div> <!-- /description --> + </div><div class="apiItem"> + <a name="method-getTitle"></a> <!-- method-anchor --> + <h4>getTitle</h4> + <div class="summary"> + <!-- Note: intentionally longer 80 columns --> + <span>chrome.pageAction.getTitle</span>(<span class="null"><span>object</span> + <var><span>details</span></var></span><span class="null"><span>, </span><span>function</span> + <var><span>callback</span></var></span>)</div> + <div class="description"> + <p>Gets the title of the browser action.</p> + <!-- PARAMETERS --> + <h4>Parameters</h4> + <dl> + <div> + <div> + <dt> + <var>details</var> + <em> + <!-- TYPE --> + <div style="display:inline"> + ( + <span id="typeTemplate"> + <span> + <span>object</span> + </span> + </span> + ) + </div> + </em> + </dt> + <dd class="todo"> + Undocumented. + </dd> + <!-- OBJECT PROPERTIES --> + <dd> + <dl> + <div> + <div> + <dt> + <var>tabId</var> + <em> + <!-- TYPE --> + <div style="display:inline"> + ( + <span id="typeTemplate"> + <span> + <span>integer</span> + </span> + </span> + ) + </div> + </em> + </dt> + <dd>Specify the tab to get the title from.</dd> + <!-- OBJECT PROPERTIES --> + <!-- OBJECT METHODS --> + <!-- OBJECT EVENT FIELDS --> + <!-- FUNCTION PARAMETERS --> + </div> + </div> + </dl> + </dd> + <!-- OBJECT METHODS --> + <!-- OBJECT EVENT FIELDS --> + <!-- FUNCTION PARAMETERS --> + </div> + </div><div> + <div> + <dt> + <var>callback</var> + <em> + <!-- TYPE --> + <div style="display:inline"> + ( + <span id="typeTemplate"> + <span> + <span>function</span> + </span> + </span> + ) + </div> + </em> + </dt> + <dd class="todo"> + Undocumented. + </dd> + <!-- OBJECT PROPERTIES --> + <!-- OBJECT METHODS --> + <!-- OBJECT EVENT FIELDS --> + <!-- FUNCTION PARAMETERS --> + </div> + </div> + </dl> + <!-- RETURNS --> + <dl> + </dl> + <!-- CALLBACK --> + <div> + <div> + <h4>Callback function</h4> + <p> + The callback <em>parameter</em> should specify a function + that looks like this: + </p> + <!-- Note: intentionally longer 80 columns --> + <pre>function(<span>string result</span>) <span class="subdued">{...}</span>;</pre> + <dl> + <div> + <div> + <dt> + <var>result</var> + <em> + <!-- TYPE --> + <div style="display:inline"> + ( + <span id="typeTemplate"> + <span> + <span>string</span> + </span> + </span> + ) + </div> + </em> + </dt> + <dd class="todo"> + Undocumented. + </dd> + <!-- OBJECT PROPERTIES --> + <!-- OBJECT METHODS --> + <!-- OBJECT EVENT FIELDS --> + <!-- FUNCTION PARAMETERS --> + </div> + </div> + </dl> + </div> + </div> + <!-- MIN_VERSION --> + </div> <!-- /description --> + </div><div class="apiItem"> <a name="method-hide"></a> <!-- method-anchor --> <h4>hide</h4> <div class="summary"> diff --git a/chrome/test/data/extensions/api_test/browser_action/getters/background.js b/chrome/test/data/extensions/api_test/browser_action/getters/background.js new file mode 100644 index 0000000..3a47ec1 --- /dev/null +++ b/chrome/test/data/extensions/api_test/browser_action/getters/background.js @@ -0,0 +1,17 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +chrome.browserAction.setBadgeBackgroundColor({color: [255, 0, 0, 255]}); +chrome.browserAction.setBadgeText({text: 'Text'}); + +chrome.tabs.getSelected(null, function(tab) { + chrome.browserAction.setPopup({tabId: tab.id, popup: 'newPopup.html'}); + chrome.browserAction.setTitle({tabId: tab.id, title: 'newTitle'}); + chrome.browserAction.setBadgeBackgroundColor({ + tabId: tab.id, + color: [0, 0, 0, 0] + }); + chrome.browserAction.setBadgeText({tabId: tab.id, text: 'newText'}); + chrome.test.notifyPass() +}); diff --git a/chrome/test/data/extensions/api_test/browser_action/getters/manifest.json b/chrome/test/data/extensions/api_test/browser_action/getters/manifest.json new file mode 100644 index 0000000..08f9845 --- /dev/null +++ b/chrome/test/data/extensions/api_test/browser_action/getters/manifest.json @@ -0,0 +1,15 @@ +{ + "name": "A browser action for testing chrome.browserAction getters", + "version": "1.0", + "manifest_version": 2, + "background": { + "scripts": ["background.js"] + }, + "permissions": [ + "tabs", "http://*/*" + ], + "browser_action": { + "default_title": "Title", + "default_popup": "Popup.html" + } +} diff --git a/chrome/test/data/extensions/api_test/browser_action/getters/update.html b/chrome/test/data/extensions/api_test/browser_action/getters/update.html new file mode 100644 index 0000000..b3d6a288 --- /dev/null +++ b/chrome/test/data/extensions/api_test/browser_action/getters/update.html @@ -0,0 +1,7 @@ +<!-- + * Copyright (c) 2012 The Chromium Authors. All rights reserved. Use of this + * source code is governed by a BSD-style license that can be found in the + * LICENSE file. +--> + +<script src="update.js"></script> diff --git a/chrome/test/data/extensions/api_test/browser_action/getters/update.js b/chrome/test/data/extensions/api_test/browser_action/getters/update.js new file mode 100644 index 0000000..bb8a125 --- /dev/null +++ b/chrome/test/data/extensions/api_test/browser_action/getters/update.js @@ -0,0 +1,32 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +var pass = chrome.test.callbackPass; + +chrome.test.runTests([ + function getBadgeText() { + chrome.browserAction.getBadgeText({}, pass(function(result) { + chrome.test.assertEq("Text", result); + })); + }, + + function getBadgeBackgroundColor() { + chrome.browserAction.getBadgeBackgroundColor({}, pass(function(result) { + chrome.test.assertEq([255, 0, 0, 255], result); + })); + }, + + function getPopup() { + chrome.browserAction.getPopup({}, pass(function(result) { + chrome.test.assertTrue( + /chrome-extension\:\/\/[a-p]{32}\/Popup\.html/.test(result)); + })); + }, + + function getTitle() { + chrome.browserAction.getTitle({}, pass(function(result) { + chrome.test.assertEq("Title", result); + })); + } +]); diff --git a/chrome/test/data/extensions/api_test/browser_action/getters/update2.html b/chrome/test/data/extensions/api_test/browser_action/getters/update2.html new file mode 100644 index 0000000..a6e64bc --- /dev/null +++ b/chrome/test/data/extensions/api_test/browser_action/getters/update2.html @@ -0,0 +1,7 @@ +<!-- + * Copyright (c) 2012 The Chromium Authors. All rights reserved. Use of this + * source code is governed by a BSD-style license that can be found in the + * LICENSE file. +--> + +<script src="update2.js"></script> diff --git a/chrome/test/data/extensions/api_test/browser_action/getters/update2.js b/chrome/test/data/extensions/api_test/browser_action/getters/update2.js new file mode 100644 index 0000000..2530145 --- /dev/null +++ b/chrome/test/data/extensions/api_test/browser_action/getters/update2.js @@ -0,0 +1,43 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +var pass = chrome.test.callbackPass; + +chrome.tabs.getSelected(null, function(tab) { + chrome.browserAction.setPopup({tabId: tab.id, popup: 'newPopup.html'}) + chrome.browserAction.setTitle({tabId: tab.id, title: 'newTitle'}); + chrome.browserAction.setBadgeBackgroundColor({ + tabId: tab.id, + color: [0, 0, 0, 0] + }); + chrome.browserAction.setBadgeText({tabId: tab.id, text: 'newText'}); + + chrome.test.runTests([ + function getBadgeText() { + chrome.browserAction.getBadgeText({tabId: tab.id}, pass(function(result) { + chrome.test.assertEq("newText", result); + })); + }, + + function getBadgeBackgroundColor() { + chrome.browserAction.getBadgeBackgroundColor({tabId: tab.id}, + pass(function(result) { + chrome.test.assertEq([0, 0, 0, 0], result); + })); + }, + + function getPopup() { + chrome.browserAction.getPopup({tabId: tab.id}, pass(function(result) { + chrome.test.assertTrue( + /chrome-extension\:\/\/[a-p]{32}\/newPopup\.html/.test(result)); + })); + }, + + function getTitle() { + chrome.browserAction.getTitle({tabId: tab.id}, pass(function(result) { + chrome.test.assertEq("newTitle", result); + })); + } + ]); +}); diff --git a/chrome/test/data/extensions/api_test/page_action/getters/background.js b/chrome/test/data/extensions/api_test/page_action/getters/background.js new file mode 100644 index 0000000..6227850 --- /dev/null +++ b/chrome/test/data/extensions/api_test/page_action/getters/background.js @@ -0,0 +1,5 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +chrome.test.notifyPass() diff --git a/chrome/test/data/extensions/api_test/page_action/getters/manifest.json b/chrome/test/data/extensions/api_test/page_action/getters/manifest.json new file mode 100644 index 0000000..1495ce1 --- /dev/null +++ b/chrome/test/data/extensions/api_test/page_action/getters/manifest.json @@ -0,0 +1,15 @@ +{ + "name": "A page action for testing chrome.pageAction getters", + "version": "1.0", + "manifest_version": 2, + "background": { + "scripts": ["background.js"] + }, + "permissions": [ + "tabs", "http://*/*" + ], + "page_action": { + "default_title": "Title", + "default_popup": "Popup.html" + } +} diff --git a/chrome/test/data/extensions/api_test/page_action/getters/update.html b/chrome/test/data/extensions/api_test/page_action/getters/update.html new file mode 100644 index 0000000..b3d6a288 --- /dev/null +++ b/chrome/test/data/extensions/api_test/page_action/getters/update.html @@ -0,0 +1,7 @@ +<!-- + * Copyright (c) 2012 The Chromium Authors. All rights reserved. Use of this + * source code is governed by a BSD-style license that can be found in the + * LICENSE file. +--> + +<script src="update.js"></script> diff --git a/chrome/test/data/extensions/api_test/page_action/getters/update.js b/chrome/test/data/extensions/api_test/page_action/getters/update.js new file mode 100644 index 0000000..f874512 --- /dev/null +++ b/chrome/test/data/extensions/api_test/page_action/getters/update.js @@ -0,0 +1,22 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +var pass = chrome.test.callbackPass; + +chrome.tabs.getSelected(null, function(tab) { + chrome.test.runTests([ + function getPopup() { + chrome.pageAction.getPopup({tabId: tab.id}, pass(function(result) { + chrome.test.assertTrue( + /chrome-extension\:\/\/[a-p]{32}\/Popup\.html/.test(result)); + })); + }, + + function getTitle() { + chrome.pageAction.getTitle({tabId: tab.id}, pass(function(result) { + chrome.test.assertEq("Title", result); + })); + } + ]); +}); |