Commit 72400ac7 authored by Robert Liao's avatar Robert Liao Committed by Commit Bot

Implement BrowserActionInteractiveTest::WaitForPopup() for Views

A proper WaitForPopup() is necessary to observe when the ExtensionPopup
appears instead of using a content notification heuristic.

BUG=818397

Change-Id: I52e28711de32671329b468844dae420be943f6fd
Reviewed-on: https://chromium-review.googlesource.com/953258
Commit-Queue: Robert Liao <robliao@chromium.org>
Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Reviewed-by: default avatarElly Fong-Jones <ellyjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#542021}
parent fa4f6f47
...@@ -3899,21 +3899,26 @@ static_library("test_support") { ...@@ -3899,21 +3899,26 @@ static_library("test_support") {
"extensions/browser_action_test_util.h", "extensions/browser_action_test_util.h",
"views/payments/test_chrome_payment_request_delegate.cc", "views/payments/test_chrome_payment_request_delegate.cc",
"views/payments/test_chrome_payment_request_delegate.h", "views/payments/test_chrome_payment_request_delegate.h",
"views/toolbar/browser_action_test_util_views_mac.mm",
] ]
if (!is_mac || mac_views_browser) { if (!is_mac || mac_views_browser) {
sources += [ sources += [
"views/find_bar_host_unittest_util_views.cc", "views/find_bar_host_unittest_util_views.cc",
"views/toolbar/browser_action_test_util_views.cc", "views/toolbar/browser_action_test_util_views.cc",
] ]
if (!is_mac) {
deps += [ "//ui/aura" ]
}
} else { } else {
sources += [ sources += [
"cocoa/extensions/browser_action_test_util_views_cocoa.mm", "cocoa/extensions/browser_action_test_util_views_cocoa.mm",
"cocoa/find_bar/find_bar_host_unittest_util_cocoa.mm", "cocoa/find_bar/find_bar_host_unittest_util_cocoa.mm",
] ]
} }
if (use_aura) {
sources += [ "views/toolbar/browser_action_test_util_views_aura.cc" ]
deps += [
"//ui/aura",
"//ui/wm",
]
}
} }
if (!is_android) { if (!is_android) {
......
...@@ -28,7 +28,6 @@ ...@@ -28,7 +28,6 @@
#include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h"
#include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h"
#include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_constants.h"
#import "ui/base/test/windowed_nsnotification_observer.h"
#include "ui/base/theme_provider.h" #include "ui/base/theme_provider.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size.h"
...@@ -248,23 +247,6 @@ gfx::NativeView BrowserActionTestUtil::GetPopupNativeView() { ...@@ -248,23 +247,6 @@ gfx::NativeView BrowserActionTestUtil::GetPopupNativeView() {
return popup_owner ? popup_owner->GetPopupNativeView() : nil; return popup_owner ? popup_owner->GetPopupNativeView() : nil;
} }
bool BrowserActionTestUtil::WaitForPopup() {
NSWindow* window = [GetPopupNativeView() window];
if (!window)
return false;
if ([window isKeyWindow])
return true;
base::scoped_nsobject<WindowedNSNotificationObserver> waiter(
[[WindowedNSNotificationObserver alloc]
initForNotification:NSWindowDidBecomeKeyNotification
object:window]);
BOOL notification_observed = [waiter wait];
return notification_observed && [window isKeyWindow];
}
bool BrowserActionTestUtil::HasPopup() { bool BrowserActionTestUtil::HasPopup() {
return GetPopupNativeView() != nil; return GetPopupNativeView() != nil;
} }
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
#include "chrome/browser/ui/views/toolbar/browser_actions_container.h" #include "chrome/browser/ui/views/toolbar/browser_actions_container.h"
#include "chrome/browser/ui/views/toolbar/toolbar_action_view.h" #include "chrome/browser/ui/views/toolbar/toolbar_action_view.h"
#include "chrome/browser/ui/views/toolbar/toolbar_view.h" #include "chrome/browser/ui/views/toolbar/toolbar_view.h"
#include "ui/aura/window.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size.h"
#include "ui/gfx/image/image.h" #include "ui/gfx/image/image.h"
...@@ -153,12 +152,6 @@ gfx::NativeView BrowserActionTestUtil::GetPopupNativeView() { ...@@ -153,12 +152,6 @@ gfx::NativeView BrowserActionTestUtil::GetPopupNativeView() {
return popup_owner ? popup_owner->GetPopupNativeView() : nullptr; return popup_owner ? popup_owner->GetPopupNativeView() : nullptr;
} }
bool BrowserActionTestUtil::WaitForPopup() {
// TODO(tapted): Implement this for MacViews.
NOTIMPLEMENTED();
return HasPopup();
}
bool BrowserActionTestUtil::HasPopup() { bool BrowserActionTestUtil::HasPopup() {
return GetPopupNativeView() != nullptr; return GetPopupNativeView() != nullptr;
} }
......
// Copyright 2018 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 "chrome/browser/ui/extensions/browser_action_test_util.h"
#include "base/logging.h"
#include "base/run_loop.h"
#include "ui/aura/client/window_types.h"
#include "ui/aura/window.h"
#include "ui/aura/window_observer.h"
#include "ui/wm/core/window_util.h"
namespace {
aura::Window* GetPopupAuraWindow(aura::Window* current) {
DCHECK(current);
while (current && (current->type() != aura::client::WINDOW_TYPE_POPUP))
current = current->parent();
return current;
}
class AuraWindowObserver : public aura::WindowObserver {
public:
AuraWindowObserver(const aura::Window* popup_window, base::RunLoop* run_loop)
: popup_window_(popup_window), run_loop_(run_loop) {}
// aura::WindowObserver:
void OnWindowVisibilityChanged(aura::Window* window, bool visible) override {
if (popup_window_ == window && visible)
run_loop_->QuitWhenIdle();
}
private:
const aura::Window* const popup_window_;
base::RunLoop* const run_loop_;
DISALLOW_COPY_AND_ASSIGN(AuraWindowObserver);
};
} // namespace
bool BrowserActionTestUtil::WaitForPopup() {
// The popup starts out active but invisible, so all we need to really do is
// look for visibility.
aura::Window* native_view = GetPopupNativeView();
if (!native_view)
return false;
aura::Window* popup = GetPopupAuraWindow(native_view);
if (!popup)
return false;
if (popup->IsVisible())
return true;
base::RunLoop run_loop;
AuraWindowObserver observer(popup, &run_loop);
popup->AddObserver(&observer);
run_loop.Run();
DCHECK(wm::IsActiveWindow(popup));
popup->RemoveObserver(&observer);
return HasPopup();
}
// Copyright 2018 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 "chrome/browser/ui/extensions/browser_action_test_util.h"
#include <AppKit/AppKit.h>
#import "base/mac/scoped_nsobject.h"
#import "ui/base/test/windowed_nsnotification_observer.h"
bool BrowserActionTestUtil::WaitForPopup() {
NSWindow* window = [GetPopupNativeView() window];
if (!window)
return false;
if ([window isKeyWindow])
return true;
base::scoped_nsobject<WindowedNSNotificationObserver> waiter(
[[WindowedNSNotificationObserver alloc]
initForNotification:NSWindowDidBecomeKeyNotification
object:window]);
BOOL notification_observed = [waiter wait];
return notification_observed && [window isKeyWindow];
}
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