OLD | NEW |
(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(LOWEST); |
| 60 EXPECT_EQ(LOWEST, 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 |
OLD | NEW |