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

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

Issue 14755002: drive: Drop "Drive" from FakeDriveFileSystem and MockDriveFileSystem (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: some more cleanup Created 7 years, 7 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/drive_file_stream_reader.h" 5 #include "chrome/browser/chromeos/drive/drive_file_stream_reader.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/message_loop.h" 12 #include "base/message_loop.h"
13 #include "chrome/browser/chromeos/drive/fake_drive_file_system.h" 13 #include "chrome/browser/chromeos/drive/fake_file_system.h"
14 #include "chrome/browser/chromeos/drive/file_system_util.h" 14 #include "chrome/browser/chromeos/drive/file_system_util.h"
15 #include "chrome/browser/chromeos/drive/test_util.h" 15 #include "chrome/browser/chromeos/drive/test_util.h"
16 #include "chrome/browser/google_apis/fake_drive_service.h" 16 #include "chrome/browser/google_apis/fake_drive_service.h"
17 #include "chrome/browser/google_apis/task_util.h" 17 #include "chrome/browser/google_apis/task_util.h"
18 #include "chrome/browser/google_apis/test_util.h" 18 #include "chrome/browser/google_apis/test_util.h"
19 #include "content/public/test/test_browser_thread.h" 19 #include "content/public/test/test_browser_thread.h"
20 #include "net/base/file_stream.h" 20 #include "net/base/file_stream.h"
21 #include "net/base/io_buffer.h" 21 #include "net/base/io_buffer.h"
22 #include "net/base/net_errors.h" 22 #include "net/base/net_errors.h"
23 #include "net/base/test_completion_callback.h" 23 #include "net/base/test_completion_callback.h"
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 void SetUpOnUIThread() { 314 void SetUpOnUIThread() {
315 // Initialize FakeDriveService. 315 // Initialize FakeDriveService.
316 fake_drive_service_.reset(new google_apis::FakeDriveService); 316 fake_drive_service_.reset(new google_apis::FakeDriveService);
317 fake_drive_service_->LoadResourceListForWapi( 317 fake_drive_service_->LoadResourceListForWapi(
318 "chromeos/gdata/root_feed.json"); 318 "chromeos/gdata/root_feed.json");
319 fake_drive_service_->LoadAccountMetadataForWapi( 319 fake_drive_service_->LoadAccountMetadataForWapi(
320 "chromeos/gdata/account_metadata.json"); 320 "chromeos/gdata/account_metadata.json");
321 fake_drive_service_->LoadAppListForDriveApi("chromeos/drive/applist.json"); 321 fake_drive_service_->LoadAppListForDriveApi("chromeos/drive/applist.json");
322 322
323 // Create a testee instance. 323 // Create a testee instance.
324 fake_drive_file_system_.reset( 324 fake_file_system_.reset(
325 new test_util::FakeDriveFileSystem(fake_drive_service_.get())); 325 new test_util::FakeFileSystem(fake_drive_service_.get()));
326 fake_drive_file_system_->Initialize(); 326 fake_file_system_->Initialize();
327 } 327 }
328 328
329 void TearDownOnUIThread() { 329 void TearDownOnUIThread() {
330 fake_drive_file_system_.reset(); 330 fake_file_system_.reset();
331 fake_drive_service_.reset(); 331 fake_drive_service_.reset();
332 } 332 }
333 333
334 DriveFileSystemInterface* GetDriveFileSystem() { 334 DriveFileSystemInterface* GetFileSystem() {
335 return fake_drive_file_system_.get(); 335 return fake_file_system_.get();
336 } 336 }
337 337
338 DriveFileStreamReader::DriveFileSystemGetter GetDriveFileSystemGetter() { 338 DriveFileStreamReader::FileSystemGetter GetFileSystemGetter() {
339 return base::Bind(&DriveFileStreamReaderTest::GetDriveFileSystem, 339 return base::Bind(&DriveFileStreamReaderTest::GetFileSystem,
340 base::Unretained(this)); 340 base::Unretained(this));
341 } 341 }
342 342
343 MessageLoopForIO message_loop_; 343 MessageLoopForIO message_loop_;
344 content::TestBrowserThread ui_thread_; 344 content::TestBrowserThread ui_thread_;
345 content::TestBrowserThread io_thread_; 345 content::TestBrowserThread io_thread_;
346 346
347 scoped_ptr<google_apis::FakeDriveService> fake_drive_service_; 347 scoped_ptr<google_apis::FakeDriveService> fake_drive_service_;
348 scoped_ptr<test_util::FakeDriveFileSystem> fake_drive_file_system_; 348 scoped_ptr<test_util::FakeFileSystem> fake_file_system_;
349 }; 349 };
350 350
351 TEST_F(DriveFileStreamReaderTest, Read) { 351 TEST_F(DriveFileStreamReaderTest, Read) {
352 const base::FilePath kDriveFile = 352 const base::FilePath kDriveFile =
353 util::GetDriveMyDriveRootPath().AppendASCII("File 1.txt"); 353 util::GetDriveMyDriveRootPath().AppendASCII("File 1.txt");
354 net::TestCompletionCallback callback; 354 net::TestCompletionCallback callback;
355 const int kBufferSize = 3; 355 const int kBufferSize = 3;
356 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kBufferSize)); 356 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kBufferSize));
357 357
358 // Create the reader, and initialize it. 358 // Create the reader, and initialize it.
359 // In this case, the file is not yet locally cached. 359 // In this case, the file is not yet locally cached.
360 scoped_ptr<DriveFileStreamReader> reader( 360 scoped_ptr<DriveFileStreamReader> reader(
361 new DriveFileStreamReader(GetDriveFileSystemGetter())); 361 new DriveFileStreamReader(GetFileSystemGetter()));
362 362
363 EXPECT_FALSE(reader->IsInitialized()); 363 EXPECT_FALSE(reader->IsInitialized());
364 364
365 FileError error = FILE_ERROR_FAILED; 365 FileError error = FILE_ERROR_FAILED;
366 scoped_ptr<DriveEntryProto> entry; 366 scoped_ptr<DriveEntryProto> entry;
367 reader->Initialize( 367 reader->Initialize(
368 kDriveFile, 368 kDriveFile,
369 google_apis::CreateComposedCallback( 369 google_apis::CreateComposedCallback(
370 base::Bind(&google_apis::test_util::RunAndQuit), 370 base::Bind(&google_apis::test_util::RunAndQuit),
371 google_apis::test_util::CreateCopyResultCallback( 371 google_apis::test_util::CreateCopyResultCallback(
(...skipping 11 matching lines...) Expand all
383 result = callback.GetResult(result); 383 result = callback.GetResult(result);
384 ASSERT_GT(result, 0); 384 ASSERT_GT(result, 0);
385 first_content.append(buffer->data(), result); 385 first_content.append(buffer->data(), result);
386 } 386 }
387 387
388 EXPECT_EQ(content_size, first_content.size()); 388 EXPECT_EQ(content_size, first_content.size());
389 389
390 // Create second instance and initialize it. 390 // Create second instance and initialize it.
391 // In this case, the file should be cached one. 391 // In this case, the file should be cached one.
392 reader.reset( 392 reader.reset(
393 new DriveFileStreamReader(GetDriveFileSystemGetter())); 393 new DriveFileStreamReader(GetFileSystemGetter()));
394 EXPECT_FALSE(reader->IsInitialized()); 394 EXPECT_FALSE(reader->IsInitialized());
395 395
396 error = FILE_ERROR_FAILED; 396 error = FILE_ERROR_FAILED;
397 entry.reset(); 397 entry.reset();
398 reader->Initialize( 398 reader->Initialize(
399 kDriveFile, 399 kDriveFile,
400 google_apis::CreateComposedCallback( 400 google_apis::CreateComposedCallback(
401 base::Bind(&google_apis::test_util::RunAndQuit), 401 base::Bind(&google_apis::test_util::RunAndQuit),
402 google_apis::test_util::CreateCopyResultCallback( 402 google_apis::test_util::CreateCopyResultCallback(
403 &error, &entry))); 403 &error, &entry)));
(...skipping 13 matching lines...) Expand all
417 result = callback.GetResult(result); 417 result = callback.GetResult(result);
418 ASSERT_GT(result, 0); 418 ASSERT_GT(result, 0);
419 second_content.append(buffer->data(), result); 419 second_content.append(buffer->data(), result);
420 } 420 }
421 421
422 // The same content is expected. 422 // The same content is expected.
423 EXPECT_EQ(first_content, second_content); 423 EXPECT_EQ(first_content, second_content);
424 } 424 }
425 425
426 } // namespace drive 426 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/drive_file_stream_reader.cc ('k') | chrome/browser/chromeos/drive/drive_protocol_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698