Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / chromeos / drive / test_util.h
blob8a300117516e1b2d1e94161fa26d7fc68c532df3
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_
8 #include <string>
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;
19 namespace net {
20 class IOBuffer;
21 } // namespace net
23 namespace drive {
25 namespace test_util {
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
36 // repeatedly.
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
41 // BrowserThread.
42 struct DestroyHelperForTests {
43 template<typename T>
44 void operator()(T* object) const {
45 if (object) {
46 object->Destroy();
47 test_util::RunBlockingPoolTask(); // Finish destruction.
52 // Reads all the data from |reader| and copies to |content|. Returns net::Error
53 // code.
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));
58 while (true) {
59 net::TestCompletionCallback callback;
60 int result = reader->Read(buffer.get(), kBufferSize, callback.callback());
61 result = callback.GetResult(result);
62 if (result <= 0) {
63 // Found an error or EOF. Return it. Note: net::OK is 0.
64 return result;
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 {
77 public:
78 FakeNetworkChangeNotifier();
80 void SetConnectionType(ConnectionType type);
82 // NetworkChangeNotifier override.
83 virtual ConnectionType GetCurrentConnectionType() const OVERRIDE;
85 private:
86 net::NetworkChangeNotifier::ConnectionType type_;
89 } // namespace test_util
90 } // namespace drive
92 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_TEST_UTIL_H_