Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / chromeos / drive / test_util.h
blob2e418a8b1aae86bafbbb8693171cee3da401ace3
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 "content/public/test/test_utils.h"
11 #include "google_apis/drive/test_util.h"
12 #include "net/base/completion_callback.h"
13 #include "net/base/io_buffer.h"
14 #include "net/base/network_change_notifier.h"
15 #include "net/base/test_completion_callback.h"
16 #include "third_party/cros_system_api/constants/cryptohome.h"
18 class PrefRegistrySimple;
20 namespace net {
21 class IOBuffer;
22 } // namespace net
24 namespace drive {
26 namespace test_util {
28 // Disk space size used by FakeFreeDiskSpaceGetter.
29 const int64 kLotsOfSpace = cryptohome::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
33 // BrowserThread.
34 struct DestroyHelperForTests {
35 template<typename T>
36 void operator()(T* object) const {
37 if (object) {
38 object->Destroy();
39 content::RunAllBlockingPoolTasksUntilIdle(); // Finish destruction.
44 // Reads all the data from |reader| and copies to |content|. Returns net::Error
45 // code.
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));
50 while (true) {
51 net::TestCompletionCallback callback;
52 int result = reader->Read(buffer.get(), kBufferSize, callback.callback());
53 result = callback.GetResult(result);
54 if (result <= 0) {
55 // Found an error or EOF. Return it. Note: net::OK is 0.
56 return result;
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 {
69 public:
70 FakeNetworkChangeNotifier();
72 void SetConnectionType(ConnectionType type);
74 // NetworkChangeNotifier override.
75 ConnectionType GetCurrentConnectionType() const override;
77 private:
78 net::NetworkChangeNotifier::ConnectionType type_;
81 } // namespace test_util
82 } // namespace drive
84 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_TEST_UTIL_H_