Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(234)

Side by Side Diff: components/omnibox/browser/url_prefix_unittest.cc

Issue 1897403002: Optimize URLPrefix::BestURLPrefix (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixes after review, round 1 Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 }
OLDNEW
« components/omnibox/browser/url_prefix.cc ('K') | « components/omnibox/browser/url_prefix.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698