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 "content/public/browser/browser_context.h" | 10 #include "content/public/browser/browser_context.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 private: | 28 private: |
29 DISALLOW_COPY_AND_ASSIGN(TestFunctionDispatcherDelegate); | 29 DISALLOW_COPY_AND_ASSIGN(TestFunctionDispatcherDelegate); |
30 }; | 30 }; |
31 | 31 |
32 base::Value* ParseJSON(const std::string& data) { | 32 base::Value* ParseJSON(const std::string& data) { |
33 return base::JSONReader::Read(data); | 33 return base::JSONReader::Read(data); |
34 } | 34 } |
35 | 35 |
36 base::ListValue* ParseList(const std::string& data) { | 36 base::ListValue* ParseList(const std::string& data) { |
37 base::Value* result = ParseJSON(data); | 37 base::Value* result = ParseJSON(data); |
38 base::ListValue* list = NULL; | 38 base::ListValue* list = nullptr; |
39 result->GetAsList(&list); | 39 result->GetAsList(&list); |
40 return list; | 40 return list; |
41 } | 41 } |
42 | 42 |
43 // This helps us be able to wait until an UIThreadExtensionFunction calls | 43 // This helps us be able to wait until an UIThreadExtensionFunction calls |
44 // SendResponse. | 44 // SendResponse. |
45 class SendResponseDelegate | 45 class SendResponseDelegate |
46 : public UIThreadExtensionFunction::DelegateForTests { | 46 : public UIThreadExtensionFunction::DelegateForTests { |
47 public: | 47 public: |
48 SendResponseDelegate() : should_post_quit_(false) {} | 48 SendResponseDelegate() : should_post_quit_(false) {} |
49 | 49 |
50 virtual ~SendResponseDelegate() {} | 50 virtual ~SendResponseDelegate() {} |
51 | 51 |
52 void set_should_post_quit(bool should_quit) { | 52 void set_should_post_quit(bool should_quit) { |
53 should_post_quit_ = should_quit; | 53 should_post_quit_ = should_quit; |
54 } | 54 } |
55 | 55 |
56 bool HasResponse() { return response_.get() != NULL; } | 56 bool HasResponse() { return response_.get() != nullptr; } |
57 | 57 |
58 bool GetResponse() { | 58 bool GetResponse() { |
59 EXPECT_TRUE(HasResponse()); | 59 EXPECT_TRUE(HasResponse()); |
60 return *response_.get(); | 60 return *response_.get(); |
61 } | 61 } |
62 | 62 |
63 virtual void OnSendResponse(UIThreadExtensionFunction* function, | 63 virtual void OnSendResponse(UIThreadExtensionFunction* function, |
64 bool success, | 64 bool success, |
65 bool bad_message) OVERRIDE { | 65 bool bad_message) OVERRIDE { |
66 ASSERT_FALSE(bad_message); | 66 ASSERT_FALSE(bad_message); |
(...skipping 30 matching lines...) Expand all Loading... |
97 const std::string& args, | 97 const std::string& args, |
98 content::BrowserContext* context, | 98 content::BrowserContext* context, |
99 scoped_ptr<extensions::ExtensionFunctionDispatcher> dispatcher, | 99 scoped_ptr<extensions::ExtensionFunctionDispatcher> dispatcher, |
100 RunFunctionFlags flags) { | 100 RunFunctionFlags flags) { |
101 scoped_refptr<ExtensionFunction> function_owner(function); | 101 scoped_refptr<ExtensionFunction> function_owner(function); |
102 // Without a callback the function will not generate a result. | 102 // Without a callback the function will not generate a result. |
103 function->set_has_callback(true); | 103 function->set_has_callback(true); |
104 RunFunction(function, args, context, dispatcher.Pass(), flags); | 104 RunFunction(function, args, context, dispatcher.Pass(), flags); |
105 EXPECT_TRUE(function->GetError().empty()) | 105 EXPECT_TRUE(function->GetError().empty()) |
106 << "Unexpected error: " << function->GetError(); | 106 << "Unexpected error: " << function->GetError(); |
107 const base::Value* single_result = NULL; | 107 const base::Value* single_result = nullptr; |
108 if (function->GetResultList() != NULL && | 108 if (function->GetResultList() != nullptr && |
109 function->GetResultList()->Get(0, &single_result)) { | 109 function->GetResultList()->Get(0, &single_result)) { |
110 return single_result->DeepCopy(); | 110 return single_result->DeepCopy(); |
111 } | 111 } |
112 return NULL; | 112 return nullptr; |
113 } | 113 } |
114 | 114 |
115 base::Value* RunFunctionAndReturnSingleResult( | 115 base::Value* RunFunctionAndReturnSingleResult( |
116 UIThreadExtensionFunction* function, | 116 UIThreadExtensionFunction* function, |
117 const std::string& args, | 117 const std::string& args, |
118 content::BrowserContext* context) { | 118 content::BrowserContext* context) { |
119 return RunFunctionAndReturnSingleResult(function, args, context, NONE); | 119 return RunFunctionAndReturnSingleResult(function, args, context, NONE); |
120 } | 120 } |
121 | 121 |
122 base::Value* RunFunctionAndReturnSingleResult( | 122 base::Value* RunFunctionAndReturnSingleResult( |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 response_delegate.set_should_post_quit(true); | 196 response_delegate.set_should_post_quit(true); |
197 content::RunMessageLoop(); | 197 content::RunMessageLoop(); |
198 } | 198 } |
199 | 199 |
200 EXPECT_TRUE(response_delegate.HasResponse()); | 200 EXPECT_TRUE(response_delegate.HasResponse()); |
201 return response_delegate.GetResponse(); | 201 return response_delegate.GetResponse(); |
202 } | 202 } |
203 | 203 |
204 } // namespace api_test_utils | 204 } // namespace api_test_utils |
205 } // namespace extensions | 205 } // namespace extensions |
OLD | NEW |