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 #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 <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/prefs/testing_pref_service.h" | 12 #include "base/prefs/testing_pref_service.h" |
| 13 #include "extensions/browser/extensions_test.h" | 13 #include "extensions/browser/extensions_test.h" |
| 14 #include "extensions/browser/mock_extension_system.h" | 14 #include "extensions/browser/mock_extension_system.h" |
| 15 | 15 |
| 16 namespace base { | 16 namespace base { |
| 17 class Value; | 17 class Value; |
| 18 class DictionaryValue; | 18 class DictionaryValue; |
| 19 class ListValue; | 19 class ListValue; |
| 20 } | 20 } |
| 21 | 21 |
| 22 namespace content { | 22 namespace content { |
| 23 class NotificationService; | 23 class NotificationService; |
| 24 class TestBrowserThreadBundle; | 24 class TestBrowserThreadBundle; |
| 25 class WebContents; | |
| 25 } | 26 } |
| 26 | 27 |
| 27 class UIThreadExtensionFunction; | 28 class UIThreadExtensionFunction; |
| 28 | 29 |
| 29 namespace extensions { | 30 namespace extensions { |
| 30 | 31 |
| 31 // Use this class to enable calling API functions in a unittest. | 32 // Use this class to enable calling API functions in a unittest. |
| 32 // By default, this class will create and load an empty unpacked |extension_|, | 33 // By default, this class will create and load an empty unpacked |extension_|, |
| 33 // which will be used in all API function calls. This extension can be | 34 // which will be used in all API function calls. This extension can be |
| 34 // overridden using set_extension(). | 35 // overridden using set_extension(). |
| 35 // When calling RunFunction[AndReturn*], |args| should be in JSON format, | 36 // When calling RunFunction[AndReturn*], |args| should be in JSON format, |
| 36 // wrapped in a list. See also RunFunction* in api_test_utils.h. | 37 // wrapped in a list. See also RunFunction* in api_test_utils.h. |
| 37 class ApiUnitTest : public ExtensionsTest { | 38 class ApiUnitTest : public ExtensionsTest { |
| 38 public: | 39 public: |
| 39 ApiUnitTest(); | 40 ApiUnitTest(); |
| 40 ~ApiUnitTest() override; | 41 ~ApiUnitTest() override; |
| 41 | 42 |
| 43 content::WebContents* contents() { return contents_.get(); } | |
| 42 const Extension* extension() const { return extension_.get(); } | 44 const Extension* extension() const { return extension_.get(); } |
| 43 scoped_refptr<Extension> extension_ref() { return extension_; } | 45 scoped_refptr<Extension> extension_ref() { return extension_; } |
| 44 void set_extension(scoped_refptr<Extension> extension) { | 46 void set_extension(scoped_refptr<Extension> extension) { |
| 45 extension_ = extension; | 47 extension_ = extension; |
| 46 } | 48 } |
| 47 | 49 |
| 48 protected: | 50 protected: |
| 49 // SetUp creates and loads an empty, unpacked Extension. | 51 // SetUp creates and loads an empty, unpacked Extension. |
| 50 void SetUp() override; | 52 void SetUp() override; |
| 51 | 53 |
| 54 // Creates WebContents for |extension_| that can be used in API calls. | |
| 55 // If |contents_| is already set, this does nothing. | |
| 56 void CreateWebContents(); | |
|
James Cook
2015/01/17 00:51:29
Is there any particular reason not to call this Cr
babu
2015/01/17 11:53:56
Done.
Changed to the original name and removed t
| |
| 57 | |
| 52 // Various ways of running an API function. These methods take ownership of | 58 // Various ways of running an API function. These methods take ownership of |
| 53 // |function|. |args| should be in JSON format, wrapped in a list. | 59 // |function|. |args| should be in JSON format, wrapped in a list. |
| 54 // See also the RunFunction* methods in extension_function_test_utils.h. | 60 // See also the RunFunction* methods in extension_function_test_utils.h. |
| 55 | 61 |
| 56 // Return the function result as a base::Value. | 62 // Return the function result as a base::Value. |
| 57 scoped_ptr<base::Value> RunFunctionAndReturnValue( | 63 scoped_ptr<base::Value> RunFunctionAndReturnValue( |
| 58 UIThreadExtensionFunction* function, | 64 UIThreadExtensionFunction* function, |
| 59 const std::string& args); | 65 const std::string& args); |
| 60 | 66 |
| 61 // Return the function result as a base::DictionaryValue, or NULL. | 67 // Return the function result as a base::DictionaryValue, or NULL. |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 80 const std::string& args); | 86 const std::string& args); |
| 81 | 87 |
| 82 private: | 88 private: |
| 83 scoped_ptr<content::NotificationService> notification_service_; | 89 scoped_ptr<content::NotificationService> notification_service_; |
| 84 | 90 |
| 85 scoped_ptr<content::TestBrowserThreadBundle> thread_bundle_; | 91 scoped_ptr<content::TestBrowserThreadBundle> thread_bundle_; |
| 86 TestingPrefServiceSimple testing_pref_service_; | 92 TestingPrefServiceSimple testing_pref_service_; |
| 87 | 93 |
| 88 MockExtensionSystemFactory<MockExtensionSystem> extension_system_factory_; | 94 MockExtensionSystemFactory<MockExtensionSystem> extension_system_factory_; |
| 89 | 95 |
| 96 // The WebContents used to associate a RenderViewHost with API function calls, | |
| 97 // or NULL. | |
|
James Cook
2015/01/17 00:51:29
nit: "null" in comments, since we don't use the NU
babu
2015/01/17 11:53:56
Done.
| |
| 98 scoped_ptr<content::WebContents> contents_; | |
| 99 | |
| 90 // The Extension used when running API function calls. | 100 // The Extension used when running API function calls. |
| 91 scoped_refptr<Extension> extension_; | 101 scoped_refptr<Extension> extension_; |
| 92 }; | 102 }; |
| 93 | 103 |
| 94 } // namespace extensions | 104 } // namespace extensions |
| 95 | 105 |
| 96 #endif // EXTENSIONS_BROWSER_API_UNITTEST_H_ | 106 #endif // EXTENSIONS_BROWSER_API_UNITTEST_H_ |
| OLD | NEW |