| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 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 "components/omnibox/browser/url_prefix.h" |
| 6 |
| 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 |
| 10 namespace { |
| 11 struct TestCase { |
| 12 TestCase(const char* text, |
| 13 const char* prefix_suffix, |
| 14 const char* expected_prefix) |
| 15 : text(base::ASCIIToUTF16(text)), |
| 16 prefix_suffix(base::ASCIIToUTF16(prefix_suffix)), |
| 17 expected_prefix(base::ASCIIToUTF16(expected_prefix)) {} |
| 18 base::string16 text; |
| 19 base::string16 prefix_suffix; |
| 20 base::string16 expected_prefix; |
| 21 }; |
| 22 } // namespace |
| 23 |
| 24 TEST(URLPrefix, BestURLPrefix) { |
| 25 const TestCase test_cases[] = { |
| 26 // Lowercase test cases with empty prefix suffix. |
| 27 TestCase("https://www.yandex.ru", "", "https://www."), |
| 28 TestCase("http://www.yandex.ru", "", "http://www."), |
| 29 TestCase("ftp://www.yandex.ru", "", "ftp://www."), |
| 30 TestCase("https://yandex.ru", "", "https://"), |
| 31 TestCase("http://yandex.ru", "", "http://"), |
| 32 TestCase("ftp://yandex.ru", "", "ftp://"), |
| 33 |
| 34 // Mixed case test cases with empty prefix suffix. |
| 35 TestCase("HTTPS://www.yandex.ru", "", "https://www."), |
| 36 TestCase("http://WWW.yandex.ru", "", "http://www."), |
| 37 |
| 38 // Cases with non empty prefix suffix. |
| 39 TestCase("http://www.yandex.ru", "yan", "http://www."), |
| 40 TestCase("https://www.yandex.ru", "YaN", "https://www."), |
| 41 |
| 42 // Prefix suffix does not match. |
| 43 TestCase("https://www.yandex.ru", "index", ""), |
| 44 }; |
| 45 |
| 46 for (const TestCase& test_case : test_cases) { |
| 47 const URLPrefix* prefix = |
| 48 URLPrefix::BestURLPrefix(test_case.text, test_case.prefix_suffix); |
| 49 if (test_case.expected_prefix.empty()) { |
| 50 EXPECT_FALSE(prefix); |
| 51 } else { |
| 52 ASSERT_TRUE(prefix); |
| 53 EXPECT_EQ(test_case.expected_prefix, prefix->prefix); |
| 54 } |
| 55 } |
| 56 } |
| OLD | NEW |