summaryrefslogtreecommitdiffstats
path: root/webkit/fileapi/file_system_usage_tracker_unittest.cc
blob: 0d8a33c3f9c5b2c4659886e2f6a84f5c1ed6389a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "webkit/fileapi/file_system_usage_tracker.h"

#include "base/basictypes.h"
#include "base/file_util.h"
#include "base/message_loop.h"
#include "base/message_loop_proxy.h"
#include "base/scoped_callback_factory.h"
#include "googleurl/src/gurl.h"
#include "base/scoped_temp_dir.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "webkit/fileapi/file_system_path_manager.h"
#include "webkit/fileapi/file_system_types.h"

using namespace fileapi;

class FileSystemUsageTrackerTest : public testing::Test {
 public:
  FileSystemUsageTrackerTest()
      : callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
  }

  void SetUp() {
    ASSERT_TRUE(data_dir_.CreateUniqueTempDir());
  }

 protected:
  FileSystemUsageTracker* NewUsageTracker(bool is_incognito) {
    return new FileSystemUsageTracker(
        base::MessageLoopProxy::CreateForCurrentThread(),
        data_dir_.path(), is_incognito);
  }

  int64 GetOriginUsage(FileSystemUsageTracker* tracker,
                       const GURL& origin_url,
                       fileapi::FileSystemType type) {
    tracker->GetOriginUsage(origin_url, type,
        callback_factory_.NewCallback(
            &FileSystemUsageTrackerTest::OnGetUsage));
    MessageLoop::current()->RunAllPending();
    return usage_;
  }

 private:
  void OnGetUsage(int64 usage) {
    usage_ = usage;
  }

  ScopedTempDir data_dir_;
  base::ScopedCallbackFactory<FileSystemUsageTrackerTest> callback_factory_;
  int64 usage_;

  DISALLOW_COPY_AND_ASSIGN(FileSystemUsageTrackerTest);
};

// TODO(dmikurube): change this test to a meaningful one once we add
// the real code in the FileSystemUsageTracker.
TEST_F(FileSystemUsageTrackerTest, DummyTest) {
  scoped_ptr<FileSystemUsageTracker> tracker(NewUsageTracker(false));
  ASSERT_EQ(0, GetOriginUsage(tracker.get(),
                              GURL("http://www.dummy.org/"),
                              fileapi::kFileSystemTypeTemporary));
}