OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
132 } | 132 } |
133 base::Value* RunFunctionAndReturnResult(UIThreadExtensionFunction* function, | 133 base::Value* RunFunctionAndReturnResult(UIThreadExtensionFunction* function, |
134 const std::string& args, | 134 const std::string& args, |
135 Browser* browser, | 135 Browser* browser, |
136 RunFunctionFlags flags) { | 136 RunFunctionFlags flags) { |
137 scoped_refptr<ExtensionFunction> function_owner(function); | 137 scoped_refptr<ExtensionFunction> function_owner(function); |
138 RunFunction(function, args, browser, flags); | 138 RunFunction(function, args, browser, flags); |
139 EXPECT_TRUE(function->GetError().empty()) << "Unexpected error: " | 139 EXPECT_TRUE(function->GetError().empty()) << "Unexpected error: " |
140 << function->GetError(); | 140 << function->GetError(); |
141 EXPECT_TRUE(function->GetResultValue()) << "No result value found"; | 141 EXPECT_TRUE(function->GetResultValue()) << "No result value found"; |
142 return function->GetResultValue()->DeepCopy(); | 142 return function->GetResultValue()->DeepCopy(); |
Aaron Boodman
2011/12/14 22:23:46
Was the only reason RunFunctionWithoutResult neede
Mike West
2011/12/14 22:41:59
Yes, that's what I originally did. Having a separa
Aaron Boodman
2011/12/14 22:44:35
You can just do that assertion at the call site.
Mike West
2011/12/14 22:59:03
Done.
| |
143 } | 143 } |
144 | 144 |
145 bool RunFunctionWithoutResult(UIThreadExtensionFunction* function, | |
146 const std::string& args, | |
147 Browser* browser) { | |
148 return RunFunctionWithoutResult(function, args, browser, NONE); | |
149 } | |
150 bool RunFunctionWithoutResult(UIThreadExtensionFunction* function, | |
151 const std::string& args, | |
152 Browser* browser, | |
153 RunFunctionFlags flags) { | |
154 scoped_refptr<ExtensionFunction> function_owner(function); | |
155 bool success = RunFunction(function, args, browser, flags); | |
156 EXPECT_TRUE(function->GetError().empty()) << "Unexpected error: " | |
157 << function->GetError(); | |
158 EXPECT_FALSE(function->GetResultValue()) << "Unexpected result value: " | |
159 << function->GetResult(); | |
160 return success; | |
161 } | |
162 | |
145 // This helps us be able to wait until an AsyncExtensionFunction calls | 163 // This helps us be able to wait until an AsyncExtensionFunction calls |
146 // SendResponse. | 164 // SendResponse. |
147 class SendResponseDelegate | 165 class SendResponseDelegate |
148 : public UIThreadExtensionFunction::DelegateForTests { | 166 : public UIThreadExtensionFunction::DelegateForTests { |
149 public: | 167 public: |
150 SendResponseDelegate() : should_post_quit_(false) {} | 168 SendResponseDelegate() : should_post_quit_(false) {} |
151 | 169 |
152 virtual ~SendResponseDelegate() {} | 170 virtual ~SendResponseDelegate() {} |
153 | 171 |
154 void set_should_post_quit(bool should_quit) { | 172 void set_should_post_quit(bool should_quit) { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
204 if (!response_delegate.HasResponse()) { | 222 if (!response_delegate.HasResponse()) { |
205 response_delegate.set_should_post_quit(true); | 223 response_delegate.set_should_post_quit(true); |
206 ui_test_utils::RunMessageLoop(); | 224 ui_test_utils::RunMessageLoop(); |
207 } | 225 } |
208 | 226 |
209 EXPECT_TRUE(response_delegate.HasResponse()); | 227 EXPECT_TRUE(response_delegate.HasResponse()); |
210 return response_delegate.GetResponse(); | 228 return response_delegate.GetResponse(); |
211 } | 229 } |
212 | 230 |
213 } // namespace extension_function_test_utils | 231 } // namespace extension_function_test_utils |
OLD | NEW |