OLD | NEW |
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 "chrome/renderer/chrome_content_renderer_client.h" | 5 #include "chrome/renderer/chrome_content_renderer_client.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/renderer/searchbox/search_bouncer.h" | 10 #include "chrome/renderer/searchbox/search_bouncer.h" |
11 #include "content/public/common/webplugininfo.h" | 11 #include "content/public/common/webplugininfo.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "url/gurl.h" |
| 14 |
| 15 #if defined(ENABLE_EXTENSIONS) |
12 #include "extensions/common/extension.h" | 16 #include "extensions/common/extension.h" |
13 #include "extensions/common/extension_builder.h" | 17 #include "extensions/common/extension_builder.h" |
14 #include "extensions/common/manifest_constants.h" | 18 #include "extensions/common/manifest_constants.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 19 #endif |
| 20 |
| 21 #if !defined(DISABLE_NACL) |
16 #include "third_party/WebKit/public/platform/WebString.h" | 22 #include "third_party/WebKit/public/platform/WebString.h" |
17 #include "third_party/WebKit/public/platform/WebVector.h" | 23 #include "third_party/WebKit/public/platform/WebVector.h" |
18 #include "third_party/WebKit/public/web/WebPluginParams.h" | 24 #include "third_party/WebKit/public/web/WebPluginParams.h" |
19 #include "url/gurl.h" | 25 #endif |
20 | 26 |
| 27 #if !defined(DISABLE_NACL) |
21 using blink::WebPluginParams; | 28 using blink::WebPluginParams; |
22 using blink::WebString; | 29 using blink::WebString; |
23 using blink::WebVector; | 30 using blink::WebVector; |
| 31 #endif |
| 32 |
24 using content::WebPluginInfo; | 33 using content::WebPluginInfo; |
25 using content::WebPluginMimeType; | 34 using content::WebPluginMimeType; |
26 | 35 |
27 namespace { | 36 namespace { |
| 37 |
| 38 #if !defined(DISABLE_NACL) |
28 const bool kNaClRestricted = false; | 39 const bool kNaClRestricted = false; |
29 const bool kNaClUnrestricted = true; | 40 const bool kNaClUnrestricted = true; |
30 const bool kExtensionRestricted = false; | 41 const bool kExtensionRestricted = false; |
31 const bool kExtensionUnrestricted = true; | 42 const bool kExtensionUnrestricted = true; |
32 const bool kExtensionNotFromWebStore = false; | 43 const bool kExtensionNotFromWebStore = false; |
33 const bool kExtensionFromWebStore = true; | 44 const bool kExtensionFromWebStore = true; |
| 45 #endif |
| 46 |
| 47 #if defined(ENABLE_EXTENSIONS) |
34 const bool kNotHostedApp = false; | 48 const bool kNotHostedApp = false; |
35 const bool kHostedApp = true; | 49 const bool kHostedApp = true; |
| 50 #endif |
36 | 51 |
| 52 #if !defined(DISABLE_NACL) |
37 const char kExtensionUrl[] = "chrome-extension://extension_id/background.html"; | 53 const char kExtensionUrl[] = "chrome-extension://extension_id/background.html"; |
38 | 54 |
39 const char kPhotosAppURL1[] = "https://foo.plus.google.com"; | 55 const char kPhotosAppURL1[] = "https://foo.plus.google.com"; |
40 const char kPhotosAppURL2[] = "https://foo.plus.sandbox.google.com"; | 56 const char kPhotosAppURL2[] = "https://foo.plus.sandbox.google.com"; |
41 const char kPhotosManifestURL1[] = "https://ssl.gstatic.com/s2/oz/nacl/foo"; | 57 const char kPhotosManifestURL1[] = "https://ssl.gstatic.com/s2/oz/nacl/foo"; |
42 const char kPhotosManifestURL2[] = "https://ssl.gstatic.com/photos/nacl/foo"; | 58 const char kPhotosManifestURL2[] = "https://ssl.gstatic.com/photos/nacl/foo"; |
43 | |
44 const char kChatAppURL1[] = "https://foo.talkgadget.google.com/hangouts/foo"; | |
45 const char kChatAppURL2[] = "https://foo.plus.google.com/hangouts/foo"; | |
46 const char kChatAppURL3[] = "https://foo.plus.sandbox.google.com/hangouts/foo"; | |
47 const char kChatManifestFS1[] = | 59 const char kChatManifestFS1[] = |
48 "filesystem:https://foo.talkgadget.google.com/foo"; | 60 "filesystem:https://foo.talkgadget.google.com/foo"; |
49 const char kChatManifestFS2[] = "filesystem:https://foo.plus.google.com/foo"; | 61 const char kChatManifestFS2[] = "filesystem:https://foo.plus.google.com/foo"; |
50 const char kChatManifestFS3[] = | 62 const char kChatManifestFS3[] = |
51 "filesystem:https://foo.plus.sandbox.google.com/foo"; | 63 "filesystem:https://foo.plus.sandbox.google.com/foo"; |
| 64 #endif |
52 | 65 |
| 66 const char kChatAppURL1[] = "https://foo.talkgadget.google.com/hangouts/foo"; |
| 67 const char kChatAppURL2[] = "https://foo.plus.google.com/hangouts/foo"; |
| 68 const char kChatAppURL3[] = "https://foo.plus.sandbox.google.com/hangouts/foo"; |
| 69 |
| 70 #if !defined(DISABLE_NACL) |
53 bool AllowsDevInterfaces(const WebPluginParams& params) { | 71 bool AllowsDevInterfaces(const WebPluginParams& params) { |
54 for (size_t i = 0; i < params.attributeNames.size(); ++i) { | 72 for (size_t i = 0; i < params.attributeNames.size(); ++i) { |
55 if (params.attributeNames[i] == WebString::fromUTF8("@dev")) | 73 if (params.attributeNames[i] == WebString::fromUTF8("@dev")) |
56 return true; | 74 return true; |
57 } | 75 } |
58 return false; | 76 return false; |
59 } | 77 } |
60 | 78 |
61 void AddFakeDevAttribute(WebPluginParams* params) { | 79 void AddFakeDevAttribute(WebPluginParams* params) { |
62 WebVector<WebString> names(static_cast<size_t>(1)); | 80 WebVector<WebString> names(static_cast<size_t>(1)); |
63 WebVector<WebString> values(static_cast<size_t>(1)); | 81 WebVector<WebString> values(static_cast<size_t>(1)); |
64 names[0] = WebString::fromUTF8("@dev"); | 82 names[0] = WebString::fromUTF8("@dev"); |
65 values[0] = WebString(); | 83 values[0] = WebString(); |
66 params->attributeNames.swap(names); | 84 params->attributeNames.swap(names); |
67 params->attributeValues.swap(values); | 85 params->attributeValues.swap(values); |
68 } | 86 } |
| 87 #endif |
69 | 88 |
70 void AddContentTypeHandler(content::WebPluginInfo* info, | 89 void AddContentTypeHandler(content::WebPluginInfo* info, |
71 const char* mime_type, | 90 const char* mime_type, |
72 const char* manifest_url) { | 91 const char* manifest_url) { |
73 content::WebPluginMimeType mime_type_info; | 92 content::WebPluginMimeType mime_type_info; |
74 mime_type_info.mime_type = mime_type; | 93 mime_type_info.mime_type = mime_type; |
75 mime_type_info.additional_param_names.push_back(base::UTF8ToUTF16("nacl")); | 94 mime_type_info.additional_param_names.push_back(base::UTF8ToUTF16("nacl")); |
76 mime_type_info.additional_param_values.push_back( | 95 mime_type_info.additional_param_values.push_back( |
77 base::UTF8ToUTF16(manifest_url)); | 96 base::UTF8ToUTF16(manifest_url)); |
78 info->mime_types.push_back(mime_type_info); | 97 info->mime_types.push_back(mime_type_info); |
79 } | 98 } |
| 99 |
80 } // namespace | 100 } // namespace |
81 | 101 |
82 typedef testing::Test ChromeContentRendererClientTest; | 102 typedef testing::Test ChromeContentRendererClientTest; |
83 | 103 |
84 | 104 |
| 105 #if defined(ENABLE_EXTENSIONS) |
85 scoped_refptr<const extensions::Extension> CreateTestExtension( | 106 scoped_refptr<const extensions::Extension> CreateTestExtension( |
86 bool is_unrestricted, bool is_from_webstore, bool is_hosted_app, | 107 bool is_unrestricted, bool is_from_webstore, bool is_hosted_app, |
87 const std::string& app_url) { | 108 const std::string& app_url) { |
88 extensions::Manifest::Location location = is_unrestricted ? | 109 extensions::Manifest::Location location = is_unrestricted ? |
89 extensions::Manifest::UNPACKED : | 110 extensions::Manifest::UNPACKED : |
90 extensions::Manifest::INTERNAL; | 111 extensions::Manifest::INTERNAL; |
91 int flags = is_from_webstore ? | 112 int flags = is_from_webstore ? |
92 extensions::Extension::FROM_WEBSTORE: | 113 extensions::Extension::FROM_WEBSTORE: |
93 extensions::Extension::NO_FLAGS; | 114 extensions::Extension::NO_FLAGS; |
94 | 115 |
(...skipping 16 matching lines...) Expand all Loading... |
111 bool is_unrestricted, bool is_from_webstore) { | 132 bool is_unrestricted, bool is_from_webstore) { |
112 return CreateTestExtension( | 133 return CreateTestExtension( |
113 is_unrestricted, is_from_webstore, kNotHostedApp, std::string()); | 134 is_unrestricted, is_from_webstore, kNotHostedApp, std::string()); |
114 } | 135 } |
115 | 136 |
116 scoped_refptr<const extensions::Extension> CreateHostedApp( | 137 scoped_refptr<const extensions::Extension> CreateHostedApp( |
117 bool is_unrestricted, bool is_from_webstore, const std::string& app_url) { | 138 bool is_unrestricted, bool is_from_webstore, const std::string& app_url) { |
118 return CreateTestExtension(is_unrestricted, is_from_webstore, kHostedApp, | 139 return CreateTestExtension(is_unrestricted, is_from_webstore, kHostedApp, |
119 app_url); | 140 app_url); |
120 } | 141 } |
| 142 #endif // defined(ENABLE_EXTENSIONS) |
121 | 143 |
122 TEST_F(ChromeContentRendererClientTest, NaClRestriction) { | 144 TEST_F(ChromeContentRendererClientTest, NaClRestriction) { |
123 // Unknown content types have no NaCl module. | 145 // Unknown content types have no NaCl module. |
124 { | 146 { |
125 WebPluginInfo info; | 147 WebPluginInfo info; |
126 EXPECT_EQ(GURL(), | 148 EXPECT_EQ(GURL(), |
127 ChromeContentRendererClient::GetNaClContentHandlerURL( | 149 ChromeContentRendererClient::GetNaClContentHandlerURL( |
128 "application/x-foo", info)); | 150 "application/x-foo", info)); |
129 } | 151 } |
130 // Known content types have a NaCl module. | 152 // Known content types have a NaCl module. |
131 { | 153 { |
132 WebPluginInfo info; | 154 WebPluginInfo info; |
133 AddContentTypeHandler(&info, "application/x-foo", "www.foo.com"); | 155 AddContentTypeHandler(&info, "application/x-foo", "www.foo.com"); |
134 EXPECT_EQ(GURL("www.foo.com"), | 156 EXPECT_EQ(GURL("www.foo.com"), |
135 ChromeContentRendererClient::GetNaClContentHandlerURL( | 157 ChromeContentRendererClient::GetNaClContentHandlerURL( |
136 "application/x-foo", info)); | 158 "application/x-foo", info)); |
137 } | 159 } |
| 160 #if !defined(DISABLE_NACL) |
138 // --enable-nacl allows all NaCl apps, with 'dev' interfaces. | 161 // --enable-nacl allows all NaCl apps, with 'dev' interfaces. |
139 { | 162 { |
140 WebPluginParams params; | 163 WebPluginParams params; |
141 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( | 164 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( |
142 GURL(), | 165 GURL(), |
143 GURL(), | 166 GURL(), |
144 kNaClUnrestricted, | 167 kNaClUnrestricted, |
145 CreateExtension(kExtensionRestricted, kExtensionNotFromWebStore).get(), | 168 CreateExtension(kExtensionRestricted, kExtensionNotFromWebStore).get(), |
146 ¶ms)); | 169 ¶ms)); |
147 EXPECT_TRUE(AllowsDevInterfaces(params)); | 170 EXPECT_TRUE(AllowsDevInterfaces(params)); |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 ¶ms)); | 388 ¶ms)); |
366 EXPECT_FALSE(ChromeContentRendererClient::IsNaClAllowed( | 389 EXPECT_FALSE(ChromeContentRendererClient::IsNaClAllowed( |
367 GURL(), | 390 GURL(), |
368 GURL("http://example.evil.com/test.html"), | 391 GURL("http://example.evil.com/test.html"), |
369 kNaClRestricted, | 392 kNaClRestricted, |
370 CreateHostedApp(kExtensionRestricted, | 393 CreateHostedApp(kExtensionRestricted, |
371 kExtensionNotFromWebStore, | 394 kExtensionNotFromWebStore, |
372 "http://example.com/").get(), | 395 "http://example.com/").get(), |
373 ¶ms)); | 396 ¶ms)); |
374 } | 397 } |
| 398 #endif // !defined(DISABLE_NACL) |
375 } | 399 } |
376 | 400 |
377 TEST_F(ChromeContentRendererClientTest, AllowPepperMediaStreamAPI) { | 401 TEST_F(ChromeContentRendererClientTest, AllowPepperMediaStreamAPI) { |
378 ChromeContentRendererClient test; | 402 ChromeContentRendererClient test; |
379 #if !defined(OS_ANDROID) | 403 #if !defined(OS_ANDROID) |
380 EXPECT_TRUE(test.AllowPepperMediaStreamAPI(GURL(kChatAppURL1))); | 404 EXPECT_TRUE(test.AllowPepperMediaStreamAPI(GURL(kChatAppURL1))); |
381 EXPECT_TRUE(test.AllowPepperMediaStreamAPI(GURL(kChatAppURL2))); | 405 EXPECT_TRUE(test.AllowPepperMediaStreamAPI(GURL(kChatAppURL2))); |
382 EXPECT_TRUE(test.AllowPepperMediaStreamAPI(GURL(kChatAppURL3))); | 406 EXPECT_TRUE(test.AllowPepperMediaStreamAPI(GURL(kChatAppURL3))); |
383 #else | 407 #else |
384 EXPECT_FALSE(test.AllowPepperMediaStreamAPI(GURL(kChatAppURL1))); | 408 EXPECT_FALSE(test.AllowPepperMediaStreamAPI(GURL(kChatAppURL1))); |
385 EXPECT_FALSE(test.AllowPepperMediaStreamAPI(GURL(kChatAppURL2))); | 409 EXPECT_FALSE(test.AllowPepperMediaStreamAPI(GURL(kChatAppURL2))); |
386 EXPECT_FALSE(test.AllowPepperMediaStreamAPI(GURL(kChatAppURL3))); | 410 EXPECT_FALSE(test.AllowPepperMediaStreamAPI(GURL(kChatAppURL3))); |
387 #endif | 411 #endif |
388 EXPECT_FALSE(test.AllowPepperMediaStreamAPI( | 412 EXPECT_FALSE(test.AllowPepperMediaStreamAPI( |
389 GURL("http://talkgadget.google.com/hangouts/foo"))); | 413 GURL("http://talkgadget.google.com/hangouts/foo"))); |
390 EXPECT_FALSE(test.AllowPepperMediaStreamAPI( | 414 EXPECT_FALSE(test.AllowPepperMediaStreamAPI( |
391 GURL("https://talkgadget.evil.com/hangouts/foo"))); | 415 GURL("https://talkgadget.evil.com/hangouts/foo"))); |
392 } | 416 } |
393 | 417 |
394 TEST_F(ChromeContentRendererClientTest, ShouldSuppressErrorPage) { | 418 TEST_F(ChromeContentRendererClientTest, ShouldSuppressErrorPage) { |
395 ChromeContentRendererClient client; | 419 ChromeContentRendererClient client; |
396 client.search_bouncer_.reset(new SearchBouncer); | 420 client.search_bouncer_.reset(new SearchBouncer); |
397 client.search_bouncer_->OnSetSearchURLs( | 421 client.search_bouncer_->OnSetSearchURLs( |
398 std::vector<GURL>(), GURL("http://example.com/n")); | 422 std::vector<GURL>(), GURL("http://example.com/n")); |
399 EXPECT_FALSE(client.ShouldSuppressErrorPage(NULL, | 423 EXPECT_FALSE(client.ShouldSuppressErrorPage(NULL, |
400 GURL("http://example.com"))); | 424 GURL("http://example.com"))); |
401 EXPECT_TRUE(client.ShouldSuppressErrorPage(NULL, | 425 EXPECT_TRUE(client.ShouldSuppressErrorPage(NULL, |
402 GURL("http://example.com/n"))); | 426 GURL("http://example.com/n"))); |
403 } | 427 } |
OLD | NEW |