Chromium Code Reviews| 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 "content/public/browser/browser_context.h" | 11 #include "content/public/browser/browser_context.h" |
| 11 #include "content/public/test/test_utils.h" | 12 #include "content/public/test/test_utils.h" |
| 12 #include "extensions/browser/extension_function.h" | 13 #include "extensions/browser/extension_function.h" |
| 13 #include "extensions/browser/extension_function_dispatcher.h" | 14 #include "extensions/browser/extension_function_dispatcher.h" |
| 14 #include "extensions/common/extension_builder.h" | 15 #include "extensions/common/extension_builder.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 17 |
| 17 using extensions::ExtensionFunctionDispatcher; | 18 using extensions::ExtensionFunctionDispatcher; |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 70 if (should_post_quit_) { | 71 if (should_post_quit_) { |
| 71 base::MessageLoopForUI::current()->Quit(); | 72 base::MessageLoopForUI::current()->Quit(); |
| 72 } | 73 } |
| 73 } | 74 } |
| 74 | 75 |
| 75 private: | 76 private: |
| 76 scoped_ptr<bool> response_; | 77 scoped_ptr<bool> response_; |
| 77 bool should_post_quit_; | 78 bool should_post_quit_; |
| 78 }; | 79 }; |
| 79 | 80 |
| 81 scoped_refptr<extensions::Extension> CreateExtension( | |
|
James Cook
2014/12/19 18:07:03
Can you move this out of the anonymous namespace a
tmpsantos
2014/12/23 02:09:38
Acknowledged.
| |
| 82 extensions::Manifest::Location location, | |
| 83 base::DictionaryValue* test_extension_value, | |
| 84 const std::string& id_input) { | |
| 85 std::string error; | |
| 86 const base::FilePath test_extension_path; | |
| 87 std::string id; | |
| 88 if (!id_input.empty()) | |
| 89 id = crx_file::id_util::GenerateId(id_input); | |
| 90 scoped_refptr<extensions::Extension> extension(extensions::Extension::Create( | |
| 91 test_extension_path, location, *test_extension_value, | |
| 92 extensions::Extension::NO_FLAGS, id, &error)); | |
| 93 EXPECT_TRUE(error.empty()) << "Could not parse test extension " << error; | |
| 94 return extension; | |
| 95 } | |
| 96 | |
| 80 } // namespace | 97 } // namespace |
| 81 | 98 |
| 82 namespace extensions { | 99 namespace extensions { |
| 83 | 100 |
| 84 namespace api_test_utils { | 101 namespace api_test_utils { |
| 85 | 102 |
| 103 base::DictionaryValue* ParseDictionary(const std::string& data) { | |
|
James Cook
2014/12/19 18:07:03
Likewise, can the extension_function_utils.cc vers
tmpsantos
2014/12/23 02:09:38
Acknowledged.
| |
| 104 base::Value* result = ParseJSON(data); | |
| 105 base::DictionaryValue* dict = NULL; | |
| 106 result->GetAsDictionary(&dict); | |
| 107 return dict; | |
| 108 } | |
| 109 | |
| 110 bool GetBoolean(const base::DictionaryValue* val, const std::string& key) { | |
| 111 bool result = false; | |
| 112 if (!val->GetBoolean(key, &result)) | |
| 113 ADD_FAILURE() << key << " does not exist or is not a boolean."; | |
| 114 return result; | |
| 115 } | |
| 116 | |
| 117 int GetInteger(const base::DictionaryValue* val, const std::string& key) { | |
| 118 int result = 0; | |
| 119 if (!val->GetInteger(key, &result)) | |
| 120 ADD_FAILURE() << key << " does not exist or is not an integer."; | |
| 121 return result; | |
| 122 } | |
| 123 | |
| 124 std::string GetString(const base::DictionaryValue* val, | |
| 125 const std::string& key) { | |
| 126 std::string result; | |
| 127 if (!val->GetString(key, &result)) | |
| 128 ADD_FAILURE() << key << " does not exist or is not a string."; | |
| 129 return result; | |
| 130 } | |
| 131 | |
| 132 scoped_refptr<Extension> CreateExtension( | |
| 133 base::DictionaryValue* test_extension_value) { | |
| 134 return ::CreateExtension(Manifest::INTERNAL, test_extension_value, | |
| 135 std::string()); | |
| 136 } | |
| 137 | |
| 86 base::Value* RunFunctionWithDelegateAndReturnSingleResult( | 138 base::Value* RunFunctionWithDelegateAndReturnSingleResult( |
| 87 UIThreadExtensionFunction* function, | 139 UIThreadExtensionFunction* function, |
| 88 const std::string& args, | 140 const std::string& args, |
| 89 content::BrowserContext* context, | 141 content::BrowserContext* context, |
| 90 scoped_ptr<extensions::ExtensionFunctionDispatcher> dispatcher) { | 142 scoped_ptr<extensions::ExtensionFunctionDispatcher> dispatcher) { |
| 91 return RunFunctionWithDelegateAndReturnSingleResult( | 143 return RunFunctionWithDelegateAndReturnSingleResult( |
| 92 function, args, context, dispatcher.Pass(), NONE); | 144 function, args, context, dispatcher.Pass(), NONE); |
| 93 } | 145 } |
| 94 | 146 |
| 95 base::Value* RunFunctionWithDelegateAndReturnSingleResult( | 147 base::Value* RunFunctionWithDelegateAndReturnSingleResult( |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 196 response_delegate.set_should_post_quit(true); | 248 response_delegate.set_should_post_quit(true); |
| 197 content::RunMessageLoop(); | 249 content::RunMessageLoop(); |
| 198 } | 250 } |
| 199 | 251 |
| 200 EXPECT_TRUE(response_delegate.HasResponse()); | 252 EXPECT_TRUE(response_delegate.HasResponse()); |
| 201 return response_delegate.GetResponse(); | 253 return response_delegate.GetResponse(); |
| 202 } | 254 } |
| 203 | 255 |
| 204 } // namespace api_test_utils | 256 } // namespace api_test_utils |
| 205 } // namespace extensions | 257 } // namespace extensions |
| OLD | NEW |