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

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

Issue 2206343002: Add metrics for YouTube Flash embed rewrite. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@layers
Patch Set: Addressed comments Created 4 years, 4 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
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
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 450 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 // Invalid parameter construct 474 // Invalid parameter construct
473 {"http://www.youtube.com/v/123/", "http://www.youtube.com/embed/123/"}, 475 {"http://www.youtube.com/v/123/", "http://www.youtube.com/embed/123/"},
474 }; 476 };
475 477
476 ChromeContentRendererClient client; 478 ChromeContentRendererClient client;
477 479
478 for (auto data : test_data) 480 for (auto data : test_data)
479 EXPECT_EQ(GURL(data.expected), 481 EXPECT_EQ(GURL(data.expected),
480 client.OverrideFlashEmbedWithHTML(GURL(data.original))); 482 client.OverrideFlashEmbedWithHTML(GURL(data.original)));
481 } 483 }
484
485 class ChromeContentRendererClientMetricsTest : public testing::Test {
486 public:
487 ChromeContentRendererClientMetricsTest() = default;
488
489 std::unique_ptr<base::HistogramSamples> GetHistogramSamples() {
490 return histogram_tester_.GetHistogramSamplesSinceCreation(
491 internal::kFlashYouTubeRewriteUMA);
492 }
493
494 void OverrideFlashEmbed(const GURL& gurl) {
495 client_.OverrideFlashEmbedWithHTML(gurl);
496 }
497
498 private:
499 ChromeContentRendererClient client_;
500 base::HistogramTester histogram_tester_;
501
502 DISALLOW_COPY_AND_ASSIGN(ChromeContentRendererClientMetricsTest);
503 };
504
505 TEST_F(ChromeContentRendererClientMetricsTest, RewriteEmbedIneligibleURL) {
506 std::unique_ptr<base::HistogramSamples> samples = GetHistogramSamples();
507 EXPECT_EQ(0, samples->TotalCount());
508
509 const std::string test_data[] = {
510 // HTTP, www, no flash
511 "http://www.youtube.com",
512 // No flash, subdomain
513 "http://www.foo.youtube.com",
514 // No flash
515 "youtube.com",
516 // Not youtube
517 "http://www.plus.google.com",
518 // Already using HTML5
519 "http://youtube.com/embed/deadbeef",
520 // Already using HTML5, enablejsapi=1
521 "http://www.youtube.com/embed/deadbeef?enablejsapi=1"};
522
523 for (auto data : test_data) {
Alexei Svitkine (slow) 2016/08/08 11:32:35 nit: const auto& or const std::string& Otherwise
kdsilva 2016/08/08 19:10:20 Done.
524 GURL gurl = GURL(data);
525 OverrideFlashEmbed(gurl);
526 samples = GetHistogramSamples();
527 EXPECT_EQ(0, samples->GetCount(internal::SUCCESS));
528 EXPECT_EQ(0, samples->TotalCount());
529 }
530 }
531
532 TEST_F(ChromeContentRendererClientMetricsTest, RewriteEmbedSuccess) {
533 ChromeContentRendererClient client;
534
535 std::unique_ptr<base::HistogramSamples> samples = GetHistogramSamples();
536 auto total_count = 0;
537 EXPECT_EQ(total_count, samples->TotalCount());
538
539 const std::string test_data[] = {
540 // HTTP, www, flash
541 "http://www.youtube.com/v/deadbeef",
542 // HTTP, no www, flash
543 "http://youtube.com/v/deadbeef",
544 // HTTPS, www, flash
545 "https://www.youtube.com/v/deadbeef",
546 // HTTPS, no www, flash
547 "https://youtube.com/v/deadbeef",
548 // Invalid parameter construct
549 "http://www.youtube.com/v/abcd/",
550 // Invalid parameter construct
551 "http://www.youtube.com/v/1234/",
552 };
553
554 for (auto data : test_data) {
555 ++total_count;
556 GURL gurl = GURL(data);
557 OverrideFlashEmbed(gurl);
558 samples = GetHistogramSamples();
559 EXPECT_EQ(total_count, samples->GetCount(internal::SUCCESS));
560 EXPECT_EQ(total_count, samples->TotalCount());
561 }
562
563 // Invalid parameter construct
564 GURL gurl = GURL("http://www.youtube.com/abcd/v/deadbeef");
565 samples = GetHistogramSamples();
566 EXPECT_EQ(total_count, samples->GetCount(internal::SUCCESS));
567 EXPECT_EQ(total_count, samples->TotalCount());
568 }
569
570 TEST_F(ChromeContentRendererClientMetricsTest, RewriteEmbedSuccessRewrite) {
571 ChromeContentRendererClient client;
572
573 std::unique_ptr<base::HistogramSamples> samples = GetHistogramSamples();
574 auto total_count = 0;
575 EXPECT_EQ(total_count, samples->TotalCount());
576
577 const std::string test_data[] = {
578 // Invalid parameter construct, one parameter
579 "http://www.youtube.com/v/deadbeef&start=4",
580 // Invalid parameter construct, has multiple parameters
581 "http://www.youtube.com/v/deadbeef&start=4&fs=1?foo=bar",
582 };
583
584 for (auto data : test_data) {
585 ++total_count;
586 GURL gurl = GURL(data);
587 client.OverrideFlashEmbedWithHTML(gurl);
588 samples = GetHistogramSamples();
589 EXPECT_EQ(total_count, samples->GetCount(internal::SUCCESS_PARAMS_REWRITE));
590 EXPECT_EQ(total_count, samples->TotalCount());
591 }
592
593 // Invalid parameter construct, not flash
594 GURL gurl = GURL("http://www.youtube.com/embed/deadbeef&start=4");
595 OverrideFlashEmbed(gurl);
596 samples = GetHistogramSamples();
597 EXPECT_EQ(total_count, samples->GetCount(internal::SUCCESS_PARAMS_REWRITE));
598 EXPECT_EQ(total_count, samples->TotalCount());
599 }
600
601 TEST_F(ChromeContentRendererClientMetricsTest, RewriteEmbedFailureJSAPI) {
602 ChromeContentRendererClient client;
603
604 std::unique_ptr<base::HistogramSamples> samples = GetHistogramSamples();
605 auto total_count = 0;
606 EXPECT_EQ(total_count, samples->TotalCount());
607
608 const std::string test_data[] = {
609 // Invalid parameter construct, one parameter
610 "http://www.youtube.com/v/deadbeef&enablejsapi=1",
611 // Invalid parameter construct, has multiple parameters
612 "http://www.youtube.com/v/deadbeef&start=4&enablejsapi=1?foo=2"};
613
614 for (auto data : test_data) {
615 ++total_count;
616 GURL gurl = GURL(data);
617 OverrideFlashEmbed(gurl);
618 samples = GetHistogramSamples();
619 EXPECT_EQ(total_count, samples->GetCount(internal::FAILURE_ENABLEJSAPI));
620 EXPECT_EQ(total_count, samples->TotalCount());
621 }
622 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698