| 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 "components/omnibox/browser/builtin_provider.h" | 5 #include "components/omnibox/browser/builtin_provider.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 14 #include "chrome/browser/autocomplete/chrome_autocomplete_provider_client.h" | |
| 15 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" | |
| 16 #include "chrome/common/url_constants.h" | |
| 17 #include "chrome/test/base/testing_profile.h" | |
| 18 #include "components/metrics/proto/omnibox_event.pb.h" | 14 #include "components/metrics/proto/omnibox_event.pb.h" |
| 19 #include "components/omnibox/browser/autocomplete_input.h" | 15 #include "components/omnibox/browser/autocomplete_input.h" |
| 20 #include "components/omnibox/browser/autocomplete_match.h" | 16 #include "components/omnibox/browser/autocomplete_match.h" |
| 21 #include "components/omnibox/browser/autocomplete_provider.h" | 17 #include "components/omnibox/browser/autocomplete_provider.h" |
| 22 #include "content/public/test/test_browser_thread_bundle.h" | 18 #include "components/omnibox/browser/mock_autocomplete_provider_client.h" |
| 19 #include "components/omnibox/browser/test_scheme_classifier.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 24 #include "url/gurl.h" | 21 #include "url/gurl.h" |
| 25 | 22 |
| 26 using base::ASCIIToUTF16; | 23 using base::ASCIIToUTF16; |
| 27 | 24 |
| 25 namespace { |
| 26 |
| 27 const char kEmbedderAboutScheme[] = "chrome"; |
| 28 const char kDefaultURL1[] = "chrome://default1/"; |
| 29 const char kDefaultURL2[] = "chrome://default2/"; |
| 30 const char kDefaultURL3[] = "chrome://foo/"; |
| 31 const char kSubpageURL[] = "chrome://subpage/"; |
| 32 |
| 33 // Arbitrary host constants, chosen to start with the letters "b" and "me". |
| 34 const char kHostBar[] = "bar"; |
| 35 const char kHostMedia[] = "media"; |
| 36 const char kHostMemory[] = "memory"; |
| 37 const char kHostMemoryInternals[] = "memory-internals"; |
| 38 const char kHostSubpage[] = "subpage"; |
| 39 |
| 40 const char kSubpageOne[] = "one"; |
| 41 const char kSubpageTwo[] = "two"; |
| 42 const char kSubpageThree[] = "three"; |
| 43 |
| 44 class FakeAutocompleteProviderClient : public MockAutocompleteProviderClient { |
| 45 public: |
| 46 FakeAutocompleteProviderClient() {} |
| 47 |
| 48 std::string GetEmbedderRepresentationOfAboutScheme() override { |
| 49 return kEmbedderAboutScheme; |
| 50 } |
| 51 |
| 52 std::vector<base::string16> GetBuiltinURLs() override { |
| 53 std::vector<base::string16> urls; |
| 54 urls.push_back(ASCIIToUTF16(kHostBar)); |
| 55 urls.push_back(ASCIIToUTF16(kHostMedia)); |
| 56 urls.push_back(ASCIIToUTF16(kHostMemory)); |
| 57 urls.push_back(ASCIIToUTF16(kHostMemoryInternals)); |
| 58 urls.push_back(ASCIIToUTF16(kHostSubpage)); |
| 59 |
| 60 base::string16 prefix = ASCIIToUTF16(kHostSubpage) + ASCIIToUTF16("/"); |
| 61 urls.push_back(prefix + ASCIIToUTF16(kSubpageOne)); |
| 62 urls.push_back(prefix + ASCIIToUTF16(kSubpageTwo)); |
| 63 urls.push_back(prefix + ASCIIToUTF16(kSubpageThree)); |
| 64 return urls; |
| 65 } |
| 66 |
| 67 std::vector<base::string16> GetBuiltinsToProvideAsUserTypes() override { |
| 68 std::vector<base::string16> urls; |
| 69 urls.push_back(ASCIIToUTF16(kDefaultURL1)); |
| 70 urls.push_back(ASCIIToUTF16(kDefaultURL2)); |
| 71 urls.push_back(ASCIIToUTF16(kDefaultURL3)); |
| 72 return urls; |
| 73 } |
| 74 |
| 75 private: |
| 76 DISALLOW_COPY_AND_ASSIGN(FakeAutocompleteProviderClient); |
| 77 }; |
| 78 |
| 79 } // namespace |
| 80 |
| 28 class BuiltinProviderTest : public testing::Test { | 81 class BuiltinProviderTest : public testing::Test { |
| 29 protected: | 82 protected: |
| 30 struct TestData { | 83 struct TestData { |
| 31 const base::string16 input; | 84 const base::string16 input; |
| 32 const size_t num_results; | 85 const size_t num_results; |
| 33 const GURL output[3]; | 86 const GURL output[3]; |
| 34 }; | 87 }; |
| 35 | 88 |
| 36 BuiltinProviderTest() : provider_(NULL) {} | 89 BuiltinProviderTest() : provider_(NULL) {} |
| 37 ~BuiltinProviderTest() override {} | 90 ~BuiltinProviderTest() override {} |
| 38 | 91 |
| 39 void SetUp() override { | 92 void SetUp() override { |
| 40 profile_.reset(new TestingProfile()); | 93 client_.reset(new FakeAutocompleteProviderClient()); |
| 41 client_.reset(new ChromeAutocompleteProviderClient(profile_.get())); | |
| 42 provider_ = new BuiltinProvider(client_.get()); | 94 provider_ = new BuiltinProvider(client_.get()); |
| 43 } | 95 } |
| 44 void TearDown() override { provider_ = NULL; } | 96 void TearDown() override { provider_ = NULL; } |
| 45 | 97 |
| 46 void RunTest(const TestData cases[], size_t num_cases) { | 98 void RunTest(const TestData cases[], size_t num_cases) { |
| 47 ACMatches matches; | 99 ACMatches matches; |
| 48 for (size_t i = 0; i < num_cases; ++i) { | 100 for (size_t i = 0; i < num_cases; ++i) { |
| 49 SCOPED_TRACE(base::StringPrintf( | 101 SCOPED_TRACE(base::StringPrintf( |
| 50 "case %" PRIuS ": %s", i, base::UTF16ToUTF8(cases[i].input).c_str())); | 102 "case %" PRIuS ": %s", i, base::UTF16ToUTF8(cases[i].input).c_str())); |
| 51 const AutocompleteInput input( | 103 const AutocompleteInput input( |
| 52 cases[i].input, base::string16::npos, std::string(), GURL(), | 104 cases[i].input, base::string16::npos, std::string(), GURL(), |
| 53 metrics::OmniboxEventProto::INVALID_SPEC, true, false, true, true, | 105 metrics::OmniboxEventProto::INVALID_SPEC, true, false, true, true, |
| 54 false, ChromeAutocompleteSchemeClassifier(NULL)); | 106 false, TestSchemeClassifier()); |
| 55 provider_->Start(input, false); | 107 provider_->Start(input, false); |
| 56 EXPECT_TRUE(provider_->done()); | 108 EXPECT_TRUE(provider_->done()); |
| 57 matches = provider_->matches(); | 109 matches = provider_->matches(); |
| 58 EXPECT_EQ(cases[i].num_results, matches.size()); | 110 EXPECT_EQ(cases[i].num_results, matches.size()); |
| 59 if (matches.size() == cases[i].num_results) { | 111 if (matches.size() == cases[i].num_results) { |
| 60 for (size_t j = 0; j < cases[i].num_results; ++j) { | 112 for (size_t j = 0; j < cases[i].num_results; ++j) { |
| 61 EXPECT_EQ(cases[i].output[j], matches[j].destination_url); | 113 EXPECT_EQ(cases[i].output[j], matches[j].destination_url); |
| 62 EXPECT_FALSE(matches[j].allowed_to_be_default_match); | 114 EXPECT_FALSE(matches[j].allowed_to_be_default_match); |
| 63 } | 115 } |
| 64 } | 116 } |
| 65 } | 117 } |
| 66 } | 118 } |
| 67 | 119 |
| 68 content::TestBrowserThreadBundle thread_bundle_; | 120 scoped_ptr<FakeAutocompleteProviderClient> client_; |
| 69 | |
| 70 scoped_ptr<TestingProfile> profile_; | |
| 71 scoped_ptr<ChromeAutocompleteProviderClient> client_; | |
| 72 scoped_refptr<BuiltinProvider> provider_; | 121 scoped_refptr<BuiltinProvider> provider_; |
| 73 | 122 |
| 74 private: | 123 private: |
| 75 DISALLOW_COPY_AND_ASSIGN(BuiltinProviderTest); | 124 DISALLOW_COPY_AND_ASSIGN(BuiltinProviderTest); |
| 76 }; | 125 }; |
| 77 | 126 |
| 78 #if !defined(OS_ANDROID) | |
| 79 TEST_F(BuiltinProviderTest, TypingScheme) { | 127 TEST_F(BuiltinProviderTest, TypingScheme) { |
| 80 const base::string16 kAbout = ASCIIToUTF16(url::kAboutScheme); | 128 const base::string16 kAbout = ASCIIToUTF16(url::kAboutScheme); |
| 81 const base::string16 kChrome = ASCIIToUTF16(content::kChromeUIScheme); | 129 const base::string16 kEmbedder = ASCIIToUTF16(kEmbedderAboutScheme); |
| 82 const base::string16 kSeparator1 = ASCIIToUTF16(":"); | 130 const base::string16 kSeparator1 = ASCIIToUTF16(":"); |
| 83 const base::string16 kSeparator2 = ASCIIToUTF16(":/"); | 131 const base::string16 kSeparator2 = ASCIIToUTF16(":/"); |
| 84 const base::string16 kSeparator3 = | 132 const base::string16 kSeparator3 = |
| 85 ASCIIToUTF16(url::kStandardSchemeSeparator); | 133 ASCIIToUTF16(url::kStandardSchemeSeparator); |
| 86 | 134 |
| 87 // These default URLs should correspond with those in BuiltinProvider::Start. | 135 // These default URLs should correspond with those in BuiltinProvider::Start. |
| 88 const GURL kURL1 = GURL(chrome::kChromeUIChromeURLsURL); | 136 const GURL kURL1(kDefaultURL1); |
| 89 const GURL kURL2 = GURL(chrome::kChromeUISettingsURL); | 137 const GURL kURL2(kDefaultURL2); |
| 90 const GURL kURL3 = GURL(chrome::kChromeUIVersionURL); | 138 const GURL kURL3(kDefaultURL3); |
| 91 | 139 |
| 92 TestData typing_scheme_cases[] = { | 140 TestData typing_scheme_cases[] = { |
| 93 // Typing an unrelated scheme should give nothing. | 141 // Typing an unrelated scheme should give nothing. |
| 94 {ASCIIToUTF16("h"), 0, {}}, | 142 {ASCIIToUTF16("h"), 0, {}}, |
| 95 {ASCIIToUTF16("http"), 0, {}}, | 143 {ASCIIToUTF16("http"), 0, {}}, |
| 96 {ASCIIToUTF16("file"), 0, {}}, | 144 {ASCIIToUTF16("file"), 0, {}}, |
| 97 {ASCIIToUTF16("abouz"), 0, {}}, | 145 {ASCIIToUTF16("abouz"), 0, {}}, |
| 98 {ASCIIToUTF16("aboutt"), 0, {}}, | 146 {ASCIIToUTF16("aboutt"), 0, {}}, |
| 99 {ASCIIToUTF16("aboutt:"), 0, {}}, | 147 {ASCIIToUTF16("aboutt:"), 0, {}}, |
| 100 {ASCIIToUTF16("chroma"), 0, {}}, | 148 {ASCIIToUTF16("chroma"), 0, {}}, |
| 101 {ASCIIToUTF16("chromee"), 0, {}}, | 149 {ASCIIToUTF16("chromee"), 0, {}}, |
| 102 {ASCIIToUTF16("chromee:"), 0, {}}, | 150 {ASCIIToUTF16("chromee:"), 0, {}}, |
| 103 | 151 |
| 104 // Typing a portion of about:// should give the default urls. | 152 // Typing a portion of about:// should give the default urls. |
| 105 {kAbout.substr(0, 1), 3, {kURL1, kURL2, kURL3}}, | 153 {kAbout.substr(0, 1), 3, {kURL1, kURL2, kURL3}}, |
| 106 {ASCIIToUTF16("A"), 3, {kURL1, kURL2, kURL3}}, | 154 {ASCIIToUTF16("A"), 3, {kURL1, kURL2, kURL3}}, |
| 107 {kAbout, 3, {kURL1, kURL2, kURL3}}, | 155 {kAbout, 3, {kURL1, kURL2, kURL3}}, |
| 108 {kAbout + kSeparator1, 3, {kURL1, kURL2, kURL3}}, | 156 {kAbout + kSeparator1, 3, {kURL1, kURL2, kURL3}}, |
| 109 {kAbout + kSeparator2, 3, {kURL1, kURL2, kURL3}}, | 157 {kAbout + kSeparator2, 3, {kURL1, kURL2, kURL3}}, |
| 110 {kAbout + kSeparator3, 3, {kURL1, kURL2, kURL3}}, | 158 {kAbout + kSeparator3, 3, {kURL1, kURL2, kURL3}}, |
| 111 {ASCIIToUTF16("aBoUT://"), 3, {kURL1, kURL2, kURL3}}, | 159 {ASCIIToUTF16("aBoUT://"), 3, {kURL1, kURL2, kURL3}}, |
| 112 | 160 |
| 113 // Typing a portion of chrome:// should give the default urls. | 161 // Typing a portion of the embedder scheme should give the default urls. |
| 114 {kChrome.substr(0, 1), 3, {kURL1, kURL2, kURL3}}, | 162 {kEmbedder.substr(0, 1), 3, {kURL1, kURL2, kURL3}}, |
| 115 {ASCIIToUTF16("C"), 3, {kURL1, kURL2, kURL3}}, | 163 {ASCIIToUTF16("C"), 3, {kURL1, kURL2, kURL3}}, |
| 116 {kChrome, 3, {kURL1, kURL2, kURL3}}, | 164 {kEmbedder, 3, {kURL1, kURL2, kURL3}}, |
| 117 {kChrome + kSeparator1, 3, {kURL1, kURL2, kURL3}}, | 165 {kEmbedder + kSeparator1, 3, {kURL1, kURL2, kURL3}}, |
| 118 {kChrome + kSeparator2, 3, {kURL1, kURL2, kURL3}}, | 166 {kEmbedder + kSeparator2, 3, {kURL1, kURL2, kURL3}}, |
| 119 {kChrome + kSeparator3, 3, {kURL1, kURL2, kURL3}}, | 167 {kEmbedder + kSeparator3, 3, {kURL1, kURL2, kURL3}}, |
| 120 {ASCIIToUTF16("ChRoMe://"), 3, {kURL1, kURL2, kURL3}}, | 168 {ASCIIToUTF16("ChRoMe://"), 3, {kURL1, kURL2, kURL3}}, |
| 121 }; | 169 }; |
| 122 | 170 |
| 123 RunTest(typing_scheme_cases, arraysize(typing_scheme_cases)); | 171 RunTest(typing_scheme_cases, arraysize(typing_scheme_cases)); |
| 124 } | 172 } |
| 125 #else // Android uses a subset of the URLs | |
| 126 TEST_F(BuiltinProviderTest, TypingScheme) { | |
| 127 const base::string16 kAbout = ASCIIToUTF16(url::kAboutScheme); | |
| 128 const base::string16 kChrome = ASCIIToUTF16(content::kChromeUIScheme); | |
| 129 const base::string16 kSeparator1 = ASCIIToUTF16(":"); | |
| 130 const base::string16 kSeparator2 = ASCIIToUTF16(":/"); | |
| 131 const base::string16 kSeparator3 = | |
| 132 ASCIIToUTF16(url::kStandardSchemeSeparator); | |
| 133 | 173 |
| 134 // These default URLs should correspond with those in BuiltinProvider::Start. | 174 TEST_F(BuiltinProviderTest, NonEmbedderURLs) { |
| 135 const GURL kURL1 = GURL(chrome::kChromeUIChromeURLsURL); | 175 TestData test_cases[] = { |
| 136 const GURL kURL2 = GURL(chrome::kChromeUIVersionURL); | |
| 137 | |
| 138 TestData typing_scheme_cases[] = { | |
| 139 // Typing an unrelated scheme should give nothing. | |
| 140 {ASCIIToUTF16("h"), 0, {}}, | |
| 141 {ASCIIToUTF16("http"), 0, {}}, | |
| 142 {ASCIIToUTF16("file"), 0, {}}, | |
| 143 {ASCIIToUTF16("abouz"), 0, {}}, | |
| 144 {ASCIIToUTF16("aboutt"), 0, {}}, | |
| 145 {ASCIIToUTF16("aboutt:"), 0, {}}, | |
| 146 {ASCIIToUTF16("chroma"), 0, {}}, | |
| 147 {ASCIIToUTF16("chromee"), 0, {}}, | |
| 148 {ASCIIToUTF16("chromee:"), 0, {}}, | |
| 149 | |
| 150 // Typing a portion of about:// should give the default urls. | |
| 151 {kAbout.substr(0, 1), 2, {kURL1, kURL2}}, | |
| 152 {ASCIIToUTF16("A"), 2, {kURL1, kURL2}}, | |
| 153 {kAbout, 2, {kURL1, kURL2}}, | |
| 154 {kAbout + kSeparator1, 2, {kURL1, kURL2}}, | |
| 155 {kAbout + kSeparator2, 2, {kURL1, kURL2}}, | |
| 156 {kAbout + kSeparator3, 2, {kURL1, kURL2}}, | |
| 157 {ASCIIToUTF16("aBoUT://"), 2, {kURL1, kURL2}}, | |
| 158 | |
| 159 // Typing a portion of chrome:// should give the default urls. | |
| 160 {kChrome.substr(0, 1), 2, {kURL1, kURL2}}, | |
| 161 {ASCIIToUTF16("C"), 2, {kURL1, kURL2}}, | |
| 162 {kChrome, 2, {kURL1, kURL2}}, | |
| 163 {kChrome + kSeparator1, 2, {kURL1, kURL2}}, | |
| 164 {kChrome + kSeparator2, 2, {kURL1, kURL2}}, | |
| 165 {kChrome + kSeparator3, 2, {kURL1, kURL2}}, | |
| 166 {ASCIIToUTF16("ChRoMe://"), 2, {kURL1, kURL2}}, | |
| 167 }; | |
| 168 | |
| 169 RunTest(typing_scheme_cases, arraysize(typing_scheme_cases)); | |
| 170 } | |
| 171 #endif | |
| 172 | |
| 173 TEST_F(BuiltinProviderTest, NonChromeURLs) { | |
| 174 TestData non_chrome_url_cases[] = { | |
| 175 // Typing an unrelated scheme should give nothing. | 176 // Typing an unrelated scheme should give nothing. |
| 176 {ASCIIToUTF16("g@rb@g3"), 0, {}}, | 177 {ASCIIToUTF16("g@rb@g3"), 0, {}}, |
| 177 {ASCIIToUTF16("www.google.com"), 0, {}}, | 178 {ASCIIToUTF16("www.google.com"), 0, {}}, |
| 178 {ASCIIToUTF16("http:www.google.com"), 0, {}}, | 179 {ASCIIToUTF16("http:www.google.com"), 0, {}}, |
| 179 {ASCIIToUTF16("http://www.google.com"), 0, {}}, | 180 {ASCIIToUTF16("http://www.google.com"), 0, {}}, |
| 180 {ASCIIToUTF16("file:filename"), 0, {}}, | 181 {ASCIIToUTF16("file:filename"), 0, {}}, |
| 181 {ASCIIToUTF16("scheme:"), 0, {}}, | 182 {ASCIIToUTF16("scheme:"), 0, {}}, |
| 182 {ASCIIToUTF16("scheme://"), 0, {}}, | 183 {ASCIIToUTF16("scheme://"), 0, {}}, |
| 183 {ASCIIToUTF16("scheme://host"), 0, {}}, | 184 {ASCIIToUTF16("scheme://host"), 0, {}}, |
| 184 {ASCIIToUTF16("scheme:host/path?query#ref"), 0, {}}, | 185 {ASCIIToUTF16("scheme:host/path?query#ref"), 0, {}}, |
| 185 {ASCIIToUTF16("scheme://host/path?query#ref"), 0, {}}, | 186 {ASCIIToUTF16("scheme://host/path?query#ref"), 0, {}}, |
| 186 }; | 187 }; |
| 187 | 188 |
| 188 RunTest(non_chrome_url_cases, arraysize(non_chrome_url_cases)); | 189 RunTest(test_cases, arraysize(test_cases)); |
| 189 } | 190 } |
| 190 | 191 |
| 191 TEST_F(BuiltinProviderTest, ChromeURLs) { | 192 TEST_F(BuiltinProviderTest, EmbedderProvidedURLs) { |
| 192 const base::string16 kAbout = ASCIIToUTF16(url::kAboutScheme); | 193 const base::string16 kAbout = ASCIIToUTF16(url::kAboutScheme); |
| 193 const base::string16 kChrome = ASCIIToUTF16(content::kChromeUIScheme); | 194 const base::string16 kEmbedder = ASCIIToUTF16(kEmbedderAboutScheme); |
| 194 const base::string16 kSeparator1 = ASCIIToUTF16(":"); | 195 const base::string16 kSep1 = ASCIIToUTF16(":"); |
| 195 const base::string16 kSeparator2 = ASCIIToUTF16(":/"); | 196 const base::string16 kSep2 = ASCIIToUTF16(":/"); |
| 196 const base::string16 kSeparator3 = | 197 const base::string16 kSep3 = |
| 197 ASCIIToUTF16(url::kStandardSchemeSeparator); | 198 ASCIIToUTF16(url::kStandardSchemeSeparator); |
| 198 | 199 |
| 199 // This makes assumptions about the chrome URLs listed by the BuiltinProvider. | 200 // The following hosts are arbitrary, chosen so that they all start with the |
| 200 // Currently they are derived from chrome::kChromeHostURLs[]. | 201 // letters "me". |
| 201 const base::string16 kHostM1 = | 202 const base::string16 kHostM1 = ASCIIToUTF16(kHostMedia); |
| 202 ASCIIToUTF16(content::kChromeUIMediaInternalsHost); | 203 const base::string16 kHostM2 = ASCIIToUTF16(kHostMemory); |
| 203 const base::string16 kHostM2 = | 204 const base::string16 kHostM3 = ASCIIToUTF16(kHostMemoryInternals); |
| 204 ASCIIToUTF16(chrome::kChromeUIMemoryHost); | 205 const GURL kURLM1(kEmbedder + kSep3 + kHostM1); |
| 205 const base::string16 kHostM3 = | 206 const GURL kURLM2(kEmbedder + kSep3 + kHostM2); |
| 206 ASCIIToUTF16(chrome::kChromeUIMemoryInternalsHost); | 207 const GURL kURLM3(kEmbedder + kSep3 + kHostM3); |
| 207 const GURL kURLM1 = GURL(kChrome + kSeparator3 + kHostM1); | |
| 208 const GURL kURLM2 = GURL(kChrome + kSeparator3 + kHostM2); | |
| 209 const GURL kURLM3 = GURL(kChrome + kSeparator3 + kHostM3); | |
| 210 | 208 |
| 211 TestData chrome_url_cases[] = { | 209 TestData test_cases[] = { |
| 212 // Typing an about URL with an unknown host should give nothing. | 210 // Typing an about URL with an unknown host should give nothing. |
| 213 {kAbout + kSeparator1 + ASCIIToUTF16("host"), 0, {}}, | 211 {kAbout + kSep1 + ASCIIToUTF16("host"), 0, {}}, |
| 214 {kAbout + kSeparator2 + ASCIIToUTF16("host"), 0, {}}, | 212 {kAbout + kSep2 + ASCIIToUTF16("host"), 0, {}}, |
| 215 {kAbout + kSeparator3 + ASCIIToUTF16("host"), 0, {}}, | 213 {kAbout + kSep3 + ASCIIToUTF16("host"), 0, {}}, |
| 216 | 214 |
| 217 // Typing a chrome URL with an unknown host should give nothing. | 215 // Typing an embedder URL with an unknown host should give nothing. |
| 218 {kChrome + kSeparator1 + ASCIIToUTF16("host"), 0, {}}, | 216 {kEmbedder + kSep1 + ASCIIToUTF16("host"), 0, {}}, |
| 219 {kChrome + kSeparator2 + ASCIIToUTF16("host"), 0, {}}, | 217 {kEmbedder + kSep2 + ASCIIToUTF16("host"), 0, {}}, |
| 220 {kChrome + kSeparator3 + ASCIIToUTF16("host"), 0, {}}, | 218 {kEmbedder + kSep3 + ASCIIToUTF16("host"), 0, {}}, |
| 221 | 219 |
| 222 // Typing an about URL should provide matching URLs. | 220 // Typing an about URL should provide matching URLs. |
| 223 {kAbout + kSeparator1 + kHostM1.substr(0, 1), 3, {kURLM1, kURLM2, kURLM3}}, | 221 {kAbout + kSep1 + kHostM1.substr(0, 1), 3, {kURLM1, kURLM2, kURLM3}}, |
| 224 {kAbout + kSeparator2 + kHostM1.substr(0, 2), 3, {kURLM1, kURLM2, kURLM3}}, | 222 {kAbout + kSep2 + kHostM1.substr(0, 2), 3, {kURLM1, kURLM2, kURLM3}}, |
| 225 {kAbout + kSeparator3 + kHostM1.substr(0, 3), 1, {kURLM1}}, | 223 {kAbout + kSep3 + kHostM1.substr(0, 3), 1, {kURLM1}}, |
| 226 {kAbout + kSeparator3 + kHostM2.substr(0, 3), 2, {kURLM2, kURLM3}}, | 224 {kAbout + kSep3 + kHostM2.substr(0, 3), 2, {kURLM2, kURLM3}}, |
| 227 {kAbout + kSeparator3 + kHostM1, 1, {kURLM1}}, | 225 {kAbout + kSep3 + kHostM1, 1, {kURLM1}}, |
| 228 {kAbout + kSeparator2 + kHostM2, 2, {kURLM2, kURLM3}}, | 226 {kAbout + kSep2 + kHostM2, 2, {kURLM2, kURLM3}}, |
| 229 {kAbout + kSeparator2 + kHostM3, 1, {kURLM3}}, | 227 {kAbout + kSep2 + kHostM3, 1, {kURLM3}}, |
| 230 | 228 |
| 231 // Typing a chrome URL should provide matching URLs. | 229 // Typing an embedder URL should provide matching URLs. |
| 232 {kChrome + kSeparator1 + kHostM1.substr(0, 1), 3, {kURLM1, kURLM2, kURLM3}}, | 230 {kEmbedder + kSep1 + kHostM1.substr(0, 1), 3, {kURLM1, kURLM2, kURLM3}}, |
| 233 {kChrome + kSeparator2 + kHostM1.substr(0, 2), 3, {kURLM1, kURLM2, kURLM3}}, | 231 {kEmbedder + kSep2 + kHostM1.substr(0, 2), 3, {kURLM1, kURLM2, kURLM3}}, |
| 234 {kChrome + kSeparator3 + kHostM1.substr(0, 3), 1, {kURLM1}}, | 232 {kEmbedder + kSep3 + kHostM1.substr(0, 3), 1, {kURLM1}}, |
| 235 {kChrome + kSeparator3 + kHostM2.substr(0, 3), 2, {kURLM2, kURLM3}}, | 233 {kEmbedder + kSep3 + kHostM2.substr(0, 3), 2, {kURLM2, kURLM3}}, |
| 236 {kChrome + kSeparator3 + kHostM1, 1, {kURLM1}}, | 234 {kEmbedder + kSep3 + kHostM1, 1, {kURLM1}}, |
| 237 {kChrome + kSeparator2 + kHostM2, 2, {kURLM2, kURLM3}}, | 235 {kEmbedder + kSep2 + kHostM2, 2, {kURLM2, kURLM3}}, |
| 238 {kChrome + kSeparator2 + kHostM3, 1, {kURLM3}}, | 236 {kEmbedder + kSep2 + kHostM3, 1, {kURLM3}}, |
| 239 }; | 237 }; |
| 240 | 238 |
| 241 RunTest(chrome_url_cases, arraysize(chrome_url_cases)); | 239 RunTest(test_cases, arraysize(test_cases)); |
| 242 } | 240 } |
| 243 | 241 |
| 244 TEST_F(BuiltinProviderTest, AboutBlank) { | 242 TEST_F(BuiltinProviderTest, AboutBlank) { |
| 245 const base::string16 kAbout = ASCIIToUTF16(url::kAboutScheme); | 243 const base::string16 kAbout = ASCIIToUTF16(url::kAboutScheme); |
| 246 const base::string16 kChrome = ASCIIToUTF16(content::kChromeUIScheme); | 244 const base::string16 kEmbedder = ASCIIToUTF16(kEmbedderAboutScheme); |
| 247 const base::string16 kAboutBlank = ASCIIToUTF16(url::kAboutBlankURL); | 245 const base::string16 kAboutBlank = ASCIIToUTF16(url::kAboutBlankURL); |
| 248 const base::string16 kBlank = ASCIIToUTF16("blank"); | 246 const base::string16 kBlank = ASCIIToUTF16("blank"); |
| 249 const base::string16 kSeparator1 = | 247 const base::string16 kSeparator1 = |
| 250 ASCIIToUTF16(url::kStandardSchemeSeparator); | 248 ASCIIToUTF16(url::kStandardSchemeSeparator); |
| 251 const base::string16 kSeparator2 = ASCIIToUTF16(":///"); | 249 const base::string16 kSeparator2 = ASCIIToUTF16(":///"); |
| 252 const base::string16 kSeparator3 = ASCIIToUTF16(";///"); | 250 const base::string16 kSeparator3 = ASCIIToUTF16(";///"); |
| 253 | 251 |
| 254 const GURL kURLBlob = GURL(kChrome + kSeparator1 + | 252 const GURL kURLBar = |
| 255 ASCIIToUTF16(content::kChromeUIBlobInternalsHost)); | 253 GURL(kEmbedder + kSeparator1 + ASCIIToUTF16(kHostBar)); |
| 256 const GURL kURLBlank = GURL(kAboutBlank); | 254 const GURL kURLBlank(kAboutBlank); |
| 257 | 255 |
| 258 TestData about_blank_cases[] = { | 256 TestData about_blank_cases[] = { |
| 259 // Typing an about:blank prefix should yield about:blank, among other URLs. | 257 // Typing an about:blank prefix should yield about:blank, among other URLs. |
| 260 {kAboutBlank.substr(0, 8), 2, {kURLBlank, kURLBlob}}, | 258 {kAboutBlank.substr(0, 7), 2, {kURLBlank, kURLBar}}, |
| 261 {kAboutBlank.substr(0, 9), 1, {kURLBlank}}, | 259 {kAboutBlank.substr(0, 8), 1, {kURLBlank}}, |
| 262 | 260 |
| 263 // Using any separator that is supported by fixup should yield about:blank. | 261 // Using any separator that is supported by fixup should yield about:blank. |
| 264 // For now, BuiltinProvider does not suggest url-what-you-typed matches for | 262 // For now, BuiltinProvider does not suggest url-what-you-typed matches for |
| 265 // for about:blank; check "about:blan" and "about;blan" substrings instead. | 263 // for about:blank; check "about:blan" and "about;blan" substrings instead. |
| 266 {kAbout + kSeparator2.substr(0, 1) + kBlank.substr(0, 4), 1, {kURLBlank}}, | 264 {kAbout + kSeparator2.substr(0, 1) + kBlank.substr(0, 4), 1, {kURLBlank}}, |
| 267 {kAbout + kSeparator2.substr(0, 2) + kBlank, 1, {kURLBlank}}, | 265 {kAbout + kSeparator2.substr(0, 2) + kBlank, 1, {kURLBlank}}, |
| 268 {kAbout + kSeparator2.substr(0, 3) + kBlank, 1, {kURLBlank}}, | 266 {kAbout + kSeparator2.substr(0, 3) + kBlank, 1, {kURLBlank}}, |
| 269 {kAbout + kSeparator2 + kBlank, 1, {kURLBlank}}, | 267 {kAbout + kSeparator2 + kBlank, 1, {kURLBlank}}, |
| 270 {kAbout + kSeparator3.substr(0, 1) + kBlank.substr(0, 4), 1, {kURLBlank}}, | 268 {kAbout + kSeparator3.substr(0, 1) + kBlank.substr(0, 4), 1, {kURLBlank}}, |
| 271 {kAbout + kSeparator3.substr(0, 2) + kBlank, 1, {kURLBlank}}, | 269 {kAbout + kSeparator3.substr(0, 2) + kBlank, 1, {kURLBlank}}, |
| 272 {kAbout + kSeparator3.substr(0, 3) + kBlank, 1, {kURLBlank}}, | 270 {kAbout + kSeparator3.substr(0, 3) + kBlank, 1, {kURLBlank}}, |
| 273 {kAbout + kSeparator3 + kBlank, 1, {kURLBlank}}, | 271 {kAbout + kSeparator3 + kBlank, 1, {kURLBlank}}, |
| 274 | 272 |
| 275 // Using the chrome scheme should not yield about:blank. | 273 // Using the embedder scheme should not yield about:blank. |
| 276 {kChrome + kSeparator1.substr(0, 1) + kBlank, 0, {}}, | 274 {kEmbedder + kSeparator1.substr(0, 1) + kBlank, 0, {}}, |
| 277 {kChrome + kSeparator1.substr(0, 2) + kBlank, 0, {}}, | 275 {kEmbedder + kSeparator1.substr(0, 2) + kBlank, 0, {}}, |
| 278 {kChrome + kSeparator1.substr(0, 3) + kBlank, 0, {}}, | 276 {kEmbedder + kSeparator1.substr(0, 3) + kBlank, 0, {}}, |
| 279 {kChrome + kSeparator1 + kBlank, 0, {}}, | 277 {kEmbedder + kSeparator1 + kBlank, 0, {}}, |
| 280 | 278 |
| 281 // Adding trailing text should not yield about:blank. | 279 // Adding trailing text should not yield about:blank. |
| 282 {kAboutBlank + ASCIIToUTF16("/"), 0, {}}, | 280 {kAboutBlank + ASCIIToUTF16("/"), 0, {}}, |
| 283 {kAboutBlank + ASCIIToUTF16("/p"), 0, {}}, | 281 {kAboutBlank + ASCIIToUTF16("/p"), 0, {}}, |
| 284 {kAboutBlank + ASCIIToUTF16("x"), 0, {}}, | 282 {kAboutBlank + ASCIIToUTF16("x"), 0, {}}, |
| 285 {kAboutBlank + ASCIIToUTF16("?q"), 0, {}}, | 283 {kAboutBlank + ASCIIToUTF16("?q"), 0, {}}, |
| 286 {kAboutBlank + ASCIIToUTF16("#r"), 0, {}}, | 284 {kAboutBlank + ASCIIToUTF16("#r"), 0, {}}, |
| 287 | 285 |
| 288 // Interrupting "blank" with conflicting text should not yield about:blank. | 286 // Interrupting "blank" with conflicting text should not yield about:blank. |
| 289 {kAboutBlank.substr(0, 9) + ASCIIToUTF16("/"), 0, {}}, | 287 {kAboutBlank.substr(0, 9) + ASCIIToUTF16("/"), 0, {}}, |
| 290 {kAboutBlank.substr(0, 9) + ASCIIToUTF16("/p"), 0, {}}, | 288 {kAboutBlank.substr(0, 9) + ASCIIToUTF16("/p"), 0, {}}, |
| 291 {kAboutBlank.substr(0, 9) + ASCIIToUTF16("x"), 0, {}}, | 289 {kAboutBlank.substr(0, 9) + ASCIIToUTF16("x"), 0, {}}, |
| 292 {kAboutBlank.substr(0, 9) + ASCIIToUTF16("?q"), 0, {}}, | 290 {kAboutBlank.substr(0, 9) + ASCIIToUTF16("?q"), 0, {}}, |
| 293 {kAboutBlank.substr(0, 9) + ASCIIToUTF16("#r"), 0, {}}, | 291 {kAboutBlank.substr(0, 9) + ASCIIToUTF16("#r"), 0, {}}, |
| 294 }; | 292 }; |
| 295 | 293 |
| 296 RunTest(about_blank_cases, arraysize(about_blank_cases)); | 294 RunTest(about_blank_cases, arraysize(about_blank_cases)); |
| 297 } | 295 } |
| 298 | 296 |
| 299 TEST_F(BuiltinProviderTest, DoesNotSupportMatchesOnFocus) { | 297 TEST_F(BuiltinProviderTest, DoesNotSupportMatchesOnFocus) { |
| 300 const AutocompleteInput input( | 298 const AutocompleteInput input( |
| 301 ASCIIToUTF16("chrome://s"), base::string16::npos, std::string(), GURL(), | 299 ASCIIToUTF16("chrome://m"), base::string16::npos, std::string(), GURL(), |
| 302 metrics::OmniboxEventProto::INVALID_SPEC, true, false, true, true, true, | 300 metrics::OmniboxEventProto::INVALID_SPEC, true, false, true, true, true, |
| 303 ChromeAutocompleteSchemeClassifier(NULL)); | 301 TestSchemeClassifier()); |
| 304 provider_->Start(input, false); | 302 provider_->Start(input, false); |
| 305 EXPECT_TRUE(provider_->matches().empty()); | 303 EXPECT_TRUE(provider_->matches().empty()); |
| 306 } | 304 } |
| 307 | 305 |
| 308 #if !defined(OS_ANDROID) | 306 TEST_F(BuiltinProviderTest, Subpages) { |
| 309 // Disabled on Android where we use native UI instead of chrome://settings. | 307 const base::string16 kSubpage = ASCIIToUTF16(kSubpageURL); |
| 310 TEST_F(BuiltinProviderTest, ChromeSettingsSubpages) { | 308 const base::string16 kPageOne = ASCIIToUTF16(kSubpageOne); |
| 311 // This makes assumptions about the chrome URLs listed by the BuiltinProvider. | 309 const base::string16 kPageTwo = ASCIIToUTF16(kSubpageTwo); |
| 312 // Currently they are derived from chrome::kChromeHostURLs[]. | 310 const base::string16 kPageThree = ASCIIToUTF16(kSubpageThree); |
| 313 const base::string16 kSettings = ASCIIToUTF16(chrome::kChromeUISettingsURL); | 311 const GURL kURLOne(kSubpage + kPageOne); |
| 314 const base::string16 kDefaultPage1 = ASCIIToUTF16(chrome::kAutofillSubPage); | 312 const GURL kURLTwo(kSubpage + kPageTwo); |
| 315 const base::string16 kDefaultPage2 = | 313 const GURL kURLThree(kSubpage + kPageThree); |
| 316 ASCIIToUTF16(chrome::kClearBrowserDataSubPage); | |
| 317 const GURL kDefaultURL1 = GURL(kSettings + kDefaultPage1); | |
| 318 const GURL kDefaultURL2 = GURL(kSettings + kDefaultPage2); | |
| 319 const base::string16 kPage1 = ASCIIToUTF16(chrome::kSearchEnginesSubPage); | |
| 320 const base::string16 kPage2 = ASCIIToUTF16(chrome::kSyncSetupSubPage); | |
| 321 const GURL kURL1 = GURL(kSettings + kPage1); | |
| 322 const GURL kURL2 = GURL(kSettings + kPage2); | |
| 323 | 314 |
| 324 TestData settings_subpage_cases[] = { | 315 TestData settings_subpage_cases[] = { |
| 325 // Typing the settings path should show settings and the first two subpages. | 316 // Typing the settings path should show settings and the first two subpages. |
| 326 {kSettings, 3, {GURL(kSettings), kDefaultURL1, kDefaultURL2}}, | 317 {kSubpage, 3, {GURL(kSubpage), kURLOne, kURLTwo}}, |
| 327 | 318 |
| 328 // Typing a subpage path should return the appropriate results. | 319 // Typing a subpage path should return the appropriate results. |
| 329 {kSettings + kPage1.substr(0, 1), 2, {kURL1, kURL2}}, | 320 {kSubpage + kPageTwo.substr(0, 1), 2, {kURLTwo, kURLThree}}, |
| 330 {kSettings + kPage1.substr(0, 2), 1, {kURL1}}, | 321 {kSubpage + kPageTwo.substr(0, 2), 1, {kURLTwo}}, |
| 331 {kSettings + kPage1.substr(0, kPage1.length() - 1), 1, {kURL1}}, | 322 {kSubpage + kPageThree.substr(0, kPageThree.length() - 1), |
| 332 {kSettings + kPage1, 1, {kURL1}}, | 323 1, {kURLThree}}, |
| 333 {kSettings + kPage2, 1, {kURL2}}, | 324 {kSubpage + kPageOne, 1, {kURLOne}}, |
| 325 {kSubpage + kPageTwo, 1, {kURLTwo}}, |
| 334 }; | 326 }; |
| 335 | 327 |
| 336 RunTest(settings_subpage_cases, arraysize(settings_subpage_cases)); | 328 RunTest(settings_subpage_cases, arraysize(settings_subpage_cases)); |
| 337 } | 329 } |
| 338 #endif | |
| OLD | NEW |