Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / test / data / extensions / api_test / management / management_policy / allowed.js
blobcdd816882a1a1287ccaed63e96fd4569dd847480
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 var callback = chrome.test.callback;
7 // The names of the extensions to operate on, from their manifest.json files.
8 var ENABLED_NAME = 'enabled_extension';
9 var DISABLED_NAME = 'disabled_extension';
10 var UNINSTALL_NAME = 'enabled_extension';
12 // Given a list of extension |items|, finds the one with the given |name|.
13 function findByName(items, name) {
14 chrome.test.assertEq(8, items.length);
15 var item;
16 for (var i = 0; i < items.length; i++) {
17 item = items[i];
18 if (item.name == name)
19 break;
21 if (name != item.name)
22 chrome.test.fail('Couldn\'t find installed extension ' + name);
23 return item;
26 var tests = [
27 // Tests disabling an extension, expecting it to succeed.
28 function allowedDisable() {
29 chrome.management.getAll(callback(function(items) {
30 var item = findByName(items, ENABLED_NAME);
31 console.log(item);
32 chrome.test.assertEq(true, item.mayDisable);
33 chrome.test.assertEq(true, item.enabled);
35 var id = item.id;
36 chrome.management.setEnabled(id, false, callback(function() {
37 chrome.management.get(id, callback(function(same_extension) {
38 chrome.test.assertEq(false, same_extension.enabled);
39 }));
40 }));
41 }));
44 // Tests enabling an extension, expecting it to succeed.
45 function allowedEnable() {
46 chrome.management.getAll(callback(function(items) {
47 var item = findByName(items, DISABLED_NAME);
48 chrome.test.assertEq(true, item.mayDisable);
49 chrome.test.assertEq(false, item.enabled);
51 var id = item.id;
52 chrome.management.setEnabled(id, true, callback(function() {
53 chrome.management.get(id, callback(function(same_extension) {
54 chrome.test.assertEq(true, same_extension.enabled);
55 }));
56 }));
57 }));
60 // Tests uninstalling an extension, expecting it to succeed.
61 function allowedUninstall() {
62 chrome.management.getAll(callback(function(items) {
63 var item = findByName(items, UNINSTALL_NAME);
64 chrome.test.assertEq(true, item.mayDisable);
66 var id = item.id;
67 chrome.test.runWithUserGesture(function() {
68 chrome.management.uninstall(id, callback(function() {
69 chrome.test.assertNoLastError();
70 // The calling api test will verify that the item was uninstalled.
71 }));
72 });
73 }));
77 chrome.test.runTests(tests);