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

Unified Diff: net/url_request/url_request_http_job_unittest.cc

Issue 12701011: [Net] Propagate priority changes from URLRequest to HttpTransaction (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix leaks Created 7 years, 9 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_http_job.cc ('k') | net/url_request/url_request_job.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
new file mode 100644
index 0000000000000000000000000000000000000000..9469a67df2551741068a8cf1ba9de04d1b2a810c
--- /dev/null
+++ b/net/url_request/url_request_http_job_unittest.cc
@@ -0,0 +1,120 @@
+// 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 "googleurl/src/gurl.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()) {}
+
+ using URLRequestHttpJob::SetPriority;
+ using URLRequestHttpJob::Start;
+ using URLRequestHttpJob::Kill;
+ using URLRequestHttpJob::priority;
+
+ protected:
+ virtual ~TestURLRequestHttpJob() {}
+};
+
+class URLRequestHttpJobTest : public ::testing::Test {
+ protected:
+ URLRequestHttpJobTest()
+ : req_(GURL("http://www.example.com"), &delegate_, &context_, NULL) {
+ context_.set_http_transaction_factory(&network_layer_);
+ }
+
+ MockNetworkLayer network_layer_;
+ TestURLRequestContext context_;
+ TestDelegate delegate_;
+ TestURLRequest req_;
+};
+
+// Make sure that SetPriority actually sets the URLRequestHttpJob's
+// priority, both before and after start.
+TEST_F(URLRequestHttpJobTest, SetPriorityBasic) {
+ scoped_refptr<TestURLRequestHttpJob> job(new TestURLRequestHttpJob(&req_));
+ EXPECT_EQ(DEFAULT_PRIORITY, job->priority());
+
+ job->SetPriority(LOWEST);
+ EXPECT_EQ(LOWEST, job->priority());
+
+ job->SetPriority(LOW);
+ EXPECT_EQ(LOW, job->priority());
+
+ job->Start();
+ EXPECT_EQ(LOW, job->priority());
+
+ job->SetPriority(MEDIUM);
+ EXPECT_EQ(MEDIUM, job->priority());
+}
+
+// Make sure that URLRequestHttpJob passes on its priority to its
+// transaction on start.
+TEST_F(URLRequestHttpJobTest, SetTransactionPriorityOnStart) {
+ scoped_refptr<TestURLRequestHttpJob> job(new TestURLRequestHttpJob(&req_));
+ job->SetPriority(LOW);
+
+ EXPECT_FALSE(network_layer_.last_transaction());
+
+ job->Start();
+
+ ASSERT_TRUE(network_layer_.last_transaction());
+ EXPECT_EQ(LOW, network_layer_.last_transaction()->priority());
+}
+
+// Make sure that URLRequestHttpJob passes on its priority updates to
+// its transaction.
+TEST_F(URLRequestHttpJobTest, SetTransactionPriority) {
+ scoped_refptr<TestURLRequestHttpJob> job(new TestURLRequestHttpJob(&req_));
+ job->SetPriority(LOW);
+ job->Start();
+ ASSERT_TRUE(network_layer_.last_transaction());
+ EXPECT_EQ(LOW, network_layer_.last_transaction()->priority());
+
+ job->SetPriority(HIGHEST);
+ EXPECT_EQ(HIGHEST, network_layer_.last_transaction()->priority());
+}
+
+// Make sure that URLRequestHttpJob passes on its priority updates to
+// newly-created transactions after the first one.
+TEST_F(URLRequestHttpJobTest, SetSubsequentTransactionPriority) {
+ scoped_refptr<TestURLRequestHttpJob> job(new TestURLRequestHttpJob(&req_));
+ job->Start();
+
+ job->SetPriority(LOW);
+ ASSERT_TRUE(network_layer_.last_transaction());
+ EXPECT_EQ(LOW, network_layer_.last_transaction()->priority());
+
+ job->Kill();
+ network_layer_.ClearLastTransaction();
+
+ // Creates a second transaction.
+ job->Start();
+ ASSERT_TRUE(network_layer_.last_transaction());
+ EXPECT_EQ(LOW, network_layer_.last_transaction()->priority());
+}
+
+} // namespace
+
+} // namespace net
« no previous file with comments | « net/url_request/url_request_http_job.cc ('k') | net/url_request/url_request_job.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698