Update V8 to version 4.6.62.
[chromium-blink-merge.git] / components / search / search_android_unittest.cc
blobf5c83206f7bc523acb0b13f743faa8a04f184d46
1 // Copyright 2014 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.
5 #include "components/search/search.h"
7 #include "base/command_line.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/metrics/field_trial.h"
10 #include "base/metrics/statistics_recorder.h"
11 #include "components/search/search.h"
12 #include "components/search/search_switches.h"
13 #include "components/variations/entropy_provider.h"
14 #include "testing/gtest/include/gtest/gtest.h"
16 namespace search {
18 namespace {
20 TEST(SearchTest, EmbeddedSearchAPIEnabled) {
21 EXPECT_EQ(1ul, EmbeddedSearchPageVersion());
22 EXPECT_FALSE(IsInstantExtendedAPIEnabled());
23 base::CommandLine::ForCurrentProcess()->AppendSwitch(
24 switches::kEnableEmbeddedSearchAPI);
25 EXPECT_EQ(2ul, EmbeddedSearchPageVersion());
26 EXPECT_TRUE(IsInstantExtendedAPIEnabled());
29 TEST(SearchTest, QueryExtractionEnabled) {
30 // Query extraction is always enabled on mobile.
31 EXPECT_TRUE(IsQueryExtractionEnabled());
34 class SearchUtilTest : public testing::Test {
35 protected:
36 void SetUp() override {
37 field_trial_list_.reset(
38 new base::FieldTrialList(new metrics::SHA1EntropyProvider("42")));
39 base::StatisticsRecorder::Initialize();
42 private:
43 scoped_ptr<base::FieldTrialList> field_trial_list_;
46 TEST_F(SearchUtilTest, UseDefaultEmbeddedSearchPageVersion) {
47 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
48 "EmbeddedSearch", "Group1 espv:-1 query_extraction:1"));
49 EXPECT_TRUE(IsQueryExtractionEnabled());
50 EXPECT_EQ("espv=1&", InstantExtendedEnabledParam(true));
51 EXPECT_EQ("espv=1&", InstantExtendedEnabledParam(false));
54 TEST_F(SearchUtilTest, ShouldPrefetchSearchResults_InstantExtendedAPIEnabled) {
55 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
56 "EmbeddedSearch", "Group1 espv:2 prefetch_results:1"));
57 EXPECT_TRUE(ShouldPrefetchSearchResults());
58 EXPECT_TRUE(IsInstantExtendedAPIEnabled());
59 EXPECT_EQ(2ul, EmbeddedSearchPageVersion());
62 TEST_F(SearchUtilTest, ShouldPrefetchSearchResults_InstantExtendedAPIDisabled) {
63 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
64 "EmbeddedSearch", "Group1 espv:1 prefetch_results:1"));
65 EXPECT_FALSE(ShouldPrefetchSearchResults());
66 EXPECT_FALSE(IsInstantExtendedAPIEnabled());
67 EXPECT_EQ(1ul, EmbeddedSearchPageVersion());
70 TEST_F(SearchUtilTest, ShouldPrefetchSearchResults_DisabledViaFieldTrials) {
71 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
72 "EmbeddedSearch", "Group1 espv:2 prefetch_results:0"));
73 EXPECT_FALSE(ShouldPrefetchSearchResults());
74 EXPECT_EQ(2ul, EmbeddedSearchPageVersion());
77 TEST_F(SearchUtilTest, ShouldPrefetchSearchResults_EnabledViaCommandLine) {
78 base::CommandLine::ForCurrentProcess()->AppendSwitch(
79 switches::kPrefetchSearchResults);
80 // Command-line enable should override Finch.
81 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
82 "EmbeddedSearch", "Group1 espv:2 prefetch_results:0"));
83 EXPECT_TRUE(ShouldPrefetchSearchResults());
84 EXPECT_EQ(2ul, EmbeddedSearchPageVersion());
87 TEST_F(SearchUtilTest,
88 ShouldReuseInstantSearchBasePage_PrefetchResultsFlagDisabled) {
89 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
90 "EmbeddedSearch",
91 "Group1 espv:2 prefetch_results:0 reuse_instant_search_base_page:1"));
92 EXPECT_FALSE(ShouldPrefetchSearchResults());
93 EXPECT_FALSE(ShouldReuseInstantSearchBasePage());
94 EXPECT_EQ(2ul, EmbeddedSearchPageVersion());
97 TEST_F(SearchUtilTest, ShouldReuseInstantSearchBasePage_EnabledViaFieldTrial) {
98 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
99 "EmbeddedSearch",
100 "Group1 espv:2 prefetch_results:1 reuse_instant_search_base_page:1"));
101 EXPECT_TRUE(ShouldReuseInstantSearchBasePage());
102 EXPECT_EQ(2ul, EmbeddedSearchPageVersion());
105 TEST_F(SearchUtilTest, ShouldReuseInstantSearchBasePage_DisabledViaFieldTrial) {
106 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
107 "EmbeddedSearch",
108 "Group1 espv:2 prefetch_results:1 reuse_instant_search_base_page:0"));
109 EXPECT_FALSE(ShouldReuseInstantSearchBasePage());
110 EXPECT_EQ(2ul, EmbeddedSearchPageVersion());
113 } // namespace
115 } // namespace chrome