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

Side by Side Diff: chrome/browser/cocoa/status_bubble_mac_unittest.mm

Issue 266018: Mac: Resize status bubble when window is resized. (Closed)
Patch Set: Updated per Avi's comments (more or less). Created 11 years, 2 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
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 #include <Cocoa/Cocoa.h> 5 #include <Cocoa/Cocoa.h>
6 6
7 #include "base/scoped_nsobject.h" 7 #include "base/scoped_nsobject.h"
8 #include "base/scoped_ptr.h" 8 #include "base/scoped_ptr.h"
9 #import "chrome/browser/cocoa/cocoa_test_helper.h" 9 #import "chrome/browser/cocoa/cocoa_test_helper.h"
10 #include "chrome/browser/cocoa/status_bubble_mac.h" 10 #include "chrome/browser/cocoa/status_bubble_mac.h"
11 #include "googleurl/src/gurl.h" 11 #include "googleurl/src/gurl.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "testing/platform_test.h" 13 #include "testing/platform_test.h"
14 #import "third_party/GTM/AppKit/GTMTheme.h" 14 #import "third_party/GTM/AppKit/GTMTheme.h"
15 15
16 @interface StatusBubbleMacTestWindowDelegate : NSObject <GTMThemeDelegate>; 16 @interface StatusBubbleMacTestWindowDelegate : NSObject <GTMThemeDelegate>;
17 @end 17 @end
18 @implementation StatusBubbleMacTestWindowDelegate 18 @implementation StatusBubbleMacTestWindowDelegate
19 - (GTMTheme *)gtm_themeForWindow:(NSWindow *)window { 19 - (GTMTheme *)gtm_themeForWindow:(NSWindow *)window {
20 NSLog(@"gettheme");
21 return [[[GTMTheme alloc] init] autorelease]; 20 return [[[GTMTheme alloc] init] autorelease];
22 } 21 }
23 @end 22 @end
24 23
25 class StatusBubbleMacTest : public PlatformTest { 24 class StatusBubbleMacTest : public PlatformTest {
26 public: 25 public:
27 StatusBubbleMacTest() { 26 StatusBubbleMacTest() {
28 NSWindow* window = cocoa_helper_.window(); 27 NSWindow* window = cocoa_helper_.window();
29 bubble_.reset(new StatusBubbleMac(window, nil)); 28 bubble_.reset(new StatusBubbleMac(window, nil));
30 EXPECT_TRUE(bubble_.get()); 29 EXPECT_TRUE(bubble_.get());
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 NSWindow* window = cocoa_helper_.window(); 111 NSWindow* window = cocoa_helper_.window();
113 // Create and delete immediately. 112 // Create and delete immediately.
114 StatusBubbleMac* bubble = new StatusBubbleMac(window, nil); 113 StatusBubbleMac* bubble = new StatusBubbleMac(window, nil);
115 delete bubble; 114 delete bubble;
116 115
117 // Create then delete while visible. 116 // Create then delete while visible.
118 bubble = new StatusBubbleMac(window, nil); 117 bubble = new StatusBubbleMac(window, nil);
119 bubble->SetStatus(L"showing"); 118 bubble->SetStatus(L"showing");
120 delete bubble; 119 delete bubble;
121 } 120 }
121
122 TEST_F(StatusBubbleMacTest, UpdateSizeAndPosition) {
123 // Test |UpdateSizeAndPosition()| when status bubble does not exist (shouldn't
124 // crash; shouldn't create window).
125 EXPECT_FALSE(GetWindow());
126 bubble_->UpdateSizeAndPosition();
127 EXPECT_FALSE(GetWindow());
128
129 // Create a status bubble (with contents) and call resize (without actually
130 // resizing); the frame size shouldn't change.
131 bubble_->SetStatus(L"UpdateSizeAndPosition test");
132 ASSERT_TRUE(GetWindow());
133 NSRect rect_before = [GetWindow() frame];
134 bubble_->UpdateSizeAndPosition();
135 NSRect rect_after = [GetWindow() frame];
136 EXPECT_TRUE(NSEqualRects(rect_before, rect_after));
137
138 // Move the window and call resize; only the origin should change.
139 NSWindow* window = cocoa_helper_.window();
140 ASSERT_TRUE(window);
141 NSRect frame = [window frame];
142 rect_before = [GetWindow() frame];
143 frame.origin.x += 10.0; // (fairly arbitrary nonzero value)
144 frame.origin.y += 10.0; // (fairly arbitrary nonzero value)
145 [window setFrame:frame display:YES];
146 bubble_->UpdateSizeAndPosition();
147 rect_after = [GetWindow() frame];
148 EXPECT_NE(rect_before.origin.x, rect_after.origin.x);
149 EXPECT_NE(rect_before.origin.y, rect_after.origin.y);
150 EXPECT_EQ(rect_before.size.width, rect_after.size.width);
151 EXPECT_EQ(rect_before.size.height, rect_after.size.height);
152
153 // Resize the window (without moving). The origin shouldn't change. The width
154 // should change (in the current implementation), but not the height.
155 frame = [window frame];
156 rect_before = [GetWindow() frame];
157 frame.size.width += 50.0; // (fairly arbitrary nonzero value)
158 frame.size.height += 50.0; // (fairly arbitrary nonzero value)
159 [window setFrame:frame display:YES];
160 bubble_->UpdateSizeAndPosition();
161 rect_after = [GetWindow() frame];
162 EXPECT_EQ(rect_before.origin.x, rect_after.origin.x);
163 EXPECT_EQ(rect_before.origin.y, rect_after.origin.y);
164 EXPECT_NE(rect_before.size.width, rect_after.size.width);
165 EXPECT_EQ(rect_before.size.height, rect_after.size.height);
166 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698