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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
10 #include "base/json/json_file_value_serializer.h" | 10 #include "base/json/json_file_value_serializer.h" |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 int idr = IDR_THEME_FRAME; | 280 int idr = IDR_THEME_FRAME; |
281 gfx::Image image = pack->GetImageNamed(idr); | 281 gfx::Image image = pack->GetImageNamed(idr); |
282 EXPECT_FALSE(image.IsEmpty()); | 282 EXPECT_FALSE(image.IsEmpty()); |
283 const gfx::ImageSkia* image_skia = image.ToImageSkia(); | 283 const gfx::ImageSkia* image_skia = image.ToImageSkia(); |
284 ASSERT_TRUE(image_skia); | 284 ASSERT_TRUE(image_skia); |
285 // Scale 100%. | 285 // Scale 100%. |
286 const gfx::ImageSkiaRep& rep1 = image_skia->GetRepresentation(1.0f); | 286 const gfx::ImageSkiaRep& rep1 = image_skia->GetRepresentation(1.0f); |
287 ASSERT_FALSE(rep1.is_null()); | 287 ASSERT_FALSE(rep1.is_null()); |
288 EXPECT_EQ(80, rep1.sk_bitmap().width()); | 288 EXPECT_EQ(80, rep1.sk_bitmap().width()); |
289 EXPECT_EQ(80, rep1.sk_bitmap().height()); | 289 EXPECT_EQ(80, rep1.sk_bitmap().height()); |
290 rep1.sk_bitmap().lockPixels(); | |
291 EXPECT_EQ(SkColorSetRGB(255, 255, 255), rep1.sk_bitmap().getColor(4, 4)); | 290 EXPECT_EQ(SkColorSetRGB(255, 255, 255), rep1.sk_bitmap().getColor(4, 4)); |
292 EXPECT_EQ(SkColorSetRGB(255, 255, 255), rep1.sk_bitmap().getColor(8, 8)); | 291 EXPECT_EQ(SkColorSetRGB(255, 255, 255), rep1.sk_bitmap().getColor(8, 8)); |
293 EXPECT_EQ(SkColorSetRGB(0, 241, 237), rep1.sk_bitmap().getColor(16, 16)); | 292 EXPECT_EQ(SkColorSetRGB(0, 241, 237), rep1.sk_bitmap().getColor(16, 16)); |
294 EXPECT_EQ(SkColorSetRGB(255, 255, 255), rep1.sk_bitmap().getColor(24, 24)); | 293 EXPECT_EQ(SkColorSetRGB(255, 255, 255), rep1.sk_bitmap().getColor(24, 24)); |
295 EXPECT_EQ(SkColorSetRGB(0, 241, 237), rep1.sk_bitmap().getColor(32, 32)); | 294 EXPECT_EQ(SkColorSetRGB(0, 241, 237), rep1.sk_bitmap().getColor(32, 32)); |
296 rep1.sk_bitmap().unlockPixels(); | |
297 // Scale 200%. | 295 // Scale 200%. |
298 const gfx::ImageSkiaRep& rep2 = image_skia->GetRepresentation(2.0f); | 296 const gfx::ImageSkiaRep& rep2 = image_skia->GetRepresentation(2.0f); |
299 ASSERT_FALSE(rep2.is_null()); | 297 ASSERT_FALSE(rep2.is_null()); |
300 EXPECT_EQ(160, rep2.sk_bitmap().width()); | 298 EXPECT_EQ(160, rep2.sk_bitmap().width()); |
301 EXPECT_EQ(160, rep2.sk_bitmap().height()); | 299 EXPECT_EQ(160, rep2.sk_bitmap().height()); |
302 rep2.sk_bitmap().lockPixels(); | |
303 EXPECT_EQ(SkColorSetRGB(255, 255, 255), rep2.sk_bitmap().getColor(4, 4)); | 300 EXPECT_EQ(SkColorSetRGB(255, 255, 255), rep2.sk_bitmap().getColor(4, 4)); |
304 EXPECT_EQ(SkColorSetRGB(223, 42, 0), rep2.sk_bitmap().getColor(8, 8)); | 301 EXPECT_EQ(SkColorSetRGB(223, 42, 0), rep2.sk_bitmap().getColor(8, 8)); |
305 EXPECT_EQ(SkColorSetRGB(223, 42, 0), rep2.sk_bitmap().getColor(16, 16)); | 302 EXPECT_EQ(SkColorSetRGB(223, 42, 0), rep2.sk_bitmap().getColor(16, 16)); |
306 EXPECT_EQ(SkColorSetRGB(223, 42, 0), rep2.sk_bitmap().getColor(24, 24)); | 303 EXPECT_EQ(SkColorSetRGB(223, 42, 0), rep2.sk_bitmap().getColor(24, 24)); |
307 EXPECT_EQ(SkColorSetRGB(255, 255, 255), rep2.sk_bitmap().getColor(32, 32)); | 304 EXPECT_EQ(SkColorSetRGB(255, 255, 255), rep2.sk_bitmap().getColor(32, 32)); |
308 rep2.sk_bitmap().unlockPixels(); | |
309 | 305 |
310 // TODO(sschmitz): I plan to remove the following (to the end of the fct) | 306 // TODO(sschmitz): I plan to remove the following (to the end of the fct) |
311 // Reason: this test may be brittle. It depends on details of how we scale | 307 // Reason: this test may be brittle. It depends on details of how we scale |
312 // an 100% image to an 200% image. If there's filtering etc, this test would | 308 // an 100% image to an 200% image. If there's filtering etc, this test would |
313 // break. Also High DPI is new, but scaling from 100% to 200% is not new | 309 // break. Also High DPI is new, but scaling from 100% to 200% is not new |
314 // and need not be tested here. But in the interrim it is useful to verify | 310 // and need not be tested here. But in the interrim it is useful to verify |
315 // that this image was scaled and did not appear in the input. | 311 // that this image was scaled and did not appear in the input. |
316 | 312 |
317 // Compare pixel colors and locations for a theme image that had | 313 // Compare pixel colors and locations for a theme image that had |
318 // only one PNG file specified (for scale 100%). The representation | 314 // only one PNG file specified (for scale 100%). The representation |
319 // for scale of 200% was computed. | 315 // for scale of 200% was computed. |
320 idr = IDR_THEME_FRAME_INCOGNITO_INACTIVE; | 316 idr = IDR_THEME_FRAME_INCOGNITO_INACTIVE; |
321 image = pack->GetImageNamed(idr); | 317 image = pack->GetImageNamed(idr); |
322 EXPECT_FALSE(image.IsEmpty()); | 318 EXPECT_FALSE(image.IsEmpty()); |
323 image_skia = image.ToImageSkia(); | 319 image_skia = image.ToImageSkia(); |
324 ASSERT_TRUE(image_skia); | 320 ASSERT_TRUE(image_skia); |
325 // Scale 100%. | 321 // Scale 100%. |
326 const gfx::ImageSkiaRep& rep3 = image_skia->GetRepresentation(1.0f); | 322 const gfx::ImageSkiaRep& rep3 = image_skia->GetRepresentation(1.0f); |
327 ASSERT_FALSE(rep3.is_null()); | 323 ASSERT_FALSE(rep3.is_null()); |
328 EXPECT_EQ(80, rep3.sk_bitmap().width()); | 324 EXPECT_EQ(80, rep3.sk_bitmap().width()); |
329 EXPECT_EQ(80, rep3.sk_bitmap().height()); | 325 EXPECT_EQ(80, rep3.sk_bitmap().height()); |
330 rep3.sk_bitmap().lockPixels(); | |
331 // We take samples of colors and locations along the diagonal whenever | 326 // We take samples of colors and locations along the diagonal whenever |
332 // the color changes. Note these colors are slightly different from | 327 // the color changes. Note these colors are slightly different from |
333 // the input PNG file due to input processing. | 328 // the input PNG file due to input processing. |
334 std::vector<std::pair<int, SkColor> > normal; | 329 std::vector<std::pair<int, SkColor> > normal; |
335 int xy = 0; | 330 int xy = 0; |
336 SkColor color = rep3.sk_bitmap().getColor(xy, xy); | 331 SkColor color = rep3.sk_bitmap().getColor(xy, xy); |
337 normal.push_back(std::make_pair(xy, color)); | 332 normal.push_back(std::make_pair(xy, color)); |
338 for (int xy = 0; xy < 40; ++xy) { | 333 for (int xy = 0; xy < 40; ++xy) { |
339 SkColor next_color = rep3.sk_bitmap().getColor(xy, xy); | 334 SkColor next_color = rep3.sk_bitmap().getColor(xy, xy); |
340 if (next_color != color) { | 335 if (next_color != color) { |
341 color = next_color; | 336 color = next_color; |
342 normal.push_back(std::make_pair(xy, color)); | 337 normal.push_back(std::make_pair(xy, color)); |
343 } | 338 } |
344 } | 339 } |
345 EXPECT_EQ(static_cast<size_t>(9), normal.size()); | 340 EXPECT_EQ(static_cast<size_t>(9), normal.size()); |
346 rep3.sk_bitmap().unlockPixels(); | |
347 // Scale 200%. | 341 // Scale 200%. |
348 const gfx::ImageSkiaRep& rep4 = image_skia->GetRepresentation(2.0f); | 342 const gfx::ImageSkiaRep& rep4 = image_skia->GetRepresentation(2.0f); |
349 ASSERT_FALSE(rep4.is_null()); | 343 ASSERT_FALSE(rep4.is_null()); |
350 EXPECT_EQ(160, rep4.sk_bitmap().width()); | 344 EXPECT_EQ(160, rep4.sk_bitmap().width()); |
351 EXPECT_EQ(160, rep4.sk_bitmap().height()); | 345 EXPECT_EQ(160, rep4.sk_bitmap().height()); |
352 rep4.sk_bitmap().lockPixels(); | |
353 // We expect the same colors and at locations scaled by 2 | 346 // We expect the same colors and at locations scaled by 2 |
354 // since this bitmap was scaled by 2. | 347 // since this bitmap was scaled by 2. |
355 for (size_t i = 0; i < normal.size(); ++i) { | 348 for (size_t i = 0; i < normal.size(); ++i) { |
356 int xy = 2 * normal[i].first; | 349 int xy = 2 * normal[i].first; |
357 SkColor color = normal[i].second; | 350 SkColor color = normal[i].second; |
358 EXPECT_EQ(color, rep4.sk_bitmap().getColor(xy, xy)); | 351 EXPECT_EQ(color, rep4.sk_bitmap().getColor(xy, xy)); |
359 } | 352 } |
360 rep4.sk_bitmap().unlockPixels(); | |
361 } | 353 } |
362 | 354 |
363 base::MessageLoop message_loop; | 355 base::MessageLoop message_loop; |
364 content::TestBrowserThread fake_ui_thread; | 356 content::TestBrowserThread fake_ui_thread; |
365 content::TestBrowserThread fake_file_thread; | 357 content::TestBrowserThread fake_file_thread; |
366 | 358 |
367 typedef std::unique_ptr<ui::test::ScopedSetSupportedScaleFactors> | 359 typedef std::unique_ptr<ui::test::ScopedSetSupportedScaleFactors> |
368 ScopedSetSupportedScaleFactors; | 360 ScopedSetSupportedScaleFactors; |
369 ScopedSetSupportedScaleFactors scoped_set_supported_scale_factors_; | 361 ScopedSetSupportedScaleFactors scoped_set_supported_scale_factors_; |
370 scoped_refptr<BrowserThemePack> theme_pack_; | 362 scoped_refptr<BrowserThemePack> theme_pack_; |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
614 } | 606 } |
615 | 607 |
616 // Part 2: Try to read back the data pack that we just wrote to disk. | 608 // Part 2: Try to read back the data pack that we just wrote to disk. |
617 { | 609 { |
618 scoped_refptr<BrowserThemePack> pack = | 610 scoped_refptr<BrowserThemePack> pack = |
619 BrowserThemePack::BuildFromDataPack(file, "gllekhaobjnhgeag"); | 611 BrowserThemePack::BuildFromDataPack(file, "gllekhaobjnhgeag"); |
620 ASSERT_TRUE(pack.get()); | 612 ASSERT_TRUE(pack.get()); |
621 VerifyHiDpiTheme(pack.get()); | 613 VerifyHiDpiTheme(pack.get()); |
622 } | 614 } |
623 } | 615 } |
OLD | NEW |