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

Side by Side Diff: chrome/browser/history/url_utils_unittest.cc

Issue 23477033: Implementing URL prefix match for history thumbnail cache. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Adding url_utils.*; adding chrome://thumb2; refactoring. Created 7 years, 3 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/history/url_utils.h"
6
7 #include "testing/gtest/include/gtest/gtest.h"
8
9 namespace history {
10
11 namespace {
12
13 TEST(UrlUtilsTest, CanonicalURLStringCompare) {
14 // Comprehensive test by comparing each pair in sorted list. O(n^2).
15 const char* sorted_list[] = {
16 "http://www.gogle.com/redirects_to_google",
17 "http://www.google.com",
18 "http://www.google.com/",
19 "http://www.google.com/?q",
20 "http://www.google.com/A",
21 "http://www.google.com/index.html",
22 "http://www.google.com/test",
23 "http://www.google.com/test?query",
24 "http://www.google.com/test?r=3",
25 "http://www.google.com/test#hash",
26 "http://www.google.com/test/?query",
27 "http://www.google.com/test/#hash",
28 "http://www.google.com/test/zzzzz",
29 "http://www.google.com/test$dollar",
30 "http://www.google.com/test%E9%9B%80",
31 "http://www.google.com/test-case",
32 "http://www.google.com:80/",
33 "https://www.google.com",
34 };
35 for (int i = 0; i < arraysize(sorted_list); ++i) {
36 EXPECT_FALSE(CanonicalURLStringCompare(sorted_list[i], sorted_list[i]))
37 << " for \"" << sorted_list[i] << "\" < \"" << sorted_list[i] << "\"";
38 // Every disjoint pair-wise comparison.
39 for (int j = i + 1; j < arraysize(sorted_list); ++j) {
40 EXPECT_TRUE(CanonicalURLStringCompare(sorted_list[i], sorted_list[j]))
41 << " for \"" << sorted_list[i] << "\" < \"" << sorted_list[j] << "\"";
42 EXPECT_FALSE(CanonicalURLStringCompare(sorted_list[j], sorted_list[i]))
43 << " for \"" << sorted_list[j] << "\" < \"" << sorted_list[i] << "\"";
44 }
45 }
46 }
47
48 TEST(UrlUtilsTest, UrlIsPrefix) {
49 struct {
50 const char* s1;
51 const char* s2;
52 } true_cases[] = {
53 {"http://www.google.com", "http://www.google.com"},
54 {"http://www.google.com/a/b", "http://www.google.com/a/b"},
55 {"http://www.google.com?test=3", "http://www.google.com/"},
56 {"http://www.google.com/#hash", "http://www.google.com/?q"},
57 {"http://www.google.com/", "http://www.google.com/test/with/dir/"},
58 {"http://www.google.com:360", "http://www.google.com:360/?q=1234"},
59 {"http://www.google.com:80", "http://www.google.com/gurl/is/smart"},
60 {"http://www.google.com:80/", "http://www.google.com/"},
61 {"http://www.google.com/test", "http://www.google.com/test/with/dir/"},
62 {"http://www.google.com/test/", "http://www.google.com/test/with/dir"},
63 {"http://www.google.com/test?", "http://www.google.com/test/with/dir/"},
64 };
65 for (int i = 0; i < arraysize(true_cases); ++i) {
66 EXPECT_TRUE(UrlIsPrefix(GURL(true_cases[i].s1), GURL(true_cases[i].s2)))
67 << " for true_cases[" << i << "]";
68 }
69 struct {
70 const char* s1;
71 const char* s2;
72 } false_cases[] = {
73 {"http://www.google.com/test", "http://www.google.com"},
74 {"http://www.google.com/a/b/", "http://www.google.com/a/b"}, // Arguable.
75 {"http://www.google.co", "http://www.google.com"},
76 {"http://google.com", "http://www.google.com"},
77 {"http://www.google.com", "https://www.google.com"},
78 {"http://www.google.com/path", "http://www.google.com:137/path"},
79 {"http://www.google.com/same/dir", "http://www.youtube.com/same/dir"},
80 {"http://www.google.com/te", "http://www.google.com/test"},
81 {"http://www.google.com/test", "http://www.google.com/test-bed"},
82 {"http://www.google.com/test-", "http://www.google.com/test?"},
83 };
84 for (int i = 0; i < arraysize(false_cases); ++i) {
85 EXPECT_FALSE(UrlIsPrefix(GURL(false_cases[i].s1), GURL(false_cases[i].s2)))
86 << " for false_cases[" << i << "]";
87 }
88 }
89
90 } // namespace
91
92 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698