OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // This file contains download browser tests that are known to be runnable | 5 // This file contains download browser tests that are known to be runnable |
6 // in a pure content context. Over time tests should be migrated here. | 6 // in a pure content context. Over time tests should be migrated here. |
7 | 7 |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
593 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(expected_terminal_state)); | 593 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(expected_terminal_state)); |
594 } | 594 } |
595 | 595 |
596 // Checks that |path| is has |file_size| bytes, and matches the |value| | 596 // Checks that |path| is has |file_size| bytes, and matches the |value| |
597 // string. | 597 // string. |
598 bool VerifyFile(const base::FilePath& path, | 598 bool VerifyFile(const base::FilePath& path, |
599 const std::string& value, | 599 const std::string& value, |
600 const int64 file_size) { | 600 const int64 file_size) { |
601 std::string file_contents; | 601 std::string file_contents; |
602 | 602 |
603 bool read = file_util::ReadFileToString(path, &file_contents); | 603 bool read = base::ReadFileToString(path, &file_contents); |
604 EXPECT_TRUE(read) << "Failed reading file: " << path.value() << std::endl; | 604 EXPECT_TRUE(read) << "Failed reading file: " << path.value() << std::endl; |
605 if (!read) | 605 if (!read) |
606 return false; // Couldn't read the file. | 606 return false; // Couldn't read the file. |
607 | 607 |
608 // Note: we don't handle really large files (more than size_t can hold) | 608 // Note: we don't handle really large files (more than size_t can hold) |
609 // so we will fail in that case. | 609 // so we will fail in that case. |
610 size_t expected_size = static_cast<size_t>(file_size); | 610 size_t expected_size = static_cast<size_t>(file_size); |
611 | 611 |
612 // Check the size. | 612 // Check the size. |
613 EXPECT_EQ(expected_size, file_contents.size()); | 613 EXPECT_EQ(expected_size, file_contents.size()); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
667 EXPECT_EQ(received_bytes, download->GetReceivedBytes()); | 667 EXPECT_EQ(received_bytes, download->GetReceivedBytes()); |
668 EXPECT_EQ(total_bytes, download->GetTotalBytes()); | 668 EXPECT_EQ(total_bytes, download->GetTotalBytes()); |
669 EXPECT_EQ(expected_filename.value(), | 669 EXPECT_EQ(expected_filename.value(), |
670 download->GetFullPath().BaseName().value()); | 670 download->GetFullPath().BaseName().value()); |
671 EXPECT_EQ(file_exists, | 671 EXPECT_EQ(file_exists, |
672 (!download->GetFullPath().empty() && | 672 (!download->GetFullPath().empty() && |
673 base::PathExists(download->GetFullPath()))); | 673 base::PathExists(download->GetFullPath()))); |
674 | 674 |
675 if (file_exists) { | 675 if (file_exists) { |
676 std::string file_contents; | 676 std::string file_contents; |
677 EXPECT_TRUE(file_util::ReadFileToString( | 677 EXPECT_TRUE(base::ReadFileToString( |
678 download->GetFullPath(), &file_contents)); | 678 download->GetFullPath(), &file_contents)); |
679 | 679 |
680 ASSERT_EQ(static_cast<size_t>(received_bytes), file_contents.size()); | 680 ASSERT_EQ(static_cast<size_t>(received_bytes), file_contents.size()); |
681 for (int i = 0; i < received_bytes; ++i) { | 681 for (int i = 0; i < received_bytes; ++i) { |
682 EXPECT_EQ(static_cast<char>((i * 2 + 15) % 256), file_contents[i]) | 682 EXPECT_EQ(static_cast<char>((i * 2 + 15) % 256), file_contents[i]) |
683 << "File contents diverged at position " << i | 683 << "File contents diverged at position " << i |
684 << " for " << expected_filename.value(); | 684 << " for " << expected_filename.value(); |
685 | 685 |
686 if (static_cast<char>((i * 2 + 15) % 256) != file_contents[i]) | 686 if (static_cast<char>((i * 2 + 15) % 256) != file_contents[i]) |
687 return; | 687 return; |
(...skipping 944 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1632 ASSERT_EQ(1u, downloads.size()); | 1632 ASSERT_EQ(1u, downloads.size()); |
1633 ASSERT_EQ(DownloadItem::COMPLETE, downloads[0]->GetState()); | 1633 ASSERT_EQ(DownloadItem::COMPLETE, downloads[0]->GetState()); |
1634 | 1634 |
1635 // Check that the cookies were correctly set. | 1635 // Check that the cookies were correctly set. |
1636 EXPECT_EQ("A=B", | 1636 EXPECT_EQ("A=B", |
1637 content::GetCookies(shell()->web_contents()->GetBrowserContext(), | 1637 content::GetCookies(shell()->web_contents()->GetBrowserContext(), |
1638 GURL(download))); | 1638 GURL(download))); |
1639 } | 1639 } |
1640 | 1640 |
1641 } // namespace content | 1641 } // namespace content |
OLD | NEW |