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

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

Powered by Google App Engine
This is Rietveld 408576698