Home | History | Annotate | Download | only in drive
      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
      3 // found in the LICENSE file.
      4 
      5 #include "chrome/browser/chromeos/drive/fileapi_worker.h"
      6 
      7 #include "base/bind.h"
      8 #include "base/bind_helpers.h"
      9 #include "base/memory/scoped_ptr.h"
     10 #include "chrome/browser/chromeos/drive/dummy_file_system.h"
     11 #include "chrome/browser/google_apis/test_util.h"
     12 #include "content/public/test/test_browser_thread_bundle.h"
     13 #include "testing/gtest/include/gtest/gtest.h"
     14 
     15 namespace drive {
     16 namespace fileapi_internal {
     17 namespace {
     18 
     19 // Increments |num_called| for checking how many times the closure is called.
     20 void Increment(int* num_called) {
     21   ++*num_called;
     22 }
     23 
     24 // Returns the |instance| as is.
     25 FileSystemInterface* GetFileSystem(FileSystemInterface* instance) {
     26   return instance;
     27 }
     28 
     29 }  // namespace
     30 
     31 class FileApiWorkerTest : public testing::Test {
     32  private:
     33   content::TestBrowserThreadBundle thread_bundle_;
     34 };
     35 
     36 TEST_F(FileApiWorkerTest, RunFileSystemCallbackSuccess) {
     37   DummyFileSystem dummy_file_system;
     38 
     39   FileSystemInterface* file_system = NULL;
     40   RunFileSystemCallback(
     41       base::Bind(&GetFileSystem, &dummy_file_system),
     42       google_apis::test_util::CreateCopyResultCallback(&file_system),
     43       base::Closure());
     44 
     45   EXPECT_EQ(&dummy_file_system, file_system);
     46 }
     47 
     48 TEST_F(FileApiWorkerTest, RunFileSystemCallbackFail) {
     49   FileSystemInterface* file_system = NULL;
     50 
     51   // Make sure on_error_callback is called if file_system_getter returns NULL.
     52   int num_called = 0;
     53   RunFileSystemCallback(
     54       base::Bind(&GetFileSystem, static_cast<FileSystemInterface*>(NULL)),
     55       google_apis::test_util::CreateCopyResultCallback(&file_system),
     56       base::Bind(&Increment, &num_called));
     57   EXPECT_EQ(1, num_called);
     58 
     59   // Just make sure this null |on_error_callback| doesn't cause a crash.
     60   RunFileSystemCallback(
     61       base::Bind(&GetFileSystem, static_cast<FileSystemInterface*>(NULL)),
     62       google_apis::test_util::CreateCopyResultCallback(&file_system),
     63       base::Closure());
     64 }
     65 
     66 }  // namespace fileapi_internal
     67 }  // namespace drive
     68