Chromium Code Reviews
|
| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/command_line.h" | |
| 6 #include "base/utf_string_conversions.h" | |
| 7 #include "chrome/browser/extensions/crx_installer.h" | |
| 8 #include "chrome/browser/extensions/extension_browsertest.h" | |
| 9 #include "chrome/browser/extensions/extension_service.h" | |
| 10 #include "chrome/browser/prefs/pref_service.h" | |
| 11 #include "chrome/browser/profiles/profile.h" | |
| 12 #include "chrome/browser/ui/browser.h" | |
| 13 #include "chrome/common/chrome_switches.h" | |
| 14 #include "chrome/common/pref_names.h" | |
| 15 #include "chrome/test/base/ui_test_utils.h" | |
| 16 #include "content/browser/tab_contents/tab_contents.h" | |
| 17 | |
| 18 namespace { | |
| 19 | |
| 20 // This class tests that the Native Client plugin is blocked unless the | |
| 21 // .nexe is part of an extension from the Chrome Webstore. | |
| 22 class NaClExtensionTest : public ExtensionBrowserTest { | |
| 23 public: | |
| 24 NaClExtensionTest() { | |
| 25 EnableDOMAutomation(); | |
| 26 } | |
| 27 | |
| 28 protected: | |
| 29 // Install the extension from a .crx file; this allows us to make the | |
| 30 // extension appear to be from the Chrome Webstore. | |
| 31 const Extension* InstallCrx(bool from_webstore) { | |
| 32 ExtensionService* service = browser()->profile()->GetExtensionService(); | |
| 33 | |
| 34 scoped_refptr<CrxInstaller> installer(service->MakeCrxInstaller(NULL)); | |
| 35 installer->set_allow_silent_install(true); | |
| 36 installer->set_is_gallery_install(from_webstore); | |
| 37 | |
| 38 FilePath crx_path = test_data_dir_.AppendASCII("native_client.crx"); | |
| 39 installer->InstallCrx(crx_path); | |
| 40 WaitForExtensionLoad(); | |
| 41 | |
| 42 const Extension* extension = | |
| 43 service->GetExtensionById("clnidlieolioaicmfgfjefgglgdbkgfl", false); | |
| 44 CHECK(extension); | |
| 45 return extension; | |
| 46 } | |
| 47 | |
| 48 // Install the extension as a component; component extensions can use | |
| 49 // native client too. | |
| 50 const Extension* InstallAsComponent() { | |
| 51 FilePath file_path = test_data_dir_.AppendASCII("native_client"); | |
| 52 LoadExtensionAsComponent(file_path); | |
| 53 | |
| 54 ExtensionService* service = browser()->profile()->GetExtensionService(); | |
| 55 const Extension* extension = | |
| 56 service->GetExtensionById("bjjcibdiodkkeanflmiijlcfieiemced", false); | |
| 57 CHECK(extension); | |
| 58 return extension; | |
| 59 } | |
| 60 | |
| 61 bool IsEmbeddedPluginCreated(TabContents* tab_contents) { | |
| 62 bool plugin_created = false; | |
| 63 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.
| |
| 64 tab_contents->render_view_host(), L"", | |
| 65 L"window.domAutomationController.send(EmbeddedPluginCreated());", | |
| 66 &plugin_created)); | |
| 67 return plugin_created; | |
| 68 } | |
| 69 | |
| 70 bool IsContentHandlerPluginCreated(TabContents* tab_contents) { | |
| 71 bool plugin_created = false; | |
| 72 CHECK(ui_test_utils::ExecuteJavaScriptAndExtractBool( | |
|
Paweł Hajdan Jr.
2011/08/05 23:18:36
Same here.
bbudge
2011/08/09 05:26:50
Done.
| |
| 73 tab_contents->render_view_host(), L"", | |
| 74 L"window.domAutomationController.send(ContentHandlerPluginCreated());", | |
| 75 &plugin_created)); | |
| 76 return plugin_created; | |
| 77 } | |
| 78 }; | |
| 79 | |
| 80 // Test that the NaCl plugin isn't blocked for Webstore extensions. | |
| 81 IN_PROC_BROWSER_TEST_F(NaClExtensionTest, WebStoreExtension) { | |
| 82 ASSERT_TRUE(test_server()->Start()); | |
| 83 | |
| 84 const Extension* extension = InstallCrx(true); | |
| 85 | |
| 86 ui_test_utils::NavigateToURL( | |
| 87 browser(), extension->GetResourceURL("test.html")); | |
| 88 TabContents* tab_contents = browser()->GetSelectedTabContents(); | |
| 89 | |
| 90 EXPECT_TRUE(IsEmbeddedPluginCreated(tab_contents)); | |
| 91 EXPECT_TRUE(IsContentHandlerPluginCreated(tab_contents)); | |
| 92 } | |
| 93 | |
| 94 // Test that the NaCl plugin is blocked for non-Webstore extensions. | |
| 95 IN_PROC_BROWSER_TEST_F(NaClExtensionTest, NonWebStoreExtension) { | |
| 96 ASSERT_TRUE(test_server()->Start()); | |
| 97 | |
| 98 const Extension* extension = InstallCrx(false); | |
| 99 | |
| 100 ui_test_utils::NavigateToURL( | |
| 101 browser(), extension->GetResourceURL("test.html")); | |
| 102 TabContents* tab_contents = browser()->GetSelectedTabContents(); | |
| 103 | |
| 104 EXPECT_FALSE(IsEmbeddedPluginCreated(tab_contents)); | |
| 105 EXPECT_FALSE(IsContentHandlerPluginCreated(tab_contents)); | |
| 106 } | |
| 107 | |
| 108 // Test that the NaCl plugin isn't blocked for component extensions. | |
| 109 IN_PROC_BROWSER_TEST_F(NaClExtensionTest, ComponentExtension) { | |
| 110 ASSERT_TRUE(test_server()->Start()); | |
| 111 | |
| 112 const Extension* extension = InstallAsComponent(); | |
| 113 | |
| 114 ui_test_utils::NavigateToURL( | |
| 115 browser(), extension->GetResourceURL("test.html")); | |
| 116 TabContents* tab_contents = browser()->GetSelectedTabContents(); | |
| 117 | |
| 118 EXPECT_TRUE(IsEmbeddedPluginCreated(tab_contents)); | |
| 119 EXPECT_TRUE(IsContentHandlerPluginCreated(tab_contents)); | |
| 120 } | |
| 121 | |
| 122 } // namespace | |
| 123 | |
| OLD | NEW |