diff options
Diffstat (limited to 'chrome/browser/extensions/extension_nacl_browsertest.cc')
-rw-r--r-- | chrome/browser/extensions/extension_nacl_browsertest.cc | 113 |
1 files changed, 113 insertions, 0 deletions
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 + |