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 TestCase test_cases[] = { | |
|
Peter Kasting
2016/04/23 00:31:01
Nit: const
Alexander Yashkin
2016/04/23 08:40:20
Done.
| |
| 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. | |
| 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 (size_t i = 0; i < arraysize(test_cases); i++) { | |
|
Peter Kasting
2016/04/23 00:31:02
Nit: Use a range-based for loop
Alexander Yashkin
2016/04/23 08:40:20
Done.
| |
| 44 TestCase& test_case = test_cases[i]; | |
|
Peter Kasting
2016/04/23 00:31:02
Nit: const
Alexander Yashkin
2016/04/23 08:40:20
Done.
| |
| 45 const URLPrefix* prefix = | |
| 46 URLPrefix::BestURLPrefix(test_case.text, test_case.prefix_suffix); | |
| 47 if (!test_case.expected_prefix.empty()) { | |
|
Peter Kasting
2016/04/23 00:31:02
Nit: Remove ! and reverse arms (so "else" case doe
Alexander Yashkin
2016/04/23 08:40:20
Done.
| |
| 48 ASSERT_TRUE(prefix); | |
| 49 EXPECT_EQ(test_case.expected_prefix, prefix->prefix); | |
| 50 } else { | |
| 51 ASSERT_FALSE(prefix); | |
|
Peter Kasting
2016/04/23 00:31:01
Nit: Can be EXPECT
Alexander Yashkin
2016/04/23 08:40:20
Done.
| |
| 52 } | |
| 53 } | |
| 54 } | |
| OLD | NEW |