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/extensions/extension_function_test_utils.h" | 5 #include "chrome/browser/extensions/extension_function_test_utils.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 const std::string& args, | 123 const std::string& args, |
124 Browser* browser) { | 124 Browser* browser) { |
125 return RunFunctionAndReturnError(function, args, browser, NONE); | 125 return RunFunctionAndReturnError(function, args, browser, NONE); |
126 } | 126 } |
127 std::string RunFunctionAndReturnError(UIThreadExtensionFunction* function, | 127 std::string RunFunctionAndReturnError(UIThreadExtensionFunction* function, |
128 const std::string& args, | 128 const std::string& args, |
129 Browser* browser, | 129 Browser* browser, |
130 RunFunctionFlags flags) { | 130 RunFunctionFlags flags) { |
131 scoped_refptr<ExtensionFunction> function_owner(function); | 131 scoped_refptr<ExtensionFunction> function_owner(function); |
132 RunFunction(function, args, browser, flags); | 132 RunFunction(function, args, browser, flags); |
133 EXPECT_FALSE(function->GetResultValue()) << "Did not expect a result"; | 133 EXPECT_FALSE(function->GetResultList()) << "Did not expect a result"; |
134 return function->GetError(); | 134 return function->GetError(); |
135 } | 135 } |
136 | 136 |
137 base::Value* RunFunctionAndReturnResult(UIThreadExtensionFunction* function, | 137 base::Value* RunFunctionAndReturnSingleResult( |
138 const std::string& args, | 138 UIThreadExtensionFunction* function, |
139 Browser* browser) { | 139 const std::string& args, |
140 return RunFunctionAndReturnResult(function, args, browser, NONE); | 140 Browser* browser) { |
| 141 return RunFunctionAndReturnSingleResult(function, args, browser, NONE); |
141 } | 142 } |
142 base::Value* RunFunctionAndReturnResult(UIThreadExtensionFunction* function, | 143 base::Value* RunFunctionAndReturnSingleResult( |
143 const std::string& args, | 144 UIThreadExtensionFunction* function, |
144 Browser* browser, | 145 const std::string& args, |
145 RunFunctionFlags flags) { | 146 Browser* browser, |
| 147 RunFunctionFlags flags) { |
146 scoped_refptr<ExtensionFunction> function_owner(function); | 148 scoped_refptr<ExtensionFunction> function_owner(function); |
147 RunFunction(function, args, browser, flags); | 149 RunFunction(function, args, browser, flags); |
148 EXPECT_TRUE(function->GetError().empty()) << "Unexpected error: " | 150 EXPECT_TRUE(function->GetError().empty()) << "Unexpected error: " |
149 << function->GetError(); | 151 << function->GetError(); |
150 return (function->GetResultValue() == NULL) ? NULL : | 152 base::Value* single_result = NULL; |
151 function->GetResultValue()->DeepCopy(); | 153 if (function->GetResultList() != NULL && |
| 154 function->GetResultList()->Get(0, &single_result)) { |
| 155 return single_result->DeepCopy(); |
| 156 } |
| 157 return NULL; |
152 } | 158 } |
153 | 159 |
154 // This helps us be able to wait until an AsyncExtensionFunction calls | 160 // This helps us be able to wait until an AsyncExtensionFunction calls |
155 // SendResponse. | 161 // SendResponse. |
156 class SendResponseDelegate | 162 class SendResponseDelegate |
157 : public UIThreadExtensionFunction::DelegateForTests { | 163 : public UIThreadExtensionFunction::DelegateForTests { |
158 public: | 164 public: |
159 SendResponseDelegate() : should_post_quit_(false) {} | 165 SendResponseDelegate() : should_post_quit_(false) {} |
160 | 166 |
161 virtual ~SendResponseDelegate() {} | 167 virtual ~SendResponseDelegate() {} |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 if (!response_delegate.HasResponse()) { | 221 if (!response_delegate.HasResponse()) { |
216 response_delegate.set_should_post_quit(true); | 222 response_delegate.set_should_post_quit(true); |
217 ui_test_utils::RunMessageLoop(); | 223 ui_test_utils::RunMessageLoop(); |
218 } | 224 } |
219 | 225 |
220 EXPECT_TRUE(response_delegate.HasResponse()); | 226 EXPECT_TRUE(response_delegate.HasResponse()); |
221 return response_delegate.GetResponse(); | 227 return response_delegate.GetResponse(); |
222 } | 228 } |
223 | 229 |
224 } // namespace extension_function_test_utils | 230 } // namespace extension_function_test_utils |
OLD | NEW |