| OLD | NEW |
| 1 // Copyright (c) 2008, Google Inc. | 1 // Copyright (c) 2008, Google Inc. |
| 2 // All rights reserved. | 2 // All rights reserved. |
| 3 // | 3 // |
| 4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
| 5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
| 6 // met: | 6 // met: |
| 7 // | 7 // |
| 8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
| 9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
| 10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 | 29 |
| 30 // Basic tests that verify our KURL's interface behaves the same as the | 30 // Basic tests that verify our KURL's interface behaves the same as the |
| 31 // original KURL's. | 31 // original KURL's. |
| 32 | 32 |
| 33 #include "config.h" | 33 #include "config.h" |
| 34 | 34 |
| 35 #include "base/compiler_specific.h" | 35 #include "base/compiler_specific.h" |
| 36 #include "testing/gtest/include/gtest/gtest.h" | 36 #include "testing/gtest/include/gtest/gtest.h" |
| 37 #include "webkit/glue/glue_util.h" | 37 #include "webkit/glue/glue_util.h" |
| 38 | 38 |
| 39 MSVC_PUSH_WARNING_LEVEL(0); | |
| 40 | |
| 41 // This is because we have multiple headers called "CString.h" and KURL.cpp | |
| 42 // can grab the wrong one. | |
| 43 #include "third_party/WebKit/WebCore/platform/text/CString.h" | |
| 44 | |
| 45 // This evil preprocessor hack allows us to run both the original KURL and our | |
| 46 // KURL code at the same time regardless of build options. | |
| 47 | |
| 48 #define KURL_DECORATE_GLOBALS | |
| 49 | |
| 50 // Old KURL | |
| 51 #undef USE_GOOGLE_URL_LIBRARY | |
| 52 #define KURL WebKitKURL | |
| 53 #include "KURL.h" | 39 #include "KURL.h" |
| 54 #include "KURL.cpp" | |
| 55 | |
| 56 // Google's KURL | |
| 57 #undef KURL_h // So the header is re-included. | |
| 58 #undef KURL // Prevent warning on redefinition. | |
| 59 #define USE_GOOGLE_URL_LIBRARY | |
| 60 #define KURL GoogleKURL | |
| 61 #include "KURL.h" | |
| 62 #include "GKURL.cpp" | |
| 63 | |
| 64 MSVC_POP_WARNING(); | |
| 65 | 40 |
| 66 #undef LOG | 41 #undef LOG |
| 67 #include "base/basictypes.h" | 42 #include "base/basictypes.h" |
| 68 #include "base/string16.h" | 43 #include "base/string16.h" |
| 69 #include "base/string_util.h" | 44 #include "base/string_util.h" |
| 70 | 45 |
| 71 namespace { | 46 namespace { |
| 72 | 47 |
| 73 struct ComponentCase { | 48 struct ComponentCase { |
| 74 const char* url; | 49 const char* url; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 87 std::ostream& operator<<(std::ostream& out, | 62 std::ostream& operator<<(std::ostream& out, |
| 88 const WebCore::String& str) { | 63 const WebCore::String& str) { |
| 89 if (str.isEmpty()) | 64 if (str.isEmpty()) |
| 90 return out; | 65 return out; |
| 91 return out << WideToUTF8(std::wstring( | 66 return out << WideToUTF8(std::wstring( |
| 92 reinterpret_cast<const wchar_t*>(str.characters()), str.length())); | 67 reinterpret_cast<const wchar_t*>(str.characters()), str.length())); |
| 93 } | 68 } |
| 94 | 69 |
| 95 } // namespace | 70 } // namespace |
| 96 | 71 |
| 97 // Test the cases where we should be the same as WebKit's old KURL | 72 // Test the cases where we should be the same as WebKit's old KURL. |
| 98 TEST(GKURL, SameGetters) { | 73 TEST(GKURL, SameGetters) { |
| 99 const char* cases[] = { | 74 struct GetterCase { |
| 100 // Regular stuff | 75 const char* url; |
| 101 "http://www.google.com/foo/blah?bar=baz#ref", | 76 const char* protocol; |
| 102 "http://foo.com:1234/foo/bar/", | 77 const char* host; |
| 103 "http://www.google.com?#", | 78 int port; |
| 104 "https://me:pass@google.com:23#foo", | 79 const char* user; |
| 105 "javascript:hello!//world", | 80 const char* pass; |
| 81 const char* last_path_component; |
| 82 const char* query; |
| 83 const char* ref; |
| 84 bool has_ref; |
| 85 } cases[] = { |
| 86 {"http://www.google.com/foo/blah?bar=baz#ref", "http", "www.google.com", 0,
"", NULL, "blah", "?bar=baz", "ref", true}, |
| 87 {"http://foo.com:1234/foo/bar/", "http", "foo.com", 1234, "", NULL, "bar", "
", NULL, false}, |
| 88 {"http://www.google.com?#", "http", "www.google.com", 0, "", NULL, NULL, "?"
, "", true}, |
| 89 {"https://me:pass@google.com:23#foo", "https", "google.com", 23, "me", "pass
", NULL, "", "foo", true}, |
| 90 {"javascript:hello!//world", "javascript", "", 0, "", NULL, "world", "", NUL
L, false}, |
| 106 }; | 91 }; |
| 107 | 92 |
| 108 for (size_t i = 0; i < arraysize(cases); i++) { | 93 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { |
| 109 // UTF-8 | 94 // UTF-8 |
| 110 WebCore::WebKitKURL kurl(cases[i]); | 95 WebCore::KURL gurl(cases[i].url); |
| 111 WebCore::GoogleKURL gurl(cases[i]); | |
| 112 | 96 |
| 113 EXPECT_EQ(kurl.protocol(), gurl.protocol()); | 97 EXPECT_EQ(cases[i].protocol, gurl.protocol()); |
| 114 EXPECT_EQ(kurl.host(), gurl.host()); | 98 EXPECT_EQ(cases[i].host, gurl.host()); |
| 115 EXPECT_EQ(kurl.port(), gurl.port()); | 99 EXPECT_EQ(cases[i].port, gurl.port()); |
| 116 EXPECT_EQ(kurl.user(), gurl.user()); | 100 EXPECT_EQ(cases[i].user, gurl.user()); |
| 117 EXPECT_EQ(kurl.pass(), gurl.pass()); | 101 EXPECT_EQ(cases[i].pass, gurl.pass()); |
| 118 EXPECT_EQ(kurl.lastPathComponent(), gurl.lastPathComponent()); | 102 EXPECT_EQ(cases[i].last_path_component, gurl.lastPathComponent()); |
| 119 EXPECT_EQ(kurl.query(), gurl.query()); | 103 EXPECT_EQ(cases[i].query, gurl.query()); |
| 120 EXPECT_EQ(kurl.ref(), gurl.ref()); | 104 EXPECT_EQ(cases[i].ref, gurl.ref()); |
| 121 EXPECT_EQ(kurl.hasRef(), gurl.hasRef()); | 105 EXPECT_EQ(cases[i].has_ref, gurl.hasRef()); |
| 122 | 106 |
| 123 // UTF-16 | 107 // UTF-16 |
| 124 std::wstring wstr(UTF8ToWide(cases[i])); | 108 string16 wstr(UTF8ToUTF16(cases[i].url)); |
| 125 WebCore::String utf16( | 109 WebCore::String utf16( |
| 126 reinterpret_cast<const ::UChar*>(wstr.c_str()), | 110 reinterpret_cast<const ::UChar*>(wstr.c_str()), |
| 127 static_cast<int>(wstr.length())); | 111 static_cast<int>(wstr.length())); |
| 128 kurl = WebCore::WebKitKURL(utf16); | 112 gurl = WebCore::KURL(utf16); |
| 129 gurl = WebCore::GoogleKURL(utf16); | |
| 130 | 113 |
| 131 EXPECT_EQ(kurl.protocol(), gurl.protocol()); | 114 EXPECT_EQ(cases[i].protocol, gurl.protocol()); |
| 132 EXPECT_EQ(kurl.host(), gurl.host()); | 115 EXPECT_EQ(cases[i].host, gurl.host()); |
| 133 EXPECT_EQ(kurl.port(), gurl.port()); | 116 EXPECT_EQ(cases[i].port, gurl.port()); |
| 134 EXPECT_EQ(kurl.user(), gurl.user()); | 117 EXPECT_EQ(cases[i].user, gurl.user()); |
| 135 EXPECT_EQ(kurl.pass(), gurl.pass()); | 118 EXPECT_EQ(cases[i].pass, gurl.pass()); |
| 136 EXPECT_EQ(kurl.lastPathComponent(), gurl.lastPathComponent()); | 119 EXPECT_EQ(cases[i].last_path_component, gurl.lastPathComponent()); |
| 137 EXPECT_EQ(kurl.query(), gurl.query()); | 120 EXPECT_EQ(cases[i].query, gurl.query()); |
| 138 EXPECT_EQ(kurl.ref(), gurl.ref()); | 121 EXPECT_EQ(cases[i].ref, gurl.ref()); |
| 139 EXPECT_EQ(kurl.hasRef(), gurl.hasRef()); | 122 EXPECT_EQ(cases[i].has_ref, gurl.hasRef()); |
| 140 }; | 123 } |
| 141 } | 124 } |
| 142 | 125 |
| 143 // Test a few cases where we're different just to make sure we give reasonable | 126 // Test a few cases where we're different just to make sure we give reasonable |
| 144 // output. | 127 // output. |
| 145 TEST(GKURL, DifferentGetters) { | 128 TEST(GKURL, DifferentGetters) { |
| 146 ComponentCase cases[] = { | 129 ComponentCase cases[] = { |
| 147 // url protocol host port us
er pass path last_path query ref | 130 // url protocol host port us
er pass path last_path query ref |
| 148 | 131 |
| 149 // Old WebKit allows references and queries in what we call "path" URLs | 132 // Old WebKit allows references and queries in what we call "path" URLs |
| 150 // like javascript, so the path here will only consist of "hello!". | 133 // like javascript, so the path here will only consist of "hello!". |
| 151 {"javascript:hello!?#/\\world", "javascript", "", 0, ""
, NULL, "hello!?#/\\world", "world", "", NULL}, | 134 {"javascript:hello!?#/\\world", "javascript", "", 0, ""
, NULL, "hello!?#/\\world", "world", "", NULL}, |
| 152 | 135 |
| 153 // Old WebKit doesn't handle "parameters" in paths, so will | 136 // Old WebKit doesn't handle "parameters" in paths, so will |
| 154 // disagree with us about where the path is for this URL. | 137 // disagree with us about where the path is for this URL. |
| 155 {"http://a.com/hello;world", "http", "a.com", 0, ""
, NULL, "/hello;world", "hello", "", NULL}, | 138 {"http://a.com/hello;world", "http", "a.com", 0, ""
, NULL, "/hello;world", "hello", "", NULL}, |
| 156 | 139 |
| 157 // WebKit doesn't like UTF-8 or UTF-16 input. | 140 // WebKit doesn't like UTF-8 or UTF-16 input. |
| 158 {"http://\xe4\xbd\xa0\xe5\xa5\xbd\xe4\xbd\xa0\xe5\xa5\xbd/", "http", "xn--6q
qa088eba", 0, "", NULL, "/", NULL, "", NULL}, | 141 {"http://\xe4\xbd\xa0\xe5\xa5\xbd\xe4\xbd\xa0\xe5\xa5\xbd/", "http", "xn--6q
qa088eba", 0, "", NULL, "/", NULL, "", NULL}, |
| 159 | 142 |
| 160 // WebKit %-escapes non-ASCII characters in reference, but we don't. | 143 // WebKit %-escapes non-ASCII characters in reference, but we don't. |
| 161 {"http://www.google.com/foo/blah?bar=baz#\xce\xb1\xce\xb2", "http", "www.goo
gle.com", 0, "", NULL, "/foo/blah/", "blah", "?bar=baz", "\xce\xb1\xce\xb2"} | 144 {"http://www.google.com/foo/blah?bar=baz#\xce\xb1\xce\xb2", "http", "www.goo
gle.com", 0, "", NULL, "/foo/blah/", "blah", "?bar=baz", "\xce\xb1\xce\xb2"} |
| 162 }; | 145 }; |
| 163 | 146 |
| 164 for (size_t i = 0; i < arraysize(cases); i++) { | 147 for (size_t i = 0; i < arraysize(cases); i++) { |
| 165 WebCore::GoogleKURL gurl(cases[i].url); | 148 WebCore::KURL gurl(cases[i].url); |
| 166 | 149 |
| 167 EXPECT_EQ(cases[i].protocol, gurl.protocol()); | 150 EXPECT_EQ(cases[i].protocol, gurl.protocol()); |
| 168 EXPECT_EQ(cases[i].host, gurl.host()); | 151 EXPECT_EQ(cases[i].host, gurl.host()); |
| 169 EXPECT_EQ(cases[i].port, gurl.port()); | 152 EXPECT_EQ(cases[i].port, gurl.port()); |
| 170 EXPECT_EQ(cases[i].user, gurl.user()); | 153 EXPECT_EQ(cases[i].user, gurl.user()); |
| 171 EXPECT_EQ(cases[i].pass, gurl.pass()); | 154 EXPECT_EQ(cases[i].pass, gurl.pass()); |
| 172 EXPECT_EQ(cases[i].last_path, gurl.lastPathComponent()); | 155 EXPECT_EQ(cases[i].last_path, gurl.lastPathComponent()); |
| 173 EXPECT_EQ(cases[i].query, gurl.query()); | 156 EXPECT_EQ(cases[i].query, gurl.query()); |
| 174 // Want to compare UCS-16 refs (or to NULL). | 157 // Want to compare UCS-16 refs (or to NULL). |
| 175 if (cases[i].ref) { | 158 if (cases[i].ref) { |
| 176 EXPECT_EQ(webkit_glue::StdWStringToString(UTF8ToWide(cases[i].ref)), | 159 EXPECT_EQ(webkit_glue::StdWStringToString(UTF8ToWide(cases[i].ref)), |
| 177 gurl.ref()); | 160 gurl.ref()); |
| 178 } else { | 161 } else { |
| 179 EXPECT_TRUE(gurl.ref().isNull()); | 162 EXPECT_TRUE(gurl.ref().isNull()); |
| 180 } | 163 } |
| 181 } | 164 } |
| 182 } | 165 } |
| 183 | 166 |
| 184 // Ensures that both ASCII and UTF-8 canonical URLs are handled properly and we | 167 // Ensures that both ASCII and UTF-8 canonical URLs are handled properly and we |
| 185 // get the correct string object out. | 168 // get the correct string object out. |
| 186 TEST(GKURL, UTF8) { | 169 TEST(GKURL, UTF8) { |
| 187 const char ascii_url[] = "http://foo/bar#baz"; | 170 const char ascii_url[] = "http://foo/bar#baz"; |
| 188 WebCore::GoogleKURL ascii_gurl(ascii_url); | 171 WebCore::KURL ascii_gurl(ascii_url); |
| 189 EXPECT_TRUE(ascii_gurl.string() == WebCore::String(ascii_url)); | 172 EXPECT_TRUE(ascii_gurl.string() == WebCore::String(ascii_url)); |
| 190 | 173 |
| 191 // When the result is ASCII, we should get an ASCII String. Some | 174 // When the result is ASCII, we should get an ASCII String. Some |
| 192 // code depends on being able to compare the result of the .string() | 175 // code depends on being able to compare the result of the .string() |
| 193 // getter with another String, and the isASCIIness of the two | 176 // getter with another String, and the isASCIIness of the two |
| 194 // strings must match for these functions (like equalIgnoringCase). | 177 // strings must match for these functions (like equalIgnoringCase). |
| 195 EXPECT_TRUE(WebCore::equalIgnoringCase(ascii_gurl, | 178 EXPECT_TRUE(WebCore::equalIgnoringCase(ascii_gurl, |
| 196 WebCore::String(ascii_url))); | 179 WebCore::String(ascii_url))); |
| 197 | 180 |
| 198 // Reproduce code path in FrameLoader.cpp -- equalIgnoringCase implicitly | 181 // Reproduce code path in FrameLoader.cpp -- equalIgnoringCase implicitly |
| 199 // expects gkurl.protocol() to have been created as ascii. | 182 // expects gkurl.protocol() to have been created as ascii. |
| 200 WebCore::GoogleKURL mailto("mailto:foo@foo.com"); | 183 WebCore::KURL mailto("mailto:foo@foo.com"); |
| 201 EXPECT_TRUE(WebCore::equalIgnoringCase(mailto.protocol(), "mailto")); | 184 EXPECT_TRUE(WebCore::equalIgnoringCase(mailto.protocol(), "mailto")); |
| 202 | 185 |
| 203 const char utf8_url[] = "http://foo/bar#\xe4\xbd\xa0\xe5\xa5\xbd"; | 186 const char utf8_url[] = "http://foo/bar#\xe4\xbd\xa0\xe5\xa5\xbd"; |
| 204 WebCore::GoogleKURL utf8_gurl(utf8_url); | 187 WebCore::KURL utf8_gurl(utf8_url); |
| 205 | 188 |
| 206 EXPECT_TRUE(utf8_gurl.string() == | 189 EXPECT_TRUE(utf8_gurl.string() == |
| 207 webkit_glue::StdWStringToString(UTF8ToWide(utf8_url))); | 190 webkit_glue::StdWStringToString(UTF8ToWide(utf8_url))); |
| 208 } | 191 } |
| 209 | 192 |
| 210 TEST(GKURL, Setters) { | 193 TEST(GKURL, Setters) { |
| 211 // Replace the starting URL with the given components one at a time and | 194 // Replace the starting URL with the given components one at a time and |
| 212 // verify that we're always the same as the old KURL. | 195 // verify that we're always the same as the old KURL. |
| 213 // | 196 // |
| 214 // Note that old KURL won't canonicalize the default port away, so we | 197 // Note that old KURL won't canonicalize the default port away, so we |
| 215 // can't set setting the http port to "80" (or even "0"). | 198 // can't set setting the http port to "80" (or even "0"). |
| 216 // | 199 // |
| 217 // We also can't test clearing the query, since | 200 // We also can't test clearing the query. |
| 218 ComponentCase cases[] = { | 201 // |
| 219 // url protocol host p
ort user pass path last_path query ref | 202 // The format is every other row is a test, and the row that follows it is the |
| 220 {"http://www.google.com/", "https", "news.google.com", 8
888, "me", "pass", "/foo", NULL, "?q=asdf", "heehee"}, | 203 // expected result. |
| 221 {"https://me:pass@google.com:88/a?f#b", "http", "goo.com", 9
2, "", "", "/", NULL, NULL, ""}, | 204 struct ExpectedComponentCase { |
| 205 const char* url; |
| 206 const char* protocol; |
| 207 const char* host; |
| 208 const int port; |
| 209 const char* user; |
| 210 const char* pass; |
| 211 const char* path; |
| 212 const char* query; |
| 213 const char* ref; |
| 214 |
| 215 // The full expected URL with the given "set" applied. |
| 216 const char* expected_protocol; |
| 217 const char* expected_host; |
| 218 const char* expected_port; |
| 219 const char* expected_user; |
| 220 const char* expected_pass; |
| 221 const char* expected_path; |
| 222 const char* expected_query; |
| 223 const char* expected_ref; |
| 224 } cases[] = { |
| 225 // url protocol host p
ort user pass path query ref |
| 226 {"http://www.google.com/", "https", "news.google.com", 8
888, "me", "pass", "/foo", "?q=asdf", "heehee", |
| 227 "https://www.google.com/", |
| 228 "https://news.google
.com/", |
| 229 "
https://news.google.com:8888/", |
| 230
"https://me@news.google.com:8888/", |
| 231
"https://me:pass@news.google.com:8888/", |
| 232
"https://me:pass@news.google.com:8888/foo", |
| 233
"https://me:pass@news.google.com:8888/foo?q=a
sdf", |
| 234
"https://me:pass@news.google.com:8
888/foo?q=asdf#heehee"}, |
| 235 |
| 236 {"https://me:pass@google.com:88/a?f#b", "http", "goo.com", 9
2, "", "", "/", NULL, "", |
| 237 "http://me:pass@google.com:88/a?f#
b", |
| 238 "http://me:pass@goo.
com:88/a?f#b", |
| 239 "
http://me:pass@goo.com:92/a?f#b", |
| 240
"http://:pass@goo.com:92/a?f#b", |
| 241
"http://goo.com:92/a?f#b", |
| 242
"http://goo.com:92/?f#b", |
| 243
"http://goo.com:92/#b", |
| 244
"https://goo.com:92/"}, |
| 222 }; | 245 }; |
| 223 | 246 |
| 224 for (size_t i = 0; i < arraysize(cases); i++) { | 247 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { |
| 225 WebCore::GoogleKURL gurl(cases[i].url); | 248 WebCore::KURL gurl(cases[i].url); |
| 226 WebCore::WebKitKURL kurl(cases[i].url); | |
| 227 | 249 |
| 228 EXPECT_EQ(kurl.string(), gurl.string()); | 250 gurl.setProtocol(cases[i].protocol); |
| 251 EXPECT_STREQ(cases[i].expected_protocol, gurl.string().utf8().data()); |
| 229 | 252 |
| 230 kurl.setProtocol(cases[i].protocol); | 253 gurl.setHost(cases[i].host); |
| 231 gurl.setProtocol(cases[i].protocol); | 254 EXPECT_STREQ(cases[i].expected_host, gurl.string().utf8().data()); |
| 232 EXPECT_EQ(kurl.string(), gurl.string()); | |
| 233 | 255 |
| 234 kurl.setHost(cases[i].host); | 256 gurl.setPort(cases[i].port); |
| 235 gurl.setHost(cases[i].host); | 257 EXPECT_STREQ(cases[i].expected_port, gurl.string().utf8().data()); |
| 236 EXPECT_EQ(kurl.string(), gurl.string()); | |
| 237 | 258 |
| 238 kurl.setPort(cases[i].port); | 259 gurl.setUser(cases[i].user); |
| 239 gurl.setPort(cases[i].port); | 260 EXPECT_STREQ(cases[i].expected_user, gurl.string().utf8().data()); |
| 240 EXPECT_EQ(kurl.string(), gurl.string()); | |
| 241 | 261 |
| 242 kurl.setUser(cases[i].user); | 262 gurl.setPass(cases[i].pass); |
| 243 gurl.setUser(cases[i].user); | 263 EXPECT_STREQ(cases[i].expected_pass, gurl.string().utf8().data()); |
| 244 EXPECT_EQ(kurl.string(), gurl.string()); | |
| 245 | 264 |
| 246 kurl.setPass(cases[i].pass); | 265 gurl.setPath(cases[i].path); |
| 247 gurl.setPass(cases[i].pass); | 266 EXPECT_STREQ(cases[i].expected_path, gurl.string().utf8().data()); |
| 248 EXPECT_EQ(kurl.string(), gurl.string()); | |
| 249 | 267 |
| 250 kurl.setPath(cases[i].path); | |
| 251 gurl.setPath(cases[i].path); | |
| 252 EXPECT_EQ(kurl.string(), gurl.string()); | |
| 253 | |
| 254 kurl.setQuery(cases[i].query); | |
| 255 gurl.setQuery(cases[i].query); | 268 gurl.setQuery(cases[i].query); |
| 256 EXPECT_EQ(kurl.string(), gurl.string()); | 269 EXPECT_STREQ(cases[i].expected_query, gurl.string().utf8().data()); |
| 257 | 270 |
| 258 // Refs are tested below. On the Safari 3.1 branch, we don't match their | 271 // Refs are tested below. On the Safari 3.1 branch, we don't match their |
| 259 // KURL since we integrated a fix from their trunk. | 272 // KURL since we integrated a fix from their trunk. |
| 260 } | 273 } |
| 261 } | 274 } |
| 262 | 275 |
| 263 // Tests that KURL::decodeURLEscapeSequences works as expected | 276 // Tests that KURL::decodeURLEscapeSequences works as expected |
| 277 #ifdef USE_GOOGLE_URL_LIBRARY |
| 264 TEST(GKURL, Decode) { | 278 TEST(GKURL, Decode) { |
| 265 const char* decode_cases[] = { | 279 struct DecodeCase { |
| 266 "hello, world", | 280 const char* input; |
| 267 "%01%02%03%04%05%06%07%08%09%0a%0B%0C%0D%0e%0f/", | 281 const char* output; |
| 268 "%10%11%12%13%14%15%16%17%18%19%1a%1B%1C%1D%1e%1f/", | 282 } decode_cases[] = { |
| 269 "%20%21%22%23%24%25%26%27%28%29%2a%2B%2C%2D%2e%2f/", | 283 {"hello, world", "hello, world"}, |
| 270 "%30%31%32%33%34%35%36%37%38%39%3a%3B%3C%3D%3e%3f/", | 284 {"%01%02%03%04%05%06%07%08%09%0a%0B%0C%0D%0e%0f/", "\x01\x02\x03\x04\x05\x06
\x07\x08\x09\x0a\x0B\x0C\x0D\x0e\x0f/"}, |
| 271 "%40%41%42%43%44%45%46%47%48%49%4a%4B%4C%4D%4e%4f/", | 285 {"%10%11%12%13%14%15%16%17%18%19%1a%1B%1C%1D%1e%1f/", "\x10\x11\x12\x13\x14\
x15\x16\x17\x18\x19\x1a\x1B\x1C\x1D\x1e\x1f/"}, |
| 272 "%50%51%52%53%54%55%56%57%58%59%5a%5B%5C%5D%5e%5f/", | 286 {"%20%21%22%23%24%25%26%27%28%29%2a%2B%2C%2D%2e%2f/", " !\"#$%&'()*+,-.//"}, |
| 273 "%60%61%62%63%64%65%66%67%68%69%6a%6B%6C%6D%6e%6f/", | 287 {"%30%31%32%33%34%35%36%37%38%39%3a%3B%3C%3D%3e%3f/", "0123456789:;<=>?/"}, |
| 274 "%70%71%72%73%74%75%76%77%78%79%7a%7B%7C%7D%7e%7f/", | 288 {"%40%41%42%43%44%45%46%47%48%49%4a%4B%4C%4D%4e%4f/", "@ABCDEFGHIJKLMNO/"}, |
| 289 {"%50%51%52%53%54%55%56%57%58%59%5a%5B%5C%5D%5e%5f/", "PQRSTUVWXYZ[\\]^_/"}, |
| 290 {"%60%61%62%63%64%65%66%67%68%69%6a%6B%6C%6D%6e%6f/", "`abcdefghijklmno/"}, |
| 291 {"%70%71%72%73%74%75%76%77%78%79%7a%7B%7C%7D%7e%7f/", "pqrstuvwxyz{|}~\x7f/"
}, |
| 275 // Test un-UTF-8-ization. | 292 // Test un-UTF-8-ization. |
| 276 "%e4%bd%a0%e5%a5%bd", | 293 {"%e4%bd%a0%e5%a5%bd", "\xe4\xbd\xa0\xe5\xa5\xbd"}, |
| 277 }; | 294 }; |
| 278 | 295 |
| 279 for (size_t i = 0; i < arraysize(decode_cases); i++) { | 296 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(decode_cases); i++) { |
| 280 WebCore::String input(decode_cases[i]); | 297 WebCore::String input(decode_cases[i].input); |
| 281 WebCore::String webkit = WebCore::WebKitKURL::decodeURLEscapeSequences(input
); | 298 WebCore::String str = WebCore::decodeURLEscapeSequences(input); |
| 282 WebCore::String google = WebCore::GoogleKURL::decodeURLEscapeSequences(input
); | 299 EXPECT_STREQ(decode_cases[i].output, str.utf8().data()); |
| 283 EXPECT_TRUE(webkit == google); | |
| 284 } | 300 } |
| 285 | 301 |
| 286 // Our decode should not decode %00 | 302 // Our decode should not decode %00 |
| 287 WebCore::String zero = WebCore::GoogleKURL::decodeURLEscapeSequences("%00"); | 303 WebCore::String zero = WebCore::decodeURLEscapeSequences("%00"); |
| 288 EXPECT_STREQ("%00", zero.utf8().data()); | 304 EXPECT_STREQ("%00", zero.utf8().data()); |
| 289 | 305 |
| 290 // Test the error behavior for invalid UTF-8 (we differ from WebKit here). | 306 // Test the error behavior for invalid UTF-8 (we differ from WebKit here). |
| 291 WebCore::String invalid = WebCore::GoogleKURL::decodeURLEscapeSequences( | 307 WebCore::String invalid = WebCore::decodeURLEscapeSequences( |
| 292 "%e4%a0%e5%a5%bd"); | 308 "%e4%a0%e5%a5%bd"); |
| 293 char16 invalid_expected_helper[4] = { 0x00e4, 0x00a0, 0x597d, 0 }; | 309 char16 invalid_expected_helper[4] = { 0x00e4, 0x00a0, 0x597d, 0 }; |
| 294 WebCore::String invalid_expected( | 310 WebCore::String invalid_expected( |
| 295 reinterpret_cast<const ::UChar*>(invalid_expected_helper), | 311 reinterpret_cast<const ::UChar*>(invalid_expected_helper), |
| 296 3); | 312 3); |
| 297 EXPECT_EQ(invalid_expected, invalid); | 313 EXPECT_EQ(invalid_expected, invalid); |
| 298 } | 314 } |
| 315 #endif |
| 299 | 316 |
| 300 TEST(GKURL, Encode) { | 317 TEST(GKURL, Encode) { |
| 301 // Also test that it gets converted to UTF-8 properly. | 318 // Also test that it gets converted to UTF-8 properly. |
| 302 char16 wide_input_helper[3] = { 0x4f60, 0x597d, 0 }; | 319 char16 wide_input_helper[3] = { 0x4f60, 0x597d, 0 }; |
| 303 WebCore::String wide_input( | 320 WebCore::String wide_input( |
| 304 reinterpret_cast<const ::UChar*>(wide_input_helper), 2); | 321 reinterpret_cast<const ::UChar*>(wide_input_helper), 2); |
| 305 WebCore::String wide_reference("\xe4\xbd\xa0\xe5\xa5\xbd", 6); | 322 WebCore::String wide_reference("\xe4\xbd\xa0\xe5\xa5\xbd", 6); |
| 306 WebCore::String wide_output = | 323 WebCore::String wide_output = |
| 307 WebCore::GoogleKURL::encodeWithURLEscapeSequences(wide_input); | 324 WebCore::encodeWithURLEscapeSequences(wide_input); |
| 308 EXPECT_EQ(wide_reference, wide_output); | 325 EXPECT_EQ(wide_reference, wide_output); |
| 309 | 326 |
| 310 // Our encode only escapes NULLs for safety (see the implementation for | 327 // Our encode only escapes NULLs for safety (see the implementation for |
| 311 // more), so we only bother to test a few cases. | 328 // more), so we only bother to test a few cases. |
| 312 WebCore::String input( | 329 WebCore::String input( |
| 313 "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f", 16); | 330 "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f", 16); |
| 314 WebCore::String reference( | 331 WebCore::String reference( |
| 315 "%00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f", 18); | 332 "%00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f", 18); |
| 316 WebCore::String output = WebCore::GoogleKURL::encodeWithURLEscapeSequences(inp
ut); | 333 WebCore::String output = WebCore::encodeWithURLEscapeSequences(input); |
| 317 EXPECT_EQ(reference, output); | 334 EXPECT_EQ(reference, output); |
| 318 } | 335 } |
| 319 | 336 |
| 320 TEST(GKURL, ResolveEmpty) { | 337 TEST(GKURL, ResolveEmpty) { |
| 321 WebCore::GoogleKURL empty_base; | 338 WebCore::KURL empty_base; |
| 322 | 339 |
| 323 // WebKit likes to be able to resolve absolute input agains empty base URLs, | 340 // WebKit likes to be able to resolve absolute input agains empty base URLs, |
| 324 // which would normally be invalid since the base URL is invalid. | 341 // which would normally be invalid since the base URL is invalid. |
| 325 const char abs[] = "http://www.google.com/"; | 342 const char abs[] = "http://www.google.com/"; |
| 326 WebCore::GoogleKURL resolve_abs(empty_base, abs); | 343 WebCore::KURL resolve_abs(empty_base, abs); |
| 327 EXPECT_TRUE(resolve_abs.isValid()); | 344 EXPECT_TRUE(resolve_abs.isValid()); |
| 328 EXPECT_STREQ(abs, resolve_abs.string().utf8().data()); | 345 EXPECT_STREQ(abs, resolve_abs.string().utf8().data()); |
| 329 | 346 |
| 330 // Resolving a non-relative URL agains the empty one should still error. | 347 // Resolving a non-relative URL agains the empty one should still error. |
| 331 const char rel[] = "foo.html"; | 348 const char rel[] = "foo.html"; |
| 332 WebCore::GoogleKURL resolve_err(empty_base, rel); | 349 WebCore::KURL resolve_err(empty_base, rel); |
| 333 EXPECT_FALSE(resolve_err.isValid()); | 350 EXPECT_FALSE(resolve_err.isValid()); |
| 334 } | 351 } |
| 335 | 352 |
| 336 // WebKit will make empty URLs and set components on them. GURL doesn't allow | 353 // WebKit will make empty URLs and set components on them. GURL doesn't allow |
| 337 // replacements on invalid URLs, but here we do. | 354 // replacements on invalid URLs, but here we do. |
| 338 TEST(GKURL, ReplaceInvalid) { | 355 TEST(GKURL, ReplaceInvalid) { |
| 339 WebCore::GoogleKURL gurl; | 356 WebCore::KURL gurl; |
| 340 WebCore::WebKitKURL kurl; | |
| 341 | 357 |
| 342 EXPECT_EQ(kurl.isValid(), gurl.isValid()); | 358 EXPECT_FALSE(gurl.isValid()); |
| 343 EXPECT_EQ(kurl.isEmpty(), gurl.isEmpty()); | 359 EXPECT_TRUE(gurl.isEmpty()); |
| 344 EXPECT_STREQ(kurl.string().utf8().data(), gurl.string().utf8().data()); | 360 EXPECT_STREQ("", gurl.string().utf8().data()); |
| 345 | 361 |
| 346 gurl.setProtocol("http"); | 362 gurl.setProtocol("http"); |
| 347 kurl.setProtocol("http"); | |
| 348 // GKURL will say that a URL with just a scheme is invalid, KURL will not. | 363 // GKURL will say that a URL with just a scheme is invalid, KURL will not. |
| 349 EXPECT_TRUE(kurl.isValid()); | 364 #ifdef USE_GOOGLE_URL_LIBRARY |
| 350 EXPECT_FALSE(gurl.isValid()); | 365 EXPECT_FALSE(gurl.isValid()); |
| 351 EXPECT_EQ(kurl.isEmpty(), gurl.isEmpty()); | 366 #else |
| 352 // At this point, the strings will *not* be equal, we do things slightly | 367 EXPECT_TRUE(gurl.isValid()); |
| 353 // differently if there is only a scheme. We check the results here to make | 368 #endif |
| 354 // it more obvious what is going on, but it shouldn't be a big deal if these | 369 EXPECT_FALSE(gurl.isEmpty()); |
| 355 // change. | 370 // At this point, we do things slightly differently if there is only a scheme. |
| 371 // We check the results here to make it more obvious what is going on, but it |
| 372 // shouldn't be a big deal if these change. |
| 373 #ifdef USE_GOOGLE_URL_LIBRARY |
| 356 EXPECT_STREQ("http:", gurl.string().utf8().data()); | 374 EXPECT_STREQ("http:", gurl.string().utf8().data()); |
| 357 EXPECT_STREQ("http:/", kurl.string().utf8().data()); | 375 #else |
| 376 EXPECT_STREQ("http:/", gurl.string().utf8().data()); |
| 377 #endif |
| 358 | 378 |
| 359 gurl.setHost("www.google.com"); | 379 gurl.setHost("www.google.com"); |
| 360 kurl.setHost("www.google.com"); | 380 EXPECT_TRUE(gurl.isValid()); |
| 361 EXPECT_EQ(kurl.isValid(), gurl.isValid()); | 381 EXPECT_FALSE(gurl.isEmpty()); |
| 362 EXPECT_EQ(kurl.isEmpty(), gurl.isEmpty()); | 382 EXPECT_STREQ("http://www.google.com/", gurl.string().utf8().data()); |
| 363 EXPECT_STREQ(kurl.string().utf8().data(), gurl.string().utf8().data()); | |
| 364 | 383 |
| 365 gurl.setPort(8000); | 384 gurl.setPort(8000); |
| 366 kurl.setPort(8000); | 385 EXPECT_TRUE(gurl.isValid()); |
| 367 EXPECT_EQ(kurl.isValid(), gurl.isValid()); | 386 EXPECT_FALSE(gurl.isEmpty()); |
| 368 EXPECT_EQ(kurl.isEmpty(), gurl.isEmpty()); | 387 EXPECT_STREQ("http://www.google.com:8000/", gurl.string().utf8().data()); |
| 369 EXPECT_STREQ(kurl.string().utf8().data(), gurl.string().utf8().data()); | |
| 370 | 388 |
| 371 gurl.setPath("/favicon.ico"); | 389 gurl.setPath("/favicon.ico"); |
| 372 kurl.setPath("/favicon.ico"); | 390 EXPECT_TRUE(gurl.isValid()); |
| 373 EXPECT_EQ(kurl.isValid(), gurl.isValid()); | 391 EXPECT_FALSE(gurl.isEmpty()); |
| 374 EXPECT_EQ(kurl.isEmpty(), gurl.isEmpty()); | |
| 375 EXPECT_STREQ(kurl.string().utf8().data(), gurl.string().utf8().data()); | |
| 376 EXPECT_STREQ("http://www.google.com:8000/favicon.ico", gurl.string().utf8().da
ta()); | 392 EXPECT_STREQ("http://www.google.com:8000/favicon.ico", gurl.string().utf8().da
ta()); |
| 377 | 393 |
| 378 // Now let's test that giving an invalid replacement still fails. | 394 // Now let's test that giving an invalid replacement still fails. |
| 395 #ifdef USE_GOOGLE_URL_LIBRARY |
| 379 gurl.setProtocol("f/sj#@"); | 396 gurl.setProtocol("f/sj#@"); |
| 380 EXPECT_FALSE(gurl.isValid()); | 397 EXPECT_FALSE(gurl.isValid()); |
| 398 #endif |
| 381 } | 399 } |
| 382 | 400 |
| 383 TEST(GKURL, Path) { | 401 TEST(GKURL, Path) { |
| 384 const char initial[] = "http://www.google.com/path/foo"; | 402 const char initial[] = "http://www.google.com/path/foo"; |
| 385 WebCore::GoogleKURL gurl(initial); | 403 WebCore::KURL gurl(initial); |
| 386 WebCore::WebKitKURL kurl(initial); | |
| 387 | 404 |
| 388 // Clear by setting a NULL string. | 405 // Clear by setting a NULL string. |
| 389 WebCore::String null_string; | 406 WebCore::String null_string; |
| 390 EXPECT_TRUE(null_string.isNull()); | 407 EXPECT_TRUE(null_string.isNull()); |
| 391 gurl.setPath(null_string); | 408 gurl.setPath(null_string); |
| 392 kurl.setPath(null_string); | |
| 393 EXPECT_STREQ(kurl.string().utf8().data(), gurl.string().utf8().data()); | |
| 394 EXPECT_STREQ("http://www.google.com/", gurl.string().utf8().data()); | 409 EXPECT_STREQ("http://www.google.com/", gurl.string().utf8().data()); |
| 395 } | 410 } |
| 396 | 411 |
| 397 // Test that setting the query to different things works. Thq query is handled | 412 // Test that setting the query to different things works. Thq query is handled |
| 398 // a littler differently than some of the other components. | 413 // a littler differently than some of the other components. |
| 399 TEST(GKURL, Query) { | 414 TEST(GKURL, Query) { |
| 400 const char initial[] = "http://www.google.com/search?q=awesome"; | 415 const char initial[] = "http://www.google.com/search?q=awesome"; |
| 401 WebCore::GoogleKURL gurl(initial); | 416 WebCore::KURL gurl(initial); |
| 402 WebCore::WebKitKURL kurl(initial); | |
| 403 | 417 |
| 404 // Clear by setting a NULL string. | 418 // Clear by setting a NULL string. |
| 405 WebCore::String null_string; | 419 WebCore::String null_string; |
| 406 EXPECT_TRUE(null_string.isNull()); | 420 EXPECT_TRUE(null_string.isNull()); |
| 407 gurl.setQuery(null_string); | 421 gurl.setQuery(null_string); |
| 408 kurl.setQuery(null_string); | 422 EXPECT_STREQ("http://www.google.com/search", gurl.string().utf8().data()); |
| 409 EXPECT_STREQ(kurl.string().utf8().data(), gurl.string().utf8().data()); | |
| 410 | 423 |
| 411 // Clear by setting an empty string. | 424 // Clear by setting an empty string. |
| 412 gurl = WebCore::GoogleKURL(initial); | 425 gurl = WebCore::KURL(initial); |
| 413 kurl = WebCore::WebKitKURL(initial); | |
| 414 WebCore::String empty_string(""); | 426 WebCore::String empty_string(""); |
| 415 EXPECT_FALSE(empty_string.isNull()); | 427 EXPECT_FALSE(empty_string.isNull()); |
| 416 gurl.setQuery(empty_string); | 428 gurl.setQuery(empty_string); |
| 417 kurl.setQuery(empty_string); | 429 EXPECT_STREQ("http://www.google.com/search?", gurl.string().utf8().data()); |
| 418 EXPECT_STREQ(kurl.string().utf8().data(), gurl.string().utf8().data()); | |
| 419 | 430 |
| 420 // Set with something that begins in a question mark. | 431 // Set with something that begins in a question mark. |
| 421 const char question[] = "?foo=bar"; | 432 const char question[] = "?foo=bar"; |
| 422 gurl.setQuery(question); | 433 gurl.setQuery(question); |
| 423 kurl.setQuery(question); | 434 EXPECT_STREQ("http://www.google.com/search?foo=bar", |
| 424 EXPECT_STREQ(kurl.string().utf8().data(), gurl.string().utf8().data()); | 435 gurl.string().utf8().data()); |
| 425 | 436 |
| 426 // Set with something that doesn't begin in a question mark. | 437 // Set with something that doesn't begin in a question mark. |
| 427 const char query[] = "foo=bar"; | 438 const char query[] = "foo=bar"; |
| 428 gurl.setQuery(query); | 439 gurl.setQuery(query); |
| 429 kurl.setQuery(query); | 440 EXPECT_STREQ("http://www.google.com/search?foo=bar", |
| 430 EXPECT_STREQ(kurl.string().utf8().data(), gurl.string().utf8().data()); | 441 gurl.string().utf8().data()); |
| 431 } | 442 } |
| 432 | 443 |
| 433 TEST(GKURL, Ref) { | 444 TEST(GKURL, Ref) { |
| 434 WebCore::GoogleKURL gurl("http://foo/bar#baz"); | 445 WebCore::KURL gurl("http://foo/bar#baz"); |
| 435 | 446 |
| 436 // Basic ref setting. | 447 // Basic ref setting. |
| 437 WebCore::GoogleKURL cur("http://foo/bar"); | 448 WebCore::KURL cur("http://foo/bar"); |
| 438 cur.setRef("asdf"); | 449 cur.setRef("asdf"); |
| 439 EXPECT_STREQ("http://foo/bar#asdf", cur.string().utf8().data()); | 450 EXPECT_STREQ("http://foo/bar#asdf", cur.string().utf8().data()); |
| 440 cur = gurl; | 451 cur = gurl; |
| 441 cur.setRef("asdf"); | 452 cur.setRef("asdf"); |
| 442 EXPECT_STREQ("http://foo/bar#asdf", cur.string().utf8().data()); | 453 EXPECT_STREQ("http://foo/bar#asdf", cur.string().utf8().data()); |
| 443 | 454 |
| 444 // Setting a ref to the empty string will set it to "#". | 455 // Setting a ref to the empty string will set it to "#". |
| 445 cur = WebCore::GoogleKURL("http://foo/bar"); | 456 cur = WebCore::KURL("http://foo/bar"); |
| 446 cur.setRef(""); | 457 cur.setRef(""); |
| 447 EXPECT_STREQ("http://foo/bar#", cur.string().utf8().data()); | 458 EXPECT_STREQ("http://foo/bar#", cur.string().utf8().data()); |
| 448 cur = gurl; | 459 cur = gurl; |
| 449 cur.setRef(""); | 460 cur.setRef(""); |
| 450 EXPECT_STREQ("http://foo/bar#", cur.string().utf8().data()); | 461 EXPECT_STREQ("http://foo/bar#", cur.string().utf8().data()); |
| 451 | 462 |
| 452 // Setting the ref to the null string will clear it altogether. | 463 // Setting the ref to the null string will clear it altogether. |
| 453 cur = WebCore::GoogleKURL("http://foo/bar"); | 464 cur = WebCore::KURL("http://foo/bar"); |
| 454 cur.setRef(WebCore::String()); | 465 cur.setRef(WebCore::String()); |
| 455 EXPECT_STREQ("http://foo/bar", cur.string().utf8().data()); | 466 EXPECT_STREQ("http://foo/bar", cur.string().utf8().data()); |
| 456 cur = gurl; | 467 cur = gurl; |
| 457 cur.setRef(WebCore::String()); | 468 cur.setRef(WebCore::String()); |
| 458 EXPECT_STREQ("http://foo/bar", cur.string().utf8().data()); | 469 EXPECT_STREQ("http://foo/bar", cur.string().utf8().data()); |
| 459 } | 470 } |
| 460 | 471 |
| 461 TEST(GKURL, Empty) { | 472 TEST(GKURL, Empty) { |
| 462 WebCore::GoogleKURL gurl; | 473 WebCore::KURL gurl; |
| 463 WebCore::WebKitKURL kurl; | |
| 464 | 474 |
| 465 // First test that regular empty URLs are the same. | 475 // First test that regular empty URLs are the same. |
| 466 EXPECT_EQ(kurl.isEmpty(), gurl.isEmpty()); | 476 EXPECT_TRUE(gurl.isEmpty()); |
| 467 EXPECT_EQ(kurl.isValid(), gurl.isValid()); | 477 EXPECT_FALSE(gurl.isValid()); |
| 468 EXPECT_EQ(kurl.isNull(), gurl.isNull()); | 478 EXPECT_TRUE(gurl.isNull()); |
| 469 EXPECT_EQ(kurl.string().isNull(), gurl.string().isNull()); | 479 EXPECT_TRUE(gurl.string().isNull()); |
| 470 EXPECT_EQ(kurl.string().isEmpty(), gurl.string().isEmpty()); | 480 EXPECT_TRUE(gurl.string().isEmpty()); |
| 471 | 481 |
| 472 // Test resolving a NULL URL on an empty string. | 482 // Test resolving a NULL URL on an empty string. |
| 473 WebCore::GoogleKURL gurl2(gurl, ""); | 483 WebCore::KURL gurl2(gurl, ""); |
| 474 WebCore::WebKitKURL kurl2(kurl, ""); | 484 EXPECT_FALSE(gurl2.isNull()); |
| 475 EXPECT_EQ(kurl2.isNull(), gurl2.isNull()); | 485 EXPECT_TRUE(gurl2.isEmpty()); |
| 476 EXPECT_EQ(kurl2.isEmpty(), gurl2.isEmpty()); | 486 EXPECT_FALSE(gurl2.isValid()); |
| 477 EXPECT_EQ(kurl2.isValid(), gurl2.isValid()); | 487 EXPECT_FALSE(gurl2.string().isNull()); |
| 478 EXPECT_EQ(kurl2.string().isNull(), gurl2.string().isNull()); | 488 EXPECT_TRUE(gurl2.string().isEmpty()); |
| 479 EXPECT_EQ(kurl2.string().isEmpty(), gurl2.string().isEmpty()); | 489 EXPECT_FALSE(gurl2.string().isNull()); |
| 480 EXPECT_EQ(kurl2.string().isNull(), gurl2.string().isNull()); | 490 EXPECT_TRUE(gurl2.string().isEmpty()); |
| 481 EXPECT_EQ(kurl2.string().isEmpty(), gurl2.string().isEmpty()); | |
| 482 | 491 |
| 483 // Resolve the NULL URL on a NULL string. | 492 // Resolve the NULL URL on a NULL string. |
| 484 WebCore::GoogleKURL gurl22(gurl, WebCore::String()); | 493 WebCore::KURL gurl22(gurl, WebCore::String()); |
| 485 WebCore::WebKitKURL kurl22(kurl, WebCore::String()); | 494 EXPECT_FALSE(gurl2.isNull()); |
| 486 EXPECT_EQ(kurl2.isNull(), gurl2.isNull()); | 495 EXPECT_TRUE(gurl2.isEmpty()); |
| 487 EXPECT_EQ(kurl2.isEmpty(), gurl2.isEmpty()); | 496 EXPECT_FALSE(gurl2.isValid()); |
| 488 EXPECT_EQ(kurl2.isValid(), gurl2.isValid()); | 497 EXPECT_FALSE(gurl2.string().isNull()); |
| 489 EXPECT_EQ(kurl2.string().isNull(), gurl2.string().isNull()); | 498 EXPECT_TRUE(gurl2.string().isEmpty()); |
| 490 EXPECT_EQ(kurl2.string().isEmpty(), gurl2.string().isEmpty()); | 499 EXPECT_FALSE(gurl2.string().isNull()); |
| 491 EXPECT_EQ(kurl2.string().isNull(), gurl2.string().isNull()); | 500 EXPECT_TRUE(gurl2.string().isEmpty()); |
| 492 EXPECT_EQ(kurl2.string().isEmpty(), gurl2.string().isEmpty()); | |
| 493 | 501 |
| 494 // Test non-hierarchical schemes resolving. The actual URLs will be different. | 502 // Test non-hierarchical schemes resolving. The actual URLs will be different. |
| 495 // WebKit's one will set the string to "something.gif" and we'll set it to an | 503 // WebKit's one will set the string to "something.gif" and we'll set it to an |
| 496 // empty string. I think either is OK, so we just check our behavior. | 504 // empty string. I think either is OK, so we just check our behavior. |
| 497 WebCore::GoogleKURL gurl3(WebCore::GoogleKURL("data:foo"), "something.gif"); | 505 #ifdef USE_GOOGLE_URL_LIBRARY |
| 506 WebCore::KURL gurl3(WebCore::KURL("data:foo"), "something.gif"); |
| 498 EXPECT_TRUE(gurl3.isEmpty()); | 507 EXPECT_TRUE(gurl3.isEmpty()); |
| 499 EXPECT_FALSE(gurl3.isValid()); | 508 EXPECT_FALSE(gurl3.isValid()); |
| 509 #endif |
| 500 | 510 |
| 501 // Test for weird isNull string input, | 511 // Test for weird isNull string input, |
| 502 // see: http://bugs.webkit.org/show_bug.cgi?id=16487 | 512 // see: http://bugs.webkit.org/show_bug.cgi?id=16487 |
| 503 WebCore::GoogleKURL gurl4(gurl.string()); | 513 WebCore::KURL gurl4(gurl.string()); |
| 504 WebCore::WebKitKURL kurl4(kurl.string()); | 514 EXPECT_TRUE(gurl4.isEmpty()); |
| 505 EXPECT_EQ(kurl4.isEmpty(), gurl4.isEmpty()); | 515 EXPECT_FALSE(gurl4.isValid()); |
| 506 EXPECT_EQ(kurl4.isValid(), gurl4.isValid()); | 516 EXPECT_TRUE(gurl4.string().isNull()); |
| 507 EXPECT_EQ(kurl4.string().isNull(), gurl4.string().isNull()); | 517 EXPECT_TRUE(gurl4.string().isEmpty()); |
| 508 EXPECT_EQ(kurl4.string().isEmpty(), gurl4.string().isEmpty()); | |
| 509 | 518 |
| 510 // Resolving an empty URL on an invalid string. | 519 // Resolving an empty URL on an invalid string. |
| 511 WebCore::GoogleKURL gurl5(WebCore::GoogleKURL(), "foo.js"); | 520 WebCore::KURL gurl5(WebCore::KURL(), "foo.js"); |
| 512 WebCore::WebKitKURL kurl5(WebCore::WebKitKURL(), "foo.js"); | |
| 513 // We'll be empty in this case, but KURL won't be. Should be OK. | 521 // We'll be empty in this case, but KURL won't be. Should be OK. |
| 514 // EXPECT_EQ(kurl5.isEmpty(), gurl5.isEmpty()); | 522 // EXPECT_EQ(kurl5.isEmpty(), gurl5.isEmpty()); |
| 515 // EXPECT_EQ(kurl5.string().isEmpty(), gurl5.string().isEmpty()); | 523 // EXPECT_EQ(kurl5.string().isEmpty(), gurl5.string().isEmpty()); |
| 516 EXPECT_EQ(kurl5.isValid(), gurl5.isValid()); | 524 EXPECT_FALSE(gurl5.isValid()); |
| 517 EXPECT_EQ(kurl5.string().isNull(), gurl5.string().isNull()); | 525 EXPECT_FALSE(gurl5.string().isNull()); |
| 518 | 526 |
| 519 // Empty string as input | 527 // Empty string as input |
| 520 WebCore::GoogleKURL gurl6(""); | 528 WebCore::KURL gurl6(""); |
| 521 WebCore::WebKitKURL kurl6(""); | 529 EXPECT_TRUE(gurl6.isEmpty()); |
| 522 EXPECT_EQ(kurl6.isEmpty(), gurl6.isEmpty()); | 530 EXPECT_FALSE(gurl6.isValid()); |
| 523 EXPECT_EQ(kurl6.isValid(), gurl6.isValid()); | 531 EXPECT_FALSE(gurl6.string().isNull()); |
| 524 EXPECT_EQ(kurl6.string().isNull(), gurl6.string().isNull()); | 532 EXPECT_TRUE(gurl6.string().isEmpty()); |
| 525 EXPECT_EQ(kurl6.string().isEmpty(), gurl6.string().isEmpty()); | |
| 526 | 533 |
| 527 // Non-empty but invalid C string as input. | 534 // Non-empty but invalid C string as input. |
| 528 WebCore::GoogleKURL gurl7("foo.js"); | 535 WebCore::KURL gurl7("foo.js"); |
| 529 WebCore::WebKitKURL kurl7("foo.js"); | |
| 530 // WebKit will actually say this URL has the string "foo.js" but is invalid. | 536 // WebKit will actually say this URL has the string "foo.js" but is invalid. |
| 531 // We don't do that. | 537 // We don't do that. |
| 532 // EXPECT_EQ(kurl7.isEmpty(), gurl7.isEmpty()); | 538 // EXPECT_EQ(kurl7.isEmpty(), gurl7.isEmpty()); |
| 533 EXPECT_EQ(kurl7.isValid(), gurl7.isValid()); | 539 EXPECT_FALSE(gurl7.isValid()); |
| 534 EXPECT_EQ(kurl7.string().isNull(), gurl7.string().isNull()); | 540 EXPECT_FALSE(gurl7.string().isNull()); |
| 535 } | 541 } |
| 536 | 542 |
| 537 TEST(GKURL, UserPass) { | 543 TEST(GKURL, UserPass) { |
| 538 const char* src = "http://user:pass@google.com/"; | 544 const char* src = "http://user:pass@google.com/"; |
| 539 WebCore::GoogleKURL gurl(src); | 545 WebCore::KURL gurl(src); |
| 540 WebCore::WebKitKURL kurl(src); | |
| 541 | 546 |
| 542 // Clear just the username. | 547 // Clear just the username. |
| 543 gurl.setUser(""); | 548 gurl.setUser(""); |
| 544 kurl.setUser(""); | 549 EXPECT_EQ("http://:pass@google.com/", gurl.string()); |
| 545 EXPECT_TRUE(kurl.string() == gurl.string()); | |
| 546 | 550 |
| 547 // Clear just the password. | 551 // Clear just the password. |
| 548 gurl = WebCore::GoogleKURL(src); | 552 gurl = WebCore::KURL(src); |
| 549 kurl = WebCore::WebKitKURL(src); | |
| 550 gurl.setPass(""); | 553 gurl.setPass(""); |
| 551 kurl.setPass(""); | 554 EXPECT_EQ("http://user@google.com/", gurl.string()); |
| 552 EXPECT_TRUE(kurl.string() == gurl.string()); | |
| 553 | 555 |
| 554 // Now clear both. | 556 // Now clear both. |
| 555 gurl.setUser(""); | 557 gurl.setUser(""); |
| 556 kurl.setUser(""); | 558 EXPECT_EQ("http://google.com/", gurl.string()); |
| 557 EXPECT_TRUE(kurl.string() == gurl.string()); | |
| 558 } | 559 } |
| 559 | 560 |
| 560 TEST(GKURL, Offsets) { | 561 TEST(GKURL, Offsets) { |
| 561 const char* src1 = "http://user:pass@google.com/foo/bar.html?baz=query#ref"; | 562 const char* src1 = "http://user:pass@google.com/foo/bar.html?baz=query#ref"; |
| 562 WebCore::GoogleKURL gurl1(src1); | 563 WebCore::KURL gurl1(src1); |
| 563 WebCore::WebKitKURL kurl1(src1); | |
| 564 | 564 |
| 565 EXPECT_TRUE(kurl1.hostStart() == gurl1.hostStart()); | 565 EXPECT_EQ(17, gurl1.hostStart()); |
| 566 EXPECT_TRUE(kurl1.hostEnd() == gurl1.hostEnd()); | 566 EXPECT_EQ(27, gurl1.hostEnd()); |
| 567 EXPECT_TRUE(kurl1.pathStart() == gurl1.pathStart()); | 567 EXPECT_EQ(27, gurl1.pathStart()); |
| 568 EXPECT_TRUE(kurl1.pathEnd() == gurl1.pathEnd()); | 568 EXPECT_EQ(40, gurl1.pathEnd()); |
| 569 EXPECT_TRUE(kurl1.pathAfterLastSlash() == gurl1.pathAfterLastSlash()); | 569 EXPECT_EQ(32, gurl1.pathAfterLastSlash()); |
| 570 | 570 |
| 571 const char* src2 = "http://google.com/foo/"; | 571 const char* src2 = "http://google.com/foo/"; |
| 572 WebCore::GoogleKURL gurl2(src2); | 572 WebCore::KURL gurl2(src2); |
| 573 WebCore::WebKitKURL kurl2(src2); | |
| 574 | 573 |
| 575 EXPECT_TRUE(kurl2.hostStart() == gurl2.hostStart()); | 574 EXPECT_EQ(7, gurl2.hostStart()); |
| 576 EXPECT_TRUE(kurl2.hostEnd() == gurl2.hostEnd()); | 575 EXPECT_EQ(17, gurl2.hostEnd()); |
| 577 EXPECT_TRUE(kurl2.pathStart() == gurl2.pathStart()); | 576 EXPECT_EQ(17, gurl2.pathStart()); |
| 578 EXPECT_TRUE(kurl2.pathEnd() == gurl2.pathEnd()); | 577 EXPECT_EQ(22, gurl2.pathEnd()); |
| 579 EXPECT_TRUE(kurl2.pathAfterLastSlash() == gurl2.pathAfterLastSlash()); | 578 EXPECT_EQ(22, gurl2.pathAfterLastSlash()); |
| 580 | 579 |
| 581 const char* src3 = "javascript:foobar"; | 580 const char* src3 = "javascript:foobar"; |
| 582 WebCore::GoogleKURL gurl3(src3); | 581 WebCore::KURL gurl3(src3); |
| 583 WebCore::WebKitKURL kurl3(src3); | |
| 584 | 582 |
| 585 EXPECT_TRUE(kurl3.hostStart() == gurl3.hostStart()); | 583 EXPECT_EQ(11, gurl3.hostStart()); |
| 586 EXPECT_TRUE(kurl3.hostEnd() == gurl3.hostEnd()); | 584 EXPECT_EQ(11, gurl3.hostEnd()); |
| 587 EXPECT_TRUE(kurl3.pathStart() == gurl3.pathStart()); | 585 EXPECT_EQ(11, gurl3.pathStart()); |
| 588 EXPECT_TRUE(kurl3.pathEnd() == gurl3.pathEnd()); | 586 EXPECT_EQ(17, gurl3.pathEnd()); |
| 589 EXPECT_TRUE(kurl3.pathAfterLastSlash() == gurl3.pathAfterLastSlash()); | 587 EXPECT_EQ(11, gurl3.pathAfterLastSlash()); |
| 590 } | 588 } |
| 589 |
| 590 TEST(GKURL, DeepCopy) { |
| 591 const char url[] = "http://www.google.com/"; |
| 592 WebCore::KURL src(url); |
| 593 EXPECT_TRUE(src.string() == url); // This really just initializes the cache. |
| 594 WebCore::KURL dest = src.copy(); |
| 595 EXPECT_TRUE(dest.string() == url); // This really just initializes the cache. |
| 596 |
| 597 // The pointers should be different for both UTF-8 and UTF-16. |
| 598 EXPECT_NE(dest.string().characters(), src.string().characters()); |
| 599 EXPECT_NE(dest.utf8String().data(), src.utf8String().data()); |
| 600 } |
| OLD | NEW |