| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_TEST_API_H_ | |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_TEST_API_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include "base/values.h" | |
| 10 #include "chrome/browser/extensions/extension_function.h" | |
| 11 | |
| 12 template <typename T> struct DefaultSingletonTraits; | |
| 13 | |
| 14 // A function that is only available in tests. | |
| 15 // Prior to running, checks that we are in an extension process. | |
| 16 class TestExtensionFunction : public SyncExtensionFunction { | |
| 17 protected: | |
| 18 virtual ~TestExtensionFunction(); | |
| 19 | |
| 20 // ExtensionFunction: | |
| 21 virtual void Run() OVERRIDE; | |
| 22 }; | |
| 23 | |
| 24 class ExtensionTestPassFunction : public TestExtensionFunction { | |
| 25 public: | |
| 26 DECLARE_EXTENSION_FUNCTION_NAME("test.notifyPass") | |
| 27 | |
| 28 protected: | |
| 29 virtual ~ExtensionTestPassFunction(); | |
| 30 | |
| 31 // ExtensionFunction: | |
| 32 virtual bool RunImpl() OVERRIDE; | |
| 33 }; | |
| 34 | |
| 35 class ExtensionTestFailFunction : public TestExtensionFunction { | |
| 36 public: | |
| 37 DECLARE_EXTENSION_FUNCTION_NAME("test.notifyFail") | |
| 38 | |
| 39 protected: | |
| 40 virtual ~ExtensionTestFailFunction(); | |
| 41 | |
| 42 // ExtensionFunction: | |
| 43 virtual bool RunImpl() OVERRIDE; | |
| 44 }; | |
| 45 | |
| 46 class ExtensionTestLogFunction : public TestExtensionFunction { | |
| 47 public: | |
| 48 DECLARE_EXTENSION_FUNCTION_NAME("test.log") | |
| 49 | |
| 50 protected: | |
| 51 virtual ~ExtensionTestLogFunction(); | |
| 52 | |
| 53 // ExtensionFunction: | |
| 54 virtual bool RunImpl() OVERRIDE; | |
| 55 }; | |
| 56 | |
| 57 class ExtensionTestQuotaResetFunction : public TestExtensionFunction { | |
| 58 public: | |
| 59 DECLARE_EXTENSION_FUNCTION_NAME("test.resetQuota") | |
| 60 | |
| 61 protected: | |
| 62 virtual ~ExtensionTestQuotaResetFunction(); | |
| 63 | |
| 64 // ExtensionFunction: | |
| 65 virtual bool RunImpl() OVERRIDE; | |
| 66 }; | |
| 67 | |
| 68 class ExtensionTestCreateIncognitoTabFunction : public TestExtensionFunction { | |
| 69 public: | |
| 70 DECLARE_EXTENSION_FUNCTION_NAME("test.createIncognitoTab") | |
| 71 | |
| 72 protected: | |
| 73 virtual ~ExtensionTestCreateIncognitoTabFunction(); | |
| 74 | |
| 75 // ExtensionFunction: | |
| 76 virtual bool RunImpl() OVERRIDE; | |
| 77 }; | |
| 78 | |
| 79 class ExtensionTestSendMessageFunction : public AsyncExtensionFunction { | |
| 80 public: | |
| 81 DECLARE_EXTENSION_FUNCTION_NAME("test.sendMessage") | |
| 82 | |
| 83 // Sends a reply back to the calling extension. Many extensions don't need | |
| 84 // a reply and will just ignore it. | |
| 85 void Reply(const std::string& message); | |
| 86 | |
| 87 protected: | |
| 88 virtual ~ExtensionTestSendMessageFunction(); | |
| 89 | |
| 90 // ExtensionFunction: | |
| 91 virtual bool RunImpl() OVERRIDE; | |
| 92 }; | |
| 93 | |
| 94 class ExtensionTestGetConfigFunction : public SyncExtensionFunction { | |
| 95 public: | |
| 96 DECLARE_EXTENSION_FUNCTION_NAME("test.getConfig") | |
| 97 | |
| 98 // Set the dictionary returned by chrome.test.getConfig(). | |
| 99 // Does not take ownership of |value|. | |
| 100 static void set_test_config_state(DictionaryValue* value); | |
| 101 | |
| 102 protected: | |
| 103 // Tests that set configuration state do so by calling | |
| 104 // set_test_config_state() as part of test set up, and unsetting it | |
| 105 // during tear down. This singleton class holds a pointer to that | |
| 106 // state, owned by the test code. | |
| 107 class TestConfigState { | |
| 108 public: | |
| 109 static TestConfigState* GetInstance(); | |
| 110 | |
| 111 void set_config_state(DictionaryValue* config_state) { | |
| 112 config_state_ = config_state; | |
| 113 } | |
| 114 | |
| 115 const DictionaryValue* config_state() { | |
| 116 return config_state_; | |
| 117 } | |
| 118 | |
| 119 private: | |
| 120 friend struct DefaultSingletonTraits<TestConfigState>; | |
| 121 TestConfigState(); | |
| 122 | |
| 123 DictionaryValue* config_state_; | |
| 124 | |
| 125 DISALLOW_COPY_AND_ASSIGN(TestConfigState); | |
| 126 }; | |
| 127 | |
| 128 virtual ~ExtensionTestGetConfigFunction(); | |
| 129 | |
| 130 // ExtensionFunction: | |
| 131 virtual bool RunImpl() OVERRIDE; | |
| 132 }; | |
| 133 | |
| 134 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_TEST_API_H_ | |
| OLD | NEW |