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 "extensions/common/extension.h" | |
13 #include "extensions/common/extension_builder.h" | |
14 #include "extensions/common/manifest_constants.h" | |
15 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
16 #include "third_party/WebKit/public/platform/WebString.h" | 13 #include "third_party/WebKit/public/platform/WebString.h" |
Yoyo Zhou
2014/10/23 00:03:59
Looks like you only need the webkit headers if !de
Lei Zhang
2014/10/23 00:30:46
Done.
| |
17 #include "third_party/WebKit/public/platform/WebVector.h" | 14 #include "third_party/WebKit/public/platform/WebVector.h" |
18 #include "third_party/WebKit/public/web/WebPluginParams.h" | 15 #include "third_party/WebKit/public/web/WebPluginParams.h" |
19 #include "url/gurl.h" | 16 #include "url/gurl.h" |
20 | 17 |
18 #if defined(ENABLE_EXTENSIONS) | |
19 #include "extensions/common/extension.h" | |
20 #include "extensions/common/extension_builder.h" | |
21 #include "extensions/common/manifest_constants.h" | |
22 #endif | |
23 | |
21 using blink::WebPluginParams; | 24 using blink::WebPluginParams; |
22 using blink::WebString; | 25 using blink::WebString; |
23 using blink::WebVector; | 26 using blink::WebVector; |
24 using content::WebPluginInfo; | 27 using content::WebPluginInfo; |
25 using content::WebPluginMimeType; | 28 using content::WebPluginMimeType; |
26 | 29 |
27 namespace { | 30 namespace { |
28 const bool kNaClRestricted = false; | 31 const bool kNaClRestricted = false; |
29 const bool kNaClUnrestricted = true; | 32 const bool kNaClUnrestricted = true; |
30 const bool kExtensionRestricted = false; | 33 const bool kExtensionRestricted = false; |
(...skipping 12 matching lines...) Expand all Loading... | |
43 | 46 |
44 const char kChatAppURL1[] = "https://foo.talkgadget.google.com/hangouts/foo"; | 47 const char kChatAppURL1[] = "https://foo.talkgadget.google.com/hangouts/foo"; |
45 const char kChatAppURL2[] = "https://foo.plus.google.com/hangouts/foo"; | 48 const char kChatAppURL2[] = "https://foo.plus.google.com/hangouts/foo"; |
46 const char kChatAppURL3[] = "https://foo.plus.sandbox.google.com/hangouts/foo"; | 49 const char kChatAppURL3[] = "https://foo.plus.sandbox.google.com/hangouts/foo"; |
47 const char kChatManifestFS1[] = | 50 const char kChatManifestFS1[] = |
48 "filesystem:https://foo.talkgadget.google.com/foo"; | 51 "filesystem:https://foo.talkgadget.google.com/foo"; |
49 const char kChatManifestFS2[] = "filesystem:https://foo.plus.google.com/foo"; | 52 const char kChatManifestFS2[] = "filesystem:https://foo.plus.google.com/foo"; |
50 const char kChatManifestFS3[] = | 53 const char kChatManifestFS3[] = |
51 "filesystem:https://foo.plus.sandbox.google.com/foo"; | 54 "filesystem:https://foo.plus.sandbox.google.com/foo"; |
52 | 55 |
56 #if !defined(DISABLE_NACL) | |
53 bool AllowsDevInterfaces(const WebPluginParams& params) { | 57 bool AllowsDevInterfaces(const WebPluginParams& params) { |
54 for (size_t i = 0; i < params.attributeNames.size(); ++i) { | 58 for (size_t i = 0; i < params.attributeNames.size(); ++i) { |
55 if (params.attributeNames[i] == WebString::fromUTF8("@dev")) | 59 if (params.attributeNames[i] == WebString::fromUTF8("@dev")) |
56 return true; | 60 return true; |
57 } | 61 } |
58 return false; | 62 return false; |
59 } | 63 } |
60 | 64 |
61 void AddFakeDevAttribute(WebPluginParams* params) { | 65 void AddFakeDevAttribute(WebPluginParams* params) { |
62 WebVector<WebString> names(static_cast<size_t>(1)); | 66 WebVector<WebString> names(static_cast<size_t>(1)); |
63 WebVector<WebString> values(static_cast<size_t>(1)); | 67 WebVector<WebString> values(static_cast<size_t>(1)); |
64 names[0] = WebString::fromUTF8("@dev"); | 68 names[0] = WebString::fromUTF8("@dev"); |
65 values[0] = WebString(); | 69 values[0] = WebString(); |
66 params->attributeNames.swap(names); | 70 params->attributeNames.swap(names); |
67 params->attributeValues.swap(values); | 71 params->attributeValues.swap(values); |
68 } | 72 } |
73 #endif | |
69 | 74 |
70 void AddContentTypeHandler(content::WebPluginInfo* info, | 75 void AddContentTypeHandler(content::WebPluginInfo* info, |
71 const char* mime_type, | 76 const char* mime_type, |
72 const char* manifest_url) { | 77 const char* manifest_url) { |
73 content::WebPluginMimeType mime_type_info; | 78 content::WebPluginMimeType mime_type_info; |
74 mime_type_info.mime_type = mime_type; | 79 mime_type_info.mime_type = mime_type; |
75 mime_type_info.additional_param_names.push_back(base::UTF8ToUTF16("nacl")); | 80 mime_type_info.additional_param_names.push_back(base::UTF8ToUTF16("nacl")); |
76 mime_type_info.additional_param_values.push_back( | 81 mime_type_info.additional_param_values.push_back( |
77 base::UTF8ToUTF16(manifest_url)); | 82 base::UTF8ToUTF16(manifest_url)); |
78 info->mime_types.push_back(mime_type_info); | 83 info->mime_types.push_back(mime_type_info); |
79 } | 84 } |
80 } // namespace | 85 } // namespace |
81 | 86 |
82 typedef testing::Test ChromeContentRendererClientTest; | 87 typedef testing::Test ChromeContentRendererClientTest; |
83 | 88 |
84 | 89 |
90 #if defined(ENABLE_EXTENSIONS) | |
85 scoped_refptr<const extensions::Extension> CreateTestExtension( | 91 scoped_refptr<const extensions::Extension> CreateTestExtension( |
86 bool is_unrestricted, bool is_from_webstore, bool is_hosted_app, | 92 bool is_unrestricted, bool is_from_webstore, bool is_hosted_app, |
87 const std::string& app_url) { | 93 const std::string& app_url) { |
88 extensions::Manifest::Location location = is_unrestricted ? | 94 extensions::Manifest::Location location = is_unrestricted ? |
89 extensions::Manifest::UNPACKED : | 95 extensions::Manifest::UNPACKED : |
90 extensions::Manifest::INTERNAL; | 96 extensions::Manifest::INTERNAL; |
91 int flags = is_from_webstore ? | 97 int flags = is_from_webstore ? |
92 extensions::Extension::FROM_WEBSTORE: | 98 extensions::Extension::FROM_WEBSTORE: |
93 extensions::Extension::NO_FLAGS; | 99 extensions::Extension::NO_FLAGS; |
94 | 100 |
(...skipping 16 matching lines...) Expand all Loading... | |
111 bool is_unrestricted, bool is_from_webstore) { | 117 bool is_unrestricted, bool is_from_webstore) { |
112 return CreateTestExtension( | 118 return CreateTestExtension( |
113 is_unrestricted, is_from_webstore, kNotHostedApp, std::string()); | 119 is_unrestricted, is_from_webstore, kNotHostedApp, std::string()); |
114 } | 120 } |
115 | 121 |
116 scoped_refptr<const extensions::Extension> CreateHostedApp( | 122 scoped_refptr<const extensions::Extension> CreateHostedApp( |
117 bool is_unrestricted, bool is_from_webstore, const std::string& app_url) { | 123 bool is_unrestricted, bool is_from_webstore, const std::string& app_url) { |
118 return CreateTestExtension(is_unrestricted, is_from_webstore, kHostedApp, | 124 return CreateTestExtension(is_unrestricted, is_from_webstore, kHostedApp, |
119 app_url); | 125 app_url); |
120 } | 126 } |
127 #endif // defined(ENABLE_EXTENSIONS) | |
121 | 128 |
122 TEST_F(ChromeContentRendererClientTest, NaClRestriction) { | 129 TEST_F(ChromeContentRendererClientTest, NaClRestriction) { |
123 // Unknown content types have no NaCl module. | 130 // Unknown content types have no NaCl module. |
124 { | 131 { |
125 WebPluginInfo info; | 132 WebPluginInfo info; |
126 EXPECT_EQ(GURL(), | 133 EXPECT_EQ(GURL(), |
127 ChromeContentRendererClient::GetNaClContentHandlerURL( | 134 ChromeContentRendererClient::GetNaClContentHandlerURL( |
128 "application/x-foo", info)); | 135 "application/x-foo", info)); |
129 } | 136 } |
130 // Known content types have a NaCl module. | 137 // Known content types have a NaCl module. |
131 { | 138 { |
132 WebPluginInfo info; | 139 WebPluginInfo info; |
133 AddContentTypeHandler(&info, "application/x-foo", "www.foo.com"); | 140 AddContentTypeHandler(&info, "application/x-foo", "www.foo.com"); |
134 EXPECT_EQ(GURL("www.foo.com"), | 141 EXPECT_EQ(GURL("www.foo.com"), |
135 ChromeContentRendererClient::GetNaClContentHandlerURL( | 142 ChromeContentRendererClient::GetNaClContentHandlerURL( |
136 "application/x-foo", info)); | 143 "application/x-foo", info)); |
137 } | 144 } |
145 #if !defined(DISABLE_NACL) | |
138 // --enable-nacl allows all NaCl apps, with 'dev' interfaces. | 146 // --enable-nacl allows all NaCl apps, with 'dev' interfaces. |
139 { | 147 { |
140 WebPluginParams params; | 148 WebPluginParams params; |
141 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( | 149 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( |
142 GURL(), | 150 GURL(), |
143 GURL(), | 151 GURL(), |
144 kNaClUnrestricted, | 152 kNaClUnrestricted, |
145 CreateExtension(kExtensionRestricted, kExtensionNotFromWebStore).get(), | 153 CreateExtension(kExtensionRestricted, kExtensionNotFromWebStore).get(), |
146 ¶ms)); | 154 ¶ms)); |
147 EXPECT_TRUE(AllowsDevInterfaces(params)); | 155 EXPECT_TRUE(AllowsDevInterfaces(params)); |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
365 ¶ms)); | 373 ¶ms)); |
366 EXPECT_FALSE(ChromeContentRendererClient::IsNaClAllowed( | 374 EXPECT_FALSE(ChromeContentRendererClient::IsNaClAllowed( |
367 GURL(), | 375 GURL(), |
368 GURL("http://example.evil.com/test.html"), | 376 GURL("http://example.evil.com/test.html"), |
369 kNaClRestricted, | 377 kNaClRestricted, |
370 CreateHostedApp(kExtensionRestricted, | 378 CreateHostedApp(kExtensionRestricted, |
371 kExtensionNotFromWebStore, | 379 kExtensionNotFromWebStore, |
372 "http://example.com/").get(), | 380 "http://example.com/").get(), |
373 ¶ms)); | 381 ¶ms)); |
374 } | 382 } |
383 #endif // !defined(DISABLE_NACL) | |
375 } | 384 } |
376 | 385 |
377 TEST_F(ChromeContentRendererClientTest, AllowPepperMediaStreamAPI) { | 386 TEST_F(ChromeContentRendererClientTest, AllowPepperMediaStreamAPI) { |
378 ChromeContentRendererClient test; | 387 ChromeContentRendererClient test; |
379 #if !defined(OS_ANDROID) | 388 #if !defined(OS_ANDROID) |
380 EXPECT_TRUE(test.AllowPepperMediaStreamAPI(GURL(kChatAppURL1))); | 389 EXPECT_TRUE(test.AllowPepperMediaStreamAPI(GURL(kChatAppURL1))); |
381 EXPECT_TRUE(test.AllowPepperMediaStreamAPI(GURL(kChatAppURL2))); | 390 EXPECT_TRUE(test.AllowPepperMediaStreamAPI(GURL(kChatAppURL2))); |
382 EXPECT_TRUE(test.AllowPepperMediaStreamAPI(GURL(kChatAppURL3))); | 391 EXPECT_TRUE(test.AllowPepperMediaStreamAPI(GURL(kChatAppURL3))); |
383 #else | 392 #else |
384 EXPECT_FALSE(test.AllowPepperMediaStreamAPI(GURL(kChatAppURL1))); | 393 EXPECT_FALSE(test.AllowPepperMediaStreamAPI(GURL(kChatAppURL1))); |
385 EXPECT_FALSE(test.AllowPepperMediaStreamAPI(GURL(kChatAppURL2))); | 394 EXPECT_FALSE(test.AllowPepperMediaStreamAPI(GURL(kChatAppURL2))); |
386 EXPECT_FALSE(test.AllowPepperMediaStreamAPI(GURL(kChatAppURL3))); | 395 EXPECT_FALSE(test.AllowPepperMediaStreamAPI(GURL(kChatAppURL3))); |
387 #endif | 396 #endif |
388 EXPECT_FALSE(test.AllowPepperMediaStreamAPI( | 397 EXPECT_FALSE(test.AllowPepperMediaStreamAPI( |
389 GURL("http://talkgadget.google.com/hangouts/foo"))); | 398 GURL("http://talkgadget.google.com/hangouts/foo"))); |
390 EXPECT_FALSE(test.AllowPepperMediaStreamAPI( | 399 EXPECT_FALSE(test.AllowPepperMediaStreamAPI( |
391 GURL("https://talkgadget.evil.com/hangouts/foo"))); | 400 GURL("https://talkgadget.evil.com/hangouts/foo"))); |
392 } | 401 } |
393 | 402 |
394 TEST_F(ChromeContentRendererClientTest, ShouldSuppressErrorPage) { | 403 TEST_F(ChromeContentRendererClientTest, ShouldSuppressErrorPage) { |
395 ChromeContentRendererClient client; | 404 ChromeContentRendererClient client; |
396 client.search_bouncer_.reset(new SearchBouncer); | 405 client.search_bouncer_.reset(new SearchBouncer); |
397 client.search_bouncer_->OnSetSearchURLs( | 406 client.search_bouncer_->OnSetSearchURLs( |
398 std::vector<GURL>(), GURL("http://example.com/n")); | 407 std::vector<GURL>(), GURL("http://example.com/n")); |
399 EXPECT_FALSE(client.ShouldSuppressErrorPage(NULL, | 408 EXPECT_FALSE(client.ShouldSuppressErrorPage(NULL, |
400 GURL("http://example.com"))); | 409 GURL("http://example.com"))); |
401 EXPECT_TRUE(client.ShouldSuppressErrorPage(NULL, | 410 EXPECT_TRUE(client.ShouldSuppressErrorPage(NULL, |
402 GURL("http://example.com/n"))); | 411 GURL("http://example.com/n"))); |
403 } | 412 } |
OLD | NEW |