OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <deque> | 5 #include <deque> |
6 #include <memory> | 6 #include <memory> |
7 #include <set> | 7 #include <set> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/location.h" | 12 #include "base/location.h" |
13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
| 16 #include "base/stl_util.h" |
16 #include "base/test/simple_test_tick_clock.h" | 17 #include "base/test/simple_test_tick_clock.h" |
17 #include "base/threading/thread_task_runner_handle.h" | 18 #include "base/threading/thread_task_runner_handle.h" |
18 #include "chrome/browser/extensions/api/runtime/chrome_runtime_api_delegate.h" | 19 #include "chrome/browser/extensions/api/runtime/chrome_runtime_api_delegate.h" |
19 #include "chrome/browser/extensions/extension_service.h" | 20 #include "chrome/browser/extensions/extension_service.h" |
20 #include "chrome/browser/extensions/extension_service_test_with_install.h" | 21 #include "chrome/browser/extensions/extension_service_test_with_install.h" |
21 #include "chrome/browser/extensions/test_extension_system.h" | 22 #include "chrome/browser/extensions/test_extension_system.h" |
22 #include "chrome/browser/extensions/update_install_gate.h" | 23 #include "chrome/browser/extensions/update_install_gate.h" |
23 #include "chrome/browser/extensions/updater/extension_updater.h" | 24 #include "chrome/browser/extensions/updater/extension_updater.h" |
24 #include "extensions/browser/event_router.h" | 25 #include "extensions/browser/event_router.h" |
25 #include "extensions/browser/event_router_factory.h" | 26 #include "extensions/browser/event_router_factory.h" |
(...skipping 12 matching lines...) Expand all Loading... |
38 class TestEventRouter : public EventRouter { | 39 class TestEventRouter : public EventRouter { |
39 public: | 40 public: |
40 explicit TestEventRouter(content::BrowserContext* context) | 41 explicit TestEventRouter(content::BrowserContext* context) |
41 : EventRouter(context, ExtensionPrefs::Get(context)) {} | 42 : EventRouter(context, ExtensionPrefs::Get(context)) {} |
42 ~TestEventRouter() override {} | 43 ~TestEventRouter() override {} |
43 | 44 |
44 // An entry in our fake event registry. | 45 // An entry in our fake event registry. |
45 using Entry = std::pair<std::string, std::string>; | 46 using Entry = std::pair<std::string, std::string>; |
46 | 47 |
47 bool ExtensionHasEventListener(const std::string& extension_id, | 48 bool ExtensionHasEventListener(const std::string& extension_id, |
48 const std::string& event_name) override { | 49 const std::string& event_name) const override { |
49 return fake_registry_.find(Entry(extension_id, event_name)) != | 50 return base::ContainsKey(fake_registry_, Entry(extension_id, event_name)); |
50 fake_registry_.end(); | |
51 } | 51 } |
52 | 52 |
53 // Pretend that |extension_id| is listening for |event_name|. | 53 // Pretend that |extension_id| is listening for |event_name|. |
54 void AddFakeListener(const std::string& extension_id, | 54 void AddFakeListener(const std::string& extension_id, |
55 const std::string& event_name) { | 55 const std::string& event_name) { |
56 fake_registry_.insert(Entry(extension_id, event_name)); | 56 fake_registry_.insert(Entry(extension_id, event_name)); |
57 } | 57 } |
58 | 58 |
59 private: | 59 private: |
60 std::set<Entry> fake_registry_; | 60 std::set<Entry> fake_registry_; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 DISALLOW_COPY_AND_ASSIGN(DownloaderTestDelegate); | 153 DISALLOW_COPY_AND_ASSIGN(DownloaderTestDelegate); |
154 }; | 154 }; |
155 | 155 |
156 // Helper to let test code wait for and return an update check result. | 156 // Helper to let test code wait for and return an update check result. |
157 class UpdateCheckResultCatcher { | 157 class UpdateCheckResultCatcher { |
158 public: | 158 public: |
159 UpdateCheckResultCatcher() {} | 159 UpdateCheckResultCatcher() {} |
160 | 160 |
161 void OnResult(const RuntimeAPIDelegate::UpdateCheckResult& result) { | 161 void OnResult(const RuntimeAPIDelegate::UpdateCheckResult& result) { |
162 EXPECT_EQ(nullptr, result_.get()); | 162 EXPECT_EQ(nullptr, result_.get()); |
163 result_.reset(new RuntimeAPIDelegate::UpdateCheckResult( | 163 result_ = base::MakeUnique<RuntimeAPIDelegate::UpdateCheckResult>( |
164 result.success, result.response, result.version)); | 164 result.success, result.response, result.version); |
165 if (run_loop_) | 165 if (run_loop_) |
166 run_loop_->Quit(); | 166 run_loop_->Quit(); |
167 } | 167 } |
168 | 168 |
169 std::unique_ptr<RuntimeAPIDelegate::UpdateCheckResult> WaitForResult() { | 169 std::unique_ptr<RuntimeAPIDelegate::UpdateCheckResult> WaitForResult() { |
170 if (!result_) { | 170 if (!result_) { |
171 run_loop_.reset(new base::RunLoop); | 171 run_loop_ = base::MakeUnique<base::RunLoop>(); |
172 run_loop_->Run(); | 172 run_loop_->Run(); |
173 } | 173 } |
174 return std::move(result_); | 174 return std::move(result_); |
175 } | 175 } |
176 | 176 |
177 private: | 177 private: |
178 std::unique_ptr<RuntimeAPIDelegate::UpdateCheckResult> result_; | 178 std::unique_ptr<RuntimeAPIDelegate::UpdateCheckResult> result_; |
179 std::unique_ptr<base::RunLoop> run_loop_; | 179 std::unique_ptr<base::RunLoop> run_loop_; |
180 | 180 |
181 DISALLOW_COPY_AND_ASSIGN(UpdateCheckResultCatcher); | 181 DISALLOW_COPY_AND_ASSIGN(UpdateCheckResultCatcher); |
182 }; | 182 }; |
183 | 183 |
184 class ChromeRuntimeAPIDelegateTest : public ExtensionServiceTestWithInstall { | 184 class ChromeRuntimeAPIDelegateTest : public ExtensionServiceTestWithInstall { |
185 public: | 185 public: |
186 ChromeRuntimeAPIDelegateTest() {} | 186 ChromeRuntimeAPIDelegateTest() {} |
187 | 187 |
188 void SetUp() override { | 188 void SetUp() override { |
189 ExtensionServiceTestWithInstall::SetUp(); | 189 ExtensionServiceTestWithInstall::SetUp(); |
190 ExtensionDownloader::set_test_delegate(&downloader_test_delegate_); | 190 ExtensionDownloader::set_test_delegate(&downloader_test_delegate_); |
191 ChromeRuntimeAPIDelegate::set_tick_clock_for_tests(&clock_); | 191 ChromeRuntimeAPIDelegate::set_tick_clock_for_tests(&clock_); |
192 | 192 |
193 InitializeExtensionServiceWithUpdater(); | 193 InitializeExtensionServiceWithUpdater(); |
194 runtime_delegate_.reset(new ChromeRuntimeAPIDelegate(browser_context())); | 194 runtime_delegate_ = |
| 195 base::MakeUnique<ChromeRuntimeAPIDelegate>(browser_context()); |
195 service()->updater()->SetExtensionCacheForTesting(nullptr); | 196 service()->updater()->SetExtensionCacheForTesting(nullptr); |
196 EventRouterFactory::GetInstance()->SetTestingFactory( | 197 EventRouterFactory::GetInstance()->SetTestingFactory( |
197 browser_context(), &TestEventRouterFactoryFunction); | 198 browser_context(), &TestEventRouterFactoryFunction); |
198 | 199 |
199 // Setup the ExtensionService so that extension updates won't complete | 200 // Setup the ExtensionService so that extension updates won't complete |
200 // installation until the extension is idle. | 201 // installation until the extension is idle. |
201 update_install_gate_.reset(new UpdateInstallGate(service())); | 202 update_install_gate_ = base::MakeUnique<UpdateInstallGate>(service()); |
202 service()->RegisterInstallGate(ExtensionPrefs::DELAY_REASON_WAIT_FOR_IDLE, | 203 service()->RegisterInstallGate(ExtensionPrefs::DELAY_REASON_WAIT_FOR_IDLE, |
203 update_install_gate_.get()); | 204 update_install_gate_.get()); |
204 static_cast<TestExtensionSystem*>(ExtensionSystem::Get(browser_context())) | 205 static_cast<TestExtensionSystem*>(ExtensionSystem::Get(browser_context())) |
205 ->SetReady(); | 206 ->SetReady(); |
206 } | 207 } |
207 | 208 |
208 void TearDown() override { | 209 void TearDown() override { |
209 ExtensionDownloader::set_test_delegate(nullptr); | 210 ExtensionDownloader::set_test_delegate(nullptr); |
210 ChromeRuntimeAPIDelegate::set_tick_clock_for_tests(nullptr); | 211 ChromeRuntimeAPIDelegate::set_tick_clock_for_tests(nullptr); |
211 ExtensionServiceTestWithInstall::TearDown(); | 212 ExtensionServiceTestWithInstall::TearDown(); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 | 313 |
313 // Call again after a longer delay, we should should be unthrottled. | 314 // Call again after a longer delay, we should should be unthrottled. |
314 clock_.Advance(base::TimeDelta::FromHours(8)); | 315 clock_.Advance(base::TimeDelta::FromHours(8)); |
315 downloader_test_delegate_.AddNoUpdateResponse(id); | 316 downloader_test_delegate_.AddNoUpdateResponse(id); |
316 DoUpdateCheck(id, "no_update", ""); | 317 DoUpdateCheck(id, "no_update", ""); |
317 } | 318 } |
318 | 319 |
319 } // namespace | 320 } // namespace |
320 | 321 |
321 } // namespace extensions | 322 } // namespace extensions |
OLD | NEW |