summaryrefslogtreecommitdiffstats
path: root/chrome/test
diff options
context:
space:
mode:
authormihaip@chromium.org <mihaip@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-07 01:34:10 +0000
committermihaip@chromium.org <mihaip@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-07 01:34:10 +0000
commita221ef093f07da6c5ed8334b988f23bc8c3d110e (patch)
tree3695cf9beea7bd903414e2f3e20cf7b126990be3 /chrome/test
parentcd7fa99f1c2de523077984561d38ef62188f774b (diff)
downloadchromium_src-a221ef093f07da6c5ed8334b988f23bc8c3d110e.zip
chromium_src-a221ef093f07da6c5ed8334b988f23bc8c3d110e.tar.gz
chromium_src-a221ef093f07da6c5ed8334b988f23bc8c3d110e.tar.bz2
Add link URL and success/failure callback parameters to chrome.webstore.install()
The link URL is used to select between multiple <link rel="chrome-webstore-item"> elements on the page. To keep track of callbacks, an install ID is generated at the start of each chrome.webstore.install() call, so that the browser knows which ones to invoke when an install completes. Also adds validation of install requesting URL against the item's verified domain (wasn't done until now since it wasn't testable). R=aa@chromium.org BUG=93380 Review URL: http://codereview.chromium.org/7795032 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@99889 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test')
-rw-r--r--chrome/test/data/extensions/api_test/webstore_inline_install/argument_validation.html71
-rw-r--r--chrome/test/data/extensions/api_test/webstore_inline_install/find_link.html11
-rw-r--r--chrome/test/data/extensions/api_test/webstore_inline_install/inlineinstall/detail/ecglahbcnmdpdciemllbhojghbkagdje1
-rw-r--r--chrome/test/data/extensions/api_test/webstore_inline_install/install-non-verified-domain.html38
-rw-r--r--chrome/test/data/extensions/api_test/webstore_inline_install/install.html11
5 files changed, 128 insertions, 4 deletions
diff --git a/chrome/test/data/extensions/api_test/webstore_inline_install/argument_validation.html b/chrome/test/data/extensions/api_test/webstore_inline_install/argument_validation.html
new file mode 100644
index 0000000..9b87ba1
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/webstore_inline_install/argument_validation.html
@@ -0,0 +1,71 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <link rel="chrome-webstore-item">
+</head>
+<body>
+<script>
+ function runTest(galleryUrl) {
+ var storeUrl = galleryUrl + '/detail/ecglahbcnmdpdciemllbhojghbkagdje';
+ // Link URL has to be generated dynamically in order to include the right
+ // port number. The ID corresponds to the data in the "extension" directory.
+ document.getElementsByTagName('link')[0].href = storeUrl;
+
+ function runTests(tests) {
+ var failed = false;
+ tests.forEach(function(test) {
+ if (test.shouldPass) {
+ try {
+ test.func();
+ } catch (e) {
+ alert('unexpected exception: ' + e);
+ failed = true;
+ }
+ } else {
+ try {
+ test.func();
+ alert('unexpected pass: ' + func);
+ failed = true;
+ } catch (e) {
+ // Expected exception
+ }
+ }
+ });
+
+ window.domAutomationController.send(!failed);
+ }
+
+ function shouldPass(func) {
+ return {
+ func: func,
+ shouldPass: true
+ }
+ }
+
+ function shouldFail(func) {
+ return {
+ func: func,
+ shouldPass: false
+ }
+ }
+
+ var cwi = chrome.webstore.install;
+ runTests([
+ shouldPass(function() {cwi()}),
+ shouldPass(function() {cwi(undefined)}),
+ shouldPass(function() {cwi(undefined, undefined)}),
+ shouldPass(function() {cwi(undefined, undefined, undefined)}),
+
+ shouldPass(function() {cwi(storeUrl)}),
+ shouldPass(function() {cwi(undefined, function() {})}),
+ shouldPass(function() {cwi(undefined, undefined, function() {})}),
+
+ shouldFail(function() {cwi(123)}),
+ shouldFail(function() {cwi(undefined, 123)}),
+ shouldFail(function() {cwi(undefined, undefined, 123)})
+ ]);
+ }
+</script>
+
+</body>
+</html>
diff --git a/chrome/test/data/extensions/api_test/webstore_inline_install/find_link.html b/chrome/test/data/extensions/api_test/webstore_inline_install/find_link.html
index 95710d2..6c735d7 100644
--- a/chrome/test/data/extensions/api_test/webstore_inline_install/find_link.html
+++ b/chrome/test/data/extensions/api_test/webstore_inline_install/find_link.html
@@ -7,9 +7,9 @@
var NO_LINK_EXCEPTION = 'No Chrome Web Store item link found.';
var INVALID_URL_EXCEPTION = 'Invalid Chrome Web Store item URL.';
- function checkNoLinkFound(expectedException) {
+ function checkNoLinkFound(expectedException, opt_preferredStoreUrl) {
try {
- chrome.webstore.install();
+ chrome.webstore.install(opt_preferredStoreUrl);
console.log('Exception should have been thrown');
window.domAutomationController.send(false);
return;
@@ -55,6 +55,13 @@
galleryUrl + '/detail/mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm?foo=bar';
checkNoLinkFound(INVALID_URL_EXCEPTION);
+ // Non-existent preferred link.
+ linkNode.rel = 'chrome-webstore-item';
+ linkNode.href = galleryUrl + '/detail/mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm';
+ checkNoLinkFound(
+ NO_LINK_EXCEPTION,
+ galleryUrl + '/detail/iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii');
+
// Successful installation is tested elsewhere
window.domAutomationController.send(true);
}
diff --git a/chrome/test/data/extensions/api_test/webstore_inline_install/inlineinstall/detail/ecglahbcnmdpdciemllbhojghbkagdje b/chrome/test/data/extensions/api_test/webstore_inline_install/inlineinstall/detail/ecglahbcnmdpdciemllbhojghbkagdje
index 1814b1e..df08f3b 100644
--- a/chrome/test/data/extensions/api_test/webstore_inline_install/inlineinstall/detail/ecglahbcnmdpdciemllbhojghbkagdje
+++ b/chrome/test/data/extensions/api_test/webstore_inline_install/inlineinstall/detail/ecglahbcnmdpdciemllbhojghbkagdje
@@ -3,5 +3,6 @@
"users": "371,674",
"average_rating": 4.36,
"rating_count": 788,
+ "verified_site": "app.com",
"manifest": "{\"name\":\"Inline Install Test Extension\",\"version\":\"0.1\",\"icons\":{\"128\":\"icon.png\"},\"permissions\":[\"tabs\"]}"
}
diff --git a/chrome/test/data/extensions/api_test/webstore_inline_install/install-non-verified-domain.html b/chrome/test/data/extensions/api_test/webstore_inline_install/install-non-verified-domain.html
new file mode 100644
index 0000000..b40f4fb
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/webstore_inline_install/install-non-verified-domain.html
@@ -0,0 +1,38 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <link rel="chrome-webstore-item">
+</head>
+<body>
+<script>
+ function runTest(galleryUrl) {
+ // Link URL has to be generated dynamically in order to include the right
+ // port number. The ID corresponds to the data in the "extension" directory.
+ document.getElementsByTagName('link')[0].href =
+ galleryUrl + '/detail/ecglahbcnmdpdciemllbhojghbkagdje';
+
+ try {
+ chrome.webstore.install(
+ undefined,
+ function() {
+ console.log('did not expect install success');
+ window.domAutomationController.send(false);
+ },
+ function(error) {
+ if (error.indexOf('verified site') != -1) {
+ window.domAutomationController.send(true);
+ } else {
+ console.log('Unexpected error: ' + error);
+ window.domAutomationController.send(false);
+ }
+ });
+ } catch (e) {
+ console.log('Unexpected exception: ' + e);
+ window.domAutomationController.send(false);
+ throw e;
+ }
+ }
+</script>
+
+</body>
+</html>
diff --git a/chrome/test/data/extensions/api_test/webstore_inline_install/install.html b/chrome/test/data/extensions/api_test/webstore_inline_install/install.html
index 73121f2..de32da4 100644
--- a/chrome/test/data/extensions/api_test/webstore_inline_install/install.html
+++ b/chrome/test/data/extensions/api_test/webstore_inline_install/install.html
@@ -12,12 +12,19 @@
galleryUrl + '/detail/ecglahbcnmdpdciemllbhojghbkagdje';
try {
- chrome.webstore.install();
+ chrome.webstore.install(
+ undefined,
+ function() {
+ window.domAutomationController.send(true);
+ },
+ function(error) {
+ console.log('Unexpected error: ' + error);
+ window.domAutomationController.send(false);
+ });
} catch (e) {
window.domAutomationController.send(false);
throw e;
}
- window.domAutomationController.send(true);
}
</script>