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

Side by Side Diff: chrome/browser/ui/cocoa/tabs/tab_strip_controller_unittest.mm

Issue 17593006: mac: Update clients of scoped_nsobject.h. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: iwyu, scoped_nsprotocol Created 7 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <Cocoa/Cocoa.h> 5 #import <Cocoa/Cocoa.h>
6 6
7 #include "base/mac/scoped_nsautorelease_pool.h" 7 #include "base/mac/scoped_nsautorelease_pool.h"
8 #include "chrome/browser/ui/browser_window.h" 8 #include "chrome/browser/ui/browser_window.h"
9 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" 9 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h"
10 #import "chrome/browser/ui/cocoa/new_tab_button.h" 10 #import "chrome/browser/ui/cocoa/new_tab_button.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 CocoaProfileTest::SetUp(); 86 CocoaProfileTest::SetUp();
87 ASSERT_TRUE(browser()); 87 ASSERT_TRUE(browser());
88 88
89 NSWindow* window = browser()->window()->GetNativeWindow(); 89 NSWindow* window = browser()->window()->GetNativeWindow();
90 NSView* parent = [window contentView]; 90 NSView* parent = [window contentView];
91 NSRect content_frame = [parent frame]; 91 NSRect content_frame = [parent frame];
92 92
93 // Create the "switch view" (view that gets changed out when a tab 93 // Create the "switch view" (view that gets changed out when a tab
94 // switches). 94 // switches).
95 NSRect switch_frame = NSMakeRect(0, 0, content_frame.size.width, 500); 95 NSRect switch_frame = NSMakeRect(0, 0, content_frame.size.width, 500);
96 scoped_nsobject<NSView> switch_view( 96 base::scoped_nsobject<NSView> switch_view(
97 [[NSView alloc] initWithFrame:switch_frame]); 97 [[NSView alloc] initWithFrame:switch_frame]);
98 [parent addSubview:switch_view.get()]; 98 [parent addSubview:switch_view.get()];
99 99
100 // Create the tab strip view. It's expected to have a child button in it 100 // Create the tab strip view. It's expected to have a child button in it
101 // already as the "new tab" button so create that too. 101 // already as the "new tab" button so create that too.
102 NSRect strip_frame = NSMakeRect(0, NSMaxY(switch_frame), 102 NSRect strip_frame = NSMakeRect(0, NSMaxY(switch_frame),
103 content_frame.size.width, 30); 103 content_frame.size.width, 30);
104 tab_strip_.reset( 104 tab_strip_.reset(
105 [[TabStripView alloc] initWithFrame:strip_frame]); 105 [[TabStripView alloc] initWithFrame:strip_frame]);
106 [parent addSubview:tab_strip_.get()]; 106 [parent addSubview:tab_strip_.get()];
107 NSRect button_frame = NSMakeRect(0, 0, 15, 15); 107 NSRect button_frame = NSMakeRect(0, 0, 15, 15);
108 scoped_nsobject<NewTabButton> new_tab_button( 108 base::scoped_nsobject<NewTabButton> new_tab_button(
109 [[NewTabButton alloc] initWithFrame:button_frame]); 109 [[NewTabButton alloc] initWithFrame:button_frame]);
110 [tab_strip_ addSubview:new_tab_button.get()]; 110 [tab_strip_ addSubview:new_tab_button.get()];
111 [tab_strip_ setNewTabButton:new_tab_button.get()]; 111 [tab_strip_ setNewTabButton:new_tab_button.get()];
112 112
113 delegate_.reset(new TestTabStripModelDelegate()); 113 delegate_.reset(new TestTabStripModelDelegate());
114 model_ = browser()->tab_strip_model(); 114 model_ = browser()->tab_strip_model();
115 controller_delegate_.reset([TestTabStripControllerDelegate alloc]); 115 controller_delegate_.reset([TestTabStripControllerDelegate alloc]);
116 controller_.reset([[TabStripController alloc] 116 controller_.reset([[TabStripController alloc]
117 initWithView:static_cast<TabStripView*>(tab_strip_.get()) 117 initWithView:static_cast<TabStripView*>(tab_strip_.get())
118 switchView:switch_view.get() 118 switchView:switch_view.get()
(...skipping 26 matching lines...) Expand all
145 controller_.reset(); 145 controller_.reset();
146 tab_strip_.reset(); 146 tab_strip_.reset();
147 // Schedule a NSLeftMouseUp to end the nested drag event loop. 147 // Schedule a NSLeftMouseUp to end the nested drag event loop.
148 NSEvent* event = 148 NSEvent* event =
149 cocoa_test_event_utils::MouseEventWithType(NSLeftMouseUp, 0); 149 cocoa_test_event_utils::MouseEventWithType(NSLeftMouseUp, 0);
150 [NSApp postEvent:event atStart:NO]; 150 [NSApp postEvent:event atStart:NO];
151 } 151 }
152 152
153 scoped_ptr<TestTabStripModelDelegate> delegate_; 153 scoped_ptr<TestTabStripModelDelegate> delegate_;
154 TabStripModel* model_; 154 TabStripModel* model_;
155 scoped_nsobject<TestTabStripControllerDelegate> controller_delegate_; 155 base::scoped_nsobject<TestTabStripControllerDelegate> controller_delegate_;
156 scoped_nsobject<TabStripController> controller_; 156 base::scoped_nsobject<TabStripController> controller_;
157 scoped_nsobject<TabStripView> tab_strip_; 157 base::scoped_nsobject<TabStripView> tab_strip_;
158 }; 158 };
159 159
160 // Test adding and removing tabs and making sure that views get added to 160 // Test adding and removing tabs and making sure that views get added to
161 // the tab strip. 161 // the tab strip.
162 TEST_F(TabStripControllerTest, AddRemoveTabs) { 162 TEST_F(TabStripControllerTest, AddRemoveTabs) {
163 EXPECT_TRUE(model_->empty()); 163 EXPECT_TRUE(model_->empty());
164 CreateTab(); 164 CreateTab();
165 EXPECT_EQ(model_->count(), 1); 165 EXPECT_EQ(model_->count(), 1);
166 } 166 }
167 167
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 // tab strip model. Use a ScopedNSAutoreleasePool to get a truly weak ref 233 // tab strip model. Use a ScopedNSAutoreleasePool to get a truly weak ref
234 // to it to test that -maybeStartDrag:forTab: can handle that properly. 234 // to it to test that -maybeStartDrag:forTab: can handle that properly.
235 { 235 {
236 base::mac::ScopedNSAutoreleasePool pool; 236 base::mac::ScopedNSAutoreleasePool pool;
237 tab = [CreateTab() controller]; 237 tab = [CreateTab() controller];
238 } 238 }
239 239
240 // Schedule a task to close all the tabs and stop the drag, before the call to 240 // Schedule a task to close all the tabs and stop the drag, before the call to
241 // -maybeStartDrag:forTab:, which starts a nested event loop. This task will 241 // -maybeStartDrag:forTab:, which starts a nested event loop. This task will
242 // run in that nested event loop, which shouldn't crash. 242 // run in that nested event loop, which shouldn't crash.
243 scoped_nsobject<TestClosureRunner> runner( 243 base::scoped_nsobject<TestClosureRunner> runner([[TestClosureRunner alloc]
244 [[TestClosureRunner alloc] initWithClosure: 244 initWithClosure:base::Bind(&TabStripControllerTest::CloseTabsAndEndDrag,
245 base::Bind(&TabStripControllerTest::CloseTabsAndEndDrag, 245 base::Unretained(this))]);
246 base::Unretained(this))]);
247 [runner scheduleDelayedRun]; 246 [runner scheduleDelayedRun];
248 247
249 NSEvent* event = 248 NSEvent* event =
250 cocoa_test_event_utils::LeftMouseDownAtPoint(NSMakePoint(0, 0)); 249 cocoa_test_event_utils::LeftMouseDownAtPoint(NSMakePoint(0, 0));
251 [[controller_ dragController] maybeStartDrag:event forTab:tab]; 250 [[controller_ dragController] maybeStartDrag:event forTab:tab];
252 } 251 }
253 252
254 TEST_F(TabStripControllerTest, ViewAccessibility_Contents) { 253 TEST_F(TabStripControllerTest, ViewAccessibility_Contents) {
255 NSArray* attrs = [tab_strip_ accessibilityAttributeNames]; 254 NSArray* attrs = [tab_strip_ accessibilityAttributeNames];
256 ASSERT_TRUE([attrs containsObject:NSAccessibilityContentsAttribute]); 255 ASSERT_TRUE([attrs containsObject:NSAccessibilityContentsAttribute]);
(...skipping 24 matching lines...) Expand all
281 280
282 model_->ActivateTabAt(0, false); 281 model_->ActivateTabAt(0, false);
283 EXPECT_TRUE([tab1 controller].selected); 282 EXPECT_TRUE([tab1 controller].selected);
284 EXPECT_FALSE([tab2 controller].selected); 283 EXPECT_FALSE([tab2 controller].selected);
285 value = 284 value =
286 [tab_strip_ accessibilityAttributeValue:NSAccessibilityValueAttribute]; 285 [tab_strip_ accessibilityAttributeValue:NSAccessibilityValueAttribute];
287 EXPECT_EQ(tab1, value); 286 EXPECT_EQ(tab1, value);
288 } 287 }
289 288
290 } // namespace 289 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698