| OLD | NEW |
| 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 #include "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
| 6 #include "third_party/skia/include/core/SkCanvas.h" | 6 #include "third_party/skia/include/core/SkCanvas.h" |
| 7 #include "third_party/skia/include/core/SkPaint.h" | 7 #include "third_party/skia/include/core/SkPaint.h" |
| 8 #include "ui/base/layout.h" | 8 #include "ui/base/layout.h" |
| 9 #include "ui/gfx/image/image.h" | 9 #include "ui/gfx/image/image.h" |
| 10 #include "ui/gfx/image/image_png_rep.h" | 10 #include "ui/gfx/image/image_png_rep.h" |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 EXPECT_TRUE(ns_image); | 440 EXPECT_TRUE(ns_image); |
| 441 base::mac::NSObjectRelease(ns_image); | 441 base::mac::NSObjectRelease(ns_image); |
| 442 } | 442 } |
| 443 #endif | 443 #endif |
| 444 | 444 |
| 445 TEST_F(ImageTest, CheckSkiaColor) { | 445 TEST_F(ImageTest, CheckSkiaColor) { |
| 446 gfx::Image image(gt::CreatePlatformImage()); | 446 gfx::Image image(gt::CreatePlatformImage()); |
| 447 | 447 |
| 448 const SkBitmap* bitmap = image.ToSkBitmap(); | 448 const SkBitmap* bitmap = image.ToSkBitmap(); |
| 449 SkAutoLockPixels auto_lock(*bitmap); | 449 SkAutoLockPixels auto_lock(*bitmap); |
| 450 gt::CheckColor(bitmap->getColor(10, 10), false); | 450 gt::CheckColors(bitmap->getColor(10, 10), SK_ColorGREEN); |
| 451 } | 451 } |
| 452 | 452 |
| 453 TEST_F(ImageTest, SkBitmapConversionPreservesOrientation) { | 453 TEST_F(ImageTest, SkBitmapConversionPreservesOrientation) { |
| 454 const int width = 50; | 454 const int width = 50; |
| 455 const int height = 50; | 455 const int height = 50; |
| 456 SkBitmap bitmap; | 456 SkBitmap bitmap; |
| 457 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); | 457 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); |
| 458 bitmap.allocPixels(); | 458 bitmap.allocPixels(); |
| 459 bitmap.eraseRGB(0, 255, 0); | 459 bitmap.eraseRGB(0, 255, 0); |
| 460 | 460 |
| 461 // Paint the upper half of the image in red (lower half is in green). | 461 // Paint the upper half of the image in red (lower half is in green). |
| 462 SkCanvas canvas(bitmap); | 462 SkCanvas canvas(bitmap); |
| 463 SkPaint red; | 463 SkPaint red; |
| 464 red.setColor(SK_ColorRED); | 464 red.setColor(SK_ColorRED); |
| 465 canvas.drawRect(SkRect::MakeWH(width, height / 2), red); | 465 canvas.drawRect(SkRect::MakeWH(width, height / 2), red); |
| 466 { | 466 { |
| 467 SCOPED_TRACE("Checking color of the initial SkBitmap"); | 467 SCOPED_TRACE("Checking color of the initial SkBitmap"); |
| 468 gt::CheckColor(bitmap.getColor(10, 10), true); | 468 gt::CheckColors(bitmap.getColor(10, 10), SK_ColorRED); |
| 469 gt::CheckColor(bitmap.getColor(10, 40), false); | 469 gt::CheckColors(bitmap.getColor(10, 40), SK_ColorGREEN); |
| 470 } | 470 } |
| 471 | 471 |
| 472 // Convert from SkBitmap to a platform representation, then check the upper | 472 // Convert from SkBitmap to a platform representation, then check the upper |
| 473 // half of the platform image to make sure it is red, not green. | 473 // half of the platform image to make sure it is red, not green. |
| 474 gfx::Image from_skbitmap(bitmap); | 474 gfx::Image from_skbitmap(bitmap); |
| 475 { | 475 { |
| 476 SCOPED_TRACE("Checking color of the platform image"); | 476 SCOPED_TRACE("Checking color of the platform image"); |
| 477 gt::CheckColor( | 477 gt::CheckColors( |
| 478 gt::GetPlatformImageColor(gt::ToPlatformType(from_skbitmap), 10, 10), | 478 gt::GetPlatformImageColor(gt::ToPlatformType(from_skbitmap), 10, 10), |
| 479 true); | 479 SK_ColorRED); |
| 480 gt::CheckColor( | 480 gt::CheckColors( |
| 481 gt::GetPlatformImageColor(gt::ToPlatformType(from_skbitmap), 10, 40), | 481 gt::GetPlatformImageColor(gt::ToPlatformType(from_skbitmap), 10, 40), |
| 482 false); | 482 SK_ColorGREEN); |
| 483 } | 483 } |
| 484 | 484 |
| 485 // Force a conversion back to SkBitmap and check that the upper half is red. | 485 // Force a conversion back to SkBitmap and check that the upper half is red. |
| 486 gfx::Image from_platform(gt::CopyPlatformType(from_skbitmap)); | 486 gfx::Image from_platform(gt::CopyPlatformType(from_skbitmap)); |
| 487 const SkBitmap* bitmap2 = from_platform.ToSkBitmap(); | 487 const SkBitmap* bitmap2 = from_platform.ToSkBitmap(); |
| 488 SkAutoLockPixels auto_lock(*bitmap2); | 488 SkAutoLockPixels auto_lock(*bitmap2); |
| 489 { | 489 { |
| 490 SCOPED_TRACE("Checking color after conversion back to SkBitmap"); | 490 SCOPED_TRACE("Checking color after conversion back to SkBitmap"); |
| 491 gt::CheckColor(bitmap2->getColor(10, 10), true); | 491 gt::CheckColors(bitmap2->getColor(10, 10), SK_ColorRED); |
| 492 gt::CheckColor(bitmap2->getColor(10, 40), false); | 492 gt::CheckColors(bitmap2->getColor(10, 40), SK_ColorGREEN); |
| 493 } | 493 } |
| 494 } | 494 } |
| 495 | 495 |
| 496 TEST_F(ImageTest, SkBitmapConversionPreservesTransparency) { | 496 TEST_F(ImageTest, SkBitmapConversionPreservesTransparency) { |
| 497 const int width = 50; | 497 const int width = 50; |
| 498 const int height = 50; | 498 const int height = 50; |
| 499 SkBitmap bitmap; | 499 SkBitmap bitmap; |
| 500 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); | 500 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); |
| 501 bitmap.allocPixels(); | 501 bitmap.allocPixels(); |
| 502 bitmap.setIsOpaque(false); | 502 bitmap.setIsOpaque(false); |
| 503 bitmap.eraseARGB(0, 0, 255, 0); | 503 bitmap.eraseARGB(0, 0, 255, 0); |
| 504 | 504 |
| 505 // Paint the upper half of the image in red (lower half is transparent). | 505 // Paint the upper half of the image in red (lower half is transparent). |
| 506 SkCanvas canvas(bitmap); | 506 SkCanvas canvas(bitmap); |
| 507 SkPaint red; | 507 SkPaint red; |
| 508 red.setColor(SK_ColorRED); | 508 red.setColor(SK_ColorRED); |
| 509 canvas.drawRect(SkRect::MakeWH(width, height / 2), red); | 509 canvas.drawRect(SkRect::MakeWH(width, height / 2), red); |
| 510 { | 510 { |
| 511 SCOPED_TRACE("Checking color of the initial SkBitmap"); | 511 SCOPED_TRACE("Checking color of the initial SkBitmap"); |
| 512 gt::CheckColor(bitmap.getColor(10, 10), true); | 512 gt::CheckColors(bitmap.getColor(10, 10), SK_ColorRED); |
| 513 gt::CheckIsTransparent(bitmap.getColor(10, 40)); | 513 gt::CheckIsTransparent(bitmap.getColor(10, 40)); |
| 514 } | 514 } |
| 515 | 515 |
| 516 // Convert from SkBitmap to a platform representation, then check the upper | 516 // Convert from SkBitmap to a platform representation, then check the upper |
| 517 // half of the platform image to make sure it is red, not green. | 517 // half of the platform image to make sure it is red, not green. |
| 518 gfx::Image from_skbitmap(bitmap); | 518 gfx::Image from_skbitmap(bitmap); |
| 519 { | 519 { |
| 520 SCOPED_TRACE("Checking color of the platform image"); | 520 SCOPED_TRACE("Checking color of the platform image"); |
| 521 gt::CheckColor( | 521 gt::CheckColors( |
| 522 gt::GetPlatformImageColor(gt::ToPlatformType(from_skbitmap), 10, 10), | 522 gt::GetPlatformImageColor(gt::ToPlatformType(from_skbitmap), 10, 10), |
| 523 true); | 523 SK_ColorRED); |
| 524 gt::CheckIsTransparent( | 524 gt::CheckIsTransparent( |
| 525 gt::GetPlatformImageColor(gt::ToPlatformType(from_skbitmap), 10, 40)); | 525 gt::GetPlatformImageColor(gt::ToPlatformType(from_skbitmap), 10, 40)); |
| 526 } | 526 } |
| 527 | 527 |
| 528 // Force a conversion back to SkBitmap and check that the upper half is red. | 528 // Force a conversion back to SkBitmap and check that the upper half is red. |
| 529 gfx::Image from_platform(gt::CopyPlatformType(from_skbitmap)); | 529 gfx::Image from_platform(gt::CopyPlatformType(from_skbitmap)); |
| 530 const SkBitmap* bitmap2 = from_platform.ToSkBitmap(); | 530 const SkBitmap* bitmap2 = from_platform.ToSkBitmap(); |
| 531 SkAutoLockPixels auto_lock(*bitmap2); | 531 SkAutoLockPixels auto_lock(*bitmap2); |
| 532 { | 532 { |
| 533 SCOPED_TRACE("Checking color after conversion back to SkBitmap"); | 533 SCOPED_TRACE("Checking color after conversion back to SkBitmap"); |
| 534 gt::CheckColor(bitmap2->getColor(10, 10), true); | 534 gt::CheckColors(bitmap2->getColor(10, 10), SK_ColorRED); |
| 535 gt::CheckIsTransparent(bitmap.getColor(10, 40)); | 535 gt::CheckIsTransparent(bitmap.getColor(10, 40)); |
| 536 } | 536 } |
| 537 } | 537 } |
| 538 | 538 |
| 539 TEST_F(ImageTest, SwapRepresentations) { | 539 TEST_F(ImageTest, SwapRepresentations) { |
| 540 const size_t kRepCount = kUsesSkiaNatively ? 1U : 2U; | 540 const size_t kRepCount = kUsesSkiaNatively ? 1U : 2U; |
| 541 | 541 |
| 542 gfx::Image image1(gt::CreateBitmap(25, 25)); | 542 gfx::Image image1(gt::CreateBitmap(25, 25)); |
| 543 const SkBitmap* bitmap1 = image1.ToSkBitmap(); | 543 const SkBitmap* bitmap1 = image1.ToSkBitmap(); |
| 544 EXPECT_EQ(1U, image1.RepresentationCount()); | 544 EXPECT_EQ(1U, image1.RepresentationCount()); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 gfx::ImageSkiaRep(bitmap, ui::SCALE_FACTOR_100P))); | 635 gfx::ImageSkiaRep(bitmap, ui::SCALE_FACTOR_100P))); |
| 636 } | 636 } |
| 637 EXPECT_TRUE(!image.ToSkBitmap()->isNull()); | 637 EXPECT_TRUE(!image.ToSkBitmap()->isNull()); |
| 638 } | 638 } |
| 639 | 639 |
| 640 // Integration tests with UI toolkit frameworks require linking against the | 640 // Integration tests with UI toolkit frameworks require linking against the |
| 641 // Views library and cannot be here (ui_unittests doesn't include it). They | 641 // Views library and cannot be here (ui_unittests doesn't include it). They |
| 642 // instead live in /chrome/browser/ui/tests/ui_gfx_image_unittest.cc. | 642 // instead live in /chrome/browser/ui/tests/ui_gfx_image_unittest.cc. |
| 643 | 643 |
| 644 } // namespace | 644 } // namespace |
| OLD | NEW |