Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / extensions / browser / api / test / test_api.h
blob358b4832de1c079ddf46b4aab1dcebb91b37ee72
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"
11 namespace base {
13 template <typename T>
14 struct DefaultSingletonTraits;
16 } // namespace base
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 {
23 protected:
24 ~TestExtensionFunction() override;
26 // SyncExtensionFunction:
27 bool RunSync() override;
29 virtual bool RunSafe() = 0;
32 class TestNotifyPassFunction : public TestExtensionFunction {
33 public:
34 DECLARE_EXTENSION_FUNCTION("test.notifyPass", UNKNOWN)
36 protected:
37 ~TestNotifyPassFunction() override;
39 // TestExtensionFunction:
40 bool RunSafe() override;
43 class TestNotifyFailFunction : public TestExtensionFunction {
44 public:
45 DECLARE_EXTENSION_FUNCTION("test.notifyFail", UNKNOWN)
47 protected:
48 ~TestNotifyFailFunction() override;
50 // TestExtensionFunction:
51 bool RunSafe() override;
54 class TestLogFunction : public TestExtensionFunction {
55 public:
56 DECLARE_EXTENSION_FUNCTION("test.log", UNKNOWN)
58 protected:
59 ~TestLogFunction() override;
61 // TestExtensionFunction:
62 bool RunSafe() override;
65 class TestSendMessageFunction : public AsyncExtensionFunction {
66 public:
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);
76 protected:
77 ~TestSendMessageFunction() override;
79 // ExtensionFunction:
80 bool RunAsync() override;
83 class TestGetConfigFunction : public TestExtensionFunction {
84 public:
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);
91 protected:
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 {
97 public:
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_; }
106 private:
107 friend struct base::DefaultSingletonTraits<TestConfigState>;
108 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 {
122 public:
123 DECLARE_EXTENSION_FUNCTION("test.waitForRoundTrip", UNKNOWN)
125 protected:
126 ~TestWaitForRoundTripFunction() override;
128 // TestExtensionFunction:
129 bool RunSafe() override;
132 } // namespace extensions
134 #endif // EXTENSIONS_BROWSER_API_TEST_TEST_API_H_