| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/history/url_utils.h" | 5 #include "chrome/browser/history/url_utils.h" |
| 6 | 6 |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "url/gurl.h" | 8 #include "url/gurl.h" |
| 9 | 9 |
| 10 namespace history { | 10 namespace history { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 "http://www.google.com/test#hash", | 26 "http://www.google.com/test#hash", |
| 27 "http://www.google.com/test/?query", | 27 "http://www.google.com/test/?query", |
| 28 "http://www.google.com/test/#hash", | 28 "http://www.google.com/test/#hash", |
| 29 "http://www.google.com/test/zzzzz", | 29 "http://www.google.com/test/zzzzz", |
| 30 "http://www.google.com/test$dollar", | 30 "http://www.google.com/test$dollar", |
| 31 "http://www.google.com/test%E9%9B%80", | 31 "http://www.google.com/test%E9%9B%80", |
| 32 "http://www.google.com/test-case", | 32 "http://www.google.com/test-case", |
| 33 "http://www.google.com:80/", | 33 "http://www.google.com:80/", |
| 34 "https://www.google.com", | 34 "https://www.google.com", |
| 35 }; | 35 }; |
| 36 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(sorted_list); ++i) { | 36 for (size_t i = 0; i < arraysize(sorted_list); ++i) { |
| 37 EXPECT_FALSE(CanonicalURLStringCompare(sorted_list[i], sorted_list[i])) | 37 EXPECT_FALSE(CanonicalURLStringCompare(sorted_list[i], sorted_list[i])) |
| 38 << " for \"" << sorted_list[i] << "\" < \"" << sorted_list[i] << "\""; | 38 << " for \"" << sorted_list[i] << "\" < \"" << sorted_list[i] << "\""; |
| 39 // Every disjoint pair-wise comparison. | 39 // Every disjoint pair-wise comparison. |
| 40 for (size_t j = i + 1; j < ARRAYSIZE_UNSAFE(sorted_list); ++j) { | 40 for (size_t j = i + 1; j < arraysize(sorted_list); ++j) { |
| 41 EXPECT_TRUE(CanonicalURLStringCompare(sorted_list[i], sorted_list[j])) | 41 EXPECT_TRUE(CanonicalURLStringCompare(sorted_list[i], sorted_list[j])) |
| 42 << " for \"" << sorted_list[i] << "\" < \"" << sorted_list[j] << "\""; | 42 << " for \"" << sorted_list[i] << "\" < \"" << sorted_list[j] << "\""; |
| 43 EXPECT_FALSE(CanonicalURLStringCompare(sorted_list[j], sorted_list[i])) | 43 EXPECT_FALSE(CanonicalURLStringCompare(sorted_list[j], sorted_list[i])) |
| 44 << " for \"" << sorted_list[j] << "\" < \"" << sorted_list[i] << "\""; | 44 << " for \"" << sorted_list[j] << "\" < \"" << sorted_list[i] << "\""; |
| 45 } | 45 } |
| 46 } | 46 } |
| 47 } | 47 } |
| 48 | 48 |
| 49 TEST(HistoryUrlUtilsTest, HaveSameSchemeHostAndPort) { | 49 TEST(HistoryUrlUtilsTest, HaveSameSchemeHostAndPort) { |
| 50 struct { | 50 struct { |
| 51 const char* s1; | 51 const char* s1; |
| 52 const char* s2; | 52 const char* s2; |
| 53 } true_cases[] = { | 53 } true_cases[] = { |
| 54 {"http://www.google.com", "http://www.google.com"}, | 54 {"http://www.google.com", "http://www.google.com"}, |
| 55 {"http://www.google.com/a/b", "http://www.google.com/a/b"}, | 55 {"http://www.google.com/a/b", "http://www.google.com/a/b"}, |
| 56 {"http://www.google.com?test=3", "http://www.google.com/"}, | 56 {"http://www.google.com?test=3", "http://www.google.com/"}, |
| 57 {"http://www.google.com/#hash", "http://www.google.com/?q"}, | 57 {"http://www.google.com/#hash", "http://www.google.com/?q"}, |
| 58 {"http://www.google.com/", "http://www.google.com/test/with/dir/"}, | 58 {"http://www.google.com/", "http://www.google.com/test/with/dir/"}, |
| 59 {"http://www.google.com:360", "http://www.google.com:360/?q=1234"}, | 59 {"http://www.google.com:360", "http://www.google.com:360/?q=1234"}, |
| 60 {"http://www.google.com:80", "http://www.google.com/gurl/is/smart"}, | 60 {"http://www.google.com:80", "http://www.google.com/gurl/is/smart"}, |
| 61 {"http://www.google.com/test", "http://www.google.com/test/with/dir/"}, | 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/"}, | 62 {"http://www.google.com/test?", "http://www.google.com/test/with/dir/"}, |
| 63 }; | 63 }; |
| 64 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(true_cases); ++i) { | 64 for (size_t i = 0; i < arraysize(true_cases); ++i) { |
| 65 EXPECT_TRUE(HaveSameSchemeHostAndPort(GURL(true_cases[i].s1), | 65 EXPECT_TRUE(HaveSameSchemeHostAndPort(GURL(true_cases[i].s1), |
| 66 GURL(true_cases[i].s2))) | 66 GURL(true_cases[i].s2))) |
| 67 << " for true_cases[" << i << "]"; | 67 << " for true_cases[" << i << "]"; |
| 68 } | 68 } |
| 69 struct { | 69 struct { |
| 70 const char* s1; | 70 const char* s1; |
| 71 const char* s2; | 71 const char* s2; |
| 72 } false_cases[] = { | 72 } false_cases[] = { |
| 73 {"http://www.google.co", "http://www.google.com"}, | 73 {"http://www.google.co", "http://www.google.com"}, |
| 74 {"http://google.com", "http://www.google.com"}, | 74 {"http://google.com", "http://www.google.com"}, |
| 75 {"http://www.google.com", "https://www.google.com"}, | 75 {"http://www.google.com", "https://www.google.com"}, |
| 76 {"http://www.google.com/path", "http://www.google.com:137/path"}, | 76 {"http://www.google.com/path", "http://www.google.com:137/path"}, |
| 77 {"http://www.google.com/same/dir", "http://www.youtube.com/same/dir"}, | 77 {"http://www.google.com/same/dir", "http://www.youtube.com/same/dir"}, |
| 78 }; | 78 }; |
| 79 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(false_cases); ++i) { | 79 for (size_t i = 0; i < arraysize(false_cases); ++i) { |
| 80 EXPECT_FALSE(HaveSameSchemeHostAndPort(GURL(false_cases[i].s1), | 80 EXPECT_FALSE(HaveSameSchemeHostAndPort(GURL(false_cases[i].s1), |
| 81 GURL(false_cases[i].s2))) | 81 GURL(false_cases[i].s2))) |
| 82 << " for false_cases[" << i << "]"; | 82 << " for false_cases[" << i << "]"; |
| 83 } | 83 } |
| 84 } | 84 } |
| 85 | 85 |
| 86 TEST(HistoryUrlUtilsTest, IsPathPrefix) { | 86 TEST(HistoryUrlUtilsTest, IsPathPrefix) { |
| 87 struct { | 87 struct { |
| 88 const char* p1; | 88 const char* p1; |
| 89 const char* p2; | 89 const char* p2; |
| 90 } true_cases[] = { | 90 } true_cases[] = { |
| 91 {"", ""}, | 91 {"", ""}, |
| 92 {"", "/"}, | 92 {"", "/"}, |
| 93 {"/", "/"}, | 93 {"/", "/"}, |
| 94 {"/a/b", "/a/b"}, | 94 {"/a/b", "/a/b"}, |
| 95 {"/", "/test/with/dir/"}, | 95 {"/", "/test/with/dir/"}, |
| 96 {"/test", "/test/with/dir/"}, | 96 {"/test", "/test/with/dir/"}, |
| 97 {"/test/", "/test/with/dir"}, | 97 {"/test/", "/test/with/dir"}, |
| 98 }; | 98 }; |
| 99 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(true_cases); ++i) { | 99 for (size_t i = 0; i < arraysize(true_cases); ++i) { |
| 100 EXPECT_TRUE(IsPathPrefix(true_cases[i].p1, true_cases[i].p2)) | 100 EXPECT_TRUE(IsPathPrefix(true_cases[i].p1, true_cases[i].p2)) |
| 101 << " for true_cases[" << i << "]"; | 101 << " for true_cases[" << i << "]"; |
| 102 } | 102 } |
| 103 struct { | 103 struct { |
| 104 const char* p1; | 104 const char* p1; |
| 105 const char* p2; | 105 const char* p2; |
| 106 } false_cases[] = { | 106 } false_cases[] = { |
| 107 {"/test", ""}, | 107 {"/test", ""}, |
| 108 {"/", ""}, // Arguable. | 108 {"/", ""}, // Arguable. |
| 109 {"/a/b/", "/a/b"}, // Arguable. | 109 {"/a/b/", "/a/b"}, // Arguable. |
| 110 {"/te", "/test"}, | 110 {"/te", "/test"}, |
| 111 {"/test", "/test-bed"}, | 111 {"/test", "/test-bed"}, |
| 112 {"/test-", "/test"}, | 112 {"/test-", "/test"}, |
| 113 }; | 113 }; |
| 114 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(false_cases); ++i) { | 114 for (size_t i = 0; i < arraysize(false_cases); ++i) { |
| 115 EXPECT_FALSE(IsPathPrefix(false_cases[i].p1, false_cases[i].p2)) | 115 EXPECT_FALSE(IsPathPrefix(false_cases[i].p1, false_cases[i].p2)) |
| 116 << " for false_cases[" << i << "]"; | 116 << " for false_cases[" << i << "]"; |
| 117 } | 117 } |
| 118 } | 118 } |
| 119 | 119 |
| 120 TEST(HistoryUrlUtilsTest, ToggleHTTPAndHTTPS) { | 120 TEST(HistoryUrlUtilsTest, ToggleHTTPAndHTTPS) { |
| 121 EXPECT_EQ(GURL("http://www.google.com/test?q#r"), | 121 EXPECT_EQ(GURL("http://www.google.com/test?q#r"), |
| 122 ToggleHTTPAndHTTPS(GURL("https://www.google.com/test?q#r"))); | 122 ToggleHTTPAndHTTPS(GURL("https://www.google.com/test?q#r"))); |
| 123 EXPECT_EQ(GURL("https://www.google.com:137/"), | 123 EXPECT_EQ(GURL("https://www.google.com:137/"), |
| 124 ToggleHTTPAndHTTPS(GURL("http://www.google.com:137/"))); | 124 ToggleHTTPAndHTTPS(GURL("http://www.google.com:137/"))); |
| 125 EXPECT_EQ(GURL::EmptyGURL(), | 125 EXPECT_EQ(GURL::EmptyGURL(), |
| 126 ToggleHTTPAndHTTPS(GURL("ftp://www.google.com/"))); | 126 ToggleHTTPAndHTTPS(GURL("ftp://www.google.com/"))); |
| 127 } | 127 } |
| 128 | 128 |
| 129 } // namespace | 129 } // namespace |
| 130 | 130 |
| 131 } // namespace history | 131 } // namespace history |
| OLD | NEW |