| 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 #ifndef EXTENSIONS_BROWSER_API_UNITTEST_H_ | 5 #ifndef EXTENSIONS_BROWSER_API_UNITTEST_H_ |
| 6 #define EXTENSIONS_BROWSER_API_UNITTEST_H_ | 6 #define EXTENSIONS_BROWSER_API_UNITTEST_H_ |
| 7 | 7 |
| 8 #include <memory> |
| 8 #include <string> | 9 #include <string> |
| 9 | 10 |
| 10 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "components/pref_registry/testing_pref_service_syncable.h" | 12 #include "components/pref_registry/testing_pref_service_syncable.h" |
| 13 #include "extensions/browser/extensions_test.h" | 13 #include "extensions/browser/extensions_test.h" |
| 14 | 14 |
| 15 namespace base { | 15 namespace base { |
| 16 class Value; | 16 class Value; |
| 17 class DictionaryValue; | 17 class DictionaryValue; |
| 18 class ListValue; | 18 class ListValue; |
| 19 } | 19 } |
| 20 | 20 |
| 21 namespace content { | 21 namespace content { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 // Creates a background page for |extension_|, and sets it for the WebContents | 54 // Creates a background page for |extension_|, and sets it for the WebContents |
| 55 // to be used in API calls. | 55 // to be used in API calls. |
| 56 // If |contents_| is already set, this does nothing. | 56 // If |contents_| is already set, this does nothing. |
| 57 void CreateBackgroundPage(); | 57 void CreateBackgroundPage(); |
| 58 | 58 |
| 59 // Various ways of running an API function. These methods take ownership of | 59 // Various ways of running an API function. These methods take ownership of |
| 60 // |function|. |args| should be in JSON format, wrapped in a list. | 60 // |function|. |args| should be in JSON format, wrapped in a list. |
| 61 // See also the RunFunction* methods in extension_function_test_utils.h. | 61 // See also the RunFunction* methods in extension_function_test_utils.h. |
| 62 | 62 |
| 63 // Return the function result as a base::Value. | 63 // Return the function result as a base::Value. |
| 64 scoped_ptr<base::Value> RunFunctionAndReturnValue( | 64 std::unique_ptr<base::Value> RunFunctionAndReturnValue( |
| 65 UIThreadExtensionFunction* function, | 65 UIThreadExtensionFunction* function, |
| 66 const std::string& args); | 66 const std::string& args); |
| 67 | 67 |
| 68 // Return the function result as a base::DictionaryValue, or NULL. | 68 // Return the function result as a base::DictionaryValue, or NULL. |
| 69 // This will EXPECT-fail if the result is not a DictionaryValue. | 69 // This will EXPECT-fail if the result is not a DictionaryValue. |
| 70 scoped_ptr<base::DictionaryValue> RunFunctionAndReturnDictionary( | 70 std::unique_ptr<base::DictionaryValue> RunFunctionAndReturnDictionary( |
| 71 UIThreadExtensionFunction* function, | 71 UIThreadExtensionFunction* function, |
| 72 const std::string& args); | 72 const std::string& args); |
| 73 | 73 |
| 74 // Return the function result as a base::ListValue, or NULL. | 74 // Return the function result as a base::ListValue, or NULL. |
| 75 // This will EXPECT-fail if the result is not a ListValue. | 75 // This will EXPECT-fail if the result is not a ListValue. |
| 76 scoped_ptr<base::ListValue> RunFunctionAndReturnList( | 76 std::unique_ptr<base::ListValue> RunFunctionAndReturnList( |
| 77 UIThreadExtensionFunction* function, | 77 UIThreadExtensionFunction* function, |
| 78 const std::string& args); | 78 const std::string& args); |
| 79 | 79 |
| 80 // Return an error thrown from the function, if one exists. | 80 // Return an error thrown from the function, if one exists. |
| 81 // This will EXPECT-fail if any result is returned from the function. | 81 // This will EXPECT-fail if any result is returned from the function. |
| 82 std::string RunFunctionAndReturnError(UIThreadExtensionFunction* function, | 82 std::string RunFunctionAndReturnError(UIThreadExtensionFunction* function, |
| 83 const std::string& args); | 83 const std::string& args); |
| 84 | 84 |
| 85 // Run the function and ignore any result. | 85 // Run the function and ignore any result. |
| 86 void RunFunction(UIThreadExtensionFunction* function, | 86 void RunFunction(UIThreadExtensionFunction* function, |
| 87 const std::string& args); | 87 const std::string& args); |
| 88 | 88 |
| 89 private: | 89 private: |
| 90 scoped_ptr<content::NotificationService> notification_service_; | 90 std::unique_ptr<content::NotificationService> notification_service_; |
| 91 | 91 |
| 92 scoped_ptr<content::TestBrowserThreadBundle> thread_bundle_; | 92 std::unique_ptr<content::TestBrowserThreadBundle> thread_bundle_; |
| 93 user_prefs::TestingPrefServiceSyncable testing_pref_service_; | 93 user_prefs::TestingPrefServiceSyncable testing_pref_service_; |
| 94 | 94 |
| 95 // The WebContents used to associate a RenderViewHost with API function calls, | 95 // The WebContents used to associate a RenderViewHost with API function calls, |
| 96 // or null. | 96 // or null. |
| 97 scoped_ptr<content::WebContents> contents_; | 97 std::unique_ptr<content::WebContents> contents_; |
| 98 | 98 |
| 99 // The Extension used when running API function calls. | 99 // The Extension used when running API function calls. |
| 100 scoped_refptr<Extension> extension_; | 100 scoped_refptr<Extension> extension_; |
| 101 }; | 101 }; |
| 102 | 102 |
| 103 } // namespace extensions | 103 } // namespace extensions |
| 104 | 104 |
| 105 #endif // EXTENSIONS_BROWSER_API_UNITTEST_H_ | 105 #endif // EXTENSIONS_BROWSER_API_UNITTEST_H_ |
| OLD | NEW |