1 // Copyright (c) 2012 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.
5 #ifndef COMPONENTS_DRIVE_DRIVE_TEST_UTIL_H_
6 #define COMPONENTS_DRIVE_DRIVE_TEST_UTIL_H_
10 #include "components/drive/file_cache.h"
11 #include "content/public/test/test_utils.h"
12 #include "google_apis/drive/test_util.h"
13 #include "net/base/completion_callback.h"
14 #include "net/base/io_buffer.h"
15 #include "net/base/network_change_notifier.h"
16 #include "net/base/test_completion_callback.h"
18 class PrefRegistrySimple
;
28 // Disk space size used by FakeFreeDiskSpaceGetter.
29 const int64 kLotsOfSpace
= drive::internal::kMinFreeSpaceInBytes
* 10;
31 // Helper to destroy objects which needs Destroy() to be called on destruction.
32 // Note: When using this helper, you should destruct objects before
34 struct DestroyHelperForTests
{
36 void operator()(T
* object
) const {
39 content::RunAllBlockingPoolTasksUntilIdle(); // Finish destruction.
44 // Reads all the data from |reader| and copies to |content|. Returns net::Error
46 template<typename Reader
>
47 int ReadAllData(Reader
* reader
, std::string
* content
) {
48 const int kBufferSize
= 10;
49 scoped_refptr
<net::IOBuffer
> buffer(new net::IOBuffer(kBufferSize
));
51 net::TestCompletionCallback callback
;
52 int result
= reader
->Read(buffer
.get(), kBufferSize
, callback
.callback());
53 result
= callback
.GetResult(result
);
55 // Found an error or EOF. Return it. Note: net::OK is 0.
58 content
->append(buffer
->data(), result
);
62 // Registers Drive related preferences in |pref_registry|. Drive related
63 // preferences should be registered as TestingPrefServiceSimple will crash if
64 // unregistered preference is referenced.
65 void RegisterDrivePrefs(PrefRegistrySimple
* pref_registry
);
67 // Fake NetworkChangeNotifier implementation.
68 class FakeNetworkChangeNotifier
: public net::NetworkChangeNotifier
{
70 FakeNetworkChangeNotifier();
72 void SetConnectionType(ConnectionType type
);
74 // NetworkChangeNotifier override.
75 ConnectionType
GetCurrentConnectionType() const override
;
78 net::NetworkChangeNotifier::ConnectionType type_
;
81 } // namespace test_util
84 #endif // COMPONENTS_DRIVE_DRIVE_TEST_UTIL_H_