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.
5 #ifndef EXTENSIONS_BROWSER_API_TEST_TEST_API_H_
6 #define EXTENSIONS_BROWSER_API_TEST_TEST_API_H_
8 #include "base/values.h"
9 #include "extensions/browser/extension_function.h"
12 struct DefaultSingletonTraits;
14 namespace extensions {
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 {
20 virtual ~TestExtensionFunction();
22 // SyncExtensionFunction:
23 virtual bool RunSync() OVERRIDE;
25 virtual bool RunSafe() = 0;
28 class TestNotifyPassFunction : public TestExtensionFunction {
30 DECLARE_EXTENSION_FUNCTION("test.notifyPass", UNKNOWN)
33 virtual ~TestNotifyPassFunction();
35 // TestExtensionFunction:
36 virtual bool RunSafe() OVERRIDE;
39 class TestNotifyFailFunction : public TestExtensionFunction {
41 DECLARE_EXTENSION_FUNCTION("test.notifyFail", UNKNOWN)
44 virtual ~TestNotifyFailFunction();
46 // TestExtensionFunction:
47 virtual bool RunSafe() OVERRIDE;
50 class TestLogFunction : public TestExtensionFunction {
52 DECLARE_EXTENSION_FUNCTION("test.log", UNKNOWN)
55 virtual ~TestLogFunction();
57 // TestExtensionFunction:
58 virtual bool RunSafe() OVERRIDE;
61 class TestResetQuotaFunction : public TestExtensionFunction {
63 DECLARE_EXTENSION_FUNCTION("test.resetQuota", UNKNOWN)
66 virtual ~TestResetQuotaFunction();
68 // TestExtensionFunction:
69 virtual bool RunSafe() OVERRIDE;
72 class TestSendMessageFunction : public AsyncExtensionFunction {
74 DECLARE_EXTENSION_FUNCTION("test.sendMessage", UNKNOWN)
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);
81 virtual ~TestSendMessageFunction();
84 virtual bool RunAsync() OVERRIDE;
87 class TestGetConfigFunction : public TestExtensionFunction {
89 DECLARE_EXTENSION_FUNCTION("test.getConfig", UNKNOWN)
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);
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 {
102 static TestConfigState* GetInstance();
104 void set_config_state(base::DictionaryValue* config_state) {
105 config_state_ = config_state;
108 const base::DictionaryValue* config_state() { return config_state_; }
111 friend struct DefaultSingletonTraits<TestConfigState>;
114 base::DictionaryValue* config_state_;
116 DISALLOW_COPY_AND_ASSIGN(TestConfigState);
119 virtual ~TestGetConfigFunction();
121 // TestExtensionFunction:
122 virtual bool RunSafe() OVERRIDE;
125 class TestWaitForRoundTripFunction : public TestExtensionFunction {
127 DECLARE_EXTENSION_FUNCTION("test.waitForRoundTrip", UNKNOWN)
130 virtual ~TestWaitForRoundTripFunction();
132 // TestExtensionFunction:
133 virtual bool RunSafe() OVERRIDE;
136 } // namespace extensions
138 #endif // EXTENSIONS_BROWSER_API_TEST_TEST_API_H_