| 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 <AppKit/AppKit.h> | 5 #import <AppKit/AppKit.h> |
| 6 #import "base/scoped_nsobject.h" | 6 #import "base/scoped_nsobject.h" |
| 7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
| 8 #include "chrome/app/chrome_dll_resource.h" | 8 #include "chrome/app/chrome_dll_resource.h" |
| 9 #include "chrome/browser/browser.h" | 9 #include "chrome/browser/browser.h" |
| 10 #include "chrome/browser/cocoa/bookmark_menu_bridge.h" | 10 #include "chrome/browser/cocoa/bookmark_menu_bridge.h" |
| 11 #include "chrome/browser/cocoa/browser_test_helper.h" | 11 #include "chrome/browser/cocoa/browser_test_helper.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #import "testing/gtest_mac.h" |
| 13 #include "testing/platform_test.h" | 14 #include "testing/platform_test.h" |
| 14 | 15 |
| 15 class TestBookmarkMenuBridge : public BookmarkMenuBridge { | 16 class TestBookmarkMenuBridge : public BookmarkMenuBridge { |
| 16 public: | 17 public: |
| 17 TestBookmarkMenuBridge(Profile* profile) | 18 TestBookmarkMenuBridge(Profile* profile) |
| 18 : BookmarkMenuBridge(profile), | 19 : BookmarkMenuBridge(profile), |
| 19 menu_([[NSMenu alloc] initWithTitle:@"test"]) { | 20 menu_([[NSMenu alloc] initWithTitle:@"test"]) { |
| 20 } | 21 } |
| 21 virtual ~TestBookmarkMenuBridge() {} | 22 virtual ~TestBookmarkMenuBridge() {} |
| 22 | 23 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 AddItemToMenu(menu, @"not", @selector(openBookmarkMenuItem:)); | 107 AddItemToMenu(menu, @"not", @selector(openBookmarkMenuItem:)); |
| 107 AddItemToMenu(menu, @"zippy", @selector(length)); | 108 AddItemToMenu(menu, @"zippy", @selector(length)); |
| 108 [menu addItem:[NSMenuItem separatorItem]]; | 109 [menu addItem:[NSMenuItem separatorItem]]; |
| 109 | 110 |
| 110 ClearBookmarkMenu(bridge_.get(), menu); | 111 ClearBookmarkMenu(bridge_.get(), menu); |
| 111 | 112 |
| 112 // Make sure all bookmark items are removed, all items with | 113 // Make sure all bookmark items are removed, all items with |
| 113 // submenus removed, and all separator items are gone. | 114 // submenus removed, and all separator items are gone. |
| 114 EXPECT_EQ(2, [menu numberOfItems]); | 115 EXPECT_EQ(2, [menu numberOfItems]); |
| 115 for (NSMenuItem *item in [menu itemArray]) { | 116 for (NSMenuItem *item in [menu itemArray]) { |
| 116 EXPECT_FALSE([[item title] isEqual:@"not"]); | 117 EXPECT_NSNE(@"not", [item title]); |
| 117 } | 118 } |
| 118 } | 119 } |
| 119 | 120 |
| 120 // Test invalidation | 121 // Test invalidation |
| 121 TEST_F(BookmarkMenuBridgeTest, TestInvalidation) { | 122 TEST_F(BookmarkMenuBridgeTest, TestInvalidation) { |
| 122 BookmarkModel* model = bridge_->GetBookmarkModel(); | 123 BookmarkModel* model = bridge_->GetBookmarkModel(); |
| 123 bridge_->Loaded(model); | 124 bridge_->Loaded(model); |
| 124 | 125 |
| 125 EXPECT_FALSE(menu_is_valid()); | 126 EXPECT_FALSE(menu_is_valid()); |
| 126 bridge_->UpdateMenu(bridge_->menu_); | 127 bridge_->UpdateMenu(bridge_->menu_); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 for (item in [menu itemArray]) { | 197 for (item in [menu itemArray]) { |
| 197 if ([[item title] hasPrefix:@"http://super-duper"]) { | 198 if ([[item title] hasPrefix:@"http://super-duper"]) { |
| 198 long_item = item; | 199 long_item = item; |
| 199 break; | 200 break; |
| 200 } | 201 } |
| 201 } | 202 } |
| 202 EXPECT_TRUE(long_item); | 203 EXPECT_TRUE(long_item); |
| 203 | 204 |
| 204 // Make sure a short title looks fine | 205 // Make sure a short title looks fine |
| 205 NSString* s = [short_item title]; | 206 NSString* s = [short_item title]; |
| 206 EXPECT_TRUE([s isEqual:[NSString stringWithUTF8String:short_url]]); | 207 EXPECT_NSEQ([NSString stringWithUTF8String:short_url], s); |
| 207 | 208 |
| 208 // Make sure a super-long title gets trimmed | 209 // Make sure a super-long title gets trimmed |
| 209 s = [long_item title]; | 210 s = [long_item title]; |
| 210 EXPECT_TRUE([s length] < strlen(long_url)); | 211 EXPECT_TRUE([s length] < strlen(long_url)); |
| 211 | 212 |
| 212 // Confirm tooltips and confirm they are not trimmed (like the item | 213 // Confirm tooltips and confirm they are not trimmed (like the item |
| 213 // name might be). Add tolerance for URL fixer-upping; | 214 // name might be). Add tolerance for URL fixer-upping; |
| 214 // e.g. http://foo becomes http://foo/) | 215 // e.g. http://foo becomes http://foo/) |
| 215 EXPECT_GE([[short_item toolTip] length], (2*strlen(short_url) - 5)); | 216 EXPECT_GE([[short_item toolTip] length], (2*strlen(short_url) - 5)); |
| 216 EXPECT_GE([[long_item toolTip] length], (2*strlen(long_url) - 5)); | 217 EXPECT_GE([[long_item toolTip] length], (2*strlen(long_url) - 5)); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 | 265 |
| 265 const char* short_url = "http://foo/"; | 266 const char* short_url = "http://foo/"; |
| 266 model->AddURL(root, 0, ASCIIToWide(short_url), GURL(short_url)); | 267 model->AddURL(root, 0, ASCIIToWide(short_url), GURL(short_url)); |
| 267 | 268 |
| 268 bridge_->UpdateMenu(menu); | 269 bridge_->UpdateMenu(menu); |
| 269 ASSERT_GT([menu numberOfItems], 0); | 270 ASSERT_GT([menu numberOfItems], 0); |
| 270 NSMenuItem* other = [menu itemAtIndex:([menu numberOfItems]-1)]; | 271 NSMenuItem* other = [menu itemAtIndex:([menu numberOfItems]-1)]; |
| 271 EXPECT_TRUE(other); | 272 EXPECT_TRUE(other); |
| 272 EXPECT_TRUE([other hasSubmenu]); | 273 EXPECT_TRUE([other hasSubmenu]); |
| 273 ASSERT_GT([[other submenu] numberOfItems], 0); | 274 ASSERT_GT([[other submenu] numberOfItems], 0); |
| 274 EXPECT_TRUE([[[[other submenu] itemAtIndex:0] title] isEqual:@"http://foo/"]); | 275 EXPECT_NSEQ(@"http://foo/", [[[other submenu] itemAtIndex:0] title]); |
| 275 } | 276 } |
| 276 | 277 |
| 277 TEST_F(BookmarkMenuBridgeTest, TestFavIconLoading) { | 278 TEST_F(BookmarkMenuBridgeTest, TestFavIconLoading) { |
| 278 std::wstring empty; | 279 std::wstring empty; |
| 279 NSMenu* menu = bridge_->menu_; | 280 NSMenu* menu = bridge_->menu_; |
| 280 | 281 |
| 281 BookmarkModel* model = bridge_->GetBookmarkModel(); | 282 BookmarkModel* model = bridge_->GetBookmarkModel(); |
| 282 const BookmarkNode* root = model->GetBookmarkBarNode(); | 283 const BookmarkNode* root = model->GetBookmarkBarNode(); |
| 283 EXPECT_TRUE(model && root); | 284 EXPECT_TRUE(model && root); |
| 284 | 285 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 307 EXPECT_TRUE([item image]); | 308 EXPECT_TRUE([item image]); |
| 308 | 309 |
| 309 model->SetTitle(node, L"New Title"); | 310 model->SetTitle(node, L"New Title"); |
| 310 | 311 |
| 311 item = [menu itemWithTitle:@"Test Item"]; | 312 item = [menu itemWithTitle:@"Test Item"]; |
| 312 EXPECT_FALSE(item); | 313 EXPECT_FALSE(item); |
| 313 item = [menu itemWithTitle:@"New Title"]; | 314 item = [menu itemWithTitle:@"New Title"]; |
| 314 EXPECT_TRUE(item); | 315 EXPECT_TRUE(item); |
| 315 } | 316 } |
| 316 | 317 |
| OLD | NEW |