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