OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/api_test_utils.h" | 5 #include "extensions/browser/api_test_utils.h" |
6 | 6 |
7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "components/crx_file/id_util.h" | 10 #include "components/crx_file/id_util.h" |
11 #include "content/public/browser/browser_context.h" | 11 #include "content/public/browser/browser_context.h" |
12 #include "content/public/test/test_utils.h" | 12 #include "content/public/test/test_utils.h" |
13 #include "extensions/browser/extension_function.h" | 13 #include "extensions/browser/extension_function.h" |
14 #include "extensions/browser/extension_function_dispatcher.h" | 14 #include "extensions/browser/extension_function_dispatcher.h" |
15 #include "extensions/common/extension_builder.h" | 15 #include "extensions/common/extension_builder.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
17 | 17 |
18 using extensions::ExtensionFunctionDispatcher; | 18 using extensions::ExtensionFunctionDispatcher; |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 scoped_ptr<base::Value> ParseJSON(const std::string& data) { | 22 scoped_ptr<base::Value> ParseJSON(const std::string& data) { |
23 return base::JSONReader::Read(data); | 23 return base::JSONReader::Read(data); |
24 } | 24 } |
25 | 25 |
26 scoped_ptr<base::ListValue> ParseList(const std::string& data) { | 26 scoped_ptr<base::ListValue> ParseList(const std::string& data) { |
27 scoped_ptr<base::Value> result = ParseJSON(data); | 27 return base::ListValue::From(ParseJSON(data)); |
28 scoped_ptr<base::ListValue> list_result; | |
29 if (result->GetAsList(nullptr)) | |
30 list_result.reset(static_cast<base::ListValue*>(result.release())); | |
31 return list_result; | |
32 } | 28 } |
33 | 29 |
34 // This helps us be able to wait until an UIThreadExtensionFunction calls | 30 // This helps us be able to wait until an UIThreadExtensionFunction calls |
35 // SendResponse. | 31 // SendResponse. |
36 class SendResponseDelegate | 32 class SendResponseDelegate |
37 : public UIThreadExtensionFunction::DelegateForTests { | 33 : public UIThreadExtensionFunction::DelegateForTests { |
38 public: | 34 public: |
39 SendResponseDelegate() : should_post_quit_(false) {} | 35 SendResponseDelegate() : should_post_quit_(false) {} |
40 | 36 |
41 virtual ~SendResponseDelegate() {} | 37 virtual ~SendResponseDelegate() {} |
(...skipping 26 matching lines...) Expand all Loading... |
68 bool should_post_quit_; | 64 bool should_post_quit_; |
69 }; | 65 }; |
70 | 66 |
71 } // namespace | 67 } // namespace |
72 | 68 |
73 namespace extensions { | 69 namespace extensions { |
74 | 70 |
75 namespace api_test_utils { | 71 namespace api_test_utils { |
76 | 72 |
77 scoped_ptr<base::DictionaryValue> ParseDictionary(const std::string& data) { | 73 scoped_ptr<base::DictionaryValue> ParseDictionary(const std::string& data) { |
78 scoped_ptr<base::Value> result = ParseJSON(data); | 74 return base::DictionaryValue::From(ParseJSON(data)); |
79 scoped_ptr<base::DictionaryValue> dict_result; | |
80 if (result->GetAsDictionary(nullptr)) | |
81 dict_result.reset(static_cast<base::DictionaryValue*>(result.release())); | |
82 return dict_result; | |
83 } | 75 } |
84 | 76 |
85 bool GetBoolean(const base::DictionaryValue* val, const std::string& key) { | 77 bool GetBoolean(const base::DictionaryValue* val, const std::string& key) { |
86 bool result = false; | 78 bool result = false; |
87 if (!val->GetBoolean(key, &result)) | 79 if (!val->GetBoolean(key, &result)) |
88 ADD_FAILURE() << key << " does not exist or is not a boolean."; | 80 ADD_FAILURE() << key << " does not exist or is not a boolean."; |
89 return result; | 81 return result; |
90 } | 82 } |
91 | 83 |
92 int GetInteger(const base::DictionaryValue* val, const std::string& key) { | 84 int GetInteger(const base::DictionaryValue* val, const std::string& key) { |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 response_delegate.set_should_post_quit(true); | 235 response_delegate.set_should_post_quit(true); |
244 content::RunMessageLoop(); | 236 content::RunMessageLoop(); |
245 } | 237 } |
246 | 238 |
247 EXPECT_TRUE(response_delegate.HasResponse()); | 239 EXPECT_TRUE(response_delegate.HasResponse()); |
248 return response_delegate.GetResponse(); | 240 return response_delegate.GetResponse(); |
249 } | 241 } |
250 | 242 |
251 } // namespace api_test_utils | 243 } // namespace api_test_utils |
252 } // namespace extensions | 244 } // namespace extensions |
OLD | NEW |