| Index: content/renderer/render_thread_impl_unittest.cc
|
| diff --git a/content/renderer/render_thread_impl_unittest.cc b/content/renderer/render_thread_impl_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..44b3a7cb72f8ab4b96bfe2b795b1ac61348b678b
|
| --- /dev/null
|
| +++ b/content/renderer/render_thread_impl_unittest.cc
|
| @@ -0,0 +1,78 @@
|
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "content/renderer/render_thread_impl.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +#include <string>
|
| +
|
| +class RenderThreadImplUnittest : public testing::Test {
|
| + public:
|
| + RenderThreadImplUnittest()
|
| + : kCustomizableHistogram_("Histogram1"),
|
| + kNormalHistogram_("Histogram2") {}
|
| + ~RenderThreadImplUnittest() {}
|
| + protected:
|
| + virtual void SetUp() OVERRIDE {
|
| + histogram_customizer_.custom_histograms_.clear();
|
| + histogram_customizer_.custom_histograms_.insert(kCustomizableHistogram_);
|
| + }
|
| + RenderThreadImpl::HistogramCustomizer histogram_customizer_;
|
| + const char* kCustomizableHistogram_;
|
| + const char* kNormalHistogram_;
|
| +};
|
| +
|
| +TEST_F(RenderThreadImplUnittest, CustomHistogramsWithNoNavigations) {
|
| + // First there is no page -> no custom histograms.
|
| + EXPECT_EQ(kCustomizableHistogram_,
|
| + histogram_customizer_.ConvertToCustomHistogramName(
|
| + kCustomizableHistogram_));
|
| + EXPECT_EQ(kNormalHistogram_,
|
| + histogram_customizer_.ConvertToCustomHistogramName(
|
| + kNormalHistogram_));
|
| +}
|
| +
|
| +TEST_F(RenderThreadImplUnittest, CustomHistogramsForOneRenderView) {
|
| + histogram_customizer_.RenderViewNavigatedToHost("mail.google.com", 1);
|
| + EXPECT_EQ(std::string(kCustomizableHistogram_) + ".gmail",
|
| + histogram_customizer_.ConvertToCustomHistogramName(
|
| + kCustomizableHistogram_));
|
| + EXPECT_EQ(kNormalHistogram_,
|
| + histogram_customizer_.ConvertToCustomHistogramName(
|
| + kNormalHistogram_));
|
| + histogram_customizer_.RenderViewNavigatedToHost("docs.google.com", 1);
|
| + EXPECT_EQ(std::string(kCustomizableHistogram_) + ".docs",
|
| + histogram_customizer_.ConvertToCustomHistogramName(
|
| + kCustomizableHistogram_));
|
| + histogram_customizer_.RenderViewNavigatedToHost("nottracked.com", 1);
|
| + EXPECT_EQ(kCustomizableHistogram_,
|
| + histogram_customizer_.ConvertToCustomHistogramName(
|
| + kCustomizableHistogram_));
|
| +}
|
| +
|
| +TEST_F(RenderThreadImplUnittest, CustomHistogramsForTwoRenderViews) {
|
| + // First there is only one view.
|
| + histogram_customizer_.RenderViewNavigatedToHost("mail.google.com", 1);
|
| + // Second view created and it navigates to the same host -> we can have a
|
| + // custom diagram.
|
| + histogram_customizer_.RenderViewNavigatedToHost("mail.google.com", 2);
|
| + EXPECT_EQ(std::string(kCustomizableHistogram_) + ".gmail",
|
| + histogram_customizer_.ConvertToCustomHistogramName(
|
| + kCustomizableHistogram_));
|
| + EXPECT_EQ(kNormalHistogram_,
|
| + histogram_customizer_.ConvertToCustomHistogramName(
|
| + kNormalHistogram_));
|
| + // Now the views diverge (one of them navigates to a different host) -> no
|
| + // custom diagram.
|
| + histogram_customizer_.RenderViewNavigatedToHost("docs.google.com", 2);
|
| + EXPECT_EQ(kCustomizableHistogram_,
|
| + histogram_customizer_.ConvertToCustomHistogramName(
|
| + kCustomizableHistogram_));
|
| + // After this point, there will never be a custom diagram again, even if the
|
| + // view navigated back to the common host.
|
| + histogram_customizer_.RenderViewNavigatedToHost("mail.google.com", 2);
|
| + EXPECT_EQ(kCustomizableHistogram_,
|
| + histogram_customizer_.ConvertToCustomHistogramName(
|
| + kCustomizableHistogram_));
|
| +}
|
|
|