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
);
16 for (var i
= 0; i
< items
.length
; i
++) {
18 if (item
.name
== name
)
21 if (name
!= item
.name
)
22 chrome
.test
.fail('Couldn\'t find installed extension ' + name
);
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
);
32 chrome
.test
.assertEq(true, item
.mayDisable
);
33 chrome
.test
.assertEq(true, item
.enabled
);
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
);
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
);
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
);
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
);
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.
77 chrome
.test
.runTests(tests
);