Chromium Code Reviews| 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 #if defined(OS_ANDROID) | |
| 504 TEST_F(ChromeContentRendererClientTest, RewriteEmbedAndroid) { | |
| 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))); | |
|
mlamouri (slow - plz ping)
2016/08/09 11:12:38
style: this requires { }
kdsilva
2016/08/09 12:43:55
Done.
| |
| 531 } | |
| 532 | |
|
mlamouri (slow - plz ping)
2016/08/09 11:12:39
nit: you could remove this empty line.
kdsilva
2016/08/09 12:43:55
Done.
| |
| 533 #else | |
| 534 TEST_F(ChromeContentRendererClientTest, RewriteEmbedDesktop) { | |
| 535 struct TestData { | |
| 536 std::string original; | |
| 537 std::string expected; | |
| 538 } test_data[] = { | |
| 539 // URL isn't using Flash, has JS API enabled | |
| 540 {"http://www.youtube.com/embed/deadbeef?enablejsapi=1", ""}, | |
| 541 // URL is using Flash, has JS API enabled | |
| 542 {"http://www.youtube.com/v/deadbeef?enablejsapi=1", ""}, | |
| 543 // youtube-nocookie.com, has JS API enabled | |
| 544 {"http://www.youtube-nocookie.com/v/123?enablejsapi=1", ""}, | |
| 545 // URL is using Flash, has JS API enabled, invalid parameter construct | |
| 546 {"http://www.youtube.com/v/deadbeef&enablejsapi=1", ""}, | |
| 547 // URL is using Flash, has JS API enabled, invalid parameter construct, | |
| 548 // has multiple parameters | |
| 549 {"http://www.youtube.com/v/deadbeef&start=4&enablejsapi=1", ""}, | |
| 550 }; | |
| 551 | |
| 552 ChromeContentRendererClient client; | |
| 553 | |
| 554 for (const auto& data : test_data) | |
| 555 EXPECT_EQ(GURL(data.expected), | |
| 556 client.OverrideFlashEmbedWithHTML(GURL(data.original))); | |
|
mlamouri (slow - plz ping)
2016/08/09 11:12:38
style: this requires { }
kdsilva
2016/08/09 12:43:55
Done.
| |
| 557 } | |
| 558 #endif | |
| 559 | |
| 508 class ChromeContentRendererClientMetricsTest : public testing::Test { | 560 class ChromeContentRendererClientMetricsTest : public testing::Test { |
| 509 public: | 561 public: |
| 510 ChromeContentRendererClientMetricsTest() = default; | 562 ChromeContentRendererClientMetricsTest() = default; |
| 511 | 563 |
| 512 std::unique_ptr<base::HistogramSamples> GetHistogramSamples() { | 564 std::unique_ptr<base::HistogramSamples> GetHistogramSamples() { |
| 513 return histogram_tester_.GetHistogramSamplesSinceCreation( | 565 return histogram_tester_.GetHistogramSamplesSinceCreation( |
| 514 internal::kFlashYouTubeRewriteUMA); | 566 internal::kFlashYouTubeRewriteUMA); |
| 515 } | 567 } |
| 516 | 568 |
| 517 void OverrideFlashEmbed(const GURL& gurl) { | 569 void OverrideFlashEmbed(const GURL& gurl) { |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 614 } | 666 } |
| 615 | 667 |
| 616 // Invalid parameter construct, not flash | 668 // Invalid parameter construct, not flash |
| 617 GURL gurl = GURL("http://www.youtube.com/embed/deadbeef&start=4"); | 669 GURL gurl = GURL("http://www.youtube.com/embed/deadbeef&start=4"); |
| 618 OverrideFlashEmbed(gurl); | 670 OverrideFlashEmbed(gurl); |
| 619 samples = GetHistogramSamples(); | 671 samples = GetHistogramSamples(); |
| 620 EXPECT_EQ(total_count, samples->GetCount(internal::SUCCESS_PARAMS_REWRITE)); | 672 EXPECT_EQ(total_count, samples->GetCount(internal::SUCCESS_PARAMS_REWRITE)); |
| 621 EXPECT_EQ(total_count, samples->TotalCount()); | 673 EXPECT_EQ(total_count, samples->TotalCount()); |
| 622 } | 674 } |
| 623 | 675 |
| 624 TEST_F(ChromeContentRendererClientMetricsTest, RewriteEmbedFailureJSAPI) { | 676 #if defined(OS_ANDROID) |
| 677 TEST_F(ChromeContentRendererClientMetricsTest, | |
| 678 RewriteEmbedFailureJSAPIAndroid) { | |
| 625 ChromeContentRendererClient client; | 679 ChromeContentRendererClient client; |
| 626 | 680 |
| 627 std::unique_ptr<base::HistogramSamples> samples = GetHistogramSamples(); | 681 std::unique_ptr<base::HistogramSamples> samples = GetHistogramSamples(); |
| 682 auto total_count = 0; | |
| 683 EXPECT_EQ(total_count, samples->TotalCount()); | |
| 684 | |
| 685 const std::string test_data[] = { | |
| 686 // Valid parameter construct, one parameter | |
| 687 "http://www.youtube.com/v/deadbeef?enablejsapi=1", | |
| 688 // Valid parameter construct, has multiple parameters | |
| 689 "http://www.youtube.com/v/deadbeef?enablejsapi=1&foo=2", | |
| 690 // Invalid parameter construct, one parameter | |
| 691 "http://www.youtube.com/v/deadbeef&enablejsapi=1", | |
| 692 // Invalid parameter construct, has multiple parameters | |
| 693 "http://www.youtube.com/v/deadbeef&enablejsapi=1&foo=2"}; | |
| 694 | |
| 695 for (const auto& data : test_data) { | |
| 696 ++total_count; | |
| 697 GURL gurl = GURL(data); | |
| 698 OverrideFlashEmbed(gurl); | |
| 699 samples = GetHistogramSamples(); | |
| 700 EXPECT_EQ(total_count, samples->GetCount(internal::SUCCESS_ENABLEJSAPI)); | |
| 701 EXPECT_EQ(total_count, samples->TotalCount()); | |
| 702 } | |
| 703 } | |
| 704 | |
|
mlamouri (slow - plz ping)
2016/08/09 11:12:38
ditto
kdsilva
2016/08/09 12:43:55
Done.
| |
| 705 #else | |
| 706 TEST_F(ChromeContentRendererClientMetricsTest, | |
| 707 RewriteEmbedFailureJSAPIDesktop) { | |
| 708 ChromeContentRendererClient client; | |
| 709 | |
| 710 std::unique_ptr<base::HistogramSamples> samples = GetHistogramSamples(); | |
| 628 auto total_count = 0; | 711 auto total_count = 0; |
| 629 EXPECT_EQ(total_count, samples->TotalCount()); | 712 EXPECT_EQ(total_count, samples->TotalCount()); |
| 630 | 713 |
| 631 const std::string test_data[] = { | 714 const std::string test_data[] = { |
| 715 // Valid parameter construct, one parameter | |
| 716 "http://www.youtube.com/v/deadbeef?enablejsapi=1", | |
| 632 // Invalid parameter construct, one parameter | 717 // Invalid parameter construct, one parameter |
| 633 "http://www.youtube.com/v/deadbeef&enablejsapi=1", | 718 "http://www.youtube.com/v/deadbeef&enablejsapi=1", |
| 634 // Invalid parameter construct, has multiple parameters | 719 // Invalid parameter construct, has multiple parameters |
| 635 "http://www.youtube.com/v/deadbeef&start=4&enablejsapi=1?foo=2"}; | 720 "http://www.youtube.com/v/deadbeef&start=4&enablejsapi=1?foo=2"}; |
| 636 | 721 |
| 637 for (const auto& data : test_data) { | 722 for (const auto& data : test_data) { |
| 638 ++total_count; | 723 ++total_count; |
| 639 GURL gurl = GURL(data); | 724 GURL gurl = GURL(data); |
| 640 OverrideFlashEmbed(gurl); | 725 OverrideFlashEmbed(gurl); |
| 641 samples = GetHistogramSamples(); | 726 samples = GetHistogramSamples(); |
| 642 EXPECT_EQ(total_count, samples->GetCount(internal::FAILURE_ENABLEJSAPI)); | 727 EXPECT_EQ(total_count, samples->GetCount(internal::FAILURE_ENABLEJSAPI)); |
| 643 EXPECT_EQ(total_count, samples->TotalCount()); | 728 EXPECT_EQ(total_count, samples->TotalCount()); |
| 644 } | 729 } |
| 645 } | 730 } |
| 731 | |
|
mlamouri (slow - plz ping)
2016/08/09 11:12:38
nit: remove this empty line
kdsilva
2016/08/09 12:43:55
Done.
| |
| 732 #endif | |
| OLD | NEW |