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 // The id of an extension we're using for install tests.
6 var extensionId
= "enfkhcelefdadlmkffamgdlgplcionje";
8 // The id of an app we're using for install tests.
9 var appId
= "iladmdjkfniedhfhcfoefgojhgaiaccc";
11 var assertEq
= chrome
.test
.assertEq
;
12 var assertFalse
= chrome
.test
.assertFalse
;
13 var assertNoLastError
= chrome
.test
.assertNoLastError
;
14 var assertTrue
= chrome
.test
.assertTrue
;
15 var callbackFail
= chrome
.test
.callbackFail
;
16 var callbackPass
= chrome
.test
.callbackPass
;
17 var listenOnce
= chrome
.test
.listenOnce
;
18 var runTests
= chrome
.test
.runTests
;
19 var succeed
= chrome
.test
.succeed
;
21 // Calls |callback| with true/false indicating whether an item with the |id|
23 function checkItemInstalled(id
, callback
) {
24 chrome
.management
.getAll(function(extensions
) {
25 callback(extensions
.some(function(ext
) {
31 // Calls |callback| with true/false indicating whether an item with an id of
32 // extensionId is installed.
33 function checkInstalled(callback
) {
34 checkItemInstalled(extensionId
, callback
);
37 var cachedIcon
= null;
40 // This returns the base64-encoded content of the extension's image.
41 function getIconData(callback
) {
46 var canvas
= document
.createElement("canvas");
47 canvas
.style
.display
= "none";
51 img
.onload = function() {
52 console
.log('img.onload called');
53 var ctx
= canvas
.getContext("2d");
54 ctx
.drawImage(img
, 0, 0);
55 var tmp
= canvas
.toDataURL();
56 // Strip the data url prefix to just get the base64-encoded bytes.
57 cachedIcon
= tmp
.slice(tmp
.search(",")+1);
60 img
.src
= "extension/icon.png";
63 // This returns the string contents of the extension's manifest file.
64 function getManifest(alternativePath
) {
65 // Do a synchronous XHR to get the manifest.
66 var xhr
= new XMLHttpRequest();
68 alternativePath
? alternativePath
: "extension/manifest.json",
71 return xhr
.responseText
;
74 // Installs the extension with the given |installOptions|, calls
75 // |whileInstalled| and then uninstalls the extension.
76 function installAndCleanUp(installOptions
, whileInstalled
) {
78 chrome
.webstorePrivate
.beginInstallWithManifest3(
80 callbackPass(function(result
) {
84 // Now complete the installation.
85 chrome
.webstorePrivate
.completeInstall(
87 callbackPass(function(result
) {
89 assertEq(undefined, result
);
93 chrome
.test
.runWithUserGesture(callbackPass(function() {
94 chrome
.management
.uninstall(extensionId
, {}, callbackPass());