Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(400)

Side by Side Diff: extensions/browser/test_extension_registry_observer.cc

Issue 334083002: Add a test helper class for ExtensionRegistry. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove failed test to fix later Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « extensions/browser/test_extension_registry_observer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "extensions/browser/test_extension_registry_observer.h"
6
7 #include "content/public/test/test_utils.h"
8 #include "extensions/browser/extension_registry.h"
9
10 namespace extensions {
11
12 class TestExtensionRegistryObserver::Waiter {
13 public:
14 Waiter(const std::string& extension_id) : observed_(false), runner_(NULL) {}
15
16 void Wait() {
17 if (observed_)
18 return;
19
20 runner_ = new content::MessageLoopRunner();
21 runner_->Run();
22 }
23
24 void OnObserved() {
25 observed_ = true;
26
27 if (runner_) {
28 runner_->Quit();
29 runner_ = NULL;
30 }
31 }
32
33 private:
34 bool observed_;
35 scoped_refptr<content::MessageLoopRunner> runner_;
36
37 DISALLOW_COPY_AND_ASSIGN(Waiter);
38 };
39
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);
50 }
51
52 TestExtensionRegistryObserver::~TestExtensionRegistryObserver() {
53 }
54
55 void TestExtensionRegistryObserver::WaitForExtensionUninstalled() {
56 uninstalled_waiter_->Wait();
57 }
58
59 void TestExtensionRegistryObserver::WaitForExtensionWillBeInstalled() {
60 will_be_installed_waiter_->Wait();
61 }
62
63 void TestExtensionRegistryObserver::WaitForExtensionLoaded() {
64 loaded_waiter_->Wait();
65 }
66
67 void TestExtensionRegistryObserver::WaitForExtensionUnloaded() {
68 unloaded_waiter_->Wait();
69 }
70
71 void TestExtensionRegistryObserver::OnExtensionWillBeInstalled(
72 content::BrowserContext* browser_context,
73 const Extension* extension,
74 bool is_update,
75 bool from_ephemeral,
76 const std::string& old_name) {
77 if (extension->id() == extension_id_)
78 will_be_installed_waiter_->OnObserved();
79 }
80
81 void TestExtensionRegistryObserver::OnExtensionUninstalled(
82 content::BrowserContext* browser_context,
83 const Extension* extension) {
84 if (extension->id() == extension_id_)
85 uninstalled_waiter_->OnObserved();
86 }
87
88 void TestExtensionRegistryObserver::OnExtensionLoaded(
89 content::BrowserContext* browser_context,
90 const Extension* extension) {
91 if (extension->id() == extension_id_)
92 loaded_waiter_->OnObserved();
93 }
94
95 void TestExtensionRegistryObserver::OnExtensionUnloaded(
96 content::BrowserContext* browser_context,
97 const Extension* extension,
98 UnloadedExtensionInfo::Reason reason) {
99 if (extension->id() == extension_id_)
100 unloaded_waiter_->OnObserved();
101 }
102
103 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/test_extension_registry_observer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698