summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbrettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-16 20:37:42 +0000
committerbrettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-16 20:37:42 +0000
commit2009148f6442bfe96170f3651ebfe99ac65eaec4 (patch)
treea41b583aa278c356de0eb52f11dc482c0322a648
parent67e7e72e6e87b0738fda920ce8341cbda0d1148d (diff)
downloadchromium_src-2009148f6442bfe96170f3651ebfe99ac65eaec4.zip
chromium_src-2009148f6442bfe96170f3651ebfe99ac65eaec4.tar.gz
chromium_src-2009148f6442bfe96170f3651ebfe99ac65eaec4.tar.bz2
Rewrite the GKURL unit tests to not use the "old" KURL as a baseline. This is
necessary for the KURL.h refactor since it's becoming more and more difficult to do my hack where the old types are defined to a different name. This also adds deep copy to GKURL. Review URL: http://codereview.chromium.org/14161 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@7089 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--webkit/port/platform/GKURL_unittest.cpp466
1 files changed, 232 insertions, 234 deletions
diff --git a/webkit/port/platform/GKURL_unittest.cpp b/webkit/port/platform/GKURL_unittest.cpp
index 4286d0a..bca7625 100644
--- a/webkit/port/platform/GKURL_unittest.cpp
+++ b/webkit/port/platform/GKURL_unittest.cpp
@@ -36,32 +36,7 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "webkit/glue/glue_util.h"
-MSVC_PUSH_WARNING_LEVEL(0);
-
-// This is because we have multiple headers called "CString.h" and KURL.cpp
-// can grab the wrong one.
-#include "third_party/WebKit/WebCore/platform/text/CString.h"
-
-// This evil preprocessor hack allows us to run both the original KURL and our
-// KURL code at the same time regardless of build options.
-
-#define KURL_DECORATE_GLOBALS
-
-// Old KURL
-#undef USE_GOOGLE_URL_LIBRARY
-#define KURL WebKitKURL
#include "KURL.h"
-#include "KURL.cpp"
-
-// Google's KURL
-#undef KURL_h // So the header is re-included.
-#undef KURL // Prevent warning on redefinition.
-#define USE_GOOGLE_URL_LIBRARY
-#define KURL GoogleKURL
-#include "KURL.h"
-#include "GKURL.cpp"
-
-MSVC_POP_WARNING();
#undef LOG
#include "base/basictypes.h"
@@ -94,50 +69,58 @@ std::ostream& operator<<(std::ostream& out,
} // namespace
-// Test the cases where we should be the same as WebKit's old KURL
+// Test the cases where we should be the same as WebKit's old KURL.
TEST(GKURL, SameGetters) {
- const char* cases[] = {
- // Regular stuff
- "http://www.google.com/foo/blah?bar=baz#ref",
- "http://foo.com:1234/foo/bar/",
- "http://www.google.com?#",
- "https://me:pass@google.com:23#foo",
- "javascript:hello!//world",
+ struct GetterCase {
+ const char* url;
+ const char* protocol;
+ const char* host;
+ int port;
+ const char* user;
+ const char* pass;
+ const char* last_path_component;
+ const char* query;
+ const char* ref;
+ bool has_ref;
+ } cases[] = {
+ {"http://www.google.com/foo/blah?bar=baz#ref", "http", "www.google.com", 0, "", NULL, "blah", "?bar=baz", "ref", true},
+ {"http://foo.com:1234/foo/bar/", "http", "foo.com", 1234, "", NULL, "bar", "", NULL, false},
+ {"http://www.google.com?#", "http", "www.google.com", 0, "", NULL, NULL, "?", "", true},
+ {"https://me:pass@google.com:23#foo", "https", "google.com", 23, "me", "pass", NULL, "", "foo", true},
+ {"javascript:hello!//world", "javascript", "", 0, "", NULL, "world", "", NULL, false},
};
- for (size_t i = 0; i < arraysize(cases); i++) {
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) {
// UTF-8
- WebCore::WebKitKURL kurl(cases[i]);
- WebCore::GoogleKURL gurl(cases[i]);
-
- EXPECT_EQ(kurl.protocol(), gurl.protocol());
- EXPECT_EQ(kurl.host(), gurl.host());
- EXPECT_EQ(kurl.port(), gurl.port());
- EXPECT_EQ(kurl.user(), gurl.user());
- EXPECT_EQ(kurl.pass(), gurl.pass());
- EXPECT_EQ(kurl.lastPathComponent(), gurl.lastPathComponent());
- EXPECT_EQ(kurl.query(), gurl.query());
- EXPECT_EQ(kurl.ref(), gurl.ref());
- EXPECT_EQ(kurl.hasRef(), gurl.hasRef());
+ WebCore::KURL gurl(cases[i].url);
+
+ EXPECT_EQ(cases[i].protocol, gurl.protocol());
+ EXPECT_EQ(cases[i].host, gurl.host());
+ EXPECT_EQ(cases[i].port, gurl.port());
+ EXPECT_EQ(cases[i].user, gurl.user());
+ EXPECT_EQ(cases[i].pass, gurl.pass());
+ EXPECT_EQ(cases[i].last_path_component, gurl.lastPathComponent());
+ EXPECT_EQ(cases[i].query, gurl.query());
+ EXPECT_EQ(cases[i].ref, gurl.ref());
+ EXPECT_EQ(cases[i].has_ref, gurl.hasRef());
// UTF-16
- std::wstring wstr(UTF8ToWide(cases[i]));
+ string16 wstr(UTF8ToUTF16(cases[i].url));
WebCore::String utf16(
reinterpret_cast<const ::UChar*>(wstr.c_str()),
static_cast<int>(wstr.length()));
- kurl = WebCore::WebKitKURL(utf16);
- gurl = WebCore::GoogleKURL(utf16);
-
- EXPECT_EQ(kurl.protocol(), gurl.protocol());
- EXPECT_EQ(kurl.host(), gurl.host());
- EXPECT_EQ(kurl.port(), gurl.port());
- EXPECT_EQ(kurl.user(), gurl.user());
- EXPECT_EQ(kurl.pass(), gurl.pass());
- EXPECT_EQ(kurl.lastPathComponent(), gurl.lastPathComponent());
- EXPECT_EQ(kurl.query(), gurl.query());
- EXPECT_EQ(kurl.ref(), gurl.ref());
- EXPECT_EQ(kurl.hasRef(), gurl.hasRef());
- };
+ gurl = WebCore::KURL(utf16);
+
+ EXPECT_EQ(cases[i].protocol, gurl.protocol());
+ EXPECT_EQ(cases[i].host, gurl.host());
+ EXPECT_EQ(cases[i].port, gurl.port());
+ EXPECT_EQ(cases[i].user, gurl.user());
+ EXPECT_EQ(cases[i].pass, gurl.pass());
+ EXPECT_EQ(cases[i].last_path_component, gurl.lastPathComponent());
+ EXPECT_EQ(cases[i].query, gurl.query());
+ EXPECT_EQ(cases[i].ref, gurl.ref());
+ EXPECT_EQ(cases[i].has_ref, gurl.hasRef());
+ }
}
// Test a few cases where we're different just to make sure we give reasonable
@@ -162,7 +145,7 @@ TEST(GKURL, DifferentGetters) {
};
for (size_t i = 0; i < arraysize(cases); i++) {
- WebCore::GoogleKURL gurl(cases[i].url);
+ WebCore::KURL gurl(cases[i].url);
EXPECT_EQ(cases[i].protocol, gurl.protocol());
EXPECT_EQ(cases[i].host, gurl.host());
@@ -185,7 +168,7 @@ TEST(GKURL, DifferentGetters) {
// get the correct string object out.
TEST(GKURL, UTF8) {
const char ascii_url[] = "http://foo/bar#baz";
- WebCore::GoogleKURL ascii_gurl(ascii_url);
+ WebCore::KURL ascii_gurl(ascii_url);
EXPECT_TRUE(ascii_gurl.string() == WebCore::String(ascii_url));
// When the result is ASCII, we should get an ASCII String. Some
@@ -197,11 +180,11 @@ TEST(GKURL, UTF8) {
// Reproduce code path in FrameLoader.cpp -- equalIgnoringCase implicitly
// expects gkurl.protocol() to have been created as ascii.
- WebCore::GoogleKURL mailto("mailto:foo@foo.com");
+ WebCore::KURL mailto("mailto:foo@foo.com");
EXPECT_TRUE(WebCore::equalIgnoringCase(mailto.protocol(), "mailto"));
const char utf8_url[] = "http://foo/bar#\xe4\xbd\xa0\xe5\xa5\xbd";
- WebCore::GoogleKURL utf8_gurl(utf8_url);
+ WebCore::KURL utf8_gurl(utf8_url);
EXPECT_TRUE(utf8_gurl.string() ==
webkit_glue::StdWStringToString(UTF8ToWide(utf8_url)));
@@ -214,46 +197,76 @@ TEST(GKURL, Setters) {
// Note that old KURL won't canonicalize the default port away, so we
// can't set setting the http port to "80" (or even "0").
//
- // We also can't test clearing the query, since
- ComponentCase cases[] = {
- // url protocol host port user pass path last_path query ref
- {"http://www.google.com/", "https", "news.google.com", 8888, "me", "pass", "/foo", NULL, "?q=asdf", "heehee"},
- {"https://me:pass@google.com:88/a?f#b", "http", "goo.com", 92, "", "", "/", NULL, NULL, ""},
+ // We also can't test clearing the query.
+ //
+ // The format is every other row is a test, and the row that follows it is the
+ // expected result.
+ struct ExpectedComponentCase {
+ const char* url;
+ const char* protocol;
+ const char* host;
+ const int port;
+ const char* user;
+ const char* pass;
+ const char* path;
+ const char* query;
+ const char* ref;
+
+ // The full expected URL with the given "set" applied.
+ const char* expected_protocol;
+ const char* expected_host;
+ const char* expected_port;
+ const char* expected_user;
+ const char* expected_pass;
+ const char* expected_path;
+ const char* expected_query;
+ const char* expected_ref;
+ } cases[] = {
+ // url protocol host port user pass path query ref
+ {"http://www.google.com/", "https", "news.google.com", 8888, "me", "pass", "/foo", "?q=asdf", "heehee",
+ "https://www.google.com/",
+ "https://news.google.com/",
+ "https://news.google.com:8888/",
+ "https://me@news.google.com:8888/",
+ "https://me:pass@news.google.com:8888/",
+ "https://me:pass@news.google.com:8888/foo",
+ "https://me:pass@news.google.com:8888/foo?q=asdf",
+ "https://me:pass@news.google.com:8888/foo?q=asdf#heehee"},
+
+ {"https://me:pass@google.com:88/a?f#b", "http", "goo.com", 92, "", "", "/", NULL, "",
+ "http://me:pass@google.com:88/a?f#b",
+ "http://me:pass@goo.com:88/a?f#b",
+ "http://me:pass@goo.com:92/a?f#b",
+ "http://:pass@goo.com:92/a?f#b",
+ "http://goo.com:92/a?f#b",
+ "http://goo.com:92/?f#b",
+ "http://goo.com:92/#b",
+ "https://goo.com:92/"},
};
- for (size_t i = 0; i < arraysize(cases); i++) {
- WebCore::GoogleKURL gurl(cases[i].url);
- WebCore::WebKitKURL kurl(cases[i].url);
-
- EXPECT_EQ(kurl.string(), gurl.string());
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) {
+ WebCore::KURL gurl(cases[i].url);
- kurl.setProtocol(cases[i].protocol);
gurl.setProtocol(cases[i].protocol);
- EXPECT_EQ(kurl.string(), gurl.string());
+ EXPECT_STREQ(cases[i].expected_protocol, gurl.string().utf8().data());
- kurl.setHost(cases[i].host);
gurl.setHost(cases[i].host);
- EXPECT_EQ(kurl.string(), gurl.string());
+ EXPECT_STREQ(cases[i].expected_host, gurl.string().utf8().data());
- kurl.setPort(cases[i].port);
gurl.setPort(cases[i].port);
- EXPECT_EQ(kurl.string(), gurl.string());
+ EXPECT_STREQ(cases[i].expected_port, gurl.string().utf8().data());
- kurl.setUser(cases[i].user);
gurl.setUser(cases[i].user);
- EXPECT_EQ(kurl.string(), gurl.string());
+ EXPECT_STREQ(cases[i].expected_user, gurl.string().utf8().data());
- kurl.setPass(cases[i].pass);
gurl.setPass(cases[i].pass);
- EXPECT_EQ(kurl.string(), gurl.string());
+ EXPECT_STREQ(cases[i].expected_pass, gurl.string().utf8().data());
- kurl.setPath(cases[i].path);
gurl.setPath(cases[i].path);
- EXPECT_EQ(kurl.string(), gurl.string());
+ EXPECT_STREQ(cases[i].expected_path, gurl.string().utf8().data());
- kurl.setQuery(cases[i].query);
gurl.setQuery(cases[i].query);
- EXPECT_EQ(kurl.string(), gurl.string());
+ EXPECT_STREQ(cases[i].expected_query, gurl.string().utf8().data());
// Refs are tested below. On the Safari 3.1 branch, we don't match their
// KURL since we integrated a fix from their trunk.
@@ -261,34 +274,37 @@ TEST(GKURL, Setters) {
}
// Tests that KURL::decodeURLEscapeSequences works as expected
+#ifdef USE_GOOGLE_URL_LIBRARY
TEST(GKURL, Decode) {
- const char* decode_cases[] = {
- "hello, world",
- "%01%02%03%04%05%06%07%08%09%0a%0B%0C%0D%0e%0f/",
- "%10%11%12%13%14%15%16%17%18%19%1a%1B%1C%1D%1e%1f/",
- "%20%21%22%23%24%25%26%27%28%29%2a%2B%2C%2D%2e%2f/",
- "%30%31%32%33%34%35%36%37%38%39%3a%3B%3C%3D%3e%3f/",
- "%40%41%42%43%44%45%46%47%48%49%4a%4B%4C%4D%4e%4f/",
- "%50%51%52%53%54%55%56%57%58%59%5a%5B%5C%5D%5e%5f/",
- "%60%61%62%63%64%65%66%67%68%69%6a%6B%6C%6D%6e%6f/",
- "%70%71%72%73%74%75%76%77%78%79%7a%7B%7C%7D%7e%7f/",
+ struct DecodeCase {
+ const char* input;
+ const char* output;
+ } decode_cases[] = {
+ {"hello, world", "hello, world"},
+ {"%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/"},
+ {"%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/"},
+ {"%20%21%22%23%24%25%26%27%28%29%2a%2B%2C%2D%2e%2f/", " !\"#$%&'()*+,-.//"},
+ {"%30%31%32%33%34%35%36%37%38%39%3a%3B%3C%3D%3e%3f/", "0123456789:;<=>?/"},
+ {"%40%41%42%43%44%45%46%47%48%49%4a%4B%4C%4D%4e%4f/", "@ABCDEFGHIJKLMNO/"},
+ {"%50%51%52%53%54%55%56%57%58%59%5a%5B%5C%5D%5e%5f/", "PQRSTUVWXYZ[\\]^_/"},
+ {"%60%61%62%63%64%65%66%67%68%69%6a%6B%6C%6D%6e%6f/", "`abcdefghijklmno/"},
+ {"%70%71%72%73%74%75%76%77%78%79%7a%7B%7C%7D%7e%7f/", "pqrstuvwxyz{|}~\x7f/"},
// Test un-UTF-8-ization.
- "%e4%bd%a0%e5%a5%bd",
+ {"%e4%bd%a0%e5%a5%bd", "\xe4\xbd\xa0\xe5\xa5\xbd"},
};
- for (size_t i = 0; i < arraysize(decode_cases); i++) {
- WebCore::String input(decode_cases[i]);
- WebCore::String webkit = WebCore::WebKitKURL::decodeURLEscapeSequences(input);
- WebCore::String google = WebCore::GoogleKURL::decodeURLEscapeSequences(input);
- EXPECT_TRUE(webkit == google);
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(decode_cases); i++) {
+ WebCore::String input(decode_cases[i].input);
+ WebCore::String str = WebCore::decodeURLEscapeSequences(input);
+ EXPECT_STREQ(decode_cases[i].output, str.utf8().data());
}
// Our decode should not decode %00
- WebCore::String zero = WebCore::GoogleKURL::decodeURLEscapeSequences("%00");
+ WebCore::String zero = WebCore::decodeURLEscapeSequences("%00");
EXPECT_STREQ("%00", zero.utf8().data());
// Test the error behavior for invalid UTF-8 (we differ from WebKit here).
- WebCore::String invalid = WebCore::GoogleKURL::decodeURLEscapeSequences(
+ WebCore::String invalid = WebCore::decodeURLEscapeSequences(
"%e4%a0%e5%a5%bd");
char16 invalid_expected_helper[4] = { 0x00e4, 0x00a0, 0x597d, 0 };
WebCore::String invalid_expected(
@@ -296,6 +312,7 @@ TEST(GKURL, Decode) {
3);
EXPECT_EQ(invalid_expected, invalid);
}
+#endif
TEST(GKURL, Encode) {
// Also test that it gets converted to UTF-8 properly.
@@ -304,7 +321,7 @@ TEST(GKURL, Encode) {
reinterpret_cast<const ::UChar*>(wide_input_helper), 2);
WebCore::String wide_reference("\xe4\xbd\xa0\xe5\xa5\xbd", 6);
WebCore::String wide_output =
- WebCore::GoogleKURL::encodeWithURLEscapeSequences(wide_input);
+ WebCore::encodeWithURLEscapeSequences(wide_input);
EXPECT_EQ(wide_reference, wide_output);
// Our encode only escapes NULLs for safety (see the implementation for
@@ -313,84 +330,82 @@ TEST(GKURL, Encode) {
"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f", 16);
WebCore::String reference(
"%00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f", 18);
- WebCore::String output = WebCore::GoogleKURL::encodeWithURLEscapeSequences(input);
+ WebCore::String output = WebCore::encodeWithURLEscapeSequences(input);
EXPECT_EQ(reference, output);
}
TEST(GKURL, ResolveEmpty) {
- WebCore::GoogleKURL empty_base;
+ WebCore::KURL empty_base;
// WebKit likes to be able to resolve absolute input agains empty base URLs,
// which would normally be invalid since the base URL is invalid.
const char abs[] = "http://www.google.com/";
- WebCore::GoogleKURL resolve_abs(empty_base, abs);
+ WebCore::KURL resolve_abs(empty_base, abs);
EXPECT_TRUE(resolve_abs.isValid());
EXPECT_STREQ(abs, resolve_abs.string().utf8().data());
// Resolving a non-relative URL agains the empty one should still error.
const char rel[] = "foo.html";
- WebCore::GoogleKURL resolve_err(empty_base, rel);
+ WebCore::KURL resolve_err(empty_base, rel);
EXPECT_FALSE(resolve_err.isValid());
}
// WebKit will make empty URLs and set components on them. GURL doesn't allow
// replacements on invalid URLs, but here we do.
TEST(GKURL, ReplaceInvalid) {
- WebCore::GoogleKURL gurl;
- WebCore::WebKitKURL kurl;
+ WebCore::KURL gurl;
- EXPECT_EQ(kurl.isValid(), gurl.isValid());
- EXPECT_EQ(kurl.isEmpty(), gurl.isEmpty());
- EXPECT_STREQ(kurl.string().utf8().data(), gurl.string().utf8().data());
+ EXPECT_FALSE(gurl.isValid());
+ EXPECT_TRUE(gurl.isEmpty());
+ EXPECT_STREQ("", gurl.string().utf8().data());
gurl.setProtocol("http");
- kurl.setProtocol("http");
// GKURL will say that a URL with just a scheme is invalid, KURL will not.
- EXPECT_TRUE(kurl.isValid());
+#ifdef USE_GOOGLE_URL_LIBRARY
EXPECT_FALSE(gurl.isValid());
- EXPECT_EQ(kurl.isEmpty(), gurl.isEmpty());
- // At this point, the strings will *not* be equal, we do things slightly
- // differently if there is only a scheme. We check the results here to make
- // it more obvious what is going on, but it shouldn't be a big deal if these
- // change.
+#else
+ EXPECT_TRUE(gurl.isValid());
+#endif
+ EXPECT_FALSE(gurl.isEmpty());
+ // At this point, we do things slightly differently if there is only a scheme.
+ // We check the results here to make it more obvious what is going on, but it
+ // shouldn't be a big deal if these change.
+#ifdef USE_GOOGLE_URL_LIBRARY
EXPECT_STREQ("http:", gurl.string().utf8().data());
- EXPECT_STREQ("http:/", kurl.string().utf8().data());
+#else
+ EXPECT_STREQ("http:/", gurl.string().utf8().data());
+#endif
gurl.setHost("www.google.com");
- kurl.setHost("www.google.com");
- EXPECT_EQ(kurl.isValid(), gurl.isValid());
- EXPECT_EQ(kurl.isEmpty(), gurl.isEmpty());
- EXPECT_STREQ(kurl.string().utf8().data(), gurl.string().utf8().data());
+ EXPECT_TRUE(gurl.isValid());
+ EXPECT_FALSE(gurl.isEmpty());
+ EXPECT_STREQ("http://www.google.com/", gurl.string().utf8().data());
gurl.setPort(8000);
- kurl.setPort(8000);
- EXPECT_EQ(kurl.isValid(), gurl.isValid());
- EXPECT_EQ(kurl.isEmpty(), gurl.isEmpty());
- EXPECT_STREQ(kurl.string().utf8().data(), gurl.string().utf8().data());
+ EXPECT_TRUE(gurl.isValid());
+ EXPECT_FALSE(gurl.isEmpty());
+ EXPECT_STREQ("http://www.google.com:8000/", gurl.string().utf8().data());
gurl.setPath("/favicon.ico");
- kurl.setPath("/favicon.ico");
- EXPECT_EQ(kurl.isValid(), gurl.isValid());
- EXPECT_EQ(kurl.isEmpty(), gurl.isEmpty());
- EXPECT_STREQ(kurl.string().utf8().data(), gurl.string().utf8().data());
+ EXPECT_TRUE(gurl.isValid());
+ EXPECT_FALSE(gurl.isEmpty());
EXPECT_STREQ("http://www.google.com:8000/favicon.ico", gurl.string().utf8().data());
// Now let's test that giving an invalid replacement still fails.
+#ifdef USE_GOOGLE_URL_LIBRARY
gurl.setProtocol("f/sj#@");
EXPECT_FALSE(gurl.isValid());
+#endif
}
TEST(GKURL, Path) {
const char initial[] = "http://www.google.com/path/foo";
- WebCore::GoogleKURL gurl(initial);
- WebCore::WebKitKURL kurl(initial);
+ WebCore::KURL gurl(initial);
// Clear by setting a NULL string.
WebCore::String null_string;
EXPECT_TRUE(null_string.isNull());
gurl.setPath(null_string);
- kurl.setPath(null_string);
- EXPECT_STREQ(kurl.string().utf8().data(), gurl.string().utf8().data());
EXPECT_STREQ("http://www.google.com/", gurl.string().utf8().data());
}
@@ -398,43 +413,39 @@ TEST(GKURL, Path) {
// a littler differently than some of the other components.
TEST(GKURL, Query) {
const char initial[] = "http://www.google.com/search?q=awesome";
- WebCore::GoogleKURL gurl(initial);
- WebCore::WebKitKURL kurl(initial);
+ WebCore::KURL gurl(initial);
// Clear by setting a NULL string.
WebCore::String null_string;
EXPECT_TRUE(null_string.isNull());
gurl.setQuery(null_string);
- kurl.setQuery(null_string);
- EXPECT_STREQ(kurl.string().utf8().data(), gurl.string().utf8().data());
+ EXPECT_STREQ("http://www.google.com/search", gurl.string().utf8().data());
// Clear by setting an empty string.
- gurl = WebCore::GoogleKURL(initial);
- kurl = WebCore::WebKitKURL(initial);
+ gurl = WebCore::KURL(initial);
WebCore::String empty_string("");
EXPECT_FALSE(empty_string.isNull());
gurl.setQuery(empty_string);
- kurl.setQuery(empty_string);
- EXPECT_STREQ(kurl.string().utf8().data(), gurl.string().utf8().data());
+ EXPECT_STREQ("http://www.google.com/search?", gurl.string().utf8().data());
// Set with something that begins in a question mark.
const char question[] = "?foo=bar";
gurl.setQuery(question);
- kurl.setQuery(question);
- EXPECT_STREQ(kurl.string().utf8().data(), gurl.string().utf8().data());
+ EXPECT_STREQ("http://www.google.com/search?foo=bar",
+ gurl.string().utf8().data());
// Set with something that doesn't begin in a question mark.
const char query[] = "foo=bar";
gurl.setQuery(query);
- kurl.setQuery(query);
- EXPECT_STREQ(kurl.string().utf8().data(), gurl.string().utf8().data());
+ EXPECT_STREQ("http://www.google.com/search?foo=bar",
+ gurl.string().utf8().data());
}
TEST(GKURL, Ref) {
- WebCore::GoogleKURL gurl("http://foo/bar#baz");
+ WebCore::KURL gurl("http://foo/bar#baz");
// Basic ref setting.
- WebCore::GoogleKURL cur("http://foo/bar");
+ WebCore::KURL cur("http://foo/bar");
cur.setRef("asdf");
EXPECT_STREQ("http://foo/bar#asdf", cur.string().utf8().data());
cur = gurl;
@@ -442,7 +453,7 @@ TEST(GKURL, Ref) {
EXPECT_STREQ("http://foo/bar#asdf", cur.string().utf8().data());
// Setting a ref to the empty string will set it to "#".
- cur = WebCore::GoogleKURL("http://foo/bar");
+ cur = WebCore::KURL("http://foo/bar");
cur.setRef("");
EXPECT_STREQ("http://foo/bar#", cur.string().utf8().data());
cur = gurl;
@@ -450,7 +461,7 @@ TEST(GKURL, Ref) {
EXPECT_STREQ("http://foo/bar#", cur.string().utf8().data());
// Setting the ref to the null string will clear it altogether.
- cur = WebCore::GoogleKURL("http://foo/bar");
+ cur = WebCore::KURL("http://foo/bar");
cur.setRef(WebCore::String());
EXPECT_STREQ("http://foo/bar", cur.string().utf8().data());
cur = gurl;
@@ -459,132 +470,119 @@ TEST(GKURL, Ref) {
}
TEST(GKURL, Empty) {
- WebCore::GoogleKURL gurl;
- WebCore::WebKitKURL kurl;
+ WebCore::KURL gurl;
// First test that regular empty URLs are the same.
- EXPECT_EQ(kurl.isEmpty(), gurl.isEmpty());
- EXPECT_EQ(kurl.isValid(), gurl.isValid());
- EXPECT_EQ(kurl.isNull(), gurl.isNull());
- EXPECT_EQ(kurl.string().isNull(), gurl.string().isNull());
- EXPECT_EQ(kurl.string().isEmpty(), gurl.string().isEmpty());
+ EXPECT_TRUE(gurl.isEmpty());
+ EXPECT_FALSE(gurl.isValid());
+ EXPECT_TRUE(gurl.isNull());
+ EXPECT_TRUE(gurl.string().isNull());
+ EXPECT_TRUE(gurl.string().isEmpty());
// Test resolving a NULL URL on an empty string.
- WebCore::GoogleKURL gurl2(gurl, "");
- WebCore::WebKitKURL kurl2(kurl, "");
- EXPECT_EQ(kurl2.isNull(), gurl2.isNull());
- EXPECT_EQ(kurl2.isEmpty(), gurl2.isEmpty());
- EXPECT_EQ(kurl2.isValid(), gurl2.isValid());
- EXPECT_EQ(kurl2.string().isNull(), gurl2.string().isNull());
- EXPECT_EQ(kurl2.string().isEmpty(), gurl2.string().isEmpty());
- EXPECT_EQ(kurl2.string().isNull(), gurl2.string().isNull());
- EXPECT_EQ(kurl2.string().isEmpty(), gurl2.string().isEmpty());
+ WebCore::KURL gurl2(gurl, "");
+ EXPECT_FALSE(gurl2.isNull());
+ EXPECT_TRUE(gurl2.isEmpty());
+ EXPECT_FALSE(gurl2.isValid());
+ EXPECT_FALSE(gurl2.string().isNull());
+ EXPECT_TRUE(gurl2.string().isEmpty());
+ EXPECT_FALSE(gurl2.string().isNull());
+ EXPECT_TRUE(gurl2.string().isEmpty());
// Resolve the NULL URL on a NULL string.
- WebCore::GoogleKURL gurl22(gurl, WebCore::String());
- WebCore::WebKitKURL kurl22(kurl, WebCore::String());
- EXPECT_EQ(kurl2.isNull(), gurl2.isNull());
- EXPECT_EQ(kurl2.isEmpty(), gurl2.isEmpty());
- EXPECT_EQ(kurl2.isValid(), gurl2.isValid());
- EXPECT_EQ(kurl2.string().isNull(), gurl2.string().isNull());
- EXPECT_EQ(kurl2.string().isEmpty(), gurl2.string().isEmpty());
- EXPECT_EQ(kurl2.string().isNull(), gurl2.string().isNull());
- EXPECT_EQ(kurl2.string().isEmpty(), gurl2.string().isEmpty());
+ WebCore::KURL gurl22(gurl, WebCore::String());
+ EXPECT_FALSE(gurl2.isNull());
+ EXPECT_TRUE(gurl2.isEmpty());
+ EXPECT_FALSE(gurl2.isValid());
+ EXPECT_FALSE(gurl2.string().isNull());
+ EXPECT_TRUE(gurl2.string().isEmpty());
+ EXPECT_FALSE(gurl2.string().isNull());
+ EXPECT_TRUE(gurl2.string().isEmpty());
// Test non-hierarchical schemes resolving. The actual URLs will be different.
// WebKit's one will set the string to "something.gif" and we'll set it to an
// empty string. I think either is OK, so we just check our behavior.
- WebCore::GoogleKURL gurl3(WebCore::GoogleKURL("data:foo"), "something.gif");
+#ifdef USE_GOOGLE_URL_LIBRARY
+ WebCore::KURL gurl3(WebCore::KURL("data:foo"), "something.gif");
EXPECT_TRUE(gurl3.isEmpty());
EXPECT_FALSE(gurl3.isValid());
+#endif
// Test for weird isNull string input,
// see: http://bugs.webkit.org/show_bug.cgi?id=16487
- WebCore::GoogleKURL gurl4(gurl.string());
- WebCore::WebKitKURL kurl4(kurl.string());
- EXPECT_EQ(kurl4.isEmpty(), gurl4.isEmpty());
- EXPECT_EQ(kurl4.isValid(), gurl4.isValid());
- EXPECT_EQ(kurl4.string().isNull(), gurl4.string().isNull());
- EXPECT_EQ(kurl4.string().isEmpty(), gurl4.string().isEmpty());
+ WebCore::KURL gurl4(gurl.string());
+ EXPECT_TRUE(gurl4.isEmpty());
+ EXPECT_FALSE(gurl4.isValid());
+ EXPECT_TRUE(gurl4.string().isNull());
+ EXPECT_TRUE(gurl4.string().isEmpty());
// Resolving an empty URL on an invalid string.
- WebCore::GoogleKURL gurl5(WebCore::GoogleKURL(), "foo.js");
- WebCore::WebKitKURL kurl5(WebCore::WebKitKURL(), "foo.js");
+ WebCore::KURL gurl5(WebCore::KURL(), "foo.js");
// We'll be empty in this case, but KURL won't be. Should be OK.
// EXPECT_EQ(kurl5.isEmpty(), gurl5.isEmpty());
// EXPECT_EQ(kurl5.string().isEmpty(), gurl5.string().isEmpty());
- EXPECT_EQ(kurl5.isValid(), gurl5.isValid());
- EXPECT_EQ(kurl5.string().isNull(), gurl5.string().isNull());
+ EXPECT_FALSE(gurl5.isValid());
+ EXPECT_FALSE(gurl5.string().isNull());
// Empty string as input
- WebCore::GoogleKURL gurl6("");
- WebCore::WebKitKURL kurl6("");
- EXPECT_EQ(kurl6.isEmpty(), gurl6.isEmpty());
- EXPECT_EQ(kurl6.isValid(), gurl6.isValid());
- EXPECT_EQ(kurl6.string().isNull(), gurl6.string().isNull());
- EXPECT_EQ(kurl6.string().isEmpty(), gurl6.string().isEmpty());
+ WebCore::KURL gurl6("");
+ EXPECT_TRUE(gurl6.isEmpty());
+ EXPECT_FALSE(gurl6.isValid());
+ EXPECT_FALSE(gurl6.string().isNull());
+ EXPECT_TRUE(gurl6.string().isEmpty());
// Non-empty but invalid C string as input.
- WebCore::GoogleKURL gurl7("foo.js");
- WebCore::WebKitKURL kurl7("foo.js");
+ WebCore::KURL gurl7("foo.js");
// WebKit will actually say this URL has the string "foo.js" but is invalid.
// We don't do that.
// EXPECT_EQ(kurl7.isEmpty(), gurl7.isEmpty());
- EXPECT_EQ(kurl7.isValid(), gurl7.isValid());
- EXPECT_EQ(kurl7.string().isNull(), gurl7.string().isNull());
+ EXPECT_FALSE(gurl7.isValid());
+ EXPECT_FALSE(gurl7.string().isNull());
}
TEST(GKURL, UserPass) {
const char* src = "http://user:pass@google.com/";
- WebCore::GoogleKURL gurl(src);
- WebCore::WebKitKURL kurl(src);
+ WebCore::KURL gurl(src);
// Clear just the username.
gurl.setUser("");
- kurl.setUser("");
- EXPECT_TRUE(kurl.string() == gurl.string());
+ EXPECT_EQ("http://:pass@google.com/", gurl.string());
// Clear just the password.
- gurl = WebCore::GoogleKURL(src);
- kurl = WebCore::WebKitKURL(src);
+ gurl = WebCore::KURL(src);
gurl.setPass("");
- kurl.setPass("");
- EXPECT_TRUE(kurl.string() == gurl.string());
+ EXPECT_EQ("http://user@google.com/", gurl.string());
// Now clear both.
gurl.setUser("");
- kurl.setUser("");
- EXPECT_TRUE(kurl.string() == gurl.string());
+ EXPECT_EQ("http://google.com/", gurl.string());
}
TEST(GKURL, Offsets) {
const char* src1 = "http://user:pass@google.com/foo/bar.html?baz=query#ref";
- WebCore::GoogleKURL gurl1(src1);
- WebCore::WebKitKURL kurl1(src1);
+ WebCore::KURL gurl1(src1);
- EXPECT_TRUE(kurl1.hostStart() == gurl1.hostStart());
- EXPECT_TRUE(kurl1.hostEnd() == gurl1.hostEnd());
- EXPECT_TRUE(kurl1.pathStart() == gurl1.pathStart());
- EXPECT_TRUE(kurl1.pathEnd() == gurl1.pathEnd());
- EXPECT_TRUE(kurl1.pathAfterLastSlash() == gurl1.pathAfterLastSlash());
+ EXPECT_EQ(17u, gurl1.hostStart());
+ EXPECT_EQ(27u, gurl1.hostEnd());
+ EXPECT_EQ(27u, gurl1.pathStart());
+ EXPECT_EQ(40u, gurl1.pathEnd());
+ EXPECT_EQ(32u, gurl1.pathAfterLastSlash());
const char* src2 = "http://google.com/foo/";
- WebCore::GoogleKURL gurl2(src2);
- WebCore::WebKitKURL kurl2(src2);
+ WebCore::KURL gurl2(src2);
- EXPECT_TRUE(kurl2.hostStart() == gurl2.hostStart());
- EXPECT_TRUE(kurl2.hostEnd() == gurl2.hostEnd());
- EXPECT_TRUE(kurl2.pathStart() == gurl2.pathStart());
- EXPECT_TRUE(kurl2.pathEnd() == gurl2.pathEnd());
- EXPECT_TRUE(kurl2.pathAfterLastSlash() == gurl2.pathAfterLastSlash());
+ EXPECT_EQ(7u, gurl2.hostStart());
+ EXPECT_EQ(17u, gurl2.hostEnd());
+ EXPECT_EQ(17u, gurl2.pathStart());
+ EXPECT_EQ(22u, gurl2.pathEnd());
+ EXPECT_EQ(22u, gurl2.pathAfterLastSlash());
const char* src3 = "javascript:foobar";
- WebCore::GoogleKURL gurl3(src3);
- WebCore::WebKitKURL kurl3(src3);
-
- EXPECT_TRUE(kurl3.hostStart() == gurl3.hostStart());
- EXPECT_TRUE(kurl3.hostEnd() == gurl3.hostEnd());
- EXPECT_TRUE(kurl3.pathStart() == gurl3.pathStart());
- EXPECT_TRUE(kurl3.pathEnd() == gurl3.pathEnd());
- EXPECT_TRUE(kurl3.pathAfterLastSlash() == gurl3.pathAfterLastSlash());
+ WebCore::KURL gurl3(src3);
+
+ EXPECT_EQ(11u, gurl3.hostStart());
+ EXPECT_EQ(11u, gurl3.hostEnd());
+ EXPECT_EQ(11u, gurl3.pathStart());
+ EXPECT_EQ(17u, gurl3.pathEnd());
+ EXPECT_EQ(11u, gurl3.pathAfterLastSlash());
}