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 |
11 #include "base/metrics/histogram_samples.h" | |
11 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "base/test/histogram_tester.h" | |
12 #include "build/build_config.h" | 14 #include "build/build_config.h" |
13 #include "chrome/renderer/searchbox/search_bouncer.h" | 15 #include "chrome/renderer/searchbox/search_bouncer.h" |
14 #include "content/public/common/webplugininfo.h" | 16 #include "content/public/common/webplugininfo.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
16 #include "url/gurl.h" | 18 #include "url/gurl.h" |
17 | 19 |
18 #if defined(ENABLE_EXTENSIONS) | 20 #if defined(ENABLE_EXTENSIONS) |
19 #include "extensions/common/extension.h" | 21 #include "extensions/common/extension.h" |
20 #include "extensions/common/extension_builder.h" | 22 #include "extensions/common/extension_builder.h" |
21 #include "extensions/common/manifest_constants.h" | 23 #include "extensions/common/manifest_constants.h" |
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
495 {"https://www.youtube-nocookie.com/v/123/", | 497 {"https://www.youtube-nocookie.com/v/123/", |
496 "https://www.youtube-nocookie.com/embed/123/"}, | 498 "https://www.youtube-nocookie.com/embed/123/"}, |
497 }; | 499 }; |
498 | 500 |
499 ChromeContentRendererClient client; | 501 ChromeContentRendererClient client; |
500 | 502 |
501 for (const auto& data : test_data) | 503 for (const auto& data : test_data) |
502 EXPECT_EQ(GURL(data.expected), | 504 EXPECT_EQ(GURL(data.expected), |
503 client.OverrideFlashEmbedWithHTML(GURL(data.original))); | 505 client.OverrideFlashEmbedWithHTML(GURL(data.original))); |
504 } | 506 } |
507 | |
508 class ChromeContentRendererClientMetricsTest : public testing::Test { | |
509 public: | |
510 ChromeContentRendererClientMetricsTest() = default; | |
511 | |
512 std::unique_ptr<base::HistogramSamples> GetHistogramSamples() { | |
513 return histogram_tester_.GetHistogramSamplesSinceCreation( | |
514 internal::kFlashYouTubeRewriteUMA); | |
515 } | |
516 | |
517 void OverrideFlashEmbed(const GURL& gurl) { | |
518 client_.OverrideFlashEmbedWithHTML(gurl); | |
519 } | |
520 | |
521 private: | |
522 ChromeContentRendererClient client_; | |
523 base::HistogramTester histogram_tester_; | |
524 | |
525 DISALLOW_COPY_AND_ASSIGN(ChromeContentRendererClientMetricsTest); | |
526 }; | |
527 | |
528 TEST_F(ChromeContentRendererClientMetricsTest, RewriteEmbedIneligibleURL) { | |
529 std::unique_ptr<base::HistogramSamples> samples = GetHistogramSamples(); | |
530 EXPECT_EQ(0, samples->TotalCount()); | |
531 | |
532 const std::string test_data[] = { | |
533 // HTTP, www, no flash | |
534 "http://www.youtube.com", | |
535 // No flash, subdomain | |
536 "http://www.foo.youtube.com", | |
537 // No flash | |
538 "youtube.com", | |
539 // Not youtube | |
540 "http://www.plus.google.com", | |
541 // Already using HTML5 | |
542 "http://youtube.com/embed/deadbeef", | |
543 // Already using HTML5, enablejsapi=1 | |
544 "http://www.youtube.com/embed/deadbeef?enablejsapi=1"}; | |
mlamouri (slow - plz ping)
2016/08/09 11:21:47
style: move }; to the next line
kdsilva
2016/08/09 12:38:20
Acknowledged. Keeping it as is because it's what `
| |
545 | |
546 for (const auto& data : test_data) { | |
547 GURL gurl = GURL(data); | |
548 OverrideFlashEmbed(gurl); | |
549 samples = GetHistogramSamples(); | |
550 EXPECT_EQ(0, samples->GetCount(internal::SUCCESS)); | |
551 EXPECT_EQ(0, samples->TotalCount()); | |
552 } | |
553 } | |
554 | |
555 TEST_F(ChromeContentRendererClientMetricsTest, RewriteEmbedSuccess) { | |
556 ChromeContentRendererClient client; | |
557 | |
558 std::unique_ptr<base::HistogramSamples> samples = GetHistogramSamples(); | |
559 auto total_count = 0; | |
560 EXPECT_EQ(total_count, samples->TotalCount()); | |
561 | |
562 const std::string test_data[] = { | |
563 // HTTP, www, flash | |
564 "http://www.youtube.com/v/deadbeef", | |
565 // HTTP, no www, flash | |
566 "http://youtube.com/v/deadbeef", | |
567 // HTTPS, www, flash | |
568 "https://www.youtube.com/v/deadbeef", | |
569 // HTTPS, no www, flash | |
570 "https://youtube.com/v/deadbeef", | |
571 // Invalid parameter construct | |
572 "http://www.youtube.com/v/abcd/", | |
573 // Invalid parameter construct | |
574 "http://www.youtube.com/v/1234/", | |
575 }; | |
576 | |
577 for (const auto& data : test_data) { | |
578 ++total_count; | |
579 GURL gurl = GURL(data); | |
580 OverrideFlashEmbed(gurl); | |
581 samples = GetHistogramSamples(); | |
582 EXPECT_EQ(total_count, samples->GetCount(internal::SUCCESS)); | |
583 EXPECT_EQ(total_count, samples->TotalCount()); | |
584 } | |
585 | |
586 // Invalid parameter construct | |
587 GURL gurl = GURL("http://www.youtube.com/abcd/v/deadbeef"); | |
588 samples = GetHistogramSamples(); | |
589 EXPECT_EQ(total_count, samples->GetCount(internal::SUCCESS)); | |
590 EXPECT_EQ(total_count, samples->TotalCount()); | |
591 } | |
592 | |
593 TEST_F(ChromeContentRendererClientMetricsTest, RewriteEmbedSuccessRewrite) { | |
594 ChromeContentRendererClient client; | |
595 | |
596 std::unique_ptr<base::HistogramSamples> samples = GetHistogramSamples(); | |
597 auto total_count = 0; | |
598 EXPECT_EQ(total_count, samples->TotalCount()); | |
599 | |
600 const std::string test_data[] = { | |
601 // Invalid parameter construct, one parameter | |
602 "http://www.youtube.com/v/deadbeef&start=4", | |
603 // Invalid parameter construct, has multiple parameters | |
604 "http://www.youtube.com/v/deadbeef&start=4&fs=1?foo=bar", | |
605 }; | |
606 | |
607 for (const auto& data : test_data) { | |
608 ++total_count; | |
609 GURL gurl = GURL(data); | |
610 client.OverrideFlashEmbedWithHTML(gurl); | |
611 samples = GetHistogramSamples(); | |
612 EXPECT_EQ(total_count, samples->GetCount(internal::SUCCESS_PARAMS_REWRITE)); | |
613 EXPECT_EQ(total_count, samples->TotalCount()); | |
614 } | |
615 | |
616 // Invalid parameter construct, not flash | |
617 GURL gurl = GURL("http://www.youtube.com/embed/deadbeef&start=4"); | |
618 OverrideFlashEmbed(gurl); | |
619 samples = GetHistogramSamples(); | |
620 EXPECT_EQ(total_count, samples->GetCount(internal::SUCCESS_PARAMS_REWRITE)); | |
621 EXPECT_EQ(total_count, samples->TotalCount()); | |
622 } | |
623 | |
624 TEST_F(ChromeContentRendererClientMetricsTest, RewriteEmbedFailureJSAPI) { | |
625 ChromeContentRendererClient client; | |
626 | |
627 std::unique_ptr<base::HistogramSamples> samples = GetHistogramSamples(); | |
628 auto total_count = 0; | |
629 EXPECT_EQ(total_count, samples->TotalCount()); | |
630 | |
631 const std::string test_data[] = { | |
632 // Invalid parameter construct, one parameter | |
633 "http://www.youtube.com/v/deadbeef&enablejsapi=1", | |
634 // Invalid parameter construct, has multiple parameters | |
635 "http://www.youtube.com/v/deadbeef&start=4&enablejsapi=1?foo=2"}; | |
mlamouri (slow - plz ping)
2016/08/09 11:21:47
style: move }; to the next line.
kdsilva
2016/08/09 12:38:20
Acknowledged.
| |
636 | |
637 for (const auto& data : test_data) { | |
638 ++total_count; | |
639 GURL gurl = GURL(data); | |
640 OverrideFlashEmbed(gurl); | |
641 samples = GetHistogramSamples(); | |
642 EXPECT_EQ(total_count, samples->GetCount(internal::FAILURE_ENABLEJSAPI)); | |
643 EXPECT_EQ(total_count, samples->TotalCount()); | |
644 } | |
645 } | |
OLD | NEW |