Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "mojo/public/cpp/bindings/binding_set.h" | 9 #include "mojo/public/cpp/bindings/binding_set.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 72 TEST_F(ImageTraitsTest, NullImageSkiaRep) { | 72 TEST_F(ImageTraitsTest, NullImageSkiaRep) { |
| 73 ImageSkiaRep null_rep; | 73 ImageSkiaRep null_rep; |
| 74 ASSERT_TRUE(null_rep.is_null()); | 74 ASSERT_TRUE(null_rep.is_null()); |
| 75 | 75 |
| 76 ImageSkiaRep output(gfx::Size(1, 1), 1.0f); | 76 ImageSkiaRep output(gfx::Size(1, 1), 1.0f); |
| 77 ASSERT_FALSE(output.is_null()); | 77 ASSERT_FALSE(output.is_null()); |
| 78 service()->EchoImageSkiaRep(null_rep, &output); | 78 service()->EchoImageSkiaRep(null_rep, &output); |
| 79 EXPECT_TRUE(output.is_null()); | 79 EXPECT_TRUE(output.is_null()); |
| 80 } | 80 } |
| 81 | 81 |
| 82 TEST_F(ImageTraitsTest, EmptyImageSkiaRep) { | 82 TEST_F(ImageTraitsTest, EmptyImageSkiaRepBecomesNull) { |
| 83 SkBitmap empty_bitmap; | 83 SkBitmap empty_bitmap; |
| 84 empty_bitmap.allocN32Pixels(0, 0); | 84 empty_bitmap.allocN32Pixels(0, 0); |
| 85 // Empty SkBitmap is not null. | 85 // Empty SkBitmap is not null. |
| 86 EXPECT_FALSE(empty_bitmap.isNull()); | 86 EXPECT_FALSE(empty_bitmap.isNull()); |
| 87 EXPECT_TRUE(empty_bitmap.drawsNothing()); | 87 EXPECT_TRUE(empty_bitmap.drawsNothing()); |
| 88 | 88 |
| 89 ImageSkiaRep empty_rep(empty_bitmap, 1.0f); | 89 ImageSkiaRep empty_rep(empty_bitmap, 1.0f); |
| 90 // ImageSkiaRep with empty bitmap is not null. | 90 // ImageSkiaRep with empty bitmap is not null. |
| 91 ASSERT_FALSE(empty_rep.is_null()); | 91 ASSERT_FALSE(empty_rep.is_null()); |
| 92 | 92 |
| 93 ImageSkiaRep output(gfx::Size(1, 1), 1.0f); | 93 ImageSkiaRep output(gfx::Size(1, 1), 1.0f); |
| 94 ASSERT_FALSE(output.is_null()); | 94 ASSERT_FALSE(output.is_null()); |
| 95 service()->EchoImageSkiaRep(empty_rep, &output); | 95 service()->EchoImageSkiaRep(empty_rep, &output); |
| 96 EXPECT_TRUE(empty_rep.sk_bitmap().drawsNothing()); | 96 // After transport, output rep has no underlying buffer but has valid size. |
| 97 EXPECT_TRUE(test::AreBitmapsEqual(empty_rep.sk_bitmap(), output.sk_bitmap())); | 97 EXPECT_TRUE(output.is_null()); |
|
msw
2017/03/25 00:59:52
Odd that this doesn't match empty_rep.is_null()...
| |
| 98 EXPECT_EQ(empty_rep.pixel_size(), output.pixel_size()); | |
| 99 EXPECT_EQ(empty_rep.scale(), output.scale()); | |
| 98 } | 100 } |
| 99 | 101 |
| 100 TEST_F(ImageTraitsTest, ImageSkiaRep) { | 102 TEST_F(ImageTraitsTest, ImageSkiaRep) { |
| 101 ImageSkiaRep image_rep(gfx::Size(2, 4), 2.0f); | 103 ImageSkiaRep image_rep(gfx::Size(2, 4), 2.0f); |
| 102 | 104 |
| 103 ImageSkiaRep output; | 105 ImageSkiaRep output; |
| 104 service()->EchoImageSkiaRep(image_rep, &output); | 106 service()->EchoImageSkiaRep(image_rep, &output); |
| 105 | 107 |
| 106 EXPECT_FALSE(output.is_null()); | 108 EXPECT_FALSE(output.is_null()); |
| 107 EXPECT_EQ(image_rep.scale(), output.scale()); | 109 EXPECT_EQ(image_rep.scale(), output.scale()); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 145 ImageSkia image(new TestImageSkiaSource(kSize), kSize); | 147 ImageSkia image(new TestImageSkiaSource(kSize), kSize); |
| 146 image.GetRepresentation(1.0f); | 148 image.GetRepresentation(1.0f); |
| 147 image.GetRepresentation(2.0f); | 149 image.GetRepresentation(2.0f); |
| 148 | 150 |
| 149 ImageSkia output; | 151 ImageSkia output; |
| 150 service()->EchoImageSkia(image, &output); | 152 service()->EchoImageSkia(image, &output); |
| 151 | 153 |
| 152 EXPECT_TRUE(test::AreImagesEqual(Image(output), Image(image))); | 154 EXPECT_TRUE(test::AreImagesEqual(Image(output), Image(image))); |
| 153 } | 155 } |
| 154 | 156 |
| 155 TEST_F(ImageTraitsTest, EmptyRepPreserved) { | |
| 156 const gfx::Size kSize(1, 2); | |
| 157 ImageSkia image(new TestImageSkiaSource(kSize), kSize); | |
| 158 image.GetRepresentation(1.0f); | |
| 159 | |
| 160 SkBitmap empty_bitmap; | |
| 161 empty_bitmap.allocN32Pixels(0, 0); | |
| 162 image.AddRepresentation(ImageSkiaRep(empty_bitmap, 2.0f)); | |
| 163 | |
| 164 ImageSkia output; | |
| 165 service()->EchoImageSkia(image, &output); | |
| 166 | |
| 167 EXPECT_TRUE(test::AreImagesEqual(Image(output), Image(image))); | |
| 168 } | |
| 169 | |
| 170 TEST_F(ImageTraitsTest, ImageSkiaWithOperations) { | 157 TEST_F(ImageTraitsTest, ImageSkiaWithOperations) { |
| 171 const gfx::Size kSize(32, 32); | 158 const gfx::Size kSize(32, 32); |
| 172 ImageSkia image(new TestImageSkiaSource(kSize), kSize); | 159 ImageSkia image(new TestImageSkiaSource(kSize), kSize); |
| 173 | 160 |
| 174 const gfx::Size kNewSize(16, 16); | 161 const gfx::Size kNewSize(16, 16); |
| 175 ImageSkia resized = ImageSkiaOperations::CreateResizedImage( | 162 ImageSkia resized = ImageSkiaOperations::CreateResizedImage( |
| 176 image, skia::ImageOperations::RESIZE_BEST, kNewSize); | 163 image, skia::ImageOperations::RESIZE_BEST, kNewSize); |
| 177 resized.GetRepresentation(1.0f); | 164 resized.GetRepresentation(1.0f); |
| 178 resized.GetRepresentation(2.0f); | 165 resized.GetRepresentation(2.0f); |
| 179 | 166 |
| 180 ImageSkia output; | 167 ImageSkia output; |
| 181 service()->EchoImageSkia(resized, &output); | 168 service()->EchoImageSkia(resized, &output); |
| 182 | 169 |
| 183 EXPECT_TRUE(test::AreImagesEqual(Image(output), Image(resized))); | 170 EXPECT_TRUE(test::AreImagesEqual(Image(output), Image(resized))); |
| 184 } | 171 } |
| 185 | 172 |
| 186 } // namespace gfx | 173 } // namespace gfx |
| OLD | NEW |