| OLD | NEW |
| 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; | |
| 28 | |
| 29 namespace drive { | 27 namespace drive { |
| 30 namespace internal { | 28 namespace internal { |
| 31 | 29 |
| 32 class WebkitFileStreamReaderImplTest : public ::testing::Test { | 30 class WebkitFileStreamReaderImplTest : public ::testing::Test { |
| 33 protected: | 31 protected: |
| 34 // Because the testee should live on IO thread, the main thread is | 32 // 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. | 33 // reused as IO thread, and UI thread will be run on background. |
| 36 WebkitFileStreamReaderImplTest() | 34 WebkitFileStreamReaderImplTest() |
| 37 : ui_thread_(BrowserThread::UI), | 35 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { |
| 38 io_thread_(BrowserThread::IO, &message_loop_) { | |
| 39 } | 36 } |
| 40 | 37 |
| 41 virtual void SetUp() OVERRIDE { | 38 virtual void SetUp() OVERRIDE { |
| 42 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 43 ui_thread_.Start(); | |
| 44 | |
| 45 worker_thread_.reset(new base::Thread("WebkitFileStreamReaderImplTest")); | 39 worker_thread_.reset(new base::Thread("WebkitFileStreamReaderImplTest")); |
| 46 ASSERT_TRUE(worker_thread_->Start()); | 40 ASSERT_TRUE(worker_thread_->Start()); |
| 47 | 41 |
| 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. | 42 // Initialize FakeDriveService. |
| 73 fake_drive_service_.reset(new google_apis::FakeDriveService); | 43 fake_drive_service_.reset(new google_apis::FakeDriveService); |
| 74 fake_drive_service_->LoadResourceListForWapi( | 44 fake_drive_service_->LoadResourceListForWapi( |
| 75 "chromeos/gdata/root_feed.json"); | 45 "chromeos/gdata/root_feed.json"); |
| 76 fake_drive_service_->LoadAccountMetadataForWapi( | 46 fake_drive_service_->LoadAccountMetadataForWapi( |
| 77 "chromeos/gdata/account_metadata.json"); | 47 "chromeos/gdata/account_metadata.json"); |
| 78 | 48 |
| 79 // Create a testee instance. | 49 // Create a testee instance. |
| 80 fake_file_system_.reset( | 50 fake_file_system_.reset( |
| 81 new test_util::FakeFileSystem(fake_drive_service_.get())); | 51 new test_util::FakeFileSystem(fake_drive_service_.get())); |
| 82 fake_file_system_->Initialize(); | 52 fake_file_system_->Initialize(); |
| 83 } | 53 } |
| 84 | 54 |
| 85 void TearDownOnUIThread() { | 55 virtual void TearDown() OVERRIDE { |
| 86 fake_file_system_.reset(); | 56 fake_file_system_.reset(); |
| 87 fake_drive_service_.reset(); | 57 fake_drive_service_.reset(); |
| 58 |
| 59 worker_thread_.reset(); |
| 88 } | 60 } |
| 89 | 61 |
| 90 FileSystemInterface* GetFileSystem() { | 62 FileSystemInterface* GetFileSystem() { |
| 91 return fake_file_system_.get(); | 63 return fake_file_system_.get(); |
| 92 } | 64 } |
| 93 | 65 |
| 94 DriveFileStreamReader::FileSystemGetter GetFileSystemGetter() { | 66 DriveFileStreamReader::FileSystemGetter GetFileSystemGetter() { |
| 95 return base::Bind(&WebkitFileStreamReaderImplTest::GetFileSystem, | 67 return base::Bind(&WebkitFileStreamReaderImplTest::GetFileSystem, |
| 96 base::Unretained(this)); | 68 base::Unretained(this)); |
| 97 } | 69 } |
| 98 | 70 |
| 99 base::MessageLoopForIO message_loop_; | 71 content::TestBrowserThreadBundle thread_bundle_; |
| 100 content::TestBrowserThread ui_thread_; | |
| 101 content::TestBrowserThread io_thread_; | |
| 102 | 72 |
| 103 scoped_ptr<base::Thread> worker_thread_; | 73 scoped_ptr<base::Thread> worker_thread_; |
| 104 | 74 |
| 105 scoped_ptr<google_apis::FakeDriveService> fake_drive_service_; | 75 scoped_ptr<google_apis::FakeDriveService> fake_drive_service_; |
| 106 scoped_ptr<test_util::FakeFileSystem> fake_file_system_; | 76 scoped_ptr<test_util::FakeFileSystem> fake_file_system_; |
| 107 }; | 77 }; |
| 108 | 78 |
| 109 TEST_F(WebkitFileStreamReaderImplTest, ReadThenGetLength) { | 79 TEST_F(WebkitFileStreamReaderImplTest, ReadThenGetLength) { |
| 110 const base::FilePath kDriveFile = | 80 const base::FilePath kDriveFile = |
| 111 util::GetDriveMyDriveRootPath().AppendASCII("File 1.txt"); | 81 util::GetDriveMyDriveRootPath().AppendASCII("File 1.txt"); |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 base::Time::FromInternalValue(1))); | 215 base::Time::FromInternalValue(1))); |
| 246 | 216 |
| 247 net::TestInt64CompletionCallback callback; | 217 net::TestInt64CompletionCallback callback; |
| 248 int64 result = reader->GetLength(callback.callback()); | 218 int64 result = reader->GetLength(callback.callback()); |
| 249 result = callback.GetResult(result); | 219 result = callback.GetResult(result); |
| 250 EXPECT_EQ(net::ERR_UPLOAD_FILE_CHANGED, result); | 220 EXPECT_EQ(net::ERR_UPLOAD_FILE_CHANGED, result); |
| 251 } | 221 } |
| 252 | 222 |
| 253 } // namespace internal | 223 } // namespace internal |
| 254 } // namespace drive | 224 } // namespace drive |
| OLD | NEW |