Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(462)

Side by Side Diff: ui/views/cocoa/bridged_native_widget_unittest.mm

Issue 329743002: MacViews: Initial skeleton for implementing NativeWidgetMac (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: respond to comments Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/views/cocoa/bridged_native_widget.mm ('k') | ui/views/views.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #import "ui/views/cocoa/bridged_native_widget.h"
6
7 #import <Cocoa/Cocoa.h>
8
9 #include "base/memory/scoped_ptr.h"
10 #import "testing/gtest_mac.h"
11 #import "ui/gfx/test/ui_cocoa_test_helper.h"
12 #import "ui/views/cocoa/bridged_content_view.h"
13 #include "ui/views/view.h"
14
15 namespace views {
16
17 class BridgedNativeWidgetTest : public ui::CocoaTest {
18 public:
19 BridgedNativeWidgetTest();
20 virtual ~BridgedNativeWidgetTest();
21
22 // testing::Test:
23 virtual void SetUp() OVERRIDE;
24 virtual void TearDown() OVERRIDE;
25
26 protected:
27 // TODO(tapted): Make this a EventCountView from widget_unittest.cc.
28 scoped_ptr<views::View> view_;
29 scoped_ptr<BridgedNativeWidget> bridge_;
30
31 private:
32 DISALLOW_COPY_AND_ASSIGN(BridgedNativeWidgetTest);
33 };
34
35 BridgedNativeWidgetTest::BridgedNativeWidgetTest() {
36 }
37
38 BridgedNativeWidgetTest::~BridgedNativeWidgetTest() {
39 }
40
41 void BridgedNativeWidgetTest::SetUp() {
42 ui::CocoaTest::SetUp();
43
44 view_.reset(new views::View);
45 bridge_.reset(new BridgedNativeWidget);
46 base::scoped_nsobject<NSWindow> window([test_window() retain]);
47 bridge_->Init(window);
48 bridge_->SetRootView(view_.get());
49
50 [test_window() makePretendKeyWindowAndSetFirstResponder:bridge_->ns_view()];
51 }
52
53 void BridgedNativeWidgetTest::TearDown() {
54 [test_window() clearPretendKeyWindowAndFirstResponder];
55
56 bridge_.reset();
57 view_.reset();
58
59 ui::CocoaTest::TearDown();
60 }
61
62 // The TEST_VIEW macro expects the view it's testing to have a superview. In
63 // these tests, the NSView bridge is a contentView, at the root. These mimic
64 // what TEST_VIEW usually does.
65 TEST_F(BridgedNativeWidgetTest, BridgedNativeWidgetTest_TestViewAddRemove) {
66 base::scoped_nsobject<BridgedContentView> view([bridge_->ns_view() retain]);
67 EXPECT_NSEQ([test_window() contentView], view);
68 EXPECT_NSEQ(test_window(), [view window]);
69
70 // The superview of a contentView is an NSNextStepFrame.
71 EXPECT_TRUE([view superview]);
72 EXPECT_TRUE([view hostedView]);
73
74 // Destroying the C++ bridge should remove references to any C++ objects in
75 // the ObjectiveC object, and remove it from the hierarchy.
76 bridge_.reset();
77 EXPECT_FALSE([view hostedView]);
78 EXPECT_FALSE([view superview]);
79 EXPECT_FALSE([view window]);
80 EXPECT_FALSE([test_window() contentView]);
81 }
82
83 TEST_F(BridgedNativeWidgetTest, BridgedNativeWidgetTest_TestViewDisplay) {
84 [bridge_->ns_view() display];
85 }
86
87 // Test that resizing the window resizes the root view appropriately.
88 TEST_F(BridgedNativeWidgetTest, ViewSizeTracksWindow) {
89 const int kTestNewWidth = 400;
90 const int kTestNewHeight = 300;
91
92 // |test_window()| is borderless, so these should align.
93 NSSize window_size = [test_window() frame].size;
94 EXPECT_EQ(view_->width(), static_cast<int>(window_size.width));
95 EXPECT_EQ(view_->height(), static_cast<int>(window_size.height));
96
97 // Make sure a resize actually occurs.
98 EXPECT_NE(kTestNewWidth, view_->width());
99 EXPECT_NE(kTestNewHeight, view_->height());
100
101 [test_window() setFrame:NSMakeRect(0, 0, kTestNewWidth, kTestNewHeight)
102 display:NO];
103 EXPECT_EQ(kTestNewWidth, view_->width());
104 EXPECT_EQ(kTestNewHeight, view_->height());
105 }
106
107 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/cocoa/bridged_native_widget.mm ('k') | ui/views/views.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698