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_API_TEST_TEST_API_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_TEST_TEST_API_H_ 7 8 #include "base/values.h" 9 #include "chrome/browser/extensions/chrome_extension_function.h" 10 11 template <typename T> struct DefaultSingletonTraits; 12 13 namespace extensions { 14 15 // A function that is only available in tests. 16 // Prior to running, checks that we are in an extension process. 17 class TestExtensionFunction : public ChromeSyncExtensionFunction { 18 protected: 19 virtual ~TestExtensionFunction(); 20 21 // ExtensionFunction: 22 virtual void Run() OVERRIDE; 23 }; 24 25 class TestNotifyPassFunction : public TestExtensionFunction { 26 public: 27 DECLARE_EXTENSION_FUNCTION("test.notifyPass", UNKNOWN) 28 29 protected: 30 virtual ~TestNotifyPassFunction(); 31 32 // ExtensionFunction: 33 virtual bool RunImpl() OVERRIDE; 34 }; 35 36 class TestNotifyFailFunction : public TestExtensionFunction { 37 public: 38 DECLARE_EXTENSION_FUNCTION("test.notifyFail", UNKNOWN) 39 40 protected: 41 virtual ~TestNotifyFailFunction(); 42 43 // ExtensionFunction: 44 virtual bool RunImpl() OVERRIDE; 45 }; 46 47 class TestLogFunction : public TestExtensionFunction { 48 public: 49 DECLARE_EXTENSION_FUNCTION("test.log", UNKNOWN) 50 51 protected: 52 virtual ~TestLogFunction(); 53 54 // ExtensionFunction: 55 virtual bool RunImpl() OVERRIDE; 56 }; 57 58 class TestResetQuotaFunction : public TestExtensionFunction { 59 public: 60 DECLARE_EXTENSION_FUNCTION("test.resetQuota", UNKNOWN) 61 62 protected: 63 virtual ~TestResetQuotaFunction(); 64 65 // ExtensionFunction: 66 virtual bool RunImpl() OVERRIDE; 67 }; 68 69 class TestCreateIncognitoTabFunction : public TestExtensionFunction { 70 public: 71 DECLARE_EXTENSION_FUNCTION("test.createIncognitoTab", UNKNOWN) 72 73 protected: 74 virtual ~TestCreateIncognitoTabFunction(); 75 76 // ExtensionFunction: 77 virtual bool RunImpl() OVERRIDE; 78 }; 79 80 class TestSendMessageFunction : public ChromeAsyncExtensionFunction { 81 public: 82 DECLARE_EXTENSION_FUNCTION("test.sendMessage", UNKNOWN) 83 84 // Sends a reply back to the calling extension. Many extensions don't need 85 // a reply and will just ignore it. 86 void Reply(const std::string& message); 87 88 protected: 89 virtual ~TestSendMessageFunction(); 90 91 // ExtensionFunction: 92 virtual bool RunImpl() OVERRIDE; 93 }; 94 95 class TestGetConfigFunction : public ChromeSyncExtensionFunction { 96 public: 97 DECLARE_EXTENSION_FUNCTION("test.getConfig", UNKNOWN) 98 99 // Set the dictionary returned by chrome.test.getConfig(). 100 // Does not take ownership of |value|. 101 static void set_test_config_state(base::DictionaryValue* value); 102 103 protected: 104 // Tests that set configuration state do so by calling 105 // set_test_config_state() as part of test set up, and unsetting it 106 // during tear down. This singleton class holds a pointer to that 107 // state, owned by the test code. 108 class TestConfigState { 109 public: 110 static TestConfigState* GetInstance(); 111 112 void set_config_state(base::DictionaryValue* config_state) { 113 config_state_ = config_state; 114 } 115 116 const base::DictionaryValue* config_state() { 117 return config_state_; 118 } 119 120 private: 121 friend struct DefaultSingletonTraits<TestConfigState>; 122 TestConfigState(); 123 124 base::DictionaryValue* config_state_; 125 126 DISALLOW_COPY_AND_ASSIGN(TestConfigState); 127 }; 128 129 virtual ~TestGetConfigFunction(); 130 131 // ExtensionFunction: 132 virtual bool RunImpl() OVERRIDE; 133 }; 134 135 } // namespace extensions 136 137 #endif // CHROME_BROWSER_EXTENSIONS_API_TEST_TEST_API_H_ 138