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

Side by Side Diff: chrome/browser/ui/cocoa/history_menu_bridge_unittest.mm

Issue 2200993004: Make TabRestoreService::Entry noncopyable and fix up surrounding code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@tab-test-cleanup
Patch Set: Created 4 years, 4 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
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 #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
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()); 103 out->reserve(out->size() + entries.size());
105 for (auto* entry : entries) { 104 for (auto* entry : entries) {
106 ret.emplace_back(entry); 105 ret.emplace_back(entry);
107 out->emplace_back(entry);
108 } 106 }
109 return ret; 107 return ret;
110 } 108 }
111 109
112 MockTRS::Tab* CreateSessionTab(SessionID::id_type id, 110 MockTRS::Tab* CreateSessionTab(SessionID::id_type id,
113 const std::string& url, 111 const std::string& url,
114 const std::string& title) { 112 const std::string& title) {
115 auto tab = new MockTRS::Tab; 113 auto tab = new MockTRS::Tab;
116 tab->id = id; 114 tab->id = id;
117 tab->current_navigation_index = 0; 115 tab->current_navigation_index = 0;
118 tab->navigations.push_back( 116 tab->navigations.push_back(
119 sessions::SerializedNavigationEntryTestHelper::CreateNavigation(url, 117 sessions::SerializedNavigationEntryTestHelper::CreateNavigation(url,
120 title)); 118 title));
121 return tab; 119 return tab;
122 } 120 }
123 121
124 MockTRS::Window* CreateSessionWindow( 122 MockTRS::Window* CreateSessionWindow(
125 SessionID::id_type id, 123 SessionID::id_type id,
126 std::initializer_list<MockTRS::Tab*> tabs) { 124 std::initializer_list<MockTRS::Tab*> tabs) {
127 auto window = new MockTRS::Window; 125 auto window = new MockTRS::Window;
128 window->id = id; 126 window->id = id;
129 window->tabs.reserve(tabs.size()); 127 window->tabs.reserve(tabs.size());
130 for (auto* tab : tabs) { 128 for (auto* tab : tabs) {
131 window->tabs.emplace_back(std::move(*tab)); 129 window->tabs.emplace_back(std::move(tab));
132 delete tab;
133 } 130 }
134 return window; 131 return window;
135 } 132 }
136 133
137 void GetFaviconForHistoryItem(HistoryMenuBridge::HistoryItem* item) { 134 void GetFaviconForHistoryItem(HistoryMenuBridge::HistoryItem* item) {
138 bridge_->GetFaviconForHistoryItem(item); 135 bridge_->GetFaviconForHistoryItem(item);
139 } 136 }
140 137
141 void GotFaviconData(HistoryMenuBridge::HistoryItem* item, 138 void GotFaviconData(HistoryMenuBridge::HistoryItem* item,
142 const favicon_base::FaviconImageResult& image_result) { 139 const favicon_base::FaviconImageResult& image_result) {
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 // Confirm tooltips and confirm they are not trimmed (like the item 231 // Confirm tooltips and confirm they are not trimmed (like the item
235 // name might be). Add tolerance for URL fixer-upping; 232 // name might be). Add tolerance for URL fixer-upping;
236 // e.g. http://foo becomes http://foo/) 233 // e.g. http://foo becomes http://foo/)
237 EXPECT_GE([[[menu itemAtIndex:0] toolTip] length], (2*short_url.length()-5)); 234 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)); 235 EXPECT_GE([[[menu itemAtIndex:1] toolTip] length], (2*long_url.length()-5));
239 } 236 }
240 237
241 // Test that the menu is created for a set of simple tabs. 238 // Test that the menu is created for a set of simple tabs.
242 TEST_F(HistoryMenuBridgeTest, RecentlyClosedTabs) { 239 TEST_F(HistoryMenuBridgeTest, RecentlyClosedTabs) {
243 std::unique_ptr<MockTRS> trs(new MockTRS(profile())); 240 std::unique_ptr<MockTRS> trs(new MockTRS(profile()));
244 std::vector<std::unique_ptr<MockTRS::Entry>> hold_entries; 241 auto entries{CreateSessionEntries({
245 auto entries{CreateSessionEntries(&hold_entries, {
246 CreateSessionTab(24, "http://google.com", "Google"), 242 CreateSessionTab(24, "http://google.com", "Google"),
247 CreateSessionTab(42, "http://apple.com", "Apple"), 243 CreateSessionTab(42, "http://apple.com", "Apple"),
248 })}; 244 })};
249 245
250 using ::testing::ReturnRef; 246 using ::testing::ReturnRef;
251 EXPECT_CALL(*trs.get(), entries()).WillOnce(ReturnRef(entries)); 247 EXPECT_CALL(*trs.get(), entries()).WillOnce(ReturnRef(entries));
252 248
253 bridge_->TabRestoreServiceChanged(trs.get()); 249 bridge_->TabRestoreServiceChanged(trs.get());
254 250
255 NSMenu* menu = bridge_->HistoryMenu(); 251 NSMenu* menu = bridge_->HistoryMenu();
256 ASSERT_EQ(2U, [[menu itemArray] count]); 252 ASSERT_EQ(2U, [[menu itemArray] count]);
257 253
258 NSMenuItem* item1 = [menu itemAtIndex:0]; 254 NSMenuItem* item1 = [menu itemAtIndex:0];
259 MockBridge::HistoryItem* hist1 = bridge_->HistoryItemForMenuItem(item1); 255 MockBridge::HistoryItem* hist1 = bridge_->HistoryItemForMenuItem(item1);
260 EXPECT_TRUE(hist1); 256 EXPECT_TRUE(hist1);
261 EXPECT_EQ(24, hist1->session_id); 257 EXPECT_EQ(24, hist1->session_id);
262 EXPECT_NSEQ(@"Google", [item1 title]); 258 EXPECT_NSEQ(@"Google", [item1 title]);
263 259
264 NSMenuItem* item2 = [menu itemAtIndex:1]; 260 NSMenuItem* item2 = [menu itemAtIndex:1];
265 MockBridge::HistoryItem* hist2 = bridge_->HistoryItemForMenuItem(item2); 261 MockBridge::HistoryItem* hist2 = bridge_->HistoryItemForMenuItem(item2);
266 EXPECT_TRUE(hist2); 262 EXPECT_TRUE(hist2);
267 EXPECT_EQ(42, hist2->session_id); 263 EXPECT_EQ(42, hist2->session_id);
268 EXPECT_NSEQ(@"Apple", [item2 title]); 264 EXPECT_NSEQ(@"Apple", [item2 title]);
269 } 265 }
270 266
271 // Test that the menu is created for a mix of windows and tabs. 267 // Test that the menu is created for a mix of windows and tabs.
272 TEST_F(HistoryMenuBridgeTest, RecentlyClosedTabsAndWindows) { 268 TEST_F(HistoryMenuBridgeTest, RecentlyClosedTabsAndWindows) {
273 std::unique_ptr<MockTRS> trs(new MockTRS(profile())); 269 std::unique_ptr<MockTRS> trs(new MockTRS(profile()));
274 std::vector<std::unique_ptr<MockTRS::Entry>> hold_entries; 270 auto entries{CreateSessionEntries({
275 auto entries{CreateSessionEntries(&hold_entries, {
276 CreateSessionTab(24, "http://google.com", "Google"), 271 CreateSessionTab(24, "http://google.com", "Google"),
277 CreateSessionWindow(30, { 272 CreateSessionWindow(30, {
278 CreateSessionTab(31, "http://foo.com", "foo"), 273 CreateSessionTab(31, "http://foo.com", "foo"),
279 CreateSessionTab(32, "http://bar.com", "bar"), 274 CreateSessionTab(32, "http://bar.com", "bar"),
280 }), 275 }),
281 CreateSessionTab(42, "http://apple.com", "Apple"), 276 CreateSessionTab(42, "http://apple.com", "Apple"),
282 CreateSessionWindow(50, { 277 CreateSessionWindow(50, {
283 CreateSessionTab(51, "http://magic.com", "magic"), 278 CreateSessionTab(51, "http://magic.com", "magic"),
284 CreateSessionTab(52, "http://goats.com", "goats"), 279 CreateSessionTab(52, "http://goats.com", "goats"),
285 CreateSessionTab(53, "http://teleporter.com", "teleporter"), 280 CreateSessionTab(53, "http://teleporter.com", "teleporter"),
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 image_result.image = gfx::Image::CreateFrom1xBitmap(bitmap); 365 image_result.image = gfx::Image::CreateFrom1xBitmap(bitmap);
371 GotFaviconData(&item, image_result); 366 GotFaviconData(&item, image_result);
372 367
373 // Make sure the callback works. 368 // Make sure the callback works.
374 EXPECT_FALSE(item.icon_requested); 369 EXPECT_FALSE(item.icon_requested);
375 EXPECT_TRUE(item.icon.get()); 370 EXPECT_TRUE(item.icon.get());
376 EXPECT_TRUE([item.menu_item image]); 371 EXPECT_TRUE([item.menu_item image]);
377 } 372 }
378 373
379 } // namespace 374 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/history_menu_bridge.mm ('k') | chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698