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 |
new file mode 100644 |
index 0000000000000000000000000000000000000000..e6481fdece401c7a6f2c6d3a8a8c91b6d2e96ec6 |
--- /dev/null |
+++ b/net/url_request/url_request_http_job_unittest.cc |
@@ -0,0 +1,110 @@ |
+// Copyright (c) 2013 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 "net/url_request/url_request_http_job.h" |
+ |
+#include <cstddef> |
+ |
+#include "base/compiler_specific.h" |
+#include "base/memory/ref_counted.h" |
+#include "net/base/auth.h" |
+#include "net/http/http_transaction_factory.h" |
+#include "net/http/http_transaction_unittest.h" |
+#include "net/url_request/url_request_status.h" |
+#include "net/url_request/url_request_test_util.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+namespace net { |
+ |
+namespace { |
+ |
+// Inherit from URLRequestHttpJob to expose the priority and some |
+// other hidden functions. |
+class TestURLRequestHttpJob : public URLRequestHttpJob { |
+ public: |
+ explicit TestURLRequestHttpJob(URLRequest* request) |
+ : URLRequestHttpJob(request, NULL, |
+ request->context()->http_user_agent_settings()) {} |
+ |
+ RequestPriority GetPriority() const { |
+ return request_info_.priority; |
+ } |
+ |
+ using URLRequestJob::GetStatus; |
+ using URLRequestHttpJob::DestroyTransaction; |
+ using URLRequestHttpJob::RestartTransactionWithAuth; |
+ using URLRequestHttpJob::OnStartCompleted; |
+ using URLRequestHttpJob::Start; |
+ using URLRequestHttpJob::SetPriority; |
+ |
+ protected: |
+ virtual ~TestURLRequestHttpJob() {} |
+}; |
+ |
+class URLRequestHttpJobTest : public ::testing::Test { |
+ protected: |
+ URLRequestHttpJobTest() { |
+ context_.set_http_transaction_factory(&network_layer_); |
+ } |
+ |
+ MockNetworkLayer network_layer_; |
+ TestURLRequestContext context_; |
+}; |
+ |
+// Make sure that URLRequestHttpJob passes on its priority updates to |
+// its transaction. |
+TEST_F(URLRequestHttpJobTest, Priority) { |
+ net::TestDelegate d; |
+ net::TestURLRequest req(GURL("http://www.example.com"), &d, &context_, NULL); |
+ |
+ scoped_refptr<TestURLRequestHttpJob> job(new TestURLRequestHttpJob(&req)); |
+ EXPECT_FALSE(network_layer_.last_transaction()); |
+ EXPECT_EQ(LOWEST, job->GetPriority()); |
+ |
+ req.SetPriority(MEDIUM); |
+ // The priority doesn't propagate to the job until Start() is called. |
+ EXPECT_EQ(LOWEST, job->GetPriority()); |
+ |
+ job->Start(); |
+ ASSERT_TRUE(network_layer_.last_transaction()); |
+ EXPECT_EQ(MEDIUM, job->GetPriority()); |
+ EXPECT_EQ(MEDIUM, network_layer_.last_transaction()->priority()); |
+ |
+ job->SetPriority(HIGHEST); |
+ EXPECT_EQ(HIGHEST, job->GetPriority()); |
+ EXPECT_EQ(HIGHEST, network_layer_.last_transaction()->priority()); |
+} |
+ |
+// Make sure that URLRequestHttpJob passes on its priority updates to |
+// newly-created transactions. |
+TEST_F(URLRequestHttpJobTest, PriorityNewTransaction) { |
+ net::TestDelegate d; |
+ net::TestURLRequest req(GURL("http://www.example.com"), &d, &context_, NULL); |
+ |
+ scoped_refptr<TestURLRequestHttpJob> job(new TestURLRequestHttpJob(&req)); |
+ EXPECT_FALSE(network_layer_.last_transaction()); |
+ |
+ job->Start(); |
+ EXPECT_TRUE(job->GetStatus().is_io_pending()); |
+ |
+ job->SetPriority(HIGHEST); |
+ EXPECT_EQ(HIGHEST, job->GetPriority()); |
+ EXPECT_TRUE(network_layer_.last_transaction()); |
+ EXPECT_EQ(HIGHEST, network_layer_.last_transaction()->priority()); |
+ |
+ MessageLoop::current()->RunUntilIdle(); |
+ EXPECT_FALSE(job->GetStatus().is_io_pending()); |
+ |
+ job->DestroyTransaction(); |
+ network_layer_.ClearLastTransaction(); |
+ |
+ // Create a new transaction. |
+ job->RestartTransactionWithAuth(AuthCredentials()); |
+ EXPECT_TRUE(network_layer_.last_transaction()); |
+ EXPECT_EQ(HIGHEST, network_layer_.last_transaction()->priority()); |
+} |
+ |
+} // namespace |
+ |
+} // namespace net |