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

Side by Side Diff: chrome/browser/chromeos/drive/webkit_file_stream_reader_impl_unittest.cc

Issue 14197014: Add TestBrowserThreadBundle into RenderViewHostTestHarness. Kill some unnecessary real threads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: compile fixes. Created 7 years, 6 months 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
OLDNEW
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 "chrome/browser/chromeos/drive/webkit_file_stream_reader_impl.h" 5 #include "chrome/browser/chromeos/drive/webkit_file_stream_reader_impl.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/message_loop.h" 12 #include "base/message_loop.h"
13 #include "base/threading/thread.h" 13 #include "base/threading/thread.h"
14 #include "base/time.h" 14 #include "base/time.h"
15 #include "chrome/browser/chromeos/drive/fake_file_system.h" 15 #include "chrome/browser/chromeos/drive/fake_file_system.h"
16 #include "chrome/browser/chromeos/drive/file_system_interface.h" 16 #include "chrome/browser/chromeos/drive/file_system_interface.h"
17 #include "chrome/browser/chromeos/drive/file_system_util.h" 17 #include "chrome/browser/chromeos/drive/file_system_util.h"
18 #include "chrome/browser/chromeos/drive/test_util.h" 18 #include "chrome/browser/chromeos/drive/test_util.h"
19 #include "chrome/browser/google_apis/fake_drive_service.h" 19 #include "chrome/browser/google_apis/fake_drive_service.h"
20 #include "chrome/browser/google_apis/time_util.h" 20 #include "chrome/browser/google_apis/time_util.h"
21 #include "content/public/test/test_browser_thread.h" 21 #include "content/public/test/test_browser_thread_bundle.h"
22 #include "net/base/io_buffer.h" 22 #include "net/base/io_buffer.h"
23 #include "net/base/net_errors.h" 23 #include "net/base/net_errors.h"
24 #include "net/base/test_completion_callback.h" 24 #include "net/base/test_completion_callback.h"
25 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
26 26
27 using content::BrowserThread; 27 using content::BrowserThread;
28 28
29 namespace drive { 29 namespace drive {
30 namespace internal { 30 namespace internal {
31 31
32 class WebkitFileStreamReaderImplTest : public ::testing::Test { 32 class WebkitFileStreamReaderImplTest : public ::testing::Test {
33 protected: 33 protected:
34 // Because the testee should live on IO thread, the main thread is 34 // Because the testee should live on IO thread, the main thread is
35 // reused as IO thread, and UI thread will be run on background. 35 // reused as IO thread, and UI thread will be run on background.
36 WebkitFileStreamReaderImplTest() 36 WebkitFileStreamReaderImplTest()
37 : ui_thread_(BrowserThread::UI), 37 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {
38 io_thread_(BrowserThread::IO, &message_loop_) {
39 } 38 }
40 39
41 virtual void SetUp() OVERRIDE { 40 virtual void SetUp() OVERRIDE {
42 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
43 ui_thread_.Start();
44
45 worker_thread_.reset(new base::Thread("WebkitFileStreamReaderImplTest")); 41 worker_thread_.reset(new base::Thread("WebkitFileStreamReaderImplTest"));
46 ASSERT_TRUE(worker_thread_->Start()); 42 ASSERT_TRUE(worker_thread_->Start());
47 43
48 BrowserThread::PostTaskAndReply(
49 BrowserThread::UI,
50 FROM_HERE,
51 base::Bind(&WebkitFileStreamReaderImplTest::SetUpOnUIThread,
52 base::Unretained(this)),
53 base::MessageLoop::QuitClosure());
54 message_loop_.Run();
55 }
56
57 virtual void TearDown() OVERRIDE {
58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
59
60 BrowserThread::PostTaskAndReply(
61 BrowserThread::UI,
62 FROM_HERE,
63 base::Bind(&WebkitFileStreamReaderImplTest::TearDownOnUIThread,
64 base::Unretained(this)),
65 base::MessageLoop::QuitClosure());
66 message_loop_.Run();
67
68 worker_thread_.reset();
69 }
70
71 void SetUpOnUIThread() {
72 // Initialize FakeDriveService. 44 // Initialize FakeDriveService.
73 fake_drive_service_.reset(new google_apis::FakeDriveService); 45 fake_drive_service_.reset(new google_apis::FakeDriveService);
74 fake_drive_service_->LoadResourceListForWapi( 46 fake_drive_service_->LoadResourceListForWapi(
75 "chromeos/gdata/root_feed.json"); 47 "chromeos/gdata/root_feed.json");
76 fake_drive_service_->LoadAccountMetadataForWapi( 48 fake_drive_service_->LoadAccountMetadataForWapi(
77 "chromeos/gdata/account_metadata.json"); 49 "chromeos/gdata/account_metadata.json");
78 50
79 // Create a testee instance. 51 // Create a testee instance.
80 fake_file_system_.reset( 52 fake_file_system_.reset(
81 new test_util::FakeFileSystem(fake_drive_service_.get())); 53 new test_util::FakeFileSystem(fake_drive_service_.get()));
82 fake_file_system_->Initialize(); 54 fake_file_system_->Initialize();
83 } 55 }
84 56
85 void TearDownOnUIThread() { 57 virtual void TearDown() OVERRIDE {
86 fake_file_system_.reset(); 58 fake_file_system_.reset();
87 fake_drive_service_.reset(); 59 fake_drive_service_.reset();
60
61 worker_thread_.reset();
88 } 62 }
89 63
90 FileSystemInterface* GetFileSystem() { 64 FileSystemInterface* GetFileSystem() {
91 return fake_file_system_.get(); 65 return fake_file_system_.get();
92 } 66 }
93 67
94 DriveFileStreamReader::FileSystemGetter GetFileSystemGetter() { 68 DriveFileStreamReader::FileSystemGetter GetFileSystemGetter() {
95 return base::Bind(&WebkitFileStreamReaderImplTest::GetFileSystem, 69 return base::Bind(&WebkitFileStreamReaderImplTest::GetFileSystem,
96 base::Unretained(this)); 70 base::Unretained(this));
97 } 71 }
98 72
99 base::MessageLoopForIO message_loop_; 73 content::TestBrowserThreadBundle thread_bundle_;
100 content::TestBrowserThread ui_thread_;
101 content::TestBrowserThread io_thread_;
102 74
103 scoped_ptr<base::Thread> worker_thread_; 75 scoped_ptr<base::Thread> worker_thread_;
104 76
105 scoped_ptr<google_apis::FakeDriveService> fake_drive_service_; 77 scoped_ptr<google_apis::FakeDriveService> fake_drive_service_;
106 scoped_ptr<test_util::FakeFileSystem> fake_file_system_; 78 scoped_ptr<test_util::FakeFileSystem> fake_file_system_;
107 }; 79 };
108 80
109 TEST_F(WebkitFileStreamReaderImplTest, ReadThenGetLength) { 81 TEST_F(WebkitFileStreamReaderImplTest, ReadThenGetLength) {
110 const base::FilePath kDriveFile = 82 const base::FilePath kDriveFile =
111 util::GetDriveMyDriveRootPath().AppendASCII("File 1.txt"); 83 util::GetDriveMyDriveRootPath().AppendASCII("File 1.txt");
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 base::Time::FromInternalValue(1))); 217 base::Time::FromInternalValue(1)));
246 218
247 net::TestInt64CompletionCallback callback; 219 net::TestInt64CompletionCallback callback;
248 int64 result = reader->GetLength(callback.callback()); 220 int64 result = reader->GetLength(callback.callback());
249 result = callback.GetResult(result); 221 result = callback.GetResult(result);
250 EXPECT_EQ(net::ERR_UPLOAD_FILE_CHANGED, result); 222 EXPECT_EQ(net::ERR_UPLOAD_FILE_CHANGED, result);
251 } 223 }
252 224
253 } // namespace internal 225 } // namespace internal
254 } // namespace drive 226 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698