| 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 <math.h> | 5 #include <math.h> |
| 6 | 6 |
| 7 #include "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/pickle.h" | 10 #include "base/pickle.h" |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 p.WriteInt(1); | 351 p.WriteInt(1); |
| 352 p.WriteInt(blink::WebHTTPBody::Element::TypeData); | 352 p.WriteInt(blink::WebHTTPBody::Element::TypeData); |
| 353 | 353 |
| 354 std::string s(static_cast<const char*>(p.data()), p.size()); | 354 std::string s(static_cast<const char*>(p.data()), p.size()); |
| 355 | 355 |
| 356 ExplodedPageState output; | 356 ExplodedPageState output; |
| 357 EXPECT_FALSE(DecodePageState(s, &output)); | 357 EXPECT_FALSE(DecodePageState(s, &output)); |
| 358 } | 358 } |
| 359 | 359 |
| 360 TEST_F(PageStateSerializationTest, DumpExpectedPageStateForBackwardsCompat) { | 360 TEST_F(PageStateSerializationTest, DumpExpectedPageStateForBackwardsCompat) { |
| 361 // Comment out this return statement to enable this code. Use this code to | 361 // Change to #if 1 to enable this code. Use this code to generate data, based |
| 362 // generate data, based on the current serialization format, for the | 362 // on the current serialization format, for the BackwardsCompat_vXX tests. |
| 363 // BackwardsCompat_vXX tests. | 363 #if 0 |
| 364 return; | |
| 365 | |
| 366 ExplodedPageState state; | 364 ExplodedPageState state; |
| 367 PopulatePageStateForBackwardsCompatTest(&state); | 365 PopulatePageStateForBackwardsCompatTest(&state); |
| 368 | 366 |
| 369 std::string encoded; | 367 std::string encoded; |
| 370 EXPECT_TRUE(EncodePageState(state, &encoded)); | 368 EXPECT_TRUE(EncodePageState(state, &encoded)); |
| 371 | 369 |
| 372 std::string base64; | 370 std::string base64; |
| 373 base::Base64Encode(encoded, &base64); | 371 base::Base64Encode(encoded, &base64); |
| 374 | 372 |
| 375 base::FilePath path; | 373 base::FilePath path; |
| 376 PathService::Get(base::DIR_TEMP, &path); | 374 PathService::Get(base::DIR_TEMP, &path); |
| 377 path = path.AppendASCII("expected.dat"); | 375 path = path.AppendASCII("expected.dat"); |
| 378 | 376 |
| 379 FILE* fp = base::OpenFile(path, "wb"); | 377 FILE* fp = base::OpenFile(path, "wb"); |
| 380 ASSERT_TRUE(fp); | 378 ASSERT_TRUE(fp); |
| 381 | 379 |
| 382 const size_t kRowSize = 76; | 380 const size_t kRowSize = 76; |
| 383 for (size_t offset = 0; offset < base64.size(); offset += kRowSize) { | 381 for (size_t offset = 0; offset < base64.size(); offset += kRowSize) { |
| 384 size_t length = std::min(base64.size() - offset, kRowSize); | 382 size_t length = std::min(base64.size() - offset, kRowSize); |
| 385 std::string segment(&base64[offset], length); | 383 std::string segment(&base64[offset], length); |
| 386 segment.push_back('\n'); | 384 segment.push_back('\n'); |
| 387 ASSERT_EQ(1U, fwrite(segment.data(), segment.size(), 1, fp)); | 385 ASSERT_EQ(1U, fwrite(segment.data(), segment.size(), 1, fp)); |
| 388 } | 386 } |
| 389 | 387 |
| 390 fclose(fp); | 388 fclose(fp); |
| 389 #endif |
| 391 } | 390 } |
| 392 | 391 |
| 393 #if !defined(OS_ANDROID) | 392 #if !defined(OS_ANDROID) |
| 394 // TODO(darin): Re-enable for Android once this test accounts for systems with | 393 // TODO(darin): Re-enable for Android once this test accounts for systems with |
| 395 // a device scale factor not equal to 2. | 394 // a device scale factor not equal to 2. |
| 396 TEST_F(PageStateSerializationTest, BackwardsCompat_v11) { | 395 TEST_F(PageStateSerializationTest, BackwardsCompat_v11) { |
| 397 TestBackwardsCompat(11); | 396 TestBackwardsCompat(11); |
| 398 } | 397 } |
| 399 #endif | 398 #endif |
| 400 | 399 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 417 TEST_F(PageStateSerializationTest, BackwardsCompat_v16) { | 416 TEST_F(PageStateSerializationTest, BackwardsCompat_v16) { |
| 418 TestBackwardsCompat(16); | 417 TestBackwardsCompat(16); |
| 419 } | 418 } |
| 420 | 419 |
| 421 TEST_F(PageStateSerializationTest, BackwardsCompat_v18) { | 420 TEST_F(PageStateSerializationTest, BackwardsCompat_v18) { |
| 422 TestBackwardsCompat(18); | 421 TestBackwardsCompat(18); |
| 423 } | 422 } |
| 424 | 423 |
| 425 } // namespace | 424 } // namespace |
| 426 } // namespace content | 425 } // namespace content |
| OLD | NEW |