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 #include "chrome/browser/google_apis/test_util.h" | 5 #include "chrome/browser/google_apis/test_util.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/json/json_file_value_serializer.h" | 8 #include "base/json/json_file_value_serializer.h" |
9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
12 #include "base/pending_task.h" | 12 #include "base/pending_task.h" |
13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
14 #include "base/stringprintf.h" | 14 #include "base/stringprintf.h" |
15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
16 #include "base/strings/string_split.h" | 16 #include "base/strings/string_split.h" |
17 #include "base/threading/sequenced_worker_pool.h" | 17 #include "base/threading/sequenced_worker_pool.h" |
18 #include "chrome/browser/google_apis/drive_api_parser.h" | 18 #include "chrome/browser/google_apis/drive_api_parser.h" |
19 #include "chrome/browser/google_apis/gdata_wapi_operations.h" | 19 #include "chrome/browser/google_apis/gdata_wapi_operations.h" |
20 #include "chrome/browser/google_apis/gdata_wapi_parser.h" | 20 #include "chrome/browser/google_apis/gdata_wapi_parser.h" |
21 #include "chrome/browser/google_apis/test_server/http_request.h" | 21 #include "chrome/browser/google_apis/test_server/http_request.h" |
22 #include "chrome/browser/google_apis/test_server/http_response.h" | 22 #include "chrome/browser/google_apis/test_server/http_response.h" |
23 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
24 #include "googleurl/src/gurl.h" | 24 #include "googleurl/src/gurl.h" |
25 | 25 |
26 namespace google_apis { | 26 namespace google_apis { |
27 namespace test_util { | 27 namespace test_util { |
28 | 28 |
29 // This class is used to monitor if any task is posted to a message loop. | 29 // This class is used to monitor if any task is posted to a message loop. |
30 class TaskObserver : public MessageLoop::TaskObserver { | 30 class TaskObserver : public base::MessageLoop::TaskObserver { |
31 public: | 31 public: |
32 TaskObserver() : posted_(false) {} | 32 TaskObserver() : posted_(false) {} |
33 virtual ~TaskObserver() {} | 33 virtual ~TaskObserver() {} |
34 | 34 |
35 // MessageLoop::TaskObserver overrides. | 35 // MessageLoop::TaskObserver overrides. |
36 virtual void WillProcessTask(const base::PendingTask& pending_task) OVERRIDE { | 36 virtual void WillProcessTask(const base::PendingTask& pending_task) OVERRIDE { |
37 } | 37 } |
38 virtual void DidProcessTask(const base::PendingTask& pending_task) OVERRIDE { | 38 virtual void DidProcessTask(const base::PendingTask& pending_task) OVERRIDE { |
39 posted_ = true; | 39 posted_ = true; |
40 } | 40 } |
(...skipping 29 matching lines...) Expand all Loading... |
70 | 70 |
71 GURL GetBaseUrlForTesting(int port) { | 71 GURL GetBaseUrlForTesting(int port) { |
72 return GURL(base::StringPrintf("http://127.0.0.1:%d/", port)); | 72 return GURL(base::StringPrintf("http://127.0.0.1:%d/", port)); |
73 } | 73 } |
74 | 74 |
75 void RunBlockingPoolTask() { | 75 void RunBlockingPoolTask() { |
76 while (true) { | 76 while (true) { |
77 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | 77 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
78 | 78 |
79 TaskObserver task_observer; | 79 TaskObserver task_observer; |
80 MessageLoop::current()->AddTaskObserver(&task_observer); | 80 base::MessageLoop::current()->AddTaskObserver(&task_observer); |
81 MessageLoop::current()->RunUntilIdle(); | 81 base::MessageLoop::current()->RunUntilIdle(); |
82 MessageLoop::current()->RemoveTaskObserver(&task_observer); | 82 base::MessageLoop::current()->RemoveTaskObserver(&task_observer); |
83 if (!task_observer.posted()) | 83 if (!task_observer.posted()) |
84 break; | 84 break; |
85 } | 85 } |
86 } | 86 } |
87 | 87 |
88 void RunAndQuit(const base::Closure& closure) { | 88 void RunAndQuit(const base::Closure& closure) { |
89 closure.Run(); | 89 closure.Run(); |
90 MessageLoop::current()->Quit(); | 90 base::MessageLoop::current()->Quit(); |
91 } | 91 } |
92 | 92 |
93 scoped_ptr<base::Value> LoadJSONFile(const std::string& relative_path) { | 93 scoped_ptr<base::Value> LoadJSONFile(const std::string& relative_path) { |
94 base::FilePath path = GetTestFilePath(relative_path); | 94 base::FilePath path = GetTestFilePath(relative_path); |
95 | 95 |
96 std::string error; | 96 std::string error; |
97 JSONFileValueSerializer serializer(path); | 97 JSONFileValueSerializer serializer(path); |
98 scoped_ptr<base::Value> value(serializer.Deserialize(NULL, &error)); | 98 scoped_ptr<base::Value> value(serializer.Deserialize(NULL, &error)); |
99 LOG_IF(WARNING, !value.get()) << "Failed to parse " << path.value() | 99 LOG_IF(WARNING, !value.get()) << "Failed to parse " << path.value() |
100 << ": " << error; | 100 << ": " << error; |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 return result; | 219 return result; |
220 } | 220 } |
221 | 221 |
222 void TestGetContentCallback::OnGetContent(google_apis::GDataErrorCode error, | 222 void TestGetContentCallback::OnGetContent(google_apis::GDataErrorCode error, |
223 scoped_ptr<std::string> data) { | 223 scoped_ptr<std::string> data) { |
224 data_.push_back(data.release()); | 224 data_.push_back(data.release()); |
225 } | 225 } |
226 | 226 |
227 } // namespace test_util | 227 } // namespace test_util |
228 } // namespace google_apis | 228 } // namespace google_apis |
OLD | NEW |