Commit 2ce645a7 authored by rdevlin.cronin's avatar rdevlin.cronin Committed by Commit bot

[Extensions] Move [Chrome]ExtensionTestNotificationObserver into extensions::

Move the ChromeExtensionTestNotificationObserver and
ExtensionTestNotificationObserver classes into the extensions namespace.

BUG=None
TBR=stevenjb@chromium.org

Review-Url: https://codereview.chromium.org/2539623002
Cr-Commit-Position: refs/heads/master@{#435537}
parent 914fa1f1
......@@ -129,7 +129,7 @@ void DriveFirstRunTest::InstallApp() {
extensions::CrxInstaller::CreateSilent(extension_service);
installer->InstallCrx(test_data_dir_.AppendASCII(kTestAppCrxName));
ChromeExtensionTestNotificationObserver observer(browser());
extensions::ChromeExtensionTestNotificationObserver observer(browser());
observer.WaitForExtensionLoad();
ASSERT_TRUE(extension_service->GetExtensionById(kTestAppId, false));
......
......@@ -766,7 +766,8 @@ IN_PROC_BROWSER_TEST_F(MergeSessionTest, XHRThrottle) {
// Reset ExtensionBrowserTest::observer_ to the right browser object.
Browser* browser = FindOrCreateVisibleBrowser(profile());
observer_.reset(new ChromeExtensionTestNotificationObserver(browser));
observer_.reset(
new extensions::ChromeExtensionTestNotificationObserver(browser));
// Run background page tests. The tests will just wait for XHR request
// to complete.
......
......@@ -211,7 +211,7 @@ class SigninExtensionsDeviceCloudPolicyBrowserTest
extensions::ExtensionSystem::Get(signin_profile)->extension_service();
scoped_refptr<extensions::UnpackedInstaller> installer(
extensions::UnpackedInstaller::Create(service));
ExtensionTestNotificationObserver observer(signin_profile);
extensions::ExtensionTestNotificationObserver observer(signin_profile);
installer->Load(GetTestExtensionSourcePath());
observer.WaitForExtensionLoad();
return GetTestExtension();
......
......@@ -15,7 +15,7 @@
#include "extensions/browser/process_manager.h"
#include "extensions/common/extension.h"
using extensions::Extension;
namespace extensions {
namespace {
......@@ -26,14 +26,13 @@ using ConditionCallback = base::Callback<bool(void)>;
bool HasPageActionVisibilityReachedTarget(
Browser* browser,
size_t target_visible_page_action_count) {
return extensions::extension_action_test_util::GetVisiblePageActionCount(
return extension_action_test_util::GetVisiblePageActionCount(
browser->tab_strip_model()->GetActiveWebContents()) ==
target_visible_page_action_count;
}
bool HaveAllExtensionRenderFrameHostsFinishedLoading(
extensions::ProcessManager* manager) {
extensions::ProcessManager::FrameSet all_views = manager->GetAllFrames();
bool HaveAllExtensionRenderFrameHostsFinishedLoading(ProcessManager* manager) {
ProcessManager::FrameSet all_views = manager->GetAllFrames();
for (content::RenderFrameHost* host : manager->GetAllFrames()) {
if (content::WebContents::FromRenderFrameHost(host)->IsLoading())
return false;
......@@ -72,18 +71,16 @@ ChromeExtensionTestNotificationObserver::GetBrowserContext() {
bool ChromeExtensionTestNotificationObserver::
WaitForPageActionVisibilityChangeTo(int count) {
DCHECK(browser_);
ScopedObserver<extensions::ExtensionActionAPI,
extensions::ExtensionActionAPI::Observer>
observer(this);
observer.Add(extensions::ExtensionActionAPI::Get(GetBrowserContext()));
ScopedObserver<ExtensionActionAPI, ExtensionActionAPI::Observer> observer(
this);
observer.Add(ExtensionActionAPI::Get(GetBrowserContext()));
WaitForCondition(
base::Bind(&HasPageActionVisibilityReachedTarget, browser_, count), NULL);
return true;
}
bool ChromeExtensionTestNotificationObserver::WaitForExtensionViewsToLoad() {
extensions::ProcessManager* manager =
extensions::ProcessManager::Get(GetBrowserContext());
ProcessManager* manager = ProcessManager::Get(GetBrowserContext());
NotificationSet notification_set;
notification_set.Add(content::NOTIFICATION_WEB_CONTENTS_DESTROYED);
notification_set.Add(content::NOTIFICATION_LOAD_STOP);
......@@ -98,9 +95,9 @@ bool ChromeExtensionTestNotificationObserver::WaitForExtensionIdle(
const std::string& extension_id) {
NotificationSet notification_set;
notification_set.Add(content::NOTIFICATION_RENDERER_PROCESS_TERMINATED);
WaitForCondition(base::Bind(&extensions::util::IsExtensionIdle, extension_id,
GetBrowserContext()),
&notification_set);
WaitForCondition(
base::Bind(&util::IsExtensionIdle, extension_id, GetBrowserContext()),
&notification_set);
return true;
}
......@@ -111,8 +108,7 @@ bool ChromeExtensionTestNotificationObserver::WaitForExtensionNotIdle(
WaitForCondition(base::Bind(
[](const std::string& extension_id,
content::BrowserContext* context) -> bool {
return !extensions::util::IsExtensionIdle(extension_id,
context);
return !util::IsExtensionIdle(extension_id, context);
},
extension_id, GetBrowserContext()),
&notification_set);
......@@ -128,3 +124,5 @@ void ChromeExtensionTestNotificationObserver::OnPageActionsUpdated(
content::WebContents* web_contents) {
MaybeQuit();
}
} // namespace extensions
......@@ -17,11 +17,12 @@ namespace content {
class BrowserContext;
}
namespace extensions {
// Test helper class for observing extension-related events.
// TODO(devlin): This should be in the extensions namespace.
class ChromeExtensionTestNotificationObserver
: public ExtensionTestNotificationObserver,
public extensions::ExtensionActionAPI::Observer {
public ExtensionActionAPI::Observer {
public:
explicit ChromeExtensionTestNotificationObserver(Browser* browser);
explicit ChromeExtensionTestNotificationObserver(
......@@ -46,7 +47,7 @@ class ChromeExtensionTestNotificationObserver
private:
content::BrowserContext* GetBrowserContext();
// extensions::ExtensionActionAPI::Observer:
// ExtensionActionAPI::Observer:
void OnPageActionsUpdated(content::WebContents* contents) override;
Browser* browser_;
......@@ -54,4 +55,6 @@ class ChromeExtensionTestNotificationObserver
DISALLOW_COPY_AND_ASSIGN(ChromeExtensionTestNotificationObserver);
};
} // namespace extensions
#endif // CHROME_BROWSER_EXTENSIONS_CHROME_EXTENSION_TEST_NOTIFICATION_OBSERVER_H_
......@@ -147,7 +147,8 @@ void ExtensionBrowserTest::SetUpCommandLine(base::CommandLine* command_line) {
void ExtensionBrowserTest::SetUpOnMainThread() {
InProcessBrowserTest::SetUpOnMainThread();
observer_.reset(new ChromeExtensionTestNotificationObserver(browser()));
observer_.reset(
new extensions::ChromeExtensionTestNotificationObserver(browser()));
if (extension_service()->updater()) {
extension_service()->updater()->SetExtensionCacheForTesting(
test_extension_cache_.get());
......
......@@ -325,7 +325,8 @@ class ExtensionBrowserTest : virtual public InProcessBrowserTest {
// test_data/extensions.
base::FilePath test_data_dir_;
std::unique_ptr<ChromeExtensionTestNotificationObserver> observer_;
std::unique_ptr<extensions::ChromeExtensionTestNotificationObserver>
observer_;
private:
// Temporary directory for testing.
......
......@@ -58,7 +58,8 @@ Profile* ExtensionSettingsUIBrowserTest::GetProfile() {
void ExtensionSettingsUIBrowserTest::SetUpOnMainThread() {
WebUIBrowserTest::SetUpOnMainThread();
observer_.reset(new ChromeExtensionTestNotificationObserver(browser()));
observer_.reset(
new extensions::ChromeExtensionTestNotificationObserver(browser()));
}
void ExtensionSettingsUIBrowserTest::InstallGoodExtension() {
......
......@@ -60,7 +60,8 @@ class ExtensionSettingsUIBrowserTest : public WebUIBrowserTest {
const base::FilePath& path);
const extensions::Extension* InstallExtension(const base::FilePath& path);
std::unique_ptr<ChromeExtensionTestNotificationObserver> observer_;
std::unique_ptr<extensions::ChromeExtensionTestNotificationObserver>
observer_;
// The default profile to be used.
Profile* profile_;
......
......@@ -15,7 +15,7 @@
#include "extensions/browser/process_manager.h"
#include "extensions/common/extension.h"
using extensions::Extension;
namespace extensions {
namespace {
......@@ -25,9 +25,8 @@ using ConditionCallback = base::Callback<bool(void)>;
const Extension* GetNonTerminatedExtensions(const std::string& id,
content::BrowserContext* context) {
return extensions::ExtensionRegistry::Get(context)->GetExtensionById(
id, extensions::ExtensionRegistry::EVERYTHING &
~extensions::ExtensionRegistry::TERMINATED);
return ExtensionRegistry::Get(context)->GetExtensionById(
id, ExtensionRegistry::EVERYTHING & ~ExtensionRegistry::TERMINATED);
}
} // namespace
......@@ -50,7 +49,7 @@ void ExtensionTestNotificationObserver::NotificationSet::Add(int type) {
}
void ExtensionTestNotificationObserver::NotificationSet::
AddExtensionFrameUnregistration(extensions::ProcessManager* manager) {
AddExtensionFrameUnregistration(ProcessManager* manager) {
process_manager_observer_.Add(manager);
}
......@@ -95,19 +94,19 @@ void ExtensionTestNotificationObserver::WaitForNotification(
bool ExtensionTestNotificationObserver::WaitForExtensionInstallError() {
int before = extension_installs_observed_;
content::WindowedNotificationObserver(
extensions::NOTIFICATION_EXTENSION_INSTALL_ERROR,
NOTIFICATION_EXTENSION_INSTALL_ERROR,
content::NotificationService::AllSources())
.Wait();
return extension_installs_observed_ == before;
}
void ExtensionTestNotificationObserver::WaitForExtensionLoad() {
WaitForNotification(extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED);
WaitForNotification(NOTIFICATION_EXTENSION_LOADED_DEPRECATED);
}
bool ExtensionTestNotificationObserver::WaitForExtensionLoadError() {
int before = extension_load_errors_observed_;
WaitForNotification(extensions::NOTIFICATION_EXTENSION_LOAD_ERROR);
WaitForNotification(NOTIFICATION_EXTENSION_LOAD_ERROR);
return extension_load_errors_observed_ != before;
}
......@@ -119,7 +118,7 @@ bool ExtensionTestNotificationObserver::WaitForExtensionCrash(
}
content::WindowedNotificationObserver(
extensions::NOTIFICATION_EXTENSION_PROCESS_TERMINATED,
NOTIFICATION_EXTENSION_PROCESS_TERMINATED,
content::NotificationService::AllSources())
.Wait();
return (GetNonTerminatedExtensions(extension_id, context_) == NULL);
......@@ -127,7 +126,7 @@ bool ExtensionTestNotificationObserver::WaitForExtensionCrash(
bool ExtensionTestNotificationObserver::WaitForCrxInstallerDone() {
int before = crx_installers_done_observed_;
WaitForNotification(extensions::NOTIFICATION_CRX_INSTALLER_DONE);
WaitForNotification(NOTIFICATION_CRX_INSTALLER_DONE);
return crx_installers_done_observed_ == before + 1;
}
......@@ -151,13 +150,13 @@ void ExtensionTestNotificationObserver::Observe(
const content::NotificationSource& source,
const content::NotificationDetails& details) {
switch (type) {
case extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED:
case NOTIFICATION_EXTENSION_LOADED_DEPRECATED:
last_loaded_extension_id_ =
content::Details<const Extension>(details).ptr()->id();
VLOG(1) << "Got EXTENSION_LOADED notification.";
break;
case extensions::NOTIFICATION_CRX_INSTALLER_DONE:
case NOTIFICATION_CRX_INSTALLER_DONE:
VLOG(1) << "Got CRX_INSTALLER_DONE notification.";
{
const Extension* extension =
......@@ -170,7 +169,7 @@ void ExtensionTestNotificationObserver::Observe(
++crx_installers_done_observed_;
break;
case extensions::NOTIFICATION_EXTENSION_LOAD_ERROR:
case NOTIFICATION_EXTENSION_LOAD_ERROR:
VLOG(1) << "Got EXTENSION_LOAD_ERROR notification.";
++extension_load_errors_observed_;
break;
......@@ -207,3 +206,5 @@ void ExtensionTestNotificationObserver::MaybeQuit() {
if (condition_.Run())
quit_closure_.Run();
}
} // namespace extensions
......@@ -24,7 +24,6 @@ class WindowedNotificationObserver;
namespace extensions {
class ProcessManager;
}
// Test helper class for observing extension-related events.
class ExtensionTestNotificationObserver : public content::NotificationObserver {
......@@ -139,4 +138,6 @@ class ExtensionTestNotificationObserver : public content::NotificationObserver {
DISALLOW_COPY_AND_ASSIGN(ExtensionTestNotificationObserver);
};
} // namespace extensions
#endif // EXTENSIONS_TEST_EXTENSION_TEST_NOTIFICATION_OBSERVER_H_
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment