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

Side by Side Diff: chrome/browser/search/search_android_unittest.cc

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