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

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 21 matching lines...) Expand all
43 const bool kNaClUnrestricted = true; 45 const bool kNaClUnrestricted = true;
44 const bool kExtensionNotFromWebStore = false; 46 const bool kExtensionNotFromWebStore = false;
45 const bool kExtensionFromWebStore = true; 47 const bool kExtensionFromWebStore = true;
46 #endif 48 #endif
47 49
48 #if defined(ENABLE_EXTENSIONS) 50 #if defined(ENABLE_EXTENSIONS)
49 const bool kNotHostedApp = false; 51 const bool kNotHostedApp = false;
50 const bool kHostedApp = true; 52 const bool kHostedApp = true;
51 #endif 53 #endif
52 54
55 const char kYouTubeRewriteStatus[] = "Plugin.Flash.YouTubeRewrite";
Alexei Svitkine (slow) 2016/08/05 16:34:56 Share this also, please. Declare it in the .h and
kdsilva 2016/08/08 11:04:42 Done.
56
53 #if !defined(DISABLE_NACL) 57 #if !defined(DISABLE_NACL)
54 const char kExtensionUrl[] = "chrome-extension://extension_id/background.html"; 58 const char kExtensionUrl[] = "chrome-extension://extension_id/background.html";
55 59
56 const char kPhotosAppURL[] = "https://foo.plus.google.com"; 60 const char kPhotosAppURL[] = "https://foo.plus.google.com";
57 const char kPhotosManifestURL[] = "https://ssl.gstatic.com/photos/nacl/foo"; 61 const char kPhotosManifestURL[] = "https://ssl.gstatic.com/photos/nacl/foo";
58 62
59 const char kChatManifestFS[] = "filesystem:https://talkgadget.google.com/foo"; 63 const char kChatManifestFS[] = "filesystem:https://talkgadget.google.com/foo";
60 #endif 64 #endif
61 65
62 const char kChatAppURL[] = "https://talkgadget.google.com/hangouts/foo"; 66 const char kChatAppURL[] = "https://talkgadget.google.com/hangouts/foo";
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 // Invalid parameter construct 476 // Invalid parameter construct
473 {"http://www.youtube.com/v/123/", "http://www.youtube.com/embed/123/"}, 477 {"http://www.youtube.com/v/123/", "http://www.youtube.com/embed/123/"},
474 }; 478 };
475 479
476 ChromeContentRendererClient client; 480 ChromeContentRendererClient client;
477 481
478 for (auto data : test_data) 482 for (auto data : test_data)
479 EXPECT_EQ(GURL(data.expected), 483 EXPECT_EQ(GURL(data.expected),
480 client.OverrideFlashEmbedWithHTML(GURL(data.original))); 484 client.OverrideFlashEmbedWithHTML(GURL(data.original)));
481 } 485 }
486
487 class ChromeContentRendererClientMetricsTest : public testing::Test {
488 public:
489 ChromeContentRendererClientMetricsTest() = default;
490
491 std::unique_ptr<base::HistogramSamples> GetHistogramSamples() {
492 return histogram_tester_.GetHistogramSamplesSinceCreation(
493 kYouTubeRewriteStatus);
494 }
495
496 void OverrideFlashEmbed(GURL gurl) {
Alexei Svitkine (slow) 2016/08/05 16:34:56 const GURL&
kdsilva 2016/08/08 11:04:42 Done.
497 client_.OverrideFlashEmbedWithHTML(gurl);
498 }
499
500 private:
501 ChromeContentRendererClient client_;
502 base::HistogramTester histogram_tester_;
503 };
Alexei Svitkine (slow) 2016/08/05 16:34:56 DISALLOW_COPY_AND)_ASSIGN()
kdsilva 2016/08/08 11:04:42 Done.
504
505 TEST_F(ChromeContentRendererClientMetricsTest, RewriteEmbedIneligibleURL) {
506 std::unique_ptr<base::HistogramSamples> samples = GetHistogramSamples();
Alexei Svitkine (slow) 2016/08/05 16:34:56 Wrong indent? Run git cl format.
kdsilva 2016/08/08 11:04:42 Done.
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) {
524 GURL gurl = GURL(data);
525 OverrideFlashEmbed(gurl);
526 samples = GetHistogramSamples();
527 EXPECT_EQ(0, samples->GetCount(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(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(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(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(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(FAILURE_ENABLEJSAPI));
620 EXPECT_EQ(total_count, samples->TotalCount());
621 }
622 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698