| 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 bool kNaClRestricted = false; |
| 26 const bool kNaClUnrestricted = true; |
| 27 const bool kExtensionRestricted = false; |
| 28 const bool kExtensionUnrestricted = true; |
| 29 const bool kExtensionNotFromWebStore = false; |
| 30 const bool kExtensionFromWebStore = true; |
| 31 |
| 32 const char kNaClMimeType[] = "application/x-nacl"; |
| 33 |
| 34 bool AllowsDevInterfaces(const WebPluginParams& params) { |
| 35 for (size_t i = 0; i < params.attributeNames.size(); ++i) { |
| 36 if (params.attributeNames[i] == WebString::fromUTF8("@dev")) |
| 37 return true; |
| 38 } |
| 39 return false; |
| 40 } |
| 41 |
| 42 void AddFakeDevAttribute(WebPluginParams* params) { |
| 43 WebVector<WebString> names(static_cast<size_t>(1)); |
| 44 WebVector<WebString> values(static_cast<size_t>(1)); |
| 45 names[0] = WebString::fromUTF8("@dev"); |
| 46 values[0] = WebString(); |
| 47 params->attributeNames.swap(names); |
| 48 params->attributeValues.swap(values); |
| 49 } |
| 50 |
| 51 void AddContentTypeHandler(WebPluginInfo* info, |
| 52 const char* mime_type, |
| 53 const char* manifest_url) { |
| 54 WebPluginMimeType mime_type_info; |
| 55 mime_type_info.mime_type = mime_type; |
| 56 mime_type_info.additional_param_names.push_back(UTF8ToUTF16("nacl")); |
| 57 mime_type_info.additional_param_values.push_back( |
| 58 UTF8ToUTF16(manifest_url)); |
| 59 info->mime_types.push_back(mime_type_info); |
| 60 } |
| 61 } // namespace |
| 62 |
| 63 typedef testing::Test ChromeContentRendererClientTest; |
| 64 |
| 65 TEST_F(ChromeContentRendererClientTest, NaClRestriction) { |
| 66 // Unknown content types have no NaCl module. |
| 67 { |
| 68 WebPluginInfo info; |
| 69 EXPECT_EQ(GURL(), |
| 70 ChromeContentRendererClient::GetNaClContentHandlerURL( |
| 71 "application/x-foo", info)); |
| 72 } |
| 73 // Known content types have a NaCl module. |
| 74 { |
| 75 WebPluginInfo info; |
| 76 AddContentTypeHandler(&info, "application/x-foo", "www.foo.com"); |
| 77 EXPECT_EQ(GURL("www.foo.com"), |
| 78 ChromeContentRendererClient::GetNaClContentHandlerURL( |
| 79 "application/x-foo", info)); |
| 80 } |
| 81 // --enable-nacl allows all NaCl apps, with 'dev' interfaces. |
| 82 { |
| 83 WebPluginParams params; |
| 84 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( |
| 85 GURL(), GURL(), kNaClUnrestricted, kExtensionRestricted, |
| 86 kExtensionNotFromWebStore, ¶ms)); |
| 87 EXPECT_TRUE(AllowsDevInterfaces(params)); |
| 88 } |
| 89 // Unrestricted extensions are allowed without --enable-nacl, with 'dev' |
| 90 // interfaces. |
| 91 { |
| 92 WebPluginParams params; |
| 93 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( |
| 94 GURL(), GURL(), kNaClRestricted, kExtensionUnrestricted, |
| 95 kExtensionNotFromWebStore, ¶ms)); |
| 96 EXPECT_TRUE(AllowsDevInterfaces(params)); |
| 97 } |
| 98 // CWS extensions are allowed without --enable-nacl, without 'dev' |
| 99 // interfaces. |
| 100 { |
| 101 WebPluginParams params; |
| 102 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( |
| 103 GURL(), GURL(), kNaClRestricted, kExtensionRestricted, |
| 104 kExtensionFromWebStore, ¶ms)); |
| 105 EXPECT_FALSE(AllowsDevInterfaces(params)); |
| 106 } |
| 107 // CWS extensions can't get 'dev' interfaces with --enable-nacl. |
| 108 { |
| 109 WebPluginParams params; |
| 110 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( |
| 111 GURL(), GURL(), kNaClUnrestricted, kExtensionRestricted, |
| 112 kExtensionFromWebStore, ¶ms)); |
| 113 EXPECT_FALSE(AllowsDevInterfaces(params)); |
| 114 } |
| 115 // CWS extensions can't get 'dev' interfaces by injecting a fake |
| 116 // '@dev' attribute. |
| 117 { |
| 118 WebPluginParams params; |
| 119 AddFakeDevAttribute(¶ms); |
| 120 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( |
| 121 GURL(), GURL(), kNaClRestricted, kExtensionRestricted, |
| 122 kExtensionFromWebStore, ¶ms)); |
| 123 EXPECT_FALSE(AllowsDevInterfaces(params)); |
| 124 } |
| 125 // The NaCl PDF extension is allowed without --enable-nacl, with 'dev' |
| 126 // interfaces. |
| 127 { |
| 128 WebPluginParams params; |
| 129 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( |
| 130 GURL("chrome-extension://acadkphlmlegjaadjagenfimbpphcgnh"), |
| 131 GURL(), kNaClRestricted, kExtensionRestricted, |
| 132 kExtensionFromWebStore, ¶ms)); |
| 133 EXPECT_TRUE(AllowsDevInterfaces(params)); |
| 134 } |
| 135 // Whitelisted URLs are allowed without --enable-nacl, without 'dev' |
| 136 // interfaces. |
| 137 { |
| 138 WebPluginParams params; |
| 139 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( |
| 140 GURL(), GURL("http://plus.google.com/games"), |
| 141 kNaClRestricted, kExtensionRestricted, kExtensionNotFromWebStore, |
| 142 ¶ms)); |
| 143 EXPECT_FALSE(AllowsDevInterfaces(params)); |
| 144 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( |
| 145 GURL(), GURL("https://plus.google.com/games"), |
| 146 kNaClRestricted, kExtensionRestricted, kExtensionNotFromWebStore, |
| 147 ¶ms)); |
| 148 EXPECT_FALSE(AllowsDevInterfaces(params)); |
| 149 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( |
| 150 GURL(), GURL("https://plus.google.com/games/209089085730"), |
| 151 kNaClRestricted, kExtensionRestricted, kExtensionNotFromWebStore, |
| 152 ¶ms)); |
| 153 EXPECT_FALSE(AllowsDevInterfaces(params)); |
| 154 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( |
| 155 GURL(), GURL("http://plus.sandbox.google.com/games"), |
| 156 kNaClRestricted, kExtensionRestricted, kExtensionNotFromWebStore, |
| 157 ¶ms)); |
| 158 EXPECT_FALSE(AllowsDevInterfaces(params)); |
| 159 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( |
| 160 GURL(), GURL("https://plus.sandbox.google.com/games"), |
| 161 kNaClRestricted, kExtensionRestricted, kExtensionNotFromWebStore, |
| 162 ¶ms)); |
| 163 EXPECT_FALSE(AllowsDevInterfaces(params)); |
| 164 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( |
| 165 GURL(), GURL("https://plus.google.com/games/209089085730"), |
| 166 kNaClRestricted, kExtensionRestricted, kExtensionNotFromWebStore, |
| 167 ¶ms)); |
| 168 EXPECT_FALSE(AllowsDevInterfaces(params)); |
| 169 } |
| 170 // Whitelisted URLs can't get 'dev' interfaces with --enable-nacl. |
| 171 { |
| 172 WebPluginParams params; |
| 173 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( |
| 174 GURL(), GURL("https://plus.google.com/games/209089085730"), |
| 175 kNaClUnrestricted, kExtensionRestricted, kExtensionNotFromWebStore, |
| 176 ¶ms)); |
| 177 EXPECT_FALSE(AllowsDevInterfaces(params)); |
| 178 } |
| 179 // Whitelisted URLs can't get 'dev' interfaces by injecting a fake |
| 180 // '@dev' attribute. |
| 181 { |
| 182 WebPluginParams params; |
| 183 AddFakeDevAttribute(¶ms); |
| 184 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( |
| 185 GURL(), GURL("https://plus.google.com/games/209089085730"), |
| 186 kNaClRestricted, kExtensionRestricted, kExtensionNotFromWebStore, |
| 187 ¶ms)); |
| 188 EXPECT_FALSE(AllowsDevInterfaces(params)); |
| 189 } |
| 190 // Non-whitelisted URLs are blocked without --enable-nacl. |
| 191 { |
| 192 WebPluginParams params; |
| 193 EXPECT_FALSE(ChromeContentRendererClient::IsNaClAllowed( |
| 194 GURL(), GURL("http://plus.google.com.evil.com/games"), |
| 195 kNaClRestricted, kExtensionRestricted, kExtensionNotFromWebStore, |
| 196 ¶ms)); |
| 197 } |
| 198 } |
| 199 |
| 200 } // namespace chrome |
| 201 |
| OLD | NEW |