Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(147)

Side by Side Diff: chrome/browser/download/download_browsertest.cc

Issue 8468028: Restructure URLRequestSlowDownloadJob to avoid races. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merged to TOT. Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | content/browser/net/url_request_slow_download_job.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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);
661 if (memcmp(file_contents.c_str(), value.c_str(), expected_size) != 0) 663 if (memcmp(file_contents.c_str(), value.c_str(), expected_size) != 0)
662 return false; 664 return false;
663 665
664 return true; 666 return true;
665 } 667 }
666 668
667 private: 669 private:
668 // Location of the test data. 670 // Location of the test data.
669 FilePath test_dir_; 671 FilePath test_dir_;
670 672
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 // The test will first attempt to download a file; but the server will "pause" 832 // The test will first attempt to download a file; but the server will "pause"
831 // in the middle until the server receives a second request for 833 // in the middle until the server receives a second request for
832 // "download-finish". At that time, the download will finish. 834 // "download-finish". At that time, the download will finish.
833 // These tests don't currently test much due to holes in |RunSizeTest()|. See 835 // These tests don't currently test much due to holes in |RunSizeTest()|. See
834 // comments in that routine for details. 836 // comments in that routine for details.
835 IN_PROC_BROWSER_TEST_F(DownloadTest, UnknownSize) { 837 IN_PROC_BROWSER_TEST_F(DownloadTest, UnknownSize) {
836 ASSERT_TRUE(RunSizeTest(browser(), SIZE_TEST_TYPE_UNKNOWN, 838 ASSERT_TRUE(RunSizeTest(browser(), SIZE_TEST_TYPE_UNKNOWN,
837 "32.0 KB - ", "100% - ")); 839 "32.0 KB - ", "100% - "));
838 } 840 }
839 841
840 #if defined(OS_LINUX)
841 // http://crbug.com/104310
842 #define KnownSize FLAKY_KnownSize
843 #endif
844 IN_PROC_BROWSER_TEST_F(DownloadTest, KnownSize) { 842 IN_PROC_BROWSER_TEST_F(DownloadTest, KnownSize) {
845 ASSERT_TRUE(RunSizeTest(browser(), SIZE_TEST_TYPE_KNOWN, 843 ASSERT_TRUE(RunSizeTest(browser(), SIZE_TEST_TYPE_KNOWN,
846 "71% - ", "100% - ")); 844 "71% - ", "100% - "));
847 } 845 }
848 846
849 // Test that when downloading an item in Incognito mode, we don't crash when 847 // Test that when downloading an item in Incognito mode, we don't crash when
850 // closing the last Incognito window (http://crbug.com/13983). 848 // closing the last Incognito window (http://crbug.com/13983).
851 // Also check that the download shelf is not visible after closing the 849 // Also check that the download shelf is not visible after closing the
852 // Incognito window. 850 // Incognito window.
853 IN_PROC_BROWSER_TEST_F(DownloadTest, IncognitoDownload) { 851 IN_PROC_BROWSER_TEST_F(DownloadTest, IncognitoDownload) {
(...skipping 821 matching lines...) Expand 10 before | Expand all | Expand 10 after
1675 search_results.clear(); 1673 search_results.clear();
1676 1674
1677 manager->SearchDownloads(UTF8ToUTF16("another_file"), &search_results); 1675 manager->SearchDownloads(UTF8ToUTF16("another_file"), &search_results);
1678 ASSERT_EQ(2u, search_results.size()); 1676 ASSERT_EQ(2u, search_results.size());
1679 std::sort(search_results.begin(), search_results.end(), 1677 std::sort(search_results.begin(), search_results.end(),
1680 DownloadItemSorter); 1678 DownloadItemSorter);
1681 EXPECT_EQ(2, search_results[0]->GetDbHandle()); 1679 EXPECT_EQ(2, search_results[0]->GetDbHandle());
1682 EXPECT_EQ(3, search_results[1]->GetDbHandle()); 1680 EXPECT_EQ(3, search_results[1]->GetDbHandle());
1683 search_results.clear(); 1681 search_results.clear();
1684 } 1682 }
OLDNEW
« no previous file with comments | « no previous file | content/browser/net/url_request_slow_download_job.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698