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

Side by Side Diff: content/browser/download/download_file_unittest.cc

Issue 2487073005: Remove direct usage of BrowserThreadImpl in tests (Closed)
Patch Set: The RDHImpl is actually not even necessary in ResourceSchedulerTest, removed. Created 4 years, 1 month 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
OLDNEW
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 #include <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/files/file.h" 11 #include "base/files/file.h"
12 #include "base/files/file_util.h" 12 #include "base/files/file_util.h"
13 #include "base/location.h" 13 #include "base/location.h"
14 #include "base/run_loop.h" 14 #include "base/run_loop.h"
15 #include "base/single_thread_task_runner.h" 15 #include "base/single_thread_task_runner.h"
16 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
17 #include "base/test/test_file_util.h" 17 #include "base/test/test_file_util.h"
18 #include "base/threading/thread_task_runner_handle.h" 18 #include "base/threading/thread_task_runner_handle.h"
19 #include "build/build_config.h" 19 #include "build/build_config.h"
20 #include "content/browser/browser_thread_impl.h"
21 #include "content/browser/byte_stream.h" 20 #include "content/browser/byte_stream.h"
22 #include "content/browser/download/download_create_info.h" 21 #include "content/browser/download/download_create_info.h"
23 #include "content/browser/download/download_destination_observer.h" 22 #include "content/browser/download/download_destination_observer.h"
24 #include "content/browser/download/download_file_impl.h" 23 #include "content/browser/download/download_file_impl.h"
25 #include "content/browser/download/download_request_handle.h" 24 #include "content/browser/download/download_request_handle.h"
26 #include "content/public/browser/download_interrupt_reasons.h" 25 #include "content/public/browser/download_interrupt_reasons.h"
27 #include "content/public/browser/download_manager.h" 26 #include "content/public/browser/download_manager.h"
28 #include "content/public/test/mock_download_manager.h" 27 #include "content/public/test/mock_download_manager.h"
28 #include "content/public/test/test_browser_thread_bundle.h"
29 #include "net/base/file_stream.h" 29 #include "net/base/file_stream.h"
30 #include "net/base/mock_file_stream.h" 30 #include "net/base/mock_file_stream.h"
31 #include "net/base/net_errors.h" 31 #include "net/base/net_errors.h"
32 #include "net/log/net_log_with_source.h" 32 #include "net/log/net_log_with_source.h"
33 #include "testing/gmock/include/gmock/gmock.h" 33 #include "testing/gmock/include/gmock/gmock.h"
34 #include "testing/gtest/include/gtest/gtest.h" 34 #include "testing/gtest/include/gtest/gtest.h"
35 35
36 using ::testing::_; 36 using ::testing::_;
37 using ::testing::AnyNumber; 37 using ::testing::AnyNumber;
38 using ::testing::DoAll; 38 using ::testing::DoAll;
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 public: 131 public:
132 static const char kTestData1[]; 132 static const char kTestData1[];
133 static const char kTestData2[]; 133 static const char kTestData2[];
134 static const char kTestData3[]; 134 static const char kTestData3[];
135 static const char kDataHash[]; 135 static const char kDataHash[];
136 static const char kEmptyHash[]; 136 static const char kEmptyHash[];
137 static const uint32_t kDummyDownloadId; 137 static const uint32_t kDummyDownloadId;
138 static const int kDummyChildId; 138 static const int kDummyChildId;
139 static const int kDummyRequestId; 139 static const int kDummyRequestId;
140 140
141 DownloadFileTest() : 141 DownloadFileTest()
142 observer_(new StrictMock<MockDownloadDestinationObserver>), 142 : observer_(new StrictMock<MockDownloadDestinationObserver>),
143 observer_factory_(observer_.get()), 143 observer_factory_(observer_.get()),
144 input_stream_(NULL), 144 input_stream_(NULL),
145 bytes_(-1), 145 bytes_(-1),
146 bytes_per_sec_(-1), 146 bytes_per_sec_(-1) {}
147 ui_thread_(BrowserThread::UI, &loop_),
148 file_thread_(BrowserThread::FILE, &loop_) {
149 }
150 147
151 ~DownloadFileTest() override {} 148 ~DownloadFileTest() override {}
152 149
153 void SetUpdateDownloadInfo(int64_t bytes, int64_t bytes_per_sec) { 150 void SetUpdateDownloadInfo(int64_t bytes, int64_t bytes_per_sec) {
154 bytes_ = bytes; 151 bytes_ = bytes;
155 bytes_per_sec_ = bytes_per_sec; 152 bytes_per_sec_ = bytes_per_sec;
156 } 153 }
157 154
158 void ConfirmUpdateDownloadInfo() { 155 void ConfirmUpdateDownloadInfo() {
159 observer_->CurrentUpdateStatus(bytes_, bytes_per_sec_); 156 observer_->CurrentUpdateStatus(bytes_, bytes_per_sec_);
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 // Owned by download_file_; will be alive for lifetime of download_file_. 362 // Owned by download_file_; will be alive for lifetime of download_file_.
366 StrictMock<MockByteStreamReader>* input_stream_; 363 StrictMock<MockByteStreamReader>* input_stream_;
367 364
368 // Sink callback data for stream. 365 // Sink callback data for stream.
369 base::Closure sink_callback_; 366 base::Closure sink_callback_;
370 367
371 // Latest update sent to the observer. 368 // Latest update sent to the observer.
372 int64_t bytes_; 369 int64_t bytes_;
373 int64_t bytes_per_sec_; 370 int64_t bytes_per_sec_;
374 371
375 base::MessageLoop loop_;
376
377 private: 372 private:
378 void SetRenameResult(const base::Closure& closure, 373 void SetRenameResult(const base::Closure& closure,
379 DownloadInterruptReason* reason_p, 374 DownloadInterruptReason* reason_p,
380 base::FilePath* result_path_p, 375 base::FilePath* result_path_p,
381 DownloadInterruptReason reason, 376 DownloadInterruptReason reason,
382 const base::FilePath& result_path) { 377 const base::FilePath& result_path) {
383 if (reason_p) 378 if (reason_p)
384 *reason_p = reason; 379 *reason_p = reason;
385 if (result_path_p) 380 if (result_path_p)
386 *result_path_p = result_path; 381 *result_path_p = result_path;
387 closure.Run(); 382 closure.Run();
388 } 383 }
389 384
390 // UI thread. 385 TestBrowserThreadBundle thread_bundle_;
391 BrowserThreadImpl ui_thread_;
392 // File thread to satisfy debug checks in DownloadFile.
393 BrowserThreadImpl file_thread_;
394 386
395 // Keep track of what data should be saved to the disk file. 387 // Keep track of what data should be saved to the disk file.
396 std::string expected_data_; 388 std::string expected_data_;
397 }; 389 };
398 390
399 // DownloadFile::RenameAndAnnotate and DownloadFile::RenameAndUniquify have a 391 // DownloadFile::RenameAndAnnotate and DownloadFile::RenameAndUniquify have a
400 // considerable amount of functional overlap. In order to re-use test logic, we 392 // considerable amount of functional overlap. In order to re-use test logic, we
401 // are going to introduce this value parameterized test fixture. It will take a 393 // are going to introduce this value parameterized test fixture. It will take a
402 // DownloadFileRenameMethodType value which can be either of the two rename 394 // DownloadFileRenameMethodType value which can be either of the two rename
403 // methods. 395 // methods.
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 EXPECT_CALL(*(observer_.get()), 782 EXPECT_CALL(*(observer_.get()),
791 CurrentUpdateStatus(strlen(kTestData1) + strlen(kTestData2), _)); 783 CurrentUpdateStatus(strlen(kTestData1) + strlen(kTestData2), _));
792 784
793 sink_callback_.Run(); 785 sink_callback_.Run();
794 base::RunLoop().RunUntilIdle(); 786 base::RunLoop().RunUntilIdle();
795 VerifyStreamAndSize(); 787 VerifyStreamAndSize();
796 DestroyDownloadFile(0); 788 DestroyDownloadFile(0);
797 } 789 }
798 790
799 } // namespace content 791 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/download/base_file_unittest.cc ('k') | content/browser/indexed_db/indexed_db_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698