summaryrefslogtreecommitdiffstats
path: root/components/search/search_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'components/search/search_unittest.cc')
-rw-r--r--components/search/search_unittest.cc133
1 files changed, 133 insertions, 0 deletions
diff --git a/components/search/search_unittest.cc b/components/search/search_unittest.cc
new file mode 100644
index 0000000..b8c4e1d
--- /dev/null
+++ b/components/search/search_unittest.cc
@@ -0,0 +1,133 @@
+// Copyright 2014 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 "components/search/search.h"
+
+#include "base/metrics/field_trial.h"
+#include "base/metrics/statistics_recorder.h"
+#include "components/variations/entropy_provider.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace chrome {
+
+class EmbeddedSearchFieldTrialTest : public testing::Test {
+ protected:
+ virtual void SetUp() {
+ field_trial_list_.reset(new base::FieldTrialList(
+ new metrics::SHA1EntropyProvider("42")));
+ base::StatisticsRecorder::Initialize();
+ }
+
+ private:
+ scoped_ptr<base::FieldTrialList> field_trial_list_;
+};
+
+TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoEmptyAndValid) {
+ FieldTrialFlags flags;
+
+ EXPECT_TRUE(GetFieldTrialInfo(&flags));
+ EXPECT_EQ(0ul, flags.size());
+
+ ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch",
+ "Group77"));
+ EXPECT_TRUE(GetFieldTrialInfo(&flags));
+ EXPECT_EQ(0ul, flags.size());
+}
+
+TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoInvalidNumber) {
+ FieldTrialFlags flags;
+
+ ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch",
+ "Group77.2"));
+ EXPECT_TRUE(GetFieldTrialInfo(&flags));
+ EXPECT_EQ(0ul, flags.size());
+}
+
+TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoInvalidName) {
+ FieldTrialFlags flags;
+
+ ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch",
+ "Invalid77"));
+ EXPECT_TRUE(GetFieldTrialInfo(&flags));
+ EXPECT_EQ(0ul, flags.size());
+}
+
+TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoValidGroup) {
+ FieldTrialFlags flags;
+
+ ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch",
+ "Group77"));
+ EXPECT_TRUE(GetFieldTrialInfo(&flags));
+ EXPECT_EQ(0ul, flags.size());
+}
+
+TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoValidFlag) {
+ FieldTrialFlags flags;
+
+ EXPECT_EQ(9999ul, GetUInt64ValueForFlagWithDefault("foo", 9999, flags));
+ ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch",
+ "Group77 foo:6"));
+ EXPECT_TRUE(GetFieldTrialInfo(&flags));
+ EXPECT_EQ(1ul, flags.size());
+ EXPECT_EQ(6ul, GetUInt64ValueForFlagWithDefault("foo", 9999, flags));
+}
+
+TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoNewName) {
+ FieldTrialFlags flags;
+
+ EXPECT_EQ(9999ul, GetUInt64ValueForFlagWithDefault("foo", 9999, flags));
+ ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch",
+ "Group77 foo:6"));
+ EXPECT_TRUE(GetFieldTrialInfo(&flags));
+ EXPECT_EQ(1ul, flags.size());
+ EXPECT_EQ(6ul, GetUInt64ValueForFlagWithDefault("foo", 9999, flags));
+}
+
+TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoNewNameOverridesOld) {
+ FieldTrialFlags flags;
+
+ EXPECT_EQ(9999ul, GetUInt64ValueForFlagWithDefault("foo", 9999, flags));
+ ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch",
+ "Group77 foo:6"));
+ ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("InstantExtended",
+ "Group78 foo:5"));
+ EXPECT_TRUE(GetFieldTrialInfo(&flags));
+ EXPECT_EQ(1ul, flags.size());
+ EXPECT_EQ(6ul, GetUInt64ValueForFlagWithDefault("foo", 9999, flags));
+}
+
+TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoLotsOfFlags) {
+ FieldTrialFlags flags;
+
+ ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
+ "EmbeddedSearch", "Group77 bar:1 baz:7 cat:dogs"));
+ EXPECT_TRUE(GetFieldTrialInfo(&flags));
+ EXPECT_EQ(3ul, flags.size());
+ EXPECT_EQ(true, GetBoolValueForFlagWithDefault("bar", false, flags));
+ EXPECT_EQ(7ul, GetUInt64ValueForFlagWithDefault("baz", 0, flags));
+ EXPECT_EQ("dogs",
+ GetStringValueForFlagWithDefault("cat", std::string(), flags));
+ EXPECT_EQ("default",
+ GetStringValueForFlagWithDefault("moose", "default", flags));
+}
+
+TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoDisabled) {
+ FieldTrialFlags flags;
+
+ ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
+ "EmbeddedSearch", "Group77 bar:1 baz:7 cat:dogs DISABLED"));
+ EXPECT_FALSE(GetFieldTrialInfo(&flags));
+ EXPECT_EQ(0ul, flags.size());
+}
+
+TEST_F(EmbeddedSearchFieldTrialTest, GetFieldTrialInfoControlFlags) {
+ FieldTrialFlags flags;
+
+ ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
+ "EmbeddedSearch", "Control77 bar:1 baz:7 cat:dogs"));
+ EXPECT_TRUE(GetFieldTrialInfo(&flags));
+ EXPECT_EQ(3ul, flags.size());
+}
+
+} // namespace chrome