Index: chrome/browser/extensions/extension_nacl_browsertest.cc |
=================================================================== |
--- chrome/browser/extensions/extension_nacl_browsertest.cc (revision 0) |
+++ chrome/browser/extensions/extension_nacl_browsertest.cc (revision 0) |
@@ -0,0 +1,123 @@ |
+// 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 { |
+ |
+// 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: |
+ // Install the extension from a .crx file; this allows us to make the |
+ // extension appear to be from the Chrome Webstore. |
+ const Extension* InstallCrx(bool from_webstore) { |
+ ExtensionService* service = browser()->profile()->GetExtensionService(); |
+ |
+ scoped_refptr<CrxInstaller> installer(service->MakeCrxInstaller(NULL)); |
+ installer->set_allow_silent_install(true); |
+ installer->set_is_gallery_install(from_webstore); |
+ |
+ FilePath crx_path = test_data_dir_.AppendASCII("native_client.crx"); |
+ installer->InstallCrx(crx_path); |
+ WaitForExtensionLoad(); |
+ |
+ const Extension* extension = |
+ service->GetExtensionById("clnidlieolioaicmfgfjefgglgdbkgfl", false); |
+ CHECK(extension); |
+ return extension; |
+ } |
+ |
+ // Install the extension as a component; component extensions can use |
+ // native client too. |
+ const Extension* InstallAsComponent() { |
+ FilePath file_path = test_data_dir_.AppendASCII("native_client"); |
+ LoadExtensionAsComponent(file_path); |
+ |
+ ExtensionService* service = browser()->profile()->GetExtensionService(); |
+ const Extension* extension = |
+ service->GetExtensionById("bjjcibdiodkkeanflmiijlcfieiemced", false); |
+ CHECK(extension); |
+ return extension; |
+ } |
+ |
+ bool IsEmbeddedPluginCreated(TabContents* tab_contents) { |
+ bool plugin_created = false; |
+ CHECK(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
Paweł Hajdan Jr.
2011/08/05 23:18:36
Do you like your tests to be DISABLED? If not, ple
bbudge
2011/08/09 05:26:50
Done.
|
+ tab_contents->render_view_host(), L"", |
+ L"window.domAutomationController.send(EmbeddedPluginCreated());", |
+ &plugin_created)); |
+ return plugin_created; |
+ } |
+ |
+ bool IsContentHandlerPluginCreated(TabContents* tab_contents) { |
+ bool plugin_created = false; |
+ CHECK(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
Paweł Hajdan Jr.
2011/08/05 23:18:36
Same here.
bbudge
2011/08/09 05:26:50
Done.
|
+ tab_contents->render_view_host(), L"", |
+ L"window.domAutomationController.send(ContentHandlerPluginCreated());", |
+ &plugin_created)); |
+ return 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 = InstallCrx(true); |
+ |
+ ui_test_utils::NavigateToURL( |
+ browser(), extension->GetResourceURL("test.html")); |
+ TabContents* tab_contents = browser()->GetSelectedTabContents(); |
+ |
+ EXPECT_TRUE(IsEmbeddedPluginCreated(tab_contents)); |
+ EXPECT_TRUE(IsContentHandlerPluginCreated(tab_contents)); |
+} |
+ |
+// 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 = InstallCrx(false); |
+ |
+ ui_test_utils::NavigateToURL( |
+ browser(), extension->GetResourceURL("test.html")); |
+ TabContents* tab_contents = browser()->GetSelectedTabContents(); |
+ |
+ EXPECT_FALSE(IsEmbeddedPluginCreated(tab_contents)); |
+ EXPECT_FALSE(IsContentHandlerPluginCreated(tab_contents)); |
+} |
+ |
+// 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 = InstallAsComponent(); |
+ |
+ ui_test_utils::NavigateToURL( |
+ browser(), extension->GetResourceURL("test.html")); |
+ TabContents* tab_contents = browser()->GetSelectedTabContents(); |
+ |
+ EXPECT_TRUE(IsEmbeddedPluginCreated(tab_contents)); |
+ EXPECT_TRUE(IsContentHandlerPluginCreated(tab_contents)); |
+} |
+ |
+} // namespace |
+ |
Property changes on: chrome\browser\extensions\extension_nacl_browsertest.cc |
___________________________________________________________________ |
Added: svn:eol-style |
+ LF |