summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/extensions/extension_browsertest.cc13
-rw-r--r--chrome/browser/extensions/extension_browsertest.h8
-rw-r--r--chrome/browser/extensions/extension_nacl_browsertest.cc113
3 files changed, 130 insertions, 4 deletions
diff --git a/chrome/browser/extensions/extension_browsertest.cc b/chrome/browser/extensions/extension_browsertest.cc
index ec64fdb..ae2d148 100644
--- a/chrome/browser/extensions/extension_browsertest.cc
+++ b/chrome/browser/extensions/extension_browsertest.cc
@@ -214,19 +214,27 @@ class MockAutoConfirmExtensionInstallUI : public ExtensionInstallUI {
}
};
+bool ExtensionBrowserTest::InstallExtensionFromWebstore(const FilePath& path,
+ int expected_change) {
+ return InstallOrUpdateExtension("", path, INSTALL_UI_TYPE_NONE,
+ expected_change, browser()->profile(),
+ true);
+}
+
bool ExtensionBrowserTest::InstallOrUpdateExtension(const std::string& id,
const FilePath& path,
InstallUIType ui_type,
int expected_change) {
return InstallOrUpdateExtension(id, path, ui_type, expected_change,
- browser()->profile());
+ browser()->profile(), false);
}
bool ExtensionBrowserTest::InstallOrUpdateExtension(const std::string& id,
const FilePath& path,
InstallUIType ui_type,
int expected_change,
- Profile* profile) {
+ Profile* profile,
+ bool from_webstore) {
ExtensionService* service = profile->GetExtensionService();
service->set_show_extensions_prompts(false);
size_t num_before = service->extensions()->size();
@@ -260,6 +268,7 @@ bool ExtensionBrowserTest::InstallOrUpdateExtension(const std::string& id,
scoped_refptr<CrxInstaller> installer(
service->MakeCrxInstaller(install_ui));
installer->set_expected_id(id);
+ installer->set_is_gallery_install(from_webstore);
installer->InstallCrx(crx_path);
ui_test_utils::RunMessageLoop();
diff --git a/chrome/browser/extensions/extension_browsertest.h b/chrome/browser/extensions/extension_browsertest.h
index 5f21f85..02ff5c3 100644
--- a/chrome/browser/extensions/extension_browsertest.h
+++ b/chrome/browser/extensions/extension_browsertest.h
@@ -51,6 +51,9 @@ class ExtensionBrowserTest
expected_change);
}
+ // Installs extension as if it came from the Chrome Webstore.
+ bool InstallExtensionFromWebstore(const FilePath& path, int expected_change);
+
// Same as above but passes an id to CrxInstaller and does not allow a
// privilege increase.
bool UpdateExtension(const std::string& id, const FilePath& path,
@@ -69,7 +72,7 @@ class ExtensionBrowserTest
int expected_change,
Profile* profile) {
return InstallOrUpdateExtension("", path, INSTALL_UI_TYPE_AUTO_CONFIRM,
- expected_change, profile);
+ expected_change, profile, false);
}
// Begins install process but simulates a user cancel.
@@ -140,7 +143,8 @@ class ExtensionBrowserTest
bool InstallOrUpdateExtension(const std::string& id, const FilePath& path,
InstallUIType ui_type,
int expected_change,
- Profile* profile);
+ Profile* profile,
+ bool from_webstore);
bool WaitForExtensionHostsToLoad();
diff --git a/chrome/browser/extensions/extension_nacl_browsertest.cc b/chrome/browser/extensions/extension_nacl_browsertest.cc
new file mode 100644
index 0000000..9218a27
--- /dev/null
+++ b/chrome/browser/extensions/extension_nacl_browsertest.cc
@@ -0,0 +1,113 @@
+// Copyright (c) 2011 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.
+
+#include "base/command_line.h"
+#include "base/utf_string_conversions.h"
+#include "chrome/browser/extensions/crx_installer.h"
+#include "chrome/browser/extensions/extension_browsertest.h"
+#include "chrome/browser/extensions/extension_service.h"
+#include "chrome/browser/prefs/pref_service.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/common/chrome_switches.h"
+#include "chrome/common/pref_names.h"
+#include "chrome/test/base/ui_test_utils.h"
+#include "content/browser/tab_contents/tab_contents.h"
+
+namespace {
+
+const char* kExtensionId = "bjjcibdiodkkeanflmiijlcfieiemced";
+
+// This class tests that the Native Client plugin is blocked unless the
+// .nexe is part of an extension from the Chrome Webstore.
+class NaClExtensionTest : public ExtensionBrowserTest {
+ public:
+ NaClExtensionTest() {
+ EnableDOMAutomation();
+ }
+
+ protected:
+ enum InstallType {
+ INSTALL_TYPE_COMPONENT,
+ INSTALL_TYPE_FROM_WEBSTORE,
+ INSTALL_TYPE_NON_WEBSTORE,
+ };
+
+ const Extension* InstallExtension(InstallType install_type) {
+ FilePath file_path = test_data_dir_.AppendASCII("native_client");
+ ExtensionService* service = browser()->profile()->GetExtensionService();
+ const Extension* extension = NULL;
+ switch (install_type) {
+ case INSTALL_TYPE_COMPONENT:
+ if (LoadExtensionAsComponent(file_path)) {
+ extension = service->GetExtensionById(kExtensionId, false);
+ }
+ break;
+
+ case INSTALL_TYPE_FROM_WEBSTORE:
+ if (InstallExtensionFromWebstore(file_path, 1)) {
+ extension = service->GetExtensionById(last_loaded_extension_id_,
+ false);
+ }
+ break;
+
+ case INSTALL_TYPE_NON_WEBSTORE:
+ if (ExtensionBrowserTest::InstallExtension(file_path, 1)) {
+ extension = service->GetExtensionById(last_loaded_extension_id_,
+ false);
+ }
+ break;
+ }
+ return extension;
+ }
+
+ void CheckPluginsCreated(const Extension* extension, bool should_create) {
+ ui_test_utils::NavigateToURL(browser(),
+ extension->GetResourceURL("test.html"));
+ bool embedded_plugin_created = false;
+ bool content_handler_plugin_created = false;
+ TabContents* tab_contents = browser()->GetSelectedTabContents();
+ ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
+ tab_contents->render_view_host(), L"",
+ L"window.domAutomationController.send(EmbeddedPluginCreated());",
+ &embedded_plugin_created));
+ ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
+ tab_contents->render_view_host(), L"",
+ L"window.domAutomationController.send(ContentHandlerPluginCreated());",
+ &content_handler_plugin_created));
+
+ EXPECT_EQ(should_create, embedded_plugin_created);
+ EXPECT_EQ(should_create, content_handler_plugin_created);
+ }
+};
+
+// Test that the NaCl plugin isn't blocked for Webstore extensions.
+IN_PROC_BROWSER_TEST_F(NaClExtensionTest, WebStoreExtension) {
+ ASSERT_TRUE(test_server()->Start());
+
+ const Extension* extension = InstallExtension(INSTALL_TYPE_FROM_WEBSTORE);
+ ASSERT_TRUE(extension);
+ CheckPluginsCreated(extension, true);
+}
+
+// Test that the NaCl plugin is blocked for non-Webstore extensions.
+IN_PROC_BROWSER_TEST_F(NaClExtensionTest, NonWebStoreExtension) {
+ ASSERT_TRUE(test_server()->Start());
+
+ const Extension* extension = InstallExtension(INSTALL_TYPE_NON_WEBSTORE);
+ ASSERT_TRUE(extension);
+ CheckPluginsCreated(extension, false);
+}
+
+// Test that the NaCl plugin isn't blocked for component extensions.
+IN_PROC_BROWSER_TEST_F(NaClExtensionTest, ComponentExtension) {
+ ASSERT_TRUE(test_server()->Start());
+
+ const Extension* extension = InstallExtension(INSTALL_TYPE_COMPONENT);
+ ASSERT_TRUE(extension);
+ CheckPluginsCreated(extension, true);
+}
+
+} // namespace
+