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

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: Address comments 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
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..0d5223beefb0d27188106e0c691c0357da49642d
--- /dev/null
+++ b/net/url_request/url_request_http_job_unittest.cc
@@ -0,0 +1,78 @@
+// 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 "base/memory/ref_counted.h"
+#include "net/http/http_transaction_unittest.h"
+#include "net/url_request/url_request_test_util.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace net {
+
+class URLRequestHttpJobTest : public ::testing::Test {
+ protected:
+ URLRequestHttpJob* MakeHttpJob(
+ URLRequest* request,
+ NetworkDelegate* network_delegate,
+ const std::string& scheme) const {
+ return static_cast<URLRequestHttpJob*>(
+ URLRequestHttpJob::Factory(request, network_delegate, scheme));
+ }
+
+ bool HttpJobHasTransaction(const URLRequestHttpJob& job) const {
+ return job.transaction_ != NULL;
+ }
+
+ RequestPriority GetJobPriority(const URLRequestHttpJob& job) const {
+ return job.request_info_.priority;
+ }
+
+ RequestPriority GetJobTransactionPriority(
+ const URLRequestHttpJob& job) const {
+ const MockNetworkTransaction* transaction =
+ static_cast<MockNetworkTransaction*>(job.transaction_.get());
mmenke 2013/03/13 15:24:38 I'd still really like to get rid of this friend re
akalin 2013/03/13 16:57:14 Done. Ended up inheriting from URLRequestHttpJob a
+ return transaction->priority();
+ }
+
+ void StartJob(const scoped_refptr<URLRequestHttpJob>& job) const {
+ job->Start();
+ }
+
+ void SetJobPriority(const scoped_refptr<URLRequestHttpJob>& job,
+ RequestPriority priority) const {
+ job->SetPriority(priority);
+ }
+};
+
+// Make sure that URLRequestHttpJob passes on its priority updates to
+// its transaction.
+TEST_F(URLRequestHttpJobTest, Priority) {
+ MockNetworkLayer network_layer;
+ net::TestURLRequestContext context;
+ context.set_http_transaction_factory(&network_layer);
+
+ net::TestDelegate d;
+ net::TestURLRequest req(GURL("http://www.example.com"), &d, &context, NULL);
+
+ scoped_refptr<URLRequestHttpJob> job = MakeHttpJob(&req, NULL, "http");
+ EXPECT_FALSE(HttpJobHasTransaction(*job));
+ EXPECT_EQ(LOWEST, GetJobPriority(*job));
+
+ req.SetPriority(MEDIUM);
+ // The priority doesn't propagate to the job until Start() is
+ // called.
mmenke 2013/03/13 15:24:38 nit: Think this fits on one line.
akalin 2013/03/13 16:57:14 Done.
+ EXPECT_EQ(LOWEST, GetJobPriority(*job));
+
+ StartJob(job);
+ EXPECT_TRUE(HttpJobHasTransaction(*job));
+ EXPECT_EQ(MEDIUM, GetJobPriority(*job));
+ EXPECT_EQ(MEDIUM, GetJobTransactionPriority(*job));
+
+ SetJobPriority(job, HIGHEST);
+ EXPECT_EQ(HIGHEST, GetJobPriority(*job));
+ EXPECT_EQ(HIGHEST, GetJobTransactionPriority(*job));
+}
+
+} // namespace net

Powered by Google App Engine
This is Rietveld 408576698