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

Unified Diff: content/common/resource_dispatcher_unittest.cc

Issue 10831104: Safely handle uninitialized load_timing info in ResourceResponseHead. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Correct patch Created 8 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/common/resource_dispatcher.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/common/resource_dispatcher_unittest.cc
diff --git a/content/common/resource_dispatcher_unittest.cc b/content/common/resource_dispatcher_unittest.cc
index e87463f40a425455750c74e1becc86fc58de9ac9..137943dbc47bf7adb2452386930f24117c6f42c1 100644
--- a/content/common/resource_dispatcher_unittest.cc
+++ b/content/common/resource_dispatcher_unittest.cc
@@ -343,4 +343,98 @@ TEST_F(DeferredResourceLoadingTest, DeferredLoadTest) {
delete bridge;
}
+class TimeConversionTest : public ResourceDispatcherTest,
+ public ResourceLoaderBridge::Peer {
+ public:
+ virtual bool Send(IPC::Message* msg) {
+ delete msg;
+ return true;
+ }
+
+ void PerformTest(const ResourceResponseHead& response_head) {
+ scoped_ptr<ResourceLoaderBridge> bridge(CreateBridge());
+ bridge->Start(this);
+
+ IPC::Message* response_message =
darin (slow to review) 2012/08/02 04:53:15 nit: no need to heap allocate the IPC message :)
James Simonsen 2012/08/02 19:02:58 Done.
+ new ResourceMsg_ReceivedResponse(0, 0, response_head);
+
+ dispatcher_->OnMessageReceived(*response_message);
+
+ delete response_message;
+ }
+
+ // ResourceLoaderBridge::Peer methods.
+ virtual void OnUploadProgress(uint64 position, uint64 size) {
+ }
darin (slow to review) 2012/08/02 04:53:15 nit: do these need OVERRIDE?
James Simonsen 2012/08/02 19:02:58 Done.
+
+ virtual bool OnReceivedRedirect(
+ const GURL& new_url,
+ const ResourceResponseInfo& info,
+ bool* has_new_first_party_for_cookies,
+ GURL* new_first_party_for_cookies) {
+ return true;
+ }
+
+ virtual void OnReceivedResponse(const ResourceResponseInfo& info) {
+ response_info_ = info;
+ }
+
+ virtual void OnDownloadedData(int len) {
+ }
+
+ virtual void OnReceivedData(const char* data,
+ int data_length,
+ int encoded_data_length) {
+ }
+
+ virtual void OnCompletedRequest(const net::URLRequestStatus& status,
+ const std::string& security_info,
+ const base::TimeTicks& completion_time) {
+ }
+
+ const ResourceResponseInfo& response_info() const { return response_info_; }
+
+ private:
+ ResourceResponseInfo response_info_;
+};
+
+TEST_F(TimeConversionTest, ProperlyInitialized) {
+ ResourceResponseHead response_head;
+ response_head.status.set_status(net::URLRequestStatus::SUCCESS);
+ response_head.request_start = base::TimeTicks::FromInternalValue(5);
+ response_head.response_start = base::TimeTicks::FromInternalValue(15);
+ response_head.load_timing.base_time = base::Time::Now();
+ response_head.load_timing.base_ticks = base::TimeTicks::FromInternalValue(10);
+ response_head.load_timing.dns_start = -1;
+ response_head.load_timing.connect_start = 3;
+
+ PerformTest(response_head);
+
+ EXPECT_LT(0, response_info().load_timing.base_ticks.ToInternalValue());
+ EXPECT_EQ(-1, response_info().load_timing.dns_start);
+ EXPECT_LE(0, response_info().load_timing.connect_start);
+}
+
+TEST_F(TimeConversionTest, PartiallyInitialized) {
+ ResourceResponseHead response_head;
+ response_head.status.set_status(net::URLRequestStatus::SUCCESS);
+ response_head.request_start = base::TimeTicks::FromInternalValue(5);
+ response_head.response_start = base::TimeTicks::FromInternalValue(15);
+
+ PerformTest(response_head);
+
+ EXPECT_EQ(0, response_info().load_timing.base_ticks.ToInternalValue());
+ EXPECT_EQ(-1, response_info().load_timing.dns_start);
+}
+
+TEST_F(TimeConversionTest, NotInitialized) {
+ ResourceResponseHead response_head;
+ response_head.status.set_status(net::URLRequestStatus::SUCCESS);
+
+ PerformTest(response_head);
+
+ EXPECT_EQ(0, response_info().load_timing.base_ticks.ToInternalValue());
+ EXPECT_EQ(-1, response_info().load_timing.dns_start);
+}
+
} // namespace content
« no previous file with comments | « content/common/resource_dispatcher.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698