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 kYouTubeRewriteStatus[] = "Plugin.Flash.YouTubeRewrite"; |
| 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 kYouTubeRewriteStatus); |
| 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 const std::string test_data[] = { |
| 515 // HTTP, www, no flash |
| 516 "http://www.youtube.com", |
| 517 // No flash, subdomain |
| 518 "http://www.foo.youtube.com", |
| 519 // No flash |
| 520 "youtube.com", |
| 521 // Not youtube |
| 522 "http://www.plus.google.com", |
| 523 // Already using HTML5 |
| 524 "http://youtube.com/embed/deadbeef", |
| 525 // Already using HTML5, enablejsapi=1 |
| 526 "http://www.youtube.com/embed/deadbeef?enablejsapi=1"}; |
| 527 |
| 528 for (auto data : test_data) { |
| 529 GURL gurl = GURL(data); |
| 530 client.OverrideFlashEmbedWithHTML(gurl); |
| 531 samples = GetHistogramSamples(); |
| 532 EXPECT_EQ(0, samples->GetCount(SUCCESS)); |
| 533 EXPECT_EQ(0, samples->TotalCount()); |
| 534 } |
| 535 } |
| 536 |
| 537 TEST_F(ChromeContentRendererClientMetricsTest, RewriteEmbedSuccess) { |
| 538 ChromeContentRendererClient client; |
| 539 |
| 540 std::unique_ptr<base::HistogramSamples> samples = GetHistogramSamples(); |
| 541 auto total_count = 0; |
| 542 EXPECT_EQ(total_count, samples->TotalCount()); |
| 543 |
| 544 const std::string test_data[] = { |
| 545 // HTTP, www, flash |
| 546 "http://www.youtube.com/v/deadbeef", |
| 547 // HTTP, no www, flash |
| 548 "http://youtube.com/v/deadbeef", |
| 549 // HTTPS, www, flash |
| 550 "https://www.youtube.com/v/deadbeef", |
| 551 // HTTPS, no www, flash |
| 552 "https://youtube.com/v/deadbeef", |
| 553 // Invalid parameter construct |
| 554 "http://www.youtube.com/v/abcd/", |
| 555 // Invalid parameter construct |
| 556 "http://www.youtube.com/v/1234/", |
| 557 }; |
| 558 |
| 559 for (auto data : test_data) { |
| 560 ++total_count; |
| 561 GURL gurl = GURL(data); |
| 562 client.OverrideFlashEmbedWithHTML(gurl); |
| 563 samples = GetHistogramSamples(); |
| 564 EXPECT_EQ(total_count, samples->GetCount(SUCCESS)); |
| 565 EXPECT_EQ(total_count, samples->TotalCount()); |
| 566 } |
| 567 |
| 568 // Invalid parameter construct |
| 569 GURL gurl = GURL("http://www.youtube.com/abcd/v/deadbeef"); |
| 570 client.OverrideFlashEmbedWithHTML(gurl); |
| 571 samples = GetHistogramSamples(); |
| 572 EXPECT_EQ(total_count, samples->GetCount(SUCCESS)); |
| 573 EXPECT_EQ(total_count, samples->TotalCount()); |
| 574 } |
| 575 |
| 576 TEST_F(ChromeContentRendererClientMetricsTest, RewriteEmbedSuccessRewrite) { |
| 577 ChromeContentRendererClient client; |
| 578 |
| 579 std::unique_ptr<base::HistogramSamples> samples = GetHistogramSamples(); |
| 580 auto total_count = 0; |
| 581 EXPECT_EQ(total_count, samples->TotalCount()); |
| 582 |
| 583 const std::string test_data[] = { |
| 584 // Invalid parameter construct, one parameter |
| 585 "http://www.youtube.com/v/deadbeef&start=4", |
| 586 // Invalid parameter construct, has multiple parameters |
| 587 "http://www.youtube.com/v/deadbeef&start=4&fs=1?foo=bar", |
| 588 }; |
| 589 |
| 590 for (auto data : test_data) { |
| 591 ++total_count; |
| 592 GURL gurl = GURL(data); |
| 593 client.OverrideFlashEmbedWithHTML(gurl); |
| 594 samples = GetHistogramSamples(); |
| 595 EXPECT_EQ(total_count, samples->GetCount(SUCCESS_PARAMS_REWRITE)); |
| 596 EXPECT_EQ(total_count, samples->TotalCount()); |
| 597 } |
| 598 |
| 599 // Invalid parameter construct, not flash |
| 600 GURL gurl = GURL("http://www.youtube.com/embed/deadbeef&start=4"); |
| 601 client.OverrideFlashEmbedWithHTML(gurl); |
| 602 samples = GetHistogramSamples(); |
| 603 EXPECT_EQ(total_count, samples->GetCount(SUCCESS_PARAMS_REWRITE)); |
| 604 EXPECT_EQ(total_count, samples->TotalCount()); |
| 605 } |
| 606 |
| 607 TEST_F(ChromeContentRendererClientMetricsTest, RewriteEmbedFailureJSAPI) { |
| 608 ChromeContentRendererClient client; |
| 609 |
| 610 std::unique_ptr<base::HistogramSamples> samples = GetHistogramSamples(); |
| 611 auto total_count = 0; |
| 612 EXPECT_EQ(total_count, samples->TotalCount()); |
| 613 |
| 614 const std::string test_data[] = { |
| 615 // Invalid parameter construct, one parameter |
| 616 "http://www.youtube.com/v/deadbeef&enablejsapi=1", |
| 617 // Invalid parameter construct, has multiple parameters |
| 618 "http://www.youtube.com/v/deadbeef&start=4&enablejsapi=1?foo=2"}; |
| 619 |
| 620 for (auto data : test_data) { |
| 621 ++total_count; |
| 622 GURL gurl = GURL(data); |
| 623 client.OverrideFlashEmbedWithHTML(gurl); |
| 624 samples = GetHistogramSamples(); |
| 625 EXPECT_EQ(total_count, samples->GetCount(FAILURE_ENABLEJSAPI)); |
| 626 EXPECT_EQ(total_count, samples->TotalCount()); |
| 627 } |
| 628 } |
OLD | NEW |