Chromium Code Reviews
|
| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/renderer/chrome_content_renderer_client.h" | |
| 6 | |
| 7 #include "base/utf_string_conversions.h" | |
| 8 #include "googleurl/src/gurl.h" | |
| 9 #include "testing/gtest/include/gtest/gtest.h" | |
| 10 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" | |
| 11 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" | |
| 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h" | |
| 13 #include "webkit/plugins/webplugininfo.h" | |
| 14 | |
| 15 using WebKit::WebPluginParams; | |
| 16 using WebKit::WebString; | |
| 17 using WebKit::WebVector; | |
| 18 using chrome::ChromeContentRendererClient; | |
| 19 using webkit::WebPluginInfo; | |
| 20 using webkit::WebPluginMimeType; | |
| 21 | |
| 22 namespace chrome { | |
| 23 | |
| 24 namespace { | |
| 25 const char kNaClMimeType[] = "application/x-nacl"; | |
| 26 | |
| 27 bool AllowsDevInterfaces(const WebPluginParams& params) { | |
| 28 for (size_t i = 0; i < params.attributeNames.size(); ++i) { | |
| 29 if (params.attributeNames[i] == WebString::fromUTF8("@dev")) | |
| 30 return true; | |
| 31 } | |
| 32 return false; | |
| 33 } | |
| 34 | |
| 35 void AddFakeDevAttribute(WebPluginParams* params) { | |
| 36 WebVector<WebString> names(static_cast<size_t>(1)); | |
| 37 WebVector<WebString> values(static_cast<size_t>(1)); | |
| 38 names[0] = WebString::fromUTF8("@dev"); | |
| 39 values[0] = WebString(); | |
| 40 params->attributeNames.swap(names); | |
| 41 params->attributeValues.swap(values); | |
| 42 } | |
| 43 | |
| 44 void AddContentTypeHandler(WebPluginInfo* info, | |
| 45 const char* mime_type, | |
| 46 const char* manifest_url) { | |
| 47 WebPluginMimeType mime_type_info; | |
| 48 mime_type_info.mime_type = mime_type; | |
| 49 mime_type_info.additional_param_names.push_back(UTF8ToUTF16("nacl")); | |
| 50 mime_type_info.additional_param_values.push_back( | |
| 51 UTF8ToUTF16(manifest_url)); | |
| 52 info->mime_types.push_back(mime_type_info); | |
| 53 } | |
| 54 } | |
| 55 | |
| 56 typedef testing::Test ChromeContentRendererClientTest; | |
| 57 | |
| 58 TEST_F(ChromeContentRendererClientTest, NaClRestriction) { | |
| 59 // Unknown content types have no NaCl module. | |
| 60 { | |
| 61 WebPluginInfo info; | |
| 62 EXPECT_EQ(ChromeContentRendererClient::GetNaClContentHandlerURL( | |
|
Mihai Parparita -not on Chrome
2012/02/17 01:19:13
Nit: the param ordering of EXPECT_EQ is expected,
bbudge
2012/02/17 19:25:04
Done.
| |
| 63 "application/x-foo", info), GURL()); | |
| 64 } | |
| 65 // Known content types have a NaCl module. | |
| 66 { | |
| 67 WebPluginInfo info; | |
| 68 AddContentTypeHandler(&info, "application/x-foo", "www.foo.com"); | |
| 69 EXPECT_EQ(ChromeContentRendererClient::GetNaClContentHandlerURL( | |
| 70 "application/x-foo", info), GURL("www.foo.com")); | |
| 71 } | |
| 72 // --enable-nacl allows all NaCl apps, with 'dev' interfaces. | |
| 73 { | |
| 74 WebPluginParams params; | |
| 75 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( | |
| 76 GURL(), GURL(), true, false, false, params)); | |
|
Mihai Parparita -not on Chrome
2012/02/17 01:19:13
All the boolean parameters make the tests harder t
bbudge
2012/02/17 19:25:04
Done. Good idea.
On 2012/02/17 01:19:13, Mihai Par
| |
| 77 EXPECT_TRUE(AllowsDevInterfaces(params)); | |
| 78 } | |
| 79 // Unrestricted extensions are allowed without --enable-nacl, with 'dev' | |
| 80 // interfaces. | |
| 81 { | |
| 82 WebPluginParams params; | |
| 83 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( | |
| 84 GURL(), GURL(), false, true, false, params)); | |
| 85 EXPECT_TRUE(AllowsDevInterfaces(params)); | |
| 86 } | |
| 87 // CWS extensions are allowed without --enable-nacl, without 'dev' | |
| 88 // interfaces. | |
| 89 { | |
| 90 WebPluginParams params; | |
| 91 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( | |
| 92 GURL(), GURL(), false, false, true, params)); | |
| 93 EXPECT_FALSE(AllowsDevInterfaces(params)); | |
| 94 } | |
| 95 // CWS extensions can't get 'dev' interfaces with --enable-nacl. | |
| 96 { | |
| 97 WebPluginParams params; | |
| 98 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( | |
| 99 GURL(), GURL(), true, false, true, params)); | |
| 100 EXPECT_FALSE(AllowsDevInterfaces(params)); | |
| 101 } | |
| 102 // CWS extensions can't get 'dev' interfaces by injecting a fake | |
| 103 // '@dev' attribute. | |
| 104 { | |
| 105 WebPluginParams params; | |
| 106 AddFakeDevAttribute(¶ms); | |
| 107 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( | |
| 108 GURL(), GURL(), false, false, true, params)); | |
| 109 EXPECT_FALSE(AllowsDevInterfaces(params)); | |
| 110 } | |
| 111 // The NaCl PDF extension is allowed without --enable-nacl, with 'dev' | |
| 112 // interfaces. | |
| 113 { | |
| 114 WebPluginParams params; | |
| 115 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( | |
| 116 GURL("chrome-extension://acadkphlmlegjaadjagenfimbpphcgnh"), | |
| 117 GURL(), false, false, true, params)); | |
| 118 EXPECT_TRUE(AllowsDevInterfaces(params)); | |
| 119 } | |
| 120 // Whitelisted URLs are allowed without --enable-nacl, without 'dev' | |
| 121 // interfaces. | |
| 122 { | |
| 123 WebPluginParams params; | |
| 124 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( | |
| 125 GURL(), GURL("http://plus.google.com/games"), | |
|
Mihai Parparita -not on Chrome
2012/02/17 01:19:13
Mind also adding a full games URL (like https://pl
bbudge
2012/02/17 19:25:04
Done.
| |
| 126 false, false, false, params)); | |
| 127 EXPECT_FALSE(AllowsDevInterfaces(params)); | |
| 128 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( | |
| 129 GURL(), GURL("https://plus.google.com/games"), | |
| 130 false, false, false, params)); | |
| 131 EXPECT_FALSE(AllowsDevInterfaces(params)); | |
| 132 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( | |
| 133 GURL(), GURL("http://plus.sandbox.google.com/games"), | |
| 134 false, false, false, params)); | |
| 135 EXPECT_FALSE(AllowsDevInterfaces(params)); | |
| 136 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( | |
| 137 GURL(), GURL("https://plus.sandbox.google.com/games"), | |
| 138 false, false, false, params)); | |
| 139 EXPECT_FALSE(AllowsDevInterfaces(params)); | |
| 140 } | |
| 141 // Whitelisted URLs can't get 'dev' interfaces with --enable-nacl. | |
| 142 { | |
| 143 WebPluginParams params; | |
| 144 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( | |
| 145 GURL(), GURL("http://plus.google.com/games"), | |
| 146 true, false, false, params)); | |
| 147 EXPECT_FALSE(AllowsDevInterfaces(params)); | |
| 148 } | |
| 149 // Whitelisted URLs can't get 'dev' interfaces by injecting a fake | |
| 150 // '@dev' attribute. | |
| 151 { | |
| 152 WebPluginParams params; | |
| 153 AddFakeDevAttribute(¶ms); | |
| 154 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( | |
| 155 GURL(), GURL("http://plus.google.com/games"), | |
| 156 false, false, false, params)); | |
| 157 EXPECT_FALSE(AllowsDevInterfaces(params)); | |
| 158 } | |
| 159 // Non-whitelisted URLs are blocked without --enable-nacl. | |
| 160 { | |
| 161 WebPluginParams params; | |
| 162 EXPECT_FALSE(ChromeContentRendererClient::IsNaClAllowed( | |
| 163 GURL(), GURL("http://plus.google.com.evil.com/games"), | |
| 164 false, false, false, params)); | |
| 165 } | |
| 166 } | |
| 167 | |
| 168 } // namespace chrome | |
| 169 | |
| OLD | NEW |