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_unittest.h" | 5 #include "extensions/browser/api_unittest.h" |
6 | 6 |
7 #include "base/values.h" | 7 #include "base/values.h" |
8 #include "components/user_prefs/user_prefs.h" | 8 #include "components/user_prefs/user_prefs.h" |
9 #include "content/public/browser/browser_context.h" | 9 #include "content/public/browser/browser_context.h" |
10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 const std::string& args) { | 58 const std::string& args) { |
59 function->set_extension(extension()); | 59 function->set_extension(extension()); |
60 return scoped_ptr<base::Value>(utils::RunFunctionAndReturnSingleResult( | 60 return scoped_ptr<base::Value>(utils::RunFunctionAndReturnSingleResult( |
61 function, args, browser_context())); | 61 function, args, browser_context())); |
62 } | 62 } |
63 | 63 |
64 scoped_ptr<base::DictionaryValue> ApiUnitTest::RunFunctionAndReturnDictionary( | 64 scoped_ptr<base::DictionaryValue> ApiUnitTest::RunFunctionAndReturnDictionary( |
65 UIThreadExtensionFunction* function, | 65 UIThreadExtensionFunction* function, |
66 const std::string& args) { | 66 const std::string& args) { |
67 base::Value* value = RunFunctionAndReturnValue(function, args).release(); | 67 base::Value* value = RunFunctionAndReturnValue(function, args).release(); |
68 base::DictionaryValue* dict = NULL; | 68 base::DictionaryValue* dict = nullptr; |
69 | 69 |
70 if (value && !value->GetAsDictionary(&dict)) | 70 if (value && !value->GetAsDictionary(&dict)) |
71 delete value; | 71 delete value; |
72 | 72 |
73 // We expect to either have successfuly retrieved a dictionary from the value, | 73 // We expect to either have successfuly retrieved a dictionary from the value, |
74 // or the value to have been NULL. | 74 // or the value to have been NULL. |
75 EXPECT_TRUE(dict || !value); | 75 EXPECT_TRUE(dict || !value); |
76 return scoped_ptr<base::DictionaryValue>(dict); | 76 return scoped_ptr<base::DictionaryValue>(dict); |
77 } | 77 } |
78 | 78 |
79 scoped_ptr<base::ListValue> ApiUnitTest::RunFunctionAndReturnList( | 79 scoped_ptr<base::ListValue> ApiUnitTest::RunFunctionAndReturnList( |
80 UIThreadExtensionFunction* function, | 80 UIThreadExtensionFunction* function, |
81 const std::string& args) { | 81 const std::string& args) { |
82 base::Value* value = RunFunctionAndReturnValue(function, args).release(); | 82 base::Value* value = RunFunctionAndReturnValue(function, args).release(); |
83 base::ListValue* list = NULL; | 83 base::ListValue* list = nullptr; |
84 | 84 |
85 if (value && !value->GetAsList(&list)) | 85 if (value && !value->GetAsList(&list)) |
86 delete value; | 86 delete value; |
87 | 87 |
88 // We expect to either have successfuly retrieved a list from the value, | 88 // We expect to either have successfuly retrieved a list from the value, |
89 // or the value to have been NULL. | 89 // or the value to have been NULL. |
90 EXPECT_TRUE(list || !value); | 90 EXPECT_TRUE(list || !value); |
91 return scoped_ptr<base::ListValue>(list); | 91 return scoped_ptr<base::ListValue>(list); |
92 } | 92 } |
93 | 93 |
94 std::string ApiUnitTest::RunFunctionAndReturnError( | 94 std::string ApiUnitTest::RunFunctionAndReturnError( |
95 UIThreadExtensionFunction* function, | 95 UIThreadExtensionFunction* function, |
96 const std::string& args) { | 96 const std::string& args) { |
97 function->set_extension(extension()); | 97 function->set_extension(extension()); |
98 return utils::RunFunctionAndReturnError(function, args, browser_context()); | 98 return utils::RunFunctionAndReturnError(function, args, browser_context()); |
99 } | 99 } |
100 | 100 |
101 void ApiUnitTest::RunFunction(UIThreadExtensionFunction* function, | 101 void ApiUnitTest::RunFunction(UIThreadExtensionFunction* function, |
102 const std::string& args) { | 102 const std::string& args) { |
103 RunFunctionAndReturnValue(function, args); | 103 RunFunctionAndReturnValue(function, args); |
104 } | 104 } |
105 | 105 |
106 } // namespace extensions | 106 } // namespace extensions |
OLD | NEW |