| Index: ui/views/cocoa/bridged_native_widget_unittest.mm
|
| diff --git a/ui/views/cocoa/bridged_native_widget_unittest.mm b/ui/views/cocoa/bridged_native_widget_unittest.mm
|
| index 5d428c0652b2d5233fde1456533907da8c935cf0..a5c551066d93875c10f94444aec1943c99362a3e 100644
|
| --- a/ui/views/cocoa/bridged_native_widget_unittest.mm
|
| +++ b/ui/views/cocoa/bridged_native_widget_unittest.mm
|
| @@ -5,6 +5,7 @@
|
| #import "ui/views/cocoa/bridged_native_widget.h"
|
|
|
| #import <Cocoa/Cocoa.h>
|
| +#import <Quartz/Quartz.h>
|
|
|
| #import "base/mac/foundation_util.h"
|
| #import "base/mac/mac_util.h"
|
| @@ -15,10 +16,12 @@
|
| #include "base/strings/sys_string_conversions.h"
|
| #include "base/strings/utf_string_conversions.h"
|
| #import "testing/gtest_mac.h"
|
| +#import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSBezierPath+CGPath.h"
|
| #import "ui/base/cocoa/window_size_constants.h"
|
| #include "ui/base/ime/input_method.h"
|
| #import "ui/gfx/test/ui_cocoa_test_helper.h"
|
| #import "ui/gfx/mac/coordinate_conversion.h"
|
| +#include "ui/views/bubble/bubble_delegate.h"
|
| #import "ui/views/cocoa/bridged_content_view.h"
|
| #import "ui/views/cocoa/native_widget_mac_nswindow.h"
|
| #import "ui/views/cocoa/views_nswindow_delegate.h"
|
| @@ -161,10 +164,8 @@ class BridgedNativeWidgetTestBase : public ui::CocoaTest {
|
| return native_widget_mac_->bridge();
|
| }
|
|
|
| - // Overridden from testing::Test:
|
| - void SetUp() override {
|
| - ui::CocoaTest::SetUp();
|
| -
|
| + // Can be overriden in derived classes to provide additional |init_params_|.
|
| + virtual void InitParams() {
|
| init_params_.native_widget = native_widget_mac_;
|
|
|
| // Use a frameless window, otherwise Widget will try to center the window
|
| @@ -179,7 +180,12 @@ class BridgedNativeWidgetTestBase : public ui::CocoaTest {
|
| init_params_.opacity = Widget::InitParams::OPAQUE_WINDOW;
|
|
|
| init_params_.bounds = gfx::Rect(100, 100, 100, 100);
|
| + }
|
|
|
| + // Overridden from testing::Test:
|
| + void SetUp() override {
|
| + ui::CocoaTest::SetUp();
|
| + InitParams();
|
| native_widget_mac_->GetWidget()->Init(init_params_);
|
| }
|
|
|
| @@ -208,6 +214,9 @@ class BridgedNativeWidgetTest : public BridgedNativeWidgetTestBase {
|
| // Returns the current text as std::string.
|
| std::string GetText();
|
|
|
| + // Returns the mask layer associated with bridge().
|
| + CAShapeLayer* GetMaskLayer();
|
| +
|
| // testing::Test:
|
| void SetUp() override;
|
| void TearDown() override;
|
| @@ -257,6 +266,11 @@ std::string BridgedNativeWidgetTest::GetText() {
|
| return SysNSStringToUTF8([text string]);
|
| }
|
|
|
| +CAShapeLayer* BridgedNativeWidgetTest::GetMaskLayer() {
|
| + return base::mac::ObjCCastStrict<CAShapeLayer>(
|
| + [[bridge()->compositor_superview_ layer] mask]);
|
| +}
|
| +
|
| void BridgedNativeWidgetTest::SetUp() {
|
| BridgedNativeWidgetTestBase::SetUp();
|
|
|
| @@ -274,6 +288,8 @@ void BridgedNativeWidgetTest::SetUp() {
|
| bridge()->SetRootView(view_.get());
|
| ns_view_ = bridge()->ns_view();
|
|
|
| + bridge()->AddCompositorSuperview();
|
| +
|
| // Pretend it has been shown via NativeWidgetMac::Show().
|
| [window orderFront:nil];
|
| [test_window() makePretendKeyWindowAndSetFirstResponder:bridge()->ns_view()];
|
| @@ -751,5 +767,45 @@ TEST_F(BridgedNativeWidgetSimulateFullscreenTest, FailToEnterAndExit) {
|
| widget_->CloseNow();
|
| }
|
|
|
| +TEST_F(BridgedNativeWidgetTest, NoMaskLayer) {
|
| + // BridgedNativeWidgetTest creates a frameless window which does not have a
|
| + // non-client view. Hence it shouldn't have a mask layer.
|
| + EXPECT_FALSE(GetMaskLayer());
|
| +}
|
| +
|
| +// This class provides a bubble delegate to the widget, which has a non-empty
|
| +// window mask.
|
| +class BridgedNativeWidgetMaskTest : public BridgedNativeWidgetTest {
|
| + public:
|
| + void InitParams() override {
|
| + BridgedNativeWidgetTest::InitParams();
|
| + init_params_.type = Widget::InitParams::TYPE_BUBBLE;
|
| + init_params_.delegate = new BubbleDelegateView();
|
| + }
|
| +};
|
| +
|
| +TEST_F(BridgedNativeWidgetMaskTest, MaskLayer) {
|
| + CAShapeLayer* mask_layer = GetMaskLayer();
|
| + EXPECT_TRUE(mask_layer);
|
| + EXPECT_TRUE([mask_layer path]);
|
| + EXPECT_TRUE(
|
| + CGPathEqualToPath([[ns_view_ windowMask] gtm_CGPath], [mask_layer path]));
|
| +
|
| + CGPathRef prev_path = [mask_layer path];
|
| +
|
| + // Resize the window and ensure the mask path changes accordingly.
|
| + const int kTestNewWidth = 400;
|
| + const int kTestNewHeight = 300;
|
| + NSRect new_frame = NSMakeRect(0, 0, kTestNewWidth, kTestNewHeight);
|
| + EXPECT_NSNE(new_frame, [test_window() frame]);
|
| + [test_window() setFrame:new_frame display:NO];
|
| + mask_layer = GetMaskLayer();
|
| +
|
| + EXPECT_FALSE(CGPathEqualToPath(prev_path, [mask_layer path]));
|
| + EXPECT_TRUE([mask_layer path]);
|
| + EXPECT_TRUE(
|
| + CGPathEqualToPath([[ns_view_ windowMask] gtm_CGPath], [mask_layer path]));
|
| +}
|
| +
|
| } // namespace test
|
| } // namespace views
|
|
|