Log:
Merge 65722 - 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
TBR=asar...@chromium.org
Review URL: http://codereview.chromium.org/4837003
Added:
branches/552/src/chrome/test/data/extensions/api_test/extension_gallery_install/common.js
- copied unchanged from r65722, /trunk/src/chrome/test/data/extensions/api_test/extension_gallery_install/common.js
branches/552/src/chrome/test/data/extensions/api_test/extension_gallery_install/complete_without_begin.html
- copied unchanged from r65722, /trunk/src/chrome/test/data/extensions/api_test/extension_gallery_install/complete_without_begin.html
branches/552/src/chrome/test/data/extensions/api_test/extension_gallery_install/invalid_begin.html
- copied unchanged from r65722, /trunk/src/chrome/test/data/extensions/api_test/extension_gallery_install/invalid_begin.html
branches/552/src/chrome/test/data/extensions/api_test/extension_gallery_install/no_user_gesture.html
- copied unchanged from r65722, /trunk/src/chrome/test/data/extensions/api_test/extension_gallery_install/no_user_gesture.html
Modified:
branches/552/src/chrome/browser/extensions/crx_installer_browsertest.cc
branches/552/src/chrome/browser/extensions/extension_gallery_install_apitest.cc
branches/552/src/chrome/common/extensions/api/extension_api.json
branches/552/src/chrome/test/data/extensions/api_test/extension_gallery_install/test.html
Modified: branches/552/src/chrome/browser/extensions/crx_installer_browsertest.cc
==============================================================================
--- branches/552/src/chrome/browser/extensions/crx_installer_browsertest.cc (original)
+++ branches/552/src/chrome/browser/extensions/crx_installer_browsertest.cc Thu Nov 11 19:48:59 2010
@@ -55,6 +55,7 @@
mock_install_ui /* ownership transferred */));
installer->set_allow_silent_install(true);
+ installer->set_is_gallery_install(true);
CrxInstaller::SetWhitelistedInstallId(id);
FilePath crx_path = test_data_dir_.AppendASCII(crx_relpath);
@@ -69,8 +70,9 @@
// A regular extension should give no prompt.
EXPECT_FALSE(DidWhitelistInstallPrompt("good.crx",
"ldnnhddmnhbkjipkidpdiheffobcpfmf"));
-
+#if !defined(OS_CHROMEOS)
// An extension with NPAPI should give a prompt.
EXPECT_TRUE(DidWhitelistInstallPrompt("uitest/plugins.crx",
"hdgllgikmikobbofgnabhfimcfoopgnd"));
+#endif // !defined(OS_CHROMEOS)
}
Modified: branches/552/src/chrome/browser/extensions/extension_gallery_install_apitest.cc
==============================================================================
--- branches/552/src/chrome/browser/extensions/extension_gallery_install_apitest.cc (original)
+++ branches/552/src/chrome/browser/extensions/extension_gallery_install_apitest.cc Thu Nov 11 19:48:59 2010
@@ -16,11 +16,27 @@
command_line->AppendSwitchASCII(switches::kAppsGalleryURL,
"http://www.example.com");
}
+
+ bool RunInstallTest(const std::string& page) {
+ std::string base_url = base::StringPrintf(
+ "http://www.example.com:%u/files/extensions/",
+ test_server()->host_port_pair().port());
+
+ std::string testing_install_base_url = base_url;
+ testing_install_base_url += "good.crx";
+ CompleteInstallFunction::SetTestingInstallBaseUrl(
+ testing_install_base_url.c_str());
+
+ std::string page_url = base_url;
+ page_url += "api_test/extension_gallery_install/" + page;
+
+ return RunPageTest(page_url.c_str());
+ }
};
// http://crbug.com/55642 - failing on XP.
#if defined (OS_WIN)
-#define MAYBE_InstallAndUninstall DISABLED_InstallAndUninstall
+#define MAYBE_InstallAndUninstall FLAKY_InstallAndUninstall
#else
#define MAYBE_InstallAndUninstall InstallAndUninstall
#endif
@@ -29,15 +45,11 @@
host_resolver()->AddRule("www.example.com", "127.0.0.1");
ASSERT_TRUE(test_server()->Start());
- std::string base_url = base::StringPrintf(
- "http://www.example.com:%u/files/extensions/",
- test_server()->host_port_pair().port());
-
- std::string testing_install_base_url = base_url;
- testing_install_base_url += "good.crx";
- InstallFunction::SetTestingInstallBaseUrl(testing_install_base_url.c_str());
-
- std::string page_url = base_url;
- page_url += "api_test/extension_gallery_install/test.html";
- ASSERT_TRUE(RunPageTest(page_url.c_str()));
+ BeginInstallFunction::SetIgnoreUserGestureForTests(true);
+ ASSERT_TRUE(RunInstallTest("test.html"));
+ ASSERT_TRUE(RunInstallTest("complete_without_begin.html"));
+ ASSERT_TRUE(RunInstallTest("invalid_begin.html"));
+
+ BeginInstallFunction::SetIgnoreUserGestureForTests(false);
+ ASSERT_TRUE(RunInstallTest("no_user_gesture.html"));
}
Modified: branches/552/src/chrome/common/extensions/api/extension_api.json
==============================================================================
--- branches/552/src/chrome/common/extensions/api/extension_api.json (original)
+++ branches/552/src/chrome/common/extensions/api/extension_api.json Thu Nov 11 19:48:59 2010
@@ -4119,6 +4119,40 @@
]
},
{
+ "name": "beginInstall",
+ "description": "Initiates the install process for the given extension id",
+ "parameters": [
+ {
+ "name": "expected_id",
+ "type": "string",
+ "description": "The id of the extension to be installled. Must be called during a user gesture."
+ },
+ {
+ "name": "callback",
+ "type": "function",
+ "optional": "true",
+ "parameters": []
+ }
+ ]
+ },
+ {
+ "name": "completeInstall",
+ "description": "",
+ "parameters": [
+ {
+ "name": "expected_id",
+ "type": "string",
+ "description": "The id of the extension to be installled. This should match a previous call to beginInstall."
+ },
+ {
+ "name": "callback",
+ "type": "function",
+ "optional": "true",
+ "parameters": []
+ }
+ ]
+ },
+ {
"name": "getBrowserLogin",
"description": "Returns the logged-in sync user login if there is one, or the empty string otherwise.",
"parameters": [
Modified: branches/552/src/chrome/test/data/extensions/api_test/extension_gallery_install/test.html
==============================================================================
--- branches/552/src/chrome/test/data/extensions/api_test/extension_gallery_install/test.html (original)
+++ branches/552/src/chrome/test/data/extensions/api_test/extension_gallery_install/test.html Thu Nov 11 19:48:59 2010
@@ -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);
+ 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);
-
- // Now uninstall
- chrome.management.onUninstalled.addListener(function() {
- // And check that it's gone.
- checkInstalled(function(installed) {
- chrome.test.assertEq(false, installed);
-
- chrome.test.succeed();
- });
- });
-
- console.log("Uninstalling...");
- chrome.management.uninstall(id, function() {
- chrome.test.assertNoLastError();
- });
+ // Begin installing.
+ chrome.webstorePrivate.beginInstall(extension_id, function() {
+ assertNoLastError();
+
+ // Now complete the installation.
+ chrome.webstorePrivate.completeInstall(extension_id, function() {
+ assertNoLastError();
});
});
- chrome.webstorePrivate.install(id, function() {
- chrome.test.assertNoLastError();
- });
- console.log("Installing...");
});
</script>