| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "ui/views/cocoa/bridged_native_widget.h" | 5 #import "ui/views/cocoa/bridged_native_widget.h" |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 | 8 |
| 9 #import "base/mac/foundation_util.h" | 9 #import "base/mac/foundation_util.h" |
| 10 #import "base/mac/mac_util.h" | 10 #import "base/mac/mac_util.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 class MockNativeWidgetMac : public NativeWidgetMac { | 71 class MockNativeWidgetMac : public NativeWidgetMac { |
| 72 public: | 72 public: |
| 73 MockNativeWidgetMac(Widget* delegate) : NativeWidgetMac(delegate) {} | 73 MockNativeWidgetMac(Widget* delegate) : NativeWidgetMac(delegate) {} |
| 74 | 74 |
| 75 // Expose a reference, so that it can be reset() independently. | 75 // Expose a reference, so that it can be reset() independently. |
| 76 scoped_ptr<BridgedNativeWidget>& bridge() { | 76 scoped_ptr<BridgedNativeWidget>& bridge() { |
| 77 return bridge_; | 77 return bridge_; |
| 78 } | 78 } |
| 79 | 79 |
| 80 // internal::NativeWidgetPrivate: | 80 // internal::NativeWidgetPrivate: |
| 81 virtual void InitNativeWidget(const Widget::InitParams& params) override { | 81 void InitNativeWidget(const Widget::InitParams& params) override { |
| 82 ownership_ = params.ownership; | 82 ownership_ = params.ownership; |
| 83 | 83 |
| 84 // Usually the bridge gets initialized here. It is skipped to run extra | 84 // Usually the bridge gets initialized here. It is skipped to run extra |
| 85 // checks in tests, and so that a second window isn't created. | 85 // checks in tests, and so that a second window isn't created. |
| 86 delegate()->OnNativeWidgetCreated(true); | 86 delegate()->OnNativeWidgetCreated(true); |
| 87 } | 87 } |
| 88 | 88 |
| 89 virtual void ReorderNativeViews() override { | 89 void ReorderNativeViews() override { |
| 90 // Called via Widget::Init to set the content view. No-op in these tests. | 90 // Called via Widget::Init to set the content view. No-op in these tests. |
| 91 } | 91 } |
| 92 | 92 |
| 93 private: | 93 private: |
| 94 DISALLOW_COPY_AND_ASSIGN(MockNativeWidgetMac); | 94 DISALLOW_COPY_AND_ASSIGN(MockNativeWidgetMac); |
| 95 }; | 95 }; |
| 96 | 96 |
| 97 // Helper test base to construct a BridgedNativeWidget with a valid parent. | 97 // Helper test base to construct a BridgedNativeWidget with a valid parent. |
| 98 class BridgedNativeWidgetTestBase : public ui::CocoaTest { | 98 class BridgedNativeWidgetTestBase : public ui::CocoaTest { |
| 99 public: | 99 public: |
| 100 BridgedNativeWidgetTestBase() | 100 BridgedNativeWidgetTestBase() |
| 101 : widget_(new Widget), | 101 : widget_(new Widget), |
| 102 native_widget_mac_(new MockNativeWidgetMac(widget_.get())) { | 102 native_widget_mac_(new MockNativeWidgetMac(widget_.get())) { |
| 103 } | 103 } |
| 104 | 104 |
| 105 scoped_ptr<BridgedNativeWidget>& bridge() { | 105 scoped_ptr<BridgedNativeWidget>& bridge() { |
| 106 return native_widget_mac_->bridge(); | 106 return native_widget_mac_->bridge(); |
| 107 } | 107 } |
| 108 | 108 |
| 109 // Overridden from testing::Test: | 109 // Overridden from testing::Test: |
| 110 virtual void SetUp() override { | 110 void SetUp() override { |
| 111 ui::CocoaTest::SetUp(); | 111 ui::CocoaTest::SetUp(); |
| 112 | 112 |
| 113 init_params_.native_widget = native_widget_mac_; | 113 init_params_.native_widget = native_widget_mac_; |
| 114 | 114 |
| 115 // To control the lifetime without an actual window that must be closed, | 115 // To control the lifetime without an actual window that must be closed, |
| 116 // tests in this file need to use WIDGET_OWNS_NATIVE_WIDGET. | 116 // tests in this file need to use WIDGET_OWNS_NATIVE_WIDGET. |
| 117 init_params_.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 117 init_params_.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 118 | 118 |
| 119 // Opacity defaults to "infer" which is usually updated by ViewsDelegate. | 119 // Opacity defaults to "infer" which is usually updated by ViewsDelegate. |
| 120 init_params_.opacity = Widget::InitParams::OPAQUE_WINDOW; | 120 init_params_.opacity = Widget::InitParams::OPAQUE_WINDOW; |
| 121 | 121 |
| 122 native_widget_mac_->GetWidget()->Init(init_params_); | 122 native_widget_mac_->GetWidget()->Init(init_params_); |
| 123 } | 123 } |
| 124 | 124 |
| 125 protected: | 125 protected: |
| 126 scoped_ptr<Widget> widget_; | 126 scoped_ptr<Widget> widget_; |
| 127 MockNativeWidgetMac* native_widget_mac_; // Weak. Owned by |widget_|. | 127 MockNativeWidgetMac* native_widget_mac_; // Weak. Owned by |widget_|. |
| 128 | 128 |
| 129 // Make the InitParams available to tests to cover initialization codepaths. | 129 // Make the InitParams available to tests to cover initialization codepaths. |
| 130 Widget::InitParams init_params_; | 130 Widget::InitParams init_params_; |
| 131 }; | 131 }; |
| 132 | 132 |
| 133 class BridgedNativeWidgetTest : public BridgedNativeWidgetTestBase { | 133 class BridgedNativeWidgetTest : public BridgedNativeWidgetTestBase { |
| 134 public: | 134 public: |
| 135 BridgedNativeWidgetTest(); | 135 BridgedNativeWidgetTest(); |
| 136 virtual ~BridgedNativeWidgetTest(); | 136 ~BridgedNativeWidgetTest() override; |
| 137 | 137 |
| 138 // Install a textfield in the view hierarchy and make it the text input | 138 // Install a textfield in the view hierarchy and make it the text input |
| 139 // client. | 139 // client. |
| 140 void InstallTextField(const std::string& text); | 140 void InstallTextField(const std::string& text); |
| 141 | 141 |
| 142 // Returns the current text as std::string. | 142 // Returns the current text as std::string. |
| 143 std::string GetText(); | 143 std::string GetText(); |
| 144 | 144 |
| 145 // testing::Test: | 145 // testing::Test: |
| 146 virtual void SetUp() override; | 146 void SetUp() override; |
| 147 virtual void TearDown() override; | 147 void TearDown() override; |
| 148 | 148 |
| 149 protected: | 149 protected: |
| 150 scoped_ptr<views::View> view_; | 150 scoped_ptr<views::View> view_; |
| 151 scoped_ptr<BridgedNativeWidget> bridge_; | 151 scoped_ptr<BridgedNativeWidget> bridge_; |
| 152 BridgedContentView* ns_view_; // Weak. Owned by bridge_. | 152 BridgedContentView* ns_view_; // Weak. Owned by bridge_. |
| 153 | 153 |
| 154 private: | 154 private: |
| 155 DISALLOW_COPY_AND_ASSIGN(BridgedNativeWidgetTest); | 155 DISALLOW_COPY_AND_ASSIGN(BridgedNativeWidgetTest); |
| 156 }; | 156 }; |
| 157 | 157 |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 [center postNotificationName:NSWindowDidExitFullScreenNotification | 499 [center postNotificationName:NSWindowDidExitFullScreenNotification |
| 500 object:window]; | 500 object:window]; |
| 501 EXPECT_EQ(1, [window ignoredToggleFullScreenCount]); // No change. | 501 EXPECT_EQ(1, [window ignoredToggleFullScreenCount]); // No change. |
| 502 EXPECT_FALSE(bridge()->target_fullscreen_state()); | 502 EXPECT_FALSE(bridge()->target_fullscreen_state()); |
| 503 | 503 |
| 504 widget_->CloseNow(); | 504 widget_->CloseNow(); |
| 505 } | 505 } |
| 506 | 506 |
| 507 } // namespace test | 507 } // namespace test |
| 508 } // namespace views | 508 } // namespace views |
| OLD | NEW |