| OLD | NEW |
| 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 #import <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
| 6 | 6 |
| 7 #include "app/theme_provider.h" | 7 #include "app/theme_provider.h" |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/scoped_nsobject.h" | 9 #include "base/scoped_nsobject.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 @end | 245 @end |
| 246 | 246 |
| 247 | 247 |
| 248 namespace { | 248 namespace { |
| 249 | 249 |
| 250 class BookmarkBarControllerTestBase : public CocoaTest { | 250 class BookmarkBarControllerTestBase : public CocoaTest { |
| 251 public: | 251 public: |
| 252 BrowserTestHelper helper_; | 252 BrowserTestHelper helper_; |
| 253 scoped_nsobject<NSView> parent_view_; | 253 scoped_nsobject<NSView> parent_view_; |
| 254 scoped_nsobject<ViewResizerPong> resizeDelegate_; | 254 scoped_nsobject<ViewResizerPong> resizeDelegate_; |
| 255 scoped_nsobject<BookmarkBarController> bar_; | |
| 256 | 255 |
| 257 BookmarkBarControllerTestBase() { | 256 BookmarkBarControllerTestBase() { |
| 258 resizeDelegate_.reset([[ViewResizerPong alloc] init]); | 257 resizeDelegate_.reset([[ViewResizerPong alloc] init]); |
| 259 NSRect parent_frame = NSMakeRect(0, 0, 800, 50); | 258 NSRect parent_frame = NSMakeRect(0, 0, 800, 50); |
| 260 parent_view_.reset([[NSView alloc] initWithFrame:parent_frame]); | 259 parent_view_.reset([[NSView alloc] initWithFrame:parent_frame]); |
| 261 [parent_view_ setHidden:YES]; | 260 [parent_view_ setHidden:YES]; |
| 262 bar_.reset([[BookmarkBarController alloc] | |
| 263 initWithBrowser:helper_.browser() | |
| 264 initialWidth:NSWidth(parent_frame) | |
| 265 delegate:nil | |
| 266 resizeDelegate:resizeDelegate_.get()]); | |
| 267 InstallAndToggleBar(bar_.get()); | |
| 268 } | 261 } |
| 269 | 262 |
| 270 void InstallAndToggleBar(BookmarkBarController* bar) { | 263 void InstallAndToggleBar(BookmarkBarController* bar) { |
| 271 // Force loading of the nib. | 264 // Force loading of the nib. |
| 272 [bar view]; | 265 [bar view]; |
| 273 // Awkwardness to look like we've been installed. | 266 // Awkwardness to look like we've been installed. |
| 274 for (NSView* subView in [parent_view_ subviews]) | 267 for (NSView* subView in [parent_view_ subviews]) |
| 275 [subView removeFromSuperview]; | 268 [subView removeFromSuperview]; |
| 276 [parent_view_ addSubview:[bar view]]; | 269 [parent_view_ addSubview:[bar view]]; |
| 277 NSRect frame = [[[bar view] superview] frame]; | 270 NSRect frame = [[[bar view] superview] frame]; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 288 showDetachedBar:NO | 281 showDetachedBar:NO |
| 289 withAnimation:NO]; | 282 withAnimation:NO]; |
| 290 } | 283 } |
| 291 }; | 284 }; |
| 292 | 285 |
| 293 class BookmarkBarControllerTest : public BookmarkBarControllerTestBase { | 286 class BookmarkBarControllerTest : public BookmarkBarControllerTestBase { |
| 294 public: | 287 public: |
| 295 scoped_nsobject<BookmarkMenu> menu_; | 288 scoped_nsobject<BookmarkMenu> menu_; |
| 296 scoped_nsobject<NSMenuItem> menu_item_; | 289 scoped_nsobject<NSMenuItem> menu_item_; |
| 297 scoped_nsobject<NSButtonCell> cell_; | 290 scoped_nsobject<NSButtonCell> cell_; |
| 291 scoped_nsobject<BookmarkBarControllerNoOpen> bar_; |
| 298 | 292 |
| 299 BookmarkBarControllerTest() { | 293 BookmarkBarControllerTest() { |
| 300 bar_.reset( | 294 bar_.reset( |
| 301 [[BookmarkBarControllerNoOpen alloc] | 295 [[BookmarkBarControllerNoOpen alloc] |
| 302 initWithBrowser:helper_.browser() | 296 initWithBrowser:helper_.browser() |
| 303 initialWidth:NSWidth([parent_view_ frame]) | 297 initialWidth:NSWidth([parent_view_ frame]) |
| 304 delegate:nil | 298 delegate:nil |
| 305 resizeDelegate:resizeDelegate_.get()]); | 299 resizeDelegate:resizeDelegate_.get()]); |
| 306 | 300 |
| 307 InstallAndToggleBar(bar_.get()); | 301 InstallAndToggleBar(bar_.get()); |
| (...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 747 TEST_F(BookmarkBarControllerTest, OpenBookmarkFromMenus) { | 741 TEST_F(BookmarkBarControllerTest, OpenBookmarkFromMenus) { |
| 748 const char* urls[] = { "http://walla.walla.ding.dong.com", | 742 const char* urls[] = { "http://walla.walla.ding.dong.com", |
| 749 "http://i_dont_know.com", | 743 "http://i_dont_know.com", |
| 750 "http://cee.enn.enn.dot.com" }; | 744 "http://cee.enn.enn.dot.com" }; |
| 751 SEL selectors[] = { @selector(openBookmarkInNewForegroundTab:), | 745 SEL selectors[] = { @selector(openBookmarkInNewForegroundTab:), |
| 752 @selector(openBookmarkInNewWindow:), | 746 @selector(openBookmarkInNewWindow:), |
| 753 @selector(openBookmarkInIncognitoWindow:) }; | 747 @selector(openBookmarkInIncognitoWindow:) }; |
| 754 WindowOpenDisposition dispositions[] = { NEW_FOREGROUND_TAB, | 748 WindowOpenDisposition dispositions[] = { NEW_FOREGROUND_TAB, |
| 755 NEW_WINDOW, | 749 NEW_WINDOW, |
| 756 OFF_THE_RECORD }; | 750 OFF_THE_RECORD }; |
| 757 for (unsigned int i = 0; | 751 for (unsigned int i = 0; i < arraysize(dispositions); i++) { |
| 758 i < sizeof(dispositions)/sizeof(dispositions[0]); | |
| 759 i++) { | |
| 760 GURL gurl(urls[i]); | 752 GURL gurl(urls[i]); |
| 761 [bar_ performSelector:selectors[i] | 753 [bar_ performSelector:selectors[i] |
| 762 withObject:ItemForBookmarkBarMenu(gurl)]; | 754 withObject:ItemForBookmarkBarMenu(gurl)]; |
| 763 EXPECT_EQ(noOpenBar()->urls_[0], gurl); | 755 EXPECT_EQ(noOpenBar()->urls_[0], gurl); |
| 764 EXPECT_EQ(noOpenBar()->dispositions_[0], dispositions[i]); | 756 EXPECT_EQ(noOpenBar()->dispositions_[0], dispositions[i]); |
| 765 [bar_ clear]; | 757 [bar_ clear]; |
| 766 } | 758 } |
| 767 } | 759 } |
| 768 | 760 |
| 769 TEST_F(BookmarkBarControllerTest, TestAddRemoveAndClear) { | 761 TEST_F(BookmarkBarControllerTest, TestAddRemoveAndClear) { |
| (...skipping 1052 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1822 // which can be overridden to fire immediately to make behavior | 1814 // which can be overridden to fire immediately to make behavior |
| 1823 // confirmable. | 1815 // confirmable. |
| 1824 | 1816 |
| 1825 // TODO(jrg): add unit test to make sure "Other Bookmarks" responds | 1817 // TODO(jrg): add unit test to make sure "Other Bookmarks" responds |
| 1826 // properly to a hover open. | 1818 // properly to a hover open. |
| 1827 | 1819 |
| 1828 // TODO(viettrungluu): figure out how to test animations. | 1820 // TODO(viettrungluu): figure out how to test animations. |
| 1829 | 1821 |
| 1830 class BookmarkBarControllerDragDropTest : public BookmarkBarControllerTestBase { | 1822 class BookmarkBarControllerDragDropTest : public BookmarkBarControllerTestBase { |
| 1831 public: | 1823 public: |
| 1824 scoped_nsobject<BookmarkBarControllerDragData> bar_; |
| 1825 |
| 1832 BookmarkBarControllerDragDropTest() { | 1826 BookmarkBarControllerDragDropTest() { |
| 1833 bar_.reset( | 1827 bar_.reset( |
| 1834 [[BookmarkBarControllerDragData alloc] | 1828 [[BookmarkBarControllerDragData alloc] |
| 1835 initWithBrowser:helper_.browser() | 1829 initWithBrowser:helper_.browser() |
| 1836 initialWidth:NSWidth([parent_view_ frame]) | 1830 initialWidth:NSWidth([parent_view_ frame]) |
| 1837 delegate:nil | 1831 delegate:nil |
| 1838 resizeDelegate:resizeDelegate_.get()]); | 1832 resizeDelegate:resizeDelegate_.get()]); |
| 1839 InstallAndToggleBar(bar_.get()); | 1833 InstallAndToggleBar(bar_.get()); |
| 1840 } | 1834 } |
| 1841 }; | 1835 }; |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2026 EXPECT_CGFLOAT_EQ(expected, actual); | 2020 EXPECT_CGFLOAT_EQ(expected, actual); |
| 2027 targetButton = [bar_ buttonWithTitleEqualTo:@"4b"]; | 2021 targetButton = [bar_ buttonWithTitleEqualTo:@"4b"]; |
| 2028 targetPoint = [targetButton right]; | 2022 targetPoint = [targetButton right]; |
| 2029 targetPoint.x += 100; // Somewhere off to the right. | 2023 targetPoint.x += 100; // Somewhere off to the right. |
| 2030 expected = NSMaxX([targetButton frame]) + xDelta; | 2024 expected = NSMaxX([targetButton frame]) + xDelta; |
| 2031 actual = [bar_ indicatorPosForDragToPoint:targetPoint]; | 2025 actual = [bar_ indicatorPosForDragToPoint:targetPoint]; |
| 2032 EXPECT_CGFLOAT_EQ(expected, actual); | 2026 EXPECT_CGFLOAT_EQ(expected, actual); |
| 2033 } | 2027 } |
| 2034 | 2028 |
| 2035 } // namespace | 2029 } // namespace |
| OLD | NEW |