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

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

Issue 2864253003: Split ImageLoader::SetImage() and set flags consistently in tests (Closed)
Patch Set: Update comment Created 3 years, 7 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/html/HTMLImageElement.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 bool color_correct_rendering; 101 bool color_correct_rendering;
102 bool color_correct_rendering_default_mode; 102 bool color_correct_rendering_default_mode;
103 }; 103 };
104 104
105 TEST_F(ImageBitmapTest, ImageResourceConsistency) { 105 TEST_F(ImageBitmapTest, ImageResourceConsistency) {
106 const ImageBitmapOptions default_options; 106 const ImageBitmapOptions default_options;
107 HTMLImageElement* image_element = 107 HTMLImageElement* image_element =
108 HTMLImageElement::Create(*Document::Create()); 108 HTMLImageElement::Create(*Document::Create());
109 ImageResourceContent* image = ImageResourceContent::CreateLoaded( 109 ImageResourceContent* image = ImageResourceContent::CreateLoaded(
110 StaticBitmapImage::Create(image_).Get()); 110 StaticBitmapImage::Create(image_).Get());
111 image_element->SetImageResource(image); 111 image_element->SetImageForTest(image);
112 112
113 Optional<IntRect> crop_rect = 113 Optional<IntRect> crop_rect =
114 IntRect(0, 0, image_->width(), image_->height()); 114 IntRect(0, 0, image_->width(), image_->height());
115 ImageBitmap* image_bitmap_no_crop = 115 ImageBitmap* image_bitmap_no_crop =
116 ImageBitmap::Create(image_element, crop_rect, 116 ImageBitmap::Create(image_element, crop_rect,
117 &(image_element->GetDocument()), default_options); 117 &(image_element->GetDocument()), default_options);
118 crop_rect = IntRect(image_->width() / 2, image_->height() / 2, 118 crop_rect = IntRect(image_->width() / 2, image_->height() / 2,
119 image_->width() / 2, image_->height() / 2); 119 image_->width() / 2, image_->height() / 2);
120 ImageBitmap* image_bitmap_interior_crop = 120 ImageBitmap* image_bitmap_interior_crop =
121 ImageBitmap::Create(image_element, crop_rect, 121 ImageBitmap::Create(image_element, crop_rect,
(...skipping 22 matching lines...) Expand all
144 image_element->CachedImage()->GetImage()->ImageForCurrentFrame()); 144 image_element->CachedImage()->GetImage()->ImageForCurrentFrame());
145 } 145 }
146 146
147 // Verifies that ImageBitmaps constructed from HTMLImageElements hold a 147 // Verifies that ImageBitmaps constructed from HTMLImageElements hold a
148 // reference to the original Image if the HTMLImageElement src is changed. 148 // reference to the original Image if the HTMLImageElement src is changed.
149 TEST_F(ImageBitmapTest, ImageBitmapSourceChanged) { 149 TEST_F(ImageBitmapTest, ImageBitmapSourceChanged) {
150 HTMLImageElement* image = HTMLImageElement::Create(*Document::Create()); 150 HTMLImageElement* image = HTMLImageElement::Create(*Document::Create());
151 ImageResourceContent* original_image_resource = 151 ImageResourceContent* original_image_resource =
152 ImageResourceContent::CreateLoaded( 152 ImageResourceContent::CreateLoaded(
153 StaticBitmapImage::Create(image_).Get()); 153 StaticBitmapImage::Create(image_).Get());
154 image->SetImageResource(original_image_resource); 154 image->SetImageForTest(original_image_resource);
155 155
156 const ImageBitmapOptions default_options; 156 const ImageBitmapOptions default_options;
157 Optional<IntRect> crop_rect = 157 Optional<IntRect> crop_rect =
158 IntRect(0, 0, image_->width(), image_->height()); 158 IntRect(0, 0, image_->width(), image_->height());
159 ImageBitmap* image_bitmap = ImageBitmap::Create( 159 ImageBitmap* image_bitmap = ImageBitmap::Create(
160 image, crop_rect, &(image->GetDocument()), default_options); 160 image, crop_rect, &(image->GetDocument()), default_options);
161 // As we are applying color space conversion for the "default" mode, 161 // As we are applying color space conversion for the "default" mode,
162 // this verifies that the color corrected image is not the same as the 162 // this verifies that the color corrected image is not the same as the
163 // source. 163 // source.
164 ASSERT_NE(image_bitmap->BitmapImage()->ImageForCurrentFrame(), 164 ASSERT_NE(image_bitmap->BitmapImage()->ImageForCurrentFrame(),
165 original_image_resource->GetImage()->ImageForCurrentFrame()); 165 original_image_resource->GetImage()->ImageForCurrentFrame());
166 166
167 ImageResourceContent* new_image_resource = ImageResourceContent::CreateLoaded( 167 ImageResourceContent* new_image_resource = ImageResourceContent::CreateLoaded(
168 StaticBitmapImage::Create(image2_).Get()); 168 StaticBitmapImage::Create(image2_).Get());
169 image->SetImageResource(new_image_resource); 169 image->SetImageForTest(new_image_resource);
170 170
171 { 171 {
172 ASSERT_NE(image_bitmap->BitmapImage()->ImageForCurrentFrame(), 172 ASSERT_NE(image_bitmap->BitmapImage()->ImageForCurrentFrame(),
173 original_image_resource->GetImage()->ImageForCurrentFrame()); 173 original_image_resource->GetImage()->ImageForCurrentFrame());
174 SkImage* image1 = image_bitmap->BitmapImage()->ImageForCurrentFrame().get(); 174 SkImage* image1 = image_bitmap->BitmapImage()->ImageForCurrentFrame().get();
175 ASSERT_NE(image1, nullptr); 175 ASSERT_NE(image1, nullptr);
176 SkImage* image2 = 176 SkImage* image2 =
177 original_image_resource->GetImage()->ImageForCurrentFrame().get(); 177 original_image_resource->GetImage()->ImageForCurrentFrame().get();
178 ASSERT_NE(image2, nullptr); 178 ASSERT_NE(image2, nullptr);
179 ASSERT_NE(image1, image2); 179 ASSERT_NE(image1, image2);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 sk_sp<SkImage> image = surface->makeImageSnapshot(); 237 sk_sp<SkImage> image = surface->makeImageSnapshot();
238 238
239 std::unique_ptr<uint8_t[]> src_pixel( 239 std::unique_ptr<uint8_t[]> src_pixel(
240 new uint8_t[raster_image_info.bytesPerPixel()]()); 240 new uint8_t[raster_image_info.bytesPerPixel()]());
241 image->readPixels(raster_image_info.makeWH(1, 1), src_pixel.get(), 241 image->readPixels(raster_image_info.makeWH(1, 1), src_pixel.get(),
242 image->width() * raster_image_info.bytesPerPixel(), 5, 5); 242 image->width() * raster_image_info.bytesPerPixel(), 5, 5);
243 243
244 ImageResourceContent* original_image_resource = 244 ImageResourceContent* original_image_resource =
245 ImageResourceContent::CreateLoaded( 245 ImageResourceContent::CreateLoaded(
246 StaticBitmapImage::Create(image).Get()); 246 StaticBitmapImage::Create(image).Get());
247 image_element->SetImageResource(original_image_resource); 247 image_element->SetImageForTest(original_image_resource);
248 248
249 Optional<IntRect> crop_rect = IntRect(0, 0, image->width(), image->height()); 249 Optional<IntRect> crop_rect = IntRect(0, 0, image->width(), image->height());
250 250
251 // Create and test the ImageBitmap objects. 251 // Create and test the ImageBitmap objects.
252 // We don't check "none" color space conversion as it requires the encoded 252 // We don't check "none" color space conversion as it requires the encoded
253 // data in a format readable by ImageDecoder. Furthermore, the code path for 253 // data in a format readable by ImageDecoder. Furthermore, the code path for
254 // "none" color space conversion is not affected by this CL. 254 // "none" color space conversion is not affected by this CL.
255 255
256 sk_sp<SkColorSpace> color_space = nullptr; 256 sk_sp<SkColorSpace> color_space = nullptr;
257 SkColorType color_type = SkColorType::kN32_SkColorType; 257 SkColorType color_type = SkColorType::kN32_SkColorType;
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 sk_sp<SkImage> image = surface->makeImageSnapshot(); 349 sk_sp<SkImage> image = surface->makeImageSnapshot();
350 350
351 std::unique_ptr<uint8_t[]> src_pixel( 351 std::unique_ptr<uint8_t[]> src_pixel(
352 new uint8_t[raster_image_info.bytesPerPixel()]()); 352 new uint8_t[raster_image_info.bytesPerPixel()]());
353 image->readPixels(raster_image_info.makeWH(1, 1), src_pixel.get(), 353 image->readPixels(raster_image_info.makeWH(1, 1), src_pixel.get(),
354 image->width() * raster_image_info.bytesPerPixel(), 5, 5); 354 image->width() * raster_image_info.bytesPerPixel(), 5, 5);
355 355
356 ImageResourceContent* source_image_resource = 356 ImageResourceContent* source_image_resource =
357 ImageResourceContent::CreateLoaded( 357 ImageResourceContent::CreateLoaded(
358 StaticBitmapImage::Create(image).Get()); 358 StaticBitmapImage::Create(image).Get());
359 image_element->SetImageResource(source_image_resource); 359 image_element->SetImageForTest(source_image_resource);
360 360
361 Optional<IntRect> crop_rect = IntRect(0, 0, image->width(), image->height()); 361 Optional<IntRect> crop_rect = IntRect(0, 0, image->width(), image->height());
362 ImageBitmapOptions options = 362 ImageBitmapOptions options =
363 PrepareBitmapOptionsAndSetRuntimeFlags(ColorSpaceConversion::SRGB); 363 PrepareBitmapOptionsAndSetRuntimeFlags(ColorSpaceConversion::SRGB);
364 ImageBitmap* source_image_bitmap = ImageBitmap::Create( 364 ImageBitmap* source_image_bitmap = ImageBitmap::Create(
365 image_element, crop_rect, &(image_element->GetDocument()), options); 365 image_element, crop_rect, &(image_element->GetDocument()), options);
366 366
367 sk_sp<SkColorSpace> color_space = nullptr; 367 sk_sp<SkColorSpace> color_space = nullptr;
368 SkColorType color_type = SkColorType::kN32_SkColorType; 368 SkColorType color_type = SkColorType::kN32_SkColorType;
369 SkColorSpaceXform::ColorFormat color_format32 = 369 SkColorSpaceXform::ColorFormat color_format32 =
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 color_space_xform->apply(color_format, transformed_pixel.get(), 608 color_space_xform->apply(color_format, transformed_pixel.get(),
609 color_format32, src_pixel.get(), 1, 609 color_format32, src_pixel.get(), 1,
610 SkAlphaType::kUnpremul_SkAlphaType); 610 SkAlphaType::kUnpremul_SkAlphaType);
611 int compare = std::memcmp(converted_pixel.get(), transformed_pixel.get(), 611 int compare = std::memcmp(converted_pixel.get(), transformed_pixel.get(),
612 image_info.bytesPerPixel()); 612 image_info.bytesPerPixel());
613 ASSERT_EQ(compare, 0); 613 ASSERT_EQ(compare, 0);
614 } 614 }
615 } 615 }
616 616
617 } // namespace blink 617 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/html/HTMLImageElement.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698