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

Side by Side Diff: chrome/browser/android/contextualsearch/contextual_search_field_trial_unittest.cc

Issue 2351283002: [TTS] Decode Now on Tap results for v1 integration. (Closed)
Patch Set: Created 4 years, 3 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/android/contextualsearch/contextual_search_field_trial. h" 5 #include "chrome/browser/android/contextualsearch/contextual_search_field_trial. h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 11
12 // Tests ContextualSearchFieldTrail class. 12 // Tests ContextualSearchFieldTrial class.
13 class ContextualSearchFieldTrailTest : public testing::Test { 13 class ContextualSearchFieldTrialTest : public testing::Test {
14 public: 14 public:
15 ContextualSearchFieldTrailTest() {} 15 ContextualSearchFieldTrialTest() {}
16 ~ContextualSearchFieldTrailTest() override {} 16 ~ContextualSearchFieldTrialTest() override {}
17 17
18 // Inner class that stubs out access to Variations and command-line switches. 18 // Inner class that stubs out access to Variations and command-line switches.
19 class ContextualSearchFieldTrailStubbed : public ContextualSearchFieldTrial { 19 class ContextualSearchFieldTrialStubbed : public ContextualSearchFieldTrial {
20 public: 20 public:
21 // Use these to set a non-empty value to override return of a Get method. 21 // Use these to set a non-empty value to override return of a Get method.
22 void SetSwitchValue(const std::string& value); 22 void SetSwitchValue(const std::string& value);
23 void SetParamValue(const std::string& value); 23 void SetParamValue(const std::string& value);
24 24
25 protected: 25 protected:
26 // These are overridden to return the Set value above. 26 // These are overridden to return the Set value above.
27 bool HasSwitch(const std::string& name) override; 27 bool HasSwitch(const std::string& name) override;
28 std::string GetSwitch(const std::string& name) override; 28 std::string GetSwitch(const std::string& name) override;
29 std::string GetParam(const std::string& name) override; 29 std::string GetParam(const std::string& name) override;
30 30
31 private: 31 private:
32 bool does_have_switch_; 32 bool does_have_switch_;
33 std::string switch_value_; 33 std::string switch_value_;
34 std::string param_value_; 34 std::string param_value_;
35 }; 35 };
36 36
37 // The class under test. 37 // The class under test.
38 std::unique_ptr<ContextualSearchFieldTrailStubbed> field_trial_; 38 std::unique_ptr<ContextualSearchFieldTrialStubbed> field_trial_;
39 39
40 protected: 40 protected:
41 void SetUp() override { 41 void SetUp() override {
42 field_trial_.reset(new ContextualSearchFieldTrailStubbed()); 42 field_trial_.reset(new ContextualSearchFieldTrialStubbed());
43 } 43 }
44 44
45 void TearDown() override {} 45 void TearDown() override {}
46 46
47 private: 47 private:
48 DISALLOW_COPY_AND_ASSIGN(ContextualSearchFieldTrailTest); 48 DISALLOW_COPY_AND_ASSIGN(ContextualSearchFieldTrialTest);
49 }; 49 };
50 50
51 bool ContextualSearchFieldTrailTest::ContextualSearchFieldTrailStubbed:: 51 bool ContextualSearchFieldTrialTest::ContextualSearchFieldTrialStubbed::
52 HasSwitch(const std::string& name) { 52 HasSwitch(const std::string& name) {
53 return does_have_switch_; 53 return does_have_switch_;
54 } 54 }
55 55
56 void ContextualSearchFieldTrailTest::ContextualSearchFieldTrailStubbed:: 56 void ContextualSearchFieldTrialTest::ContextualSearchFieldTrialStubbed::
57 SetSwitchValue(const std::string& value) { 57 SetSwitchValue(const std::string& value) {
58 switch_value_ = value; 58 switch_value_ = value;
59 does_have_switch_ = true; 59 does_have_switch_ = true;
60 } 60 }
61 61
62 std::string 62 std::string
63 ContextualSearchFieldTrailTest::ContextualSearchFieldTrailStubbed::GetSwitch( 63 ContextualSearchFieldTrialTest::ContextualSearchFieldTrialStubbed::GetSwitch(
64 const std::string& name) { 64 const std::string& name) {
65 return switch_value_; 65 return switch_value_;
66 } 66 }
67 67
68 void ContextualSearchFieldTrailTest::ContextualSearchFieldTrailStubbed:: 68 void ContextualSearchFieldTrialTest::ContextualSearchFieldTrialStubbed::
69 SetParamValue(const std::string& value) { 69 SetParamValue(const std::string& value) {
70 param_value_ = value; 70 param_value_ = value;
71 } 71 }
72 72
73 std::string 73 std::string
74 ContextualSearchFieldTrailTest::ContextualSearchFieldTrailStubbed::GetParam( 74 ContextualSearchFieldTrialTest::ContextualSearchFieldTrialStubbed::GetParam(
75 const std::string& name) { 75 const std::string& name) {
76 return param_value_; 76 return param_value_;
77 } 77 }
78 78
79 TEST_F(ContextualSearchFieldTrailTest, IntegerDefaultValue) { 79 TEST_F(ContextualSearchFieldTrialTest, IntegerDefaultValue) {
80 // Should return this default value. 80 // Should return this default value.
81 EXPECT_EQ( 81 EXPECT_EQ(
82 ContextualSearchFieldTrial::kContextualSearchDefaultIcingSurroundingSize, 82 ContextualSearchFieldTrial::kContextualSearchDefaultIcingSurroundingSize,
83 field_trial_->GetIcingSurroundingSize()); 83 field_trial_->GetIcingSurroundingSize());
84 } 84 }
85 85
86 TEST_F(ContextualSearchFieldTrailTest, IntegerParamOverrides) { 86 TEST_F(ContextualSearchFieldTrialTest, IntegerParamOverrides) {
87 // Params override defaults. 87 // Params override defaults.
88 field_trial_->SetParamValue("500"); 88 field_trial_->SetParamValue("500");
89 EXPECT_EQ(500, field_trial_->GetIcingSurroundingSize()); 89 EXPECT_EQ(500, field_trial_->GetIcingSurroundingSize());
90 } 90 }
91 91
92 TEST_F(ContextualSearchFieldTrailTest, IntegerSwitchOverrides) { 92 TEST_F(ContextualSearchFieldTrialTest, IntegerSwitchOverrides) {
93 field_trial_->SetParamValue("500"); 93 field_trial_->SetParamValue("500");
94 // Switches override params. 94 // Switches override params.
95 field_trial_->SetSwitchValue("200"); 95 field_trial_->SetSwitchValue("200");
96 EXPECT_EQ(200, field_trial_->GetIcingSurroundingSize()); 96 EXPECT_EQ(200, field_trial_->GetIcingSurroundingSize());
97 } 97 }
98 98
99 TEST_F(ContextualSearchFieldTrailTest, IntegerJunkIgnored) { 99 TEST_F(ContextualSearchFieldTrialTest, IntegerJunkIgnored) {
100 // A junk value effectively resets the switch. 100 // A junk value effectively resets the switch.
101 field_trial_->SetSwitchValue("foo"); 101 field_trial_->SetSwitchValue("foo");
102 EXPECT_EQ( 102 EXPECT_EQ(
103 ContextualSearchFieldTrial::kContextualSearchDefaultIcingSurroundingSize, 103 ContextualSearchFieldTrial::kContextualSearchDefaultIcingSurroundingSize,
104 field_trial_->GetIcingSurroundingSize()); 104 field_trial_->GetIcingSurroundingSize());
105 } 105 }
106 106
107 TEST_F(ContextualSearchFieldTrailTest, BooleanDefaultValue) { 107 TEST_F(ContextualSearchFieldTrialTest, BooleanDefaultValue) {
108 // Should return this default value. 108 // Should return this default value.
109 EXPECT_FALSE(field_trial_->IsSendBasePageURLDisabled()); 109 EXPECT_FALSE(field_trial_->IsSendBasePageURLDisabled());
110 } 110 }
111 111
112 TEST_F(ContextualSearchFieldTrailTest, BooleanParamOverrides) { 112 TEST_F(ContextualSearchFieldTrialTest, BooleanParamOverrides) {
113 // Params override defaults. 113 // Params override defaults.
114 field_trial_->SetParamValue("any"); 114 field_trial_->SetParamValue("any");
115 EXPECT_TRUE(field_trial_->IsSendBasePageURLDisabled()); 115 EXPECT_TRUE(field_trial_->IsSendBasePageURLDisabled());
116 } 116 }
117 117
118 TEST_F(ContextualSearchFieldTrailTest, BooleanFalseParam) { 118 TEST_F(ContextualSearchFieldTrialTest, BooleanFalseParam) {
119 field_trial_->SetParamValue("false"); 119 field_trial_->SetParamValue("false");
120 EXPECT_FALSE(field_trial_->IsSendBasePageURLDisabled()); 120 EXPECT_FALSE(field_trial_->IsSendBasePageURLDisabled());
121 } 121 }
122 122
123 TEST_F(ContextualSearchFieldTrailTest, BooleanSwitchOverrides) { 123 TEST_F(ContextualSearchFieldTrialTest, BooleanSwitchOverrides) {
124 field_trial_->SetParamValue("false"); 124 field_trial_->SetParamValue("false");
125 // Switches override params. 125 // Switches override params.
126 field_trial_->SetSwitchValue("any"); 126 field_trial_->SetSwitchValue("any");
127 EXPECT_TRUE(field_trial_->IsSendBasePageURLDisabled()); 127 EXPECT_TRUE(field_trial_->IsSendBasePageURLDisabled());
128 } 128 }
129 129
130 TEST_F(ContextualSearchFieldTrailTest, BooleanEmptySwitch) { 130 TEST_F(ContextualSearchFieldTrialTest, BooleanEmptySwitch) {
131 // An empty switch that's present should return true; 131 // An empty switch that's present should return true;
132 field_trial_->SetSwitchValue(""); 132 field_trial_->SetSwitchValue("");
133 EXPECT_TRUE(field_trial_->IsSendBasePageURLDisabled()); 133 EXPECT_TRUE(field_trial_->IsSendBasePageURLDisabled());
134 } 134 }
135 135
136 TEST_F(ContextualSearchFieldTrailTest, StringDefaultEmpty) { 136 TEST_F(ContextualSearchFieldTrialTest, StringDefaultEmpty) {
137 // Default should return an empty string. 137 // Default should return an empty string.
138 EXPECT_TRUE(field_trial_->GetResolverURLPrefix().empty()); 138 EXPECT_TRUE(field_trial_->GetResolverURLPrefix().empty());
139 } 139 }
140 140
141 TEST_F(ContextualSearchFieldTrailTest, StringParamOverrides) { 141 TEST_F(ContextualSearchFieldTrialTest, StringParamOverrides) {
142 // Params override. 142 // Params override.
143 field_trial_->SetParamValue("param"); 143 field_trial_->SetParamValue("param");
144 EXPECT_EQ("param", field_trial_->GetResolverURLPrefix()); 144 EXPECT_EQ("param", field_trial_->GetResolverURLPrefix());
145 } 145 }
146 146
147 TEST_F(ContextualSearchFieldTrailTest, StringSwitchOverrides) { 147 TEST_F(ContextualSearchFieldTrialTest, StringSwitchOverrides) {
148 field_trial_->SetParamValue("param"); 148 field_trial_->SetParamValue("param");
149 // Switches override params. 149 // Switches override params.
150 field_trial_->SetSwitchValue("switch"); 150 field_trial_->SetSwitchValue("switch");
151 EXPECT_EQ("switch", field_trial_->GetResolverURLPrefix()); 151 EXPECT_EQ("switch", field_trial_->GetResolverURLPrefix());
152 } 152 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698