Commit 09471bf4 authored by Kelvin Jiang's avatar Kelvin Jiang Committed by Commit Bot

[Extensions] Allow setBadgeText to remove tab specific badge text

This CL makes the "text" param in chrome.browserAction.setBadgeText
optional. Setting text to be null (or not specifying it) removes the
explicitly set badge text for a given tab. The tab's badge text will
then be removed, or will show the default non-tab-specific badge text if
set.

Bug: 1002961
Change-Id: I7f9f4ef2ac3187fff0b06455fd4abcc1db0a5143
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2067641
Commit-Queue: Kelvin Jiang <kelvinjiang@chromium.org>
Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Reviewed-by: default avatarKaran Bhatia <karandeepb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#748366}
parent d3cc8c2a
......@@ -426,9 +426,13 @@ ExtensionActionSetPopupFunction::RunExtensionAction() {
ExtensionFunction::ResponseAction
ExtensionActionSetBadgeTextFunction::RunExtensionAction() {
EXTENSION_FUNCTION_VALIDATE(details_);
std::string badge_text;
EXTENSION_FUNCTION_VALIDATE(details_->GetString("text", &badge_text));
extension_action_->SetBadgeText(tab_id_, badge_text);
if (details_->GetString("text", &badge_text))
extension_action_->SetBadgeText(tab_id_, badge_text);
else
extension_action_->ClearBadgeText(tab_id_);
NotifyChange();
return RespondNow(NoArguments());
}
......
......@@ -190,7 +190,8 @@
"properties": {
"text": {
"type": "string",
"description": "Any number of characters can be passed, but only about four can fit into the space."
"optional": true,
"description": "Any number of characters can be passed, but only about four can fit into the space. If an empty string (<code>''</code>) is passed, the badge text is cleared. If <code>tabId</code> is specified and <code>text</code> is null, the text for the specified tab is cleared and defaults to the global badge text."
},
"tabId": {
"type": "integer",
......
......@@ -12,12 +12,50 @@ chrome.tabs.getSelected(null, function(tab) {
color: [0, 0, 0, 0]
});
chrome.browserAction.setBadgeText({tabId: tab.id, text: 'newText'});
chrome.browserAction.setBadgeText({text: 'defaultText'});
chrome.test.runTests([
function getBadgeText() {
chrome.browserAction.getBadgeText({tabId: tab.id}, pass(function(result) {
chrome.test.assertEq("newText", result);
}));
chrome.test.assertEq(
'newText', result);
}));
},
// Sanity check that specifying an empty string for setBadgeText will set
// the badge text to be empty instead of reset it to the default badge text.
function emptyTabBadgeText() {
chrome.browserAction.setBadgeText(
{tabId: tab.id, text: ''}, pass(function() {
chrome.browserAction.getBadgeText(
{tabId: tab.id}, pass(function(result) {
chrome.test.assertEq('', result);
}));
}));
},
// The badge text shown should be the default badge text (if set) after the
// tab specific badge text is removed via setBadgeText({tabId: tab.id}).
function clearTabBadgeText() {
chrome.browserAction.setBadgeText(
{tabId: tab.id}, pass(function() {
chrome.browserAction.getBadgeText(
{tabId: tab.id}, pass(function(result) {
chrome.test.assertEq('defaultText', result);
}));
}));
},
// The default badge text should be removed after setBadgeText({}) is
// called.
function clearGlobalBadgeText() {
chrome.browserAction.setBadgeText({}, pass(function() {
chrome.browserAction.getBadgeText(
{}, pass(function(result) {
chrome.test.assertEq(
'', result);
}));
}));
},
function getBadgeBackgroundColor() {
......@@ -36,8 +74,8 @@ chrome.tabs.getSelected(null, function(tab) {
function getTitle() {
chrome.browserAction.getTitle({tabId: tab.id}, pass(function(result) {
chrome.test.assertEq("newTitle", result);
}));
chrome.test.assertEq('newTitle', result);
}));
}
]);
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment