Bug 1237822 - Throw error if tabs.query is used without "tabs" permission with url param. r=kmag

MozReview-Commit-ID: 4WpawIYcwnl

--HG--
extra : transplant_source : %1FD%00%5D%CEJ%E6%10Wj%C3%92%87%FFN%A4Vo%0C%E7
This commit is contained in:
tofumatt 2016-03-15 15:39:27 +01:00
Родитель eb138db0c4
Коммит 0f151b21a6
2 изменённых файлов: 51 добавлений и 0 удалений

Просмотреть файл

@ -553,6 +553,10 @@ extensions.registerSchemaAPI("tabs", null, (extension, context) => {
query: function(queryInfo) {
let pattern = null;
if (queryInfo.url !== null) {
if (!extension.hasPermission("tabs")) {
return Promise.reject({message: 'The "tabs" permission is required to use the query API with the "url" parameter'});
}
pattern = new MatchPattern(queryInfo.url);
}

Просмотреть файл

@ -136,3 +136,50 @@ add_task(function* () {
yield BrowserTestUtils.removeTab(tab2);
yield BrowserTestUtils.removeTab(tab3);
});
add_task(function* testQueryPermissions() {
let extension = ExtensionTestUtils.loadExtension({
manifest: {
"permissions": [],
},
background: function(x) {
browser.tabs.query({currentWindow: true, active: true}).then((tabs) => {
browser.test.assertEq(tabs.length, 1, "Expect query to return tabs");
browser.test.notifyPass("queryPermissions");
}).catch((e) => {
browser.test.notifyFail("queryPermissions");
});
},
});
yield extension.startup();
yield extension.awaitFinish("queryPermissions");
yield extension.unload();
});
add_task(function* testQueryWithURLPermissions() {
let extension = ExtensionTestUtils.loadExtension({
manifest: {
"permissions": [],
},
background: function(x) {
browser.tabs.query({"url": "http://www.bbc.com/"}).then(() => {
browser.test.notifyFail("queryWithURLPermissions");
}).catch((e) => {
browser.test.assertEq('The "tabs" permission is required to use the query API with the "url" parameter',
e.message, "Expected permissions error message");
browser.test.notifyPass("queryWithURLPermissions");
});
},
});
yield extension.startup();
yield extension.awaitFinish("queryWithURLPermissions");
yield extension.unload();
});