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/singleton.h" | 10 #include "base/memory/singleton.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 | 31 |
32 namespace extensions { | 32 namespace extensions { |
33 | 33 |
34 namespace Log = core_api::test::Log; | 34 namespace Log = core_api::test::Log; |
35 namespace NotifyFail = core_api::test::NotifyFail; | 35 namespace NotifyFail = core_api::test::NotifyFail; |
36 namespace PassMessage = core_api::test::PassMessage; | 36 namespace PassMessage = core_api::test::PassMessage; |
37 namespace WaitForRoundTrip = core_api::test::WaitForRoundTrip; | 37 namespace WaitForRoundTrip = core_api::test::WaitForRoundTrip; |
38 | 38 |
39 TestExtensionFunction::~TestExtensionFunction() {} | 39 TestExtensionFunction::~TestExtensionFunction() {} |
40 | 40 |
41 void TestExtensionFunction::Run() { | 41 bool TestExtensionFunction::RunSync() { |
42 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) { | 42 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) { |
43 error_ = kNotTestProcessError; | 43 error_ = kNotTestProcessError; |
44 SendResponse(false); | 44 return false; |
45 return; | |
46 } | 45 } |
47 SendResponse(RunImpl()); | 46 return RunSafe(); |
48 } | 47 } |
49 | 48 |
50 TestNotifyPassFunction::~TestNotifyPassFunction() {} | 49 TestNotifyPassFunction::~TestNotifyPassFunction() {} |
51 | 50 |
52 bool TestNotifyPassFunction::RunImpl() { | 51 bool TestNotifyPassFunction::RunSafe() { |
53 content::NotificationService::current()->Notify( | 52 content::NotificationService::current()->Notify( |
54 chrome::NOTIFICATION_EXTENSION_TEST_PASSED, | 53 chrome::NOTIFICATION_EXTENSION_TEST_PASSED, |
55 content::Source<content::BrowserContext>(dispatcher()->browser_context()), | 54 content::Source<content::BrowserContext>(dispatcher()->browser_context()), |
56 content::NotificationService::NoDetails()); | 55 content::NotificationService::NoDetails()); |
57 return true; | 56 return true; |
58 } | 57 } |
59 | 58 |
60 TestNotifyFailFunction::~TestNotifyFailFunction() {} | 59 TestNotifyFailFunction::~TestNotifyFailFunction() {} |
61 | 60 |
62 bool TestNotifyFailFunction::RunImpl() { | 61 bool TestNotifyFailFunction::RunSafe() { |
63 scoped_ptr<NotifyFail::Params> params(NotifyFail::Params::Create(*args_)); | 62 scoped_ptr<NotifyFail::Params> params(NotifyFail::Params::Create(*args_)); |
64 EXTENSION_FUNCTION_VALIDATE(params.get()); | 63 EXTENSION_FUNCTION_VALIDATE(params.get()); |
65 content::NotificationService::current()->Notify( | 64 content::NotificationService::current()->Notify( |
66 chrome::NOTIFICATION_EXTENSION_TEST_FAILED, | 65 chrome::NOTIFICATION_EXTENSION_TEST_FAILED, |
67 content::Source<content::BrowserContext>(dispatcher()->browser_context()), | 66 content::Source<content::BrowserContext>(dispatcher()->browser_context()), |
68 content::Details<std::string>(¶ms->message)); | 67 content::Details<std::string>(¶ms->message)); |
69 return true; | 68 return true; |
70 } | 69 } |
71 | 70 |
72 TestLogFunction::~TestLogFunction() {} | 71 TestLogFunction::~TestLogFunction() {} |
73 | 72 |
74 bool TestLogFunction::RunImpl() { | 73 bool TestLogFunction::RunSafe() { |
75 scoped_ptr<Log::Params> params(Log::Params::Create(*args_)); | 74 scoped_ptr<Log::Params> params(Log::Params::Create(*args_)); |
76 EXTENSION_FUNCTION_VALIDATE(params.get()); | 75 EXTENSION_FUNCTION_VALIDATE(params.get()); |
77 VLOG(1) << params->message; | 76 VLOG(1) << params->message; |
78 return true; | 77 return true; |
79 } | 78 } |
80 | 79 |
81 TestResetQuotaFunction::~TestResetQuotaFunction() {} | 80 TestResetQuotaFunction::~TestResetQuotaFunction() {} |
82 | 81 |
83 bool TestResetQuotaFunction::RunImpl() { | 82 bool TestResetQuotaFunction::RunSafe() { |
84 QuotaService* quota = | 83 QuotaService* quota = |
85 ExtensionSystem::Get(browser_context())->quota_service(); | 84 ExtensionSystem::Get(browser_context())->quota_service(); |
86 quota->Purge(); | 85 quota->Purge(); |
87 quota->violation_errors_.clear(); | 86 quota->violation_errors_.clear(); |
88 return true; | 87 return true; |
89 } | 88 } |
90 | 89 |
91 bool TestSendMessageFunction::RunImpl() { | 90 bool TestSendMessageFunction::RunImpl() { |
92 scoped_ptr<PassMessage::Params> params(PassMessage::Params::Create(*args_)); | 91 scoped_ptr<PassMessage::Params> params(PassMessage::Params::Create(*args_)); |
93 EXTENSION_FUNCTION_VALIDATE(params.get()); | 92 EXTENSION_FUNCTION_VALIDATE(params.get()); |
(...skipping 22 matching lines...) Expand all Loading... |
116 : config_state_(NULL) {} | 115 : config_state_(NULL) {} |
117 | 116 |
118 // static | 117 // static |
119 TestGetConfigFunction::TestConfigState* | 118 TestGetConfigFunction::TestConfigState* |
120 TestGetConfigFunction::TestConfigState::GetInstance() { | 119 TestGetConfigFunction::TestConfigState::GetInstance() { |
121 return Singleton<TestConfigState>::get(); | 120 return Singleton<TestConfigState>::get(); |
122 } | 121 } |
123 | 122 |
124 TestGetConfigFunction::~TestGetConfigFunction() {} | 123 TestGetConfigFunction::~TestGetConfigFunction() {} |
125 | 124 |
126 bool TestGetConfigFunction::RunImpl() { | 125 bool TestGetConfigFunction::RunSafe() { |
127 TestConfigState* test_config_state = TestConfigState::GetInstance(); | 126 TestConfigState* test_config_state = TestConfigState::GetInstance(); |
128 | 127 |
129 if (!test_config_state->config_state()) { | 128 if (!test_config_state->config_state()) { |
130 error_ = kNoTestConfigDataError; | 129 error_ = kNoTestConfigDataError; |
131 return false; | 130 return false; |
132 } | 131 } |
133 | 132 |
134 SetResult(test_config_state->config_state()->DeepCopy()); | 133 SetResult(test_config_state->config_state()->DeepCopy()); |
135 return true; | 134 return true; |
136 } | 135 } |
137 | 136 |
138 TestWaitForRoundTripFunction::~TestWaitForRoundTripFunction() {} | 137 TestWaitForRoundTripFunction::~TestWaitForRoundTripFunction() {} |
139 | 138 |
140 bool TestWaitForRoundTripFunction::RunImpl() { | 139 bool TestWaitForRoundTripFunction::RunSafe() { |
141 scoped_ptr<WaitForRoundTrip::Params> params( | 140 scoped_ptr<WaitForRoundTrip::Params> params( |
142 WaitForRoundTrip::Params::Create(*args_)); | 141 WaitForRoundTrip::Params::Create(*args_)); |
143 SetResult(new base::StringValue(params->message)); | 142 SetResult(new base::StringValue(params->message)); |
144 return true; | 143 return true; |
145 } | 144 } |
146 | 145 |
147 } // namespace extensions | 146 } // namespace extensions |
OLD | NEW |