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 <memory> | 9 #include <memory> |
10 #include <vector> | 10 #include <vector> |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 | 246 |
247 // 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. |
248 TEST_F(HistoryMenuBridgeTest, RecentlyClosedTabsAndWindows) { | 248 TEST_F(HistoryMenuBridgeTest, RecentlyClosedTabsAndWindows) { |
249 std::unique_ptr<MockTRS> trs(new MockTRS(profile())); | 249 std::unique_ptr<MockTRS> trs(new MockTRS(profile())); |
250 MockTRS::Entries entries; | 250 MockTRS::Entries entries; |
251 | 251 |
252 MockTRS::Tab tab1 = CreateSessionTab("http://google.com", "Google"); | 252 MockTRS::Tab tab1 = CreateSessionTab("http://google.com", "Google"); |
253 tab1.id = 24; | 253 tab1.id = 24; |
254 entries.push_back(&tab1); | 254 entries.push_back(&tab1); |
255 | 255 |
| 256 // TODO(sdy): The tab ids below *must* be set after all of them have been |
| 257 // pushed onto window.tabs. Otherwise, the ids will change when push_back |
| 258 // reallocates the vector's storage and calls each tabs' copy ctor. Ugh. |
| 259 |
256 MockTRS::Window win1; | 260 MockTRS::Window win1; |
257 win1.id = 30; | 261 win1.id = 30; |
258 win1.tabs.push_back(CreateSessionTab("http://foo.com", "foo")); | 262 win1.tabs.push_back(CreateSessionTab("http://foo.com", "foo")); |
| 263 win1.tabs.push_back(CreateSessionTab("http://bar.com", "bar")); |
259 win1.tabs[0].id = 31; | 264 win1.tabs[0].id = 31; |
260 win1.tabs.push_back(CreateSessionTab("http://bar.com", "bar")); | |
261 win1.tabs[1].id = 32; | 265 win1.tabs[1].id = 32; |
262 entries.push_back(&win1); | 266 entries.push_back(&win1); |
263 | 267 |
264 MockTRS::Tab tab2 = CreateSessionTab("http://apple.com", "Apple"); | 268 MockTRS::Tab tab2 = CreateSessionTab("http://apple.com", "Apple"); |
265 tab2.id = 42; | 269 tab2.id = 42; |
266 entries.push_back(&tab2); | 270 entries.push_back(&tab2); |
267 | 271 |
268 MockTRS::Window win2; | 272 MockTRS::Window win2; |
269 win2.id = 50; | 273 win2.id = 50; |
270 win2.tabs.push_back(CreateSessionTab("http://magic.com", "magic")); | 274 win2.tabs.push_back(CreateSessionTab("http://magic.com", "magic")); |
| 275 win2.tabs.push_back(CreateSessionTab("http://goats.com", "goats")); |
| 276 win2.tabs.push_back(CreateSessionTab("http://teleporter.com", "teleporter")); |
271 win2.tabs[0].id = 51; | 277 win2.tabs[0].id = 51; |
272 win2.tabs.push_back(CreateSessionTab("http://goats.com", "goats")); | |
273 win2.tabs[1].id = 52; | 278 win2.tabs[1].id = 52; |
274 win2.tabs.push_back(CreateSessionTab("http://teleporter.com", "teleporter")); | 279 win2.tabs[2].id = 53; |
275 win2.tabs[1].id = 53; | |
276 entries.push_back(&win2); | 280 entries.push_back(&win2); |
277 | 281 |
278 using ::testing::ReturnRef; | 282 using ::testing::ReturnRef; |
279 EXPECT_CALL(*trs.get(), entries()).WillOnce(ReturnRef(entries)); | 283 EXPECT_CALL(*trs.get(), entries()).WillOnce(ReturnRef(entries)); |
280 | 284 |
281 bridge_->TabRestoreServiceChanged(trs.get()); | 285 bridge_->TabRestoreServiceChanged(trs.get()); |
282 | 286 |
283 NSMenu* menu = bridge_->HistoryMenu(); | 287 NSMenu* menu = bridge_->HistoryMenu(); |
284 ASSERT_EQ(4U, [[menu itemArray] count]); | 288 ASSERT_EQ(4U, [[menu itemArray] count]); |
285 | 289 |
286 NSMenuItem* item1 = [menu itemAtIndex:0]; | 290 NSMenuItem* item1 = [menu itemAtIndex:0]; |
287 MockBridge::HistoryItem* hist1 = bridge_->HistoryItemForMenuItem(item1); | 291 MockBridge::HistoryItem* hist1 = bridge_->HistoryItemForMenuItem(item1); |
288 EXPECT_TRUE(hist1); | 292 EXPECT_TRUE(hist1); |
289 EXPECT_EQ(24, hist1->session_id); | 293 EXPECT_EQ(24, hist1->session_id); |
290 EXPECT_NSEQ(@"Google", [item1 title]); | 294 EXPECT_NSEQ(@"Google", [item1 title]); |
291 | 295 |
292 NSMenuItem* item2 = [menu itemAtIndex:1]; | 296 NSMenuItem* item2 = [menu itemAtIndex:1]; |
293 MockBridge::HistoryItem* hist2 = bridge_->HistoryItemForMenuItem(item2); | 297 MockBridge::HistoryItem* hist2 = bridge_->HistoryItemForMenuItem(item2); |
294 EXPECT_TRUE(hist2); | 298 EXPECT_TRUE(hist2); |
295 EXPECT_EQ(30, hist2->session_id); | 299 EXPECT_EQ(30, hist2->session_id); |
296 EXPECT_EQ(2U, hist2->tabs.size()); | 300 EXPECT_EQ(2U, hist2->tabs.size()); |
297 // Do not test menu item title because it is localized. | 301 // Do not test menu item title because it is localized. |
298 NSMenu* submenu1 = [item2 submenu]; | 302 NSMenu* submenu1 = [item2 submenu]; |
299 EXPECT_EQ(4U, [[submenu1 itemArray] count]); | 303 EXPECT_EQ(4U, [[submenu1 itemArray] count]); |
300 // Do not test Restore All Tabs because it is localiced. | 304 // Do not test Restore All Tabs because it is localiced. |
301 EXPECT_TRUE([[submenu1 itemAtIndex:1] isSeparatorItem]); | 305 EXPECT_TRUE([[submenu1 itemAtIndex:1] isSeparatorItem]); |
302 EXPECT_NSEQ(@"foo", [[submenu1 itemAtIndex:2] title]); | 306 EXPECT_NSEQ(@"foo", [[submenu1 itemAtIndex:2] title]); |
303 EXPECT_NSEQ(@"bar", [[submenu1 itemAtIndex:3] title]); | 307 EXPECT_NSEQ(@"bar", [[submenu1 itemAtIndex:3] title]); |
| 308 EXPECT_EQ(31, hist2->tabs[0]->session_id); |
| 309 EXPECT_EQ(32, hist2->tabs[1]->session_id); |
304 | 310 |
305 NSMenuItem* item3 = [menu itemAtIndex:2]; | 311 NSMenuItem* item3 = [menu itemAtIndex:2]; |
306 MockBridge::HistoryItem* hist3 = bridge_->HistoryItemForMenuItem(item3); | 312 MockBridge::HistoryItem* hist3 = bridge_->HistoryItemForMenuItem(item3); |
307 EXPECT_TRUE(hist3); | 313 EXPECT_TRUE(hist3); |
308 EXPECT_EQ(42, hist3->session_id); | 314 EXPECT_EQ(42, hist3->session_id); |
309 EXPECT_NSEQ(@"Apple", [item3 title]); | 315 EXPECT_NSEQ(@"Apple", [item3 title]); |
310 | 316 |
311 NSMenuItem* item4 = [menu itemAtIndex:3]; | 317 NSMenuItem* item4 = [menu itemAtIndex:3]; |
312 MockBridge::HistoryItem* hist4 = bridge_->HistoryItemForMenuItem(item4); | 318 MockBridge::HistoryItem* hist4 = bridge_->HistoryItemForMenuItem(item4); |
313 EXPECT_TRUE(hist4); | 319 EXPECT_TRUE(hist4); |
314 EXPECT_EQ(50, hist4->session_id); | 320 EXPECT_EQ(50, hist4->session_id); |
315 EXPECT_EQ(3U, hist4->tabs.size()); | 321 EXPECT_EQ(3U, hist4->tabs.size()); |
316 // Do not test menu item title because it is localized. | 322 // Do not test menu item title because it is localized. |
317 NSMenu* submenu2 = [item4 submenu]; | 323 NSMenu* submenu2 = [item4 submenu]; |
318 EXPECT_EQ(5U, [[submenu2 itemArray] count]); | 324 EXPECT_EQ(5U, [[submenu2 itemArray] count]); |
319 // Do not test Restore All Tabs because it is localiced. | 325 // Do not test Restore All Tabs because it is localiced. |
320 EXPECT_TRUE([[submenu2 itemAtIndex:1] isSeparatorItem]); | 326 EXPECT_TRUE([[submenu2 itemAtIndex:1] isSeparatorItem]); |
321 EXPECT_NSEQ(@"magic", [[submenu2 itemAtIndex:2] title]); | 327 EXPECT_NSEQ(@"magic", [[submenu2 itemAtIndex:2] title]); |
322 EXPECT_NSEQ(@"goats", [[submenu2 itemAtIndex:3] title]); | 328 EXPECT_NSEQ(@"goats", [[submenu2 itemAtIndex:3] title]); |
323 EXPECT_NSEQ(@"teleporter", [[submenu2 itemAtIndex:4] title]); | 329 EXPECT_NSEQ(@"teleporter", [[submenu2 itemAtIndex:4] title]); |
| 330 EXPECT_EQ(51, hist4->tabs[0]->session_id); |
| 331 EXPECT_EQ(52, hist4->tabs[1]->session_id); |
| 332 EXPECT_EQ(53, hist4->tabs[2]->session_id); |
324 } | 333 } |
325 | 334 |
326 // Tests that we properly request an icon from the FaviconService. | 335 // Tests that we properly request an icon from the FaviconService. |
327 TEST_F(HistoryMenuBridgeTest, GetFaviconForHistoryItem) { | 336 TEST_F(HistoryMenuBridgeTest, GetFaviconForHistoryItem) { |
328 // Create a fake item. | 337 // Create a fake item. |
329 HistoryMenuBridge::HistoryItem item; | 338 HistoryMenuBridge::HistoryItem item; |
330 item.title = base::ASCIIToUTF16("Title"); | 339 item.title = base::ASCIIToUTF16("Title"); |
331 item.url = GURL("http://google.com"); | 340 item.url = GURL("http://google.com"); |
332 | 341 |
333 // Request the icon. | 342 // Request the icon. |
(...skipping 20 matching lines...) Expand all Loading... |
354 image_result.image = gfx::Image::CreateFrom1xBitmap(bitmap); | 363 image_result.image = gfx::Image::CreateFrom1xBitmap(bitmap); |
355 GotFaviconData(&item, image_result); | 364 GotFaviconData(&item, image_result); |
356 | 365 |
357 // Make sure the callback works. | 366 // Make sure the callback works. |
358 EXPECT_FALSE(item.icon_requested); | 367 EXPECT_FALSE(item.icon_requested); |
359 EXPECT_TRUE(item.icon.get()); | 368 EXPECT_TRUE(item.icon.get()); |
360 EXPECT_TRUE([item.menu_item image]); | 369 EXPECT_TRUE([item.menu_item image]); |
361 } | 370 } |
362 | 371 |
363 } // namespace | 372 } // namespace |
OLD | NEW |