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

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: Fix use-after-free bug 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 using URLRequestHttpJob::SetPriority;
32 using URLRequestHttpJob::Start;
33 using URLRequestHttpJob::Kill;
34 using URLRequestHttpJob::priority;
35
36 protected:
37 virtual ~TestURLRequestHttpJob() {}
38 };
39
40 class URLRequestHttpJobTest : public ::testing::Test {
41 protected:
42 URLRequestHttpJobTest()
43 : req_(GURL("http://www.example.com"), &delegate_, &context_, NULL) {
44 context_.set_http_transaction_factory(&network_layer_);
45 }
46
47 MockNetworkLayer network_layer_;
48 TestURLRequestContext context_;
49 TestDelegate delegate_;
50 TestURLRequest req_;
51 };
52
53 // Make sure that SetPriority actually sets the URLRequestHttpJob's
54 // priority, both before and after start.
55 TEST_F(URLRequestHttpJobTest, SetPriorityBasic) {
56 scoped_refptr<TestURLRequestHttpJob> job(new TestURLRequestHttpJob(&req_));
57 EXPECT_EQ(DEFAULT_PRIORITY, job->priority());
58
59 job->SetPriority(LOW);
60 EXPECT_EQ(LOW, job->priority());
61
62 job->Start();
63 EXPECT_EQ(LOW, job->priority());
64
65 job->SetPriority(MEDIUM);
66 EXPECT_EQ(MEDIUM, job->priority());
67 }
68
69 // Make sure that URLRequestHttpJob passes on its priority to its
70 // transaction on start.
71 TEST_F(URLRequestHttpJobTest, SetTransactionPriorityOnStart) {
72 scoped_refptr<TestURLRequestHttpJob> job(new TestURLRequestHttpJob(&req_));
73 job->SetPriority(LOW);
74
75 EXPECT_FALSE(network_layer_.last_transaction());
76
77 job->Start();
78
79 ASSERT_TRUE(network_layer_.last_transaction());
80 EXPECT_EQ(LOW, network_layer_.last_transaction()->priority());
81 }
82
83 // Make sure that URLRequestHttpJob passes on its priority updates to
84 // its transaction.
85 TEST_F(URLRequestHttpJobTest, SetTransactionPriority) {
86 scoped_refptr<TestURLRequestHttpJob> job(new TestURLRequestHttpJob(&req_));
87 job->SetPriority(LOW);
88 job->Start();
89 ASSERT_TRUE(network_layer_.last_transaction());
90 EXPECT_EQ(LOW, network_layer_.last_transaction()->priority());
91
92 job->SetPriority(HIGHEST);
93 EXPECT_EQ(HIGHEST, network_layer_.last_transaction()->priority());
94 }
95
96 // Make sure that URLRequestHttpJob passes on its priority updates to
97 // newly-created transactions after the first one.
98 TEST_F(URLRequestHttpJobTest, SetSubsequentTransactionPriority) {
99 scoped_refptr<TestURLRequestHttpJob> job(new TestURLRequestHttpJob(&req_));
100 job->Start();
101
102 job->SetPriority(LOW);
103 ASSERT_TRUE(network_layer_.last_transaction());
104 EXPECT_EQ(LOW, network_layer_.last_transaction()->priority());
105
106 job->Kill();
107 network_layer_.ClearLastTransaction();
108
109 // Creates a second transaction.
110 job->Start();
111 ASSERT_TRUE(network_layer_.last_transaction());
112 EXPECT_EQ(LOW, network_layer_.last_transaction()->priority());
113 }
114
115 } // namespace
116
117 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698