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

Side by Side Diff: net/http/http_stream_factory_impl_request_unittest.cc

Issue 1952423002: JobController 2: Remove reference between HttpStreamFactoryImpl::Jobs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@Job_Controller_1
Patch Set: fix a include typo Created 4 years, 4 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
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/http/http_stream_factory_impl_request.h" 5 #include "net/http/http_stream_factory_impl_request.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "net/http/http_stream_factory_impl.h" 10 #include "net/http/http_stream_factory_impl.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 request->SetPriority(MEDIUM); 47 request->SetPriority(MEDIUM);
48 EXPECT_EQ(MEDIUM, job_controller->main_job()->priority()); 48 EXPECT_EQ(MEDIUM, job_controller->main_job()->priority());
49 49
50 EXPECT_CALL(request_delegate, OnStreamFailed(_, _)).Times(1); 50 EXPECT_CALL(request_delegate, OnStreamFailed(_, _)).Times(1);
51 job_controller->OnStreamFailed(job_factory.main_job(), ERR_FAILED, 51 job_controller->OnStreamFailed(job_factory.main_job(), ERR_FAILED,
52 SSLConfig()); 52 SSLConfig());
53 53
54 request->SetPriority(IDLE); 54 request->SetPriority(IDLE);
55 EXPECT_EQ(IDLE, job_controller->main_job()->priority()); 55 EXPECT_EQ(IDLE, job_controller->main_job()->priority());
56 } 56 }
57
58 TEST_F(HttpStreamFactoryImplRequestTest, DelayMainJob) {
59 SpdySessionDependencies session_deps(ProxyService::CreateDirect());
60
61 std::unique_ptr<HttpNetworkSession> session =
62 SpdySessionDependencies::SpdyCreateSession(&session_deps);
63
64 StaticSocketDataProvider socket_data;
65 socket_data.set_connect_data(MockConnect(SYNCHRONOUS, ERR_IO_PENDING));
66 session_deps.socket_factory->AddSocketDataProvider(&socket_data);
67
68 HttpStreamFactoryImpl* factory =
69 static_cast<HttpStreamFactoryImpl*>(session->http_stream_factory());
70 MockHttpStreamRequestDelegate request_delegate;
71 HttpStreamFactoryImpl::JobFactory* job_factory =
72 HttpStreamFactoryImplPeer::GetDefaultJobFactory(factory);
73 HttpStreamFactoryImpl::JobController* job_controller =
74 new HttpStreamFactoryImpl::JobController(factory, &request_delegate,
75 session.get(), job_factory);
76 factory->job_controller_set_.insert(base::WrapUnique(job_controller));
77
78 HttpRequestInfo request_info;
79 request_info.method = "GET";
80 request_info.url = GURL("https://www.google.com");
81
82 HttpStreamFactoryImpl::Request request(
83 request_info.url, job_controller, &request_delegate, nullptr,
84 BoundNetLog(), HttpStreamFactoryImpl::Request::HTTP_STREAM);
85 job_controller->request_ = &request;
86
87 HostPortPair server = HostPortPair::FromURL(request_info.url);
88 GURL original_url =
89 job_controller->ApplyHostMappingRules(request_info.url, &server);
90
91 HttpStreamFactoryImpl::Job* job = new HttpStreamFactoryImpl::Job(
92 job_controller, HttpStreamFactoryImpl::MAIN, session.get(), request_info,
93 DEFAULT_PRIORITY, SSLConfig(), SSLConfig(), server, original_url,
94 nullptr);
95 job_controller->main_job_.reset(job);
96 job_controller->AttachJob(job);
97 EXPECT_EQ(DEFAULT_PRIORITY, job->priority());
98
99 AlternativeService alternative_service(net::NPN_HTTP_2, server);
100 HttpStreamFactoryImpl::Job* alternative_job = new HttpStreamFactoryImpl::Job(
101 job_controller, HttpStreamFactoryImpl::ALTERNATIVE, session.get(),
102 request_info, DEFAULT_PRIORITY, SSLConfig(), SSLConfig(), server,
103 original_url, alternative_service, nullptr);
104 job_controller->alternative_job_.reset(alternative_job);
105 job_controller->AttachJob(alternative_job);
106
107 job->WaitFor(alternative_job);
108 EXPECT_EQ(HttpStreamFactoryImpl::Job::STATE_NONE, job->next_state_);
109
110 // Test |alternative_job| resuming the |job| after delay.
111 int wait_time = 1;
112 base::TimeDelta delay = base::TimeDelta::FromMilliseconds(wait_time);
113 job->Resume(alternative_job, delay);
114
115 // Verify |job| has |wait_time_| and there is no |blocking_job_|
116 EXPECT_EQ(delay, job->wait_time_);
117 EXPECT_TRUE(!job->blocking_job_);
118
119 // Start the |job| and verify |job|'s |wait_time_| is cleared.
120 job->Start(request.stream_type());
121
122 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(wait_time + 1));
123 base::RunLoop().RunUntilIdle();
124
125 EXPECT_NE(delay, job->wait_time_);
126 EXPECT_TRUE(job->wait_time_.is_zero());
127 EXPECT_EQ(HttpStreamFactoryImpl::Job::STATE_INIT_CONNECTION_COMPLETE,
128 job->next_state_);
129 }
130
131 } // namespace net 57 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_stream_factory_impl_job_controller_unittest.cc ('k') | net/http/http_stream_factory_test_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698