summaryrefslogtreecommitdiffstats
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
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
-rw-r--r--chrome/browser/extensions/api/content_settings/content_settings_apitest.cc9
-rw-r--r--chrome/browser/extensions/api/preference/preference_apitest.cc9
-rw-r--r--chrome/browser/extensions/extension_storage_monitor_browsertest.cc9
-rw-r--r--chrome/chrome_tests.gypi2
-rw-r--r--extensions/DEPS1
-rw-r--r--extensions/browser/test_extension_registry_observer.cc103
-rw-r--r--extensions/browser/test_extension_registry_observer.h60
7 files changed, 181 insertions, 12 deletions
diff --git a/chrome/browser/extensions/api/content_settings/content_settings_apitest.cc b/chrome/browser/extensions/api/content_settings/content_settings_apitest.cc
index f50535a..a7fae5e 100644
--- a/chrome/browser/extensions/api/content_settings/content_settings_apitest.cc
+++ b/chrome/browser/extensions/api/content_settings/content_settings_apitest.cc
@@ -18,6 +18,8 @@
#include "content/public/browser/plugin_service.h"
#include "content/public/common/webplugininfo.h"
#include "content/public/test/test_utils.h"
+#include "extensions/browser/extension_registry.h"
+#include "extensions/browser/test_extension_registry_observer.h"
namespace {
@@ -196,11 +198,10 @@ IN_PROC_BROWSER_TEST_F(ExtensionContentSettingsApiTest, MAYBE_Standard) {
// Uninstalling and installing the extension (without running the test that
// calls the extension API) should clear the settings.
- content::WindowedNotificationObserver observer(
- chrome::NOTIFICATION_EXTENSION_UNINSTALLED_DEPRECATED,
- content::NotificationService::AllSources());
+ TestExtensionRegistryObserver observer(ExtensionRegistry::Get(profile()),
+ last_loaded_extension_id());
UninstallExtension(last_loaded_extension_id());
- observer.Wait();
+ observer.WaitForExtensionUninstalled();
CheckContentSettingsDefault();
LoadExtension(test_data_dir_.AppendASCII(kExtensionPath));
diff --git a/chrome/browser/extensions/api/preference/preference_apitest.cc b/chrome/browser/extensions/api/preference/preference_apitest.cc
index ca6d323..29fdcbc 100644
--- a/chrome/browser/extensions/api/preference/preference_apitest.cc
+++ b/chrome/browser/extensions/api/preference/preference_apitest.cc
@@ -15,6 +15,8 @@
#include "chrome/test/base/ui_test_utils.h"
#include "components/translate/core/common/translate_pref_names.h"
#include "content/public/browser/notification_service.h"
+#include "extensions/browser/extension_registry.h"
+#include "extensions/browser/test_extension_registry_observer.h"
namespace {
@@ -122,11 +124,10 @@ IN_PROC_BROWSER_TEST_F(ExtensionPreferenceApiTest, MAYBE_Standard) {
// Uninstalling and installing the extension (without running the test that
// calls the extension API) should clear the settings.
- content::WindowedNotificationObserver observer(
- chrome::NOTIFICATION_EXTENSION_UNINSTALLED_DEPRECATED,
- content::NotificationService::AllSources());
+ extensions::TestExtensionRegistryObserver observer(
+ extensions::ExtensionRegistry::Get(profile_), last_loaded_extension_id());
UninstallExtension(last_loaded_extension_id());
- observer.Wait();
+ observer.WaitForExtensionUninstalled();
CheckPreferencesCleared();
LoadExtension(test_data_dir_.AppendASCII(kExtensionPath));
diff --git a/chrome/browser/extensions/extension_storage_monitor_browsertest.cc b/chrome/browser/extensions/extension_storage_monitor_browsertest.cc
index 1c32600..c71fa4f 100644
--- a/chrome/browser/extensions/extension_storage_monitor_browsertest.cc
+++ b/chrome/browser/extensions/extension_storage_monitor_browsertest.cc
@@ -13,7 +13,9 @@
#include "chrome/browser/ui/extensions/application_launch.h"
#include "content/public/test/test_utils.h"
#include "extensions/browser/extension_prefs.h"
+#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
+#include "extensions/browser/test_extension_registry_observer.h"
#include "ui/message_center/message_center.h"
#include "ui/message_center/message_center_observer.h"
@@ -332,11 +334,10 @@ IN_PROC_BROWSER_TEST_F(ExtensionStorageMonitorTest, UninstallExtension) {
ExtensionStorageMonitor::BUTTON_UNINSTALL);
// Also fake accepting the uninstall.
- content::WindowedNotificationObserver uninstalled_signal(
- chrome::NOTIFICATION_EXTENSION_UNINSTALLED_DEPRECATED,
- content::Source<Profile>(profile()));
+ TestExtensionRegistryObserver observer(ExtensionRegistry::Get(profile()),
+ extension->id());
SimulateUninstallDialogAccept();
- uninstalled_signal.Wait();
+ observer.WaitForExtensionUninstalled();
}
} // namespace extensions
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index 89ae9c2..1a84175 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -856,6 +856,8 @@
'../apps/load_and_launch_browsertest.cc',
'../extensions/browser/api/usb/usb_apitest.cc',
'../extensions/browser/api/usb/usb_manual_apitest.cc',
+ '../extensions/browser/test_extension_registry_observer.h',
+ '../extensions/browser/test_extension_registry_observer.cc',
'../extensions/renderer/script_context_browsertest.cc',
# TODO(blundell): Bring up a components_browsertests target and move
# this test to be in that target. crbug.com/283846
diff --git a/extensions/DEPS b/extensions/DEPS
index e3000b6..3e4f6ad 100644
--- a/extensions/DEPS
+++ b/extensions/DEPS
@@ -1,6 +1,7 @@
include_rules = [
"+components/url_matcher",
"+content/public/common",
+ "+content/public/test",
"+crypto",
"+grit/extensions_renderer_resources.h",
"+grit/extensions_resources.h",
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_