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 "chrome/browser/themes/browser_theme_pack.h" | 5 #include "chrome/browser/themes/browser_theme_pack.h" |
6 | 6 |
7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
8 #include "base/json/json_file_value_serializer.h" | 8 #include "base/json/json_file_value_serializer.h" |
9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 | 263 |
264 // Compare some known pixel colors at know locations for a theme | 264 // Compare some known pixel colors at know locations for a theme |
265 // image where two different PNG files were specified for scales 100% | 265 // image where two different PNG files were specified for scales 100% |
266 // and 200% respectively. | 266 // and 200% respectively. |
267 int idr = IDR_THEME_FRAME; | 267 int idr = IDR_THEME_FRAME; |
268 gfx::Image image = pack->GetImageNamed(idr); | 268 gfx::Image image = pack->GetImageNamed(idr); |
269 EXPECT_FALSE(image.IsEmpty()); | 269 EXPECT_FALSE(image.IsEmpty()); |
270 const gfx::ImageSkia* image_skia = image.ToImageSkia(); | 270 const gfx::ImageSkia* image_skia = image.ToImageSkia(); |
271 ASSERT_TRUE(image_skia); | 271 ASSERT_TRUE(image_skia); |
272 // Scale 100%. | 272 // Scale 100%. |
273 const gfx::ImageSkiaRep& rep1 = image_skia->GetRepresentation( | 273 const gfx::ImageSkiaRep& rep1 = image_skia->GetRepresentation(1.0f); |
274 ui::SCALE_FACTOR_100P); | |
275 ASSERT_FALSE(rep1.is_null()); | 274 ASSERT_FALSE(rep1.is_null()); |
276 EXPECT_EQ(80, rep1.sk_bitmap().width()); | 275 EXPECT_EQ(80, rep1.sk_bitmap().width()); |
277 EXPECT_EQ(80, rep1.sk_bitmap().height()); | 276 EXPECT_EQ(80, rep1.sk_bitmap().height()); |
278 rep1.sk_bitmap().lockPixels(); | 277 rep1.sk_bitmap().lockPixels(); |
279 EXPECT_EQ(SkColorSetRGB(255, 255, 255), rep1.sk_bitmap().getColor( 4, 4)); | 278 EXPECT_EQ(SkColorSetRGB(255, 255, 255), rep1.sk_bitmap().getColor( 4, 4)); |
280 EXPECT_EQ(SkColorSetRGB(255, 255, 255), rep1.sk_bitmap().getColor( 8, 8)); | 279 EXPECT_EQ(SkColorSetRGB(255, 255, 255), rep1.sk_bitmap().getColor( 8, 8)); |
281 EXPECT_EQ(SkColorSetRGB( 0, 241, 237), rep1.sk_bitmap().getColor(16, 16)); | 280 EXPECT_EQ(SkColorSetRGB( 0, 241, 237), rep1.sk_bitmap().getColor(16, 16)); |
282 EXPECT_EQ(SkColorSetRGB(255, 255, 255), rep1.sk_bitmap().getColor(24, 24)); | 281 EXPECT_EQ(SkColorSetRGB(255, 255, 255), rep1.sk_bitmap().getColor(24, 24)); |
283 EXPECT_EQ(SkColorSetRGB( 0, 241, 237), rep1.sk_bitmap().getColor(32, 32)); | 282 EXPECT_EQ(SkColorSetRGB( 0, 241, 237), rep1.sk_bitmap().getColor(32, 32)); |
284 rep1.sk_bitmap().unlockPixels(); | 283 rep1.sk_bitmap().unlockPixels(); |
285 // Scale 200%. | 284 // Scale 200%. |
286 const gfx::ImageSkiaRep& rep2 = image_skia->GetRepresentation( | 285 const gfx::ImageSkiaRep& rep2 = image_skia->GetRepresentation(2.0f); |
287 ui::SCALE_FACTOR_200P); | |
288 ASSERT_FALSE(rep2.is_null()); | 286 ASSERT_FALSE(rep2.is_null()); |
289 EXPECT_EQ(160, rep2.sk_bitmap().width()); | 287 EXPECT_EQ(160, rep2.sk_bitmap().width()); |
290 EXPECT_EQ(160, rep2.sk_bitmap().height()); | 288 EXPECT_EQ(160, rep2.sk_bitmap().height()); |
291 rep2.sk_bitmap().lockPixels(); | 289 rep2.sk_bitmap().lockPixels(); |
292 EXPECT_EQ(SkColorSetRGB(255, 255, 255), rep2.sk_bitmap().getColor( 4, 4)); | 290 EXPECT_EQ(SkColorSetRGB(255, 255, 255), rep2.sk_bitmap().getColor( 4, 4)); |
293 EXPECT_EQ(SkColorSetRGB(223, 42, 0), rep2.sk_bitmap().getColor( 8, 8)); | 291 EXPECT_EQ(SkColorSetRGB(223, 42, 0), rep2.sk_bitmap().getColor( 8, 8)); |
294 EXPECT_EQ(SkColorSetRGB(223, 42, 0), rep2.sk_bitmap().getColor(16, 16)); | 292 EXPECT_EQ(SkColorSetRGB(223, 42, 0), rep2.sk_bitmap().getColor(16, 16)); |
295 EXPECT_EQ(SkColorSetRGB(223, 42, 0), rep2.sk_bitmap().getColor(24, 24)); | 293 EXPECT_EQ(SkColorSetRGB(223, 42, 0), rep2.sk_bitmap().getColor(24, 24)); |
296 EXPECT_EQ(SkColorSetRGB(255, 255, 255), rep2.sk_bitmap().getColor(32, 32)); | 294 EXPECT_EQ(SkColorSetRGB(255, 255, 255), rep2.sk_bitmap().getColor(32, 32)); |
297 rep2.sk_bitmap().unlockPixels(); | 295 rep2.sk_bitmap().unlockPixels(); |
298 | 296 |
299 // TODO(sschmitz): I plan to remove the following (to the end of the fct) | 297 // TODO(sschmitz): I plan to remove the following (to the end of the fct) |
300 // Reason: this test may be brittle. It depends on details of how we scale | 298 // Reason: this test may be brittle. It depends on details of how we scale |
301 // an 100% image to an 200% image. If there's filtering etc, this test would | 299 // an 100% image to an 200% image. If there's filtering etc, this test would |
302 // break. Also High DPI is new, but scaling from 100% to 200% is not new | 300 // break. Also High DPI is new, but scaling from 100% to 200% is not new |
303 // and need not be tested here. But in the interrim it is useful to verify | 301 // and need not be tested here. But in the interrim it is useful to verify |
304 // that this image was scaled and did not appear in the input. | 302 // that this image was scaled and did not appear in the input. |
305 | 303 |
306 // Compare pixel colors and locations for a theme image that had | 304 // Compare pixel colors and locations for a theme image that had |
307 // only one PNG file specified (for scale 100%). The representation | 305 // only one PNG file specified (for scale 100%). The representation |
308 // for scale of 200% was computed. | 306 // for scale of 200% was computed. |
309 idr = IDR_THEME_FRAME_INCOGNITO_INACTIVE; | 307 idr = IDR_THEME_FRAME_INCOGNITO_INACTIVE; |
310 image = pack->GetImageNamed(idr); | 308 image = pack->GetImageNamed(idr); |
311 EXPECT_FALSE(image.IsEmpty()); | 309 EXPECT_FALSE(image.IsEmpty()); |
312 image_skia = image.ToImageSkia(); | 310 image_skia = image.ToImageSkia(); |
313 ASSERT_TRUE(image_skia); | 311 ASSERT_TRUE(image_skia); |
314 // Scale 100%. | 312 // Scale 100%. |
315 const gfx::ImageSkiaRep& rep3 = image_skia->GetRepresentation( | 313 const gfx::ImageSkiaRep& rep3 = image_skia->GetRepresentation(1.0f); |
316 ui::SCALE_FACTOR_100P); | |
317 ASSERT_FALSE(rep3.is_null()); | 314 ASSERT_FALSE(rep3.is_null()); |
318 EXPECT_EQ(80, rep3.sk_bitmap().width()); | 315 EXPECT_EQ(80, rep3.sk_bitmap().width()); |
319 EXPECT_EQ(80, rep3.sk_bitmap().height()); | 316 EXPECT_EQ(80, rep3.sk_bitmap().height()); |
320 rep3.sk_bitmap().lockPixels(); | 317 rep3.sk_bitmap().lockPixels(); |
321 // We take samples of colors and locations along the diagonal whenever | 318 // We take samples of colors and locations along the diagonal whenever |
322 // the color changes. Note these colors are slightly different from | 319 // the color changes. Note these colors are slightly different from |
323 // the input PNG file due to input processing. | 320 // the input PNG file due to input processing. |
324 std::vector<std::pair<int, SkColor> > normal; | 321 std::vector<std::pair<int, SkColor> > normal; |
325 int xy = 0; | 322 int xy = 0; |
326 SkColor color = rep3.sk_bitmap().getColor(xy, xy); | 323 SkColor color = rep3.sk_bitmap().getColor(xy, xy); |
327 normal.push_back(std::make_pair(xy, color)); | 324 normal.push_back(std::make_pair(xy, color)); |
328 for (int xy = 0; xy < 40; ++xy) { | 325 for (int xy = 0; xy < 40; ++xy) { |
329 SkColor next_color = rep3.sk_bitmap().getColor(xy, xy); | 326 SkColor next_color = rep3.sk_bitmap().getColor(xy, xy); |
330 if (next_color != color) { | 327 if (next_color != color) { |
331 color = next_color; | 328 color = next_color; |
332 normal.push_back(std::make_pair(xy, color)); | 329 normal.push_back(std::make_pair(xy, color)); |
333 } | 330 } |
334 } | 331 } |
335 EXPECT_EQ(static_cast<size_t>(9), normal.size()); | 332 EXPECT_EQ(static_cast<size_t>(9), normal.size()); |
336 rep3.sk_bitmap().unlockPixels(); | 333 rep3.sk_bitmap().unlockPixels(); |
337 // Scale 200%. | 334 // Scale 200%. |
338 const gfx::ImageSkiaRep& rep4 = image_skia->GetRepresentation( | 335 const gfx::ImageSkiaRep& rep4 = image_skia->GetRepresentation(2.0f); |
339 ui::SCALE_FACTOR_200P); | |
340 ASSERT_FALSE(rep4.is_null()); | 336 ASSERT_FALSE(rep4.is_null()); |
341 EXPECT_EQ(160, rep4.sk_bitmap().width()); | 337 EXPECT_EQ(160, rep4.sk_bitmap().width()); |
342 EXPECT_EQ(160, rep4.sk_bitmap().height()); | 338 EXPECT_EQ(160, rep4.sk_bitmap().height()); |
343 rep4.sk_bitmap().lockPixels(); | 339 rep4.sk_bitmap().lockPixels(); |
344 // We expect the same colors and at locations scaled by 2 | 340 // We expect the same colors and at locations scaled by 2 |
345 // since this bitmap was scaled by 2. | 341 // since this bitmap was scaled by 2. |
346 for (size_t i = 0; i < normal.size(); ++i) { | 342 for (size_t i = 0; i < normal.size(); ++i) { |
347 int xy = 2 * normal[i].first; | 343 int xy = 2 * normal[i].first; |
348 SkColor color = normal[i].second; | 344 SkColor color = normal[i].second; |
349 EXPECT_EQ(color, rep4.sk_bitmap().getColor(xy, xy)); | 345 EXPECT_EQ(color, rep4.sk_bitmap().getColor(xy, xy)); |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 } | 598 } |
603 | 599 |
604 // Part 2: Try to read back the data pack that we just wrote to disk. | 600 // Part 2: Try to read back the data pack that we just wrote to disk. |
605 { | 601 { |
606 scoped_refptr<BrowserThemePack> pack = | 602 scoped_refptr<BrowserThemePack> pack = |
607 BrowserThemePack::BuildFromDataPack(file, "gllekhaobjnhgeag"); | 603 BrowserThemePack::BuildFromDataPack(file, "gllekhaobjnhgeag"); |
608 ASSERT_TRUE(pack.get()); | 604 ASSERT_TRUE(pack.get()); |
609 VerifyHiDpiTheme(pack.get()); | 605 VerifyHiDpiTheme(pack.get()); |
610 } | 606 } |
611 } | 607 } |
OLD | NEW |