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