OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "extensions/browser/api/test/test_api.h" | 5 #include "extensions/browser/api/test/test_api.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 | 31 |
32 namespace extensions { | 32 namespace extensions { |
33 | 33 |
34 namespace Log = api::test::Log; | 34 namespace Log = api::test::Log; |
35 namespace NotifyFail = api::test::NotifyFail; | 35 namespace NotifyFail = api::test::NotifyFail; |
36 namespace PassMessage = api::test::PassMessage; | 36 namespace PassMessage = api::test::PassMessage; |
37 namespace WaitForRoundTrip = api::test::WaitForRoundTrip; | 37 namespace WaitForRoundTrip = api::test::WaitForRoundTrip; |
38 | 38 |
39 TestExtensionFunction::~TestExtensionFunction() {} | 39 TestExtensionFunction::~TestExtensionFunction() {} |
40 | 40 |
41 bool TestExtensionFunction::RunSync() { | 41 bool TestExtensionFunction::PreRunValidation(std::string* error) { |
| 42 if (!UIThreadExtensionFunction::PreRunValidation(error)) |
| 43 return false; |
42 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) { | 44 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) { |
43 error_ = kNotTestProcessError; | 45 *error = kNotTestProcessError; |
44 return false; | 46 return false; |
45 } | 47 } |
46 return RunSafe(); | 48 return true; |
47 } | 49 } |
48 | 50 |
49 TestNotifyPassFunction::~TestNotifyPassFunction() {} | 51 TestNotifyPassFunction::~TestNotifyPassFunction() {} |
50 | 52 |
51 bool TestNotifyPassFunction::RunSafe() { | 53 ExtensionFunction::ResponseAction TestNotifyPassFunction::Run() { |
52 content::NotificationService::current()->Notify( | 54 content::NotificationService::current()->Notify( |
53 extensions::NOTIFICATION_EXTENSION_TEST_PASSED, | 55 extensions::NOTIFICATION_EXTENSION_TEST_PASSED, |
54 content::Source<content::BrowserContext>(dispatcher()->browser_context()), | 56 content::Source<content::BrowserContext>(dispatcher()->browser_context()), |
55 content::NotificationService::NoDetails()); | 57 content::NotificationService::NoDetails()); |
56 return true; | 58 return RespondNow(NoArguments()); |
57 } | 59 } |
58 | 60 |
59 TestNotifyFailFunction::~TestNotifyFailFunction() {} | 61 TestNotifyFailFunction::~TestNotifyFailFunction() {} |
60 | 62 |
61 bool TestNotifyFailFunction::RunSafe() { | 63 ExtensionFunction::ResponseAction TestNotifyFailFunction::Run() { |
62 std::unique_ptr<NotifyFail::Params> params( | 64 std::unique_ptr<NotifyFail::Params> params( |
63 NotifyFail::Params::Create(*args_)); | 65 NotifyFail::Params::Create(*args_)); |
64 EXTENSION_FUNCTION_VALIDATE(params.get()); | 66 EXTENSION_FUNCTION_VALIDATE(params.get()); |
65 content::NotificationService::current()->Notify( | 67 content::NotificationService::current()->Notify( |
66 extensions::NOTIFICATION_EXTENSION_TEST_FAILED, | 68 extensions::NOTIFICATION_EXTENSION_TEST_FAILED, |
67 content::Source<content::BrowserContext>(dispatcher()->browser_context()), | 69 content::Source<content::BrowserContext>(dispatcher()->browser_context()), |
68 content::Details<std::string>(¶ms->message)); | 70 content::Details<std::string>(¶ms->message)); |
69 return true; | 71 return RespondNow(NoArguments()); |
70 } | 72 } |
71 | 73 |
72 TestLogFunction::~TestLogFunction() {} | 74 TestLogFunction::~TestLogFunction() {} |
73 | 75 |
74 bool TestLogFunction::RunSafe() { | 76 ExtensionFunction::ResponseAction TestLogFunction::Run() { |
75 std::unique_ptr<Log::Params> params(Log::Params::Create(*args_)); | 77 std::unique_ptr<Log::Params> params(Log::Params::Create(*args_)); |
76 EXTENSION_FUNCTION_VALIDATE(params.get()); | 78 EXTENSION_FUNCTION_VALIDATE(params.get()); |
77 VLOG(1) << params->message; | 79 VLOG(1) << params->message; |
78 return true; | 80 return RespondNow(NoArguments()); |
79 } | 81 } |
80 | 82 |
81 TestSendMessageFunction::TestSendMessageFunction() : waiting_(false) {} | 83 TestSendMessageFunction::TestSendMessageFunction() : waiting_(false) {} |
82 | 84 |
83 ExtensionFunction::ResponseAction TestSendMessageFunction::Run() { | 85 ExtensionFunction::ResponseAction TestSendMessageFunction::Run() { |
84 std::unique_ptr<PassMessage::Params> params( | 86 std::unique_ptr<PassMessage::Params> params( |
85 PassMessage::Params::Create(*args_)); | 87 PassMessage::Params::Create(*args_)); |
86 EXTENSION_FUNCTION_VALIDATE(params.get()); | 88 EXTENSION_FUNCTION_VALIDATE(params.get()); |
87 bool listener_will_respond = false; | 89 bool listener_will_respond = false; |
88 std::pair<std::string, bool*> details(params->message, | 90 std::pair<std::string, bool*> details(params->message, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 : config_state_(NULL) {} | 134 : config_state_(NULL) {} |
133 | 135 |
134 // static | 136 // static |
135 TestGetConfigFunction::TestConfigState* | 137 TestGetConfigFunction::TestConfigState* |
136 TestGetConfigFunction::TestConfigState::GetInstance() { | 138 TestGetConfigFunction::TestConfigState::GetInstance() { |
137 return base::Singleton<TestConfigState>::get(); | 139 return base::Singleton<TestConfigState>::get(); |
138 } | 140 } |
139 | 141 |
140 TestGetConfigFunction::~TestGetConfigFunction() {} | 142 TestGetConfigFunction::~TestGetConfigFunction() {} |
141 | 143 |
142 bool TestGetConfigFunction::RunSafe() { | 144 ExtensionFunction::ResponseAction TestGetConfigFunction::Run() { |
143 TestConfigState* test_config_state = TestConfigState::GetInstance(); | 145 TestConfigState* test_config_state = TestConfigState::GetInstance(); |
144 | 146 if (!test_config_state->config_state()) |
145 if (!test_config_state->config_state()) { | 147 return RespondNow(Error(kNoTestConfigDataError)); |
146 error_ = kNoTestConfigDataError; | 148 return RespondNow( |
147 return false; | 149 OneArgument(test_config_state->config_state()->CreateDeepCopy())); |
148 } | |
149 | |
150 SetResult(test_config_state->config_state()->CreateDeepCopy()); | |
151 return true; | |
152 } | 150 } |
153 | 151 |
154 TestWaitForRoundTripFunction::~TestWaitForRoundTripFunction() {} | 152 TestWaitForRoundTripFunction::~TestWaitForRoundTripFunction() {} |
155 | 153 |
156 bool TestWaitForRoundTripFunction::RunSafe() { | 154 ExtensionFunction::ResponseAction TestWaitForRoundTripFunction::Run() { |
157 std::unique_ptr<WaitForRoundTrip::Params> params( | 155 std::unique_ptr<WaitForRoundTrip::Params> params( |
158 WaitForRoundTrip::Params::Create(*args_)); | 156 WaitForRoundTrip::Params::Create(*args_)); |
159 SetResult(base::MakeUnique<base::StringValue>(params->message)); | 157 return RespondNow( |
160 return true; | 158 OneArgument(base::MakeUnique<base::StringValue>(params->message))); |
161 } | 159 } |
162 | 160 |
163 } // namespace extensions | 161 } // namespace extensions |
OLD | NEW |