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 CHROME_BROWSER_CHROMEOS_DRIVE_TEST_UTIL_H_
6 #define CHROME_BROWSER_CHROMEOS_DRIVE_TEST_UTIL_H_
10 #include "google_apis/drive/test_util.h"
11 #include "net/base/completion_callback.h"
12 #include "net/base/io_buffer.h"
13 #include "net/base/network_change_notifier.h"
14 #include "net/base/test_completion_callback.h"
15 #include "third_party/cros_system_api/constants/cryptohome.h"
17 class PrefRegistrySimple
;
27 // Disk space size used by FakeFreeDiskSpaceGetter.
28 const int64 kLotsOfSpace
= cryptohome::kMinFreeSpaceInBytes
* 10;
30 // Runs a task posted to the blocking pool, including subsequent tasks posted
31 // to the UI message loop and the blocking pool.
33 // A task is often posted to the blocking pool with PostTaskAndReply(). In
34 // that case, a task is posted back to the UI message loop, which can again
35 // post a task to the blocking pool. This function processes these tasks
37 void RunBlockingPoolTask();
39 // Helper to destroy objects which needs Destroy() to be called on destruction.
40 // Note: When using this helper, you should destruct objects before
42 struct DestroyHelperForTests
{
44 void operator()(T
* object
) const {
47 test_util::RunBlockingPoolTask(); // Finish destruction.
52 // Reads all the data from |reader| and copies to |content|. Returns net::Error
54 template<typename Reader
>
55 int ReadAllData(Reader
* reader
, std::string
* content
) {
56 const int kBufferSize
= 10;
57 scoped_refptr
<net::IOBuffer
> buffer(new net::IOBuffer(kBufferSize
));
59 net::TestCompletionCallback callback
;
60 int result
= reader
->Read(buffer
.get(), kBufferSize
, callback
.callback());
61 result
= callback
.GetResult(result
);
63 // Found an error or EOF. Return it. Note: net::OK is 0.
66 content
->append(buffer
->data(), result
);
70 // Registers Drive related preferences in |pref_registry|. Drive related
71 // preferences should be registered as TestingPrefServiceSimple will crash if
72 // unregistered preference is referenced.
73 void RegisterDrivePrefs(PrefRegistrySimple
* pref_registry
);
75 // Fake NetworkChangeNotifier implementation.
76 class FakeNetworkChangeNotifier
: public net::NetworkChangeNotifier
{
78 FakeNetworkChangeNotifier();
80 void SetConnectionType(ConnectionType type
);
82 // NetworkChangeNotifier override.
83 virtual ConnectionType
GetCurrentConnectionType() const OVERRIDE
;
86 net::NetworkChangeNotifier::ConnectionType type_
;
89 } // namespace test_util
92 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_TEST_UTIL_H_