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 21 matching lines...) Expand all Loading... | |
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* YOUTUBE_REWRITE_STATUS = "Plugin.Flash.YouTubeRewrite"; | |
Alexei Svitkine (slow)
2016/08/04 14:31:18
const char kYoutubeRewriteStatus[] =
kdsilva
2016/08/04 18:28:52
Done.
| |
56 | |
57 enum YouTubeRewriteStatus { | |
58 SUCCESS = 0, | |
59 SUCCESS_PARAMS_REWRITE = 1, | |
60 SUCCESS_ENABLEJSAPI = 2, | |
61 FAILURE_ENABLEJSAPI = 3, | |
62 NUM_PLUGIN_ERROR // should be kept last | |
63 }; | |
64 | |
53 #if !defined(DISABLE_NACL) | 65 #if !defined(DISABLE_NACL) |
54 const char kExtensionUrl[] = "chrome-extension://extension_id/background.html"; | 66 const char kExtensionUrl[] = "chrome-extension://extension_id/background.html"; |
55 | 67 |
56 const char kPhotosAppURL[] = "https://foo.plus.google.com"; | 68 const char kPhotosAppURL[] = "https://foo.plus.google.com"; |
57 const char kPhotosManifestURL[] = "https://ssl.gstatic.com/photos/nacl/foo"; | 69 const char kPhotosManifestURL[] = "https://ssl.gstatic.com/photos/nacl/foo"; |
58 | 70 |
59 const char kChatManifestFS[] = "filesystem:https://talkgadget.google.com/foo"; | 71 const char kChatManifestFS[] = "filesystem:https://talkgadget.google.com/foo"; |
60 #endif | 72 #endif |
61 | 73 |
62 const char kChatAppURL[] = "https://talkgadget.google.com/hangouts/foo"; | 74 const char kChatAppURL[] = "https://talkgadget.google.com/hangouts/foo"; |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
472 // Invalid parameter construct | 484 // Invalid parameter construct |
473 {"http://www.youtube.com/v/123/", "http://www.youtube.com/embed/123/"}, | 485 {"http://www.youtube.com/v/123/", "http://www.youtube.com/embed/123/"}, |
474 }; | 486 }; |
475 | 487 |
476 ChromeContentRendererClient client; | 488 ChromeContentRendererClient client; |
477 | 489 |
478 for (auto data : test_data) | 490 for (auto data : test_data) |
479 EXPECT_EQ(GURL(data.expected), | 491 EXPECT_EQ(GURL(data.expected), |
480 client.OverrideFlashEmbedWithHTML(GURL(data.original))); | 492 client.OverrideFlashEmbedWithHTML(GURL(data.original))); |
481 } | 493 } |
494 | |
495 class ChromeContentRendererClientMetricsTest : public testing::Test { | |
496 public: | |
497 ChromeContentRendererClientMetricsTest() = default; | |
498 | |
499 std::unique_ptr<base::HistogramSamples> GetHistogramSamples() { | |
500 return histogram_tester_.GetHistogramSamplesSinceCreation( | |
501 YOUTUBE_REWRITE_STATUS); | |
502 } | |
503 | |
504 private: | |
505 base::HistogramTester histogram_tester_; | |
506 }; | |
507 | |
508 TEST_F(ChromeContentRendererClientMetricsTest, RewriteEmbedIneligibleURL) { | |
509 ChromeContentRendererClient client; | |
510 | |
511 std::unique_ptr<base::HistogramSamples> samples = GetHistogramSamples(); | |
512 EXPECT_EQ(0, samples->TotalCount()); | |
513 | |
514 // http, www, no flash | |
515 GURL gurl = GURL("http://www.youtube.com"); | |
516 client.OverrideFlashEmbedWithHTML(gurl); | |
517 samples = GetHistogramSamples(); | |
518 EXPECT_EQ(0, samples->GetCount(SUCCESS)); | |
519 EXPECT_EQ(0, samples->TotalCount()); | |
520 | |
521 // no flash, subdomain | |
522 gurl = GURL("http://www.foo.youtube.com"); | |
523 client.OverrideFlashEmbedWithHTML(gurl); | |
524 samples = GetHistogramSamples(); | |
525 EXPECT_EQ(0, samples->GetCount(SUCCESS)); | |
526 EXPECT_EQ(0, samples->TotalCount()); | |
527 | |
528 // no flash | |
529 gurl = GURL("youtube.com"); | |
530 client.OverrideFlashEmbedWithHTML(gurl); | |
531 samples = GetHistogramSamples(); | |
532 EXPECT_EQ(0, samples->GetCount(SUCCESS)); | |
533 EXPECT_EQ(0, samples->TotalCount()); | |
534 | |
535 // not youtube | |
536 gurl = GURL("http://www.plus.google.com"); | |
537 client.OverrideFlashEmbedWithHTML(gurl); | |
538 samples = GetHistogramSamples(); | |
539 EXPECT_EQ(0, samples->GetCount(SUCCESS)); | |
540 EXPECT_EQ(0, samples->TotalCount()); | |
541 | |
542 // already using HTML5 | |
543 gurl = GURL("http://youtube.com/embed/deadbeef"); | |
544 client.OverrideFlashEmbedWithHTML(gurl); | |
545 samples = GetHistogramSamples(); | |
546 EXPECT_EQ(0, samples->GetCount(SUCCESS)); | |
547 EXPECT_EQ(0, samples->TotalCount()); | |
548 | |
549 // already using HTML5, enablejsapi=1 | |
550 gurl = GURL("http://www.youtube.com/embed/deadbeef?enablejsapi=1"); | |
551 client.OverrideFlashEmbedWithHTML(gurl); | |
552 samples = GetHistogramSamples(); | |
553 EXPECT_EQ(0, samples->GetCount(SUCCESS)); | |
554 EXPECT_EQ(0, samples->TotalCount()); | |
555 } | |
556 | |
557 TEST_F(ChromeContentRendererClientMetricsTest, RewriteEmbedSuccess) { | |
558 ChromeContentRendererClient client; | |
559 | |
560 std::unique_ptr<base::HistogramSamples> samples = GetHistogramSamples(); | |
561 EXPECT_EQ(0, samples->TotalCount()); | |
562 | |
563 // http, www, flash | |
564 GURL gurl = GURL("http://www.youtube.com/v/deadbeef"); | |
565 client.OverrideFlashEmbedWithHTML(gurl); | |
566 samples = GetHistogramSamples(); | |
567 EXPECT_EQ(1, samples->GetCount(SUCCESS)); | |
568 EXPECT_EQ(1, samples->TotalCount()); | |
569 | |
570 // http, no www, flash | |
571 gurl = GURL("http://youtube.com/v/deadbeef"); | |
572 client.OverrideFlashEmbedWithHTML(gurl); | |
573 samples = GetHistogramSamples(); | |
574 EXPECT_EQ(2, samples->GetCount(SUCCESS)); | |
575 EXPECT_EQ(2, samples->TotalCount()); | |
576 | |
577 // https, www, flash | |
578 gurl = GURL("https://www.youtube.com/v/deadbeef"); | |
579 client.OverrideFlashEmbedWithHTML(gurl); | |
580 samples = GetHistogramSamples(); | |
581 EXPECT_EQ(3, samples->GetCount(SUCCESS)); | |
582 EXPECT_EQ(3, samples->TotalCount()); | |
583 | |
584 // https, no www, flash | |
585 gurl = GURL("https://youtube.com/v/deadbeef"); | |
586 client.OverrideFlashEmbedWithHTML(gurl); | |
587 samples = GetHistogramSamples(); | |
588 EXPECT_EQ(4, samples->GetCount(SUCCESS)); | |
589 EXPECT_EQ(4, samples->TotalCount()); | |
590 | |
591 // invalid parameter construct | |
592 gurl = GURL("http://www.youtube.com/v/abcd/"); | |
593 client.OverrideFlashEmbedWithHTML(gurl); | |
594 samples = GetHistogramSamples(); | |
595 EXPECT_EQ(5, samples->GetCount(SUCCESS)); | |
596 EXPECT_EQ(5, samples->TotalCount()); | |
597 | |
598 // invalid parameter construct | |
599 gurl = GURL("http://www.youtube.com/v/1234/"); | |
600 client.OverrideFlashEmbedWithHTML(gurl); | |
601 samples = GetHistogramSamples(); | |
602 EXPECT_EQ(6, samples->GetCount(SUCCESS)); | |
603 EXPECT_EQ(6, samples->TotalCount()); | |
604 | |
605 // invalid parameter construct | |
606 gurl = GURL("http://www.youtube.com/abcd/v/deadbeef"); | |
607 client.OverrideFlashEmbedWithHTML(gurl); | |
608 samples = GetHistogramSamples(); | |
609 EXPECT_EQ(6, samples->GetCount(SUCCESS)); | |
610 EXPECT_EQ(6, samples->TotalCount()); | |
611 } | |
612 | |
613 TEST_F(ChromeContentRendererClientMetricsTest, RewriteEmbedSuccessRewrite) { | |
614 ChromeContentRendererClient client; | |
615 | |
616 std::unique_ptr<base::HistogramSamples> samples = GetHistogramSamples(); | |
617 EXPECT_EQ(0, samples->TotalCount()); | |
618 | |
619 // invalid parameter construct, one parameter | |
620 GURL gurl = GURL("http://www.youtube.com/v/deadbeef&start=4"); | |
621 client.OverrideFlashEmbedWithHTML(gurl); | |
622 samples = GetHistogramSamples(); | |
623 EXPECT_EQ(1, samples->GetCount(SUCCESS_PARAMS_REWRITE)); | |
624 EXPECT_EQ(1, samples->TotalCount()); | |
625 | |
626 // invalid parameter construct, has multiple parameters | |
627 gurl = GURL("http://www.youtube.com/v/deadbeef&start=4&fs=1?foo=bar"); | |
628 client.OverrideFlashEmbedWithHTML(gurl); | |
629 samples = GetHistogramSamples(); | |
630 EXPECT_EQ(2, samples->GetCount(SUCCESS_PARAMS_REWRITE)); | |
631 EXPECT_EQ(2, samples->TotalCount()); | |
632 | |
633 // invalid parameter construct, not flash | |
634 gurl = GURL("http://www.youtube.com/embed/deadbeef&start=4"); | |
635 client.OverrideFlashEmbedWithHTML(gurl); | |
636 samples = GetHistogramSamples(); | |
637 EXPECT_EQ(2, samples->GetCount(SUCCESS_PARAMS_REWRITE)); | |
638 EXPECT_EQ(2, samples->TotalCount()); | |
639 } | |
640 | |
641 TEST_F(ChromeContentRendererClientMetricsTest, RewriteEmbedFailureJSAPI) { | |
642 ChromeContentRendererClient client; | |
643 | |
644 std::unique_ptr<base::HistogramSamples> samples = GetHistogramSamples(); | |
645 EXPECT_EQ(0, samples->TotalCount()); | |
646 | |
647 // invalid parameter construct, one parameter | |
648 GURL gurl = GURL("http://www.youtube.com/v/deadbeef&enablejsapi=1"); | |
649 client.OverrideFlashEmbedWithHTML(gurl); | |
650 samples = GetHistogramSamples(); | |
651 EXPECT_EQ(1, samples->GetCount(FAILURE_ENABLEJSAPI)); | |
652 EXPECT_EQ(1, samples->TotalCount()); | |
653 | |
654 // invalid parameter construct, has multiple parameters | |
655 gurl = GURL("http://www.youtube.com/v/deadbeef&start=4&enablejsapi=1?foo=2"); | |
656 client.OverrideFlashEmbedWithHTML(gurl); | |
657 samples = GetHistogramSamples(); | |
658 EXPECT_EQ(2, samples->GetCount(FAILURE_ENABLEJSAPI)); | |
659 EXPECT_EQ(2, samples->TotalCount()); | |
660 } | |
OLD | NEW |