Chromium Code Reviews| Index: chrome/renderer/chrome_content_renderer_client_unittest.cc |
| diff --git a/chrome/renderer/chrome_content_renderer_client_unittest.cc b/chrome/renderer/chrome_content_renderer_client_unittest.cc |
| index f09390e494718f2c34b2bbf40acb1bc981b6ced1..a66376918ca68b64d74bb8908f0d7087cd1305e1 100644 |
| --- a/chrome/renderer/chrome_content_renderer_client_unittest.cc |
| +++ b/chrome/renderer/chrome_content_renderer_client_unittest.cc |
| @@ -8,7 +8,9 @@ |
| #include <vector> |
| +#include "base/metrics/histogram_samples.h" |
| #include "base/strings/utf_string_conversions.h" |
| +#include "base/test/histogram_tester.h" |
| #include "build/build_config.h" |
| #include "chrome/renderer/searchbox/search_bouncer.h" |
| #include "content/public/common/webplugininfo.h" |
| @@ -50,6 +52,8 @@ const bool kNotHostedApp = false; |
| const bool kHostedApp = true; |
| #endif |
| +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.
|
| + |
| #if !defined(DISABLE_NACL) |
| const char kExtensionUrl[] = "chrome-extension://extension_id/background.html"; |
| @@ -479,3 +483,140 @@ TEST_F(ChromeContentRendererClientTest, RewriteYouTubeFlashEmbed) { |
| EXPECT_EQ(GURL(data.expected), |
| client.OverrideFlashEmbedWithHTML(GURL(data.original))); |
| } |
| + |
| +class ChromeContentRendererClientMetricsTest : public testing::Test { |
| + public: |
| + ChromeContentRendererClientMetricsTest() = default; |
| + |
| + std::unique_ptr<base::HistogramSamples> GetHistogramSamples() { |
| + return histogram_tester_.GetHistogramSamplesSinceCreation( |
| + kYouTubeRewriteStatus); |
| + } |
| + |
| + void OverrideFlashEmbed(GURL gurl) { |
|
Alexei Svitkine (slow)
2016/08/05 16:34:56
const GURL&
kdsilva
2016/08/08 11:04:42
Done.
|
| + client_.OverrideFlashEmbedWithHTML(gurl); |
| + } |
| + |
| + private: |
| + ChromeContentRendererClient client_; |
| + base::HistogramTester histogram_tester_; |
| +}; |
|
Alexei Svitkine (slow)
2016/08/05 16:34:56
DISALLOW_COPY_AND)_ASSIGN()
kdsilva
2016/08/08 11:04:42
Done.
|
| + |
| +TEST_F(ChromeContentRendererClientMetricsTest, RewriteEmbedIneligibleURL) { |
| + 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.
|
| + EXPECT_EQ(0, samples->TotalCount()); |
| + |
| + const std::string test_data[] = { |
| + // HTTP, www, no flash |
| + "http://www.youtube.com", |
| + // No flash, subdomain |
| + "http://www.foo.youtube.com", |
| + // No flash |
| + "youtube.com", |
| + // Not youtube |
| + "http://www.plus.google.com", |
| + // Already using HTML5 |
| + "http://youtube.com/embed/deadbeef", |
| + // Already using HTML5, enablejsapi=1 |
| + "http://www.youtube.com/embed/deadbeef?enablejsapi=1"}; |
| + |
| + for (auto data : test_data) { |
| + GURL gurl = GURL(data); |
| + OverrideFlashEmbed(gurl); |
| + samples = GetHistogramSamples(); |
| + EXPECT_EQ(0, samples->GetCount(SUCCESS)); |
| + EXPECT_EQ(0, samples->TotalCount()); |
| + } |
| +} |
| + |
| +TEST_F(ChromeContentRendererClientMetricsTest, RewriteEmbedSuccess) { |
| + ChromeContentRendererClient client; |
| + |
| + std::unique_ptr<base::HistogramSamples> samples = GetHistogramSamples(); |
| + auto total_count = 0; |
| + EXPECT_EQ(total_count, samples->TotalCount()); |
| + |
| + const std::string test_data[] = { |
| + // HTTP, www, flash |
| + "http://www.youtube.com/v/deadbeef", |
| + // HTTP, no www, flash |
| + "http://youtube.com/v/deadbeef", |
| + // HTTPS, www, flash |
| + "https://www.youtube.com/v/deadbeef", |
| + // HTTPS, no www, flash |
| + "https://youtube.com/v/deadbeef", |
| + // Invalid parameter construct |
| + "http://www.youtube.com/v/abcd/", |
| + // Invalid parameter construct |
| + "http://www.youtube.com/v/1234/", |
| + }; |
| + |
| + for (auto data : test_data) { |
| + ++total_count; |
| + GURL gurl = GURL(data); |
| + OverrideFlashEmbed(gurl); |
| + samples = GetHistogramSamples(); |
| + EXPECT_EQ(total_count, samples->GetCount(SUCCESS)); |
| + EXPECT_EQ(total_count, samples->TotalCount()); |
| + } |
| + |
| + // Invalid parameter construct |
| + GURL gurl = GURL("http://www.youtube.com/abcd/v/deadbeef"); |
| + samples = GetHistogramSamples(); |
| + EXPECT_EQ(total_count, samples->GetCount(SUCCESS)); |
| + EXPECT_EQ(total_count, samples->TotalCount()); |
| +} |
| + |
| +TEST_F(ChromeContentRendererClientMetricsTest, RewriteEmbedSuccessRewrite) { |
| + ChromeContentRendererClient client; |
| + |
| + std::unique_ptr<base::HistogramSamples> samples = GetHistogramSamples(); |
| + auto total_count = 0; |
| + EXPECT_EQ(total_count, samples->TotalCount()); |
| + |
| + const std::string test_data[] = { |
| + // Invalid parameter construct, one parameter |
| + "http://www.youtube.com/v/deadbeef&start=4", |
| + // Invalid parameter construct, has multiple parameters |
| + "http://www.youtube.com/v/deadbeef&start=4&fs=1?foo=bar", |
| + }; |
| + |
| + for (auto data : test_data) { |
| + ++total_count; |
| + GURL gurl = GURL(data); |
| + client.OverrideFlashEmbedWithHTML(gurl); |
| + samples = GetHistogramSamples(); |
| + EXPECT_EQ(total_count, samples->GetCount(SUCCESS_PARAMS_REWRITE)); |
| + EXPECT_EQ(total_count, samples->TotalCount()); |
| + } |
| + |
| + // Invalid parameter construct, not flash |
| + GURL gurl = GURL("http://www.youtube.com/embed/deadbeef&start=4"); |
| + OverrideFlashEmbed(gurl); |
| + samples = GetHistogramSamples(); |
| + EXPECT_EQ(total_count, samples->GetCount(SUCCESS_PARAMS_REWRITE)); |
| + EXPECT_EQ(total_count, samples->TotalCount()); |
| +} |
| + |
| +TEST_F(ChromeContentRendererClientMetricsTest, RewriteEmbedFailureJSAPI) { |
| + ChromeContentRendererClient client; |
| + |
| + std::unique_ptr<base::HistogramSamples> samples = GetHistogramSamples(); |
| + auto total_count = 0; |
| + EXPECT_EQ(total_count, samples->TotalCount()); |
| + |
| + const std::string test_data[] = { |
| + // Invalid parameter construct, one parameter |
| + "http://www.youtube.com/v/deadbeef&enablejsapi=1", |
| + // Invalid parameter construct, has multiple parameters |
| + "http://www.youtube.com/v/deadbeef&start=4&enablejsapi=1?foo=2"}; |
| + |
| + for (auto data : test_data) { |
| + ++total_count; |
| + GURL gurl = GURL(data); |
| + OverrideFlashEmbed(gurl); |
| + samples = GetHistogramSamples(); |
| + EXPECT_EQ(total_count, samples->GetCount(FAILURE_ENABLEJSAPI)); |
| + EXPECT_EQ(total_count, samples->TotalCount()); |
| + } |
| +} |