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

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

Issue 10870022: Change FaviconData to be able to return data for multiple bitmaps for same icon URL (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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 | Annotate | Revision Log
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 #import <Cocoa/Cocoa.h> 5 #import <Cocoa/Cocoa.h>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/memory/ref_counted_memory.h" 8 #include "base/memory/ref_counted_memory.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 tab.navigations.push_back( 96 tab.navigations.push_back(
97 TabNavigation(0, url, content::Referrer(), title, std::string(), 97 TabNavigation(0, url, content::Referrer(), title, std::string(),
98 content::PAGE_TRANSITION_LINK)); 98 content::PAGE_TRANSITION_LINK));
99 return tab; 99 return tab;
100 } 100 }
101 101
102 void GetFaviconForHistoryItem(HistoryMenuBridge::HistoryItem* item) { 102 void GetFaviconForHistoryItem(HistoryMenuBridge::HistoryItem* item) {
103 bridge_->GetFaviconForHistoryItem(item); 103 bridge_->GetFaviconForHistoryItem(item);
104 } 104 }
105 105
106 void GotFaviconData(FaviconService::Handle handle, 106 void GotFaviconData(
107 history::FaviconData favicon) { 107 FaviconService::Handle handle,
108 bridge_->GotFaviconData(handle, favicon); 108 const history::FaviconImageResult& image_result) {
109 bridge_->GotFaviconData(handle, image_result);
109 } 110 }
110 111
111 CancelableRequestConsumerTSimple<HistoryMenuBridge::HistoryItem*>& 112 CancelableRequestConsumerTSimple<HistoryMenuBridge::HistoryItem*>&
112 favicon_consumer() { 113 favicon_consumer() {
113 return bridge_->favicon_consumer_; 114 return bridge_->favicon_consumer_;
114 } 115 }
115 116
116 scoped_ptr<MockBridge> bridge_; 117 scoped_ptr<MockBridge> bridge_;
117 }; 118 };
118 119
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 EXPECT_GT(item.icon_handle, 0); 352 EXPECT_GT(item.icon_handle, 0);
352 } 353 }
353 354
354 TEST_F(HistoryMenuBridgeTest, GotFaviconData) { 355 TEST_F(HistoryMenuBridgeTest, GotFaviconData) {
355 // Create a dummy bitmap. 356 // Create a dummy bitmap.
356 SkBitmap bitmap; 357 SkBitmap bitmap;
357 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 25, 25); 358 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 25, 25);
358 bitmap.allocPixels(); 359 bitmap.allocPixels();
359 bitmap.eraseRGB(255, 0, 0); 360 bitmap.eraseRGB(255, 0, 0);
360 361
361 // Convert it to raw PNG bytes. We totally ignore color order here because
362 // we just want to test the roundtrip through the Bridge, not that we can
363 // make icons look pretty.
364 std::vector<unsigned char> raw;
365 gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, true, &raw);
366
367 // Set up the HistoryItem. 362 // Set up the HistoryItem.
368 HistoryMenuBridge::HistoryItem item; 363 HistoryMenuBridge::HistoryItem item;
369 item.menu_item.reset([[NSMenuItem alloc] init]); 364 item.menu_item.reset([[NSMenuItem alloc] init]);
370 GetFaviconForHistoryItem(&item); 365 GetFaviconForHistoryItem(&item);
371 366
372 // Pretend to be called back. 367 // Pretend to be called back.
373 history::FaviconData favicon; 368 history::FaviconImageResult image_result;
374 favicon.known_icon = true; 369 image_result.image = gfx::Image(bitmap);
375 favicon.image_data = new base::RefCountedBytes(raw); 370 GotFaviconData(item.icon_handle, image_result);
376 favicon.expired = false;
377 favicon.icon_url = GURL();
378 favicon.icon_type = history::FAVICON;
379 GotFaviconData(item.icon_handle, favicon);
380 371
381 // Make sure the callback works. 372 // Make sure the callback works.
382 EXPECT_FALSE(item.icon_requested); 373 EXPECT_FALSE(item.icon_requested);
383 EXPECT_TRUE(item.icon.get()); 374 EXPECT_TRUE(item.icon.get());
384 EXPECT_TRUE([item.menu_item image]); 375 EXPECT_TRUE([item.menu_item image]);
385 } 376 }
386 377
387 } // namespace 378 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698