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 ~TestExtensionFunction() override
;
22 // SyncExtensionFunction:
23 bool RunSync() override
;
25 virtual bool RunSafe() = 0;
28 class TestNotifyPassFunction
: public TestExtensionFunction
{
30 DECLARE_EXTENSION_FUNCTION("test.notifyPass", UNKNOWN
)
33 ~TestNotifyPassFunction() override
;
35 // TestExtensionFunction:
36 bool RunSafe() override
;
39 class TestNotifyFailFunction
: public TestExtensionFunction
{
41 DECLARE_EXTENSION_FUNCTION("test.notifyFail", UNKNOWN
)
44 ~TestNotifyFailFunction() override
;
46 // TestExtensionFunction:
47 bool RunSafe() override
;
50 class TestLogFunction
: public TestExtensionFunction
{
52 DECLARE_EXTENSION_FUNCTION("test.log", UNKNOWN
)
55 ~TestLogFunction() override
;
57 // TestExtensionFunction:
58 bool RunSafe() override
;
61 class TestSendMessageFunction
: public AsyncExtensionFunction
{
63 DECLARE_EXTENSION_FUNCTION("test.sendMessage", UNKNOWN
)
65 // Sends a reply back to the calling extension. Many extensions don't need
66 // a reply and will just ignore it.
67 void Reply(const std::string
& message
);
69 // Sends an error back to the calling extension.
70 void ReplyWithError(const std::string
& error
);
73 ~TestSendMessageFunction() override
;
76 bool RunAsync() override
;
79 class TestGetConfigFunction
: public TestExtensionFunction
{
81 DECLARE_EXTENSION_FUNCTION("test.getConfig", UNKNOWN
)
83 // Set the dictionary returned by chrome.test.getConfig().
84 // Does not take ownership of |value|.
85 static void set_test_config_state(base::DictionaryValue
* value
);
88 // Tests that set configuration state do so by calling
89 // set_test_config_state() as part of test set up, and unsetting it
90 // during tear down. This singleton class holds a pointer to that
91 // state, owned by the test code.
92 class TestConfigState
{
94 static TestConfigState
* GetInstance();
96 void set_config_state(base::DictionaryValue
* config_state
) {
97 config_state_
= config_state
;
100 const base::DictionaryValue
* config_state() { return config_state_
; }
103 friend struct DefaultSingletonTraits
<TestConfigState
>;
106 base::DictionaryValue
* config_state_
;
108 DISALLOW_COPY_AND_ASSIGN(TestConfigState
);
111 ~TestGetConfigFunction() override
;
113 // TestExtensionFunction:
114 bool RunSafe() override
;
117 class TestWaitForRoundTripFunction
: public TestExtensionFunction
{
119 DECLARE_EXTENSION_FUNCTION("test.waitForRoundTrip", UNKNOWN
)
122 ~TestWaitForRoundTripFunction() override
;
124 // TestExtensionFunction:
125 bool RunSafe() override
;
128 } // namespace extensions
130 #endif // EXTENSIONS_BROWSER_API_TEST_TEST_API_H_