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

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: Remove a case that fails on Android. 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.
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(),
41 }; 40 AutocompleteInput::INVALID_SPEC,
42 41 true, false, true, true);
43 void BuiltinProviderTest::SetUp() { 42 provider_->Start(input, false);
44 builtin_provider_ = new BuiltinProvider(NULL, NULL); 43 EXPECT_TRUE(provider_->done());
45 } 44 matches = provider_->matches();
46 45 EXPECT_EQ(cases[i].num_results, matches.size());
47 void BuiltinProviderTest::TearDown() { 46 if (matches.size() == cases[i].num_results) {
48 builtin_provider_ = NULL; 47 for (size_t j = 0; j < cases[i].num_results; ++j) {
49 } 48 EXPECT_EQ(cases[i].output[j], matches[j].destination_url);
50 49 EXPECT_FALSE(matches[j].allowed_to_be_default_match);
51 template<class ResultType> 50 }
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 } 51 }
72 } 52 }
73 } 53 }
74 } 54
55 private:
56 scoped_refptr<BuiltinProvider> provider_;
57
58 DISALLOW_COPY_AND_ASSIGN(BuiltinProviderTest);
59 };
75 60
76 #if !defined(OS_ANDROID) 61 #if !defined(OS_ANDROID)
77 TEST_F(BuiltinProviderTest, TypingScheme) { 62 TEST_F(BuiltinProviderTest, TypingScheme) {
78 const base::string16 kAbout = ASCIIToUTF16(content::kAboutScheme); 63 const base::string16 kAbout = ASCIIToUTF16(content::kAboutScheme);
79 const base::string16 kChrome = ASCIIToUTF16(content::kChromeUIScheme); 64 const base::string16 kChrome = ASCIIToUTF16(content::kChromeUIScheme);
80 const base::string16 kSeparator1 = ASCIIToUTF16(":"); 65 const base::string16 kSeparator1 = ASCIIToUTF16(":");
81 const base::string16 kSeparator2 = ASCIIToUTF16(":/"); 66 const base::string16 kSeparator2 = ASCIIToUTF16(":/");
82 const base::string16 kSeparator3 = 67 const base::string16 kSeparator3 =
83 ASCIIToUTF16(content::kStandardSchemeSeparator); 68 ASCIIToUTF16(content::kStandardSchemeSeparator);
84 69
85 // These default URLs should correspond with those in BuiltinProvider::Start. 70 // These default URLs should correspond with those in BuiltinProvider::Start.
86 const GURL kURL1 = GURL(chrome::kChromeUIChromeURLsURL); 71 const GURL kURL1 = GURL(chrome::kChromeUIChromeURLsURL);
87 const GURL kURL2 = GURL(chrome::kChromeUISettingsURL); 72 const GURL kURL2 = GURL(chrome::kChromeUISettingsURL);
88 const GURL kURL3 = GURL(chrome::kChromeUIVersionURL); 73 const GURL kURL3 = GURL(chrome::kChromeUIVersionURL);
89 74
90 test_data<GURL> typing_scheme_cases[] = { 75 TestData typing_scheme_cases[] = {
91 // Typing an unrelated scheme should give nothing. 76 // Typing an unrelated scheme should give nothing.
92 {ASCIIToUTF16("h"), 0, {}}, 77 {ASCIIToUTF16("h"), 0, {}},
93 {ASCIIToUTF16("http"), 0, {}}, 78 {ASCIIToUTF16("http"), 0, {}},
94 {ASCIIToUTF16("file"), 0, {}}, 79 {ASCIIToUTF16("file"), 0, {}},
95 {ASCIIToUTF16("abouz"), 0, {}}, 80 {ASCIIToUTF16("abouz"), 0, {}},
96 {ASCIIToUTF16("aboutt"), 0, {}}, 81 {ASCIIToUTF16("aboutt"), 0, {}},
97 {ASCIIToUTF16("aboutt:"), 0, {}}, 82 {ASCIIToUTF16("aboutt:"), 0, {}},
98 {ASCIIToUTF16("chroma"), 0, {}}, 83 {ASCIIToUTF16("chroma"), 0, {}},
99 {ASCIIToUTF16("chromee"), 0, {}}, 84 {ASCIIToUTF16("chromee"), 0, {}},
100 {ASCIIToUTF16("chromee:"), 0, {}}, 85 {ASCIIToUTF16("chromee:"), 0, {}},
(...skipping 10 matching lines...) Expand all
111 // Typing a portion of chrome:// should give the default urls. 96 // Typing a portion of chrome:// should give the default urls.
112 {kChrome.substr(0, 1), 3, {kURL1, kURL2, kURL3}}, 97 {kChrome.substr(0, 1), 3, {kURL1, kURL2, kURL3}},
113 {ASCIIToUTF16("C"), 3, {kURL1, kURL2, kURL3}}, 98 {ASCIIToUTF16("C"), 3, {kURL1, kURL2, kURL3}},
114 {kChrome, 3, {kURL1, kURL2, kURL3}}, 99 {kChrome, 3, {kURL1, kURL2, kURL3}},
115 {kChrome + kSeparator1, 3, {kURL1, kURL2, kURL3}}, 100 {kChrome + kSeparator1, 3, {kURL1, kURL2, kURL3}},
116 {kChrome + kSeparator2, 3, {kURL1, kURL2, kURL3}}, 101 {kChrome + kSeparator2, 3, {kURL1, kURL2, kURL3}},
117 {kChrome + kSeparator3, 3, {kURL1, kURL2, kURL3}}, 102 {kChrome + kSeparator3, 3, {kURL1, kURL2, kURL3}},
118 {ASCIIToUTF16("ChRoMe://"), 3, {kURL1, kURL2, kURL3}}, 103 {ASCIIToUTF16("ChRoMe://"), 3, {kURL1, kURL2, kURL3}},
119 }; 104 };
120 105
121 RunTest<GURL>(typing_scheme_cases, arraysize(typing_scheme_cases), 106 RunTest(typing_scheme_cases, arraysize(typing_scheme_cases));
122 &AutocompleteMatch::destination_url);
123 } 107 }
124 #else // Android uses a subset of the URLs 108 #else // Android uses a subset of the URLs
125 TEST_F(BuiltinProviderTest, TypingScheme) { 109 TEST_F(BuiltinProviderTest, TypingScheme) {
126 const base::string16 kAbout = ASCIIToUTF16(content::kAboutScheme); 110 const base::string16 kAbout = ASCIIToUTF16(content::kAboutScheme);
127 const base::string16 kChrome = ASCIIToUTF16(content::kChromeUIScheme); 111 const base::string16 kChrome = ASCIIToUTF16(content::kChromeUIScheme);
128 const base::string16 kSeparator1 = ASCIIToUTF16(":"); 112 const base::string16 kSeparator1 = ASCIIToUTF16(":");
129 const base::string16 kSeparator2 = ASCIIToUTF16(":/"); 113 const base::string16 kSeparator2 = ASCIIToUTF16(":/");
130 const base::string16 kSeparator3 = 114 const base::string16 kSeparator3 =
131 ASCIIToUTF16(content::kStandardSchemeSeparator); 115 ASCIIToUTF16(content::kStandardSchemeSeparator);
132 116
133 // These default URLs should correspond with those in BuiltinProvider::Start. 117 // These default URLs should correspond with those in BuiltinProvider::Start.
134 const GURL kURL1 = GURL(chrome::kChromeUIChromeURLsURL); 118 const GURL kURL1 = GURL(chrome::kChromeUIChromeURLsURL);
135 const GURL kURL2 = GURL(chrome::kChromeUIVersionURL); 119 const GURL kURL2 = GURL(chrome::kChromeUIVersionURL);
136 120
137 test_data<GURL> typing_scheme_cases[] = { 121 TestData typing_scheme_cases[] = {
138 // Typing an unrelated scheme should give nothing. 122 // Typing an unrelated scheme should give nothing.
139 {ASCIIToUTF16("h"), 0, {}}, 123 {ASCIIToUTF16("h"), 0, {}},
140 {ASCIIToUTF16("http"), 0, {}}, 124 {ASCIIToUTF16("http"), 0, {}},
141 {ASCIIToUTF16("file"), 0, {}}, 125 {ASCIIToUTF16("file"), 0, {}},
142 {ASCIIToUTF16("abouz"), 0, {}}, 126 {ASCIIToUTF16("abouz"), 0, {}},
143 {ASCIIToUTF16("aboutt"), 0, {}}, 127 {ASCIIToUTF16("aboutt"), 0, {}},
144 {ASCIIToUTF16("aboutt:"), 0, {}}, 128 {ASCIIToUTF16("aboutt:"), 0, {}},
145 {ASCIIToUTF16("chroma"), 0, {}}, 129 {ASCIIToUTF16("chroma"), 0, {}},
146 {ASCIIToUTF16("chromee"), 0, {}}, 130 {ASCIIToUTF16("chromee"), 0, {}},
147 {ASCIIToUTF16("chromee:"), 0, {}}, 131 {ASCIIToUTF16("chromee:"), 0, {}},
(...skipping 10 matching lines...) Expand all
158 // Typing a portion of chrome:// should give the default urls. 142 // Typing a portion of chrome:// should give the default urls.
159 {kChrome.substr(0, 1), 2, {kURL1, kURL2}}, 143 {kChrome.substr(0, 1), 2, {kURL1, kURL2}},
160 {ASCIIToUTF16("C"), 2, {kURL1, kURL2}}, 144 {ASCIIToUTF16("C"), 2, {kURL1, kURL2}},
161 {kChrome, 2, {kURL1, kURL2}}, 145 {kChrome, 2, {kURL1, kURL2}},
162 {kChrome + kSeparator1, 2, {kURL1, kURL2}}, 146 {kChrome + kSeparator1, 2, {kURL1, kURL2}},
163 {kChrome + kSeparator2, 2, {kURL1, kURL2}}, 147 {kChrome + kSeparator2, 2, {kURL1, kURL2}},
164 {kChrome + kSeparator3, 2, {kURL1, kURL2}}, 148 {kChrome + kSeparator3, 2, {kURL1, kURL2}},
165 {ASCIIToUTF16("ChRoMe://"), 2, {kURL1, kURL2}}, 149 {ASCIIToUTF16("ChRoMe://"), 2, {kURL1, kURL2}},
166 }; 150 };
167 151
168 RunTest<GURL>(typing_scheme_cases, arraysize(typing_scheme_cases), 152 RunTest(typing_scheme_cases, arraysize(typing_scheme_cases));
169 &AutocompleteMatch::destination_url);
170 } 153 }
171 #endif 154 #endif
172 155
173 TEST_F(BuiltinProviderTest, NonChromeURLs) { 156 TEST_F(BuiltinProviderTest, NonChromeURLs) {
174 test_data<GURL> non_chrome_url_cases[] = { 157 TestData non_chrome_url_cases[] = {
175 // Typing an unrelated scheme should give nothing. 158 // Typing an unrelated scheme should give nothing.
176 {ASCIIToUTF16("g@rb@g3"), 0, {}}, 159 {ASCIIToUTF16("g@rb@g3"), 0, {}},
177 {ASCIIToUTF16("www.google.com"), 0, {}}, 160 {ASCIIToUTF16("www.google.com"), 0, {}},
178 {ASCIIToUTF16("http:www.google.com"), 0, {}}, 161 {ASCIIToUTF16("http:www.google.com"), 0, {}},
179 {ASCIIToUTF16("http://www.google.com"), 0, {}}, 162 {ASCIIToUTF16("http://www.google.com"), 0, {}},
180 {ASCIIToUTF16("file:filename"), 0, {}}, 163 {ASCIIToUTF16("file:filename"), 0, {}},
181 {ASCIIToUTF16("scheme:"), 0, {}}, 164 {ASCIIToUTF16("scheme:"), 0, {}},
182 {ASCIIToUTF16("scheme://"), 0, {}}, 165 {ASCIIToUTF16("scheme://"), 0, {}},
183 {ASCIIToUTF16("scheme://host"), 0, {}}, 166 {ASCIIToUTF16("scheme://host"), 0, {}},
184 {ASCIIToUTF16("scheme:host/path?query#ref"), 0, {}}, 167 {ASCIIToUTF16("scheme:host/path?query#ref"), 0, {}},
185 {ASCIIToUTF16("scheme://host/path?query#ref"), 0, {}}, 168 {ASCIIToUTF16("scheme://host/path?query#ref"), 0, {}},
186 }; 169 };
187 170
188 RunTest<GURL>(non_chrome_url_cases, arraysize(non_chrome_url_cases), 171 RunTest(non_chrome_url_cases, arraysize(non_chrome_url_cases));
189 &AutocompleteMatch::destination_url);
190 } 172 }
191 173
192 TEST_F(BuiltinProviderTest, ChromeURLs) { 174 TEST_F(BuiltinProviderTest, ChromeURLs) {
193 const base::string16 kAbout = ASCIIToUTF16(content::kAboutScheme); 175 const base::string16 kAbout = ASCIIToUTF16(content::kAboutScheme);
194 const base::string16 kChrome = ASCIIToUTF16(content::kChromeUIScheme); 176 const base::string16 kChrome = ASCIIToUTF16(content::kChromeUIScheme);
195 const base::string16 kSeparator1 = ASCIIToUTF16(":"); 177 const base::string16 kSeparator1 = ASCIIToUTF16(":");
196 const base::string16 kSeparator2 = ASCIIToUTF16(":/"); 178 const base::string16 kSeparator2 = ASCIIToUTF16(":/");
197 const base::string16 kSeparator3 = 179 const base::string16 kSeparator3 =
198 ASCIIToUTF16(content::kStandardSchemeSeparator); 180 ASCIIToUTF16(content::kStandardSchemeSeparator);
199 181
200 // This makes assumptions about the chrome URLs listed by the BuiltinProvider. 182 // This makes assumptions about the chrome URLs listed by the BuiltinProvider.
201 // Currently they are derived from chrome::kChromeHostURLs[]. 183 // Currently they are derived from chrome::kChromeHostURLs[].
202 const base::string16 kHostM1 = 184 const base::string16 kHostM1 =
203 ASCIIToUTF16(content::kChromeUIMediaInternalsHost); 185 ASCIIToUTF16(content::kChromeUIMediaInternalsHost);
204 const base::string16 kHostM2 = 186 const base::string16 kHostM2 =
205 ASCIIToUTF16(chrome::kChromeUIMemoryHost); 187 ASCIIToUTF16(chrome::kChromeUIMemoryHost);
206 const base::string16 kHostM3 = 188 const base::string16 kHostM3 =
207 ASCIIToUTF16(chrome::kChromeUIMemoryInternalsHost); 189 ASCIIToUTF16(chrome::kChromeUIMemoryInternalsHost);
208 const GURL kURLM1 = GURL(kChrome + kSeparator3 + kHostM1); 190 const GURL kURLM1 = GURL(kChrome + kSeparator3 + kHostM1);
209 const GURL kURLM2 = GURL(kChrome + kSeparator3 + kHostM2); 191 const GURL kURLM2 = GURL(kChrome + kSeparator3 + kHostM2);
210 const GURL kURLM3 = GURL(kChrome + kSeparator3 + kHostM3); 192 const GURL kURLM3 = GURL(kChrome + kSeparator3 + kHostM3);
211 193
212 test_data<GURL> chrome_url_cases[] = { 194 TestData chrome_url_cases[] = {
213 // Typing an about URL with an unknown host should give nothing. 195 // Typing an about URL with an unknown host should give nothing.
214 {kAbout + kSeparator1 + ASCIIToUTF16("host"), 0, {}}, 196 {kAbout + kSeparator1 + ASCIIToUTF16("host"), 0, {}},
215 {kAbout + kSeparator2 + ASCIIToUTF16("host"), 0, {}}, 197 {kAbout + kSeparator2 + ASCIIToUTF16("host"), 0, {}},
216 {kAbout + kSeparator3 + ASCIIToUTF16("host"), 0, {}}, 198 {kAbout + kSeparator3 + ASCIIToUTF16("host"), 0, {}},
217 199
218 // Typing a chrome URL with an unknown host should give nothing. 200 // Typing a chrome URL with an unknown host should give nothing.
219 {kChrome + kSeparator1 + ASCIIToUTF16("host"), 0, {}}, 201 {kChrome + kSeparator1 + ASCIIToUTF16("host"), 0, {}},
220 {kChrome + kSeparator2 + ASCIIToUTF16("host"), 0, {}}, 202 {kChrome + kSeparator2 + ASCIIToUTF16("host"), 0, {}},
221 {kChrome + kSeparator3 + ASCIIToUTF16("host"), 0, {}}, 203 {kChrome + kSeparator3 + ASCIIToUTF16("host"), 0, {}},
222 204
223 // Typing an about URL should provide matching URLs. 205 // Typing an about URL should provide matching URLs.
224 {kAbout + kSeparator1 + kHostM1.substr(0, 1), 3, {kURLM1, kURLM2, kURLM3}}, 206 {kAbout + kSeparator1 + kHostM1.substr(0, 1), 3, {kURLM1, kURLM2, kURLM3}},
225 {kAbout + kSeparator2 + kHostM1.substr(0, 2), 3, {kURLM1, kURLM2, kURLM3}}, 207 {kAbout + kSeparator2 + kHostM1.substr(0, 2), 3, {kURLM1, kURLM2, kURLM3}},
226 {kAbout + kSeparator3 + kHostM1.substr(0, 3), 1, {kURLM1}}, 208 {kAbout + kSeparator3 + kHostM1.substr(0, 3), 1, {kURLM1}},
227 {kAbout + kSeparator3 + kHostM2.substr(0, 3), 2, {kURLM2, kURLM3}}, 209 {kAbout + kSeparator3 + kHostM2.substr(0, 3), 2, {kURLM2, kURLM3}},
228 {kAbout + kSeparator3 + kHostM1, 1, {kURLM1}}, 210 {kAbout + kSeparator3 + kHostM1, 1, {kURLM1}},
229 {kAbout + kSeparator2 + kHostM2, 2, {kURLM2, kURLM3}}, 211 {kAbout + kSeparator2 + kHostM2, 2, {kURLM2, kURLM3}},
230 {kAbout + kSeparator2 + kHostM3, 1, {kURLM3}}, 212 {kAbout + kSeparator2 + kHostM3, 1, {kURLM3}},
231 213
232 // Typing a chrome URL should provide matching URLs. 214 // Typing a chrome URL should provide matching URLs.
233 {kChrome + kSeparator1 + kHostM1.substr(0, 1), 3, {kURLM1, kURLM2, kURLM3}}, 215 {kChrome + kSeparator1 + kHostM1.substr(0, 1), 3, {kURLM1, kURLM2, kURLM3}},
234 {kChrome + kSeparator2 + kHostM1.substr(0, 2), 3, {kURLM1, kURLM2, kURLM3}}, 216 {kChrome + kSeparator2 + kHostM1.substr(0, 2), 3, {kURLM1, kURLM2, kURLM3}},
235 {kChrome + kSeparator3 + kHostM1.substr(0, 3), 1, {kURLM1}}, 217 {kChrome + kSeparator3 + kHostM1.substr(0, 3), 1, {kURLM1}},
236 {kChrome + kSeparator3 + kHostM2.substr(0, 3), 2, {kURLM2, kURLM3}}, 218 {kChrome + kSeparator3 + kHostM2.substr(0, 3), 2, {kURLM2, kURLM3}},
237 {kChrome + kSeparator3 + kHostM1, 1, {kURLM1}}, 219 {kChrome + kSeparator3 + kHostM1, 1, {kURLM1}},
238 {kChrome + kSeparator2 + kHostM2, 2, {kURLM2, kURLM3}}, 220 {kChrome + kSeparator2 + kHostM2, 2, {kURLM2, kURLM3}},
239 {kChrome + kSeparator2 + kHostM3, 1, {kURLM3}}, 221 {kChrome + kSeparator2 + kHostM3, 1, {kURLM3}},
240 }; 222 };
241 223
242 RunTest<GURL>(chrome_url_cases, arraysize(chrome_url_cases), 224 RunTest(chrome_url_cases, arraysize(chrome_url_cases));
243 &AutocompleteMatch::destination_url); 225 }
226
227 TEST_F(BuiltinProviderTest, AboutBlank) {
228 const base::string16 kAbout = ASCIIToUTF16(content::kAboutScheme);
229 const base::string16 kChrome = ASCIIToUTF16(content::kChromeUIScheme);
230 const base::string16 kAboutBlank = ASCIIToUTF16(content::kAboutBlankURL);
231 const base::string16 kBlank = ASCIIToUTF16("blank");
232 const base::string16 kSeparator1 =
233 ASCIIToUTF16(content::kStandardSchemeSeparator);
234 const base::string16 kSeparator2 = ASCIIToUTF16(":///");
235 const base::string16 kSeparator3 = ASCIIToUTF16(";///");
236
237 const GURL kURLBlob = GURL(kChrome + kSeparator1 +
238 ASCIIToUTF16(content::kChromeUIBlobInternalsHost));
239 const GURL kURLBlank = GURL(kAboutBlank);
240
241 TestData about_blank_cases[] = {
242 // Typing an about:blank prefix should yield about:blank, among other URLs.
243 {kAboutBlank.substr(0, 8), 2, {kURLBlank, kURLBlob}},
244 {kAboutBlank.substr(0, 9), 1, {kURLBlank}},
245
246 // Using any separator that is supported by fixup should yield about:blank.
247 // For now, BuiltinProvider does not suggest url-what-you-typed matches for
248 // for about:blank; check "about:blan" and "about;blan" substrings instead.
249 {kAbout + kSeparator2.substr(0, 1) + kBlank.substr(0, 4), 1, {kURLBlank}},
250 {kAbout + kSeparator2.substr(0, 2) + kBlank, 1, {kURLBlank}},
251 {kAbout + kSeparator2.substr(0, 3) + kBlank, 1, {kURLBlank}},
252 {kAbout + kSeparator2 + kBlank, 1, {kURLBlank}},
253 {kAbout + kSeparator3.substr(0, 1) + kBlank.substr(0, 4), 1, {kURLBlank}},
254 {kAbout + kSeparator3.substr(0, 2) + kBlank, 1, {kURLBlank}},
255 {kAbout + kSeparator3.substr(0, 3) + kBlank, 1, {kURLBlank}},
256 {kAbout + kSeparator3 + kBlank, 1, {kURLBlank}},
257
258 // Using the chrome scheme should not yield about:blank.
259 {kChrome + kSeparator1.substr(0, 1) + kBlank, 0, {}},
260 {kChrome + kSeparator1.substr(0, 2) + kBlank, 0, {}},
261 {kChrome + kSeparator1.substr(0, 3) + kBlank, 0, {}},
262 {kChrome + kSeparator1 + kBlank, 0, {}},
263
264 // Adding trailing text should not yield about:blank.
265 {kAboutBlank + ASCIIToUTF16("/"), 0, {}},
266 {kAboutBlank + ASCIIToUTF16("/p"), 0, {}},
267 {kAboutBlank + ASCIIToUTF16("x"), 0, {}},
268 {kAboutBlank + ASCIIToUTF16("?q"), 0, {}},
269 {kAboutBlank + ASCIIToUTF16("#r"), 0, {}},
270
271 // Interrupting "blank" with conflicting text should not yield about:blank.
272 {kAboutBlank.substr(0, 9) + ASCIIToUTF16("/"), 0, {}},
273 {kAboutBlank.substr(0, 9) + ASCIIToUTF16("/p"), 0, {}},
274 {kAboutBlank.substr(0, 9) + ASCIIToUTF16("x"), 0, {}},
275 {kAboutBlank.substr(0, 9) + ASCIIToUTF16("?q"), 0, {}},
276 {kAboutBlank.substr(0, 9) + ASCIIToUTF16("#r"), 0, {}},
277 };
278
279 RunTest(about_blank_cases, arraysize(about_blank_cases));
244 } 280 }
245 281
246 #if !defined(OS_ANDROID) 282 #if !defined(OS_ANDROID)
247 // Disabled on Android where we use native UI instead of chrome://settings. 283 // Disabled on Android where we use native UI instead of chrome://settings.
248 TEST_F(BuiltinProviderTest, ChromeSettingsSubpages) { 284 TEST_F(BuiltinProviderTest, ChromeSettingsSubpages) {
249 // This makes assumptions about the chrome URLs listed by the BuiltinProvider. 285 // This makes assumptions about the chrome URLs listed by the BuiltinProvider.
250 // Currently they are derived from chrome::kChromeHostURLs[]. 286 // Currently they are derived from chrome::kChromeHostURLs[].
251 const base::string16 kSettings = ASCIIToUTF16(chrome::kChromeUISettingsURL); 287 const base::string16 kSettings = ASCIIToUTF16(chrome::kChromeUISettingsURL);
252 const base::string16 kDefaultPage1 = ASCIIToUTF16(chrome::kAutofillSubPage); 288 const base::string16 kDefaultPage1 = ASCIIToUTF16(chrome::kAutofillSubPage);
253 const base::string16 kDefaultPage2 = 289 const base::string16 kDefaultPage2 =
254 ASCIIToUTF16(chrome::kClearBrowserDataSubPage); 290 ASCIIToUTF16(chrome::kClearBrowserDataSubPage);
255 const GURL kDefaultURL1 = GURL(kSettings + kDefaultPage1); 291 const GURL kDefaultURL1 = GURL(kSettings + kDefaultPage1);
256 const GURL kDefaultURL2 = GURL(kSettings + kDefaultPage2); 292 const GURL kDefaultURL2 = GURL(kSettings + kDefaultPage2);
257 const base::string16 kPage1 = ASCIIToUTF16(chrome::kSearchEnginesSubPage); 293 const base::string16 kPage1 = ASCIIToUTF16(chrome::kSearchEnginesSubPage);
258 const base::string16 kPage2 = ASCIIToUTF16(chrome::kSyncSetupSubPage); 294 const base::string16 kPage2 = ASCIIToUTF16(chrome::kSyncSetupSubPage);
259 const GURL kURL1 = GURL(kSettings + kPage1); 295 const GURL kURL1 = GURL(kSettings + kPage1);
260 const GURL kURL2 = GURL(kSettings + kPage2); 296 const GURL kURL2 = GURL(kSettings + kPage2);
261 297
262 test_data<GURL> settings_subpage_cases[] = { 298 TestData settings_subpage_cases[] = {
263 // Typing the settings path should show settings and the first two subpages. 299 // Typing the settings path should show settings and the first two subpages.
264 {kSettings, 3, {GURL(kSettings), kDefaultURL1, kDefaultURL2}}, 300 {kSettings, 3, {GURL(kSettings), kDefaultURL1, kDefaultURL2}},
265 301
266 // Typing a subpage path should return the appropriate results. 302 // Typing a subpage path should return the appropriate results.
267 {kSettings + kPage1.substr(0, 1), 2, {kURL1, kURL2}}, 303 {kSettings + kPage1.substr(0, 1), 2, {kURL1, kURL2}},
268 {kSettings + kPage1.substr(0, 2), 1, {kURL1}}, 304 {kSettings + kPage1.substr(0, 2), 1, {kURL1}},
269 {kSettings + kPage1.substr(0, kPage1.length() - 1), 1, {kURL1}}, 305 {kSettings + kPage1.substr(0, kPage1.length() - 1), 1, {kURL1}},
270 {kSettings + kPage1, 1, {kURL1}}, 306 {kSettings + kPage1, 1, {kURL1}},
271 {kSettings + kPage2, 1, {kURL2}}, 307 {kSettings + kPage2, 1, {kURL2}},
272 }; 308 };
273 309
274 RunTest<GURL>(settings_subpage_cases, arraysize(settings_subpage_cases), 310 RunTest(settings_subpage_cases, arraysize(settings_subpage_cases));
275 &AutocompleteMatch::destination_url);
276 } 311 }
277 #endif 312 #endif
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/builtin_provider.cc ('k') | chrome/browser/ui/omnibox/omnibox_view_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698