[email protected] | b2d9876 | 2012-09-03 17:04:06 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "content/renderer/render_thread_impl.h" |
| 6 | #include "testing/gtest/include/gtest/gtest.h" |
| 7 | |
| 8 | #include <string> |
| 9 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 10 | namespace content { |
| 11 | |
[email protected] | b2d9876 | 2012-09-03 17:04:06 | [diff] [blame] | 12 | class RenderThreadImplUnittest : public testing::Test { |
| 13 | public: |
| 14 | RenderThreadImplUnittest() |
| 15 | : kCustomizableHistogram_("Histogram1"), |
| 16 | kNormalHistogram_("Histogram2") {} |
dcheng | f576215 | 2014-10-29 02:12:06 | [diff] [blame] | 17 | ~RenderThreadImplUnittest() override {} |
| 18 | |
[email protected] | b2d9876 | 2012-09-03 17:04:06 | [diff] [blame] | 19 | protected: |
dcheng | f576215 | 2014-10-29 02:12:06 | [diff] [blame] | 20 | void SetUp() override { |
[email protected] | b2d9876 | 2012-09-03 17:04:06 | [diff] [blame] | 21 | histogram_customizer_.custom_histograms_.clear(); |
| 22 | histogram_customizer_.custom_histograms_.insert(kCustomizableHistogram_); |
| 23 | } |
| 24 | RenderThreadImpl::HistogramCustomizer histogram_customizer_; |
| 25 | const char* kCustomizableHistogram_; |
| 26 | const char* kNormalHistogram_; |
| 27 | }; |
| 28 | |
| 29 | TEST_F(RenderThreadImplUnittest, CustomHistogramsWithNoNavigations) { |
| 30 | // First there is no page -> no custom histograms. |
| 31 | EXPECT_EQ(kCustomizableHistogram_, |
| 32 | histogram_customizer_.ConvertToCustomHistogramName( |
| 33 | kCustomizableHistogram_)); |
| 34 | EXPECT_EQ(kNormalHistogram_, |
| 35 | histogram_customizer_.ConvertToCustomHistogramName( |
| 36 | kNormalHistogram_)); |
| 37 | } |
| 38 | |
| 39 | TEST_F(RenderThreadImplUnittest, CustomHistogramsForOneRenderView) { |
| 40 | histogram_customizer_.RenderViewNavigatedToHost("mail.google.com", 1); |
| 41 | EXPECT_EQ(std::string(kCustomizableHistogram_) + ".gmail", |
| 42 | histogram_customizer_.ConvertToCustomHistogramName( |
| 43 | kCustomizableHistogram_)); |
| 44 | EXPECT_EQ(kNormalHistogram_, |
| 45 | histogram_customizer_.ConvertToCustomHistogramName( |
| 46 | kNormalHistogram_)); |
| 47 | histogram_customizer_.RenderViewNavigatedToHost("docs.google.com", 1); |
| 48 | EXPECT_EQ(std::string(kCustomizableHistogram_) + ".docs", |
| 49 | histogram_customizer_.ConvertToCustomHistogramName( |
| 50 | kCustomizableHistogram_)); |
| 51 | histogram_customizer_.RenderViewNavigatedToHost("nottracked.com", 1); |
| 52 | EXPECT_EQ(kCustomizableHistogram_, |
| 53 | histogram_customizer_.ConvertToCustomHistogramName( |
| 54 | kCustomizableHistogram_)); |
| 55 | } |
| 56 | |
| 57 | TEST_F(RenderThreadImplUnittest, CustomHistogramsForTwoRenderViews) { |
| 58 | // First there is only one view. |
| 59 | histogram_customizer_.RenderViewNavigatedToHost("mail.google.com", 1); |
| 60 | // Second view created and it navigates to the same host -> we can have a |
| 61 | // custom diagram. |
| 62 | histogram_customizer_.RenderViewNavigatedToHost("mail.google.com", 2); |
| 63 | EXPECT_EQ(std::string(kCustomizableHistogram_) + ".gmail", |
| 64 | histogram_customizer_.ConvertToCustomHistogramName( |
| 65 | kCustomizableHistogram_)); |
| 66 | EXPECT_EQ(kNormalHistogram_, |
| 67 | histogram_customizer_.ConvertToCustomHistogramName( |
| 68 | kNormalHistogram_)); |
| 69 | // Now the views diverge (one of them navigates to a different host) -> no |
| 70 | // custom diagram. |
| 71 | histogram_customizer_.RenderViewNavigatedToHost("docs.google.com", 2); |
| 72 | EXPECT_EQ(kCustomizableHistogram_, |
| 73 | histogram_customizer_.ConvertToCustomHistogramName( |
| 74 | kCustomizableHistogram_)); |
| 75 | // After this point, there will never be a custom diagram again, even if the |
| 76 | // view navigated back to the common host. |
| 77 | histogram_customizer_.RenderViewNavigatedToHost("mail.google.com", 2); |
| 78 | EXPECT_EQ(kCustomizableHistogram_, |
| 79 | histogram_customizer_.ConvertToCustomHistogramName( |
| 80 | kCustomizableHistogram_)); |
| 81 | } |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 82 | |
hablich | d6a4f12 | 2015-10-28 11:34:49 | [diff] [blame] | 83 | TEST_F(RenderThreadImplUnittest, IdentifyAlexaTop10NonGoogleSite) { |
| 84 | EXPECT_TRUE(histogram_customizer_.IsAlexaTop10NonGoogleSite("www.amazon.de")); |
| 85 | EXPECT_TRUE(histogram_customizer_.IsAlexaTop10NonGoogleSite("amazon.de")); |
| 86 | EXPECT_TRUE(histogram_customizer_.IsAlexaTop10NonGoogleSite("amazon.co.uk")); |
| 87 | EXPECT_TRUE( |
| 88 | histogram_customizer_.IsAlexaTop10NonGoogleSite("jp.wikipedia.org")); |
| 89 | EXPECT_TRUE( |
| 90 | histogram_customizer_.IsAlexaTop10NonGoogleSite("www.facebook.com")); |
| 91 | EXPECT_FALSE(histogram_customizer_.IsAlexaTop10NonGoogleSite("")); |
| 92 | EXPECT_FALSE( |
| 93 | histogram_customizer_.IsAlexaTop10NonGoogleSite("www.google.com")); |
| 94 | EXPECT_FALSE(histogram_customizer_.IsAlexaTop10NonGoogleSite("madeup")); |
| 95 | } |
| 96 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 97 | } // namespace content |