Chromium Code Reviews| 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 // Mixed case test cases with empty prefix suffix. | |
|
Peter Kasting
2016/04/23 19:51:30
Nit: Blank line above this, as well as the two com
Alexander Yashkin
2016/04/24 07:18:50
Done.
| |
| 34 TestCase("HTTPS://www.yandex.ru", "", "https://www."), | |
| 35 TestCase("http://WWW.yandex.ru", "", "http://www."), | |
| 36 // Cases with non empty prefix suffix. | |
| 37 TestCase("http://www.yandex.ru", "yan", "http://www."), | |
| 38 TestCase("https://www.yandex.ru", "YaN", "https://www."), | |
| 39 // Prefix suffix does not match. | |
| 40 TestCase("https://www.yandex.ru", "index", ""), | |
| 41 }; | |
| 42 | |
| 43 for (const TestCase& test_case : test_cases) { | |
| 44 const URLPrefix* prefix = | |
| 45 URLPrefix::BestURLPrefix(test_case.text, test_case.prefix_suffix); | |
| 46 if (test_case.expected_prefix.empty()) { | |
| 47 EXPECT_FALSE(prefix); | |
| 48 } else { | |
| 49 ASSERT_TRUE(prefix); | |
| 50 EXPECT_EQ(test_case.expected_prefix, prefix->prefix); | |
| 51 } | |
| 52 } | |
| 53 } | |
| OLD | NEW |