| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // The id of an extension we're using for install tests. | 5 // The id of an extension we're using for install tests. |
| 6 var extensionId = "enfkhcelefdadlmkffamgdlgplcionje"; | 6 var extensionId = "enfkhcelefdadlmkffamgdlgplcionje"; |
| 7 | 7 |
| 8 // The id of an app we're using for install tests. | 8 // The id of an app we're using for install tests. |
| 9 var appId = "iladmdjkfniedhfhcfoefgojhgaiaccc"; | 9 var appId = "iladmdjkfniedhfhcfoefgojhgaiaccc"; |
| 10 | 10 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 checkItemInstalled(extensionId, callback); | 34 checkItemInstalled(extensionId, callback); |
| 35 } | 35 } |
| 36 | 36 |
| 37 var cachedIcon = null; | 37 var cachedIcon = null; |
| 38 var img = null; | 38 var img = null; |
| 39 | 39 |
| 40 // This returns the base64-encoded content of the extension's image. | 40 // This returns the base64-encoded content of the extension's image. |
| 41 function getIconData(callback) { | 41 function getIconData(callback) { |
| 42 if (cachedIcon) { | 42 if (cachedIcon) { |
| 43 callback(cachedIcon); | 43 callback(cachedIcon); |
| 44 return; |
| 44 } | 45 } |
| 45 var canvas = document.createElement("canvas"); | 46 var canvas = document.createElement("canvas"); |
| 46 canvas.style.display = "none"; | 47 canvas.style.display = "none"; |
| 47 canvas.width = 128; | 48 canvas.width = 128; |
| 48 canvas.height = 128; | 49 canvas.height = 128; |
| 49 img = new Image(); | 50 img = new Image(); |
| 50 img.onload = function() { | 51 img.onload = function() { |
| 51 console.log('img.onload called'); | 52 console.log('img.onload called'); |
| 52 var ctx = canvas.getContext("2d"); | 53 var ctx = canvas.getContext("2d"); |
| 53 ctx.drawImage(img, 0, 0); | 54 ctx.drawImage(img, 0, 0); |
| 54 var tmp = canvas.toDataURL(); | 55 var tmp = canvas.toDataURL(); |
| 55 // Strip the data url prefix to just get the base64-encoded bytes. | 56 // Strip the data url prefix to just get the base64-encoded bytes. |
| 56 cachedIcon = tmp.slice(tmp.search(",")+1); | 57 cachedIcon = tmp.slice(tmp.search(",")+1); |
| 57 callback(cachedIcon); | 58 callback(cachedIcon); |
| 58 }; | 59 }; |
| 59 img.src = "extension/icon.png"; | 60 img.src = "extension/icon.png"; |
| 60 } | 61 } |
| 61 | 62 |
| 62 // This returns the string contents of the extension's manifest file. | 63 // This returns the string contents of the extension's manifest file. |
| 63 function getManifest(alternativePath) { | 64 function getManifest(alternativePath) { |
| 64 // Do a synchronous XHR to get the manifest. | 65 // Do a synchronous XHR to get the manifest. |
| 65 var xhr = new XMLHttpRequest(); | 66 var xhr = new XMLHttpRequest(); |
| 66 xhr.open("GET", | 67 xhr.open("GET", |
| 67 alternativePath ? alternativePath : "extension/manifest.json", | 68 alternativePath ? alternativePath : "extension/manifest.json", |
| 68 false); | 69 false); |
| 69 xhr.send(null); | 70 xhr.send(null); |
| 70 return xhr.responseText; | 71 return xhr.responseText; |
| 71 } | 72 } |
| 73 |
| 74 // Installs the extension with the given |installOptions|, calls |
| 75 // |whileInstalled| and then uninstalls the extension. |
| 76 function installAndCleanUp(installOptions, whileInstalled) { |
| 77 // Begin installing. |
| 78 chrome.webstorePrivate.beginInstallWithManifest3( |
| 79 installOptions, |
| 80 callbackPass(function(result) { |
| 81 assertNoLastError(); |
| 82 assertEq("", result); |
| 83 |
| 84 // Now complete the installation. |
| 85 chrome.webstorePrivate.completeInstall( |
| 86 extensionId, |
| 87 callbackPass(function(result) { |
| 88 assertNoLastError(); |
| 89 assertEq(undefined, result); |
| 90 |
| 91 whileInstalled(); |
| 92 |
| 93 chrome.management.uninstall(extensionId, {}, callbackPass()); |
| 94 })); |
| 95 })); |
| 96 } |
| OLD | NEW |