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

Side by Side Diff: chrome/browser/autocomplete/builtin_provider_unittest.cc

Issue 290333015: Suggest about:blank autocompletion from BuiltinProvider. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix OmniboxViewTest.UndoRedo, minor cleanup. Created 6 years, 6 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
Mark P 2014/05/29 23:48:05 Thank you for simplifying this file.
msw 2014/05/30 00:29:49 :)
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/autocomplete/builtin_provider.h" 5 #include "chrome/browser/autocomplete/builtin_provider.h"
6 6
7 #include "base/message_loop/message_loop.h" 7 #include "base/format_macros.h"
8 #include "base/strings/stringprintf.h"
8 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/autocomplete/autocomplete_input.h" 10 #include "chrome/browser/autocomplete/autocomplete_input.h"
10 #include "chrome/browser/autocomplete/autocomplete_match.h" 11 #include "chrome/browser/autocomplete/autocomplete_match.h"
11 #include "chrome/browser/autocomplete/autocomplete_provider.h" 12 #include "chrome/browser/autocomplete/autocomplete_provider.h"
12 #include "chrome/common/url_constants.h" 13 #include "chrome/common/url_constants.h"
13 #include "chrome/test/base/testing_browser_process.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "url/gurl.h" 15 #include "url/gurl.h"
16 16
17 using base::ASCIIToUTF16; 17 using base::ASCIIToUTF16;
18 18
19 class BuiltinProviderTest : public testing::Test { 19 class BuiltinProviderTest : public testing::Test {
20 protected: 20 protected:
21 template<class ResultType> 21 struct TestData {
22 struct test_data {
23 const base::string16 input; 22 const base::string16 input;
24 const size_t num_results; 23 const size_t num_results;
25 const ResultType output[3]; 24 const GURL output[3];
26 }; 25 };
27 26
28 BuiltinProviderTest() : builtin_provider_(NULL) {} 27 BuiltinProviderTest() : provider_(NULL) {}
29 virtual ~BuiltinProviderTest() {} 28 virtual ~BuiltinProviderTest() {}
30 29
31 virtual void SetUp(); 30 virtual void SetUp() OVERRIDE { provider_ = new BuiltinProvider(NULL, NULL); }
32 virtual void TearDown(); 31 virtual void TearDown() OVERRIDE { provider_ = NULL; }
33 32
34 template<class ResultType> 33 void RunTest(const TestData cases[], size_t num_cases) {
35 void RunTest(test_data<ResultType>* builtin_cases, 34 ACMatches matches;
36 int num_cases, 35 for (size_t i = 0; i < num_cases; ++i) {
37 ResultType AutocompleteMatch::* member); 36 SCOPED_TRACE(base::StringPrintf(
38 37 "case %" PRIuS ": %s", i, base::UTF16ToUTF8(cases[i].input).c_str()));
39 protected: 38 const AutocompleteInput input(cases[i].input, base::string16::npos,
40 scoped_refptr<BuiltinProvider> builtin_provider_; 39 base::string16(), GURL(), AutocompleteInput::INVALID_SPEC, true,
Mark P 2014/05/29 23:48:05 nit: indentation
msw 2014/05/30 00:29:49 Done.
41 }; 40 false, true, true);
42 41 provider_->Start(input, false);
43 void BuiltinProviderTest::SetUp() { 42 EXPECT_TRUE(provider_->done());
44 builtin_provider_ = new BuiltinProvider(NULL, NULL); 43 matches = provider_->matches();
45 } 44 EXPECT_EQ(cases[i].num_results, matches.size());
46 45 if (matches.size() == cases[i].num_results) {
47 void BuiltinProviderTest::TearDown() { 46 for (size_t j = 0; j < cases[i].num_results; ++j) {
48 builtin_provider_ = NULL; 47 EXPECT_EQ(cases[i].output[j], matches[j].destination_url);
49 } 48 EXPECT_FALSE(matches[j].allowed_to_be_default_match);
50 49 }
51 template<class ResultType>
52 void BuiltinProviderTest::RunTest(test_data<ResultType>* builtin_cases,
53 int num_cases,
54 ResultType AutocompleteMatch::* member) {
55 ACMatches matches;
56 for (int i = 0; i < num_cases; ++i) {
57 AutocompleteInput input(builtin_cases[i].input, base::string16::npos,
58 base::string16(), GURL(),
59 AutocompleteInput::INVALID_SPEC, true,
60 false, true, true);
61 builtin_provider_->Start(input, false);
62 EXPECT_TRUE(builtin_provider_->done());
63 matches = builtin_provider_->matches();
64 EXPECT_EQ(builtin_cases[i].num_results, matches.size()) <<
65 ASCIIToUTF16("Input was: ") << builtin_cases[i].input;
66 if (matches.size() == builtin_cases[i].num_results) {
67 for (size_t j = 0; j < builtin_cases[i].num_results; ++j) {
68 EXPECT_EQ(builtin_cases[i].output[j], matches[j].*member) <<
69 ASCIIToUTF16("Input was: ") << builtin_cases[i].input;
70 EXPECT_FALSE(matches[j].allowed_to_be_default_match);
71 } 50 }
72 } 51 }
73 } 52 }
74 } 53
54 private:
55 scoped_refptr<BuiltinProvider> provider_;
56
57 DISALLOW_COPY_AND_ASSIGN(BuiltinProviderTest);
58 };
75 59
76 #if !defined(OS_ANDROID) 60 #if !defined(OS_ANDROID)
77 TEST_F(BuiltinProviderTest, TypingScheme) { 61 TEST_F(BuiltinProviderTest, TypingScheme) {
78 const base::string16 kAbout = ASCIIToUTF16(content::kAboutScheme); 62 const base::string16 kAbout = ASCIIToUTF16(content::kAboutScheme);
79 const base::string16 kChrome = ASCIIToUTF16(content::kChromeUIScheme); 63 const base::string16 kChrome = ASCIIToUTF16(content::kChromeUIScheme);
80 const base::string16 kSeparator1 = ASCIIToUTF16(":"); 64 const base::string16 kSeparator1 = ASCIIToUTF16(":");
81 const base::string16 kSeparator2 = ASCIIToUTF16(":/"); 65 const base::string16 kSeparator2 = ASCIIToUTF16(":/");
82 const base::string16 kSeparator3 = 66 const base::string16 kSeparator3 =
83 ASCIIToUTF16(content::kStandardSchemeSeparator); 67 ASCIIToUTF16(content::kStandardSchemeSeparator);
84 68
85 // These default URLs should correspond with those in BuiltinProvider::Start. 69 // These default URLs should correspond with those in BuiltinProvider::Start.
86 const GURL kURL1 = GURL(chrome::kChromeUIChromeURLsURL); 70 const GURL kURL1 = GURL(chrome::kChromeUIChromeURLsURL);
87 const GURL kURL2 = GURL(chrome::kChromeUISettingsURL); 71 const GURL kURL2 = GURL(chrome::kChromeUISettingsURL);
88 const GURL kURL3 = GURL(chrome::kChromeUIVersionURL); 72 const GURL kURL3 = GURL(chrome::kChromeUIVersionURL);
89 73
90 test_data<GURL> typing_scheme_cases[] = { 74 TestData typing_scheme_cases[] = {
91 // Typing an unrelated scheme should give nothing. 75 // Typing an unrelated scheme should give nothing.
92 {ASCIIToUTF16("h"), 0, {}}, 76 {ASCIIToUTF16("h"), 0, {}},
93 {ASCIIToUTF16("http"), 0, {}}, 77 {ASCIIToUTF16("http"), 0, {}},
94 {ASCIIToUTF16("file"), 0, {}}, 78 {ASCIIToUTF16("file"), 0, {}},
95 {ASCIIToUTF16("abouz"), 0, {}}, 79 {ASCIIToUTF16("abouz"), 0, {}},
96 {ASCIIToUTF16("aboutt"), 0, {}}, 80 {ASCIIToUTF16("aboutt"), 0, {}},
97 {ASCIIToUTF16("aboutt:"), 0, {}}, 81 {ASCIIToUTF16("aboutt:"), 0, {}},
98 {ASCIIToUTF16("chroma"), 0, {}}, 82 {ASCIIToUTF16("chroma"), 0, {}},
99 {ASCIIToUTF16("chromee"), 0, {}}, 83 {ASCIIToUTF16("chromee"), 0, {}},
100 {ASCIIToUTF16("chromee:"), 0, {}}, 84 {ASCIIToUTF16("chromee:"), 0, {}},
(...skipping 10 matching lines...) Expand all
111 // Typing a portion of chrome:// should give the default urls. 95 // Typing a portion of chrome:// should give the default urls.
112 {kChrome.substr(0, 1), 3, {kURL1, kURL2, kURL3}}, 96 {kChrome.substr(0, 1), 3, {kURL1, kURL2, kURL3}},
113 {ASCIIToUTF16("C"), 3, {kURL1, kURL2, kURL3}}, 97 {ASCIIToUTF16("C"), 3, {kURL1, kURL2, kURL3}},
114 {kChrome, 3, {kURL1, kURL2, kURL3}}, 98 {kChrome, 3, {kURL1, kURL2, kURL3}},
115 {kChrome + kSeparator1, 3, {kURL1, kURL2, kURL3}}, 99 {kChrome + kSeparator1, 3, {kURL1, kURL2, kURL3}},
116 {kChrome + kSeparator2, 3, {kURL1, kURL2, kURL3}}, 100 {kChrome + kSeparator2, 3, {kURL1, kURL2, kURL3}},
117 {kChrome + kSeparator3, 3, {kURL1, kURL2, kURL3}}, 101 {kChrome + kSeparator3, 3, {kURL1, kURL2, kURL3}},
118 {ASCIIToUTF16("ChRoMe://"), 3, {kURL1, kURL2, kURL3}}, 102 {ASCIIToUTF16("ChRoMe://"), 3, {kURL1, kURL2, kURL3}},
119 }; 103 };
120 104
121 RunTest<GURL>(typing_scheme_cases, arraysize(typing_scheme_cases), 105 RunTest(typing_scheme_cases, arraysize(typing_scheme_cases));
122 &AutocompleteMatch::destination_url);
123 } 106 }
124 #else // Android uses a subset of the URLs 107 #else // Android uses a subset of the URLs
125 TEST_F(BuiltinProviderTest, TypingScheme) { 108 TEST_F(BuiltinProviderTest, TypingScheme) {
126 const base::string16 kAbout = ASCIIToUTF16(content::kAboutScheme); 109 const base::string16 kAbout = ASCIIToUTF16(content::kAboutScheme);
127 const base::string16 kChrome = ASCIIToUTF16(content::kChromeUIScheme); 110 const base::string16 kChrome = ASCIIToUTF16(content::kChromeUIScheme);
128 const base::string16 kSeparator1 = ASCIIToUTF16(":"); 111 const base::string16 kSeparator1 = ASCIIToUTF16(":");
129 const base::string16 kSeparator2 = ASCIIToUTF16(":/"); 112 const base::string16 kSeparator2 = ASCIIToUTF16(":/");
130 const base::string16 kSeparator3 = 113 const base::string16 kSeparator3 =
131 ASCIIToUTF16(content::kStandardSchemeSeparator); 114 ASCIIToUTF16(content::kStandardSchemeSeparator);
132 115
133 // These default URLs should correspond with those in BuiltinProvider::Start. 116 // These default URLs should correspond with those in BuiltinProvider::Start.
134 const GURL kURL1 = GURL(chrome::kChromeUIChromeURLsURL); 117 const GURL kURL1 = GURL(chrome::kChromeUIChromeURLsURL);
135 const GURL kURL2 = GURL(chrome::kChromeUIVersionURL); 118 const GURL kURL2 = GURL(chrome::kChromeUIVersionURL);
136 119
137 test_data<GURL> typing_scheme_cases[] = { 120 TestData typing_scheme_cases[] = {
138 // Typing an unrelated scheme should give nothing. 121 // Typing an unrelated scheme should give nothing.
139 {ASCIIToUTF16("h"), 0, {}}, 122 {ASCIIToUTF16("h"), 0, {}},
140 {ASCIIToUTF16("http"), 0, {}}, 123 {ASCIIToUTF16("http"), 0, {}},
141 {ASCIIToUTF16("file"), 0, {}}, 124 {ASCIIToUTF16("file"), 0, {}},
142 {ASCIIToUTF16("abouz"), 0, {}}, 125 {ASCIIToUTF16("abouz"), 0, {}},
143 {ASCIIToUTF16("aboutt"), 0, {}}, 126 {ASCIIToUTF16("aboutt"), 0, {}},
144 {ASCIIToUTF16("aboutt:"), 0, {}}, 127 {ASCIIToUTF16("aboutt:"), 0, {}},
145 {ASCIIToUTF16("chroma"), 0, {}}, 128 {ASCIIToUTF16("chroma"), 0, {}},
146 {ASCIIToUTF16("chromee"), 0, {}}, 129 {ASCIIToUTF16("chromee"), 0, {}},
147 {ASCIIToUTF16("chromee:"), 0, {}}, 130 {ASCIIToUTF16("chromee:"), 0, {}},
(...skipping 10 matching lines...) Expand all
158 // Typing a portion of chrome:// should give the default urls. 141 // Typing a portion of chrome:// should give the default urls.
159 {kChrome.substr(0, 1), 2, {kURL1, kURL2}}, 142 {kChrome.substr(0, 1), 2, {kURL1, kURL2}},
160 {ASCIIToUTF16("C"), 2, {kURL1, kURL2}}, 143 {ASCIIToUTF16("C"), 2, {kURL1, kURL2}},
161 {kChrome, 2, {kURL1, kURL2}}, 144 {kChrome, 2, {kURL1, kURL2}},
162 {kChrome + kSeparator1, 2, {kURL1, kURL2}}, 145 {kChrome + kSeparator1, 2, {kURL1, kURL2}},
163 {kChrome + kSeparator2, 2, {kURL1, kURL2}}, 146 {kChrome + kSeparator2, 2, {kURL1, kURL2}},
164 {kChrome + kSeparator3, 2, {kURL1, kURL2}}, 147 {kChrome + kSeparator3, 2, {kURL1, kURL2}},
165 {ASCIIToUTF16("ChRoMe://"), 2, {kURL1, kURL2}}, 148 {ASCIIToUTF16("ChRoMe://"), 2, {kURL1, kURL2}},
166 }; 149 };
167 150
168 RunTest<GURL>(typing_scheme_cases, arraysize(typing_scheme_cases), 151 RunTest(typing_scheme_cases, arraysize(typing_scheme_cases));
169 &AutocompleteMatch::destination_url);
170 } 152 }
171 #endif 153 #endif
172 154
173 TEST_F(BuiltinProviderTest, NonChromeURLs) { 155 TEST_F(BuiltinProviderTest, NonChromeURLs) {
174 test_data<GURL> non_chrome_url_cases[] = { 156 TestData non_chrome_url_cases[] = {
175 // Typing an unrelated scheme should give nothing. 157 // Typing an unrelated scheme should give nothing.
176 {ASCIIToUTF16("g@rb@g3"), 0, {}}, 158 {ASCIIToUTF16("g@rb@g3"), 0, {}},
177 {ASCIIToUTF16("www.google.com"), 0, {}}, 159 {ASCIIToUTF16("www.google.com"), 0, {}},
178 {ASCIIToUTF16("http:www.google.com"), 0, {}}, 160 {ASCIIToUTF16("http:www.google.com"), 0, {}},
179 {ASCIIToUTF16("http://www.google.com"), 0, {}}, 161 {ASCIIToUTF16("http://www.google.com"), 0, {}},
180 {ASCIIToUTF16("file:filename"), 0, {}}, 162 {ASCIIToUTF16("file:filename"), 0, {}},
181 {ASCIIToUTF16("scheme:"), 0, {}}, 163 {ASCIIToUTF16("scheme:"), 0, {}},
182 {ASCIIToUTF16("scheme://"), 0, {}}, 164 {ASCIIToUTF16("scheme://"), 0, {}},
183 {ASCIIToUTF16("scheme://host"), 0, {}}, 165 {ASCIIToUTF16("scheme://host"), 0, {}},
184 {ASCIIToUTF16("scheme:host/path?query#ref"), 0, {}}, 166 {ASCIIToUTF16("scheme:host/path?query#ref"), 0, {}},
185 {ASCIIToUTF16("scheme://host/path?query#ref"), 0, {}}, 167 {ASCIIToUTF16("scheme://host/path?query#ref"), 0, {}},
186 }; 168 };
187 169
188 RunTest<GURL>(non_chrome_url_cases, arraysize(non_chrome_url_cases), 170 RunTest(non_chrome_url_cases, arraysize(non_chrome_url_cases));
189 &AutocompleteMatch::destination_url);
190 } 171 }
191 172
192 TEST_F(BuiltinProviderTest, ChromeURLs) { 173 TEST_F(BuiltinProviderTest, ChromeURLs) {
193 const base::string16 kAbout = ASCIIToUTF16(content::kAboutScheme); 174 const base::string16 kAbout = ASCIIToUTF16(content::kAboutScheme);
194 const base::string16 kChrome = ASCIIToUTF16(content::kChromeUIScheme); 175 const base::string16 kChrome = ASCIIToUTF16(content::kChromeUIScheme);
195 const base::string16 kSeparator1 = ASCIIToUTF16(":"); 176 const base::string16 kSeparator1 = ASCIIToUTF16(":");
196 const base::string16 kSeparator2 = ASCIIToUTF16(":/"); 177 const base::string16 kSeparator2 = ASCIIToUTF16(":/");
197 const base::string16 kSeparator3 = 178 const base::string16 kSeparator3 =
198 ASCIIToUTF16(content::kStandardSchemeSeparator); 179 ASCIIToUTF16(content::kStandardSchemeSeparator);
199 180
200 // This makes assumptions about the chrome URLs listed by the BuiltinProvider. 181 // This makes assumptions about the chrome URLs listed by the BuiltinProvider.
201 // Currently they are derived from chrome::kChromeHostURLs[]. 182 // Currently they are derived from chrome::kChromeHostURLs[].
202 const base::string16 kHostM1 = 183 const base::string16 kHostM1 =
203 ASCIIToUTF16(content::kChromeUIMediaInternalsHost); 184 ASCIIToUTF16(content::kChromeUIMediaInternalsHost);
204 const base::string16 kHostM2 = 185 const base::string16 kHostM2 =
205 ASCIIToUTF16(chrome::kChromeUIMemoryHost); 186 ASCIIToUTF16(chrome::kChromeUIMemoryHost);
206 const base::string16 kHostM3 = 187 const base::string16 kHostM3 =
207 ASCIIToUTF16(chrome::kChromeUIMemoryInternalsHost); 188 ASCIIToUTF16(chrome::kChromeUIMemoryInternalsHost);
208 const GURL kURLM1 = GURL(kChrome + kSeparator3 + kHostM1); 189 const GURL kURLM1 = GURL(kChrome + kSeparator3 + kHostM1);
209 const GURL kURLM2 = GURL(kChrome + kSeparator3 + kHostM2); 190 const GURL kURLM2 = GURL(kChrome + kSeparator3 + kHostM2);
210 const GURL kURLM3 = GURL(kChrome + kSeparator3 + kHostM3); 191 const GURL kURLM3 = GURL(kChrome + kSeparator3 + kHostM3);
211 192
212 test_data<GURL> chrome_url_cases[] = { 193 TestData chrome_url_cases[] = {
213 // Typing an about URL with an unknown host should give nothing. 194 // Typing an about URL with an unknown host should give nothing.
214 {kAbout + kSeparator1 + ASCIIToUTF16("host"), 0, {}}, 195 {kAbout + kSeparator1 + ASCIIToUTF16("host"), 0, {}},
215 {kAbout + kSeparator2 + ASCIIToUTF16("host"), 0, {}}, 196 {kAbout + kSeparator2 + ASCIIToUTF16("host"), 0, {}},
216 {kAbout + kSeparator3 + ASCIIToUTF16("host"), 0, {}}, 197 {kAbout + kSeparator3 + ASCIIToUTF16("host"), 0, {}},
217 198
218 // Typing a chrome URL with an unknown host should give nothing. 199 // Typing a chrome URL with an unknown host should give nothing.
219 {kChrome + kSeparator1 + ASCIIToUTF16("host"), 0, {}}, 200 {kChrome + kSeparator1 + ASCIIToUTF16("host"), 0, {}},
220 {kChrome + kSeparator2 + ASCIIToUTF16("host"), 0, {}}, 201 {kChrome + kSeparator2 + ASCIIToUTF16("host"), 0, {}},
221 {kChrome + kSeparator3 + ASCIIToUTF16("host"), 0, {}}, 202 {kChrome + kSeparator3 + ASCIIToUTF16("host"), 0, {}},
222 203
223 // Typing an about URL should provide matching URLs. 204 // Typing an about URL should provide matching URLs.
224 {kAbout + kSeparator1 + kHostM1.substr(0, 1), 3, {kURLM1, kURLM2, kURLM3}}, 205 {kAbout + kSeparator1 + kHostM1.substr(0, 1), 3, {kURLM1, kURLM2, kURLM3}},
225 {kAbout + kSeparator2 + kHostM1.substr(0, 2), 3, {kURLM1, kURLM2, kURLM3}}, 206 {kAbout + kSeparator2 + kHostM1.substr(0, 2), 3, {kURLM1, kURLM2, kURLM3}},
226 {kAbout + kSeparator3 + kHostM1.substr(0, 3), 1, {kURLM1}}, 207 {kAbout + kSeparator3 + kHostM1.substr(0, 3), 1, {kURLM1}},
227 {kAbout + kSeparator3 + kHostM2.substr(0, 3), 2, {kURLM2, kURLM3}}, 208 {kAbout + kSeparator3 + kHostM2.substr(0, 3), 2, {kURLM2, kURLM3}},
228 {kAbout + kSeparator3 + kHostM1, 1, {kURLM1}}, 209 {kAbout + kSeparator3 + kHostM1, 1, {kURLM1}},
229 {kAbout + kSeparator2 + kHostM2, 2, {kURLM2, kURLM3}}, 210 {kAbout + kSeparator2 + kHostM2, 2, {kURLM2, kURLM3}},
230 {kAbout + kSeparator2 + kHostM3, 1, {kURLM3}}, 211 {kAbout + kSeparator2 + kHostM3, 1, {kURLM3}},
231 212
232 // Typing a chrome URL should provide matching URLs. 213 // Typing a chrome URL should provide matching URLs.
233 {kChrome + kSeparator1 + kHostM1.substr(0, 1), 3, {kURLM1, kURLM2, kURLM3}}, 214 {kChrome + kSeparator1 + kHostM1.substr(0, 1), 3, {kURLM1, kURLM2, kURLM3}},
234 {kChrome + kSeparator2 + kHostM1.substr(0, 2), 3, {kURLM1, kURLM2, kURLM3}}, 215 {kChrome + kSeparator2 + kHostM1.substr(0, 2), 3, {kURLM1, kURLM2, kURLM3}},
235 {kChrome + kSeparator3 + kHostM1.substr(0, 3), 1, {kURLM1}}, 216 {kChrome + kSeparator3 + kHostM1.substr(0, 3), 1, {kURLM1}},
236 {kChrome + kSeparator3 + kHostM2.substr(0, 3), 2, {kURLM2, kURLM3}}, 217 {kChrome + kSeparator3 + kHostM2.substr(0, 3), 2, {kURLM2, kURLM3}},
237 {kChrome + kSeparator3 + kHostM1, 1, {kURLM1}}, 218 {kChrome + kSeparator3 + kHostM1, 1, {kURLM1}},
238 {kChrome + kSeparator2 + kHostM2, 2, {kURLM2, kURLM3}}, 219 {kChrome + kSeparator2 + kHostM2, 2, {kURLM2, kURLM3}},
239 {kChrome + kSeparator2 + kHostM3, 1, {kURLM3}}, 220 {kChrome + kSeparator2 + kHostM3, 1, {kURLM3}},
240 }; 221 };
241 222
242 RunTest<GURL>(chrome_url_cases, arraysize(chrome_url_cases), 223 RunTest(chrome_url_cases, arraysize(chrome_url_cases));
243 &AutocompleteMatch::destination_url);
244 } 224 }
245 225
226 TEST_F(BuiltinProviderTest, AboutBlank) {
227 const base::string16 kAbout = ASCIIToUTF16(content::kAboutScheme);
228 const base::string16 kChrome = ASCIIToUTF16(content::kChromeUIScheme);
229 const base::string16 kAboutBlank = ASCIIToUTF16(content::kAboutBlankURL);
230 const base::string16 kBlank = ASCIIToUTF16("blank");
231 const base::string16 kSeparator1 =
232 ASCIIToUTF16(content::kStandardSchemeSeparator);
233 const base::string16 kSeparator2 = ASCIIToUTF16(":///");
234 const base::string16 kSeparator3 = ASCIIToUTF16(";///");
235
236 const base::string16 kHostB1 = ASCIIToUTF16(chrome::kChromeUIBookmarksHost);
237 const base::string16 kHostB2 =
238 ASCIIToUTF16(content::kChromeUIBlobInternalsHost);
239 const GURL kURLB1 = GURL(kChrome + kSeparator1 + kHostB1);
240 const GURL kURLB2 = GURL(kChrome + kSeparator1 + kHostB2);
Mark P 2014/05/29 23:48:05 why don't you swap b1 and b2 so you don't have eve
msw 2014/05/30 00:29:49 Done.
241 const GURL kURLBlank = GURL(kAboutBlank);
242
243 TestData about_blank_cases[] = {
244 // Another provider suggests url-what-you-typed matches for about:blank.
245 {kAboutBlank, 0, {}},
Mark P 2014/05/29 23:48:05 There's nothing wrong with BuiltinProvider suggest
msw 2014/05/30 00:29:49 Agreed, I removed this test case and adjusted the
246
247 // Typing an about:blank prefix should yield about:blank, among other URLs.
248 {kAboutBlank.substr(0, 7), 3, {kURLBlank, kURLB2, kURLB1}},
249 {kAboutBlank.substr(0, 8), 2, {kURLBlank, kURLB2}},
250 {kAboutBlank.substr(0, 9), 1, {kURLBlank}},
251
252 // Using any separator that's supported by fixup should yield about:blank.
253 {kAbout + kSeparator2.substr(0, 1) + kBlank, 0, {}},
254 {kAbout + kSeparator2.substr(0, 2) + kBlank, 1, {kURLBlank}},
255 {kAbout + kSeparator2.substr(0, 3) + kBlank, 1, {kURLBlank}},
256 {kAbout + kSeparator2 + kBlank, 1, {kURLBlank}},
257 {kAbout + kSeparator3.substr(0, 1) + kBlank, 0, {}},
258 {kAbout + kSeparator3.substr(0, 2) + kBlank, 1, {kURLBlank}},
259 {kAbout + kSeparator3.substr(0, 3) + kBlank, 1, {kURLBlank}},
260 {kAbout + kSeparator3 + kBlank, 1, {kURLBlank}},
261
262 // Using the chrome scheme should not yield about:blank.
263 {kChrome + kSeparator1.substr(0, 1) + kBlank, 0, {}},
264 {kChrome + kSeparator1.substr(0, 2) + kBlank, 0, {}},
265 {kChrome + kSeparator1.substr(0, 3) + kBlank, 0, {}},
266 {kChrome + kSeparator1 + kBlank, 0, {}},
267
268 // Adding trailing text should not yield about:blank.
269 {kAboutBlank + ASCIIToUTF16("/"), 0, {}},
270 {kAboutBlank + ASCIIToUTF16("/p"), 0, {}},
271 {kAboutBlank + ASCIIToUTF16("x"), 0, {}},
272 {kAboutBlank + ASCIIToUTF16("?q"), 0, {}},
273 {kAboutBlank + ASCIIToUTF16("#r"), 0, {}},
274
275 // Interrupting "blank" with conflicting text should not yield about:blank.
276 {kAboutBlank.substr(0, 9) + ASCIIToUTF16("/"), 0, {}},
277 {kAboutBlank.substr(0, 9) + ASCIIToUTF16("/p"), 0, {}},
278 {kAboutBlank.substr(0, 9) + ASCIIToUTF16("x"), 0, {}},
279 {kAboutBlank.substr(0, 9) + ASCIIToUTF16("?q"), 0, {}},
280 {kAboutBlank.substr(0, 9) + ASCIIToUTF16("#r"), 0, {}},
281 };
282
283 RunTest(about_blank_cases, arraysize(about_blank_cases));
284 }
285
286
246 #if !defined(OS_ANDROID) 287 #if !defined(OS_ANDROID)
247 // Disabled on Android where we use native UI instead of chrome://settings. 288 // Disabled on Android where we use native UI instead of chrome://settings.
248 TEST_F(BuiltinProviderTest, ChromeSettingsSubpages) { 289 TEST_F(BuiltinProviderTest, ChromeSettingsSubpages) {
249 // This makes assumptions about the chrome URLs listed by the BuiltinProvider. 290 // This makes assumptions about the chrome URLs listed by the BuiltinProvider.
250 // Currently they are derived from chrome::kChromeHostURLs[]. 291 // Currently they are derived from chrome::kChromeHostURLs[].
251 const base::string16 kSettings = ASCIIToUTF16(chrome::kChromeUISettingsURL); 292 const base::string16 kSettings = ASCIIToUTF16(chrome::kChromeUISettingsURL);
252 const base::string16 kDefaultPage1 = ASCIIToUTF16(chrome::kAutofillSubPage); 293 const base::string16 kDefaultPage1 = ASCIIToUTF16(chrome::kAutofillSubPage);
253 const base::string16 kDefaultPage2 = 294 const base::string16 kDefaultPage2 =
254 ASCIIToUTF16(chrome::kClearBrowserDataSubPage); 295 ASCIIToUTF16(chrome::kClearBrowserDataSubPage);
255 const GURL kDefaultURL1 = GURL(kSettings + kDefaultPage1); 296 const GURL kDefaultURL1 = GURL(kSettings + kDefaultPage1);
256 const GURL kDefaultURL2 = GURL(kSettings + kDefaultPage2); 297 const GURL kDefaultURL2 = GURL(kSettings + kDefaultPage2);
257 const base::string16 kPage1 = ASCIIToUTF16(chrome::kSearchEnginesSubPage); 298 const base::string16 kPage1 = ASCIIToUTF16(chrome::kSearchEnginesSubPage);
258 const base::string16 kPage2 = ASCIIToUTF16(chrome::kSyncSetupSubPage); 299 const base::string16 kPage2 = ASCIIToUTF16(chrome::kSyncSetupSubPage);
259 const GURL kURL1 = GURL(kSettings + kPage1); 300 const GURL kURL1 = GURL(kSettings + kPage1);
260 const GURL kURL2 = GURL(kSettings + kPage2); 301 const GURL kURL2 = GURL(kSettings + kPage2);
261 302
262 test_data<GURL> settings_subpage_cases[] = { 303 TestData settings_subpage_cases[] = {
263 // Typing the settings path should show settings and the first two subpages. 304 // Typing the settings path should show settings and the first two subpages.
264 {kSettings, 3, {GURL(kSettings), kDefaultURL1, kDefaultURL2}}, 305 {kSettings, 3, {GURL(kSettings), kDefaultURL1, kDefaultURL2}},
265 306
266 // Typing a subpage path should return the appropriate results. 307 // Typing a subpage path should return the appropriate results.
267 {kSettings + kPage1.substr(0, 1), 2, {kURL1, kURL2}}, 308 {kSettings + kPage1.substr(0, 1), 2, {kURL1, kURL2}},
268 {kSettings + kPage1.substr(0, 2), 1, {kURL1}}, 309 {kSettings + kPage1.substr(0, 2), 1, {kURL1}},
269 {kSettings + kPage1.substr(0, kPage1.length() - 1), 1, {kURL1}}, 310 {kSettings + kPage1.substr(0, kPage1.length() - 1), 1, {kURL1}},
270 {kSettings + kPage1, 1, {kURL1}}, 311 {kSettings + kPage1, 1, {kURL1}},
271 {kSettings + kPage2, 1, {kURL2}}, 312 {kSettings + kPage2, 1, {kURL2}},
272 }; 313 };
273 314
274 RunTest<GURL>(settings_subpage_cases, arraysize(settings_subpage_cases), 315 RunTest(settings_subpage_cases, arraysize(settings_subpage_cases));
275 &AutocompleteMatch::destination_url);
276 } 316 }
277 #endif 317 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698