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,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 { |
+ |
+// 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: |
+ void CheckPluginsCreated(TabContents* tab_contents, |
+ bool* embedded_plugin, |
+ bool* content_handler_plugin) { |
+ ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
+ tab_contents->render_view_host(), L"", |
+ L"window.domAutomationController.send(EmbeddedPluginCreated());", |
+ embedded_plugin)); |
+ ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
+ tab_contents->render_view_host(), L"", |
+ L"window.domAutomationController.send(ContentHandlerPluginCreated());", |
+ content_handler_plugin)); |
+ } |
+}; |
+ |
+// Test that the NaCl plugin isn't blocked for Webstore extensions. |
+IN_PROC_BROWSER_TEST_F(NaClExtensionTest, WebStoreExtension) { |
+ ASSERT_TRUE(test_server()->Start()); |
+ |
+ FilePath path = test_data_dir_.AppendASCII("native_client"); |
+ ASSERT_TRUE(InstallExtensionFromWebstore(path, 1)); |
+ |
+ ExtensionService* service = browser()->profile()->GetExtensionService(); |
+ const Extension* extension = |
+ service->GetExtensionById(last_loaded_extension_id_, false); |
+ ASSERT_TRUE(extension); |
+ |
+ ui_test_utils::NavigateToURL( |
+ browser(), extension->GetResourceURL("test.html")); |
+ |
+ bool embedded_plugin = false; |
+ bool content_handler_plugin = false; |
+ CheckPluginsCreated(browser()->GetSelectedTabContents(), |
+ &embedded_plugin, |
+ &content_handler_plugin); |
+ EXPECT_TRUE(embedded_plugin && content_handler_plugin); |
+} |
+ |
+// Test that the NaCl plugin is blocked for non-Webstore extensions. |
+IN_PROC_BROWSER_TEST_F(NaClExtensionTest, NonWebStoreExtension) { |
+ ASSERT_TRUE(test_server()->Start()); |
+ |
+ FilePath path = test_data_dir_.AppendASCII("native_client"); |
+ ASSERT_TRUE(InstallExtension(path, 1)); |
+ |
+ ExtensionService* service = browser()->profile()->GetExtensionService(); |
+ const Extension* extension = |
+ service->GetExtensionById(last_loaded_extension_id_, false); |
+ ASSERT_TRUE(extension); |
+ |
+ ui_test_utils::NavigateToURL( |
+ browser(), extension->GetResourceURL("test.html")); |
+ |
+ bool embedded_plugin = false; |
+ bool content_handler_plugin = false; |
+ CheckPluginsCreated(browser()->GetSelectedTabContents(), |
+ &embedded_plugin, |
+ &content_handler_plugin); |
+ EXPECT_FALSE(embedded_plugin && content_handler_plugin); |
+} |
+ |
+// Test that the NaCl plugin isn't blocked for component extensions. |
+IN_PROC_BROWSER_TEST_F(NaClExtensionTest, ComponentExtension) { |
+ ASSERT_TRUE(test_server()->Start()); |
+ |
+ FilePath file_path = test_data_dir_.AppendASCII("native_client"); |
+ LoadExtensionAsComponent(file_path); |
+ |
+ ExtensionService* service = browser()->profile()->GetExtensionService(); |
+ const Extension* extension = |
+ service->GetExtensionById("bjjcibdiodkkeanflmiijlcfieiemced", false); |
+ ASSERT_TRUE(extension); |
+ |
+ ui_test_utils::NavigateToURL( |
+ browser(), extension->GetResourceURL("test.html")); |
+ |
+ bool embedded_plugin = false; |
+ bool content_handler_plugin = false; |
+ CheckPluginsCreated(browser()->GetSelectedTabContents(), |
+ &embedded_plugin, |
+ &content_handler_plugin); |
+ EXPECT_TRUE(embedded_plugin && content_handler_plugin); |
asargent_no_longer_on_chrome
2011/08/09 19:23:34
nit: It looks like the body of these 3 tests are i
bbudge
2011/08/11 18:56:02
Done.
|
+} |
+ |
+} // namespace |
+ |
Property changes on: chrome\browser\extensions\extension_nacl_browsertest.cc |
___________________________________________________________________ |
Added: svn:eol-style |
+ LF |