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

Side by Side Diff: content/common/page_state_serialization_unittest.cc

Issue 1987053002: Deduplicating code performing WebHTTPBody::Element conversions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: s/data/test_body/g Created 4 years, 7 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
« no previous file with comments | « content/common/page_state_serialization.cc ('k') | content/common/resource_request_body.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 25 matching lines...) Expand all
36 template <typename T> 36 template <typename T>
37 void ExpectEquality(const std::vector<T>& a, const std::vector<T>& b) { 37 void ExpectEquality(const std::vector<T>& a, const std::vector<T>& b) {
38 EXPECT_EQ(a.size(), b.size()); 38 EXPECT_EQ(a.size(), b.size());
39 for (size_t i = 0; i < std::min(a.size(), b.size()); ++i) 39 for (size_t i = 0; i < std::min(a.size(), b.size()); ++i)
40 ExpectEquality(a[i], b[i]); 40 ExpectEquality(a[i], b[i]);
41 } 41 }
42 42
43 template <> 43 template <>
44 void ExpectEquality(const ExplodedHttpBodyElement& a, 44 void ExpectEquality(const ExplodedHttpBodyElement& a,
45 const ExplodedHttpBodyElement& b) { 45 const ExplodedHttpBodyElement& b) {
46 EXPECT_EQ(a.type, b.type); 46 EXPECT_EQ(a.type(), b.type());
47 EXPECT_EQ(a.data, b.data); 47 if (a.type() == ExplodedHttpBodyElement::TYPE_BYTES &&
48 EXPECT_EQ(a.file_path, b.file_path); 48 b.type() == ExplodedHttpBodyElement::TYPE_BYTES) {
49 EXPECT_EQ(a.filesystem_url, b.filesystem_url); 49 EXPECT_EQ(std::string(a.bytes(), a.length()),
50 EXPECT_EQ(a.file_start, b.file_start); 50 std::string(b.bytes(), b.length()));
51 EXPECT_EQ(a.file_length, b.file_length);
52 if (!(std::isnan(a.file_modification_time) &&
53 std::isnan(b.file_modification_time))) {
54 EXPECT_DOUBLE_EQ(a.file_modification_time, b.file_modification_time);
55 } 51 }
56 EXPECT_EQ(a.blob_uuid, b.blob_uuid); 52 EXPECT_EQ(a.path(), b.path());
53 EXPECT_EQ(a.filesystem_url(), b.filesystem_url());
54 EXPECT_EQ(a.offset(), b.offset());
55 EXPECT_EQ(a.length(), b.length());
56 EXPECT_EQ(a.expected_modification_time(), b.expected_modification_time());
57 EXPECT_EQ(a.blob_uuid(), b.blob_uuid());
57 } 58 }
58 59
59 template <> 60 template <>
60 void ExpectEquality(const ExplodedHttpBody& a, const ExplodedHttpBody& b) { 61 void ExpectEquality(const ExplodedHttpBody& a, const ExplodedHttpBody& b) {
61 EXPECT_EQ(a.http_content_type, b.http_content_type); 62 EXPECT_EQ(a.http_content_type, b.http_content_type);
62 EXPECT_EQ(a.identifier, b.identifier); 63 EXPECT_EQ(a.identifier, b.identifier);
63 EXPECT_EQ(a.contains_passwords, b.contains_passwords); 64 EXPECT_EQ(a.contains_passwords, b.contains_passwords);
64 EXPECT_EQ(a.is_null, b.is_null); 65 EXPECT_EQ(a.is_null, b.is_null);
65 ExpectEquality(a.elements, b.elements); 66 ExpectEquality(a.elements, b.elements);
66 } 67 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 } 114 }
114 115
115 void PopulateHttpBody(ExplodedHttpBody* http_body, 116 void PopulateHttpBody(ExplodedHttpBody* http_body,
116 std::vector<base::NullableString16>* referenced_files) { 117 std::vector<base::NullableString16>* referenced_files) {
117 http_body->is_null = false; 118 http_body->is_null = false;
118 http_body->identifier = 12345; 119 http_body->identifier = 12345;
119 http_body->contains_passwords = false; 120 http_body->contains_passwords = false;
120 http_body->http_content_type = NS16("text/foo"); 121 http_body->http_content_type = NS16("text/foo");
121 122
122 ExplodedHttpBodyElement e1; 123 ExplodedHttpBodyElement e1;
123 e1.type = blink::WebHTTPBody::Element::TypeData; 124 std::string test_body("foo");
124 e1.data = "foo"; 125 e1.SetToBytes(test_body.data(), test_body.size());
125 http_body->elements.push_back(e1); 126 http_body->elements.push_back(e1);
126 127
127 ExplodedHttpBodyElement e2; 128 ExplodedHttpBodyElement e2;
128 e2.type = blink::WebHTTPBody::Element::TypeFile; 129 e2.SetToFilePathRange(base::FilePath::FromUTF8Unsafe("file.txt"), 100, 1024,
129 e2.file_path = NS16("file.txt"); 130 base::Time::FromDoubleT(9999.0));
130 e2.file_start = 100;
131 e2.file_length = 1024;
132 e2.file_modification_time = 9999.0;
133 http_body->elements.push_back(e2); 131 http_body->elements.push_back(e2);
134 132
135 referenced_files->push_back(e2.file_path); 133 referenced_files->push_back(
134 base::NullableString16(e2.path().AsUTF16Unsafe(), false));
136 } 135 }
137 136
138 void PopulateFrameStateForBackwardsCompatTest( 137 void PopulateFrameStateForBackwardsCompatTest(
139 ExplodedFrameState* frame_state, 138 ExplodedFrameState* frame_state,
140 bool is_child) { 139 bool is_child) {
141 frame_state->url_string = NS16("http://chromium.org/"); 140 frame_state->url_string = NS16("http://chromium.org/");
142 frame_state->referrer = NS16("http://google.com/"); 141 frame_state->referrer = NS16("http://google.com/");
143 frame_state->referrer_policy = blink::WebReferrerPolicyDefault; 142 frame_state->referrer_policy = blink::WebReferrerPolicyDefault;
144 if (!is_child) 143 if (!is_child)
145 frame_state->target = NS16("target"); 144 frame_state->target = NS16("target");
(...skipping 14 matching lines...) Expand all
160 frame_state->document_state.push_back(NS16("2")); 159 frame_state->document_state.push_back(NS16("2"));
161 frame_state->document_state.push_back(NS16("file.txt")); 160 frame_state->document_state.push_back(NS16("file.txt"));
162 frame_state->document_state.push_back(NS16("displayName")); 161 frame_state->document_state.push_back(NS16("displayName"));
163 162
164 if (!is_child) { 163 if (!is_child) {
165 frame_state->http_body.http_content_type = NS16("foo/bar"); 164 frame_state->http_body.http_content_type = NS16("foo/bar");
166 frame_state->http_body.identifier = 789; 165 frame_state->http_body.identifier = 789;
167 frame_state->http_body.is_null = false; 166 frame_state->http_body.is_null = false;
168 167
169 ExplodedHttpBodyElement e1; 168 ExplodedHttpBodyElement e1;
170 e1.type = blink::WebHTTPBody::Element::TypeData; 169 std::string test_body("first data block");
171 e1.data = "first data block"; 170 e1.SetToBytes(test_body.data(), test_body.size());
172 frame_state->http_body.elements.push_back(e1); 171 frame_state->http_body.elements.push_back(e1);
173 172
174 ExplodedHttpBodyElement e2; 173 ExplodedHttpBodyElement e2;
175 e2.type = blink::WebHTTPBody::Element::TypeFile; 174 e2.SetToFilePath(base::FilePath::FromUTF8Unsafe("file.txt"));
176 e2.file_path = NS16("file.txt");
177 frame_state->http_body.elements.push_back(e2); 175 frame_state->http_body.elements.push_back(e2);
178 176
179 ExplodedHttpBodyElement e3; 177 ExplodedHttpBodyElement e3;
180 e3.type = blink::WebHTTPBody::Element::TypeData; 178 std::string test_body2("data the second");
181 e3.data = "data the second"; 179 e3.SetToBytes(test_body2.data(), test_body2.size());
182 frame_state->http_body.elements.push_back(e3); 180 frame_state->http_body.elements.push_back(e3);
183 181
184 ExplodedFrameState child_state; 182 ExplodedFrameState child_state;
185 PopulateFrameStateForBackwardsCompatTest(&child_state, true); 183 PopulateFrameStateForBackwardsCompatTest(&child_state, true);
186 frame_state->children.push_back(child_state); 184 frame_state->children.push_back(child_state);
187 } 185 }
188 } 186 }
189 187
190 void PopulatePageStateForBackwardsCompatTest(ExplodedPageState* page_state) { 188 void PopulatePageStateForBackwardsCompatTest(ExplodedPageState* page_state) {
191 page_state->referenced_files.push_back(NS16("file.txt")); 189 page_state->referenced_files.push_back(NS16("file.txt"));
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 TEST_F(PageStateSerializationTest, BackwardsCompat_v21) { 435 TEST_F(PageStateSerializationTest, BackwardsCompat_v21) {
438 TestBackwardsCompat(21); 436 TestBackwardsCompat(21);
439 } 437 }
440 438
441 TEST_F(PageStateSerializationTest, BackwardsCompat_v22) { 439 TEST_F(PageStateSerializationTest, BackwardsCompat_v22) {
442 TestBackwardsCompat(22); 440 TestBackwardsCompat(22);
443 } 441 }
444 442
445 } // namespace 443 } // namespace
446 } // namespace content 444 } // namespace content
OLDNEW
« no previous file with comments | « content/common/page_state_serialization.cc ('k') | content/common/resource_request_body.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698