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

Unified Diff: net/url_request/url_request_http_job_unittest.cc

Issue 380003002: Improve testing for SDCH. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed Isolation test for ChromeOS. Created 6 years, 4 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_context_storage.cc ('k') | net/url_request/url_request_test_util.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/url_request/url_request_http_job_unittest.cc
diff --git a/net/url_request/url_request_http_job_unittest.cc b/net/url_request/url_request_http_job_unittest.cc
index 203d6d077da9e7841eaf023fa530b5669470ef03..7b93b35b38bfe6028be7a15d620ab4c692494121 100644
--- a/net/url_request/url_request_http_job_unittest.cc
+++ b/net/url_request/url_request_http_job_unittest.cc
@@ -54,6 +54,37 @@ class URLRequestHttpJobTest : public ::testing::Test {
context_.set_http_transaction_factory(&network_layer_);
}
+ bool TransactionAcceptsSdchEncoding() {
+ base::WeakPtr<MockNetworkTransaction> transaction(
+ network_layer_.last_transaction());
+ EXPECT_TRUE(transaction);
+ if (!transaction) return false;
+
+ const HttpRequestInfo* request_info = transaction->request();
+ EXPECT_TRUE(request_info);
+ if (!request_info) return false;
+
+ std::string encoding_headers;
+ bool get_success = request_info->extra_headers.GetHeader(
+ "Accept-Encoding", &encoding_headers);
+ EXPECT_TRUE(get_success);
+ if (!get_success) return false;
+
+ // This check isn't wrapped with EXPECT* macros because different
+ // results from this function may be expected in different tests.
+ std::vector<std::string> tokens;
+ size_t num_tokens = Tokenize(encoding_headers, ",", &tokens);
+ for (size_t i = 0; i < num_tokens; i++) {
+ if (!base::strncasecmp(tokens[i].data(), "sdch", tokens[i].length()))
+ return true;
+ }
+ return false;
+ }
+
+ void EnableSdch() {
+ context_.SetSdchManager(scoped_ptr<SdchManager>(new SdchManager).Pass());
+ }
+
MockNetworkLayer network_layer_;
TestURLRequestContext context_;
TestDelegate delegate_;
@@ -125,6 +156,24 @@ TEST_F(URLRequestHttpJobTest, SetSubsequentTransactionPriority) {
EXPECT_EQ(LOW, network_layer_.last_transaction()->priority());
}
+// Confirm we do advertise SDCH encoding in the case of a GET.
+TEST_F(URLRequestHttpJobTest, SdchAdvertisementGet) {
+ EnableSdch();
+ req_.set_method("GET"); // Redundant with default.
+ scoped_refptr<TestURLRequestHttpJob> job(new TestURLRequestHttpJob(&req_));
+ job->Start();
+ EXPECT_TRUE(TransactionAcceptsSdchEncoding());
+}
+
+// Confirm we don't advertise SDCH encoding in the case of a POST.
+TEST_F(URLRequestHttpJobTest, SdchAdvertisementPost) {
+ EnableSdch();
+ req_.set_method("POST");
+ scoped_refptr<TestURLRequestHttpJob> job(new TestURLRequestHttpJob(&req_));
+ job->Start();
+ EXPECT_FALSE(TransactionAcceptsSdchEncoding());
+}
+
// This base class just serves to set up some things before the TestURLRequest
// constructor is called.
class URLRequestHttpJobWebSocketTestBase : public ::testing::Test {
« no previous file with comments | « net/url_request/url_request_context_storage.cc ('k') | net/url_request/url_request_test_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698