diff options
author | bbudge@chromium.org <bbudge@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-11 22:21:48 +0000 |
---|---|---|
committer | bbudge@chromium.org <bbudge@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-11 22:21:48 +0000 |
commit | cefa749d026c083bc3fd0e6977dbec1890185c4a (patch) | |
tree | 980397623f69454312434a277a9ce907706db806 | |
parent | 70e8d7456744d806ef4a6c4b78088282eacbdd1b (diff) | |
download | chromium_src-cefa749d026c083bc3fd0e6977dbec1890185c4a.zip chromium_src-cefa749d026c083bc3fd0e6977dbec1890185c4a.tar.gz chromium_src-cefa749d026c083bc3fd0e6977dbec1890185c4a.tar.bz2 |
Add tests for CWS restriction of NaCl plugin.
BUG=none
TEST=this
Review URL: http://codereview.chromium.org/7488060
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@96467 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/extensions/extension_browsertest.cc | 13 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_browsertest.h | 8 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_nacl_browsertest.cc | 113 | ||||
-rw-r--r-- | chrome/chrome_tests.gypi | 1 | ||||
-rw-r--r-- | chrome/test/data/extensions/native_client/manifest.json | 11 | ||||
-rw-r--r-- | chrome/test/data/extensions/native_client/test.html | 56 |
6 files changed, 198 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 + diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 949963b..2701a79 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -2522,6 +2522,7 @@ 'browser/extensions/extension_messages_browsertest.cc', 'browser/extensions/extension_metrics_apitest.cc', 'browser/extensions/extension_module_apitest.cc', + 'browser/extensions/extension_nacl_browsertest.cc', 'browser/extensions/extension_omnibox_apitest.cc', 'browser/extensions/extension_override_apitest.cc', 'browser/extensions/extension_processes_apitest.cc', diff --git a/chrome/test/data/extensions/native_client/manifest.json b/chrome/test/data/extensions/native_client/manifest.json new file mode 100644 index 0000000..3138711 --- /dev/null +++ b/chrome/test/data/extensions/native_client/manifest.json @@ -0,0 +1,11 @@ +{ + "key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCp40PYAXfSDlzCW1f5MDzRW64h0YhgV7MX8Frem0vO1ZAlq/mlUO4KxwkF2AZliFScO4Cc3CYpO6jpHXwz27tUwaN46C/LzYO7u/kb2piOep8gClvZ64EMnDv5PIoIeZlOJhkpnfs/5FbQt5sqT9avXX7YfLCLBJBql0U/V5615wIDAQAB", + "name": "NaClExtensionTest", + "version": "0.1", + "description": "Tests Chrome Webstore restriction for Native Client.", + "permissions": ["nativeclient"], + "nacl_modules": [{ + "path": "dummy.nmf", + "mime_type": "application/pdf" + }] +} diff --git a/chrome/test/data/extensions/native_client/test.html b/chrome/test/data/extensions/native_client/test.html new file mode 100644 index 0000000..f2180c7 --- /dev/null +++ b/chrome/test/data/extensions/native_client/test.html @@ -0,0 +1,56 @@ +<html> +<!-- +This test file causes Chrome to attempt to create the NaCl plugin as a simple +embed and as a content type handler. The script allows the test to check if +the plugin was created or blocked in either case. +--> +<head> +<title>Native Client CWS Restriction</title> + +<script> + var embedded_event; + var content_handler_event; + + function setListeners(body_element) { + var eventListener = function(e) { + var target_element = e.target; + if (target_element.className != 'naclModule') + return; + + var element_id = target_element.id; + if (element_id == 'embedded') + embedded_event = e.type; + else if (element_id == 'content_handler') + content_handler_event = e.type; + } + body_element.addEventListener('loadstart', eventListener, true); + body_element.addEventListener('error', eventListener, true); + } + + function EmbeddedPluginCreated() { + return embedded_event != undefined; + } + + function ContentHandlerPluginCreated() { + return content_handler_event != undefined; + } + +</script> + +</head> +<body> + <embed id="embedded" + class="naclModule" + type="application/x-nacl" + src="dummy.nmf"> + </embed> + <embed id="content_handler" + class="naclModule" + type="application/pdf" + src="test.pdf"> + </embed> + <script> + setListeners(document.body); + </script> +</body> +</html> |