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 "content/public/test/test_utils.h"
8 #include "extensions/browser/extension_registry.h"
10 namespace extensions
{
12 class TestExtensionRegistryObserver::Waiter
{
14 Waiter(const std::string
& extension_id
) : observed_(false), runner_(NULL
) {}
20 runner_
= new content::MessageLoopRunner();
35 scoped_refptr
<content::MessageLoopRunner
> runner_
;
37 DISALLOW_COPY_AND_ASSIGN(Waiter
);
40 TestExtensionRegistryObserver::TestExtensionRegistryObserver(
41 ExtensionRegistry
* registry
,
42 const std::string
& extension_id
)
43 : will_be_installed_waiter_(new Waiter(extension_id
)),
44 uninstalled_waiter_(new Waiter(extension_id
)),
45 loaded_waiter_(new Waiter(extension_id
)),
46 unloaded_waiter_(new Waiter(extension_id
)),
47 extension_registry_observer_(this),
48 extension_id_(extension_id
) {
49 extension_registry_observer_
.Add(registry
);
52 TestExtensionRegistryObserver::~TestExtensionRegistryObserver() {
55 void TestExtensionRegistryObserver::WaitForExtensionUninstalled() {
56 uninstalled_waiter_
->Wait();
59 void TestExtensionRegistryObserver::WaitForExtensionWillBeInstalled() {
60 will_be_installed_waiter_
->Wait();
63 void TestExtensionRegistryObserver::WaitForExtensionLoaded() {
64 loaded_waiter_
->Wait();
67 void TestExtensionRegistryObserver::WaitForExtensionUnloaded() {
68 unloaded_waiter_
->Wait();
71 void TestExtensionRegistryObserver::OnExtensionWillBeInstalled(
72 content::BrowserContext
* browser_context
,
73 const Extension
* extension
,
76 const std::string
& old_name
) {
77 if (extension
->id() == extension_id_
)
78 will_be_installed_waiter_
->OnObserved();
81 void TestExtensionRegistryObserver::OnExtensionUninstalled(
82 content::BrowserContext
* browser_context
,
83 const Extension
* extension
,
84 extensions::UninstallReason reason
) {
85 if (extension
->id() == extension_id_
)
86 uninstalled_waiter_
->OnObserved();
89 void TestExtensionRegistryObserver::OnExtensionLoaded(
90 content::BrowserContext
* browser_context
,
91 const Extension
* extension
) {
92 if (extension
->id() == extension_id_
)
93 loaded_waiter_
->OnObserved();
96 void TestExtensionRegistryObserver::OnExtensionUnloaded(
97 content::BrowserContext
* browser_context
,
98 const Extension
* extension
,
99 UnloadedExtensionInfo::Reason reason
) {
100 if (extension
->id() == extension_id_
)
101 unloaded_waiter_
->OnObserved();
104 } // namespace extensions