+ Fix cloud sprite clipping on 2x
[chromium-blink-merge.git] / extensions / browser / test_extension_registry_observer.cc
blobd9a1575d16b1f0ae24d4bfa7cdba07ed3f35efeb
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 {
13 public:
14 explicit Waiter(const std::string& extension_id)
15 : observed_(false), runner_(NULL) {}
17 void Wait() {
18 if (observed_)
19 return;
21 runner_ = new content::MessageLoopRunner();
22 runner_->Run();
25 void OnObserved() {
26 observed_ = true;
28 if (runner_.get()) {
29 runner_->Quit();
30 runner_ = NULL;
34 private:
35 bool observed_;
36 scoped_refptr<content::MessageLoopRunner> runner_;
38 DISALLOW_COPY_AND_ASSIGN(Waiter);
41 TestExtensionRegistryObserver::TestExtensionRegistryObserver(
42 ExtensionRegistry* registry,
43 const std::string& extension_id)
44 : will_be_installed_waiter_(new Waiter(extension_id)),
45 uninstalled_waiter_(new Waiter(extension_id)),
46 loaded_waiter_(new Waiter(extension_id)),
47 unloaded_waiter_(new Waiter(extension_id)),
48 extension_registry_observer_(this),
49 extension_id_(extension_id) {
50 extension_registry_observer_.Add(registry);
53 TestExtensionRegistryObserver::~TestExtensionRegistryObserver() {
56 void TestExtensionRegistryObserver::WaitForExtensionUninstalled() {
57 uninstalled_waiter_->Wait();
60 void TestExtensionRegistryObserver::WaitForExtensionWillBeInstalled() {
61 will_be_installed_waiter_->Wait();
64 void TestExtensionRegistryObserver::WaitForExtensionLoaded() {
65 loaded_waiter_->Wait();
68 void TestExtensionRegistryObserver::WaitForExtensionUnloaded() {
69 unloaded_waiter_->Wait();
72 void TestExtensionRegistryObserver::OnExtensionWillBeInstalled(
73 content::BrowserContext* browser_context,
74 const Extension* extension,
75 bool is_update,
76 bool from_ephemeral,
77 const std::string& old_name) {
78 if (extension->id() == extension_id_)
79 will_be_installed_waiter_->OnObserved();
82 void TestExtensionRegistryObserver::OnExtensionUninstalled(
83 content::BrowserContext* browser_context,
84 const Extension* extension,
85 extensions::UninstallReason reason) {
86 if (extension->id() == extension_id_)
87 uninstalled_waiter_->OnObserved();
90 void TestExtensionRegistryObserver::OnExtensionLoaded(
91 content::BrowserContext* browser_context,
92 const Extension* extension) {
93 if (extension->id() == extension_id_)
94 loaded_waiter_->OnObserved();
97 void TestExtensionRegistryObserver::OnExtensionUnloaded(
98 content::BrowserContext* browser_context,
99 const Extension* extension,
100 UnloadedExtensionInfo::Reason reason) {
101 if (extension->id() == extension_id_)
102 unloaded_waiter_->OnObserved();
105 } // namespace extensions