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

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: Rebase 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 <cstddef>
8
9 #include "base/compiler_specific.h"
10 #include "base/memory/ref_counted.h"
11 #include "googleurl/src/gurl.h"
12 #include "net/base/auth.h"
13 #include "net/http/http_transaction_factory.h"
14 #include "net/http/http_transaction_unittest.h"
15 #include "net/url_request/url_request_status.h"
16 #include "net/url_request/url_request_test_util.h"
17 #include "testing/gtest/include/gtest/gtest.h"
18
19 namespace net {
20
21 namespace {
22
23 // Inherit from URLRequestHttpJob to expose the priority and some
24 // other hidden functions.
25 class TestURLRequestHttpJob : public URLRequestHttpJob {
26 public:
27 explicit TestURLRequestHttpJob(URLRequest* request)
28 : URLRequestHttpJob(request, NULL,
29 request->context()->http_user_agent_settings()) {}
30
31 RequestPriority priority() const {
32 return priority_;
33 }
34
35 using URLRequestHttpJob::SetPriority;
36 using URLRequestHttpJob::Start;
37 using URLRequestHttpJob::Kill;
38
39 protected:
40 virtual ~TestURLRequestHttpJob() {}
41 };
42
43 class URLRequestHttpJobTest : public ::testing::Test {
44 protected:
45 URLRequestHttpJobTest()
46 : req_(GURL("http://www.example.com"), &delegate_, &context_, NULL) {
47 context_.set_http_transaction_factory(&network_layer_);
48 }
49
50 MockNetworkLayer network_layer_;
51 TestURLRequestContext context_;
52 TestDelegate delegate_;
53 TestURLRequest req_;
54 };
55
56 // Make sure that SetPriority actually sets the URLRequestHttpJob's
57 // priority, both before and after start.
58 TEST_F(URLRequestHttpJobTest, SetPriorityBasic) {
59 scoped_refptr<TestURLRequestHttpJob> job(new TestURLRequestHttpJob(&req_));
60 EXPECT_EQ(DEFAULT_PRIORITY, job->priority());
61
62 job->SetPriority(LOW);
63 EXPECT_EQ(LOW, job->priority());
64
65 job->Start();
66 EXPECT_EQ(LOW, job->priority());
67
68 job->SetPriority(MEDIUM);
69 EXPECT_EQ(MEDIUM, job->priority());
70 }
71
72 // Make sure that URLRequestHttpJob passes on its priority to its
73 // transaction on start.
74 TEST_F(URLRequestHttpJobTest, SetTransactionPriorityOnStart) {
75 scoped_refptr<TestURLRequestHttpJob> job(new TestURLRequestHttpJob(&req_));
76 job->SetPriority(LOW);
77
78 EXPECT_FALSE(network_layer_.last_transaction());
79
80 job->Start();
81
82 ASSERT_TRUE(network_layer_.last_transaction());
83 EXPECT_EQ(LOW, network_layer_.last_transaction()->priority());
84 }
85
86 // Make sure that URLRequestHttpJob passes on its priority updates to
87 // its transaction.
88 TEST_F(URLRequestHttpJobTest, SetTransactionPriority) {
89 scoped_refptr<TestURLRequestHttpJob> job(new TestURLRequestHttpJob(&req_));
90 job->SetPriority(LOW);
91 job->Start();
92 ASSERT_TRUE(network_layer_.last_transaction());
93 EXPECT_EQ(LOW, network_layer_.last_transaction()->priority());
94
95 job->SetPriority(HIGHEST);
96 EXPECT_EQ(HIGHEST, network_layer_.last_transaction()->priority());
97 }
98
99 // Make sure that URLRequestHttpJob passes on its priority updates to
100 // newly-created transactions after the first one.
101 TEST_F(URLRequestHttpJobTest, SetSubsequentTransactionPriority) {
102 scoped_refptr<TestURLRequestHttpJob> job(new TestURLRequestHttpJob(&req_));
103 job->Start();
104
105 job->SetPriority(LOW);
106 ASSERT_TRUE(network_layer_.last_transaction());
107 EXPECT_EQ(LOW, network_layer_.last_transaction()->priority());
108
109 job->Kill();
110 network_layer_.ClearLastTransaction();
111
112 // Creates a second transaction.
113 job->Start();
114 ASSERT_TRUE(network_layer_.last_transaction());
115 EXPECT_EQ(LOW, network_layer_.last_transaction()->priority());
116 }
117
118 } // namespace
119
120 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698