OLD | NEW |
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 Loading... |
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 if (a.type() == ExplodedHttpBodyElement::TYPE_BYTES && | 47 EXPECT_EQ(a.data, b.data); |
48 b.type() == ExplodedHttpBodyElement::TYPE_BYTES) { | 48 EXPECT_EQ(a.file_path, b.file_path); |
49 EXPECT_EQ(std::string(a.bytes(), a.length()), | 49 EXPECT_EQ(a.filesystem_url, b.filesystem_url); |
50 std::string(b.bytes(), b.length())); | 50 EXPECT_EQ(a.file_start, b.file_start); |
| 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); |
51 } | 55 } |
52 EXPECT_EQ(a.path(), b.path()); | 56 EXPECT_EQ(a.blob_uuid, b.blob_uuid); |
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()); | |
58 } | 57 } |
59 | 58 |
60 template <> | 59 template <> |
61 void ExpectEquality(const ExplodedHttpBody& a, const ExplodedHttpBody& b) { | 60 void ExpectEquality(const ExplodedHttpBody& a, const ExplodedHttpBody& b) { |
62 EXPECT_EQ(a.http_content_type, b.http_content_type); | 61 EXPECT_EQ(a.http_content_type, b.http_content_type); |
63 EXPECT_EQ(a.identifier, b.identifier); | 62 EXPECT_EQ(a.identifier, b.identifier); |
64 EXPECT_EQ(a.contains_passwords, b.contains_passwords); | 63 EXPECT_EQ(a.contains_passwords, b.contains_passwords); |
65 EXPECT_EQ(a.is_null, b.is_null); | 64 EXPECT_EQ(a.is_null, b.is_null); |
66 ExpectEquality(a.elements, b.elements); | 65 ExpectEquality(a.elements, b.elements); |
67 } | 66 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 } | 113 } |
115 | 114 |
116 void PopulateHttpBody(ExplodedHttpBody* http_body, | 115 void PopulateHttpBody(ExplodedHttpBody* http_body, |
117 std::vector<base::NullableString16>* referenced_files) { | 116 std::vector<base::NullableString16>* referenced_files) { |
118 http_body->is_null = false; | 117 http_body->is_null = false; |
119 http_body->identifier = 12345; | 118 http_body->identifier = 12345; |
120 http_body->contains_passwords = false; | 119 http_body->contains_passwords = false; |
121 http_body->http_content_type = NS16("text/foo"); | 120 http_body->http_content_type = NS16("text/foo"); |
122 | 121 |
123 ExplodedHttpBodyElement e1; | 122 ExplodedHttpBodyElement e1; |
124 std::string test_body("foo"); | 123 e1.type = blink::WebHTTPBody::Element::TypeData; |
125 e1.SetToBytes(test_body.data(), test_body.size()); | 124 e1.data = "foo"; |
126 http_body->elements.push_back(e1); | 125 http_body->elements.push_back(e1); |
127 | 126 |
128 ExplodedHttpBodyElement e2; | 127 ExplodedHttpBodyElement e2; |
129 e2.SetToFilePathRange(base::FilePath::FromUTF8Unsafe("file.txt"), 100, 1024, | 128 e2.type = blink::WebHTTPBody::Element::TypeFile; |
130 base::Time::FromDoubleT(9999.0)); | 129 e2.file_path = NS16("file.txt"); |
| 130 e2.file_start = 100; |
| 131 e2.file_length = 1024; |
| 132 e2.file_modification_time = 9999.0; |
131 http_body->elements.push_back(e2); | 133 http_body->elements.push_back(e2); |
132 | 134 |
133 referenced_files->push_back( | 135 referenced_files->push_back(e2.file_path); |
134 base::NullableString16(e2.path().AsUTF16Unsafe(), false)); | |
135 } | 136 } |
136 | 137 |
137 void PopulateFrameStateForBackwardsCompatTest( | 138 void PopulateFrameStateForBackwardsCompatTest( |
138 ExplodedFrameState* frame_state, | 139 ExplodedFrameState* frame_state, |
139 bool is_child) { | 140 bool is_child) { |
140 frame_state->url_string = NS16("http://chromium.org/"); | 141 frame_state->url_string = NS16("http://chromium.org/"); |
141 frame_state->referrer = NS16("http://google.com/"); | 142 frame_state->referrer = NS16("http://google.com/"); |
142 frame_state->referrer_policy = blink::WebReferrerPolicyDefault; | 143 frame_state->referrer_policy = blink::WebReferrerPolicyDefault; |
143 if (!is_child) | 144 if (!is_child) |
144 frame_state->target = NS16("target"); | 145 frame_state->target = NS16("target"); |
(...skipping 14 matching lines...) Expand all Loading... |
159 frame_state->document_state.push_back(NS16("2")); | 160 frame_state->document_state.push_back(NS16("2")); |
160 frame_state->document_state.push_back(NS16("file.txt")); | 161 frame_state->document_state.push_back(NS16("file.txt")); |
161 frame_state->document_state.push_back(NS16("displayName")); | 162 frame_state->document_state.push_back(NS16("displayName")); |
162 | 163 |
163 if (!is_child) { | 164 if (!is_child) { |
164 frame_state->http_body.http_content_type = NS16("foo/bar"); | 165 frame_state->http_body.http_content_type = NS16("foo/bar"); |
165 frame_state->http_body.identifier = 789; | 166 frame_state->http_body.identifier = 789; |
166 frame_state->http_body.is_null = false; | 167 frame_state->http_body.is_null = false; |
167 | 168 |
168 ExplodedHttpBodyElement e1; | 169 ExplodedHttpBodyElement e1; |
169 std::string test_body("first data block"); | 170 e1.type = blink::WebHTTPBody::Element::TypeData; |
170 e1.SetToBytes(test_body.data(), test_body.size()); | 171 e1.data = "first data block"; |
171 frame_state->http_body.elements.push_back(e1); | 172 frame_state->http_body.elements.push_back(e1); |
172 | 173 |
173 ExplodedHttpBodyElement e2; | 174 ExplodedHttpBodyElement e2; |
174 e2.SetToFilePath(base::FilePath::FromUTF8Unsafe("file.txt")); | 175 e2.type = blink::WebHTTPBody::Element::TypeFile; |
| 176 e2.file_path = NS16("file.txt"); |
175 frame_state->http_body.elements.push_back(e2); | 177 frame_state->http_body.elements.push_back(e2); |
176 | 178 |
177 ExplodedHttpBodyElement e3; | 179 ExplodedHttpBodyElement e3; |
178 std::string test_body2("data the second"); | 180 e3.type = blink::WebHTTPBody::Element::TypeData; |
179 e3.SetToBytes(test_body2.data(), test_body2.size()); | 181 e3.data = "data the second"; |
180 frame_state->http_body.elements.push_back(e3); | 182 frame_state->http_body.elements.push_back(e3); |
181 | 183 |
182 ExplodedFrameState child_state; | 184 ExplodedFrameState child_state; |
183 PopulateFrameStateForBackwardsCompatTest(&child_state, true); | 185 PopulateFrameStateForBackwardsCompatTest(&child_state, true); |
184 frame_state->children.push_back(child_state); | 186 frame_state->children.push_back(child_state); |
185 } | 187 } |
186 } | 188 } |
187 | 189 |
188 void PopulatePageStateForBackwardsCompatTest(ExplodedPageState* page_state) { | 190 void PopulatePageStateForBackwardsCompatTest(ExplodedPageState* page_state) { |
189 page_state->referenced_files.push_back(NS16("file.txt")); | 191 page_state->referenced_files.push_back(NS16("file.txt")); |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 TEST_F(PageStateSerializationTest, BackwardsCompat_v21) { | 437 TEST_F(PageStateSerializationTest, BackwardsCompat_v21) { |
436 TestBackwardsCompat(21); | 438 TestBackwardsCompat(21); |
437 } | 439 } |
438 | 440 |
439 TEST_F(PageStateSerializationTest, BackwardsCompat_v22) { | 441 TEST_F(PageStateSerializationTest, BackwardsCompat_v22) { |
440 TestBackwardsCompat(22); | 442 TestBackwardsCompat(22); |
441 } | 443 } |
442 | 444 |
443 } // namespace | 445 } // namespace |
444 } // namespace content | 446 } // namespace content |
OLD | NEW |