diff options
author | asargent@chromium.org <asargent@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-10 22:59:30 +0000 |
---|---|---|
committer | asargent@chromium.org <asargent@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-10 22:59:30 +0000 |
commit | b1f04cca79abf21ec97b227caf95eff9871a044a (patch) | |
tree | e591cb932baa005e04a1ce31a72efe9a9350be03 /chrome/test | |
parent | 9246de382277a2700c0d1e9f1305591c31a316d0 (diff) | |
download | chromium_src-b1f04cca79abf21ec97b227caf95eff9871a044a.zip chromium_src-b1f04cca79abf21ec97b227caf95eff9871a044a.tar.gz chromium_src-b1f04cca79abf21ec97b227caf95eff9871a044a.tar.bz2 |
Split the private webstore install API into two parts.
The first part, beginInstall, must be called during a user gesture. The second
part should supply a matching id and actually starts the download and install
process.
BUG=61954
TEST=Requires webstore server side changes before it can be fully tested. For
now, you can test that visiting the webstore and running something like the
following command in the javascript console generates an error:
chrome.webstorePrivate.beginInstall("mihcahmgecmbnbcchbopgniflfhgnkff")
Review URL: http://codereview.chromium.org/4727001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@65722 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test')
5 files changed, 64 insertions, 48 deletions
diff --git a/chrome/test/data/extensions/api_test/extension_gallery_install/common.js b/chrome/test/data/extensions/api_test/extension_gallery_install/common.js new file mode 100644 index 0000000..c9d1687 --- /dev/null +++ b/chrome/test/data/extensions/api_test/extension_gallery_install/common.js @@ -0,0 +1,20 @@ +// Copyright (c) 2010 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 extension_id = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; + +var assertEq = chrome.test.assertEq; +var assertNoLastError = chrome.test.assertNoLastError; +var succeed = chrome.test.succeed; + +// Calls |callback| with true/false indicating whether an item with an id of +// extension_id is installed. +function checkInstalled(callback) { + chrome.management.getAll(function(extensions) { + var found = false; + callback(extensions.some(function(ext) { + return ext.id == extension_id; + })); + }); +} diff --git a/chrome/test/data/extensions/api_test/extension_gallery_install/complete_without_begin.html b/chrome/test/data/extensions/api_test/extension_gallery_install/complete_without_begin.html new file mode 100644 index 0000000..1907619 --- /dev/null +++ b/chrome/test/data/extensions/api_test/extension_gallery_install/complete_without_begin.html @@ -0,0 +1,11 @@ +<script src="common.js"></script> +<script> +// This tests that a call to completeInstall without a previous call to begin +// generates an error. +chrome.webstorePrivate.completeInstall(extension_id, function() { + var expected_error = extension_id + + " does not match a previous call to beginInstall"; + chrome.test.assertEq(chrome.extension.lastError.message, expected_error); + chrome.test.succeed(); +}); +</script> diff --git a/chrome/test/data/extensions/api_test/extension_gallery_install/invalid_begin.html b/chrome/test/data/extensions/api_test/extension_gallery_install/invalid_begin.html new file mode 100644 index 0000000..7c2d5d7 --- /dev/null +++ b/chrome/test/data/extensions/api_test/extension_gallery_install/invalid_begin.html @@ -0,0 +1,8 @@ +<script src="common.js"></script> +<script> +// This tests that an invalid id passed to beginInstall generates an error. +chrome.webstorePrivate.beginInstall("some invalid id", function() { + assertEq(chrome.extension.lastError.message, "Invalid id"); + succeed(); +}); +</script> diff --git a/chrome/test/data/extensions/api_test/extension_gallery_install/no_user_gesture.html b/chrome/test/data/extensions/api_test/extension_gallery_install/no_user_gesture.html new file mode 100644 index 0000000..4aa5714 --- /dev/null +++ b/chrome/test/data/extensions/api_test/extension_gallery_install/no_user_gesture.html @@ -0,0 +1,10 @@ +<script src="common.js"></script> +<script> +// We expect that this test is called outside of a user gesture, which should +// generate an error. +chrome.webstorePrivate.beginInstall(extension_id, function() { + assertEq(chrome.extension.lastError.message, + "This function must be called during a user gesture"); + succeed(); +}); +</script> diff --git a/chrome/test/data/extensions/api_test/extension_gallery_install/test.html b/chrome/test/data/extensions/api_test/extension_gallery_install/test.html index 13acc1f..b3ced6e 100644 --- a/chrome/test/data/extensions/api_test/extension_gallery_install/test.html +++ b/chrome/test/data/extensions/api_test/extension_gallery_install/test.html @@ -1,58 +1,25 @@ +<script src="common.js"></script> <script> -// This tests that the management install and uninstall functions work -// properly when called by the gallery. Additionally, it implicitly tests -// that the install() function, when called from the gallery, avoids the -// dangerous download prompt and the extension permissions install prompt. -// If either were to appear, this test wouldn't complete. -// Note that for the purposes of this test the gallery url is "www.a.com" -// which is set in extension_gallery_install_apitest.cc. +// This tests the webstorePrivate beginInstall and completeInstall functions. -var id = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; - -function checkInstalled(callback) { - chrome.management.getAll(function(extensions) { - var found = false; - extensions.forEach(function(extension) { - if (id == extension.id) - found = true; - }); - - callback(found); - }); -} +// Register a listener for when the install is completed. +chrome.management.onInstalled.addListener(function(info) { + assertEq(info.id, extension_id); + succeed(); +}); -// Make sure our "gallery" extension isn't yet installed. +// Make sure our extension isn't yet installed. checkInstalled(function(installed) { - chrome.test.assertEq(false, installed); - - // Install "gallery" extensions. - chrome.management.onInstalled.addListener(function(info) { - chrome.test.assertEq(id, info.id); - console.log("Installed " + info.id); - - // Double check it is installed. - checkInstalled(function(installed) { - chrome.test.assertEq(true, installed); + assertEq(false, installed); - // Now uninstall - chrome.management.onUninstalled.addListener(function() { - // And check that it's gone. - checkInstalled(function(installed) { - chrome.test.assertEq(false, installed); - - chrome.test.succeed(); - }); - }); + // Begin installing. + chrome.webstorePrivate.beginInstall(extension_id, function() { + assertNoLastError(); - console.log("Uninstalling..."); - chrome.management.uninstall(id, function() { - chrome.test.assertNoLastError(); - }); + // Now complete the installation. + chrome.webstorePrivate.completeInstall(extension_id, function() { + assertNoLastError(); }); }); - chrome.webstorePrivate.install(id, function() { - chrome.test.assertNoLastError(); - }); - console.log("Installing..."); }); </script> |