| OLD | NEW | 
|---|
| 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.h" | 7 #include "base/message_loop.h" | 
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" | 
| 9 #include "chrome/browser/autocomplete/autocomplete_input.h" | 9 #include "chrome/browser/autocomplete/autocomplete_input.h" | 
| 10 #include "chrome/browser/autocomplete/autocomplete_match.h" | 10 #include "chrome/browser/autocomplete/autocomplete_match.h" | 
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 136 | 136 | 
| 137 TEST_F(BuiltinProviderTest, ChromeURLs) { | 137 TEST_F(BuiltinProviderTest, ChromeURLs) { | 
| 138   const string16 kAbout = ASCIIToUTF16(chrome::kAboutScheme); | 138   const string16 kAbout = ASCIIToUTF16(chrome::kAboutScheme); | 
| 139   const string16 kChrome = ASCIIToUTF16(chrome::kChromeUIScheme); | 139   const string16 kChrome = ASCIIToUTF16(chrome::kChromeUIScheme); | 
| 140   const string16 kSeparator1 = ASCIIToUTF16(":"); | 140   const string16 kSeparator1 = ASCIIToUTF16(":"); | 
| 141   const string16 kSeparator2 = ASCIIToUTF16(":/"); | 141   const string16 kSeparator2 = ASCIIToUTF16(":/"); | 
| 142   const string16 kSeparator3 = ASCIIToUTF16(content::kStandardSchemeSeparator); | 142   const string16 kSeparator3 = ASCIIToUTF16(content::kStandardSchemeSeparator); | 
| 143 | 143 | 
| 144   // This makes assumptions about the chrome URLs listed by the BuiltinProvider. | 144   // This makes assumptions about the chrome URLs listed by the BuiltinProvider. | 
| 145   // Currently they are derived from ChromePaths() in browser_about_handler.cc. | 145   // Currently they are derived from ChromePaths() in browser_about_handler.cc. | 
| 146   const string16 kHostE = ASCIIToUTF16(chrome::kChromeUIExtensionsHost); | 146   const string16 kHostA = ASCIIToUTF16(chrome::kChromeUIAppCacheInternalsHost); | 
| 147   const GURL kURLE = GURL(kChrome + kSeparator3 + kHostE); | 147   const GURL kURLA = GURL(kChrome + kSeparator3 + kHostA); | 
| 148   const string16 kHostF1 = ASCIIToUTF16(chrome::kChromeUIFlagsHost); | 148   const string16 kHostM1 = ASCIIToUTF16(chrome::kChromeUIMediaInternalsHost); | 
| 149   const string16 kHostF2 = ASCIIToUTF16(chrome::kChromeUIFlashHost); | 149   const string16 kHostM2 = ASCIIToUTF16(chrome::kChromeUIMemoryHost); | 
| 150   const GURL kURLF1 = GURL(kChrome + kSeparator3 + kHostF1); | 150   const GURL kURLM1 = GURL(kChrome + kSeparator3 + kHostM1); | 
| 151   const GURL kURLF2 = GURL(kChrome + kSeparator3 + kHostF2); | 151   const GURL kURLM2 = GURL(kChrome + kSeparator3 + kHostM2); | 
| 152 | 152 | 
| 153   test_data<GURL> chrome_url_cases[] = { | 153   test_data<GURL> chrome_url_cases[] = { | 
| 154     // Typing an about URL with an unknown host should give nothing. | 154     // Typing an about URL with an unknown host should give nothing. | 
| 155     {kAbout + kSeparator1 + ASCIIToUTF16("host"), 0, {}}, | 155     {kAbout + kSeparator1 + ASCIIToUTF16("host"), 0, {}}, | 
| 156     {kAbout + kSeparator2 + ASCIIToUTF16("host"), 0, {}}, | 156     {kAbout + kSeparator2 + ASCIIToUTF16("host"), 0, {}}, | 
| 157     {kAbout + kSeparator3 + ASCIIToUTF16("host"), 0, {}}, | 157     {kAbout + kSeparator3 + ASCIIToUTF16("host"), 0, {}}, | 
| 158 | 158 | 
| 159     // Typing a chrome URL with an unknown host should give nothing. | 159     // Typing a chrome URL with an unknown host should give nothing. | 
| 160     {kChrome + kSeparator1 + ASCIIToUTF16("host"), 0, {}}, | 160     {kChrome + kSeparator1 + ASCIIToUTF16("host"), 0, {}}, | 
| 161     {kChrome + kSeparator2 + ASCIIToUTF16("host"), 0, {}}, | 161     {kChrome + kSeparator2 + ASCIIToUTF16("host"), 0, {}}, | 
| 162     {kChrome + kSeparator3 + ASCIIToUTF16("host"), 0, {}}, | 162     {kChrome + kSeparator3 + ASCIIToUTF16("host"), 0, {}}, | 
| 163 | 163 | 
| 164     // Typing an about URL for a unique host should provide that full URL. | 164     // Typing an about URL for a unique host should provide that full URL. | 
| 165     {kAbout + kSeparator1 + kHostE.substr(0, 1),                   1, {kURLE}}, | 165     {kAbout + kSeparator1 + kHostA.substr(0, 1),                   1, {kURLA}}, | 
| 166     {kAbout + kSeparator2 + kHostE.substr(0, 2),                   1, {kURLE}}, | 166     {kAbout + kSeparator2 + kHostA.substr(0, 2),                   1, {kURLA}}, | 
| 167     {kAbout + kSeparator3 + kHostE.substr(0, kHostE.length() - 1), 1, {kURLE}}, | 167     {kAbout + kSeparator3 + kHostA.substr(0, kHostA.length() - 1), 1, {kURLA}}, | 
| 168     {kAbout + kSeparator1 + kHostE,                                1, {kURLE}}, | 168     {kAbout + kSeparator1 + kHostA,                                1, {kURLA}}, | 
| 169     {kAbout + kSeparator2 + kHostE,                                1, {kURLE}}, | 169     {kAbout + kSeparator2 + kHostA,                                1, {kURLA}}, | 
| 170     {kAbout + kSeparator3 + kHostE,                                1, {kURLE}}, | 170     {kAbout + kSeparator3 + kHostA,                                1, {kURLA}}, | 
| 171 | 171 | 
| 172     // Typing a chrome URL for a unique host should provide that full URL. | 172     // Typing a chrome URL for a unique host should provide that full URL. | 
| 173     {kChrome + kSeparator1 + kHostE.substr(0, 1),                   1, {kURLE}}, | 173     {kChrome + kSeparator1 + kHostA.substr(0, 1),                   1, {kURLA}}, | 
| 174     {kChrome + kSeparator2 + kHostE.substr(0, 2),                   1, {kURLE}}, | 174     {kChrome + kSeparator2 + kHostA.substr(0, 2),                   1, {kURLA}}, | 
| 175     {kChrome + kSeparator3 + kHostE.substr(0, kHostE.length() - 1), 1, {kURLE}}, | 175     {kChrome + kSeparator3 + kHostA.substr(0, kHostA.length() - 1), 1, {kURLA}}, | 
| 176     {kChrome + kSeparator1 + kHostE,                                1, {kURLE}}, | 176     {kChrome + kSeparator1 + kHostA,                                1, {kURLA}}, | 
| 177     {kChrome + kSeparator2 + kHostE,                                1, {kURLE}}, | 177     {kChrome + kSeparator2 + kHostA,                                1, {kURLA}}, | 
| 178     {kChrome + kSeparator3 + kHostE,                                1, {kURLE}}, | 178     {kChrome + kSeparator3 + kHostA,                                1, {kURLA}}, | 
| 179 | 179 | 
| 180     // Typing an about URL with a non-unique host should provide matching URLs. | 180     // Typing an about URL with a non-unique host should provide matching URLs. | 
| 181     {kAbout + kSeparator1 + kHostF1.substr(0, 1), 2, {kURLF1, kURLF2}}, | 181     {kAbout + kSeparator1 + kHostM1.substr(0, 1), 2, {kURLM1, kURLM2}}, | 
| 182     {kAbout + kSeparator2 + kHostF1.substr(0, 2), 2, {kURLF1, kURLF2}}, | 182     {kAbout + kSeparator2 + kHostM1.substr(0, 2), 2, {kURLM1, kURLM2}}, | 
| 183     {kAbout + kSeparator3 + kHostF2.substr(0, 3), 2, {kURLF1, kURLF2}}, | 183     {kAbout + kSeparator3 + kHostM1.substr(0, 3), 1, {kURLM1}}, | 
| 184     {kAbout + kSeparator3 + kHostF1.substr(0, 4), 1, {kURLF1}}, | 184     {kAbout + kSeparator3 + kHostM2.substr(0, 3), 1, {kURLM2}}, | 
| 185     {kAbout + kSeparator3 + kHostF2.substr(0, 4), 1, {kURLF2}}, | 185     {kAbout + kSeparator3 + kHostM1,              1, {kURLM1}}, | 
| 186     {kAbout + kSeparator3 + kHostF1,              1, {kURLF1}}, | 186     {kAbout + kSeparator2 + kHostM2,              1, {kURLM2}}, | 
| 187     {kAbout + kSeparator2 + kHostF2,              1, {kURLF2}}, |  | 
| 188 | 187 | 
| 189     // Typing a chrome URL with a non-unique host should provide matching URLs. | 188     // Typing a chrome URL with a non-unique host should provide matching URLs. | 
| 190     {kChrome + kSeparator1 + kHostF1.substr(0, 1), 2, {kURLF1, kURLF2}}, | 189     {kChrome + kSeparator1 + kHostM1.substr(0, 1), 2, {kURLM1, kURLM2}}, | 
| 191     {kChrome + kSeparator2 + kHostF1.substr(0, 2), 2, {kURLF1, kURLF2}}, | 190     {kChrome + kSeparator2 + kHostM1.substr(0, 2), 2, {kURLM1, kURLM2}}, | 
| 192     {kChrome + kSeparator3 + kHostF2.substr(0, 3), 2, {kURLF1, kURLF2}}, | 191     {kChrome + kSeparator3 + kHostM1.substr(0, 3), 1, {kURLM1}}, | 
| 193     {kChrome + kSeparator3 + kHostF1.substr(0, 4), 1, {kURLF1}}, | 192     {kChrome + kSeparator3 + kHostM2.substr(0, 3), 1, {kURLM2}}, | 
| 194     {kChrome + kSeparator3 + kHostF2.substr(0, 4), 1, {kURLF2}}, | 193     {kChrome + kSeparator3 + kHostM1,              1, {kURLM1}}, | 
| 195     {kChrome + kSeparator3 + kHostF1,              1, {kURLF1}}, | 194     {kChrome + kSeparator2 + kHostM2,              1, {kURLM2}}, | 
| 196     {kChrome + kSeparator2 + kHostF2,              1, {kURLF2}}, |  | 
| 197   }; | 195   }; | 
| 198 | 196 | 
| 199   RunTest<GURL>(chrome_url_cases, arraysize(chrome_url_cases), | 197   RunTest<GURL>(chrome_url_cases, arraysize(chrome_url_cases), | 
| 200                 &AutocompleteMatch::destination_url); | 198                 &AutocompleteMatch::destination_url); | 
| 201 } | 199 } | 
| 202 | 200 | 
|  | 201 #if !defined(OS_ANDROID) | 
|  | 202 // Disabled on Android where we use native UI instead of chrome://settings. | 
| 203 TEST_F(BuiltinProviderTest, ChromeSettingsSubpages) { | 203 TEST_F(BuiltinProviderTest, ChromeSettingsSubpages) { | 
| 204   // This makes assumptions about the chrome URLs listed by the BuiltinProvider. | 204   // This makes assumptions about the chrome URLs listed by the BuiltinProvider. | 
| 205   // Currently they are derived from ChromePaths() in browser_about_handler.cc. | 205   // Currently they are derived from ChromePaths() in browser_about_handler.cc. | 
| 206   const string16 kSettings = ASCIIToUTF16(chrome::kChromeUISettingsURL); | 206   const string16 kSettings = ASCIIToUTF16(chrome::kChromeUISettingsURL); | 
| 207   const string16 kDefaultPage1 = ASCIIToUTF16(chrome::kAutofillSubPage); | 207   const string16 kDefaultPage1 = ASCIIToUTF16(chrome::kAutofillSubPage); | 
| 208   const string16 kDefaultPage2 = ASCIIToUTF16(chrome::kClearBrowserDataSubPage); | 208   const string16 kDefaultPage2 = ASCIIToUTF16(chrome::kClearBrowserDataSubPage); | 
| 209   const GURL kDefaultURL1 = GURL(kSettings + kDefaultPage1); | 209   const GURL kDefaultURL1 = GURL(kSettings + kDefaultPage1); | 
| 210   const GURL kDefaultURL2 = GURL(kSettings + kDefaultPage2); | 210   const GURL kDefaultURL2 = GURL(kSettings + kDefaultPage2); | 
| 211   const string16 kPage1 = ASCIIToUTF16(chrome::kSearchEnginesSubPage); | 211   const string16 kPage1 = ASCIIToUTF16(chrome::kSearchEnginesSubPage); | 
| 212   const string16 kPage2 = ASCIIToUTF16(chrome::kSyncSetupSubPage); | 212   const string16 kPage2 = ASCIIToUTF16(chrome::kSyncSetupSubPage); | 
| 213   const GURL kURL1 = GURL(kSettings + kPage1); | 213   const GURL kURL1 = GURL(kSettings + kPage1); | 
| 214   const GURL kURL2 = GURL(kSettings + kPage2); | 214   const GURL kURL2 = GURL(kSettings + kPage2); | 
| 215 | 215 | 
| 216   test_data<GURL> settings_subpage_cases[] = { | 216   test_data<GURL> settings_subpage_cases[] = { | 
| 217     // Typing the settings path should show settings and the first two subpages. | 217     // Typing the settings path should show settings and the first two subpages. | 
| 218     {kSettings, 3, {GURL(kSettings), kDefaultURL1, kDefaultURL2}}, | 218     {kSettings, 3, {GURL(kSettings), kDefaultURL1, kDefaultURL2}}, | 
| 219 | 219 | 
| 220     // Typing a subpage path should return the appropriate results. | 220     // Typing a subpage path should return the appropriate results. | 
| 221     {kSettings + kPage1.substr(0, 1),                   2, {kURL1, kURL2}}, | 221     {kSettings + kPage1.substr(0, 1),                   2, {kURL1, kURL2}}, | 
| 222     {kSettings + kPage1.substr(0, 2),                   1, {kURL1}}, | 222     {kSettings + kPage1.substr(0, 2),                   1, {kURL1}}, | 
| 223     {kSettings + kPage1.substr(0, kPage1.length() - 1), 1, {kURL1}}, | 223     {kSettings + kPage1.substr(0, kPage1.length() - 1), 1, {kURL1}}, | 
| 224     {kSettings + kPage1,                                1, {kURL1}}, | 224     {kSettings + kPage1,                                1, {kURL1}}, | 
| 225     {kSettings + kPage2,                                1, {kURL2}}, | 225     {kSettings + kPage2,                                1, {kURL2}}, | 
| 226   }; | 226   }; | 
| 227 | 227 | 
| 228   RunTest<GURL>(settings_subpage_cases, arraysize(settings_subpage_cases), | 228   RunTest<GURL>(settings_subpage_cases, arraysize(settings_subpage_cases), | 
| 229                 &AutocompleteMatch::destination_url); | 229                 &AutocompleteMatch::destination_url); | 
| 230 } | 230 } | 
|  | 231 #endif | 
| OLD | NEW | 
|---|