Chromium Code Reviews| 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" | 5 #include "chrome/browser/ui/cocoa/history_menu_bridge.h" | 
| 6 | 6 | 
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> | 
| 8 | 8 | 
| 9 #include <initializer_list> | 9 #include <initializer_list> | 
| 10 #include <memory> | 10 #include <memory> | 
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 | 91 | 
| 92 HistoryMenuBridge::HistoryItem* CreateItem(const base::string16& title) { | 92 HistoryMenuBridge::HistoryItem* CreateItem(const base::string16& title) { | 
| 93 HistoryMenuBridge::HistoryItem* item = | 93 HistoryMenuBridge::HistoryItem* item = | 
| 94 new HistoryMenuBridge::HistoryItem(); | 94 new HistoryMenuBridge::HistoryItem(); | 
| 95 item->title = title; | 95 item->title = title; | 
| 96 item->url = GURL(title); | 96 item->url = GURL(title); | 
| 97 return item; | 97 return item; | 
| 98 } | 98 } | 
| 99 | 99 | 
| 100 MockTRS::Entries CreateSessionEntries( | 100 MockTRS::Entries CreateSessionEntries( | 
| 101 std::vector<std::unique_ptr<MockTRS::Entry>>* out, | |
| 102 std::initializer_list<MockTRS::Entry*> entries) { | 101 std::initializer_list<MockTRS::Entry*> entries) { | 
| 103 MockTRS::Entries ret; | 102 MockTRS::Entries ret; | 
| 104 out->reserve(out->size() + entries.size()); | |
| 105 for (auto* entry : entries) { | 103 for (auto* entry : entries) { | 
| 
 
sky
2016/08/04 16:34:38
no {}
 
 | |
| 106 ret.emplace_back(entry); | 104 ret.emplace_back(entry); | 
| 107 out->emplace_back(entry); | |
| 108 } | 105 } | 
| 109 return ret; | 106 return ret; | 
| 110 } | 107 } | 
| 111 | 108 | 
| 112 MockTRS::Tab* CreateSessionTab(SessionID::id_type id, | 109 MockTRS::Tab* CreateSessionTab(SessionID::id_type id, | 
| 113 const std::string& url, | 110 const std::string& url, | 
| 114 const std::string& title) { | 111 const std::string& title) { | 
| 115 auto tab = new MockTRS::Tab; | 112 auto tab = new MockTRS::Tab; | 
| 116 tab->id = id; | 113 tab->id = id; | 
| 117 tab->current_navigation_index = 0; | 114 tab->current_navigation_index = 0; | 
| 118 tab->navigations.push_back( | 115 tab->navigations.push_back( | 
| 119 sessions::SerializedNavigationEntryTestHelper::CreateNavigation(url, | 116 sessions::SerializedNavigationEntryTestHelper::CreateNavigation(url, | 
| 120 title)); | 117 title)); | 
| 121 return tab; | 118 return tab; | 
| 122 } | 119 } | 
| 123 | 120 | 
| 124 MockTRS::Window* CreateSessionWindow( | 121 MockTRS::Window* CreateSessionWindow( | 
| 125 SessionID::id_type id, | 122 SessionID::id_type id, | 
| 126 std::initializer_list<MockTRS::Tab*> tabs) { | 123 std::initializer_list<MockTRS::Tab*> tabs) { | 
| 127 auto window = new MockTRS::Window; | 124 auto window = new MockTRS::Window; | 
| 128 window->id = id; | 125 window->id = id; | 
| 129 window->tabs.reserve(tabs.size()); | 126 window->tabs.reserve(tabs.size()); | 
| 130 for (auto* tab : tabs) { | 127 for (auto* tab : tabs) | 
| 131 window->tabs.emplace_back(std::move(*tab)); | 128 window->tabs.emplace_back(std::move(tab)); | 
| 132 delete tab; | |
| 133 } | |
| 134 return window; | 129 return window; | 
| 135 } | 130 } | 
| 136 | 131 | 
| 137 void GetFaviconForHistoryItem(HistoryMenuBridge::HistoryItem* item) { | 132 void GetFaviconForHistoryItem(HistoryMenuBridge::HistoryItem* item) { | 
| 138 bridge_->GetFaviconForHistoryItem(item); | 133 bridge_->GetFaviconForHistoryItem(item); | 
| 139 } | 134 } | 
| 140 | 135 | 
| 141 void GotFaviconData(HistoryMenuBridge::HistoryItem* item, | 136 void GotFaviconData(HistoryMenuBridge::HistoryItem* item, | 
| 142 const favicon_base::FaviconImageResult& image_result) { | 137 const favicon_base::FaviconImageResult& image_result) { | 
| 143 bridge_->GotFaviconData(item, image_result); | 138 bridge_->GotFaviconData(item, image_result); | 
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 234 // Confirm tooltips and confirm they are not trimmed (like the item | 229 // Confirm tooltips and confirm they are not trimmed (like the item | 
| 235 // name might be). Add tolerance for URL fixer-upping; | 230 // name might be). Add tolerance for URL fixer-upping; | 
| 236 // e.g. http://foo becomes http://foo/) | 231 // e.g. http://foo becomes http://foo/) | 
| 237 EXPECT_GE([[[menu itemAtIndex:0] toolTip] length], (2*short_url.length()-5)); | 232 EXPECT_GE([[[menu itemAtIndex:0] toolTip] length], (2*short_url.length()-5)); | 
| 238 EXPECT_GE([[[menu itemAtIndex:1] toolTip] length], (2*long_url.length()-5)); | 233 EXPECT_GE([[[menu itemAtIndex:1] toolTip] length], (2*long_url.length()-5)); | 
| 239 } | 234 } | 
| 240 | 235 | 
| 241 // Test that the menu is created for a set of simple tabs. | 236 // Test that the menu is created for a set of simple tabs. | 
| 242 TEST_F(HistoryMenuBridgeTest, RecentlyClosedTabs) { | 237 TEST_F(HistoryMenuBridgeTest, RecentlyClosedTabs) { | 
| 243 std::unique_ptr<MockTRS> trs(new MockTRS(profile())); | 238 std::unique_ptr<MockTRS> trs(new MockTRS(profile())); | 
| 244 std::vector<std::unique_ptr<MockTRS::Entry>> hold_entries; | 239 auto entries{CreateSessionEntries({ | 
| 245 auto entries{CreateSessionEntries(&hold_entries, { | |
| 246 CreateSessionTab(24, "http://google.com", "Google"), | 240 CreateSessionTab(24, "http://google.com", "Google"), | 
| 247 CreateSessionTab(42, "http://apple.com", "Apple"), | 241 CreateSessionTab(42, "http://apple.com", "Apple"), | 
| 248 })}; | 242 })}; | 
| 249 | 243 | 
| 250 using ::testing::ReturnRef; | 244 using ::testing::ReturnRef; | 
| 251 EXPECT_CALL(*trs.get(), entries()).WillOnce(ReturnRef(entries)); | 245 EXPECT_CALL(*trs.get(), entries()).WillOnce(ReturnRef(entries)); | 
| 252 | 246 | 
| 253 bridge_->TabRestoreServiceChanged(trs.get()); | 247 bridge_->TabRestoreServiceChanged(trs.get()); | 
| 254 | 248 | 
| 255 NSMenu* menu = bridge_->HistoryMenu(); | 249 NSMenu* menu = bridge_->HistoryMenu(); | 
| 256 ASSERT_EQ(2U, [[menu itemArray] count]); | 250 ASSERT_EQ(2U, [[menu itemArray] count]); | 
| 257 | 251 | 
| 258 NSMenuItem* item1 = [menu itemAtIndex:0]; | 252 NSMenuItem* item1 = [menu itemAtIndex:0]; | 
| 259 MockBridge::HistoryItem* hist1 = bridge_->HistoryItemForMenuItem(item1); | 253 MockBridge::HistoryItem* hist1 = bridge_->HistoryItemForMenuItem(item1); | 
| 260 EXPECT_TRUE(hist1); | 254 EXPECT_TRUE(hist1); | 
| 261 EXPECT_EQ(24, hist1->session_id); | 255 EXPECT_EQ(24, hist1->session_id); | 
| 262 EXPECT_NSEQ(@"Google", [item1 title]); | 256 EXPECT_NSEQ(@"Google", [item1 title]); | 
| 263 | 257 | 
| 264 NSMenuItem* item2 = [menu itemAtIndex:1]; | 258 NSMenuItem* item2 = [menu itemAtIndex:1]; | 
| 265 MockBridge::HistoryItem* hist2 = bridge_->HistoryItemForMenuItem(item2); | 259 MockBridge::HistoryItem* hist2 = bridge_->HistoryItemForMenuItem(item2); | 
| 266 EXPECT_TRUE(hist2); | 260 EXPECT_TRUE(hist2); | 
| 267 EXPECT_EQ(42, hist2->session_id); | 261 EXPECT_EQ(42, hist2->session_id); | 
| 268 EXPECT_NSEQ(@"Apple", [item2 title]); | 262 EXPECT_NSEQ(@"Apple", [item2 title]); | 
| 269 } | 263 } | 
| 270 | 264 | 
| 271 // Test that the menu is created for a mix of windows and tabs. | 265 // Test that the menu is created for a mix of windows and tabs. | 
| 272 TEST_F(HistoryMenuBridgeTest, RecentlyClosedTabsAndWindows) { | 266 TEST_F(HistoryMenuBridgeTest, RecentlyClosedTabsAndWindows) { | 
| 273 std::unique_ptr<MockTRS> trs(new MockTRS(profile())); | 267 std::unique_ptr<MockTRS> trs(new MockTRS(profile())); | 
| 274 std::vector<std::unique_ptr<MockTRS::Entry>> hold_entries; | 268 auto entries{CreateSessionEntries({ | 
| 275 auto entries{CreateSessionEntries(&hold_entries, { | |
| 276 CreateSessionTab(24, "http://google.com", "Google"), | 269 CreateSessionTab(24, "http://google.com", "Google"), | 
| 277 CreateSessionWindow(30, { | 270 CreateSessionWindow(30, { | 
| 278 CreateSessionTab(31, "http://foo.com", "foo"), | 271 CreateSessionTab(31, "http://foo.com", "foo"), | 
| 279 CreateSessionTab(32, "http://bar.com", "bar"), | 272 CreateSessionTab(32, "http://bar.com", "bar"), | 
| 280 }), | 273 }), | 
| 281 CreateSessionTab(42, "http://apple.com", "Apple"), | 274 CreateSessionTab(42, "http://apple.com", "Apple"), | 
| 282 CreateSessionWindow(50, { | 275 CreateSessionWindow(50, { | 
| 283 CreateSessionTab(51, "http://magic.com", "magic"), | 276 CreateSessionTab(51, "http://magic.com", "magic"), | 
| 284 CreateSessionTab(52, "http://goats.com", "goats"), | 277 CreateSessionTab(52, "http://goats.com", "goats"), | 
| 285 CreateSessionTab(53, "http://teleporter.com", "teleporter"), | 278 CreateSessionTab(53, "http://teleporter.com", "teleporter"), | 
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 370 image_result.image = gfx::Image::CreateFrom1xBitmap(bitmap); | 363 image_result.image = gfx::Image::CreateFrom1xBitmap(bitmap); | 
| 371 GotFaviconData(&item, image_result); | 364 GotFaviconData(&item, image_result); | 
| 372 | 365 | 
| 373 // Make sure the callback works. | 366 // Make sure the callback works. | 
| 374 EXPECT_FALSE(item.icon_requested); | 367 EXPECT_FALSE(item.icon_requested); | 
| 375 EXPECT_TRUE(item.icon.get()); | 368 EXPECT_TRUE(item.icon.get()); | 
| 376 EXPECT_TRUE([item.menu_item image]); | 369 EXPECT_TRUE([item.menu_item image]); | 
| 377 } | 370 } | 
| 378 | 371 | 
| 379 } // namespace | 372 } // namespace | 
| OLD | NEW |