| OLD | NEW |
| (Empty) | |
| 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. |
| 4 |
| 5 #include "chrome/browser/chromeos/gdata/gdata_test_util.h" |
| 6 |
| 7 #include "base/file_util.h" |
| 8 #include "base/json/json_file_value_serializer.h" |
| 9 #include "base/message_loop.h" |
| 10 #include "base/path_service.h" |
| 11 #include "base/threading/sequenced_worker_pool.h" |
| 12 #include "chrome/common/chrome_paths.h" |
| 13 #include "content/public/browser/browser_thread.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 |
| 16 |
| 17 namespace gdata { |
| 18 namespace test_util { |
| 19 |
| 20 // This class is used to monitor if any task is posted to a message loop. |
| 21 class TaskObserver : public MessageLoop::TaskObserver { |
| 22 public: |
| 23 TaskObserver() : posted_(false) {} |
| 24 virtual ~TaskObserver() {} |
| 25 |
| 26 // MessageLoop::TaskObserver overrides. |
| 27 virtual void WillProcessTask(base::TimeTicks time_posted) {} |
| 28 virtual void DidProcessTask(base::TimeTicks time_posted) { |
| 29 posted_ = true; |
| 30 } |
| 31 |
| 32 // Returns true if any task was posted. |
| 33 bool posted() const { return posted_; } |
| 34 |
| 35 private: |
| 36 bool posted_; |
| 37 DISALLOW_COPY_AND_ASSIGN(TaskObserver); |
| 38 }; |
| 39 |
| 40 FilePath GetTestFilePath(const std::string& relative_path) { |
| 41 FilePath path; |
| 42 std::string error; |
| 43 PathService::Get(chrome::DIR_TEST_DATA, &path); |
| 44 path = path.AppendASCII("chromeos") |
| 45 .Append(FilePath::FromUTF8Unsafe(relative_path)); |
| 46 EXPECT_TRUE(file_util::PathExists(path)) << |
| 47 "Couldn't find " << path.value(); |
| 48 return path; |
| 49 } |
| 50 |
| 51 void RunBlockingPoolTask() { |
| 52 while (true) { |
| 53 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 54 |
| 55 TaskObserver task_observer; |
| 56 MessageLoop::current()->AddTaskObserver(&task_observer); |
| 57 MessageLoop::current()->RunAllPending(); |
| 58 MessageLoop::current()->RemoveTaskObserver(&task_observer); |
| 59 if (!task_observer.posted()) |
| 60 break; |
| 61 } |
| 62 } |
| 63 |
| 64 |
| 65 scoped_ptr<base::Value> LoadJSONFile(const std::string& relative_path) { |
| 66 FilePath path = GetTestFilePath(relative_path); |
| 67 |
| 68 std::string error; |
| 69 JSONFileValueSerializer serializer(path); |
| 70 scoped_ptr<base::Value> value(serializer.Deserialize(NULL, &error)); |
| 71 EXPECT_TRUE(value.get()) << |
| 72 "Parse error " << path.value() << ": " << error; |
| 73 return value.Pass(); |
| 74 } |
| 75 |
| 76 } // namespace test_util |
| 77 } // namespace gdata |
| OLD | NEW |