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

Side by Side Diff: third_party/WebKit/Source/core/frame/ImageBitmapTest.cpp

Issue 2035113002: Implement ImageBitmapOptions resize (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments Created 4 years, 5 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
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2013, Google Inc. All rights reserved. 2 * Copyright (c) 2013, 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 Persistent<MemoryCache> m_globalMemoryCache; 77 Persistent<MemoryCache> m_globalMemoryCache;
78 }; 78 };
79 79
80 TEST_F(ImageBitmapTest, ImageResourceConsistency) 80 TEST_F(ImageBitmapTest, ImageResourceConsistency)
81 { 81 {
82 const ImageBitmapOptions defaultOptions; 82 const ImageBitmapOptions defaultOptions;
83 HTMLImageElement* imageElement = HTMLImageElement::create(*Document::create( )); 83 HTMLImageElement* imageElement = HTMLImageElement::create(*Document::create( ));
84 ImageResource* image = ImageResource::create(StaticBitmapImage::create(m_ima ge).get()); 84 ImageResource* image = ImageResource::create(StaticBitmapImage::create(m_ima ge).get());
85 imageElement->setImageResource(image); 85 imageElement->setImageResource(image);
86 86
87 Optional<IntRect> cropRect = IntRect(0, 0, m_image->width(), m_image->height ());
87 ImageBitmap* imageBitmapNoCrop = ImageBitmap::create(imageElement, 88 ImageBitmap* imageBitmapNoCrop = ImageBitmap::create(imageElement,
88 IntRect(0, 0, m_image->width(), m_image->height()), 89 cropRect, &(imageElement->document()), defaultOptions);
89 &(imageElement->document()), defaultOptions); 90 cropRect = IntRect(m_image->width() / 2, m_image->height() / 2, m_image->wid th() / 2, m_image->height() / 2);
90 ImageBitmap* imageBitmapInteriorCrop = ImageBitmap::create(imageElement, 91 ImageBitmap* imageBitmapInteriorCrop = ImageBitmap::create(imageElement,
91 IntRect(m_image->width() / 2, m_image->height() / 2, m_image->width() / 2, m_image->height() / 2), 92 cropRect, &(imageElement->document()), defaultOptions);
92 &(imageElement->document()), defaultOptions); 93 cropRect = IntRect(-m_image->width() / 2, -m_image->height() / 2, m_image->w idth(), m_image->height());
93 ImageBitmap* imageBitmapExteriorCrop = ImageBitmap::create(imageElement, 94 ImageBitmap* imageBitmapExteriorCrop = ImageBitmap::create(imageElement,
94 IntRect(-m_image->width() / 2, -m_image->height() / 2, m_image->width(), m_image->height()), 95 cropRect, &(imageElement->document()), defaultOptions);
95 &(imageElement->document()), defaultOptions); 96 cropRect = IntRect(-m_image->width(), -m_image->height(), m_image->width(), m_image->height());
96 ImageBitmap* imageBitmapOutsideCrop = ImageBitmap::create(imageElement, 97 ImageBitmap* imageBitmapOutsideCrop = ImageBitmap::create(imageElement,
97 IntRect(-m_image->width(), -m_image->height(), m_image->width(), m_image ->height()), 98 cropRect, &(imageElement->document()), defaultOptions);
98 &(imageElement->document()), defaultOptions);
99 99
100 ASSERT_EQ(imageBitmapNoCrop->bitmapImage()->imageForCurrentFrame(), imageEle ment->cachedImage()->getImage()->imageForCurrentFrame()); 100 ASSERT_EQ(imageBitmapNoCrop->bitmapImage()->imageForCurrentFrame(), imageEle ment->cachedImage()->getImage()->imageForCurrentFrame());
101 ASSERT_NE(imageBitmapInteriorCrop->bitmapImage()->imageForCurrentFrame(), im ageElement->cachedImage()->getImage()->imageForCurrentFrame()); 101 ASSERT_NE(imageBitmapInteriorCrop->bitmapImage()->imageForCurrentFrame(), im ageElement->cachedImage()->getImage()->imageForCurrentFrame());
102 ASSERT_NE(imageBitmapExteriorCrop->bitmapImage()->imageForCurrentFrame(), im ageElement->cachedImage()->getImage()->imageForCurrentFrame()); 102 ASSERT_NE(imageBitmapExteriorCrop->bitmapImage()->imageForCurrentFrame(), im ageElement->cachedImage()->getImage()->imageForCurrentFrame());
103 103
104 StaticBitmapImage* emptyImage = imageBitmapOutsideCrop->bitmapImage(); 104 StaticBitmapImage* emptyImage = imageBitmapOutsideCrop->bitmapImage();
105 ASSERT_NE(emptyImage->imageForCurrentFrame(), imageElement->cachedImage()->g etImage()->imageForCurrentFrame()); 105 ASSERT_NE(emptyImage->imageForCurrentFrame(), imageElement->cachedImage()->g etImage()->imageForCurrentFrame());
106 } 106 }
107 107
108 // Verifies that ImageBitmaps constructed from HTMLImageElements hold a referenc e to the original Image if the HTMLImageElement src is changed. 108 // Verifies that ImageBitmaps constructed from HTMLImageElements hold a referenc e to the original Image if the HTMLImageElement src is changed.
109 TEST_F(ImageBitmapTest, ImageBitmapSourceChanged) 109 TEST_F(ImageBitmapTest, ImageBitmapSourceChanged)
110 { 110 {
111 HTMLImageElement* image = HTMLImageElement::create(*Document::create()); 111 HTMLImageElement* image = HTMLImageElement::create(*Document::create());
112 ImageResource* originalImageResource = ImageResource::create( 112 ImageResource* originalImageResource = ImageResource::create(
113 StaticBitmapImage::create(m_image).get()); 113 StaticBitmapImage::create(m_image).get());
114 image->setImageResource(originalImageResource); 114 image->setImageResource(originalImageResource);
115 115
116 const ImageBitmapOptions defaultOptions; 116 const ImageBitmapOptions defaultOptions;
117 Optional<IntRect> cropRect = IntRect(0, 0, m_image->width(), m_image->height ());
117 ImageBitmap* imageBitmap = ImageBitmap::create(image, 118 ImageBitmap* imageBitmap = ImageBitmap::create(image,
118 IntRect(0, 0, m_image->width(), m_image->height()), 119 cropRect, &(image->document()), defaultOptions);
119 &(image->document()), defaultOptions);
120 ASSERT_EQ(imageBitmap->bitmapImage()->imageForCurrentFrame(), originalImageR esource->getImage()->imageForCurrentFrame()); 120 ASSERT_EQ(imageBitmap->bitmapImage()->imageForCurrentFrame(), originalImageR esource->getImage()->imageForCurrentFrame());
121 121
122 ImageResource* newImageResource = ImageResource::create( 122 ImageResource* newImageResource = ImageResource::create(
123 StaticBitmapImage::create(m_image2).get()); 123 StaticBitmapImage::create(m_image2).get());
124 image->setImageResource(newImageResource); 124 image->setImageResource(newImageResource);
125 125
126 // The ImageBitmap should contain the same data as the original cached image 126 // The ImageBitmap should contain the same data as the original cached image
127 { 127 {
128 ASSERT_EQ(imageBitmap->bitmapImage()->imageForCurrentFrame(), originalIm ageResource->getImage()->imageForCurrentFrame()); 128 ASSERT_EQ(imageBitmap->bitmapImage()->imageForCurrentFrame(), originalIm ageResource->getImage()->imageForCurrentFrame());
129 SkImage* image1 = imageBitmap->bitmapImage()->imageForCurrentFrame().get (); 129 SkImage* image1 = imageBitmap->bitmapImage()->imageForCurrentFrame().get ();
130 ASSERT_NE(image1, nullptr); 130 ASSERT_NE(image1, nullptr);
131 SkImage* image2 = originalImageResource->getImage()->imageForCurrentFram e().get(); 131 SkImage* image2 = originalImageResource->getImage()->imageForCurrentFram e().get();
132 ASSERT_NE(image2, nullptr); 132 ASSERT_NE(image2, nullptr);
133 ASSERT_EQ(image1, image2); 133 ASSERT_EQ(image1, image2);
134 } 134 }
135 135
136 { 136 {
137 ASSERT_NE(imageBitmap->bitmapImage()->imageForCurrentFrame(), newImageRe source->getImage()->imageForCurrentFrame()); 137 ASSERT_NE(imageBitmap->bitmapImage()->imageForCurrentFrame(), newImageRe source->getImage()->imageForCurrentFrame());
138 SkImage* image1 = imageBitmap->bitmapImage()->imageForCurrentFrame().get (); 138 SkImage* image1 = imageBitmap->bitmapImage()->imageForCurrentFrame().get ();
139 ASSERT_NE(image1, nullptr); 139 ASSERT_NE(image1, nullptr);
140 SkImage* image2 = newImageResource->getImage()->imageForCurrentFrame().g et(); 140 SkImage* image2 = newImageResource->getImage()->imageForCurrentFrame().g et();
141 ASSERT_NE(image2, nullptr); 141 ASSERT_NE(image2, nullptr);
142 ASSERT_NE(image1, image2); 142 ASSERT_NE(image1, image2);
143 } 143 }
144 } 144 }
145 145
146 } // namespace blink 146 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/frame/ImageBitmap.cpp ('k') | third_party/WebKit/Source/core/html/HTMLCanvasElement.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698