Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
| 7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 638 } | 638 } |
| 639 | 639 |
| 640 // Checks that |path| is has |file_size| bytes, and matches the |value| | 640 // Checks that |path| is has |file_size| bytes, and matches the |value| |
| 641 // string. | 641 // string. |
| 642 bool VerifyFile(const FilePath& path, | 642 bool VerifyFile(const FilePath& path, |
| 643 const std::string& value, | 643 const std::string& value, |
| 644 const int64 file_size) { | 644 const int64 file_size) { |
| 645 std::string file_contents; | 645 std::string file_contents; |
| 646 | 646 |
| 647 bool read = file_util::ReadFileToString(path, &file_contents); | 647 bool read = file_util::ReadFileToString(path, &file_contents); |
| 648 | 648 EXPECT_TRUE(read) << "Failed reading file: " << path.value() << std::endl; |
| 649 if (!read) | 649 if (!read) |
| 650 return false; // Couldn't read the file. | 650 return false; // Couldn't read the file. |
| 651 | 651 |
| 652 // Note: we don't handle really large files (more than size_t can hold) | 652 // Note: we don't handle really large files (more than size_t can hold) |
| 653 // so we will fail in that case. | 653 // so we will fail in that case. |
| 654 size_t expected_size = static_cast<size_t>(file_size); | 654 size_t expected_size = static_cast<size_t>(file_size); |
| 655 | 655 |
| 656 // Check the size. | 656 // Check the size. |
| 657 EXPECT_EQ(expected_size, file_contents.size()); | |
| 657 if (expected_size != file_contents.size()) | 658 if (expected_size != file_contents.size()) |
| 658 return false; | 659 return false; |
| 659 | 660 |
| 660 // Check the contents. | 661 // Check the contents. |
| 662 EXPECT_EQ(value, file_contents) | |
| 663 << "File string comparison mismatch. Expected: ----\n" << value | |
|
eroman
2011/11/18 01:54:46
I believe EXPECT_EQ prints the mismatch, so should
Randy Smith (Not in Mondays)
2011/11/18 15:30:18
Done.
| |
| 664 << "\n---\nGot:\n----\n" << file_contents << std::endl; | |
| 661 if (memcmp(file_contents.c_str(), value.c_str(), expected_size) != 0) | 665 if (memcmp(file_contents.c_str(), value.c_str(), expected_size) != 0) |
| 662 return false; | 666 return false; |
| 663 | 667 |
| 664 return true; | 668 return true; |
| 665 } | 669 } |
| 666 | 670 |
| 667 private: | 671 private: |
| 668 // Location of the test data. | 672 // Location of the test data. |
| 669 FilePath test_dir_; | 673 FilePath test_dir_; |
| 670 | 674 |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 829 // The test will first attempt to download a file; but the server will "pause" | 833 // The test will first attempt to download a file; but the server will "pause" |
| 830 // in the middle until the server receives a second request for | 834 // in the middle until the server receives a second request for |
| 831 // "download-finish". At that time, the download will finish. | 835 // "download-finish". At that time, the download will finish. |
| 832 // These tests don't currently test much due to holes in |RunSizeTest()|. See | 836 // These tests don't currently test much due to holes in |RunSizeTest()|. See |
| 833 // comments in that routine for details. | 837 // comments in that routine for details. |
| 834 IN_PROC_BROWSER_TEST_F(DownloadTest, UnknownSize) { | 838 IN_PROC_BROWSER_TEST_F(DownloadTest, UnknownSize) { |
| 835 ASSERT_TRUE(RunSizeTest(browser(), SIZE_TEST_TYPE_UNKNOWN, | 839 ASSERT_TRUE(RunSizeTest(browser(), SIZE_TEST_TYPE_UNKNOWN, |
| 836 "32.0 KB - ", "100% - ")); | 840 "32.0 KB - ", "100% - ")); |
| 837 } | 841 } |
| 838 | 842 |
| 839 #if defined(OS_LINUX) | |
| 840 // http://crbug.com/104310 | |
| 841 #define KnownSize FLAKY_KnownSize | |
| 842 #endif | |
| 843 IN_PROC_BROWSER_TEST_F(DownloadTest, KnownSize) { | 843 IN_PROC_BROWSER_TEST_F(DownloadTest, KnownSize) { |
| 844 ASSERT_TRUE(RunSizeTest(browser(), SIZE_TEST_TYPE_KNOWN, | 844 ASSERT_TRUE(RunSizeTest(browser(), SIZE_TEST_TYPE_KNOWN, |
| 845 "71% - ", "100% - ")); | 845 "71% - ", "100% - ")); |
| 846 } | 846 } |
| 847 | 847 |
| 848 // Test that when downloading an item in Incognito mode, we don't crash when | 848 // Test that when downloading an item in Incognito mode, we don't crash when |
| 849 // closing the last Incognito window (http://crbug.com/13983). | 849 // closing the last Incognito window (http://crbug.com/13983). |
| 850 // Also check that the download shelf is not visible after closing the | 850 // Also check that the download shelf is not visible after closing the |
| 851 // Incognito window. | 851 // Incognito window. |
| 852 IN_PROC_BROWSER_TEST_F(DownloadTest, IncognitoDownload) { | 852 IN_PROC_BROWSER_TEST_F(DownloadTest, IncognitoDownload) { |
| (...skipping 822 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1675 search_results.clear(); | 1675 search_results.clear(); |
| 1676 | 1676 |
| 1677 manager->SearchDownloads(UTF8ToUTF16("another_file"), &search_results); | 1677 manager->SearchDownloads(UTF8ToUTF16("another_file"), &search_results); |
| 1678 ASSERT_EQ(2u, search_results.size()); | 1678 ASSERT_EQ(2u, search_results.size()); |
| 1679 std::sort(search_results.begin(), search_results.end(), | 1679 std::sort(search_results.begin(), search_results.end(), |
| 1680 DownloadItemSorter); | 1680 DownloadItemSorter); |
| 1681 EXPECT_EQ(2, search_results[0]->db_handle()); | 1681 EXPECT_EQ(2, search_results[0]->db_handle()); |
| 1682 EXPECT_EQ(3, search_results[1]->db_handle()); | 1682 EXPECT_EQ(3, search_results[1]->db_handle()); |
| 1683 search_results.clear(); | 1683 search_results.clear(); |
| 1684 } | 1684 } |
| OLD | NEW |