| Index: chrome/browser/extensions/extension_test_notification_observer.cc
|
| diff --git a/chrome/browser/extensions/extension_test_notification_observer.cc b/chrome/browser/extensions/extension_test_notification_observer.cc
|
| index 162d42190734f06ad9e9fc4bb385e4b7637026aa..fb8c7f7d8e590fa6d01033deaa654fb7bceb3538 100644
|
| --- a/chrome/browser/extensions/extension_test_notification_observer.cc
|
| +++ b/chrome/browser/extensions/extension_test_notification_observer.cc
|
| @@ -21,11 +21,12 @@ using extensions::Extension;
|
|
|
| namespace {
|
|
|
| -bool HasExtensionPageActionVisibilityReachedTarget(
|
| - LocationBarTesting* location_bar,
|
| - int target_visible_page_action_count) {
|
| - VLOG(1) << "Number of visible page actions: "
|
| - << location_bar->PageActionVisibleCount();
|
| +// A callback that returns true if the condition has been met and takes no
|
| +// arguments.
|
| +typedef base::Callback<bool(void)> ConditionCallback;
|
| +
|
| +bool HasPageActionVisibilityReachedTarget(
|
| + LocationBarTesting* location_bar, int target_visible_page_action_count) {
|
| return location_bar->PageActionVisibleCount() ==
|
| target_visible_page_action_count;
|
| }
|
| @@ -42,7 +43,13 @@ bool HaveAllExtensionRenderViewHostsFinishedLoading(
|
| return true;
|
| }
|
|
|
| -class NotificationSet : public content::NotificationObserver {
|
| +} // namespace
|
| +
|
| +////////////////////////////////////////////////////////////////////////////////
|
| +// ExtensionTestNotificationObserver::NotificationSet
|
| +
|
| +class ExtensionTestNotificationObserver::NotificationSet
|
| + : public content::NotificationObserver {
|
| public:
|
| void Add(int type, const content::NotificationSource& source);
|
| void Add(int type);
|
| @@ -63,52 +70,25 @@ class NotificationSet : public content::NotificationObserver {
|
| base::CallbackList<void()> callback_list_;
|
| };
|
|
|
| -void NotificationSet::Add(
|
| +void ExtensionTestNotificationObserver::NotificationSet::Add(
|
| int type,
|
| const content::NotificationSource& source) {
|
| notification_registrar_.Add(this, type, source);
|
| }
|
|
|
| -void NotificationSet::Add(int type) {
|
| +void ExtensionTestNotificationObserver::NotificationSet::Add(int type) {
|
| Add(type, content::NotificationService::AllSources());
|
| }
|
|
|
| -void NotificationSet::Observe(
|
| +void ExtensionTestNotificationObserver::NotificationSet::Observe(
|
| int type,
|
| const content::NotificationSource& source,
|
| const content::NotificationDetails& details) {
|
| callback_list_.Notify();
|
| }
|
|
|
| -void MaybeQuit(content::MessageLoopRunner* runner,
|
| - const base::Callback<bool(void)>& condition) {
|
| - if (condition.Run())
|
| - runner->Quit();
|
| -}
|
| -
|
| -void WaitForCondition(
|
| - const base::Callback<bool(void)>& condition,
|
| - NotificationSet* notification_set) {
|
| - if (condition.Run())
|
| - return;
|
| -
|
| - scoped_refptr<content::MessageLoopRunner> runner(
|
| - new content::MessageLoopRunner);
|
| - scoped_ptr<base::CallbackList<void()>::Subscription> subscription =
|
| - notification_set->callback_list().Add(
|
| - base::Bind(&MaybeQuit, base::Unretained(runner.get()), condition));
|
| - runner->Run();
|
| -}
|
| -
|
| -void WaitForCondition(
|
| - const base::Callback<bool(void)>& condition,
|
| - int type) {
|
| - NotificationSet notification_set;
|
| - notification_set.Add(type);
|
| - WaitForCondition(condition, ¬ification_set);
|
| -}
|
| -
|
| -} // namespace
|
| +////////////////////////////////////////////////////////////////////////////////
|
| +// ExtensionTestNotificationObserver
|
|
|
| ExtensionTestNotificationObserver::ExtensionTestNotificationObserver(
|
| Browser* browser)
|
| @@ -147,10 +127,12 @@ bool ExtensionTestNotificationObserver::WaitForPageActionVisibilityChangeTo(
|
| int count) {
|
| LocationBarTesting* location_bar =
|
| browser_->window()->GetLocationBar()->GetLocationBarForTesting();
|
| + extensions::ExtensionActionAPI::Get(GetProfile())->AddObserver(this);
|
| WaitForCondition(
|
| - base::Bind(
|
| - &HasExtensionPageActionVisibilityReachedTarget, location_bar, count),
|
| - extensions::NOTIFICATION_EXTENSION_PAGE_ACTIONS_UPDATED);
|
| + base::Bind(&HasPageActionVisibilityReachedTarget, location_bar, count),
|
| + NULL);
|
| + extensions::ExtensionActionAPI::Get(GetProfile())->
|
| + RemoveObserver(this);
|
| return true;
|
| }
|
|
|
| @@ -271,3 +253,36 @@ void ExtensionTestNotificationObserver::Observe(
|
| break;
|
| }
|
| }
|
| +
|
| +void ExtensionTestNotificationObserver::OnPageActionsUpdated(
|
| + content::WebContents* web_contents) {
|
| + MaybeQuit();
|
| +}
|
| +
|
| +void ExtensionTestNotificationObserver::WaitForCondition(
|
| + const ConditionCallback& condition,
|
| + NotificationSet* notification_set) {
|
| + if (condition.Run())
|
| + return;
|
| + condition_ = condition;
|
| +
|
| + scoped_refptr<content::MessageLoopRunner> runner(
|
| + new content::MessageLoopRunner);
|
| + quit_closure_ = runner->QuitClosure();
|
| +
|
| + scoped_ptr<base::CallbackList<void()>::Subscription> subscription;
|
| + if (notification_set) {
|
| + subscription = notification_set->callback_list().Add(
|
| + base::Bind(&ExtensionTestNotificationObserver::MaybeQuit,
|
| + base::Unretained(this)));
|
| + }
|
| + runner->Run();
|
| +
|
| + condition_.Reset();
|
| + quit_closure_.Reset();
|
| +}
|
| +
|
| +void ExtensionTestNotificationObserver::MaybeQuit() {
|
| + if (condition_.Run())
|
| + quit_closure_.Run();
|
| +}
|
|
|