| 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 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 PopulatePageStateForBackwardsCompatTest(&expected); | 234 PopulatePageStateForBackwardsCompatTest(&expected); |
| 235 | 235 |
| 236 ExpectEquality(expected, output); | 236 ExpectEquality(expected, output); |
| 237 } | 237 } |
| 238 }; | 238 }; |
| 239 | 239 |
| 240 TEST_F(PageStateSerializationTest, BasicEmpty) { | 240 TEST_F(PageStateSerializationTest, BasicEmpty) { |
| 241 ExplodedPageState input; | 241 ExplodedPageState input; |
| 242 | 242 |
| 243 std::string encoded; | 243 std::string encoded; |
| 244 EXPECT_TRUE(EncodePageState(input, &encoded)); | 244 EncodePageState(input, &encoded); |
| 245 | 245 |
| 246 ExplodedPageState output; | 246 ExplodedPageState output; |
| 247 EXPECT_TRUE(DecodePageState(encoded, &output)); | 247 EXPECT_TRUE(DecodePageState(encoded, &output)); |
| 248 | 248 |
| 249 ExpectEquality(input, output); | 249 ExpectEquality(input, output); |
| 250 } | 250 } |
| 251 | 251 |
| 252 TEST_F(PageStateSerializationTest, BasicFrame) { | 252 TEST_F(PageStateSerializationTest, BasicFrame) { |
| 253 ExplodedPageState input; | 253 ExplodedPageState input; |
| 254 PopulateFrameState(&input.top); | 254 PopulateFrameState(&input.top); |
| 255 | 255 |
| 256 std::string encoded; | 256 std::string encoded; |
| 257 EXPECT_TRUE(EncodePageState(input, &encoded)); | 257 EncodePageState(input, &encoded); |
| 258 | 258 |
| 259 ExplodedPageState output; | 259 ExplodedPageState output; |
| 260 EXPECT_TRUE(DecodePageState(encoded, &output)); | 260 EXPECT_TRUE(DecodePageState(encoded, &output)); |
| 261 | 261 |
| 262 ExpectEquality(input, output); | 262 ExpectEquality(input, output); |
| 263 } | 263 } |
| 264 | 264 |
| 265 TEST_F(PageStateSerializationTest, BasicFramePOST) { | 265 TEST_F(PageStateSerializationTest, BasicFramePOST) { |
| 266 ExplodedPageState input; | 266 ExplodedPageState input; |
| 267 PopulateFrameState(&input.top); | 267 PopulateFrameState(&input.top); |
| 268 PopulateHttpBody(&input.top.http_body, &input.referenced_files); | 268 PopulateHttpBody(&input.top.http_body, &input.referenced_files); |
| 269 | 269 |
| 270 std::string encoded; | 270 std::string encoded; |
| 271 EXPECT_TRUE(EncodePageState(input, &encoded)); | 271 EncodePageState(input, &encoded); |
| 272 | 272 |
| 273 ExplodedPageState output; | 273 ExplodedPageState output; |
| 274 EXPECT_TRUE(DecodePageState(encoded, &output)); | 274 EXPECT_TRUE(DecodePageState(encoded, &output)); |
| 275 | 275 |
| 276 ExpectEquality(input, output); | 276 ExpectEquality(input, output); |
| 277 } | 277 } |
| 278 | 278 |
| 279 TEST_F(PageStateSerializationTest, BasicFrameSet) { | 279 TEST_F(PageStateSerializationTest, BasicFrameSet) { |
| 280 ExplodedPageState input; | 280 ExplodedPageState input; |
| 281 PopulateFrameState(&input.top); | 281 PopulateFrameState(&input.top); |
| 282 | 282 |
| 283 // Add some child frames. | 283 // Add some child frames. |
| 284 for (int i = 0; i < 4; ++i) { | 284 for (int i = 0; i < 4; ++i) { |
| 285 ExplodedFrameState child_state; | 285 ExplodedFrameState child_state; |
| 286 PopulateFrameState(&child_state); | 286 PopulateFrameState(&child_state); |
| 287 input.top.children.push_back(child_state); | 287 input.top.children.push_back(child_state); |
| 288 } | 288 } |
| 289 | 289 |
| 290 std::string encoded; | 290 std::string encoded; |
| 291 EXPECT_TRUE(EncodePageState(input, &encoded)); | 291 EncodePageState(input, &encoded); |
| 292 | 292 |
| 293 ExplodedPageState output; | 293 ExplodedPageState output; |
| 294 EXPECT_TRUE(DecodePageState(encoded, &output)); | 294 EXPECT_TRUE(DecodePageState(encoded, &output)); |
| 295 | 295 |
| 296 ExpectEquality(input, output); | 296 ExpectEquality(input, output); |
| 297 } | 297 } |
| 298 | 298 |
| 299 TEST_F(PageStateSerializationTest, BasicFrameSetPOST) { | 299 TEST_F(PageStateSerializationTest, BasicFrameSetPOST) { |
| 300 ExplodedPageState input; | 300 ExplodedPageState input; |
| 301 PopulateFrameState(&input.top); | 301 PopulateFrameState(&input.top); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 } | 364 } |
| 365 | 365 |
| 366 TEST_F(PageStateSerializationTest, DumpExpectedPageStateForBackwardsCompat) { | 366 TEST_F(PageStateSerializationTest, DumpExpectedPageStateForBackwardsCompat) { |
| 367 // Change to #if 1 to enable this code. Use this code to generate data, based | 367 // Change to #if 1 to enable this code. Use this code to generate data, based |
| 368 // on the current serialization format, for the BackwardsCompat_vXX tests. | 368 // on the current serialization format, for the BackwardsCompat_vXX tests. |
| 369 #if 0 | 369 #if 0 |
| 370 ExplodedPageState state; | 370 ExplodedPageState state; |
| 371 PopulatePageStateForBackwardsCompatTest(&state); | 371 PopulatePageStateForBackwardsCompatTest(&state); |
| 372 | 372 |
| 373 std::string encoded; | 373 std::string encoded; |
| 374 EXPECT_TRUE(EncodePageState(state, &encoded)); | 374 EncodePageState(state, &encoded); |
| 375 | 375 |
| 376 std::string base64; | 376 std::string base64; |
| 377 base::Base64Encode(encoded, &base64); | 377 base::Base64Encode(encoded, &base64); |
| 378 | 378 |
| 379 base::FilePath path; | 379 base::FilePath path; |
| 380 PathService::Get(base::DIR_TEMP, &path); | 380 PathService::Get(base::DIR_TEMP, &path); |
| 381 path = path.AppendASCII("expected.dat"); | 381 path = path.AppendASCII("expected.dat"); |
| 382 | 382 |
| 383 FILE* fp = base::OpenFile(path, "wb"); | 383 FILE* fp = base::OpenFile(path, "wb"); |
| 384 ASSERT_TRUE(fp); | 384 ASSERT_TRUE(fp); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 TEST_F(PageStateSerializationTest, BackwardsCompat_v21) { | 434 TEST_F(PageStateSerializationTest, BackwardsCompat_v21) { |
| 435 TestBackwardsCompat(21); | 435 TestBackwardsCompat(21); |
| 436 } | 436 } |
| 437 | 437 |
| 438 TEST_F(PageStateSerializationTest, BackwardsCompat_v22) { | 438 TEST_F(PageStateSerializationTest, BackwardsCompat_v22) { |
| 439 TestBackwardsCompat(22); | 439 TestBackwardsCompat(22); |
| 440 } | 440 } |
| 441 | 441 |
| 442 } // namespace | 442 } // namespace |
| 443 } // namespace content | 443 } // namespace content |
| OLD | NEW |