Chromium Code Reviews| Index: chrome/renderer/chrome_content_renderer_client_unittest.cc |
| =================================================================== |
| --- chrome/renderer/chrome_content_renderer_client_unittest.cc (revision 0) |
| +++ chrome/renderer/chrome_content_renderer_client_unittest.cc (revision 0) |
| @@ -0,0 +1,169 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/renderer/chrome_content_renderer_client.h" |
| + |
| +#include "base/utf_string_conversions.h" |
| +#include "googleurl/src/gurl.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| +#include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" |
| +#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" |
| +#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h" |
| +#include "webkit/plugins/webplugininfo.h" |
| + |
| +using WebKit::WebPluginParams; |
| +using WebKit::WebString; |
| +using WebKit::WebVector; |
| +using chrome::ChromeContentRendererClient; |
| +using webkit::WebPluginInfo; |
| +using webkit::WebPluginMimeType; |
| + |
| +namespace chrome { |
| + |
| +namespace { |
| +const char kNaClMimeType[] = "application/x-nacl"; |
| + |
| +bool AllowsDevInterfaces(const WebPluginParams& params) { |
| + for (size_t i = 0; i < params.attributeNames.size(); ++i) { |
| + if (params.attributeNames[i] == WebString::fromUTF8("@dev")) |
| + return true; |
| + } |
| + return false; |
| +} |
| + |
| +void AddFakeDevAttribute(WebPluginParams* params) { |
| + WebVector<WebString> names(static_cast<size_t>(1)); |
| + WebVector<WebString> values(static_cast<size_t>(1)); |
| + names[0] = WebString::fromUTF8("@dev"); |
| + values[0] = WebString(); |
| + params->attributeNames.swap(names); |
| + params->attributeValues.swap(values); |
| +} |
| + |
| +void AddContentTypeHandler(WebPluginInfo* info, |
| + const char* mime_type, |
| + const char* manifest_url) { |
| + WebPluginMimeType mime_type_info; |
| + mime_type_info.mime_type = mime_type; |
| + mime_type_info.additional_param_names.push_back(UTF8ToUTF16("nacl")); |
| + mime_type_info.additional_param_values.push_back( |
| + UTF8ToUTF16(manifest_url)); |
| + info->mime_types.push_back(mime_type_info); |
| +} |
| +} |
| + |
| +typedef testing::Test ChromeContentRendererClientTest; |
| + |
| +TEST_F(ChromeContentRendererClientTest, NaClRestriction) { |
| + // Unknown content types have no NaCl module. |
| + { |
| + WebPluginInfo info; |
| + 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.
|
| + "application/x-foo", info), GURL()); |
| + } |
| + // Known content types have a NaCl module. |
| + { |
| + WebPluginInfo info; |
| + AddContentTypeHandler(&info, "application/x-foo", "www.foo.com"); |
| + EXPECT_EQ(ChromeContentRendererClient::GetNaClContentHandlerURL( |
| + "application/x-foo", info), GURL("www.foo.com")); |
| + } |
| + // --enable-nacl allows all NaCl apps, with 'dev' interfaces. |
| + { |
| + WebPluginParams params; |
| + EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( |
| + 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
|
| + EXPECT_TRUE(AllowsDevInterfaces(params)); |
| + } |
| + // Unrestricted extensions are allowed without --enable-nacl, with 'dev' |
| + // interfaces. |
| + { |
| + WebPluginParams params; |
| + EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( |
| + GURL(), GURL(), false, true, false, params)); |
| + EXPECT_TRUE(AllowsDevInterfaces(params)); |
| + } |
| + // CWS extensions are allowed without --enable-nacl, without 'dev' |
| + // interfaces. |
| + { |
| + WebPluginParams params; |
| + EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( |
| + GURL(), GURL(), false, false, true, params)); |
| + EXPECT_FALSE(AllowsDevInterfaces(params)); |
| + } |
| + // CWS extensions can't get 'dev' interfaces with --enable-nacl. |
| + { |
| + WebPluginParams params; |
| + EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( |
| + GURL(), GURL(), true, false, true, params)); |
| + EXPECT_FALSE(AllowsDevInterfaces(params)); |
| + } |
| + // CWS extensions can't get 'dev' interfaces by injecting a fake |
| + // '@dev' attribute. |
| + { |
| + WebPluginParams params; |
| + AddFakeDevAttribute(¶ms); |
| + EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( |
| + GURL(), GURL(), false, false, true, params)); |
| + EXPECT_FALSE(AllowsDevInterfaces(params)); |
| + } |
| + // The NaCl PDF extension is allowed without --enable-nacl, with 'dev' |
| + // interfaces. |
| + { |
| + WebPluginParams params; |
| + EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( |
| + GURL("chrome-extension://acadkphlmlegjaadjagenfimbpphcgnh"), |
| + GURL(), false, false, true, params)); |
| + EXPECT_TRUE(AllowsDevInterfaces(params)); |
| + } |
| + // Whitelisted URLs are allowed without --enable-nacl, without 'dev' |
| + // interfaces. |
| + { |
| + WebPluginParams params; |
| + EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( |
| + 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.
|
| + false, false, false, params)); |
| + EXPECT_FALSE(AllowsDevInterfaces(params)); |
| + EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( |
| + GURL(), GURL("https://plus.google.com/games"), |
| + false, false, false, params)); |
| + EXPECT_FALSE(AllowsDevInterfaces(params)); |
| + EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( |
| + GURL(), GURL("http://plus.sandbox.google.com/games"), |
| + false, false, false, params)); |
| + EXPECT_FALSE(AllowsDevInterfaces(params)); |
| + EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( |
| + GURL(), GURL("https://plus.sandbox.google.com/games"), |
| + false, false, false, params)); |
| + EXPECT_FALSE(AllowsDevInterfaces(params)); |
| + } |
| + // Whitelisted URLs can't get 'dev' interfaces with --enable-nacl. |
| + { |
| + WebPluginParams params; |
| + EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( |
| + GURL(), GURL("http://plus.google.com/games"), |
| + true, false, false, params)); |
| + EXPECT_FALSE(AllowsDevInterfaces(params)); |
| + } |
| + // Whitelisted URLs can't get 'dev' interfaces by injecting a fake |
| + // '@dev' attribute. |
| + { |
| + WebPluginParams params; |
| + AddFakeDevAttribute(¶ms); |
| + EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( |
| + GURL(), GURL("http://plus.google.com/games"), |
| + false, false, false, params)); |
| + EXPECT_FALSE(AllowsDevInterfaces(params)); |
| + } |
| + // Non-whitelisted URLs are blocked without --enable-nacl. |
| + { |
| + WebPluginParams params; |
| + EXPECT_FALSE(ChromeContentRendererClient::IsNaClAllowed( |
| + GURL(), GURL("http://plus.google.com.evil.com/games"), |
| + false, false, false, params)); |
| + } |
| +} |
| + |
| +} // namespace chrome |
| + |
| Property changes on: chrome\renderer\chrome_content_renderer_client_unittest.cc |
| ___________________________________________________________________ |
| Added: svn:eol-style |
| + LF |