Add a CefGetMimeType function for retrieving the mime type of a file extension (issue #1098).

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@1577 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt
2014-01-28 17:26:59 +00:00
parent 0c8b381a46
commit 2f8b024797
6 changed files with 119 additions and 49 deletions

View File

@@ -12,8 +12,8 @@ TEST(URLTest, CreateURL) {
CefString url;
CefString(&parts.spec).FromASCII(
"http://user:pass@www.example.com:88/path/to.html?foo=test&bar=test2");
ASSERT_TRUE(CefCreateURL(parts, url));
ASSERT_EQ(url,
EXPECT_TRUE(CefCreateURL(parts, url));
EXPECT_EQ(url,
"http://user:pass@www.example.com:88/path/to.html?foo=test&bar=test2");
}
@@ -22,13 +22,13 @@ TEST(URLTest, CreateURL) {
CefURLParts parts;
CefString url;
CefString(&parts.scheme).FromASCII("http");
ASSERT_FALSE(CefCreateURL(parts, url));
EXPECT_FALSE(CefCreateURL(parts, url));
}
{
CefURLParts parts;
CefString url;
CefString(&parts.host).FromASCII("www.example.com");
ASSERT_FALSE(CefCreateURL(parts, url));
EXPECT_FALSE(CefCreateURL(parts, url));
}
// Create the URL using scheme and host.
@@ -37,8 +37,8 @@ TEST(URLTest, CreateURL) {
CefString url;
CefString(&parts.scheme).FromASCII("http");
CefString(&parts.host).FromASCII("www.example.com");
ASSERT_TRUE(CefCreateURL(parts, url));
ASSERT_EQ(url, "http://www.example.com/");
EXPECT_TRUE(CefCreateURL(parts, url));
EXPECT_EQ(url, "http://www.example.com/");
}
// Create the URL using scheme, host and path.
@@ -48,8 +48,8 @@ TEST(URLTest, CreateURL) {
CefString(&parts.scheme).FromASCII("http");
CefString(&parts.host).FromASCII("www.example.com");
CefString(&parts.path).FromASCII("/path/to.html");
ASSERT_TRUE(CefCreateURL(parts, url));
ASSERT_EQ(url, "http://www.example.com/path/to.html");
EXPECT_TRUE(CefCreateURL(parts, url));
EXPECT_EQ(url, "http://www.example.com/path/to.html");
}
// Create the URL using scheme, host, path and query.
@@ -60,8 +60,8 @@ TEST(URLTest, CreateURL) {
CefString(&parts.host).FromASCII("www.example.com");
CefString(&parts.path).FromASCII("/path/to.html");
CefString(&parts.query).FromASCII("foo=test&bar=test2");
ASSERT_TRUE(CefCreateURL(parts, url));
ASSERT_EQ(url, "http://www.example.com/path/to.html?foo=test&bar=test2");
EXPECT_TRUE(CefCreateURL(parts, url));
EXPECT_EQ(url, "http://www.example.com/path/to.html?foo=test&bar=test2");
}
// Create the URL using all the various components.
@@ -75,8 +75,8 @@ TEST(URLTest, CreateURL) {
CefString(&parts.port).FromASCII("88");
CefString(&parts.path).FromASCII("/path/to.html");
CefString(&parts.query).FromASCII("foo=test&bar=test2");
ASSERT_TRUE(CefCreateURL(parts, url));
ASSERT_EQ(url,
EXPECT_TRUE(CefCreateURL(parts, url));
EXPECT_EQ(url,
"http://user:pass@www.example.com:88/path/to.html?foo=test&bar=test2");
}
}
@@ -87,20 +87,20 @@ TEST(URLTest, ParseURL) {
CefURLParts parts;
CefString url;
url.FromASCII("http://www.example.com");
ASSERT_TRUE(CefParseURL(url, parts));
EXPECT_TRUE(CefParseURL(url, parts));
CefString spec(&parts.spec);
ASSERT_EQ(spec, "http://www.example.com/");
ASSERT_EQ(parts.username.length, (size_t)0);
ASSERT_EQ(parts.password.length, (size_t)0);
EXPECT_EQ(spec, "http://www.example.com/");
EXPECT_EQ(parts.username.length, (size_t)0);
EXPECT_EQ(parts.password.length, (size_t)0);
CefString scheme(&parts.scheme);
ASSERT_EQ(scheme, "http");
EXPECT_EQ(scheme, "http");
CefString host(&parts.host);
ASSERT_EQ(host, "www.example.com");
ASSERT_EQ(parts.port.length, (size_t)0);
EXPECT_EQ(host, "www.example.com");
EXPECT_EQ(parts.port.length, (size_t)0);
CefString path(&parts.path);
ASSERT_EQ(path, "/");
ASSERT_EQ(parts.query.length, (size_t)0);
EXPECT_EQ(path, "/");
EXPECT_EQ(parts.query.length, (size_t)0);
}
// Parse the URL using scheme, host and path.
@@ -108,20 +108,20 @@ TEST(URLTest, ParseURL) {
CefURLParts parts;
CefString url;
url.FromASCII("http://www.example.com/path/to.html");
ASSERT_TRUE(CefParseURL(url, parts));
EXPECT_TRUE(CefParseURL(url, parts));
CefString spec(&parts.spec);
ASSERT_EQ(spec, "http://www.example.com/path/to.html");
ASSERT_EQ(parts.username.length, (size_t)0);
ASSERT_EQ(parts.password.length, (size_t)0);
EXPECT_EQ(spec, "http://www.example.com/path/to.html");
EXPECT_EQ(parts.username.length, (size_t)0);
EXPECT_EQ(parts.password.length, (size_t)0);
CefString scheme(&parts.scheme);
ASSERT_EQ(scheme, "http");
EXPECT_EQ(scheme, "http");
CefString host(&parts.host);
ASSERT_EQ(host, "www.example.com");
ASSERT_EQ(parts.port.length, (size_t)0);
EXPECT_EQ(host, "www.example.com");
EXPECT_EQ(parts.port.length, (size_t)0);
CefString path(&parts.path);
ASSERT_EQ(path, "/path/to.html");
ASSERT_EQ(parts.query.length, (size_t)0);
EXPECT_EQ(path, "/path/to.html");
EXPECT_EQ(parts.query.length, (size_t)0);
}
// Parse the URL using scheme, host, path and query.
@@ -129,21 +129,21 @@ TEST(URLTest, ParseURL) {
CefURLParts parts;
CefString url;
url.FromASCII("http://www.example.com/path/to.html?foo=test&bar=test2");
ASSERT_TRUE(CefParseURL(url, parts));
EXPECT_TRUE(CefParseURL(url, parts));
CefString spec(&parts.spec);
ASSERT_EQ(spec, "http://www.example.com/path/to.html?foo=test&bar=test2");
ASSERT_EQ(parts.username.length, (size_t)0);
ASSERT_EQ(parts.password.length, (size_t)0);
EXPECT_EQ(spec, "http://www.example.com/path/to.html?foo=test&bar=test2");
EXPECT_EQ(parts.username.length, (size_t)0);
EXPECT_EQ(parts.password.length, (size_t)0);
CefString scheme(&parts.scheme);
ASSERT_EQ(scheme, "http");
EXPECT_EQ(scheme, "http");
CefString host(&parts.host);
ASSERT_EQ(host, "www.example.com");
ASSERT_EQ(parts.port.length, (size_t)0);
EXPECT_EQ(host, "www.example.com");
EXPECT_EQ(parts.port.length, (size_t)0);
CefString path(&parts.path);
ASSERT_EQ(path, "/path/to.html");
EXPECT_EQ(path, "/path/to.html");
CefString query(&parts.query);
ASSERT_EQ(query, "foo=test&bar=test2");
EXPECT_EQ(query, "foo=test&bar=test2");
}
// Parse the URL using all the various components.
@@ -152,25 +152,25 @@ TEST(URLTest, ParseURL) {
CefString url;
url.FromASCII(
"http://user:pass@www.example.com:88/path/to.html?foo=test&bar=test2");
ASSERT_TRUE(CefParseURL(url, parts));
EXPECT_TRUE(CefParseURL(url, parts));
CefString spec(&parts.spec);
ASSERT_EQ(spec,
EXPECT_EQ(spec,
"http://user:pass@www.example.com:88/path/to.html?foo=test&bar=test2");
CefString scheme(&parts.scheme);
ASSERT_EQ(scheme, "http");
EXPECT_EQ(scheme, "http");
CefString username(&parts.username);
ASSERT_EQ(username, "user");
EXPECT_EQ(username, "user");
CefString password(&parts.password);
ASSERT_EQ(password, "pass");
EXPECT_EQ(password, "pass");
CefString host(&parts.host);
ASSERT_EQ(host, "www.example.com");
EXPECT_EQ(host, "www.example.com");
CefString port(&parts.port);
ASSERT_EQ(port, "88");
EXPECT_EQ(port, "88");
CefString path(&parts.path);
ASSERT_EQ(path, "/path/to.html");
EXPECT_EQ(path, "/path/to.html");
CefString query(&parts.query);
ASSERT_EQ(query, "foo=test&bar=test2");
EXPECT_EQ(query, "foo=test&bar=test2");
}
// Parse an invalid URL.
@@ -178,6 +178,19 @@ TEST(URLTest, ParseURL) {
CefURLParts parts;
CefString url;
url.FromASCII("www.example.com");
ASSERT_FALSE(CefParseURL(url, parts));
EXPECT_FALSE(CefParseURL(url, parts));
}
}
TEST(URLTest, GetMimeType) {
CefString mime_type;
mime_type = CefGetMimeType("html");
EXPECT_STREQ("text/html", mime_type.ToString().c_str());
mime_type = CefGetMimeType("txt");
EXPECT_STREQ("text/plain", mime_type.ToString().c_str());
mime_type = CefGetMimeType("gif");
EXPECT_STREQ("image/gif", mime_type.ToString().c_str());
}