OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 14 matching lines...) Expand all Loading... |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 #include "public/platform/WebImage.h" | 32 #include "public/platform/WebImage.h" |
33 | 33 |
34 #include <gtest/gtest.h> | 34 #include <gtest/gtest.h> |
35 #include "core/platform/FileSystem.h" | |
36 #include "core/platform/SharedBuffer.h" | 35 #include "core/platform/SharedBuffer.h" |
37 #include "public/platform/Platform.h" | 36 #include "public/platform/Platform.h" |
38 #include "public/platform/WebData.h" | 37 #include "public/platform/WebData.h" |
39 #include "public/platform/WebSize.h" | 38 #include "public/platform/WebSize.h" |
40 #include "public/platform/WebUnitTestSupport.h" | 39 #include "public/platform/WebUnitTestSupport.h" |
41 | 40 |
42 using namespace WebCore; | 41 using namespace WebCore; |
43 using namespace WebKit; | 42 using namespace WebKit; |
44 | 43 |
45 namespace { | 44 namespace { |
46 | 45 |
47 static PassRefPtr<SharedBuffer> readFile(const char* fileName) | 46 static PassRefPtr<SharedBuffer> readFile(const char* fileName) |
48 { | 47 { |
49 String filePath = Platform::current()->unitTestSupport()->webKitRootDir(); | 48 String filePath = Platform::current()->unitTestSupport()->webKitRootDir(); |
50 filePath.append("/Source/web/tests/data/"); | 49 filePath.append("/Source/web/tests/data/"); |
51 filePath.append(fileName); | 50 filePath.append(fileName); |
52 | 51 |
53 long long fileSize; | 52 return Platform::current()->unitTestSupport()->readFromFile(filePath); |
54 if (!getFileSize(filePath, fileSize)) | |
55 return 0; | |
56 | |
57 PlatformFileHandle handle = openFile(filePath, OpenForRead); | |
58 int fileLength = static_cast<int>(fileSize); | |
59 Vector<char> buffer(fileLength); | |
60 readFromFile(handle, buffer.data(), fileLength); | |
61 closeFile(handle); | |
62 return SharedBuffer::adoptVector(buffer); | |
63 } | 53 } |
64 | 54 |
65 TEST(WebImageTest, PNGImage) | 55 TEST(WebImageTest, PNGImage) |
66 { | 56 { |
67 RefPtr<SharedBuffer> data = readFile("white-1x1.png"); | 57 RefPtr<SharedBuffer> data = readFile("white-1x1.png"); |
68 ASSERT_TRUE(data.get()); | 58 ASSERT_TRUE(data.get()); |
69 | 59 |
70 WebImage image = WebImage::fromData(WebData(data), WebSize()); | 60 WebImage image = WebImage::fromData(WebData(data), WebSize()); |
71 EXPECT_TRUE(image.size() == WebSize(1, 1)); | 61 EXPECT_TRUE(image.size() == WebSize(1, 1)); |
72 SkAutoLockPixels autoLock(image.getSkBitmap()); | 62 SkAutoLockPixels autoLock(image.getSkBitmap()); |
(...skipping 29 matching lines...) Expand all Loading... |
102 const char badImage[] = "hello world"; | 92 const char badImage[] = "hello world"; |
103 WebVector<WebImage> images = WebImage::framesFromData(WebData(badImage)); | 93 WebVector<WebImage> images = WebImage::framesFromData(WebData(badImage)); |
104 ASSERT_EQ(0u, images.size()); | 94 ASSERT_EQ(0u, images.size()); |
105 | 95 |
106 WebImage image = WebImage::fromData(WebData(badImage), WebSize()); | 96 WebImage image = WebImage::fromData(WebData(badImage), WebSize()); |
107 EXPECT_TRUE(image.getSkBitmap().empty()); | 97 EXPECT_TRUE(image.getSkBitmap().empty()); |
108 EXPECT_TRUE(image.getSkBitmap().isNull()); | 98 EXPECT_TRUE(image.getSkBitmap().isNull()); |
109 } | 99 } |
110 | 100 |
111 } // namespace | 101 } // namespace |
OLD | NEW |