| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/net/load_timing_observer.h" | 5 #include "chrome/browser/net/load_timing_observer.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/format_macros.h" | 8 #include "base/format_macros.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
| 11 #include "base/time.h" | 11 #include "base/time.h" |
| 12 #include "content/public/test/test_browser_thread.h" | 12 #include "content/public/test/test_browser_thread.h" |
| 13 #include "net/base/load_flags.h" | 13 #include "net/base/load_flags.h" |
| 14 #include "net/url_request/url_request_netlog_params.h" | 14 #include "net/url_request/url_request_netlog_params.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 using base::TimeDelta; | 19 using base::TimeDelta; |
| 20 using content::BrowserThread; | 20 using content::BrowserThread; |
| 21 using net::NetLog; | 21 using net::NetLog; |
| 22 | 22 |
| 23 class TestLoadTimingObserver : public LoadTimingObserver { |
| 24 public: |
| 25 TestLoadTimingObserver() {} |
| 26 virtual ~TestLoadTimingObserver() {} |
| 27 |
| 28 void IncementTime(base::TimeDelta delta) { |
| 29 current_time_ += delta; |
| 30 } |
| 31 |
| 32 virtual base::TimeTicks GetCurrentTime() const OVERRIDE { |
| 33 return current_time_; |
| 34 } |
| 35 |
| 36 private: |
| 37 base::TimeTicks current_time_; |
| 38 |
| 39 DISALLOW_COPY_AND_ASSIGN(TestLoadTimingObserver); |
| 40 }; |
| 41 |
| 23 // Serves to identify the current thread as the IO thread. | 42 // Serves to identify the current thread as the IO thread. |
| 24 class LoadTimingObserverTest : public testing::Test { | 43 class LoadTimingObserverTest : public testing::Test { |
| 25 public: | 44 public: |
| 26 LoadTimingObserverTest() : io_thread_(BrowserThread::IO, &message_loop_) { | 45 LoadTimingObserverTest() : io_thread_(BrowserThread::IO, &message_loop_) { |
| 27 } | 46 } |
| 28 | 47 |
| 48 protected: |
| 49 TestLoadTimingObserver observer_; |
| 50 |
| 29 private: | 51 private: |
| 30 MessageLoop message_loop_; | 52 MessageLoop message_loop_; |
| 31 content::TestBrowserThread io_thread_; | 53 content::TestBrowserThread io_thread_; |
| 32 }; | 54 }; |
| 33 | 55 |
| 34 base::TimeTicks current_time; | 56 void AddStartEntry(LoadTimingObserver& observer, |
| 57 const NetLog::Source& source, |
| 58 NetLog::EventType type) { |
| 59 net::NetLog::Entry entry(type, |
| 60 source, |
| 61 NetLog::PHASE_BEGIN, |
| 62 NULL, |
| 63 NetLog::LOG_BASIC); |
| 64 observer.OnAddEntry(entry); |
| 65 } |
| 35 | 66 |
| 36 void AddStartEntry(LoadTimingObserver& observer, | 67 void AddStartEntry(LoadTimingObserver& observer, |
| 37 const NetLog::Source& source, | 68 const NetLog::Source& source, |
| 38 NetLog::EventType type, | 69 NetLog::EventType type, |
| 39 NetLog::EventParameters* params) { | 70 const NetLog::ParametersCallback& params_callback) { |
| 40 observer.OnAddEntry(type, current_time, source, NetLog::PHASE_BEGIN, params); | 71 net::NetLog::Entry entry(type, |
| 72 source, |
| 73 NetLog::PHASE_BEGIN, |
| 74 ¶ms_callback, |
| 75 NetLog::LOG_BASIC); |
| 76 observer.OnAddEntry(entry); |
| 41 } | 77 } |
| 42 | 78 |
| 43 void AddEndEntry(LoadTimingObserver& observer, | 79 void AddEndEntry(LoadTimingObserver& observer, |
| 44 const NetLog::Source& source, | 80 const NetLog::Source& source, |
| 45 NetLog::EventType type, | 81 NetLog::EventType type) { |
| 46 NetLog::EventParameters* params) { | 82 net::NetLog::Entry entry(type, |
| 47 observer.OnAddEntry(type, current_time, source, NetLog::PHASE_END, params); | 83 source, |
| 84 NetLog::PHASE_END, |
| 85 NULL, |
| 86 NetLog::LOG_BASIC); |
| 87 observer.OnAddEntry(entry); |
| 48 } | 88 } |
| 49 | 89 |
| 50 void AddStartURLRequestEntries(LoadTimingObserver& observer, | 90 void AddStartURLRequestEntries(LoadTimingObserver& observer, |
| 51 uint32 id, | 91 uint32 id, |
| 52 bool request_timing) { | 92 bool request_timing) { |
| 53 scoped_refptr<net::URLRequestStartEventParameters> params( | |
| 54 new net::URLRequestStartEventParameters( | |
| 55 GURL(base::StringPrintf("http://req%d", id)), | |
| 56 "GET", | |
| 57 request_timing ? net::LOAD_ENABLE_LOAD_TIMING : 0, | |
| 58 net::LOW)); | |
| 59 NetLog::Source source(NetLog::SOURCE_URL_REQUEST, id); | 93 NetLog::Source source(NetLog::SOURCE_URL_REQUEST, id); |
| 60 AddStartEntry(observer, source, NetLog::TYPE_REQUEST_ALIVE, NULL); | 94 AddStartEntry(observer, source, NetLog::TYPE_REQUEST_ALIVE); |
| 61 AddStartEntry(observer, | 95 |
| 62 source, | 96 GURL url(base::StringPrintf("http://req%d", id)); |
| 63 NetLog::TYPE_URL_REQUEST_START_JOB, | 97 std::string method = "GET"; |
| 64 params.get()); | 98 AddStartEntry( |
| 99 observer, |
| 100 source, |
| 101 NetLog::TYPE_URL_REQUEST_START_JOB, |
| 102 base::Bind(&net::NetLogURLRequestStartCallback, |
| 103 &url, |
| 104 &method, |
| 105 request_timing ? net::LOAD_ENABLE_LOAD_TIMING : 0, |
| 106 net::LOW)); |
| 65 } | 107 } |
| 66 | 108 |
| 67 void AddEndURLRequestEntries(LoadTimingObserver& observer, uint32 id) { | 109 void AddEndURLRequestEntries(LoadTimingObserver& observer, uint32 id) { |
| 68 NetLog::Source source(NetLog::SOURCE_URL_REQUEST, id); | 110 NetLog::Source source(NetLog::SOURCE_URL_REQUEST, id); |
| 69 AddEndEntry(observer, source, NetLog::TYPE_REQUEST_ALIVE, NULL); | 111 AddEndEntry(observer, source, NetLog::TYPE_REQUEST_ALIVE); |
| 70 AddEndEntry(observer, | 112 AddEndEntry(observer, source, NetLog::TYPE_URL_REQUEST_START_JOB); |
| 71 source, | |
| 72 NetLog::TYPE_URL_REQUEST_START_JOB, | |
| 73 NULL); | |
| 74 } | 113 } |
| 75 | 114 |
| 76 void AddStartHTTPStreamJobEntries(LoadTimingObserver& observer, uint32 id) { | 115 void AddStartHTTPStreamJobEntries(LoadTimingObserver& observer, uint32 id) { |
| 77 NetLog::Source source(NetLog::SOURCE_HTTP_STREAM_JOB, id); | 116 NetLog::Source source(NetLog::SOURCE_HTTP_STREAM_JOB, id); |
| 78 AddStartEntry(observer, source, NetLog::TYPE_HTTP_STREAM_JOB, NULL); | 117 AddStartEntry(observer, source, NetLog::TYPE_HTTP_STREAM_JOB); |
| 79 } | 118 } |
| 80 | 119 |
| 81 void AddEndHTTPStreamJobEntries(LoadTimingObserver& observer, uint32 id) { | 120 void AddEndHTTPStreamJobEntries(LoadTimingObserver& observer, uint32 id) { |
| 82 NetLog::Source source(NetLog::SOURCE_HTTP_STREAM_JOB, id); | 121 NetLog::Source source(NetLog::SOURCE_HTTP_STREAM_JOB, id); |
| 83 AddEndEntry(observer, source, NetLog::TYPE_HTTP_STREAM_JOB, NULL); | 122 AddEndEntry(observer, source, NetLog::TYPE_HTTP_STREAM_JOB); |
| 84 } | 123 } |
| 85 | 124 |
| 86 void AddStartConnectJobEntries(LoadTimingObserver& observer, uint32 id) { | 125 void AddStartConnectJobEntries(LoadTimingObserver& observer, uint32 id) { |
| 87 NetLog::Source source(NetLog::SOURCE_CONNECT_JOB, id); | 126 NetLog::Source source(NetLog::SOURCE_CONNECT_JOB, id); |
| 88 AddStartEntry(observer, source, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB, NULL); | 127 AddStartEntry(observer, source, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB); |
| 89 } | 128 } |
| 90 | 129 |
| 91 void AddEndConnectJobEntries(LoadTimingObserver& observer, uint32 id) { | 130 void AddEndConnectJobEntries(LoadTimingObserver& observer, uint32 id) { |
| 92 NetLog::Source source(NetLog::SOURCE_CONNECT_JOB, id); | 131 NetLog::Source source(NetLog::SOURCE_CONNECT_JOB, id); |
| 93 AddEndEntry(observer, source, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB, NULL); | 132 AddEndEntry(observer, source, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB); |
| 94 } | 133 } |
| 95 | 134 |
| 96 void AddStartSocketEntries(LoadTimingObserver& observer, uint32 id) { | 135 void AddStartSocketEntries(LoadTimingObserver& observer, uint32 id) { |
| 97 NetLog::Source source(NetLog::SOURCE_SOCKET, id); | 136 NetLog::Source source(NetLog::SOURCE_SOCKET, id); |
| 98 AddStartEntry(observer, source, NetLog::TYPE_SOCKET_ALIVE, NULL); | 137 AddStartEntry(observer, source, NetLog::TYPE_SOCKET_ALIVE); |
| 99 } | 138 } |
| 100 | 139 |
| 101 void AddEndSocketEntries(LoadTimingObserver& observer, uint32 id) { | 140 void AddEndSocketEntries(LoadTimingObserver& observer, uint32 id) { |
| 102 NetLog::Source source(NetLog::SOURCE_SOCKET, id); | 141 NetLog::Source source(NetLog::SOURCE_SOCKET, id); |
| 103 AddEndEntry(observer, source, NetLog::TYPE_SOCKET_ALIVE, NULL); | 142 AddEndEntry(observer, source, NetLog::TYPE_SOCKET_ALIVE); |
| 104 } | 143 } |
| 105 | 144 |
| 106 void BindURLRequestToHTTPStreamJob(LoadTimingObserver& observer, | 145 void BindURLRequestToHTTPStreamJob(LoadTimingObserver& observer, |
| 107 NetLog::Source url_request_source, | 146 NetLog::Source url_request_source, |
| 108 NetLog::Source http_stream_job_source) { | 147 NetLog::Source http_stream_job_source) { |
| 109 scoped_refptr<net::NetLogSourceParameter> params( | |
| 110 new net::NetLogSourceParameter("source_dependency", | |
| 111 http_stream_job_source)); | |
| 112 AddStartEntry(observer, | 148 AddStartEntry(observer, |
| 113 url_request_source, | 149 url_request_source, |
| 114 NetLog::TYPE_HTTP_STREAM_REQUEST_BOUND_TO_JOB, | 150 NetLog::TYPE_HTTP_STREAM_REQUEST_BOUND_TO_JOB, |
| 115 params.get()); | 151 http_stream_job_source.ToEventParametersCallback()); |
| 116 } | 152 } |
| 117 | 153 |
| 118 void BindHTTPStreamJobToConnectJob(LoadTimingObserver& observer, | 154 void BindHTTPStreamJobToConnectJob(LoadTimingObserver& observer, |
| 119 NetLog::Source& http_stream_job_source, | 155 NetLog::Source& http_stream_job_source, |
| 120 NetLog::Source& connect_source) { | 156 NetLog::Source& connect_source) { |
| 121 scoped_refptr<net::NetLogSourceParameter> params( | |
| 122 new net::NetLogSourceParameter("source_dependency", connect_source)); | |
| 123 AddStartEntry(observer, | 157 AddStartEntry(observer, |
| 124 http_stream_job_source, | 158 http_stream_job_source, |
| 125 NetLog::TYPE_SOCKET_POOL_BOUND_TO_CONNECT_JOB, | 159 NetLog::TYPE_SOCKET_POOL_BOUND_TO_CONNECT_JOB, |
| 126 params.get()); | 160 connect_source.ToEventParametersCallback()); |
| 127 } | 161 } |
| 128 | 162 |
| 129 void BindHTTPStreamJobToSocket(LoadTimingObserver& observer, | 163 void BindHTTPStreamJobToSocket(LoadTimingObserver& observer, |
| 130 NetLog::Source& http_stream_job_source, | 164 NetLog::Source& http_stream_job_source, |
| 131 NetLog::Source& socket_source) { | 165 NetLog::Source& socket_source) { |
| 132 scoped_refptr<net::NetLogSourceParameter> params( | |
| 133 new net::NetLogSourceParameter("source_dependency", socket_source)); | |
| 134 AddStartEntry(observer, | 166 AddStartEntry(observer, |
| 135 http_stream_job_source, | 167 http_stream_job_source, |
| 136 NetLog::TYPE_SOCKET_POOL_BOUND_TO_SOCKET, | 168 NetLog::TYPE_SOCKET_POOL_BOUND_TO_SOCKET, |
| 137 params.get()); | 169 socket_source.ToEventParametersCallback()); |
| 138 } | 170 } |
| 139 | 171 |
| 140 } // namespace | 172 } // namespace |
| 141 | 173 |
| 142 // Test that net::URLRequest with no load timing flag is not processed. | 174 // Test that net::URLRequest with no load timing flag is not processed. |
| 143 TEST_F(LoadTimingObserverTest, NoLoadTimingEnabled) { | 175 TEST_F(LoadTimingObserverTest, NoLoadTimingEnabled) { |
| 144 LoadTimingObserver observer; | 176 AddStartURLRequestEntries(observer_, 0, false); |
| 145 | 177 LoadTimingObserver::URLRequestRecord* record = |
| 146 AddStartURLRequestEntries(observer, 0, false); | 178 observer_.GetURLRequestRecord(0); |
| 147 LoadTimingObserver::URLRequestRecord* record = | |
| 148 observer.GetURLRequestRecord(0); | |
| 149 ASSERT_TRUE(record == NULL); | 179 ASSERT_TRUE(record == NULL); |
| 150 } | 180 } |
| 151 | 181 |
| 152 // Test that URLRequestRecord is created, deleted and is not growing unbound. | 182 // Test that URLRequestRecord is created, deleted and is not growing unbound. |
| 153 TEST_F(LoadTimingObserverTest, URLRequestRecord) { | 183 TEST_F(LoadTimingObserverTest, URLRequestRecord) { |
| 154 LoadTimingObserver observer; | |
| 155 | |
| 156 // Create record. | 184 // Create record. |
| 157 AddStartURLRequestEntries(observer, 0, true); | 185 AddStartURLRequestEntries(observer_, 0, true); |
| 158 LoadTimingObserver::URLRequestRecord* record = | 186 LoadTimingObserver::URLRequestRecord* record = |
| 159 observer.GetURLRequestRecord(0); | 187 observer_.GetURLRequestRecord(0); |
| 160 ASSERT_FALSE(record == NULL); | 188 ASSERT_FALSE(record == NULL); |
| 161 | 189 |
| 162 // Collect record. | 190 // Collect record. |
| 163 AddEndURLRequestEntries(observer, 0); | 191 AddEndURLRequestEntries(observer_, 0); |
| 164 record = observer.GetURLRequestRecord(0); | 192 record = observer_.GetURLRequestRecord(0); |
| 165 ASSERT_TRUE(record == NULL); | 193 ASSERT_TRUE(record == NULL); |
| 166 | 194 |
| 167 // Check unbound growth. | 195 // Check unbound growth. |
| 168 for (size_t i = 1; i < 1100; ++i) | 196 for (size_t i = 1; i < 1100; ++i) |
| 169 AddStartURLRequestEntries(observer, i, true); | 197 AddStartURLRequestEntries(observer_, i, true); |
| 170 record = observer.GetURLRequestRecord(1); | 198 record = observer_.GetURLRequestRecord(1); |
| 171 ASSERT_TRUE(record == NULL); | 199 ASSERT_TRUE(record == NULL); |
| 172 } | 200 } |
| 173 | 201 |
| 174 // Test that HTTPStreamJobRecord is created, deleted and is not growing unbound. | 202 // Test that HTTPStreamJobRecord is created, deleted and is not growing unbound. |
| 175 TEST_F(LoadTimingObserverTest, HTTPStreamJobRecord) { | 203 TEST_F(LoadTimingObserverTest, HTTPStreamJobRecord) { |
| 176 LoadTimingObserver observer; | |
| 177 | |
| 178 // Create record. | 204 // Create record. |
| 179 AddStartHTTPStreamJobEntries(observer, 0); | 205 AddStartHTTPStreamJobEntries(observer_, 0); |
| 180 ASSERT_FALSE(observer.http_stream_job_to_record_.find(0) == | 206 ASSERT_FALSE(observer_.http_stream_job_to_record_.find(0) == |
| 181 observer.http_stream_job_to_record_.end()); | 207 observer_.http_stream_job_to_record_.end()); |
| 182 | 208 |
| 183 // Collect record. | 209 // Collect record. |
| 184 AddEndHTTPStreamJobEntries(observer, 0); | 210 AddEndHTTPStreamJobEntries(observer_, 0); |
| 185 ASSERT_TRUE(observer.http_stream_job_to_record_.find(0) == | 211 ASSERT_TRUE(observer_.http_stream_job_to_record_.find(0) == |
| 186 observer.http_stream_job_to_record_.end()); | 212 observer_.http_stream_job_to_record_.end()); |
| 187 | 213 |
| 188 // Check unbound growth. | 214 // Check unbound growth. |
| 189 for (size_t i = 1; i < 1100; ++i) | 215 for (size_t i = 1; i < 1100; ++i) |
| 190 AddStartHTTPStreamJobEntries(observer, i); | 216 AddStartHTTPStreamJobEntries(observer_, i); |
| 191 ASSERT_TRUE(observer.http_stream_job_to_record_.find(1) == | 217 ASSERT_TRUE(observer_.http_stream_job_to_record_.find(1) == |
| 192 observer.http_stream_job_to_record_.end()); | 218 observer_.http_stream_job_to_record_.end()); |
| 193 } | 219 } |
| 194 | 220 |
| 195 // Test that ConnectJobRecord is created, deleted and is not growing unbound. | 221 // Test that ConnectJobRecord is created, deleted and is not growing unbound. |
| 196 TEST_F(LoadTimingObserverTest, ConnectJobRecord) { | 222 TEST_F(LoadTimingObserverTest, ConnectJobRecord) { |
| 197 LoadTimingObserver observer; | |
| 198 | |
| 199 // Create record. | 223 // Create record. |
| 200 AddStartConnectJobEntries(observer, 0); | 224 AddStartConnectJobEntries(observer_, 0); |
| 201 ASSERT_FALSE(observer.connect_job_to_record_.find(0) == | 225 ASSERT_FALSE(observer_.connect_job_to_record_.find(0) == |
| 202 observer.connect_job_to_record_.end()); | 226 observer_.connect_job_to_record_.end()); |
| 203 | 227 |
| 204 // Collect record. | 228 // Collect record. |
| 205 AddEndConnectJobEntries(observer, 0); | 229 AddEndConnectJobEntries(observer_, 0); |
| 206 ASSERT_TRUE(observer.connect_job_to_record_.find(0) == | 230 ASSERT_TRUE(observer_.connect_job_to_record_.find(0) == |
| 207 observer.connect_job_to_record_.end()); | 231 observer_.connect_job_to_record_.end()); |
| 208 | 232 |
| 209 // Check unbound growth. | 233 // Check unbound growth. |
| 210 for (size_t i = 1; i < 1100; ++i) | 234 for (size_t i = 1; i < 1100; ++i) |
| 211 AddStartConnectJobEntries(observer, i); | 235 AddStartConnectJobEntries(observer_, i); |
| 212 ASSERT_TRUE(observer.connect_job_to_record_.find(1) == | 236 ASSERT_TRUE(observer_.connect_job_to_record_.find(1) == |
| 213 observer.connect_job_to_record_.end()); | 237 observer_.connect_job_to_record_.end()); |
| 214 } | 238 } |
| 215 | 239 |
| 216 // Test that SocketRecord is created, deleted and is not growing unbound. | 240 // Test that SocketRecord is created, deleted and is not growing unbound. |
| 217 TEST_F(LoadTimingObserverTest, SocketRecord) { | 241 TEST_F(LoadTimingObserverTest, SocketRecord) { |
| 218 LoadTimingObserver observer; | |
| 219 | |
| 220 // Create record. | 242 // Create record. |
| 221 AddStartSocketEntries(observer, 0); | 243 AddStartSocketEntries(observer_, 0); |
| 222 ASSERT_FALSE(observer.socket_to_record_.find(0) == | 244 ASSERT_FALSE(observer_.socket_to_record_.find(0) == |
| 223 observer.socket_to_record_.end()); | 245 observer_.socket_to_record_.end()); |
| 224 | 246 |
| 225 // Collect record. | 247 // Collect record. |
| 226 AddEndSocketEntries(observer, 0); | 248 AddEndSocketEntries(observer_, 0); |
| 227 ASSERT_TRUE(observer.socket_to_record_.find(0) == | 249 ASSERT_TRUE(observer_.socket_to_record_.find(0) == |
| 228 observer.socket_to_record_.end()); | 250 observer_.socket_to_record_.end()); |
| 229 | |
| 230 | 251 |
| 231 // Check unbound growth. | 252 // Check unbound growth. |
| 232 for (size_t i = 1; i < 1100; ++i) | 253 for (size_t i = 1; i < 1100; ++i) |
| 233 AddStartSocketEntries(observer, i); | 254 AddStartSocketEntries(observer_, i); |
| 234 ASSERT_TRUE(observer.socket_to_record_.find(1) == | 255 ASSERT_TRUE(observer_.socket_to_record_.find(1) == |
| 235 observer.socket_to_record_.end()); | 256 observer_.socket_to_record_.end()); |
| 236 } | 257 } |
| 237 | 258 |
| 238 // Test that basic time is set to the request. | 259 // Test that basic time is set to the request. |
| 239 TEST_F(LoadTimingObserverTest, BaseTicks) { | 260 TEST_F(LoadTimingObserverTest, BaseTicks) { |
| 240 LoadTimingObserver observer; | 261 observer_.IncementTime(TimeDelta::FromSeconds(1)); |
| 241 current_time += TimeDelta::FromSeconds(1); | 262 AddStartURLRequestEntries(observer_, 0, true); |
| 242 AddStartURLRequestEntries(observer, 0, true); | 263 |
| 243 | 264 LoadTimingObserver::URLRequestRecord* record = |
| 244 LoadTimingObserver::URLRequestRecord* record = | 265 observer_.GetURLRequestRecord(0); |
| 245 observer.GetURLRequestRecord(0); | |
| 246 ASSERT_EQ(1000000, record->base_ticks.ToInternalValue()); | 266 ASSERT_EQ(1000000, record->base_ticks.ToInternalValue()); |
| 247 } | 267 } |
| 248 | 268 |
| 249 // Test proxy time detection. | 269 // Test proxy time detection. |
| 250 TEST_F(LoadTimingObserverTest, ProxyTime) { | 270 TEST_F(LoadTimingObserverTest, ProxyTime) { |
| 251 LoadTimingObserver observer; | 271 observer_.IncementTime(TimeDelta::FromSeconds(1)); |
| 252 current_time += TimeDelta::FromSeconds(1); | 272 |
| 253 | 273 AddStartURLRequestEntries(observer_, 0, true); |
| 254 AddStartURLRequestEntries(observer, 0, true); | 274 NetLog::Source source(NetLog::SOURCE_URL_REQUEST, 0); |
| 255 NetLog::Source source(NetLog::SOURCE_URL_REQUEST, 0); | 275 |
| 256 | 276 observer_.IncementTime(TimeDelta::FromSeconds(2)); |
| 257 current_time += TimeDelta::FromSeconds(2); | 277 AddStartEntry(observer_, source, NetLog::TYPE_PROXY_SERVICE); |
| 258 AddStartEntry(observer, source, NetLog::TYPE_PROXY_SERVICE, NULL); | 278 observer_.IncementTime(TimeDelta::FromSeconds(3)); |
| 259 current_time += TimeDelta::FromSeconds(3); | 279 AddEndEntry(observer_, source, NetLog::TYPE_PROXY_SERVICE); |
| 260 AddEndEntry(observer, source, NetLog::TYPE_PROXY_SERVICE, NULL); | 280 |
| 261 | 281 LoadTimingObserver::URLRequestRecord* record = |
| 262 LoadTimingObserver::URLRequestRecord* record = | 282 observer_.GetURLRequestRecord(0); |
| 263 observer.GetURLRequestRecord(0); | |
| 264 ASSERT_EQ(2000, record->timing.proxy_start); | 283 ASSERT_EQ(2000, record->timing.proxy_start); |
| 265 ASSERT_EQ(5000, record->timing.proxy_end); | 284 ASSERT_EQ(5000, record->timing.proxy_end); |
| 266 } | 285 } |
| 267 | 286 |
| 268 // Test connect time detection. | 287 // Test connect time detection. |
| 269 TEST_F(LoadTimingObserverTest, ConnectTime) { | 288 TEST_F(LoadTimingObserverTest, ConnectTime) { |
| 270 LoadTimingObserver observer; | 289 observer_.IncementTime(TimeDelta::FromSeconds(1)); |
| 271 current_time += TimeDelta::FromSeconds(1); | 290 |
| 272 | 291 AddStartURLRequestEntries(observer_, 0, true); |
| 273 AddStartURLRequestEntries(observer, 0, true); | |
| 274 NetLog::Source source(NetLog::SOURCE_URL_REQUEST, 0); | 292 NetLog::Source source(NetLog::SOURCE_URL_REQUEST, 0); |
| 275 | 293 |
| 276 NetLog::Source http_stream_job_source(NetLog::SOURCE_HTTP_STREAM_JOB, 1); | 294 NetLog::Source http_stream_job_source(NetLog::SOURCE_HTTP_STREAM_JOB, 1); |
| 277 AddStartHTTPStreamJobEntries(observer, 1); | 295 AddStartHTTPStreamJobEntries(observer_, 1); |
| 278 | 296 |
| 279 current_time += TimeDelta::FromSeconds(2); | 297 observer_.IncementTime(TimeDelta::FromSeconds(2)); |
| 280 AddStartEntry(observer, http_stream_job_source, NetLog::TYPE_SOCKET_POOL, | 298 AddStartEntry(observer_, http_stream_job_source, NetLog::TYPE_SOCKET_POOL); |
| 281 NULL); | 299 observer_.IncementTime(TimeDelta::FromSeconds(3)); |
| 282 current_time += TimeDelta::FromSeconds(3); | 300 AddEndEntry(observer_, http_stream_job_source, NetLog::TYPE_SOCKET_POOL); |
| 283 AddEndEntry(observer, http_stream_job_source, NetLog::TYPE_SOCKET_POOL, NULL); | 301 |
| 284 | 302 BindURLRequestToHTTPStreamJob(observer_, source, http_stream_job_source); |
| 285 BindURLRequestToHTTPStreamJob(observer, source, http_stream_job_source); | 303 |
| 286 | 304 LoadTimingObserver::URLRequestRecord* record = |
| 287 LoadTimingObserver::URLRequestRecord* record = | 305 observer_.GetURLRequestRecord(0); |
| 288 observer.GetURLRequestRecord(0); | |
| 289 ASSERT_EQ(2000, record->timing.connect_start); | 306 ASSERT_EQ(2000, record->timing.connect_start); |
| 290 ASSERT_EQ(5000, record->timing.connect_end); | 307 ASSERT_EQ(5000, record->timing.connect_end); |
| 291 } | 308 } |
| 292 | 309 |
| 293 // Test dns time detection. | 310 // Test dns time detection. |
| 294 TEST_F(LoadTimingObserverTest, DnsTime) { | 311 TEST_F(LoadTimingObserverTest, DnsTime) { |
| 295 LoadTimingObserver observer; | |
| 296 | |
| 297 // Start request. | 312 // Start request. |
| 298 NetLog::Source source(NetLog::SOURCE_URL_REQUEST, 0); | 313 NetLog::Source source(NetLog::SOURCE_URL_REQUEST, 0); |
| 299 AddStartURLRequestEntries(observer, 0, true); | 314 AddStartURLRequestEntries(observer_, 0, true); |
| 300 current_time += TimeDelta::FromSeconds(1); | 315 observer_.IncementTime(TimeDelta::FromSeconds(1)); |
| 301 | 316 |
| 302 // Add resolver entry. | 317 // Add resolver entry. |
| 303 AddStartConnectJobEntries(observer, 1); | 318 AddStartConnectJobEntries(observer_, 1); |
| 304 NetLog::Source connect_source(NetLog::SOURCE_CONNECT_JOB, 1); | 319 NetLog::Source connect_source(NetLog::SOURCE_CONNECT_JOB, 1); |
| 305 AddStartEntry(observer, | 320 AddStartEntry(observer_, connect_source, NetLog::TYPE_HOST_RESOLVER_IMPL); |
| 306 connect_source, | 321 observer_.IncementTime(TimeDelta::FromSeconds(2)); |
| 307 NetLog::TYPE_HOST_RESOLVER_IMPL, | 322 AddEndEntry(observer_, connect_source, NetLog::TYPE_HOST_RESOLVER_IMPL); |
| 308 NULL); | 323 AddEndConnectJobEntries(observer_, 1); |
| 309 current_time += TimeDelta::FromSeconds(2); | |
| 310 AddEndEntry(observer, connect_source, NetLog::TYPE_HOST_RESOLVER_IMPL, NULL); | |
| 311 AddEndConnectJobEntries(observer, 1); | |
| 312 | 324 |
| 313 NetLog::Source http_stream_job_source(NetLog::SOURCE_HTTP_STREAM_JOB, 2); | 325 NetLog::Source http_stream_job_source(NetLog::SOURCE_HTTP_STREAM_JOB, 2); |
| 314 AddStartHTTPStreamJobEntries(observer, 2); | 326 AddStartHTTPStreamJobEntries(observer_, 2); |
| 315 | 327 |
| 316 BindHTTPStreamJobToConnectJob(observer, http_stream_job_source, | 328 BindHTTPStreamJobToConnectJob(observer_, http_stream_job_source, |
| 317 connect_source); | 329 connect_source); |
| 318 BindURLRequestToHTTPStreamJob(observer, source, http_stream_job_source); | 330 BindURLRequestToHTTPStreamJob(observer_, source, http_stream_job_source); |
| 319 | 331 |
| 320 LoadTimingObserver::URLRequestRecord* record = | 332 LoadTimingObserver::URLRequestRecord* record = |
| 321 observer.GetURLRequestRecord(0); | 333 observer_.GetURLRequestRecord(0); |
| 322 ASSERT_EQ(1000, record->timing.dns_start); | 334 ASSERT_EQ(1000, record->timing.dns_start); |
| 323 ASSERT_EQ(3000, record->timing.dns_end); | 335 ASSERT_EQ(3000, record->timing.dns_end); |
| 324 } | 336 } |
| 325 | 337 |
| 326 // Test send time detection. | 338 // Test send time detection. |
| 327 TEST_F(LoadTimingObserverTest, SendTime) { | 339 TEST_F(LoadTimingObserverTest, SendTime) { |
| 328 LoadTimingObserver observer; | |
| 329 | |
| 330 // Start request. | 340 // Start request. |
| 331 NetLog::Source source(NetLog::SOURCE_URL_REQUEST, 0); | 341 NetLog::Source source(NetLog::SOURCE_URL_REQUEST, 0); |
| 332 AddStartURLRequestEntries(observer, 0, true); | 342 AddStartURLRequestEntries(observer_, 0, true); |
| 333 current_time += TimeDelta::FromSeconds(2); | 343 observer_.IncementTime(TimeDelta::FromSeconds(2)); |
| 334 | 344 |
| 335 // Add send request entry. | 345 // Add send request entry. |
| 336 AddStartEntry(observer, | 346 AddStartEntry(observer_, source, NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST); |
| 337 source, | 347 observer_.IncementTime(TimeDelta::FromSeconds(5)); |
| 338 NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST, | 348 AddEndEntry(observer_, source, NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST); |
| 339 NULL); | 349 |
| 340 current_time += TimeDelta::FromSeconds(5); | 350 LoadTimingObserver::URLRequestRecord* record = |
| 341 AddEndEntry(observer, | 351 observer_.GetURLRequestRecord(0); |
| 342 source, | |
| 343 NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST, | |
| 344 NULL); | |
| 345 | |
| 346 LoadTimingObserver::URLRequestRecord* record = | |
| 347 observer.GetURLRequestRecord(0); | |
| 348 ASSERT_EQ(2000, record->timing.send_start); | 352 ASSERT_EQ(2000, record->timing.send_start); |
| 349 ASSERT_EQ(7000, record->timing.send_end); | 353 ASSERT_EQ(7000, record->timing.send_end); |
| 350 } | 354 } |
| 351 | 355 |
| 352 // Test receive time detection. | 356 // Test receive time detection. |
| 353 TEST_F(LoadTimingObserverTest, ReceiveTime) { | 357 TEST_F(LoadTimingObserverTest, ReceiveTime) { |
| 354 LoadTimingObserver observer; | |
| 355 | |
| 356 // Start request. | 358 // Start request. |
| 357 NetLog::Source source(NetLog::SOURCE_URL_REQUEST, 0); | 359 NetLog::Source source(NetLog::SOURCE_URL_REQUEST, 0); |
| 358 AddStartURLRequestEntries(observer, 0, true); | 360 AddStartURLRequestEntries(observer_, 0, true); |
| 359 current_time += TimeDelta::FromSeconds(2); | 361 observer_.IncementTime(TimeDelta::FromSeconds(2)); |
| 360 | 362 |
| 361 // Add send request entry. | 363 // Add send request entry. |
| 362 AddStartEntry(observer, | 364 AddStartEntry(observer_, source, NetLog::TYPE_HTTP_TRANSACTION_READ_HEADERS); |
| 363 source, | 365 observer_.IncementTime(TimeDelta::FromSeconds(5)); |
| 364 NetLog::TYPE_HTTP_TRANSACTION_READ_HEADERS, | 366 AddEndEntry(observer_, source, NetLog::TYPE_HTTP_TRANSACTION_READ_HEADERS); |
| 365 NULL); | 367 |
| 366 current_time += TimeDelta::FromSeconds(5); | 368 LoadTimingObserver::URLRequestRecord* record = |
| 367 AddEndEntry(observer, | 369 observer_.GetURLRequestRecord(0); |
| 368 source, | |
| 369 NetLog::TYPE_HTTP_TRANSACTION_READ_HEADERS, | |
| 370 NULL); | |
| 371 | |
| 372 LoadTimingObserver::URLRequestRecord* record = | |
| 373 observer.GetURLRequestRecord(0); | |
| 374 ASSERT_EQ(2000, record->timing.receive_headers_start); | 370 ASSERT_EQ(2000, record->timing.receive_headers_start); |
| 375 ASSERT_EQ(7000, record->timing.receive_headers_end); | 371 ASSERT_EQ(7000, record->timing.receive_headers_end); |
| 376 } | 372 } |
| 377 | 373 |
| 378 // Test ssl time detection. | 374 // Test ssl time detection. |
| 379 TEST_F(LoadTimingObserverTest, SslTime) { | 375 TEST_F(LoadTimingObserverTest, SslTime) { |
| 380 LoadTimingObserver observer; | |
| 381 | |
| 382 // Start request. | 376 // Start request. |
| 383 NetLog::Source source(NetLog::SOURCE_URL_REQUEST, 0); | 377 NetLog::Source source(NetLog::SOURCE_URL_REQUEST, 0); |
| 384 AddStartURLRequestEntries(observer, 0, true); | 378 AddStartURLRequestEntries(observer_, 0, true); |
| 385 current_time += TimeDelta::FromSeconds(1); | 379 observer_.IncementTime(TimeDelta::FromSeconds(1)); |
| 386 | 380 |
| 387 // Add resolver entry. | 381 // Add resolver entry. |
| 388 AddStartSocketEntries(observer, 1); | 382 AddStartSocketEntries(observer_, 1); |
| 389 NetLog::Source socket_source(NetLog::SOURCE_SOCKET, 1); | 383 NetLog::Source socket_source(NetLog::SOURCE_SOCKET, 1); |
| 390 AddStartEntry(observer, socket_source, NetLog::TYPE_SSL_CONNECT, NULL); | 384 AddStartEntry(observer_, socket_source, NetLog::TYPE_SSL_CONNECT); |
| 391 current_time += TimeDelta::FromSeconds(2); | 385 observer_.IncementTime(TimeDelta::FromSeconds(2)); |
| 392 AddEndEntry(observer, socket_source, NetLog::TYPE_SSL_CONNECT, NULL); | 386 AddEndEntry(observer_, socket_source, NetLog::TYPE_SSL_CONNECT); |
| 393 | 387 |
| 394 NetLog::Source http_stream_job_source(NetLog::SOURCE_HTTP_STREAM_JOB, 2); | 388 NetLog::Source http_stream_job_source(NetLog::SOURCE_HTTP_STREAM_JOB, 2); |
| 395 AddStartHTTPStreamJobEntries(observer, 2); | 389 AddStartHTTPStreamJobEntries(observer_, 2); |
| 396 | 390 |
| 397 BindHTTPStreamJobToSocket(observer, http_stream_job_source, socket_source); | 391 BindHTTPStreamJobToSocket(observer_, http_stream_job_source, socket_source); |
| 398 BindURLRequestToHTTPStreamJob(observer, source, http_stream_job_source); | 392 BindURLRequestToHTTPStreamJob(observer_, source, http_stream_job_source); |
| 399 | 393 |
| 400 LoadTimingObserver::URLRequestRecord* record = | 394 LoadTimingObserver::URLRequestRecord* record = |
| 401 observer.GetURLRequestRecord(0); | 395 observer_.GetURLRequestRecord(0); |
| 402 ASSERT_EQ(1000, record->timing.ssl_start); | 396 ASSERT_EQ(1000, record->timing.ssl_start); |
| 403 ASSERT_EQ(3000, record->timing.ssl_end); | 397 ASSERT_EQ(3000, record->timing.ssl_end); |
| 404 } | 398 } |
| OLD | NEW |