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 18 matching lines...) Expand all Loading... |
29 | 29 |
30 // Maps image ids to maps of scale factors to file paths. | 30 // Maps image ids to maps of scale factors to file paths. |
31 // A similar typedef in BrowserThemePack is private. | 31 // A similar typedef in BrowserThemePack is private. |
32 typedef std::map<int, TestScaleFactorToFileMap> TestFilePathMap; | 32 typedef std::map<int, TestScaleFactorToFileMap> TestFilePathMap; |
33 | 33 |
34 class BrowserThemePackTest : public ::testing::Test { | 34 class BrowserThemePackTest : public ::testing::Test { |
35 public: | 35 public: |
36 BrowserThemePackTest() | 36 BrowserThemePackTest() |
37 : message_loop(), | 37 : message_loop(), |
38 fake_ui_thread(BrowserThread::UI, &message_loop), | 38 fake_ui_thread(BrowserThread::UI, &message_loop), |
39 fake_file_thread(BrowserThread::FILE, &message_loop), | 39 fake_file_thread(BrowserThread::FILE, &message_loop) { |
40 theme_pack_(new BrowserThemePack) { | 40 std::vector<ui::ScaleFactor> scale_factors; |
| 41 scale_factors.push_back(ui::SCALE_FACTOR_100P); |
| 42 scale_factors.push_back(ui::SCALE_FACTOR_200P); |
| 43 scoped_set_supported_scale_factors_.reset( |
| 44 new ui::test::ScopedSetSupportedScaleFactors(scale_factors)); |
| 45 theme_pack_ = new BrowserThemePack(); |
41 } | 46 } |
42 | 47 |
43 // Transformation for link underline colors. | 48 // Transformation for link underline colors. |
44 SkColor BuildThirdOpacity(SkColor color_link) { | 49 SkColor BuildThirdOpacity(SkColor color_link) { |
45 return SkColorSetA(color_link, SkColorGetA(color_link) / 3); | 50 return SkColorSetA(color_link, SkColorGetA(color_link) / 3); |
46 } | 51 } |
47 | 52 |
48 void GenerateDefaultFrameColor(std::map<int, SkColor>* colors, | 53 void GenerateDefaultFrameColor(std::map<int, SkColor>* colors, |
49 int color, int tint) { | 54 int color, int tint) { |
50 (*colors)[color] = HSLShift( | 55 (*colors)[color] = HSLShift( |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 | 268 |
264 // Compare some known pixel colors at know locations for a theme | 269 // Compare some known pixel colors at know locations for a theme |
265 // image where two different PNG files were specified for scales 100% | 270 // image where two different PNG files were specified for scales 100% |
266 // and 200% respectively. | 271 // and 200% respectively. |
267 int idr = IDR_THEME_FRAME; | 272 int idr = IDR_THEME_FRAME; |
268 gfx::Image image = pack->GetImageNamed(idr); | 273 gfx::Image image = pack->GetImageNamed(idr); |
269 EXPECT_FALSE(image.IsEmpty()); | 274 EXPECT_FALSE(image.IsEmpty()); |
270 const gfx::ImageSkia* image_skia = image.ToImageSkia(); | 275 const gfx::ImageSkia* image_skia = image.ToImageSkia(); |
271 ASSERT_TRUE(image_skia); | 276 ASSERT_TRUE(image_skia); |
272 // Scale 100%. | 277 // Scale 100%. |
273 const gfx::ImageSkiaRep& rep1 = image_skia->GetRepresentation( | 278 const gfx::ImageSkiaRep& rep1 = image_skia->GetRepresentation(1.0f); |
274 ui::SCALE_FACTOR_100P); | |
275 ASSERT_FALSE(rep1.is_null()); | 279 ASSERT_FALSE(rep1.is_null()); |
276 EXPECT_EQ(80, rep1.sk_bitmap().width()); | 280 EXPECT_EQ(80, rep1.sk_bitmap().width()); |
277 EXPECT_EQ(80, rep1.sk_bitmap().height()); | 281 EXPECT_EQ(80, rep1.sk_bitmap().height()); |
278 rep1.sk_bitmap().lockPixels(); | 282 rep1.sk_bitmap().lockPixels(); |
279 EXPECT_EQ(SkColorSetRGB(255, 255, 255), rep1.sk_bitmap().getColor( 4, 4)); | 283 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)); | 284 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)); | 285 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)); | 286 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)); | 287 EXPECT_EQ(SkColorSetRGB( 0, 241, 237), rep1.sk_bitmap().getColor(32, 32)); |
284 rep1.sk_bitmap().unlockPixels(); | 288 rep1.sk_bitmap().unlockPixels(); |
285 // Scale 200%. | 289 // Scale 200%. |
286 const gfx::ImageSkiaRep& rep2 = image_skia->GetRepresentation( | 290 const gfx::ImageSkiaRep& rep2 = image_skia->GetRepresentation(2.0f); |
287 ui::SCALE_FACTOR_200P); | |
288 ASSERT_FALSE(rep2.is_null()); | 291 ASSERT_FALSE(rep2.is_null()); |
289 EXPECT_EQ(160, rep2.sk_bitmap().width()); | 292 EXPECT_EQ(160, rep2.sk_bitmap().width()); |
290 EXPECT_EQ(160, rep2.sk_bitmap().height()); | 293 EXPECT_EQ(160, rep2.sk_bitmap().height()); |
291 rep2.sk_bitmap().lockPixels(); | 294 rep2.sk_bitmap().lockPixels(); |
292 EXPECT_EQ(SkColorSetRGB(255, 255, 255), rep2.sk_bitmap().getColor( 4, 4)); | 295 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)); | 296 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)); | 297 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)); | 298 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)); | 299 EXPECT_EQ(SkColorSetRGB(255, 255, 255), rep2.sk_bitmap().getColor(32, 32)); |
297 rep2.sk_bitmap().unlockPixels(); | 300 rep2.sk_bitmap().unlockPixels(); |
298 | 301 |
299 // TODO(sschmitz): I plan to remove the following (to the end of the fct) | 302 // 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 | 303 // 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 | 304 // 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 | 305 // 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 | 306 // 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. | 307 // that this image was scaled and did not appear in the input. |
305 | 308 |
306 // Compare pixel colors and locations for a theme image that had | 309 // Compare pixel colors and locations for a theme image that had |
307 // only one PNG file specified (for scale 100%). The representation | 310 // only one PNG file specified (for scale 100%). The representation |
308 // for scale of 200% was computed. | 311 // for scale of 200% was computed. |
309 idr = IDR_THEME_FRAME_INCOGNITO_INACTIVE; | 312 idr = IDR_THEME_FRAME_INCOGNITO_INACTIVE; |
310 image = pack->GetImageNamed(idr); | 313 image = pack->GetImageNamed(idr); |
311 EXPECT_FALSE(image.IsEmpty()); | 314 EXPECT_FALSE(image.IsEmpty()); |
312 image_skia = image.ToImageSkia(); | 315 image_skia = image.ToImageSkia(); |
313 ASSERT_TRUE(image_skia); | 316 ASSERT_TRUE(image_skia); |
314 // Scale 100%. | 317 // Scale 100%. |
315 const gfx::ImageSkiaRep& rep3 = image_skia->GetRepresentation( | 318 const gfx::ImageSkiaRep& rep3 = image_skia->GetRepresentation(1.0f); |
316 ui::SCALE_FACTOR_100P); | |
317 ASSERT_FALSE(rep3.is_null()); | 319 ASSERT_FALSE(rep3.is_null()); |
318 EXPECT_EQ(80, rep3.sk_bitmap().width()); | 320 EXPECT_EQ(80, rep3.sk_bitmap().width()); |
319 EXPECT_EQ(80, rep3.sk_bitmap().height()); | 321 EXPECT_EQ(80, rep3.sk_bitmap().height()); |
320 rep3.sk_bitmap().lockPixels(); | 322 rep3.sk_bitmap().lockPixels(); |
321 // We take samples of colors and locations along the diagonal whenever | 323 // We take samples of colors and locations along the diagonal whenever |
322 // the color changes. Note these colors are slightly different from | 324 // the color changes. Note these colors are slightly different from |
323 // the input PNG file due to input processing. | 325 // the input PNG file due to input processing. |
324 std::vector<std::pair<int, SkColor> > normal; | 326 std::vector<std::pair<int, SkColor> > normal; |
325 int xy = 0; | 327 int xy = 0; |
326 SkColor color = rep3.sk_bitmap().getColor(xy, xy); | 328 SkColor color = rep3.sk_bitmap().getColor(xy, xy); |
327 normal.push_back(std::make_pair(xy, color)); | 329 normal.push_back(std::make_pair(xy, color)); |
328 for (int xy = 0; xy < 40; ++xy) { | 330 for (int xy = 0; xy < 40; ++xy) { |
329 SkColor next_color = rep3.sk_bitmap().getColor(xy, xy); | 331 SkColor next_color = rep3.sk_bitmap().getColor(xy, xy); |
330 if (next_color != color) { | 332 if (next_color != color) { |
331 color = next_color; | 333 color = next_color; |
332 normal.push_back(std::make_pair(xy, color)); | 334 normal.push_back(std::make_pair(xy, color)); |
333 } | 335 } |
334 } | 336 } |
335 EXPECT_EQ(static_cast<size_t>(9), normal.size()); | 337 EXPECT_EQ(static_cast<size_t>(9), normal.size()); |
336 rep3.sk_bitmap().unlockPixels(); | 338 rep3.sk_bitmap().unlockPixels(); |
337 // Scale 200%. | 339 // Scale 200%. |
338 const gfx::ImageSkiaRep& rep4 = image_skia->GetRepresentation( | 340 const gfx::ImageSkiaRep& rep4 = image_skia->GetRepresentation(2.0f); |
339 ui::SCALE_FACTOR_200P); | |
340 ASSERT_FALSE(rep4.is_null()); | 341 ASSERT_FALSE(rep4.is_null()); |
341 EXPECT_EQ(160, rep4.sk_bitmap().width()); | 342 EXPECT_EQ(160, rep4.sk_bitmap().width()); |
342 EXPECT_EQ(160, rep4.sk_bitmap().height()); | 343 EXPECT_EQ(160, rep4.sk_bitmap().height()); |
343 rep4.sk_bitmap().lockPixels(); | 344 rep4.sk_bitmap().lockPixels(); |
344 // We expect the same colors and at locations scaled by 2 | 345 // We expect the same colors and at locations scaled by 2 |
345 // since this bitmap was scaled by 2. | 346 // since this bitmap was scaled by 2. |
346 for (size_t i = 0; i < normal.size(); ++i) { | 347 for (size_t i = 0; i < normal.size(); ++i) { |
347 int xy = 2 * normal[i].first; | 348 int xy = 2 * normal[i].first; |
348 SkColor color = normal[i].second; | 349 SkColor color = normal[i].second; |
349 EXPECT_EQ(color, rep4.sk_bitmap().getColor(xy, xy)); | 350 EXPECT_EQ(color, rep4.sk_bitmap().getColor(xy, xy)); |
350 } | 351 } |
351 rep4.sk_bitmap().unlockPixels(); | 352 rep4.sk_bitmap().unlockPixels(); |
352 } | 353 } |
353 | 354 |
354 base::MessageLoop message_loop; | 355 base::MessageLoop message_loop; |
355 content::TestBrowserThread fake_ui_thread; | 356 content::TestBrowserThread fake_ui_thread; |
356 content::TestBrowserThread fake_file_thread; | 357 content::TestBrowserThread fake_file_thread; |
357 | 358 |
| 359 typedef scoped_ptr<ui::test::ScopedSetSupportedScaleFactors> |
| 360 ScopedSetSupportedScaleFactors; |
| 361 ScopedSetSupportedScaleFactors scoped_set_supported_scale_factors_; |
358 scoped_refptr<BrowserThemePack> theme_pack_; | 362 scoped_refptr<BrowserThemePack> theme_pack_; |
359 }; | 363 }; |
360 | 364 |
361 | 365 |
362 TEST_F(BrowserThemePackTest, DeriveUnderlineLinkColor) { | 366 TEST_F(BrowserThemePackTest, DeriveUnderlineLinkColor) { |
363 // If we specify a link color, but don't specify the underline color, the | 367 // If we specify a link color, but don't specify the underline color, the |
364 // theme provider should create one. | 368 // theme provider should create one. |
365 std::string color_json = "{ \"ntp_link\": [128, 128, 128]," | 369 std::string color_json = "{ \"ntp_link\": [128, 128, 128]," |
366 " \"ntp_section_link\": [128, 128, 128] }"; | 370 " \"ntp_section_link\": [128, 128, 128] }"; |
367 LoadColorJSON(color_json); | 371 LoadColorJSON(color_json); |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 { | 581 { |
578 scoped_refptr<BrowserThemePack> pack = | 582 scoped_refptr<BrowserThemePack> pack = |
579 BrowserThemePack::BuildFromDataPack( | 583 BrowserThemePack::BuildFromDataPack( |
580 file, "mblmlcbknbnfebdfjnolmcapmdofhmme"); | 584 file, "mblmlcbknbnfebdfjnolmcapmdofhmme"); |
581 ASSERT_TRUE(pack.get()); | 585 ASSERT_TRUE(pack.get()); |
582 VerifyStarGazing(pack.get()); | 586 VerifyStarGazing(pack.get()); |
583 } | 587 } |
584 } | 588 } |
585 | 589 |
586 TEST_F(BrowserThemePackTest, HiDpiThemeTest) { | 590 TEST_F(BrowserThemePackTest, HiDpiThemeTest) { |
587 std::vector<ui::ScaleFactor> scale_factors; | |
588 scale_factors.push_back(ui::SCALE_FACTOR_100P); | |
589 scale_factors.push_back(ui::SCALE_FACTOR_200P); | |
590 ui::test::ScopedSetSupportedScaleFactors test_scale_factors(scale_factors); | |
591 base::ScopedTempDir dir; | 591 base::ScopedTempDir dir; |
592 ASSERT_TRUE(dir.CreateUniqueTempDir()); | 592 ASSERT_TRUE(dir.CreateUniqueTempDir()); |
593 base::FilePath file = dir.path().AppendASCII("theme_data.pak"); | 593 base::FilePath file = dir.path().AppendASCII("theme_data.pak"); |
594 | 594 |
595 // Part 1: Build the pack from an extension. | 595 // Part 1: Build the pack from an extension. |
596 { | 596 { |
597 base::FilePath hidpi_path = GetHiDpiThemePath(); | 597 base::FilePath hidpi_path = GetHiDpiThemePath(); |
598 scoped_refptr<BrowserThemePack> pack; | 598 scoped_refptr<BrowserThemePack> pack; |
599 BuildFromUnpackedExtension(hidpi_path, pack); | 599 BuildFromUnpackedExtension(hidpi_path, pack); |
600 ASSERT_TRUE(pack->WriteToDisk(file)); | 600 ASSERT_TRUE(pack->WriteToDisk(file)); |
601 VerifyHiDpiTheme(pack.get()); | 601 VerifyHiDpiTheme(pack.get()); |
602 } | 602 } |
603 | 603 |
604 // Part 2: Try to read back the data pack that we just wrote to disk. | 604 // Part 2: Try to read back the data pack that we just wrote to disk. |
605 { | 605 { |
606 scoped_refptr<BrowserThemePack> pack = | 606 scoped_refptr<BrowserThemePack> pack = |
607 BrowserThemePack::BuildFromDataPack(file, "gllekhaobjnhgeag"); | 607 BrowserThemePack::BuildFromDataPack(file, "gllekhaobjnhgeag"); |
608 ASSERT_TRUE(pack.get()); | 608 ASSERT_TRUE(pack.get()); |
609 VerifyHiDpiTheme(pack.get()); | 609 VerifyHiDpiTheme(pack.get()); |
610 } | 610 } |
611 } | 611 } |
OLD | NEW |