Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(120)

Side by Side Diff: components/search/search_android_unittest.cc

Issue 1260033003: Partially componentize //chrome/browser/search/search.{h,cc} (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix compilation on iOS Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/search/search.cc ('k') | components/search/search_switches.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/search/search.h" 5 #include "components/search/search.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/metrics/field_trial.h" 9 #include "base/metrics/field_trial.h"
10 #include "base/metrics/statistics_recorder.h" 10 #include "base/metrics/statistics_recorder.h"
11 #include "components/search/search.h"
11 #include "components/search/search_switches.h" 12 #include "components/search/search_switches.h"
12 #include "components/variations/entropy_provider.h" 13 #include "components/variations/entropy_provider.h"
13 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
14 15
15 namespace chrome { 16 namespace search {
16 17
17 namespace { 18 namespace {
18 19
19 TEST(SearchTest, EmbeddedSearchAPIEnabled) { 20 TEST(SearchTest, EmbeddedSearchAPIEnabled) {
20 EXPECT_EQ(1ul, EmbeddedSearchPageVersion()); 21 EXPECT_EQ(1ul, EmbeddedSearchPageVersion());
21 EXPECT_FALSE(IsInstantExtendedAPIEnabled()); 22 EXPECT_FALSE(IsInstantExtendedAPIEnabled());
22 base::CommandLine::ForCurrentProcess()->AppendSwitch( 23 base::CommandLine::ForCurrentProcess()->AppendSwitch(
23 switches::kEnableEmbeddedSearchAPI); 24 switches::kEnableEmbeddedSearchAPI);
24 EXPECT_EQ(2ul, EmbeddedSearchPageVersion()); 25 EXPECT_EQ(2ul, EmbeddedSearchPageVersion());
25 EXPECT_TRUE(IsInstantExtendedAPIEnabled()); 26 EXPECT_TRUE(IsInstantExtendedAPIEnabled());
26 } 27 }
27 28
29 TEST(SearchTest, QueryExtractionEnabled) {
30 // Query extraction is always enabled on mobile.
31 EXPECT_TRUE(IsQueryExtractionEnabled());
32 }
33
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();
40 }
41
42 private:
43 scoped_ptr<base::FieldTrialList> field_trial_list_;
44 };
45
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));
52 }
53
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());
60 }
61
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());
68 }
69
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());
75 }
76
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());
85 }
86
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());
95 }
96
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());
103 }
104
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());
111 }
112
28 } // namespace 113 } // namespace
29 114
30 } // namespace chrome 115 } // namespace chrome
OLDNEW
« no previous file with comments | « components/search/search.cc ('k') | components/search/search_switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698