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

Unified Diff: net/url_request/url_request_data_job_unittest.cc

Issue 294193002: Set response headers for data URL. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/url_request/url_request_data_job.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/url_request/url_request_data_job_unittest.cc
diff --git a/net/url_request/url_request_data_job_unittest.cc b/net/url_request/url_request_data_job_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..81903be2516828c7772a99ea50afd0f760f16e61
--- /dev/null
+++ b/net/url_request/url_request_data_job_unittest.cc
@@ -0,0 +1,89 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <string>
+
+#include "base/memory/ref_counted.h"
+#include "net/base/net_errors.h"
+#include "net/http/http_response_headers.h"
+#include "net/http/http_version.h"
+#include "net/url_request/url_request_data_job.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "url/gurl.h"
+
+namespace net {
+
+TEST(BuildResponseTest, Simple) {
+ std::string mime_type;
+ std::string charset;
+ std::string data;
+ scoped_refptr<net::HttpResponseHeaders> headers(
+ new net::HttpResponseHeaders(std::string()));
+
+ ASSERT_EQ(
+ net::OK,
+ URLRequestDataJob::BuildResponse(
+ GURL("data:,Hello"), &mime_type, &charset, &data, headers.get()));
+
+ EXPECT_EQ("text/plain", mime_type);
+ EXPECT_EQ("US-ASCII", charset);
+ EXPECT_EQ("Hello", data);
+
+ const net::HttpVersion& version = headers->GetParsedHttpVersion();
+ EXPECT_EQ(1, version.major_value());
+ EXPECT_EQ(1, version.minor_value());
+ EXPECT_EQ("OK", headers->GetStatusText());
+ std::string value;
+ EXPECT_TRUE(headers->GetNormalizedHeader("Content-Type", &value));
+ EXPECT_EQ(value, "text/plain;charset=US-ASCII");
+ value.clear();
+ EXPECT_TRUE(
+ headers->GetNormalizedHeader("Access-Control-Allow-Origin", &value));
+ EXPECT_EQ(value, "*");
+}
+
+TEST(BuildResponseTest, InvalidInput) {
+ std::string mime_type;
+ std::string charset;
+ std::string data;
+ scoped_refptr<net::HttpResponseHeaders> headers(
+ new net::HttpResponseHeaders(std::string()));
+
+ EXPECT_EQ(
+ net::ERR_INVALID_URL,
+ URLRequestDataJob::BuildResponse(
+ GURL("bogus"), &mime_type, &charset, &data, headers.get()));
+}
+
+TEST(BuildResponseTest, InvalidMimeType) {
+ std::string mime_type;
+ std::string charset;
+ std::string data;
+ scoped_refptr<net::HttpResponseHeaders> headers(
+ new net::HttpResponseHeaders(std::string()));
+
+ // MIME type contains delimiters. Must be rejected.
+ EXPECT_EQ(
+ net::ERR_INVALID_URL,
+ URLRequestDataJob::BuildResponse(
+ GURL("data:f(o/b)r,test"),
+ &mime_type, &charset, &data, headers.get()));
+}
+
+TEST(BuildResponseTest, InvalidCharset) {
+ std::string mime_type;
+ std::string charset;
+ std::string data;
+ scoped_refptr<net::HttpResponseHeaders> headers(
+ new net::HttpResponseHeaders(std::string()));
+
+ // MIME type contains delimiters. Must be rejected.
+ EXPECT_EQ(
+ net::ERR_INVALID_URL,
+ URLRequestDataJob::BuildResponse(
+ GURL("data:text/html;charset=(),test"),
+ &mime_type, &charset, &data, headers.get()));
+}
+
+} // namespace net
« no previous file with comments | « net/url_request/url_request_data_job.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698