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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "net/url_request/url_request_http_job.h"
6
7 #include "base/memory/ref_counted.h"
8 #include "net/http/http_transaction_unittest.h"
9 #include "net/url_request/url_request_test_util.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 namespace net {
13
14 class URLRequestHttpJobTest : public ::testing::Test {
15 protected:
16 URLRequestHttpJob* MakeHttpJob(
17 URLRequest* request,
18 NetworkDelegate* network_delegate,
19 const std::string& scheme) const {
20 return static_cast<URLRequestHttpJob*>(
21 URLRequestHttpJob::Factory(request, network_delegate, scheme));
22 }
23
24 bool HttpJobHasTransaction(const URLRequestHttpJob& job) const {
25 return job.transaction_ != NULL;
26 }
27
28 RequestPriority GetJobPriority(const URLRequestHttpJob& job) const {
29 return job.request_info_.priority;
30 }
31
32 RequestPriority GetJobTransactionPriority(
33 const URLRequestHttpJob& job) const {
34 const MockNetworkTransaction* transaction =
35 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
36 return transaction->priority();
37 }
38
39 void StartJob(const scoped_refptr<URLRequestHttpJob>& job) const {
40 job->Start();
41 }
42
43 void SetJobPriority(const scoped_refptr<URLRequestHttpJob>& job,
44 RequestPriority priority) const {
45 job->SetPriority(priority);
46 }
47 };
48
49 // Make sure that URLRequestHttpJob passes on its priority updates to
50 // its transaction.
51 TEST_F(URLRequestHttpJobTest, Priority) {
52 MockNetworkLayer network_layer;
53 net::TestURLRequestContext context;
54 context.set_http_transaction_factory(&network_layer);
55
56 net::TestDelegate d;
57 net::TestURLRequest req(GURL("http://www.example.com"), &d, &context, NULL);
58
59 scoped_refptr<URLRequestHttpJob> job = MakeHttpJob(&req, NULL, "http");
60 EXPECT_FALSE(HttpJobHasTransaction(*job));
61 EXPECT_EQ(LOWEST, GetJobPriority(*job));
62
63 req.SetPriority(MEDIUM);
64 // The priority doesn't propagate to the job until Start() is
65 // called.
mmenke 2013/03/13 15:24:38 nit: Think this fits on one line.
akalin 2013/03/13 16:57:14 Done.
66 EXPECT_EQ(LOWEST, GetJobPriority(*job));
67
68 StartJob(job);
69 EXPECT_TRUE(HttpJobHasTransaction(*job));
70 EXPECT_EQ(MEDIUM, GetJobPriority(*job));
71 EXPECT_EQ(MEDIUM, GetJobTransactionPriority(*job));
72
73 SetJobPriority(job, HIGHEST);
74 EXPECT_EQ(HIGHEST, GetJobPriority(*job));
75 EXPECT_EQ(HIGHEST, GetJobTransactionPriority(*job));
76 }
77
78 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698