Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / extensions / browser / test_extension_registry_observer.h
blobcd422c08e0f68993cebf58a1274abc1165960fe6
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 #ifndef EXTENSIONS_BROWSER_TEST_EXTENSION_REGISTRY_OBSERVER_H_
6 #define EXTENSIONS_BROWSER_TEST_EXTENSION_REGISTRY_OBSERVER_H_
8 #include <string>
10 #include "base/memory/scoped_ptr.h"
11 #include "base/scoped_observer.h"
12 #include "extensions/browser/extension_registry_observer.h"
14 namespace extensions {
15 class ExtensionRegistry;
17 // A helper class that listen for ExtensionRegistry notifications.
18 class TestExtensionRegistryObserver : public ExtensionRegistryObserver {
19 public:
20 // If |extension_id| is provided, listens only to events relating to that
21 // extension. Otherwise, listens to all events.
22 explicit TestExtensionRegistryObserver(ExtensionRegistry* registry);
23 TestExtensionRegistryObserver(ExtensionRegistry* registry,
24 const std::string& extension_id);
26 ~TestExtensionRegistryObserver() override;
28 // Waits for the notification, and returns the extension that caused it.
29 const Extension* WaitForExtensionWillBeInstalled();
30 const Extension* WaitForExtensionUninstalled();
31 const Extension* WaitForExtensionLoaded();
32 const Extension* WaitForExtensionUnloaded();
34 private:
35 class Waiter;
37 // ExtensionRegistryObserver.
38 void OnExtensionWillBeInstalled(content::BrowserContext* browser_context,
39 const Extension* extension,
40 bool is_update,
41 bool from_ephemeral,
42 const std::string& old_name) override;
43 void OnExtensionUninstalled(content::BrowserContext* browser_context,
44 const Extension* extension,
45 extensions::UninstallReason reason) override;
46 void OnExtensionLoaded(content::BrowserContext* browser_context,
47 const Extension* extension) override;
48 void OnExtensionUnloaded(content::BrowserContext* browser_context,
49 const Extension* extension,
50 UnloadedExtensionInfo::Reason reason) override;
52 const Extension* Wait(scoped_ptr<Waiter>* waiter);
54 scoped_ptr<Waiter> will_be_installed_waiter_;
55 scoped_ptr<Waiter> uninstalled_waiter_;
56 scoped_ptr<Waiter> loaded_waiter_;
57 scoped_ptr<Waiter> unloaded_waiter_;
59 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
60 extension_registry_observer_;
62 std::string extension_id_;
64 DISALLOW_COPY_AND_ASSIGN(TestExtensionRegistryObserver);
67 } // namespace extensions
69 #endif // EXTENSIONS_BROWSER_TEST_EXTENSION_REGISTRY_OBSERVER_H_