summaryrefslogtreecommitdiffstats
path: root/extensions/browser
diff options
context:
space:
mode:
authorlimasdf@gmail.com <limasdf@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-27 21:39:45 +0000
committerlimasdf@gmail.com <limasdf@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-27 21:39:45 +0000
commiteccbbb6912589f00943d866d03b14964edd0507d (patch)
treeaa795b32a7268d8999f8cd00760cdede8a09bdc6 /extensions/browser
parent0c3bcea1195537f9ba440443508f6231a8f2ec84 (diff)
downloadchromium_src-eccbbb6912589f00943d866d03b14964edd0507d.zip
chromium_src-eccbbb6912589f00943d866d03b14964edd0507d.tar.gz
chromium_src-eccbbb6912589f00943d866d03b14964edd0507d.tar.bz2
Add a test helper class for ExtensionRegistry.
And use it from c/e/b/extensions/. BUG=354046 R=yoz@chromium.org, thestig@chromium.org, kalman@chromium.org TEST=browser_tests Review URL: https://codereview.chromium.org/334083002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@280415 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'extensions/browser')
-rw-r--r--extensions/browser/test_extension_registry_observer.cc103
-rw-r--r--extensions/browser/test_extension_registry_observer.h60
2 files changed, 163 insertions, 0 deletions
diff --git a/extensions/browser/test_extension_registry_observer.cc b/extensions/browser/test_extension_registry_observer.cc
new file mode 100644
index 0000000..9982f2d
--- /dev/null
+++ b/extensions/browser/test_extension_registry_observer.cc
@@ -0,0 +1,103 @@
+// 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 "content/public/test/test_utils.h"
+#include "extensions/browser/extension_registry.h"
+
+namespace extensions {
+
+class TestExtensionRegistryObserver::Waiter {
+ public:
+ Waiter(const std::string& extension_id) : observed_(false), runner_(NULL) {}
+
+ void Wait() {
+ if (observed_)
+ return;
+
+ runner_ = new content::MessageLoopRunner();
+ runner_->Run();
+ }
+
+ void OnObserved() {
+ observed_ = true;
+
+ if (runner_) {
+ runner_->Quit();
+ runner_ = NULL;
+ }
+ }
+
+ private:
+ bool observed_;
+ scoped_refptr<content::MessageLoopRunner> runner_;
+
+ DISALLOW_COPY_AND_ASSIGN(Waiter);
+};
+
+TestExtensionRegistryObserver::TestExtensionRegistryObserver(
+ ExtensionRegistry* registry,
+ const std::string& extension_id)
+ : will_be_installed_waiter_(new Waiter(extension_id)),
+ uninstalled_waiter_(new Waiter(extension_id)),
+ loaded_waiter_(new Waiter(extension_id)),
+ unloaded_waiter_(new Waiter(extension_id)),
+ extension_registry_observer_(this),
+ extension_id_(extension_id) {
+ extension_registry_observer_.Add(registry);
+}
+
+TestExtensionRegistryObserver::~TestExtensionRegistryObserver() {
+}
+
+void TestExtensionRegistryObserver::WaitForExtensionUninstalled() {
+ uninstalled_waiter_->Wait();
+}
+
+void TestExtensionRegistryObserver::WaitForExtensionWillBeInstalled() {
+ will_be_installed_waiter_->Wait();
+}
+
+void TestExtensionRegistryObserver::WaitForExtensionLoaded() {
+ loaded_waiter_->Wait();
+}
+
+void TestExtensionRegistryObserver::WaitForExtensionUnloaded() {
+ unloaded_waiter_->Wait();
+}
+
+void TestExtensionRegistryObserver::OnExtensionWillBeInstalled(
+ content::BrowserContext* browser_context,
+ const Extension* extension,
+ bool is_update,
+ bool from_ephemeral,
+ const std::string& old_name) {
+ if (extension->id() == extension_id_)
+ will_be_installed_waiter_->OnObserved();
+}
+
+void TestExtensionRegistryObserver::OnExtensionUninstalled(
+ content::BrowserContext* browser_context,
+ const Extension* extension) {
+ if (extension->id() == extension_id_)
+ uninstalled_waiter_->OnObserved();
+}
+
+void TestExtensionRegistryObserver::OnExtensionLoaded(
+ content::BrowserContext* browser_context,
+ const Extension* extension) {
+ if (extension->id() == extension_id_)
+ loaded_waiter_->OnObserved();
+}
+
+void TestExtensionRegistryObserver::OnExtensionUnloaded(
+ content::BrowserContext* browser_context,
+ const Extension* extension,
+ UnloadedExtensionInfo::Reason reason) {
+ if (extension->id() == extension_id_)
+ unloaded_waiter_->OnObserved();
+}
+
+} // namespace extensions
diff --git a/extensions/browser/test_extension_registry_observer.h b/extensions/browser/test_extension_registry_observer.h
new file mode 100644
index 0000000..ce3beb0
--- /dev/null
+++ b/extensions/browser/test_extension_registry_observer.h
@@ -0,0 +1,60 @@
+// 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.
+
+#ifndef EXTENSIONS_BROWSER_TEST_EXTENSION_REGISTRY_OBSERVER_H_
+#define EXTENSIONS_BROWSER_TEST_EXTENSION_REGISTRY_OBSERVER_H_
+
+#include "base/scoped_observer.h"
+#include "extensions/browser/extension_registry_observer.h"
+
+namespace extensions {
+class ExtensionRegistry;
+
+// A helper class that listen for ExtensionRegistry notifications.
+class TestExtensionRegistryObserver : public ExtensionRegistryObserver {
+ public:
+ explicit TestExtensionRegistryObserver(ExtensionRegistry* registry,
+ const std::string& extension_id);
+ virtual ~TestExtensionRegistryObserver();
+
+ void WaitForExtensionWillBeInstalled();
+ void WaitForExtensionUninstalled();
+ void WaitForExtensionLoaded();
+ void WaitForExtensionUnloaded();
+
+ private:
+ class Waiter;
+
+ // ExtensionRegistryObserver.
+ virtual void OnExtensionWillBeInstalled(
+ content::BrowserContext* browser_context,
+ const Extension* extension,
+ bool is_update,
+ bool from_ephemeral,
+ const std::string& old_name) OVERRIDE;
+ virtual void OnExtensionUninstalled(content::BrowserContext* browser_context,
+ const Extension* extension) OVERRIDE;
+ virtual void OnExtensionLoaded(content::BrowserContext* browser_context,
+ const Extension* extension) OVERRIDE;
+ virtual void OnExtensionUnloaded(
+ content::BrowserContext* browser_context,
+ const Extension* extension,
+ UnloadedExtensionInfo::Reason reason) OVERRIDE;
+
+ scoped_ptr<Waiter> will_be_installed_waiter_;
+ scoped_ptr<Waiter> uninstalled_waiter_;
+ scoped_ptr<Waiter> loaded_waiter_;
+ scoped_ptr<Waiter> unloaded_waiter_;
+
+ ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
+ extension_registry_observer_;
+
+ std::string extension_id_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestExtensionRegistryObserver);
+};
+
+} // namespace extensions
+
+#endif // EXTENSIONS_BROWSER_TEST_EXTENSION_REGISTRY_OBSERVER_H_