OLD | NEW |
---|---|
(Empty) | |
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 | |
10 class RenderThreadImplUnittest : public testing::Test { | |
11 public: | |
12 RenderThreadImplUnittest() | |
13 : kCustomizableHistogram_("Histogram1"), | |
14 kNormalHistogram_("Histogram2") {} | |
15 ~RenderThreadImplUnittest() {} | |
16 protected: | |
17 virtual void SetUp() OVERRIDE { | |
18 histogram_customizer_.custom_histograms_.clear(); | |
19 histogram_customizer_.custom_histograms_.insert(kCustomizableHistogram_); | |
20 } | |
21 RenderThreadImpl::HistogramCustomizer histogram_customizer_; | |
22 const char* kCustomizableHistogram_; | |
23 const char* kNormalHistogram_; | |
24 }; | |
25 | |
26 TEST_F(RenderThreadImplUnittest, CustomHistogramsWithNoNavigations) { | |
27 // First there is no page -> no custom histograms. | |
28 EXPECT_EQ(kCustomizableHistogram_, | |
29 histogram_customizer_.ConvertToCustomHistogramName( | |
30 kCustomizableHistogram_)); | |
31 EXPECT_EQ(kNormalHistogram_, | |
32 histogram_customizer_.ConvertToCustomHistogramName( | |
33 kNormalHistogram_)); | |
34 } | |
35 | |
36 TEST_F(RenderThreadImplUnittest, CustomHistogramsForOneRenderView) { | |
37 histogram_customizer_.RenderViewNavigatedToHost("mail.google.com", 1); | |
38 EXPECT_EQ(std::string(kCustomizableHistogram_) + ".gmail", | |
39 histogram_customizer_.ConvertToCustomHistogramName( | |
40 kCustomizableHistogram_)); | |
41 EXPECT_EQ(kNormalHistogram_, | |
42 histogram_customizer_.ConvertToCustomHistogramName( | |
43 kNormalHistogram_)); | |
44 histogram_customizer_.RenderViewNavigatedToHost("docs.google.com", 1); | |
45 EXPECT_EQ(std::string(kCustomizableHistogram_) + ".docs", | |
46 histogram_customizer_.ConvertToCustomHistogramName( | |
47 kCustomizableHistogram_)); | |
48 histogram_customizer_.RenderViewNavigatedToHost("nottracked.com", 1); | |
49 EXPECT_EQ(kCustomizableHistogram_, | |
50 histogram_customizer_.ConvertToCustomHistogramName( | |
51 kCustomizableHistogram_)); | |
52 } | |
53 | |
54 TEST_F(RenderThreadImplUnittest, CustomHistogramsForTwoRenderViews) { | |
55 // First there is only one view. | |
56 histogram_customizer_.RenderViewNavigatedToHost("mail.google.com", 1); | |
57 // Second view created and it navigates to the same host -> we can have a | |
58 // custom diagram. | |
59 histogram_customizer_.RenderViewNavigatedToHost("mail.google.com", 2); | |
60 EXPECT_EQ(std::string(kCustomizableHistogram_) + ".gmail", | |
61 histogram_customizer_.ConvertToCustomHistogramName( | |
62 kCustomizableHistogram_)); | |
63 EXPECT_EQ(kNormalHistogram_, | |
64 histogram_customizer_.ConvertToCustomHistogramName( | |
65 kNormalHistogram_)); | |
66 // Now the views diverge (one of them navigates to a different host) -> no | |
67 // custom diagram. | |
68 histogram_customizer_.RenderViewNavigatedToHost("docs.google.com", 2); | |
69 EXPECT_EQ(kCustomizableHistogram_, | |
70 histogram_customizer_.ConvertToCustomHistogramName( | |
71 kCustomizableHistogram_)); | |
72 // After this point, there will never be a custom diagram again, even if the | |
73 // view navigated back to the common host. | |
Charlie Reis
2012/08/23 16:30:40
Are you ok with there being a custom histogram aga
marja
2012/08/24 09:29:10
I think so; I'd assume that all resources from the
| |
74 histogram_customizer_.RenderViewNavigatedToHost("mail.google.com", 2); | |
75 EXPECT_EQ(kCustomizableHistogram_, | |
76 histogram_customizer_.ConvertToCustomHistogramName( | |
77 kCustomizableHistogram_)); | |
78 } | |
OLD | NEW |