OLD | NEW |
1 // Copyright (c) 2008-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2008-2009 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/mac_util.h" | 8 #include "base/mac_util.h" |
9 | 9 |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 [[NSData alloc] initWithBytes:&(*png_representation)[0] | 50 [[NSData alloc] initWithBytes:&(*png_representation)[0] |
51 length:png_representation->size()]); | 51 length:png_representation->size()]); |
52 NSBitmapImageRep* rep = [NSBitmapImageRep imageRepWithData:image_data.get()]; | 52 NSBitmapImageRep* rep = [NSBitmapImageRep imageRepWithData:image_data.get()]; |
53 EXPECT_TRUE([rep isKindOfClass:[NSBitmapImageRep class]]); | 53 EXPECT_TRUE([rep isKindOfClass:[NSBitmapImageRep class]]); |
54 EXPECT_TRUE(CGImageGetWidth([rep CGImage]) == 400); | 54 EXPECT_TRUE(CGImageGetWidth([rep CGImage]) == 400); |
55 NSColor* color = [rep colorAtX:200 y:200]; | 55 NSColor* color = [rep colorAtX:200 y:200]; |
56 CGFloat red = 0, green = 0, blue = 0, alpha = 0; | 56 CGFloat red = 0, green = 0, blue = 0, alpha = 0; |
57 [color getRed:&red green:&green blue:&blue alpha:&alpha]; | 57 [color getRed:&red green:&green blue:&blue alpha:&alpha]; |
58 EXPECT_GE(red + green + blue, 3.0); | 58 EXPECT_GE(red + green + blue, 3.0); |
59 } | 59 } |
| 60 |
| 61 TEST_F(MacUtilTest, TestGetAppBundlePath) { |
| 62 FilePath out; |
| 63 |
| 64 // Make sure it doesn't crash. |
| 65 out = mac_util::GetAppBundlePath(FilePath()); |
| 66 EXPECT_TRUE(out.empty()); |
| 67 |
| 68 // Some more invalid inputs. |
| 69 const char* invalid_inputs[] = { |
| 70 "/", "/foo", "foo", "/foo/bar.", "foo/bar.", "/foo/bar./bazquux", |
| 71 "foo/bar./bazquux", "foo/.app", "//foo", |
| 72 }; |
| 73 for (size_t i = 0; i < arraysize(invalid_inputs); i++) { |
| 74 out = mac_util::GetAppBundlePath(FilePath(invalid_inputs[i])); |
| 75 EXPECT_TRUE(out.empty()) << "loop: " << i; |
| 76 } |
| 77 |
| 78 // Some valid inputs; this and |expected_outputs| should be in sync. |
| 79 struct { |
| 80 const char *in; |
| 81 const char *expected_out; |
| 82 } valid_inputs[] = { |
| 83 { "FooBar.app/", "FooBar.app" }, |
| 84 { "/FooBar.app", "/FooBar.app" }, |
| 85 { "/FooBar.app/", "/FooBar.app" }, |
| 86 { "//FooBar.app", "//FooBar.app" }, |
| 87 { "/Foo/Bar.app", "/Foo/Bar.app" }, |
| 88 { "/Foo/Bar.app/", "/Foo/Bar.app" }, |
| 89 { "/F/B.app", "/F/B.app" }, |
| 90 { "/F/B.app/", "/F/B.app" }, |
| 91 { "/Foo/Bar.app/baz", "/Foo/Bar.app" }, |
| 92 { "/Foo/Bar.app/baz/", "/Foo/Bar.app" }, |
| 93 { "/Foo/Bar.app/baz/quux.app/quuux", "/Foo/Bar.app" }, |
| 94 { "/Applications/Google Foo.app/bar/Foo Helper.app/quux/Foo Helper", |
| 95 "/Applications/Google Foo.app" }, |
| 96 }; |
| 97 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(valid_inputs); i++) { |
| 98 out = mac_util::GetAppBundlePath(FilePath(valid_inputs[i].in)); |
| 99 EXPECT_FALSE(out.empty()) << "loop: " << i; |
| 100 EXPECT_STREQ(valid_inputs[i].expected_out, |
| 101 out.value().c_str()) << "loop: " << i; |
| 102 } |
| 103 } |
OLD | NEW |