Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10422)

Unified Diff: chrome/test/data/extensions/api_test/permissions/optional_deny/background.js

Issue 8762014: Move another set of extension tests to manifest_version 2 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/test/data/extensions/api_test/permissions/optional_deny/background.js
===================================================================
--- chrome/test/data/extensions/api_test/permissions/optional_deny/background.js (revision 0)
+++ chrome/test/data/extensions/api_test/permissions/optional_deny/background.js (revision 0)
@@ -0,0 +1,65 @@
+// Copyright (c) 2011 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 assertFalse = chrome.test.assertFalse;
+var assertTrue = chrome.test.assertTrue;
+var pass = chrome.test.callbackPass;
+
+var NO_TABS_PERMISSION =
+ "You do not have permission to use 'windows.getAll'.";
+
+chrome.test.getConfig(function(config) {
+
+ function doReq(domain, callback) {
+ var req = new XMLHttpRequest();
+ var url = domain + ":PORT/files/extensions/test_file.txt";
+ url = url.replace(/PORT/, config.testServer.port);
+
+ chrome.test.log("Requesting url: " + url);
+ req.open("GET", url, true);
+
+ req.onload = function() {
+ assertEq(200, req.status);
+ assertEq("Hello!", req.responseText);
+ callback(true);
+ };
+
+ req.onerror = function() {
+ chrome.test.log("status: " + req.status);
+ chrome.test.log("text: " + req.responseText);
+ callback(false);
+ };
+
+ req.send(null);
+ }
+
+ chrome.test.runTests([
+ function denyRequest() {
+ chrome.permissions.request(
+ {permissions: ['tabs'], origins: ['http://*.c.com/*']},
+ pass(function(granted) {
+ // They were not granted, and there should be no error.
+ assertFalse(granted);
+ assertTrue(chrome.extension.lastError === undefined);
+
+ // Make sure they weren't granted...
+ chrome.permissions.contains(
+ {permissions: ['tabs'], origins:['http://*.c.com/*']},
+ pass(function(result) { assertFalse(result); }));
+
+ try {
+ chrome.windows.getAll({populate: true}, function() {
+ chrome.test.fail("Should not have tabs API permission.");
+ });
+ } catch (e) {
+ assertTrue(e.message.indexOf(NO_TABS_PERMISSION) == 0);
+ }
+
+ doReq('http://b.c.com/', pass(function(result) {
+ assertFalse(result);
+ }));
+ }));
+ }
+ ]);
+});

Powered by Google App Engine
This is Rietveld 408576698