| 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 23 matching lines...) Expand all Loading... |
| 34 } | 34 } |
| 35 | 35 |
| 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 ResourceRequestBody::Element& a, |
| 45 const ExplodedHttpBodyElement& b) { | 45 const ResourceRequestBody::Element& b) { |
| 46 EXPECT_EQ(a.type(), b.type()); | 46 EXPECT_EQ(a.type(), b.type()); |
| 47 if (a.type() == ExplodedHttpBodyElement::TYPE_BYTES && | 47 if (a.type() == ResourceRequestBody::Element::TYPE_BYTES && |
| 48 b.type() == ExplodedHttpBodyElement::TYPE_BYTES) { | 48 b.type() == ResourceRequestBody::Element::TYPE_BYTES) { |
| 49 EXPECT_EQ(std::string(a.bytes(), a.length()), | 49 EXPECT_EQ(std::string(a.bytes(), a.length()), |
| 50 std::string(b.bytes(), b.length())); | 50 std::string(b.bytes(), b.length())); |
| 51 } | 51 } |
| 52 EXPECT_EQ(a.path(), b.path()); | 52 EXPECT_EQ(a.path(), b.path()); |
| 53 EXPECT_EQ(a.filesystem_url(), b.filesystem_url()); | 53 EXPECT_EQ(a.filesystem_url(), b.filesystem_url()); |
| 54 EXPECT_EQ(a.offset(), b.offset()); | 54 EXPECT_EQ(a.offset(), b.offset()); |
| 55 EXPECT_EQ(a.length(), b.length()); | 55 EXPECT_EQ(a.length(), b.length()); |
| 56 EXPECT_EQ(a.expected_modification_time(), b.expected_modification_time()); | 56 EXPECT_EQ(a.expected_modification_time(), b.expected_modification_time()); |
| 57 EXPECT_EQ(a.blob_uuid(), b.blob_uuid()); | 57 EXPECT_EQ(a.blob_uuid(), b.blob_uuid()); |
| 58 } | 58 } |
| 59 | 59 |
| 60 template <> | 60 template <> |
| 61 void ExpectEquality(const ExplodedHttpBody& a, const ExplodedHttpBody& b) { | 61 void ExpectEquality(const ExplodedHttpBody& a, const ExplodedHttpBody& b) { |
| 62 EXPECT_EQ(a.http_content_type, b.http_content_type); | 62 EXPECT_EQ(a.http_content_type, b.http_content_type); |
| 63 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 if (a.request_body == nullptr || b.request_body == nullptr) { |
| 66 ExpectEquality(a.elements, b.elements); | 65 EXPECT_EQ(nullptr, a.request_body); |
| 66 EXPECT_EQ(nullptr, b.request_body); |
| 67 } else { |
| 68 EXPECT_EQ(a.request_body->identifier(), b.request_body->identifier()); |
| 69 ExpectEquality(*a.request_body->elements(), *b.request_body->elements()); |
| 70 } |
| 67 } | 71 } |
| 68 | 72 |
| 69 template <> | 73 template <> |
| 70 void ExpectEquality(const ExplodedFrameState& a, const ExplodedFrameState& b) { | 74 void ExpectEquality(const ExplodedFrameState& a, const ExplodedFrameState& b) { |
| 71 EXPECT_EQ(a.url_string, b.url_string); | 75 EXPECT_EQ(a.url_string, b.url_string); |
| 72 EXPECT_EQ(a.referrer, b.referrer); | 76 EXPECT_EQ(a.referrer, b.referrer); |
| 73 EXPECT_EQ(a.referrer_policy, b.referrer_policy); | 77 EXPECT_EQ(a.referrer_policy, b.referrer_policy); |
| 74 EXPECT_EQ(a.target, b.target); | 78 EXPECT_EQ(a.target, b.target); |
| 75 EXPECT_EQ(a.state_object, b.state_object); | 79 EXPECT_EQ(a.state_object, b.state_object); |
| 76 ExpectEquality(a.document_state, b.document_state); | 80 ExpectEquality(a.document_state, b.document_state); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 blink::WebHistoryScrollRestorationManual; | 112 blink::WebHistoryScrollRestorationManual; |
| 109 frame_state->visual_viewport_scroll_offset = gfx::PointF(10, 15); | 113 frame_state->visual_viewport_scroll_offset = gfx::PointF(10, 15); |
| 110 frame_state->scroll_offset = gfx::Point(0, 100); | 114 frame_state->scroll_offset = gfx::Point(0, 100); |
| 111 frame_state->item_sequence_number = 1; | 115 frame_state->item_sequence_number = 1; |
| 112 frame_state->document_sequence_number = 2; | 116 frame_state->document_sequence_number = 2; |
| 113 frame_state->page_scale_factor = 2.0; | 117 frame_state->page_scale_factor = 2.0; |
| 114 } | 118 } |
| 115 | 119 |
| 116 void PopulateHttpBody(ExplodedHttpBody* http_body, | 120 void PopulateHttpBody(ExplodedHttpBody* http_body, |
| 117 std::vector<base::NullableString16>* referenced_files) { | 121 std::vector<base::NullableString16>* referenced_files) { |
| 118 http_body->is_null = false; | 122 http_body->request_body = new ResourceRequestBody(); |
| 119 http_body->identifier = 12345; | 123 http_body->request_body->set_identifier(12345); |
| 120 http_body->contains_passwords = false; | 124 http_body->contains_passwords = false; |
| 121 http_body->http_content_type = NS16("text/foo"); | 125 http_body->http_content_type = NS16("text/foo"); |
| 122 | 126 |
| 123 ExplodedHttpBodyElement e1; | |
| 124 std::string test_body("foo"); | 127 std::string test_body("foo"); |
| 125 e1.SetToBytes(test_body.data(), test_body.size()); | 128 http_body->request_body->AppendBytes(test_body.data(), test_body.size()); |
| 126 http_body->elements.push_back(e1); | |
| 127 | 129 |
| 128 ExplodedHttpBodyElement e2; | 130 base::FilePath path(FILE_PATH_LITERAL("file.txt")); |
| 129 e2.SetToFilePathRange(base::FilePath::FromUTF8Unsafe("file.txt"), 100, 1024, | 131 http_body->request_body->AppendFileRange(base::FilePath(path), 100, 1024, |
| 130 base::Time::FromDoubleT(9999.0)); | 132 base::Time::FromDoubleT(9999.0)); |
| 131 http_body->elements.push_back(e2); | |
| 132 | 133 |
| 133 referenced_files->push_back( | 134 referenced_files->push_back( |
| 134 base::NullableString16(e2.path().AsUTF16Unsafe(), false)); | 135 base::NullableString16(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 10 matching lines...) Expand all Loading... |
| 155 frame_state->document_state.push_back(NS16("form key")); | 156 frame_state->document_state.push_back(NS16("form key")); |
| 156 frame_state->document_state.push_back(NS16("1")); | 157 frame_state->document_state.push_back(NS16("1")); |
| 157 frame_state->document_state.push_back(NS16("foo")); | 158 frame_state->document_state.push_back(NS16("foo")); |
| 158 frame_state->document_state.push_back(NS16("file")); | 159 frame_state->document_state.push_back(NS16("file")); |
| 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.request_body = new ResourceRequestBody(); |
| 166 frame_state->http_body.is_null = false; | 167 frame_state->http_body.request_body->set_identifier(789); |
| 167 | 168 |
| 168 ExplodedHttpBodyElement e1; | |
| 169 std::string test_body("first data block"); | 169 std::string test_body("first data block"); |
| 170 e1.SetToBytes(test_body.data(), test_body.size()); | 170 frame_state->http_body.request_body->AppendBytes(test_body.data(), |
| 171 frame_state->http_body.elements.push_back(e1); | 171 test_body.size()); |
| 172 | 172 |
| 173 ExplodedHttpBodyElement e2; | 173 frame_state->http_body.request_body->AppendFileRange( |
| 174 e2.SetToFilePath(base::FilePath::FromUTF8Unsafe("file.txt")); | 174 base::FilePath(FILE_PATH_LITERAL("file.txt")), 0, |
| 175 frame_state->http_body.elements.push_back(e2); | 175 std::numeric_limits<uint64_t>::max(), base::Time::FromDoubleT(0.0)); |
| 176 | 176 |
| 177 ExplodedHttpBodyElement e3; | |
| 178 std::string test_body2("data the second"); | 177 std::string test_body2("data the second"); |
| 179 e3.SetToBytes(test_body2.data(), test_body2.size()); | 178 frame_state->http_body.request_body->AppendBytes(test_body2.data(), |
| 180 frame_state->http_body.elements.push_back(e3); | 179 test_body2.size()); |
| 181 | 180 |
| 182 ExplodedFrameState child_state; | 181 ExplodedFrameState child_state; |
| 183 PopulateFrameStateForBackwardsCompatTest(&child_state, true); | 182 PopulateFrameStateForBackwardsCompatTest(&child_state, true); |
| 184 frame_state->children.push_back(child_state); | 183 frame_state->children.push_back(child_state); |
| 185 } | 184 } |
| 186 } | 185 } |
| 187 | 186 |
| 188 void PopulatePageStateForBackwardsCompatTest(ExplodedPageState* page_state) { | 187 void PopulatePageStateForBackwardsCompatTest(ExplodedPageState* page_state) { |
| 189 page_state->referenced_files.push_back(NS16("file.txt")); | 188 page_state->referenced_files.push_back(NS16("file.txt")); |
| 190 PopulateFrameStateForBackwardsCompatTest(&page_state->top, false); | 189 PopulateFrameStateForBackwardsCompatTest(&page_state->top, false); |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 TEST_F(PageStateSerializationTest, BackwardsCompat_v21) { | 434 TEST_F(PageStateSerializationTest, BackwardsCompat_v21) { |
| 436 TestBackwardsCompat(21); | 435 TestBackwardsCompat(21); |
| 437 } | 436 } |
| 438 | 437 |
| 439 TEST_F(PageStateSerializationTest, BackwardsCompat_v22) { | 438 TEST_F(PageStateSerializationTest, BackwardsCompat_v22) { |
| 440 TestBackwardsCompat(22); | 439 TestBackwardsCompat(22); |
| 441 } | 440 } |
| 442 | 441 |
| 443 } // namespace | 442 } // namespace |
| 444 } // namespace content | 443 } // namespace content |
| OLD | NEW |