Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(303)

Side by Side Diff: chrome/browser/extensions/extension_nacl_browsertest.cc

Issue 12612011: Allow NaCl plugin to be loaded from hosted app URLs. (Closed) Base URL: https://src.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/renderer/chrome_content_renderer_client.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/files/file_path.h" 6 #include "base/files/file_path.h"
7 #include "base/path_service.h" 7 #include "base/path_service.h"
8 #include "base/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/extensions/crx_installer.h" 10 #include "chrome/browser/extensions/crx_installer.h"
11 #include "chrome/browser/extensions/extension_browsertest.h" 11 #include "chrome/browser/extensions/extension_browsertest.h"
12 #include "chrome/browser/extensions/extension_service.h" 12 #include "chrome/browser/extensions/extension_service.h"
13 #include "chrome/browser/extensions/extension_system.h" 13 #include "chrome/browser/extensions/extension_system.h"
14 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/tabs/tab_strip_model.h" 16 #include "chrome/browser/ui/tabs/tab_strip_model.h"
17 #include "chrome/common/chrome_paths.h" 17 #include "chrome/common/chrome_paths.h"
18 #include "chrome/common/chrome_switches.h" 18 #include "chrome/common/chrome_switches.h"
19 #include "chrome/common/pref_names.h" 19 #include "chrome/common/pref_names.h"
20 #include "chrome/test/base/ui_test_utils.h" 20 #include "chrome/test/base/ui_test_utils.h"
21 #include "content/public/browser/plugin_service.h" 21 #include "content/public/browser/plugin_service.h"
22 #include "content/public/browser/web_contents.h" 22 #include "content/public/browser/web_contents.h"
23 #include "content/public/test/browser_test_utils.h" 23 #include "content/public/test/browser_test_utils.h"
24 #include "net/base/mock_host_resolver.h"
24 #include "webkit/plugins/webplugininfo.h" 25 #include "webkit/plugins/webplugininfo.h"
25 26
26 using content::PluginService; 27 using content::PluginService;
27 using content::WebContents; 28 using content::WebContents;
28 using extensions::Extension; 29 using extensions::Extension;
29 using extensions::Manifest; 30 using extensions::Manifest;
30 31
31 namespace { 32 namespace {
32 33
33 const char* kExtensionId = "bjjcibdiodkkeanflmiijlcfieiemced"; 34 const char* kExtensionId = "bjjcibdiodkkeanflmiijlcfieiemced";
34 35
35 // This class tests that the Native Client plugin is blocked unless the 36 // This class tests that the Native Client plugin is blocked unless the
36 // .nexe is part of an extension from the Chrome Webstore. 37 // .nexe is part of an extension from the Chrome Webstore.
37 class NaClExtensionTest : public ExtensionBrowserTest { 38 class NaClExtensionTest : public ExtensionBrowserTest {
38 public: 39 public:
39 NaClExtensionTest() {} 40 NaClExtensionTest() {}
40 41
41 protected: 42 protected:
42 enum InstallType { 43 enum InstallType {
43 INSTALL_TYPE_COMPONENT, 44 INSTALL_TYPE_COMPONENT,
44 INSTALL_TYPE_UNPACKED, 45 INSTALL_TYPE_UNPACKED,
45 INSTALL_TYPE_FROM_WEBSTORE, 46 INSTALL_TYPE_FROM_WEBSTORE,
46 INSTALL_TYPE_NON_WEBSTORE, 47 INSTALL_TYPE_NON_WEBSTORE,
47 }; 48 };
48 49
49 const Extension* InstallExtension(InstallType install_type) { 50 const Extension* InstallExtension(const base::FilePath& file_path,
50 base::FilePath file_path = test_data_dir_.AppendASCII("native_client"); 51 InstallType install_type) {
51 ExtensionService* service = extensions::ExtensionSystem::Get( 52 ExtensionService* service = extensions::ExtensionSystem::Get(
52 browser()->profile())->extension_service(); 53 browser()->profile())->extension_service();
53 const Extension* extension = NULL; 54 const Extension* extension = NULL;
54 switch (install_type) { 55 switch (install_type) {
55 case INSTALL_TYPE_COMPONENT: 56 case INSTALL_TYPE_COMPONENT:
56 if (LoadExtensionAsComponent(file_path)) { 57 if (LoadExtensionAsComponent(file_path)) {
57 extension = service->GetExtensionById(kExtensionId, false); 58 extension = service->GetExtensionById(kExtensionId, false);
58 } 59 }
59 break; 60 break;
60 61
(...skipping 16 matching lines...) Expand all
77 // Install native_client.crx but not from the webstore. 78 // Install native_client.crx but not from the webstore.
78 if (ExtensionBrowserTest::InstallExtension(file_path, 1)) { 79 if (ExtensionBrowserTest::InstallExtension(file_path, 1)) {
79 extension = service->GetExtensionById(last_loaded_extension_id_, 80 extension = service->GetExtensionById(last_loaded_extension_id_,
80 false); 81 false);
81 } 82 }
82 break; 83 break;
83 } 84 }
84 return extension; 85 return extension;
85 } 86 }
86 87
88 const Extension* InstallExtension(InstallType install_type) {
89 base::FilePath file_path = test_data_dir_.AppendASCII("native_client");
90 return InstallExtension(file_path, install_type);
91 }
92
93 const Extension* InstallHostedApp() {
94 base::FilePath file_path = test_data_dir_.AppendASCII(
95 "native_client_hosted_app");
96 return InstallExtension(file_path, INSTALL_TYPE_FROM_WEBSTORE);
97 }
98
87 bool IsNaClPluginLoaded() { 99 bool IsNaClPluginLoaded() {
88 base::FilePath path; 100 base::FilePath path;
89 if (PathService::Get(chrome::FILE_NACL_PLUGIN, &path)) { 101 if (PathService::Get(chrome::FILE_NACL_PLUGIN, &path)) {
90 webkit::WebPluginInfo info; 102 webkit::WebPluginInfo info;
91 return PluginService::GetInstance()->GetPluginInfoByPath(path, &info); 103 return PluginService::GetInstance()->GetPluginInfoByPath(path, &info);
92 } 104 }
93 return false; 105 return false;
94 } 106 }
95 107
96 void CheckPluginsCreated(const GURL& url, bool should_create) { 108 void CheckPluginsCreated(const GURL& url, bool should_create) {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 // Test that the NaCl plugin is blocked for non chrome-extension urls. 175 // Test that the NaCl plugin is blocked for non chrome-extension urls.
164 IN_PROC_BROWSER_TEST_F(NaClExtensionTest, NonExtensionScheme) { 176 IN_PROC_BROWSER_TEST_F(NaClExtensionTest, NonExtensionScheme) {
165 ASSERT_TRUE(test_server()->Start()); 177 ASSERT_TRUE(test_server()->Start());
166 178
167 const Extension* extension = InstallExtension(INSTALL_TYPE_FROM_WEBSTORE); 179 const Extension* extension = InstallExtension(INSTALL_TYPE_FROM_WEBSTORE);
168 ASSERT_TRUE(extension); 180 ASSERT_TRUE(extension);
169 CheckPluginsCreated( 181 CheckPluginsCreated(
170 test_server()->GetURL("files/extensions/native_client/test.html"), false); 182 test_server()->GetURL("files/extensions/native_client/test.html"), false);
171 } 183 }
172 184
185 // Test that NaCl plugin isn't blocked for hosted app URLs.
186 IN_PROC_BROWSER_TEST_F(NaClExtensionTest, HostedApp) {
187 host_resolver()->AddRule("*", "127.0.0.1");
188 ASSERT_TRUE(test_server()->Start());
189
190 GURL url = test_server()->GetURL("files/extensions/native_client/test.html");
191 GURL::Replacements replace_host;
192 std::string host_str("localhost");
193 replace_host.SetHostStr(host_str);
194 replace_host.ClearPort();
195 url = url.ReplaceComponents(replace_host);
196
197 const Extension* extension = InstallHostedApp();
198 ASSERT_TRUE(extension);
199 CheckPluginsCreated(url, true);
200 }
201
173 } // namespace 202 } // namespace
OLDNEW
« no previous file with comments | « no previous file | chrome/renderer/chrome_content_renderer_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698