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 #include "extensions/browser/test_extension_registry_observer.h"
7 #include "base/run_loop.h"
8 #include "extensions/browser/extension_registry.h"
10 namespace extensions
{
12 class TestExtensionRegistryObserver::Waiter
{
14 explicit Waiter(const std::string
& extension_id
) : observed_(false) {}
29 base::RunLoop run_loop_
;
31 DISALLOW_COPY_AND_ASSIGN(Waiter
);
34 TestExtensionRegistryObserver::TestExtensionRegistryObserver(
35 ExtensionRegistry
* registry
,
36 const std::string
& extension_id
)
37 : will_be_installed_waiter_(new Waiter(extension_id
)),
38 uninstalled_waiter_(new Waiter(extension_id
)),
39 loaded_waiter_(new Waiter(extension_id
)),
40 unloaded_waiter_(new Waiter(extension_id
)),
41 extension_registry_observer_(this),
42 extension_id_(extension_id
) {
43 extension_registry_observer_
.Add(registry
);
46 TestExtensionRegistryObserver::~TestExtensionRegistryObserver() {
49 void TestExtensionRegistryObserver::WaitForExtensionUninstalled() {
50 uninstalled_waiter_
->Wait();
53 void TestExtensionRegistryObserver::WaitForExtensionWillBeInstalled() {
54 will_be_installed_waiter_
->Wait();
57 void TestExtensionRegistryObserver::WaitForExtensionLoaded() {
58 loaded_waiter_
->Wait();
61 void TestExtensionRegistryObserver::WaitForExtensionUnloaded() {
62 unloaded_waiter_
->Wait();
65 void TestExtensionRegistryObserver::OnExtensionWillBeInstalled(
66 content::BrowserContext
* browser_context
,
67 const Extension
* extension
,
70 const std::string
& old_name
) {
71 if (extension
->id() == extension_id_
)
72 will_be_installed_waiter_
->OnObserved();
75 void TestExtensionRegistryObserver::OnExtensionUninstalled(
76 content::BrowserContext
* browser_context
,
77 const Extension
* extension
,
78 extensions::UninstallReason reason
) {
79 if (extension
->id() == extension_id_
)
80 uninstalled_waiter_
->OnObserved();
83 void TestExtensionRegistryObserver::OnExtensionLoaded(
84 content::BrowserContext
* browser_context
,
85 const Extension
* extension
) {
86 if (extension
->id() == extension_id_
)
87 loaded_waiter_
->OnObserved();
90 void TestExtensionRegistryObserver::OnExtensionUnloaded(
91 content::BrowserContext
* browser_context
,
92 const Extension
* extension
,
93 UnloadedExtensionInfo::Reason reason
) {
94 if (extension
->id() == extension_id_
)
95 unloaded_waiter_
->OnObserved();
98 } // namespace extensions