OLD | NEW |
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 #include "chrome/browser/ui/cocoa/history_menu_bridge.h" |
| 6 |
5 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 |
| 9 #include <memory> |
6 #include <vector> | 10 #include <vector> |
7 | 11 |
| 12 #include "base/memory/ptr_util.h" |
8 #include "base/memory/ref_counted_memory.h" | 13 #include "base/memory/ref_counted_memory.h" |
9 #include "base/memory/scoped_ptr.h" | |
10 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
11 #include "base/strings/sys_string_conversions.h" | 15 #include "base/strings/sys_string_conversions.h" |
12 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
13 #include "chrome/app/chrome_command_ids.h" | 17 #include "chrome/app/chrome_command_ids.h" |
14 #include "chrome/browser/sessions/chrome_tab_restore_service_client.h" | 18 #include "chrome/browser/sessions/chrome_tab_restore_service_client.h" |
15 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" | 19 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" |
16 #include "chrome/browser/ui/cocoa/history_menu_bridge.h" | |
17 #include "chrome/test/base/testing_profile.h" | 20 #include "chrome/test/base/testing_profile.h" |
18 #include "components/favicon_base/favicon_types.h" | 21 #include "components/favicon_base/favicon_types.h" |
19 #include "components/sessions/core/persistent_tab_restore_service.h" | 22 #include "components/sessions/core/persistent_tab_restore_service.h" |
20 #include "components/sessions/core/serialized_navigation_entry_test_helper.h" | 23 #include "components/sessions/core/serialized_navigation_entry_test_helper.h" |
21 #include "testing/gmock/include/gmock/gmock.h" | 24 #include "testing/gmock/include/gmock/gmock.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
23 #import "testing/gtest_mac.h" | 26 #import "testing/gtest_mac.h" |
24 #include "third_party/skia/include/core/SkBitmap.h" | 27 #include "third_party/skia/include/core/SkBitmap.h" |
25 #include "ui/gfx/codec/png_codec.h" | 28 #include "ui/gfx/codec/png_codec.h" |
26 | 29 |
27 namespace { | 30 namespace { |
28 | 31 |
29 class MockTRS : public sessions::PersistentTabRestoreService { | 32 class MockTRS : public sessions::PersistentTabRestoreService { |
30 public: | 33 public: |
31 MockTRS(Profile* profile) | 34 MockTRS(Profile* profile) |
32 : sessions::PersistentTabRestoreService( | 35 : sessions::PersistentTabRestoreService( |
33 make_scoped_ptr(new ChromeTabRestoreServiceClient(profile)), | 36 base::WrapUnique(new ChromeTabRestoreServiceClient(profile)), |
34 nullptr) {} | 37 nullptr) {} |
35 MOCK_CONST_METHOD0(entries, const sessions::TabRestoreService::Entries&()); | 38 MOCK_CONST_METHOD0(entries, const sessions::TabRestoreService::Entries&()); |
36 }; | 39 }; |
37 | 40 |
38 class MockBridge : public HistoryMenuBridge { | 41 class MockBridge : public HistoryMenuBridge { |
39 public: | 42 public: |
40 MockBridge(Profile* profile) | 43 MockBridge(Profile* profile) |
41 : HistoryMenuBridge(profile), | 44 : HistoryMenuBridge(profile), |
42 menu_([[NSMenu alloc] initWithTitle:@"History"]) {} | 45 menu_([[NSMenu alloc] initWithTitle:@"History"]) {} |
43 | 46 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 | 108 |
106 void GetFaviconForHistoryItem(HistoryMenuBridge::HistoryItem* item) { | 109 void GetFaviconForHistoryItem(HistoryMenuBridge::HistoryItem* item) { |
107 bridge_->GetFaviconForHistoryItem(item); | 110 bridge_->GetFaviconForHistoryItem(item); |
108 } | 111 } |
109 | 112 |
110 void GotFaviconData(HistoryMenuBridge::HistoryItem* item, | 113 void GotFaviconData(HistoryMenuBridge::HistoryItem* item, |
111 const favicon_base::FaviconImageResult& image_result) { | 114 const favicon_base::FaviconImageResult& image_result) { |
112 bridge_->GotFaviconData(item, image_result); | 115 bridge_->GotFaviconData(item, image_result); |
113 } | 116 } |
114 | 117 |
115 scoped_ptr<MockBridge> bridge_; | 118 std::unique_ptr<MockBridge> bridge_; |
116 }; | 119 }; |
117 | 120 |
118 // Edge case test for clearing until the end of a menu. | 121 // Edge case test for clearing until the end of a menu. |
119 TEST_F(HistoryMenuBridgeTest, ClearHistoryMenuUntilEnd) { | 122 TEST_F(HistoryMenuBridgeTest, ClearHistoryMenuUntilEnd) { |
120 NSMenu* menu = [[[NSMenu alloc] initWithTitle:@"history foo"] autorelease]; | 123 NSMenu* menu = [[[NSMenu alloc] initWithTitle:@"history foo"] autorelease]; |
121 AddItemToMenu(menu, @"HEADER", NULL, HistoryMenuBridge::kVisitedTitle); | 124 AddItemToMenu(menu, @"HEADER", NULL, HistoryMenuBridge::kVisitedTitle); |
122 | 125 |
123 NSInteger tag = HistoryMenuBridge::kVisited; | 126 NSInteger tag = HistoryMenuBridge::kVisited; |
124 AddItemToMenu(menu, @"alpha", @selector(openHistoryMenuItem:), tag); | 127 AddItemToMenu(menu, @"alpha", @selector(openHistoryMenuItem:), tag); |
125 AddItemToMenu(menu, @"bravo", @selector(openHistoryMenuItem:), tag); | 128 AddItemToMenu(menu, @"bravo", @selector(openHistoryMenuItem:), tag); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 | 205 |
203 // Confirm tooltips and confirm they are not trimmed (like the item | 206 // Confirm tooltips and confirm they are not trimmed (like the item |
204 // name might be). Add tolerance for URL fixer-upping; | 207 // name might be). Add tolerance for URL fixer-upping; |
205 // e.g. http://foo becomes http://foo/) | 208 // e.g. http://foo becomes http://foo/) |
206 EXPECT_GE([[[menu itemAtIndex:0] toolTip] length], (2*short_url.length()-5)); | 209 EXPECT_GE([[[menu itemAtIndex:0] toolTip] length], (2*short_url.length()-5)); |
207 EXPECT_GE([[[menu itemAtIndex:1] toolTip] length], (2*long_url.length()-5)); | 210 EXPECT_GE([[[menu itemAtIndex:1] toolTip] length], (2*long_url.length()-5)); |
208 } | 211 } |
209 | 212 |
210 // Test that the menu is created for a set of simple tabs. | 213 // Test that the menu is created for a set of simple tabs. |
211 TEST_F(HistoryMenuBridgeTest, RecentlyClosedTabs) { | 214 TEST_F(HistoryMenuBridgeTest, RecentlyClosedTabs) { |
212 scoped_ptr<MockTRS> trs(new MockTRS(profile())); | 215 std::unique_ptr<MockTRS> trs(new MockTRS(profile())); |
213 MockTRS::Entries entries; | 216 MockTRS::Entries entries; |
214 | 217 |
215 MockTRS::Tab tab1 = CreateSessionTab("http://google.com", "Google"); | 218 MockTRS::Tab tab1 = CreateSessionTab("http://google.com", "Google"); |
216 tab1.id = 24; | 219 tab1.id = 24; |
217 entries.push_back(&tab1); | 220 entries.push_back(&tab1); |
218 | 221 |
219 MockTRS::Tab tab2 = CreateSessionTab("http://apple.com", "Apple"); | 222 MockTRS::Tab tab2 = CreateSessionTab("http://apple.com", "Apple"); |
220 tab2.id = 42; | 223 tab2.id = 42; |
221 entries.push_back(&tab2); | 224 entries.push_back(&tab2); |
222 | 225 |
(...skipping 13 matching lines...) Expand all Loading... |
236 | 239 |
237 NSMenuItem* item2 = [menu itemAtIndex:1]; | 240 NSMenuItem* item2 = [menu itemAtIndex:1]; |
238 MockBridge::HistoryItem* hist2 = bridge_->HistoryItemForMenuItem(item2); | 241 MockBridge::HistoryItem* hist2 = bridge_->HistoryItemForMenuItem(item2); |
239 EXPECT_TRUE(hist2); | 242 EXPECT_TRUE(hist2); |
240 EXPECT_EQ(42, hist2->session_id); | 243 EXPECT_EQ(42, hist2->session_id); |
241 EXPECT_NSEQ(@"Apple", [item2 title]); | 244 EXPECT_NSEQ(@"Apple", [item2 title]); |
242 } | 245 } |
243 | 246 |
244 // Test that the menu is created for a mix of windows and tabs. | 247 // Test that the menu is created for a mix of windows and tabs. |
245 TEST_F(HistoryMenuBridgeTest, RecentlyClosedTabsAndWindows) { | 248 TEST_F(HistoryMenuBridgeTest, RecentlyClosedTabsAndWindows) { |
246 scoped_ptr<MockTRS> trs(new MockTRS(profile())); | 249 std::unique_ptr<MockTRS> trs(new MockTRS(profile())); |
247 MockTRS::Entries entries; | 250 MockTRS::Entries entries; |
248 | 251 |
249 MockTRS::Tab tab1 = CreateSessionTab("http://google.com", "Google"); | 252 MockTRS::Tab tab1 = CreateSessionTab("http://google.com", "Google"); |
250 tab1.id = 24; | 253 tab1.id = 24; |
251 entries.push_back(&tab1); | 254 entries.push_back(&tab1); |
252 | 255 |
253 MockTRS::Window win1; | 256 MockTRS::Window win1; |
254 win1.id = 30; | 257 win1.id = 30; |
255 win1.tabs.push_back(CreateSessionTab("http://foo.com", "foo")); | 258 win1.tabs.push_back(CreateSessionTab("http://foo.com", "foo")); |
256 win1.tabs[0].id = 31; | 259 win1.tabs[0].id = 31; |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 image_result.image = gfx::Image::CreateFrom1xBitmap(bitmap); | 354 image_result.image = gfx::Image::CreateFrom1xBitmap(bitmap); |
352 GotFaviconData(&item, image_result); | 355 GotFaviconData(&item, image_result); |
353 | 356 |
354 // Make sure the callback works. | 357 // Make sure the callback works. |
355 EXPECT_FALSE(item.icon_requested); | 358 EXPECT_FALSE(item.icon_requested); |
356 EXPECT_TRUE(item.icon.get()); | 359 EXPECT_TRUE(item.icon.get()); |
357 EXPECT_TRUE([item.menu_item image]); | 360 EXPECT_TRUE([item.menu_item image]); |
358 } | 361 } |
359 | 362 |
360 } // namespace | 363 } // namespace |
OLD | NEW |