| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_TEST_UTIL_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_TEST_UTIL_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_TEST_UTIL_H_ | 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_TEST_UTIL_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "content/public/test/test_utils.h" |
| 10 #include "google_apis/drive/test_util.h" | 11 #include "google_apis/drive/test_util.h" |
| 11 #include "net/base/completion_callback.h" | 12 #include "net/base/completion_callback.h" |
| 12 #include "net/base/io_buffer.h" | 13 #include "net/base/io_buffer.h" |
| 13 #include "net/base/network_change_notifier.h" | 14 #include "net/base/network_change_notifier.h" |
| 14 #include "net/base/test_completion_callback.h" | 15 #include "net/base/test_completion_callback.h" |
| 15 #include "third_party/cros_system_api/constants/cryptohome.h" | 16 #include "third_party/cros_system_api/constants/cryptohome.h" |
| 16 | 17 |
| 17 class PrefRegistrySimple; | 18 class PrefRegistrySimple; |
| 18 | 19 |
| 19 namespace net { | 20 namespace net { |
| 20 class IOBuffer; | 21 class IOBuffer; |
| 21 } // namespace net | 22 } // namespace net |
| 22 | 23 |
| 23 namespace drive { | 24 namespace drive { |
| 24 | 25 |
| 25 namespace test_util { | 26 namespace test_util { |
| 26 | 27 |
| 27 // Disk space size used by FakeFreeDiskSpaceGetter. | 28 // Disk space size used by FakeFreeDiskSpaceGetter. |
| 28 const int64 kLotsOfSpace = cryptohome::kMinFreeSpaceInBytes * 10; | 29 const int64 kLotsOfSpace = cryptohome::kMinFreeSpaceInBytes * 10; |
| 29 | 30 |
| 30 // Runs a task posted to the blocking pool, including subsequent tasks posted | |
| 31 // to the UI message loop and the blocking pool. | |
| 32 // | |
| 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(); | |
| 38 | |
| 39 // Helper to destroy objects which needs Destroy() to be called on destruction. | 31 // Helper to destroy objects which needs Destroy() to be called on destruction. |
| 40 // Note: When using this helper, you should destruct objects before | 32 // Note: When using this helper, you should destruct objects before |
| 41 // BrowserThread. | 33 // BrowserThread. |
| 42 struct DestroyHelperForTests { | 34 struct DestroyHelperForTests { |
| 43 template<typename T> | 35 template<typename T> |
| 44 void operator()(T* object) const { | 36 void operator()(T* object) const { |
| 45 if (object) { | 37 if (object) { |
| 46 object->Destroy(); | 38 object->Destroy(); |
| 47 test_util::RunBlockingPoolTask(); // Finish destruction. | 39 content::RunAllBlockingPoolTasksUntilIdle(); // Finish destruction. |
| 48 } | 40 } |
| 49 } | 41 } |
| 50 }; | 42 }; |
| 51 | 43 |
| 52 // Reads all the data from |reader| and copies to |content|. Returns net::Error | 44 // Reads all the data from |reader| and copies to |content|. Returns net::Error |
| 53 // code. | 45 // code. |
| 54 template<typename Reader> | 46 template<typename Reader> |
| 55 int ReadAllData(Reader* reader, std::string* content) { | 47 int ReadAllData(Reader* reader, std::string* content) { |
| 56 const int kBufferSize = 10; | 48 const int kBufferSize = 10; |
| 57 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kBufferSize)); | 49 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kBufferSize)); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 83 virtual ConnectionType GetCurrentConnectionType() const OVERRIDE; | 75 virtual ConnectionType GetCurrentConnectionType() const OVERRIDE; |
| 84 | 76 |
| 85 private: | 77 private: |
| 86 net::NetworkChangeNotifier::ConnectionType type_; | 78 net::NetworkChangeNotifier::ConnectionType type_; |
| 87 }; | 79 }; |
| 88 | 80 |
| 89 } // namespace test_util | 81 } // namespace test_util |
| 90 } // namespace drive | 82 } // namespace drive |
| 91 | 83 |
| 92 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_TEST_UTIL_H_ | 84 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_TEST_UTIL_H_ |
| OLD | NEW |