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

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

Issue 7488060: Add tests for CWS restriction of Nacl plugin invocation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/extensions/extension_browsertest.cc ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(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 const char* kExtensionId = "bjjcibdiodkkeanflmiijlcfieiemced";
21
22 // This class tests that the Native Client plugin is blocked unless the
23 // .nexe is part of an extension from the Chrome Webstore.
24 class NaClExtensionTest : public ExtensionBrowserTest {
25 public:
26 NaClExtensionTest() {
27 EnableDOMAutomation();
28 }
29
30 protected:
31 enum InstallType {
32 INSTALL_TYPE_COMPONENT,
33 INSTALL_TYPE_FROM_WEBSTORE,
34 INSTALL_TYPE_NON_WEBSTORE,
35 };
36
37 const Extension* InstallExtension(InstallType install_type) {
38 FilePath file_path = test_data_dir_.AppendASCII("native_client");
39 ExtensionService* service = browser()->profile()->GetExtensionService();
40 const Extension* extension = NULL;
41 switch (install_type) {
42 case INSTALL_TYPE_COMPONENT:
43 if (LoadExtensionAsComponent(file_path)) {
44 extension = service->GetExtensionById(kExtensionId, false);
45 }
46 break;
47
48 case INSTALL_TYPE_FROM_WEBSTORE:
49 if (InstallExtensionFromWebstore(file_path, 1)) {
50 extension = service->GetExtensionById(last_loaded_extension_id_,
51 false);
52 }
53 break;
54
55 case INSTALL_TYPE_NON_WEBSTORE:
56 if (ExtensionBrowserTest::InstallExtension(file_path, 1)) {
57 extension = service->GetExtensionById(last_loaded_extension_id_,
58 false);
59 }
60 break;
61 }
62 return extension;
63 }
64
65 void CheckPluginsCreated(const Extension* extension, bool should_create) {
66 ui_test_utils::NavigateToURL(browser(),
67 extension->GetResourceURL("test.html"));
68 bool embedded_plugin_created = false;
69 bool content_handler_plugin_created = false;
70 TabContents* tab_contents = browser()->GetSelectedTabContents();
71 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
72 tab_contents->render_view_host(), L"",
73 L"window.domAutomationController.send(EmbeddedPluginCreated());",
74 &embedded_plugin_created));
75 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
76 tab_contents->render_view_host(), L"",
77 L"window.domAutomationController.send(ContentHandlerPluginCreated());",
78 &content_handler_plugin_created));
79
80 EXPECT_EQ(should_create, embedded_plugin_created);
81 EXPECT_EQ(should_create, content_handler_plugin_created);
82 }
83 };
84
85 // Test that the NaCl plugin isn't blocked for Webstore extensions.
86 IN_PROC_BROWSER_TEST_F(NaClExtensionTest, WebStoreExtension) {
87 ASSERT_TRUE(test_server()->Start());
88
89 const Extension* extension = InstallExtension(INSTALL_TYPE_FROM_WEBSTORE);
90 ASSERT_TRUE(extension);
91 CheckPluginsCreated(extension, true);
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 = InstallExtension(INSTALL_TYPE_NON_WEBSTORE);
99 ASSERT_TRUE(extension);
100 CheckPluginsCreated(extension, false);
101 }
102
103 // Test that the NaCl plugin isn't blocked for component extensions.
104 IN_PROC_BROWSER_TEST_F(NaClExtensionTest, ComponentExtension) {
105 ASSERT_TRUE(test_server()->Start());
106
107 const Extension* extension = InstallExtension(INSTALL_TYPE_COMPONENT);
108 ASSERT_TRUE(extension);
109 CheckPluginsCreated(extension, true);
110 }
111
112 } // namespace
113
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_browsertest.cc ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698