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

Side by Side Diff: chrome/browser/cocoa/cocoa_utils_unittest.mm

Issue 131018: Add favicons to tabs on the Mac (Closed)
Patch Set: Rebase Created 11 years, 6 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
« no previous file with comments | « chrome/browser/cocoa/cocoa_utils.mm ('k') | chrome/browser/cocoa/tab_strip_controller.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #import "chrome/browser/cocoa/cocoa_utils.h"
6 #import "chrome/browser/cocoa/cocoa_test_helper.h"
7 #include "testing/gtest/include/gtest/gtest.h"
8
9 namespace {
10
11 class CocoaUtilsTest : public testing::Test {
12 public:
13 CocoaTestHelper cocoa_helper_; // Inits Cocoa, creates window, etc...
14
15 // If not red, is blue.
16 // If not tfbit (twenty-four-bit), is 444.
17 void ShapeHelper(int width, int height, bool isred, bool tfbit);
18 };
19
20 void CocoaUtilsTest::ShapeHelper(int width, int height,
21 bool isred, bool tfbit) {
22 SkBitmap thing;
23
24 if (tfbit)
25 thing.setConfig(SkBitmap::kARGB_8888_Config, width, height);
26 else
27 thing.setConfig(SkBitmap::kARGB_4444_Config, width, height);
28 thing.allocPixels();
29
30 if (isred)
31 thing.eraseRGB(0xff, 0, 0);
32 else
33 thing.eraseRGB(0, 0, 0xff);
34
35 // Confirm size
36 NSImage* image = CocoaUtils::SkBitmapToNSImage(thing);
37 EXPECT_DOUBLE_EQ([image size].width, (double)width);
38 EXPECT_DOUBLE_EQ([image size].height, (double)height);
39
40 // Get the color of a pixel and make sure it looks fine
41 [image lockFocus];
42
43 int x = width > 17 ? 17 : 0;
44 int y = height > 17 ? 17 : 0;
45 NSColor* color = NSReadPixel(NSMakePoint(x, y));
46 CGFloat red = 0, green = 0, blue = 0, alpha = 0;
47 [image unlockFocus];
48 [color getRed:&red green:&green blue:&blue alpha:&alpha];
49
50 // Be tolerant of floating point rounding, gamma, etc.
51 if (isred) {
52 EXPECT_GT(red, 0.8);
53 EXPECT_LT(blue, 0.2);
54 } else {
55 EXPECT_LT(red, 0.2);
56 EXPECT_GT(blue, 0.8);
57 }
58 EXPECT_LT(green, 0.2);
59 EXPECT_GT(alpha, 0.9);
60 }
61
62
63 TEST_F(CocoaUtilsTest, BitmapToNSImage_RedSquare64x64) {
64 ShapeHelper(64, 64, true, true);
65 }
66
67 TEST_F(CocoaUtilsTest, BitmapToNSImage_BlueRectangle199x19) {
68 ShapeHelper(199, 19, false, true);
69 }
70
71 TEST_F(CocoaUtilsTest, BitmapToNSImage_BlueRectangle444) {
72 ShapeHelper(200, 200, false, false);
73 }
74
75
76 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/cocoa_utils.mm ('k') | chrome/browser/cocoa/tab_strip_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698