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

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