Chromium Code Reviews| 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 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| 11 #import "base/mac/foundation_util.h" | 11 #import "base/mac/foundation_util.h" |
| 12 #import "base/mac/mac_util.h" | 12 #import "base/mac/mac_util.h" |
| 13 #import "base/mac/sdk_forward_declarations.h" | 13 #import "base/mac/sdk_forward_declarations.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 16 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
| 17 #include "base/strings/sys_string_conversions.h" | 17 #include "base/strings/sys_string_conversions.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
| 19 #import "testing/gtest_mac.h" | 19 #import "testing/gtest_mac.h" |
| 20 #import "ui/base/cocoa/window_size_constants.h" | 20 #import "ui/base/cocoa/window_size_constants.h" |
| 21 #include "ui/base/ime/input_method.h" | 21 #include "ui/base/ime/input_method.h" |
| 22 #include "ui/base/material_design/material_design_controller.h" | |
| 23 #include "ui/base/test/material_design_controller_test_api.h" | |
| 22 #include "ui/events/test/cocoa_test_event_utils.h" | 24 #include "ui/events/test/cocoa_test_event_utils.h" |
| 23 #import "ui/gfx/mac/coordinate_conversion.h" | 25 #import "ui/gfx/mac/coordinate_conversion.h" |
| 24 #import "ui/gfx/test/ui_cocoa_test_helper.h" | 26 #import "ui/gfx/test/ui_cocoa_test_helper.h" |
| 25 #import "ui/views/cocoa/bridged_content_view.h" | 27 #import "ui/views/cocoa/bridged_content_view.h" |
| 26 #import "ui/views/cocoa/native_widget_mac_nswindow.h" | 28 #import "ui/views/cocoa/native_widget_mac_nswindow.h" |
| 27 #import "ui/views/cocoa/views_nswindow_delegate.h" | 29 #import "ui/views/cocoa/views_nswindow_delegate.h" |
| 28 #include "ui/views/controls/textfield/textfield.h" | 30 #include "ui/views/controls/textfield/textfield.h" |
| 29 #include "ui/views/controls/textfield/textfield_model.h" | 31 #include "ui/views/controls/textfield/textfield_model.h" |
| 30 #include "ui/views/view.h" | 32 #include "ui/views/view.h" |
| 31 #include "ui/views/widget/native_widget_mac.h" | 33 #include "ui/views/widget/native_widget_mac.h" |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 232 native_widget_mac_(new MockNativeWidgetMac(widget_.get())) { | 234 native_widget_mac_(new MockNativeWidgetMac(widget_.get())) { |
| 233 } | 235 } |
| 234 | 236 |
| 235 std::unique_ptr<BridgedNativeWidget>& bridge() { | 237 std::unique_ptr<BridgedNativeWidget>& bridge() { |
| 236 return native_widget_mac_->bridge(); | 238 return native_widget_mac_->bridge(); |
| 237 } | 239 } |
| 238 | 240 |
| 239 // Overridden from testing::Test: | 241 // Overridden from testing::Test: |
| 240 void SetUp() override { | 242 void SetUp() override { |
| 241 ui::CocoaTest::SetUp(); | 243 ui::CocoaTest::SetUp(); |
| 244 ui::MaterialDesignController::Initialize(); | |
| 242 | 245 |
| 243 init_params_.native_widget = native_widget_mac_; | 246 init_params_.native_widget = native_widget_mac_; |
| 244 | 247 |
| 245 // Use a frameless window, otherwise Widget will try to center the window | 248 // Use a frameless window, otherwise Widget will try to center the window |
| 246 // before the tests covering the Init() flow are ready to do that. | 249 // before the tests covering the Init() flow are ready to do that. |
| 247 init_params_.type = Widget::InitParams::TYPE_WINDOW_FRAMELESS; | 250 init_params_.type = Widget::InitParams::TYPE_WINDOW_FRAMELESS; |
| 248 | 251 |
| 249 // To control the lifetime without an actual window that must be closed, | 252 // To control the lifetime without an actual window that must be closed, |
| 250 // tests in this file need to use WIDGET_OWNS_NATIVE_WIDGET. | 253 // tests in this file need to use WIDGET_OWNS_NATIVE_WIDGET. |
| 251 init_params_.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 254 init_params_.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 252 | 255 |
| 253 // Opacity defaults to "infer" which is usually updated by ViewsDelegate. | 256 // Opacity defaults to "infer" which is usually updated by ViewsDelegate. |
| 254 init_params_.opacity = Widget::InitParams::OPAQUE_WINDOW; | 257 init_params_.opacity = Widget::InitParams::OPAQUE_WINDOW; |
| 255 | 258 |
| 256 init_params_.bounds = gfx::Rect(100, 100, 100, 100); | 259 init_params_.bounds = gfx::Rect(100, 100, 100, 100); |
| 257 | 260 |
| 258 native_widget_mac_->GetWidget()->Init(init_params_); | 261 native_widget_mac_->GetWidget()->Init(init_params_); |
| 259 } | 262 } |
| 260 | 263 |
| 264 void TearDown() override { | |
| 265 ui::test::MaterialDesignControllerTestAPI::Uninitialize(); | |
| 266 } | |
|
tapted
2016/08/09 01:35:13
ui::CocoaTest::TearDown() after the ::Uninitialize
Evan Stade
2016/08/09 01:39:28
thanks, done
| |
| 267 | |
| 261 protected: | 268 protected: |
| 262 std::unique_ptr<Widget> widget_; | 269 std::unique_ptr<Widget> widget_; |
| 263 MockNativeWidgetMac* native_widget_mac_; // Weak. Owned by |widget_|. | 270 MockNativeWidgetMac* native_widget_mac_; // Weak. Owned by |widget_|. |
| 264 | 271 |
| 265 // Make the InitParams available to tests to cover initialization codepaths. | 272 // Make the InitParams available to tests to cover initialization codepaths. |
| 266 Widget::InitParams init_params_; | 273 Widget::InitParams init_params_; |
| 267 }; | 274 }; |
| 268 | 275 |
| 269 class BridgedNativeWidgetTest : public BridgedNativeWidgetTestBase { | 276 class BridgedNativeWidgetTest : public BridgedNativeWidgetTestBase { |
| 270 public: | 277 public: |
| (...skipping 1018 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1289 [center postNotificationName:NSWindowDidExitFullScreenNotification | 1296 [center postNotificationName:NSWindowDidExitFullScreenNotification |
| 1290 object:window]; | 1297 object:window]; |
| 1291 EXPECT_EQ(1, [window ignoredToggleFullScreenCount]); // No change. | 1298 EXPECT_EQ(1, [window ignoredToggleFullScreenCount]); // No change. |
| 1292 EXPECT_FALSE(bridge()->target_fullscreen_state()); | 1299 EXPECT_FALSE(bridge()->target_fullscreen_state()); |
| 1293 | 1300 |
| 1294 widget_->CloseNow(); | 1301 widget_->CloseNow(); |
| 1295 } | 1302 } |
| 1296 | 1303 |
| 1297 } // namespace test | 1304 } // namespace test |
| 1298 } // namespace views | 1305 } // namespace views |
| OLD | NEW |