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