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"
14 struct DefaultSingletonTraits
;
18 namespace extensions
{
20 // A function that is only available in tests.
21 // Prior to running, checks that we are in a testing process.
22 class TestExtensionFunction
: public SyncExtensionFunction
{
24 ~TestExtensionFunction() override
;
26 // SyncExtensionFunction:
27 bool RunSync() override
;
29 virtual bool RunSafe() = 0;
32 class TestNotifyPassFunction
: public TestExtensionFunction
{
34 DECLARE_EXTENSION_FUNCTION("test.notifyPass", UNKNOWN
)
37 ~TestNotifyPassFunction() override
;
39 // TestExtensionFunction:
40 bool RunSafe() override
;
43 class TestNotifyFailFunction
: public TestExtensionFunction
{
45 DECLARE_EXTENSION_FUNCTION("test.notifyFail", UNKNOWN
)
48 ~TestNotifyFailFunction() override
;
50 // TestExtensionFunction:
51 bool RunSafe() override
;
54 class TestLogFunction
: public TestExtensionFunction
{
56 DECLARE_EXTENSION_FUNCTION("test.log", UNKNOWN
)
59 ~TestLogFunction() override
;
61 // TestExtensionFunction:
62 bool RunSafe() override
;
65 class TestSendMessageFunction
: public AsyncExtensionFunction
{
67 DECLARE_EXTENSION_FUNCTION("test.sendMessage", UNKNOWN
)
69 // Sends a reply back to the calling extension. Many extensions don't need
70 // a reply and will just ignore it.
71 void Reply(const std::string
& message
);
73 // Sends an error back to the calling extension.
74 void ReplyWithError(const std::string
& error
);
77 ~TestSendMessageFunction() override
;
80 bool RunAsync() override
;
83 class TestGetConfigFunction
: public TestExtensionFunction
{
85 DECLARE_EXTENSION_FUNCTION("test.getConfig", UNKNOWN
)
87 // Set the dictionary returned by chrome.test.getConfig().
88 // Does not take ownership of |value|.
89 static void set_test_config_state(base::DictionaryValue
* value
);
92 // Tests that set configuration state do so by calling
93 // set_test_config_state() as part of test set up, and unsetting it
94 // during tear down. This singleton class holds a pointer to that
95 // state, owned by the test code.
96 class TestConfigState
{
98 static TestConfigState
* GetInstance();
100 void set_config_state(base::DictionaryValue
* config_state
) {
101 config_state_
= config_state
;
104 const base::DictionaryValue
* config_state() { return config_state_
; }
107 friend struct base::DefaultSingletonTraits
<TestConfigState
>;
110 base::DictionaryValue
* config_state_
;
112 DISALLOW_COPY_AND_ASSIGN(TestConfigState
);
115 ~TestGetConfigFunction() override
;
117 // TestExtensionFunction:
118 bool RunSafe() override
;
121 class TestWaitForRoundTripFunction
: public TestExtensionFunction
{
123 DECLARE_EXTENSION_FUNCTION("test.waitForRoundTrip", UNKNOWN
)
126 ~TestWaitForRoundTripFunction() override
;
128 // TestExtensionFunction:
129 bool RunSafe() override
;
132 } // namespace extensions
134 #endif // EXTENSIONS_BROWSER_API_TEST_TEST_API_H_