| 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_GOOGLE_APIS_TEST_UTIL_H_ | 5 #ifndef CHROME_BROWSER_GOOGLE_APIS_TEST_UTIL_H_ |
| 6 #define CHROME_BROWSER_GOOGLE_APIS_TEST_UTIL_H_ | 6 #define CHROME_BROWSER_GOOGLE_APIS_TEST_UTIL_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "chrome/browser/google_apis/gdata_errorcode.h" | 11 #include "chrome/browser/google_apis/gdata_errorcode.h" |
| 12 #include "googleurl/src/gurl.h" | 12 #include "googleurl/src/gurl.h" |
| 13 | 13 |
| 14 class FilePath; | 14 class FilePath; |
| 15 | 15 |
| 16 namespace base { | 16 namespace base { |
| 17 class Value; | 17 class Value; |
| 18 } | 18 } |
| 19 | 19 |
| 20 namespace google_apis { | 20 namespace google_apis { |
| 21 | 21 |
| 22 class AppList; | 22 class AppList; |
| 23 class AccountMetadataFeed; | 23 class AccountMetadataFeed; |
| 24 class AuthenticatedOperationInterface; | 24 class AuthenticatedOperationInterface; |
| 25 class ResourceEntry; | 25 class ResourceEntry; |
| 26 class ResourceList; | 26 class ResourceList; |
| 27 | 27 |
| 28 namespace test_server { | 28 namespace test_server { |
| 29 struct HttpRequest; |
| 29 class HttpResponse; | 30 class HttpResponse; |
| 30 } | 31 } |
| 31 | 32 |
| 32 namespace test_util { | 33 namespace test_util { |
| 33 | 34 |
| 34 // Runs a task posted to the blocking pool, including subsequent tasks posted | 35 // Runs a task posted to the blocking pool, including subsequent tasks posted |
| 35 // to the UI message loop and the blocking pool. | 36 // to the UI message loop and the blocking pool. |
| 36 // | 37 // |
| 37 // A task is often posted to the blocking pool with PostTaskAndReply(). In | 38 // A task is often posted to the blocking pool with PostTaskAndReply(). In |
| 38 // that case, a task is posted back to the UI message loop, which can again | 39 // that case, a task is posted back to the UI message loop, which can again |
| 39 // post a task to the blocking pool. This function processes these tasks | 40 // post a task to the blocking pool. This function processes these tasks |
| 40 // repeatedly. | 41 // repeatedly. |
| 41 void RunBlockingPoolTask(); | 42 void RunBlockingPoolTask(); |
| 42 | 43 |
| 44 // Removes |prefix| from |input| and stores the result in |output|. Returns |
| 45 // true if the prefix is removed. |
| 46 bool RemovePrefix(const std::string& input, |
| 47 const std::string& prefix, |
| 48 std::string* output); |
| 49 |
| 43 // Returns the absolute path for a test file stored under | 50 // Returns the absolute path for a test file stored under |
| 44 // chrome/test/data/chromeos. | 51 // chrome/test/data/chromeos. |
| 45 FilePath GetTestFilePath(const std::string& relative_path); | 52 FilePath GetTestFilePath(const std::string& relative_path); |
| 46 | 53 |
| 47 // Returns the base URL for communicating with the local test server for | 54 // Returns the base URL for communicating with the local test server for |
| 48 // testing, running at the specified port number. | 55 // testing, running at the specified port number. |
| 49 GURL GetBaseUrlForTesting(int port); | 56 GURL GetBaseUrlForTesting(int port); |
| 50 | 57 |
| 51 // Loads a test JSON file as a base::Value, from a test file stored under | 58 // Loads a test JSON file as a base::Value, from a test file stored under |
| 52 // chrome/test/data/chromeos. | 59 // chrome/test/data/chromeos. |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 // Returns a HttpResponse created from the given file path. | 117 // Returns a HttpResponse created from the given file path. |
| 111 scoped_ptr<test_server::HttpResponse> CreateHttpResponseFromFile( | 118 scoped_ptr<test_server::HttpResponse> CreateHttpResponseFromFile( |
| 112 const FilePath& file_path); | 119 const FilePath& file_path); |
| 113 | 120 |
| 114 // Does nothing for ReAuthenticateCallback(). This function should be used | 121 // Does nothing for ReAuthenticateCallback(). This function should be used |
| 115 // if it is not expected to reach this method as there won't be any | 122 // if it is not expected to reach this method as there won't be any |
| 116 // authentication failures in the test. | 123 // authentication failures in the test. |
| 117 void DoNothingForReAuthenticateCallback( | 124 void DoNothingForReAuthenticateCallback( |
| 118 AuthenticatedOperationInterface* operation); | 125 AuthenticatedOperationInterface* operation); |
| 119 | 126 |
| 127 // Handles a request for downloading a file. Reads a file from the test |
| 128 // directory and returns the content. Also, copies the |request| to the memory |
| 129 // pointed by |out_request|. |
| 130 // |base_url| must be set to the server's base url. |
| 131 scoped_ptr<test_server::HttpResponse> HandleDownloadRequest( |
| 132 const GURL& base_url, |
| 133 test_server::HttpRequest* out_request, |
| 134 const test_server::HttpRequest& request); |
| 135 |
| 120 // Returns true if |json_data| is not NULL and equals to the content in | 136 // Returns true if |json_data| is not NULL and equals to the content in |
| 121 // |expected_json_file_path|. The failure reason will be logged into LOG(ERROR) | 137 // |expected_json_file_path|. The failure reason will be logged into LOG(ERROR) |
| 122 // if necessary. | 138 // if necessary. |
| 123 bool VerifyJsonData(const FilePath& expected_json_file_path, | 139 bool VerifyJsonData(const FilePath& expected_json_file_path, |
| 124 const base::Value* json_data); | 140 const base::Value* json_data); |
| 125 | 141 |
| 126 } // namespace test_util | 142 } // namespace test_util |
| 127 } // namespace google_apis | 143 } // namespace google_apis |
| 128 | 144 |
| 129 #endif // CHROME_BROWSER_GOOGLE_APIS_TEST_UTIL_H_ | 145 #endif // CHROME_BROWSER_GOOGLE_APIS_TEST_UTIL_H_ |
| OLD | NEW |