Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(976)

Side by Side Diff: chrome/renderer/chrome_content_renderer_client_unittest.cc

Issue 2001233002: Cherry-picking hangouts.google.com whitelisting change into M51 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2704
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/renderer/chrome_content_renderer_client.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <vector> 9 #include <vector>
10 10
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 #endif 46 #endif
47 47
48 #if defined(ENABLE_EXTENSIONS) 48 #if defined(ENABLE_EXTENSIONS)
49 const bool kNotHostedApp = false; 49 const bool kNotHostedApp = false;
50 const bool kHostedApp = true; 50 const bool kHostedApp = true;
51 #endif 51 #endif
52 52
53 #if !defined(DISABLE_NACL) 53 #if !defined(DISABLE_NACL)
54 const char kExtensionUrl[] = "chrome-extension://extension_id/background.html"; 54 const char kExtensionUrl[] = "chrome-extension://extension_id/background.html";
55 55
56 const char kPhotosAppURL1[] = "https://foo.plus.google.com"; 56 const char kPhotosAppURL[] = "https://foo.plus.google.com";
57 const char kPhotosAppURL2[] = "https://foo.plus.sandbox.google.com"; 57 const char kPhotosManifestURL[] = "https://ssl.gstatic.com/photos/nacl/foo";
58 const char kPhotosManifestURL1[] = "https://ssl.gstatic.com/s2/oz/nacl/foo"; 58
59 const char kPhotosManifestURL2[] = "https://ssl.gstatic.com/photos/nacl/foo"; 59 const char kChatManifestFS[] = "filesystem:https://talkgadget.google.com/foo";
60 const char kChatManifestFS1[] =
61 "filesystem:https://foo.talkgadget.google.com/foo";
62 const char kChatManifestFS2[] = "filesystem:https://foo.plus.google.com/foo";
63 const char kChatManifestFS3[] =
64 "filesystem:https://foo.plus.sandbox.google.com/foo";
65 #endif 60 #endif
66 61
67 const char kChatAppURL1[] = "https://foo.talkgadget.google.com/hangouts/foo"; 62 const char kChatAppURL[] = "https://talkgadget.google.com/hangouts/foo";
68 const char kChatAppURL2[] = "https://foo.plus.google.com/hangouts/foo";
69 const char kChatAppURL3[] = "https://foo.plus.sandbox.google.com/hangouts/foo";
70 63
71 #if !defined(DISABLE_NACL) 64 #if !defined(DISABLE_NACL)
72 bool AllowsDevInterfaces(const WebPluginParams& params) { 65 bool AllowsDevInterfaces(const WebPluginParams& params) {
73 for (size_t i = 0; i < params.attributeNames.size(); ++i) { 66 for (size_t i = 0; i < params.attributeNames.size(); ++i) {
74 if (params.attributeNames[i] == "@dev") 67 if (params.attributeNames[i] == "@dev")
75 return true; 68 return true;
76 } 69 }
77 return false; 70 return false;
78 } 71 }
79 72
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 &params)); 264 &params));
272 EXPECT_FALSE(AllowsDevInterfaces(params)); 265 EXPECT_FALSE(AllowsDevInterfaces(params));
273 } 266 }
274 267
275 // Whitelisted URLs are allowed without --enable-nacl, without 'dev' 268 // Whitelisted URLs are allowed without --enable-nacl, without 'dev'
276 // interfaces. There is a whitelist for the app URL and the manifest URL. 269 // interfaces. There is a whitelist for the app URL and the manifest URL.
277 { 270 {
278 WebPluginParams params; 271 WebPluginParams params;
279 // Whitelisted Photos app is allowed (two app URLs, two manifest URLs) 272 // Whitelisted Photos app is allowed (two app URLs, two manifest URLs)
280 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( 273 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed(
281 GURL(kPhotosManifestURL1), 274 GURL(kPhotosManifestURL),
282 GURL(kPhotosAppURL1), 275 GURL(kPhotosAppURL),
283 kNaClRestricted, 276 kNaClRestricted,
284 nullptr, 277 nullptr,
285 &params)); 278 &params));
286 EXPECT_FALSE(AllowsDevInterfaces(params)); 279 EXPECT_FALSE(AllowsDevInterfaces(params));
287 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( 280
288 GURL(kPhotosManifestURL1),
289 GURL(kPhotosAppURL2),
290 kNaClRestricted,
291 nullptr,
292 &params));
293 EXPECT_FALSE(AllowsDevInterfaces(params));
294 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed(
295 GURL(kPhotosManifestURL2),
296 GURL(kPhotosAppURL1),
297 kNaClRestricted,
298 nullptr,
299 &params));
300 EXPECT_FALSE(AllowsDevInterfaces(params));
301 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed(
302 GURL(kPhotosManifestURL2),
303 GURL(kPhotosAppURL2),
304 kNaClRestricted,
305 nullptr,
306 &params));
307 EXPECT_FALSE(AllowsDevInterfaces(params));
308 // Whitelisted Chat app is allowed. 281 // Whitelisted Chat app is allowed.
309 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( 282 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed(
310 GURL(kChatManifestFS1), 283 GURL(kChatManifestFS),
311 GURL(kChatAppURL1), 284 GURL(kChatAppURL),
312 kNaClRestricted,
313 nullptr,
314 &params));
315 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed(
316 GURL(kChatManifestFS2),
317 GURL(kChatAppURL2),
318 kNaClRestricted,
319 nullptr,
320 &params));
321 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed(
322 GURL(kChatManifestFS3),
323 GURL(kChatAppURL3),
324 kNaClRestricted, 285 kNaClRestricted,
325 nullptr, 286 nullptr,
326 &params)); 287 &params));
327 288
328 // Whitelisted manifest URL, bad app URLs, NOT allowed. 289 // Whitelisted manifest URL, bad app URLs, NOT allowed.
329 EXPECT_FALSE(ChromeContentRendererClient::IsNaClAllowed( 290 EXPECT_FALSE(ChromeContentRendererClient::IsNaClAllowed(
330 GURL(kPhotosManifestURL1), 291 GURL(kPhotosManifestURL),
331 GURL("http://plus.google.com/foo"), // http scheme 292 GURL("http://plus.google.com/foo"), // http scheme
332 kNaClRestricted, 293 kNaClRestricted,
333 nullptr, 294 nullptr,
334 &params)); 295 &params));
335 EXPECT_FALSE(ChromeContentRendererClient::IsNaClAllowed( 296 EXPECT_FALSE(ChromeContentRendererClient::IsNaClAllowed(
336 GURL(kPhotosManifestURL1), 297 GURL(kPhotosManifestURL),
337 GURL("http://plus.sandbox.google.com/foo"), // http scheme 298 GURL("http://plus.sandbox.google.com/foo"), // http scheme
338 kNaClRestricted, 299 kNaClRestricted,
339 nullptr, 300 nullptr,
340 &params)); 301 &params));
341 EXPECT_FALSE(ChromeContentRendererClient::IsNaClAllowed( 302 EXPECT_FALSE(ChromeContentRendererClient::IsNaClAllowed(
342 GURL(kPhotosManifestURL1), 303 GURL(kPhotosManifestURL),
343 GURL("https://plus.google.evil.com/foo"), // bad host 304 GURL("https://plus.google.evil.com/foo"), // bad host
344 kNaClRestricted, 305 kNaClRestricted,
345 nullptr, 306 nullptr,
346 &params)); 307 &params));
347 // Whitelisted app URL, bad manifest URL, NOT allowed. 308 // Whitelisted app URL, bad manifest URL, NOT allowed.
348 EXPECT_FALSE(ChromeContentRendererClient::IsNaClAllowed( 309 EXPECT_FALSE(ChromeContentRendererClient::IsNaClAllowed(
349 GURL("http://ssl.gstatic.com/s2/oz/nacl/foo"), // http scheme 310 GURL("http://ssl.gstatic.com/s2/oz/nacl/foo"), // http scheme
350 GURL(kPhotosAppURL1), 311 GURL(kPhotosAppURL),
351 kNaClRestricted, 312 kNaClRestricted,
352 nullptr, 313 nullptr,
353 &params)); 314 &params));
354 EXPECT_FALSE(ChromeContentRendererClient::IsNaClAllowed( 315 EXPECT_FALSE(ChromeContentRendererClient::IsNaClAllowed(
355 GURL("https://ssl.gstatic.evil.com/s2/oz/nacl/foo"), // bad host 316 GURL("https://ssl.gstatic.evil.com/s2/oz/nacl/foo"), // bad host
356 GURL(kPhotosAppURL1), 317 GURL(kPhotosAppURL),
357 kNaClRestricted, 318 kNaClRestricted,
358 nullptr, 319 nullptr,
359 &params)); 320 &params));
360 EXPECT_FALSE(ChromeContentRendererClient::IsNaClAllowed( 321 EXPECT_FALSE(ChromeContentRendererClient::IsNaClAllowed(
361 GURL("https://ssl.gstatic.com/wrong/s2/oz/nacl/foo"), // bad path 322 GURL("https://ssl.gstatic.com/wrong/s2/oz/nacl/foo"), // bad path
362 GURL(kPhotosAppURL1), 323 GURL(kPhotosAppURL),
363 kNaClRestricted, 324 kNaClRestricted,
364 nullptr, 325 nullptr,
365 &params)); 326 &params));
366 } 327 }
367 // Whitelisted URLs can't get 'dev' interfaces with --enable-nacl. 328 // Whitelisted URLs can't get 'dev' interfaces with --enable-nacl.
368 { 329 {
369 WebPluginParams params; 330 WebPluginParams params;
370 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( 331 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed(
371 GURL(kPhotosManifestURL1), 332 GURL(kPhotosManifestURL),
372 GURL(kPhotosAppURL1), 333 GURL(kPhotosAppURL),
373 kNaClUnrestricted, 334 kNaClUnrestricted,
374 nullptr, 335 nullptr,
375 &params)); 336 &params));
376 EXPECT_FALSE(AllowsDevInterfaces(params)); 337 EXPECT_FALSE(AllowsDevInterfaces(params));
377 } 338 }
378 // Whitelisted URLs can't get 'dev' interfaces by injecting a fake 339 // Whitelisted URLs can't get 'dev' interfaces by injecting a fake
379 // '@dev' attribute. 340 // '@dev' attribute.
380 { 341 {
381 WebPluginParams params; 342 WebPluginParams params;
382 AddFakeDevAttribute(&params); 343 AddFakeDevAttribute(&params);
383 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( 344 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed(
384 GURL(kPhotosManifestURL1), 345 GURL(kPhotosManifestURL),
385 GURL(kPhotosAppURL1), 346 GURL(kPhotosAppURL),
386 kNaClRestricted, 347 kNaClRestricted,
387 nullptr, 348 nullptr,
388 &params)); 349 &params));
389 EXPECT_FALSE(AllowsDevInterfaces(params)); 350 EXPECT_FALSE(AllowsDevInterfaces(params));
390 } 351 }
391 // Non-whitelisted URLs are blocked without --enable-nacl. 352 // Non-whitelisted URLs are blocked without --enable-nacl.
392 { 353 {
393 WebPluginParams params; 354 WebPluginParams params;
394 EXPECT_FALSE(ChromeContentRendererClient::IsNaClAllowed( 355 EXPECT_FALSE(ChromeContentRendererClient::IsNaClAllowed(
395 GURL(), 356 GURL(),
(...skipping 26 matching lines...) Expand all
422 kNaClRestricted, 383 kNaClRestricted,
423 CreateHostedApp(kExtensionNotFromWebStore, 384 CreateHostedApp(kExtensionNotFromWebStore,
424 "http://example.com/").get(), 385 "http://example.com/").get(),
425 &params)); 386 &params));
426 } 387 }
427 #endif // !defined(DISABLE_NACL) 388 #endif // !defined(DISABLE_NACL)
428 } 389 }
429 390
430 TEST_F(ChromeContentRendererClientTest, AllowPepperMediaStreamAPI) { 391 TEST_F(ChromeContentRendererClientTest, AllowPepperMediaStreamAPI) {
431 ChromeContentRendererClient test; 392 ChromeContentRendererClient test;
432 #if !defined(OS_ANDROID) 393 #if defined(OS_ANDROID)
433 EXPECT_TRUE(test.AllowPepperMediaStreamAPI(GURL(kChatAppURL1))); 394 EXPECT_FALSE(test.AllowPepperMediaStreamAPI(GURL(kChatAppURL)));
434 EXPECT_TRUE(test.AllowPepperMediaStreamAPI(GURL(kChatAppURL2)));
435 EXPECT_TRUE(test.AllowPepperMediaStreamAPI(GURL(kChatAppURL3)));
436 #else 395 #else
437 EXPECT_FALSE(test.AllowPepperMediaStreamAPI(GURL(kChatAppURL1))); 396 EXPECT_TRUE(test.AllowPepperMediaStreamAPI(GURL(kChatAppURL)));
438 EXPECT_FALSE(test.AllowPepperMediaStreamAPI(GURL(kChatAppURL2)));
439 EXPECT_FALSE(test.AllowPepperMediaStreamAPI(GURL(kChatAppURL3)));
440 #endif 397 #endif
441 EXPECT_FALSE(test.AllowPepperMediaStreamAPI(
442 GURL("http://talkgadget.google.com/hangouts/foo")));
443 EXPECT_FALSE(test.AllowPepperMediaStreamAPI(
444 GURL("https://talkgadget.evil.com/hangouts/foo")));
445 } 398 }
446 399
447 TEST_F(ChromeContentRendererClientTest, ShouldSuppressErrorPage) { 400 TEST_F(ChromeContentRendererClientTest, ShouldSuppressErrorPage) {
448 ChromeContentRendererClient client; 401 ChromeContentRendererClient client;
449 SearchBouncer::GetInstance()->OnSetSearchURLs( 402 SearchBouncer::GetInstance()->OnSetSearchURLs(
450 std::vector<GURL>(), GURL("http://example.com/n")); 403 std::vector<GURL>(), GURL("http://example.com/n"));
451 EXPECT_FALSE(client.ShouldSuppressErrorPage(nullptr, 404 EXPECT_FALSE(client.ShouldSuppressErrorPage(nullptr,
452 GURL("http://example.com"))); 405 GURL("http://example.com")));
453 EXPECT_TRUE(client.ShouldSuppressErrorPage(nullptr, 406 EXPECT_TRUE(client.ShouldSuppressErrorPage(nullptr,
454 GURL("http://example.com/n"))); 407 GURL("http://example.com/n")));
455 SearchBouncer::GetInstance()->OnSetSearchURLs( 408 SearchBouncer::GetInstance()->OnSetSearchURLs(
456 std::vector<GURL>(), GURL::EmptyGURL()); 409 std::vector<GURL>(), GURL::EmptyGURL());
457 } 410 }
OLDNEW
« no previous file with comments | « chrome/renderer/chrome_content_renderer_client.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698