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

Unified 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: Y and B comments. 2014 brazil world cup morning at 6AM korea vs russia 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 side-by-side diff with in-line comments
Download patch
« extensions/DEPS ('K') | « extensions/browser/test_extension_registry_observer.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/browser/test_extension_registry_observer.cc
diff --git a/extensions/browser/test_extension_registry_observer.cc b/extensions/browser/test_extension_registry_observer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6db7fa12401d75eeb9f25a6ed099252fd5668bc7
--- /dev/null
+++ b/extensions/browser/test_extension_registry_observer.cc
@@ -0,0 +1,105 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "extensions/browser/test_extension_registry_observer.h"
+
+#include "base/run_loop.h"
+#include "extensions/browser/extension_registry.h"
+
+namespace extensions {
+
+class TestExtensionRegistryObserver::Waiter {
+ public:
+ Waiter() : observed_(false), runner_(NULL), extension_id_(std::string()) {}
+
+ void Wait(const std::string& id) {
+ if (observed_ && extension_id_ == id)
+ return;
+
+ extension_id_ = id;
+ runner_ = new content::MessageLoopRunner();
+ runner_->Run();
+ }
+
+ void OnObserved(const std::string& id) {
+ observed_ = true;
+ extension_id_ = id;
+
+ if (runner_) {
+ runner_->Quit();
+ runner_ = NULL;
+ }
+ }
+
+ private:
+ bool observed_;
+ scoped_refptr<content::MessageLoopRunner> runner_;
+
+ std::string extension_id_;
+
+ DISALLOW_COPY_AND_ASSIGN(Waiter);
+};
+
+TestExtensionRegistryObserver::TestExtensionRegistryObserver(
+ ExtensionRegistry* registry)
+ : will_be_installed_waiter_(new Waiter()),
Yoyo Zhou 2014/06/17 18:15:37 Do we need to instantiate all these if they're not
Yoyo Zhou 2014/06/17 21:48:06 Ah, I see what you mean. Right now there is a fla
limasdf 2014/06/19 18:06:28 Done.
+ uninstalled_waiter_(new Waiter()),
+ loaded_waiter_(new Waiter()),
+ unloaded_waiter_(new Waiter()),
+ extension_registry_observer_(this) {
+ extension_registry_observer_.Add(registry);
+}
+
+TestExtensionRegistryObserver::~TestExtensionRegistryObserver() {
+}
+
+void TestExtensionRegistryObserver::WaitForExtensionUninstalled(
+ const std::string& extension_id) {
+ uninstalled_waiter_->Wait(extension_id);
+}
+
+void TestExtensionRegistryObserver::WaitForExtensionWillBeInstalled(
+ const std::string& extension_id) {
+ will_be_installed_waiter_->Wait(extension_id);
+}
+
+void TestExtensionRegistryObserver::WaitForExtensionLoaded(
+ const std::string& extension_id) {
+ loaded_waiter_->Wait(extension_id);
+}
+
+void TestExtensionRegistryObserver::WaitForExtensionUnloaded(
+ const std::string& extension_id) {
+ unloaded_waiter_->Wait(extension_id);
+}
+
+void TestExtensionRegistryObserver::OnExtensionWillBeInstalled(
+ content::BrowserContext* browser_context,
+ const Extension* extension,
+ bool is_update,
+ bool from_ephemeral,
+ const std::string& old_name) {
+ will_be_installed_waiter_->OnObserved(extension->id());
+}
+
+void TestExtensionRegistryObserver::OnExtensionUninstalled(
+ content::BrowserContext* browser_context,
+ const Extension* extension) {
+ uninstalled_waiter_->OnObserved(extension->id());
+}
+
+void TestExtensionRegistryObserver::OnExtensionLoaded(
+ content::BrowserContext* browser_context,
+ const Extension* extension) {
+ loaded_waiter_->OnObserved(extension->id());
+}
+
+void TestExtensionRegistryObserver::OnExtensionUnloaded(
+ content::BrowserContext* browser_context,
+ const Extension* extension,
+ UnloadedExtensionInfo::Reason reason) {
+ unloaded_waiter_->OnObserved(extension->id());
+}
+
+} // namespace extensions
« extensions/DEPS ('K') | « 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