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

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

Issue 7193003: Revert 89298 - Update BuiltinProvider to provide chrome:// URLs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 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 "base/message_loop.h"
6 #include "base/utf_string_conversions.h"
7 #include "chrome/browser/autocomplete/autocomplete_match.h"
8 #include "chrome/browser/autocomplete/builtin_provider.h"
9 #include "chrome/common/url_constants.h"
10 #include "chrome/test/testing_browser_process.h"
11 #include "chrome/test/testing_browser_process_test.h"
12 #include "googleurl/src/gurl.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 class BuiltinProviderTest : public TestingBrowserProcessTest {
16 protected:
17 template<class ResultType>
18 struct test_data {
19 const string16 input;
20 const size_t num_results;
21 const ResultType output[3];
22 };
23
24 BuiltinProviderTest() : builtin_provider_(NULL) { }
25 virtual ~BuiltinProviderTest() { }
26
27 virtual void SetUp();
28 virtual void TearDown();
29
30 template<class ResultType>
31 void RunTest(test_data<ResultType>* builtin_cases,
32 int num_cases,
33 ResultType AutocompleteMatch::* member);
34
35 protected:
36 scoped_refptr<BuiltinProvider> builtin_provider_;
37 };
38
39 void BuiltinProviderTest::SetUp() {
40 builtin_provider_ = new BuiltinProvider(NULL, NULL);
41 }
42
43 void BuiltinProviderTest::TearDown() {
44 builtin_provider_ = NULL;
45 }
46
47 template<class ResultType>
48 void BuiltinProviderTest::RunTest(test_data<ResultType>* builtin_cases,
49 int num_cases,
50 ResultType AutocompleteMatch::* member) {
51 ACMatches matches;
52 for (int i = 0; i < num_cases; ++i) {
53 AutocompleteInput input(builtin_cases[i].input, string16(), true,
54 false, true, AutocompleteInput::ALL_MATCHES);
55 builtin_provider_->Start(input, false);
56 EXPECT_TRUE(builtin_provider_->done());
57 matches = builtin_provider_->matches();
58 EXPECT_EQ(builtin_cases[i].num_results, matches.size()) <<
59 ASCIIToUTF16("Input was: ") << builtin_cases[i].input;
60 if (matches.size() == builtin_cases[i].num_results) {
61 for (size_t j = 0; j < builtin_cases[i].num_results; ++j) {
62 EXPECT_EQ(builtin_cases[i].output[j], matches[j].*member) <<
63 ASCIIToUTF16("Input was: ") << builtin_cases[i].input;
64 }
65 }
66 }
67 }
68
69 TEST_F(BuiltinProviderTest, TypingScheme) {
70 const string16 kAbout = ASCIIToUTF16(chrome::kAboutScheme);
71 const string16 kChrome = ASCIIToUTF16(chrome::kChromeUIScheme);
72 const string16 kSeparator1 = ASCIIToUTF16(":");
73 const string16 kSeparator2 = ASCIIToUTF16(":/");
74 const string16 kSeparator3 = ASCIIToUTF16(chrome::kStandardSchemeSeparator);
75
76 // These default URLs should correspond with those in BuiltinProvider::Start.
77 const GURL kURL1 = GURL(chrome::kChromeUIChromeURLsURL);
78 const GURL kURL2 = GURL(chrome::kChromeUISettingsURL);
79 const GURL kURL3 = GURL(chrome::kChromeUIVersionURL);
80
81 test_data<GURL> typing_scheme_cases[] = {
82 // Typing an unrelated scheme should give nothing.
83 {ASCIIToUTF16("h"), 0, {}},
84 {ASCIIToUTF16("http"), 0, {}},
85 {ASCIIToUTF16("file"), 0, {}},
86 {ASCIIToUTF16("abouz"), 0, {}},
87 {ASCIIToUTF16("aboutt"), 0, {}},
88 {ASCIIToUTF16("aboutt:"), 0, {}},
89 {ASCIIToUTF16("chroma"), 0, {}},
90 {ASCIIToUTF16("chromee"), 0, {}},
91 {ASCIIToUTF16("chromee:"), 0, {}},
92
93 // Typing a portion of about:// should give the default urls.
94 {kAbout.substr(0, 1), 3, {kURL1, kURL2, kURL3}},
95 {ASCIIToUTF16("A"), 3, {kURL1, kURL2, kURL3}},
96 {kAbout, 3, {kURL1, kURL2, kURL3}},
97 {kAbout + kSeparator1, 3, {kURL1, kURL2, kURL3}},
98 {kAbout + kSeparator2, 3, {kURL1, kURL2, kURL3}},
99 {kAbout + kSeparator3, 3, {kURL1, kURL2, kURL3}},
100 {ASCIIToUTF16("aBoUT://"), 3, {kURL1, kURL2, kURL3}},
101
102 // Typing a portion of chrome:// should give the default urls.
103 {kChrome.substr(0, 1), 3, {kURL1, kURL2, kURL3}},
104 {ASCIIToUTF16("C"), 3, {kURL1, kURL2, kURL3}},
105 {kChrome, 3, {kURL1, kURL2, kURL3}},
106 {kChrome + kSeparator1, 3, {kURL1, kURL2, kURL3}},
107 {kChrome + kSeparator2, 3, {kURL1, kURL2, kURL3}},
108 {kChrome + kSeparator3, 3, {kURL1, kURL2, kURL3}},
109 {ASCIIToUTF16("ChRoMe://"), 3, {kURL1, kURL2, kURL3}},
110 };
111
112 RunTest<GURL>(typing_scheme_cases, arraysize(typing_scheme_cases),
113 &AutocompleteMatch::destination_url);
114 }
115
116 TEST_F(BuiltinProviderTest, NonChromeURLs) {
117 test_data<GURL> non_chrome_url_cases[] = {
118 // Typing an unrelated scheme should give nothing.
119 {ASCIIToUTF16("g@rb@g3"), 0, {}},
120 {ASCIIToUTF16("www.google.com"), 0, {}},
121 {ASCIIToUTF16("http:www.google.com"), 0, {}},
122 {ASCIIToUTF16("http://www.google.com"), 0, {}},
123 {ASCIIToUTF16("file:filename"), 0, {}},
124 {ASCIIToUTF16("scheme:"), 0, {}},
125 {ASCIIToUTF16("scheme://"), 0, {}},
126 {ASCIIToUTF16("scheme://host"), 0, {}},
127 {ASCIIToUTF16("scheme:host/path?query#ref"), 0, {}},
128 {ASCIIToUTF16("scheme://host/path?query#ref"), 0, {}},
129 };
130
131 RunTest<GURL>(non_chrome_url_cases, arraysize(non_chrome_url_cases),
132 &AutocompleteMatch::destination_url);
133 }
134
135 TEST_F(BuiltinProviderTest, ChromeURLs) {
136 const string16 kAbout = ASCIIToUTF16(chrome::kAboutScheme);
137 const string16 kChrome = ASCIIToUTF16(chrome::kChromeUIScheme);
138 const string16 kSeparator1 = ASCIIToUTF16(":");
139 const string16 kSeparator2 = ASCIIToUTF16(":/");
140 const string16 kSeparator3 = ASCIIToUTF16(chrome::kStandardSchemeSeparator);
141
142 // This makes assumptions about the chrome URLs listed by the BuiltinProvider.
143 // Currently they are derived from ChromePaths() in browser_about_handler.cc.
144 const string16 kHostA = ASCIIToUTF16(chrome::kChromeUIAppCacheInternalsHost);
145 const GURL kURLA = GURL(kChrome + kSeparator3 + kHostA);
146 // This test assumes these are the first three chrome hosts starting with "c".
147 const string16 kHostC1 = ASCIIToUTF16(chrome::kChromeUIChromeURLsHost);
148 const string16 kHostC2 = ASCIIToUTF16(chrome::kChromeUICrashesHost);
149 const string16 kHostC3 = ASCIIToUTF16(chrome::kChromeUICreditsHost);
150 const GURL kURLC1 = GURL(kChrome + kSeparator3 + kHostC1);
151 const GURL kURLC2 = GURL(kChrome + kSeparator3 + kHostC2);
152 const GURL kURLC3 = GURL(kChrome + kSeparator3 + kHostC3);
153
154 test_data<GURL> chrome_url_cases[] = {
155 // Typing an about URL with an unknown host should give nothing.
156 {kAbout + kSeparator1 + ASCIIToUTF16("host"), 0, {}},
157 {kAbout + kSeparator2 + ASCIIToUTF16("host"), 0, {}},
158 {kAbout + kSeparator3 + ASCIIToUTF16("host"), 0, {}},
159
160 // Typing a chrome URL with an unknown host should give nothing.
161 {kChrome + kSeparator1 + ASCIIToUTF16("host"), 0, {}},
162 {kChrome + kSeparator2 + ASCIIToUTF16("host"), 0, {}},
163 {kChrome + kSeparator3 + ASCIIToUTF16("host"), 0, {}},
164
165 // Typing an about URL for a unique host should provide that full URL.
166 {kAbout + kSeparator1 + kHostA.substr(0, 1), 1, {kURLA}},
167 {kAbout + kSeparator2 + kHostA.substr(0, 2), 1, {kURLA}},
168 {kAbout + kSeparator3 + kHostA.substr(0, kHostA.length() - 1), 1, {kURLA}},
169 {kAbout + kSeparator1 + kHostA, 1, {kURLA}},
170 {kAbout + kSeparator2 + kHostA, 1, {kURLA}},
171 {kAbout + kSeparator3 + kHostA, 1, {kURLA}},
172
173 // Typing a chrome URL for a unique host should provide that full URL.
174 {kChrome + kSeparator1 + kHostA.substr(0, 1), 1, {kURLA}},
175 {kChrome + kSeparator2 + kHostA.substr(0, 2), 1, {kURLA}},
176 {kChrome + kSeparator3 + kHostA.substr(0, kHostA.length() - 1), 1, {kURLA}},
177 {kChrome + kSeparator1 + kHostA, 1, {kURLA}},
178 {kChrome + kSeparator2 + kHostA, 1, {kURLA}},
179 {kChrome + kSeparator3 + kHostA, 1, {kURLA}},
180
181 // Typing an about URL with a non-unique host should provide matching URLs.
182 {kAbout + kSeparator1 + kHostC1.substr(0, 1), 3, {kURLC1, kURLC2, kURLC3}},
183 {kAbout + kSeparator2 + kHostC1.substr(0, 2), 1, {kURLC1}},
184 {kAbout + kSeparator3 + kHostC2.substr(0, 2), 2, {kURLC2, kURLC3}},
185 {kAbout + kSeparator3 + kHostC2.substr(0, 3), 1, {kURLC2}},
186 {kAbout + kSeparator3 + kHostC1, 1, {kURLC1}},
187 {kAbout + kSeparator2 + kHostC2, 1, {kURLC2}},
188 {kAbout + kSeparator1 + kHostC3, 1, {kURLC3}},
189
190 // Typing a chrome URL with a non-unique host should provide matching URLs.
191 {kChrome + kSeparator1 + kHostC1.substr(0, 1), 3, {kURLC1, kURLC2, kURLC3}},
192 {kChrome + kSeparator2 + kHostC1.substr(0, 2), 1, {kURLC1}},
193 {kChrome + kSeparator3 + kHostC2.substr(0, 2), 2, {kURLC2, kURLC3}},
194 {kChrome + kSeparator3 + kHostC2.substr(0, 3), 1, {kURLC2}},
195 {kChrome + kSeparator3 + kHostC1, 1, {kURLC1}},
196 {kChrome + kSeparator2 + kHostC2, 1, {kURLC2}},
197 {kChrome + kSeparator1 + kHostC3, 1, {kURLC3}},
198 };
199
200 RunTest<GURL>(chrome_url_cases, arraysize(chrome_url_cases),
201 &AutocompleteMatch::destination_url);
202 }
203
204 TEST_F(BuiltinProviderTest, ChromeSettingsSubpages) {
205 // This makes assumptions about the chrome URLs listed by the BuiltinProvider.
206 // Currently they are derived from ChromePaths() in browser_about_handler.cc.
207 const string16 kSettings = ASCIIToUTF16(chrome::kChromeUISettingsURL);
208 const string16 kDefaultPage1 = ASCIIToUTF16(chrome::kAdvancedOptionsSubPage);
209 const string16 kDefaultPage2 = ASCIIToUTF16(chrome::kAutofillSubPage);
210 const GURL kDefaultURL1 = GURL(kSettings + kDefaultPage1);
211 const GURL kDefaultURL2 = GURL(kSettings + kDefaultPage2);
212 const string16 kPage1 = ASCIIToUTF16(chrome::kPersonalOptionsSubPage);
213 const string16 kPage2 = ASCIIToUTF16(chrome::kPasswordManagerSubPage);
214 const GURL kURL1 = GURL(kSettings + kPage1);
215 const GURL kURL2 = GURL(kSettings + kPage2);
216
217 test_data<GURL> settings_subpage_cases[] = {
218 // Typing the settings path should show settings and the first two subpages.
219 {kSettings, 3, {GURL(kSettings), kDefaultURL1, kDefaultURL2}},
220
221 // Typing a subpage path should return the appropriate results.
222 {kSettings + kPage1.substr(0, 1), 2, {kURL1, kURL2}},
223 {kSettings + kPage1.substr(0, 2), 1, {kURL1}},
224 {kSettings + kPage1.substr(0, kPage1.length() - 1), 1, {kURL1}},
225 {kSettings + kPage1, 1, {kURL1}},
226 {kSettings + kPage2, 1, {kURL2}},
227 };
228
229 RunTest<GURL>(settings_subpage_cases, arraysize(settings_subpage_cases),
230 &AutocompleteMatch::destination_url);
231 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/builtin_provider.cc ('k') | chrome/browser/browser_about_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698