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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
404 SearchBouncer::GetInstance()->OnSetSearchURLs( | 404 SearchBouncer::GetInstance()->OnSetSearchURLs( |
405 std::vector<GURL>(), GURL("http://example.com/n")); | 405 std::vector<GURL>(), GURL("http://example.com/n")); |
406 EXPECT_FALSE(client.ShouldSuppressErrorPage(nullptr, | 406 EXPECT_FALSE(client.ShouldSuppressErrorPage(nullptr, |
407 GURL("http://example.com"))); | 407 GURL("http://example.com"))); |
408 EXPECT_TRUE(client.ShouldSuppressErrorPage(nullptr, | 408 EXPECT_TRUE(client.ShouldSuppressErrorPage(nullptr, |
409 GURL("http://example.com/n"))); | 409 GURL("http://example.com/n"))); |
410 SearchBouncer::GetInstance()->OnSetSearchURLs( | 410 SearchBouncer::GetInstance()->OnSetSearchURLs( |
411 std::vector<GURL>(), GURL::EmptyGURL()); | 411 std::vector<GURL>(), GURL::EmptyGURL()); |
412 } | 412 } |
413 | 413 |
414 TEST_F(ChromeContentRendererClientTest, RewriteYouTubeFlashEmbed) { | 414 // These are tests that are common for both Android and desktop browsers. |
415 TEST_F(ChromeContentRendererClientTest, RewriteEmbedCommon) { | |
415 struct TestData { | 416 struct TestData { |
416 std::string original; | 417 std::string original; |
417 std::string expected; | 418 std::string expected; |
418 } test_data[] = { | 419 } test_data[] = { |
419 // { original, expected } | 420 // { original, expected } |
420 {"youtube.com", ""}, | 421 {"youtube.com", ""}, |
421 {"www.youtube.com", ""}, | 422 {"www.youtube.com", ""}, |
422 {"http://www.youtube.com", ""}, | 423 {"http://www.youtube.com", ""}, |
423 {"https://www.youtube.com", ""}, | 424 {"https://www.youtube.com", ""}, |
424 {"http://www.foo.youtube.com", ""}, | 425 {"http://www.foo.youtube.com", ""}, |
425 {"https://www.foo.youtube.com", ""}, | 426 {"https://www.foo.youtube.com", ""}, |
426 // Non-YouTube domains shouldn't be modified | 427 // Non-YouTube domains shouldn't be modified |
427 {"http://www.plus.google.com", ""}, | 428 {"http://www.plus.google.com", ""}, |
428 // URL isn't using Flash | 429 // URL isn't using Flash |
429 {"http://www.youtube.com/embed/deadbeef", ""}, | 430 {"http://www.youtube.com/embed/deadbeef", ""}, |
430 // URL isn't using Flash, no www | 431 // URL isn't using Flash, no www |
431 {"http://youtube.com/embed/deadbeef", ""}, | 432 {"http://youtube.com/embed/deadbeef", ""}, |
432 // URL isn't using Flash, has JS API enabled | |
433 {"http://www.youtube.com/embed/deadbeef?enablejsapi=1", ""}, | |
434 // URL isn't using Flash, invalid parameter construct | 433 // URL isn't using Flash, invalid parameter construct |
435 {"http://www.youtube.com/embed/deadbeef&start=4", ""}, | 434 {"http://www.youtube.com/embed/deadbeef&start=4", ""}, |
436 // URL is using Flash, no www | 435 // URL is using Flash, no www |
437 {"http://youtube.com/v/deadbeef", "http://youtube.com/embed/deadbeef"}, | 436 {"http://youtube.com/v/deadbeef", "http://youtube.com/embed/deadbeef"}, |
438 // URL is using Flash, has JS API enabled | |
439 {"http://www.youtube.com/v/deadbeef?enablejsapi=1", ""}, | |
440 // URL is using Flash, is valid, https | 437 // URL is using Flash, is valid, https |
441 {"https://www.youtube.com/v/deadbeef", | 438 {"https://www.youtube.com/v/deadbeef", |
442 "https://www.youtube.com/embed/deadbeef"}, | 439 "https://www.youtube.com/embed/deadbeef"}, |
443 // URL is using Flash, is valid, http | 440 // URL is using Flash, is valid, http |
444 {"http://www.youtube.com/v/deadbeef", | 441 {"http://www.youtube.com/v/deadbeef", |
445 "http://www.youtube.com/embed/deadbeef"}, | 442 "http://www.youtube.com/embed/deadbeef"}, |
446 // URL is using Flash, is valid, not a complete URL, no www or protocol | 443 // URL is using Flash, is valid, not a complete URL, no www or protocol |
447 {"youtube.com/v/deadbeef", ""}, | 444 {"youtube.com/v/deadbeef", ""}, |
448 // URL is using Flash, is valid, not a complete URL,or protocol | 445 // URL is using Flash, is valid, not a complete URL,or protocol |
449 {"www.youtube.com/v/deadbeef", ""}, | 446 {"www.youtube.com/v/deadbeef", ""}, |
(...skipping 21 matching lines...) Expand all Loading... | |
471 {"http://www.youtube.com/abcd/v/deadbeef", ""}, | 468 {"http://www.youtube.com/abcd/v/deadbeef", ""}, |
472 // Invalid parameter construct | 469 // Invalid parameter construct |
473 {"http://www.youtube.com/v/abcd/", "http://www.youtube.com/embed/abcd/"}, | 470 {"http://www.youtube.com/v/abcd/", "http://www.youtube.com/embed/abcd/"}, |
474 // Invalid parameter construct | 471 // Invalid parameter construct |
475 {"http://www.youtube.com/v/123/", "http://www.youtube.com/embed/123/"}, | 472 {"http://www.youtube.com/v/123/", "http://www.youtube.com/embed/123/"}, |
476 // youtube-nocookie.com | 473 // youtube-nocookie.com |
477 {"http://www.youtube-nocookie.com/v/123/", | 474 {"http://www.youtube-nocookie.com/v/123/", |
478 "http://www.youtube-nocookie.com/embed/123/"}, | 475 "http://www.youtube-nocookie.com/embed/123/"}, |
479 // youtube-nocookie.com, isn't using flash | 476 // youtube-nocookie.com, isn't using flash |
480 {"http://www.youtube-nocookie.com/embed/123/", ""}, | 477 {"http://www.youtube-nocookie.com/embed/123/", ""}, |
481 // youtube-nocookie.com, has JS API enabled | |
482 {"http://www.youtube-nocookie.com/v/123?enablejsapi=1", ""}, | |
483 // youtube-nocookie.com, has one parameter | 478 // youtube-nocookie.com, has one parameter |
484 {"http://www.youtube-nocookie.com/v/123?start=foo", | 479 {"http://www.youtube-nocookie.com/v/123?start=foo", |
485 "http://www.youtube-nocookie.com/embed/123?start=foo"}, | 480 "http://www.youtube-nocookie.com/embed/123?start=foo"}, |
486 // youtube-nocookie.com, has multiple parameters | 481 // youtube-nocookie.com, has multiple parameters |
487 {"http://www.youtube-nocookie.com/v/123?start=foo&bar=baz", | 482 {"http://www.youtube-nocookie.com/v/123?start=foo&bar=baz", |
488 "http://www.youtube-nocookie.com/embed/123?start=foo&bar=baz"}, | 483 "http://www.youtube-nocookie.com/embed/123?start=foo&bar=baz"}, |
489 // youtube-nocookie.com, invalid parameter construct, has one parameter | 484 // youtube-nocookie.com, invalid parameter construct, has one parameter |
490 {"http://www.youtube-nocookie.com/v/123&start=foo", | 485 {"http://www.youtube-nocookie.com/v/123&start=foo", |
491 "http://www.youtube-nocookie.com/embed/123?start=foo"}, | 486 "http://www.youtube-nocookie.com/embed/123?start=foo"}, |
492 // youtube-nocookie.com, invalid parameter construct, has multiple | 487 // youtube-nocookie.com, invalid parameter construct, has multiple |
493 // parameters | 488 // parameters |
494 {"http://www.youtube-nocookie.com/v/123&start=foo&bar=baz", | 489 {"http://www.youtube-nocookie.com/v/123&start=foo&bar=baz", |
495 "http://www.youtube-nocookie.com/embed/123?start=foo&bar=baz"}, | 490 "http://www.youtube-nocookie.com/embed/123?start=foo&bar=baz"}, |
496 // youtube-nocookie.com, https | 491 // youtube-nocookie.com, https |
497 {"https://www.youtube-nocookie.com/v/123/", | 492 {"https://www.youtube-nocookie.com/v/123/", |
498 "https://www.youtube-nocookie.com/embed/123/"}, | 493 "https://www.youtube-nocookie.com/embed/123/"}, |
499 }; | 494 }; |
500 | 495 |
501 ChromeContentRendererClient client; | 496 ChromeContentRendererClient client; |
502 | 497 |
503 for (const auto& data : test_data) | 498 for (const auto& data : test_data) |
504 EXPECT_EQ(GURL(data.expected), | 499 EXPECT_EQ(GURL(data.expected), |
505 client.OverrideFlashEmbedWithHTML(GURL(data.original))); | 500 client.OverrideFlashEmbedWithHTML(GURL(data.original))); |
506 } | 501 } |
507 | 502 |
503 TEST_F(ChromeContentRendererClientTest, RewriteEmbedAndroid) { | |
504 #if defined(OS_ANDROID) | |
mlamouri (slow - plz ping)
2016/08/08 19:50:25
Maybe better to put the ifdef outside of TEST_F()
kdsilva
2016/08/09 10:56:27
Done.
| |
505 struct TestData { | |
506 std::string original; | |
507 std::string expected; | |
508 } test_data[] = { | |
509 // URL isn't using Flash, has JS API enabled | |
510 {"http://www.youtube.com/embed/deadbeef?enablejsapi=1", ""}, | |
511 // URL is using Flash, has JS API enabled | |
512 {"http://www.youtube.com/v/deadbeef?enablejsapi=1", | |
513 "http://www.youtube.com/embed/deadbeef?enablejsapi=1"}, | |
514 // youtube-nocookie.com, has JS API enabled | |
515 {"http://www.youtube-nocookie.com/v/123?enablejsapi=1", | |
516 "http://www.youtube-nocookie.com/embed/123?enablejsapi=1"}, | |
517 // URL is using Flash, has JS API enabled, invalid parameter construct | |
518 {"http://www.youtube.com/v/deadbeef&enablejsapi=1", | |
519 "http://www.youtube.com/embed/deadbeef?enablejsapi=1"}, | |
520 // URL is using Flash, has JS API enabled, invalid parameter construct, | |
521 // has multiple parameters | |
522 {"http://www.youtube.com/v/deadbeef&start=4&enablejsapi=1", | |
523 "http://www.youtube.com/embed/deadbeef?start=4&enablejsapi=1"}, | |
524 }; | |
525 | |
526 ChromeContentRendererClient client; | |
527 | |
528 for (const auto& data : test_data) | |
529 EXPECT_EQ(GURL(data.expected), | |
530 client.OverrideFlashEmbedWithHTML(GURL(data.original))); | |
531 #endif | |
532 } | |
533 | |
534 TEST_F(ChromeContentRendererClientTest, RewriteEmbedDesktop) { | |
535 #if !defined(OS_ANDROID) | |
mlamouri (slow - plz ping)
2016/08/08 19:50:25
ditto, you could even have a #else
kdsilva
2016/08/09 10:56:27
Done.
| |
536 struct TestData { | |
537 std::string original; | |
538 std::string expected; | |
539 } test_data[] = { | |
540 // URL isn't using Flash, has JS API enabled | |
541 {"http://www.youtube.com/embed/deadbeef?enablejsapi=1", ""}, | |
542 // URL is using Flash, has JS API enabled | |
543 {"http://www.youtube.com/v/deadbeef?enablejsapi=1", ""}, | |
544 // youtube-nocookie.com, has JS API enabled | |
545 {"http://www.youtube-nocookie.com/v/123?enablejsapi=1", ""}, | |
546 // URL is using Flash, has JS API enabled, invalid parameter construct | |
547 {"http://www.youtube.com/v/deadbeef&enablejsapi=1", ""}, | |
548 // URL is using Flash, has JS API enabled, invalid parameter construct, | |
549 // has multiple parameters | |
550 {"http://www.youtube.com/v/deadbeef&start=4&enablejsapi=1", ""}, | |
551 }; | |
552 | |
553 ChromeContentRendererClient client; | |
554 | |
555 for (const auto& data : test_data) | |
556 EXPECT_EQ(GURL(data.expected), | |
557 client.OverrideFlashEmbedWithHTML(GURL(data.original))); | |
558 #endif | |
559 } | |
560 | |
508 class ChromeContentRendererClientMetricsTest : public testing::Test { | 561 class ChromeContentRendererClientMetricsTest : public testing::Test { |
509 public: | 562 public: |
510 ChromeContentRendererClientMetricsTest() = default; | 563 ChromeContentRendererClientMetricsTest() = default; |
511 | 564 |
512 std::unique_ptr<base::HistogramSamples> GetHistogramSamples() { | 565 std::unique_ptr<base::HistogramSamples> GetHistogramSamples() { |
513 return histogram_tester_.GetHistogramSamplesSinceCreation( | 566 return histogram_tester_.GetHistogramSamplesSinceCreation( |
514 internal::kFlashYouTubeRewriteUMA); | 567 internal::kFlashYouTubeRewriteUMA); |
515 } | 568 } |
516 | 569 |
517 void OverrideFlashEmbed(const GURL& gurl) { | 570 void OverrideFlashEmbed(const GURL& gurl) { |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
614 } | 667 } |
615 | 668 |
616 // Invalid parameter construct, not flash | 669 // Invalid parameter construct, not flash |
617 GURL gurl = GURL("http://www.youtube.com/embed/deadbeef&start=4"); | 670 GURL gurl = GURL("http://www.youtube.com/embed/deadbeef&start=4"); |
618 OverrideFlashEmbed(gurl); | 671 OverrideFlashEmbed(gurl); |
619 samples = GetHistogramSamples(); | 672 samples = GetHistogramSamples(); |
620 EXPECT_EQ(total_count, samples->GetCount(internal::SUCCESS_PARAMS_REWRITE)); | 673 EXPECT_EQ(total_count, samples->GetCount(internal::SUCCESS_PARAMS_REWRITE)); |
621 EXPECT_EQ(total_count, samples->TotalCount()); | 674 EXPECT_EQ(total_count, samples->TotalCount()); |
622 } | 675 } |
623 | 676 |
624 TEST_F(ChromeContentRendererClientMetricsTest, RewriteEmbedFailureJSAPI) { | 677 TEST_F(ChromeContentRendererClientMetricsTest, |
678 RewriteEmbedFailureJSAPIDesktop) { | |
679 #if !defined(OS_ANDROID) | |
625 ChromeContentRendererClient client; | 680 ChromeContentRendererClient client; |
626 | 681 |
627 std::unique_ptr<base::HistogramSamples> samples = GetHistogramSamples(); | 682 std::unique_ptr<base::HistogramSamples> samples = GetHistogramSamples(); |
628 auto total_count = 0; | 683 auto total_count = 0; |
629 EXPECT_EQ(total_count, samples->TotalCount()); | 684 EXPECT_EQ(total_count, samples->TotalCount()); |
630 | 685 |
631 const std::string test_data[] = { | 686 const std::string test_data[] = { |
687 // Valid parameter construct, one parameter | |
688 "http://www.youtube.com/v/deadbeef?enablejsapi=1", | |
632 // Invalid parameter construct, one parameter | 689 // Invalid parameter construct, one parameter |
633 "http://www.youtube.com/v/deadbeef&enablejsapi=1", | 690 "http://www.youtube.com/v/deadbeef&enablejsapi=1", |
634 // Invalid parameter construct, has multiple parameters | 691 // Invalid parameter construct, has multiple parameters |
635 "http://www.youtube.com/v/deadbeef&start=4&enablejsapi=1?foo=2"}; | 692 "http://www.youtube.com/v/deadbeef&start=4&enablejsapi=1?foo=2"}; |
636 | 693 |
637 for (const auto& data : test_data) { | 694 for (const auto& data : test_data) { |
638 ++total_count; | 695 ++total_count; |
639 GURL gurl = GURL(data); | 696 GURL gurl = GURL(data); |
640 OverrideFlashEmbed(gurl); | 697 OverrideFlashEmbed(gurl); |
641 samples = GetHistogramSamples(); | 698 samples = GetHistogramSamples(); |
642 EXPECT_EQ(total_count, samples->GetCount(internal::FAILURE_ENABLEJSAPI)); | 699 EXPECT_EQ(total_count, samples->GetCount(internal::FAILURE_ENABLEJSAPI)); |
643 EXPECT_EQ(total_count, samples->TotalCount()); | 700 EXPECT_EQ(total_count, samples->TotalCount()); |
644 } | 701 } |
702 #endif | |
645 } | 703 } |
704 | |
705 TEST_F(ChromeContentRendererClientMetricsTest, | |
706 RewriteEmbedFailureJSAPIAndroid) { | |
707 #if defined(OS_ANDROID) | |
708 ChromeContentRendererClient client; | |
709 | |
710 std::unique_ptr<base::HistogramSamples> samples = GetHistogramSamples(); | |
711 auto total_count = 0; | |
712 EXPECT_EQ(total_count, samples->TotalCount()); | |
713 | |
714 const std::string test_data[] = { | |
715 // Valid parameter construct, one parameter | |
716 "http://www.youtube.com/v/deadbeef?enablejsapi=1", | |
717 // Valid parameter construct, has multiple parameters | |
718 "http://www.youtube.com/v/deadbeef?enablejsapi=1&foo=2", | |
719 // Invalid parameter construct, one parameter | |
720 "http://www.youtube.com/v/deadbeef&enablejsapi=1", | |
721 // Invalid parameter construct, has multiple parameters | |
722 "http://www.youtube.com/v/deadbeef&enablejsapi=1&foo=2"}; | |
723 | |
724 for (const auto& data : test_data) { | |
725 ++total_count; | |
726 GURL gurl = GURL(data); | |
727 OverrideFlashEmbed(gurl); | |
728 samples = GetHistogramSamples(); | |
729 EXPECT_EQ(total_count, samples->GetCount(internal::SUCCESS_ENABLEJSAPI)); | |
730 EXPECT_EQ(total_count, samples->TotalCount()); | |
731 } | |
732 #endif | |
733 } | |
OLD | NEW |