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 "ui/base/resource/resource_bundle.h" | 5 #include "ui/base/resource/resource_bundle.h" |
6 | 6 |
7 #include "base/base_paths.h" | 7 #include "base/base_paths.h" |
8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/memory/ref_counted_memory.h" | 10 #include "base/memory/ref_counted_memory.h" |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
328 | 328 |
329 // Test requesting image reps at various scale factors from the image returned | 329 // Test requesting image reps at various scale factors from the image returned |
330 // via ResourceBundle::GetImageNamed(). | 330 // via ResourceBundle::GetImageNamed(). |
331 TEST(ResourceBundle, GetImageNamed) { | 331 TEST(ResourceBundle, GetImageNamed) { |
332 // On Windows, the default data is compiled into the binary so this does | 332 // On Windows, the default data is compiled into the binary so this does |
333 // nothing. | 333 // nothing. |
334 ScopedTempDir dir; | 334 ScopedTempDir dir; |
335 ASSERT_TRUE(dir.CreateUniqueTempDir()); | 335 ASSERT_TRUE(dir.CreateUniqueTempDir()); |
336 | 336 |
337 FilePath locale_path = dir.path().Append(FILE_PATH_LITERAL("empty.pak")); | 337 FilePath locale_path = dir.path().Append(FILE_PATH_LITERAL("empty.pak")); |
338 FilePath data_path = dir.path().Append(FILE_PATH_LITERAL("sample.pak")); | 338 FilePath data_default_path = |
339 dir.path().Append(FILE_PATH_LITERAL("sample.pak")); | |
340 FilePath data_1x_path = dir.path().Append(FILE_PATH_LITERAL("sample_1x.pak")); | |
339 FilePath data_2x_path = dir.path().Append(FILE_PATH_LITERAL("sample_2x.pak")); | 341 FilePath data_2x_path = dir.path().Append(FILE_PATH_LITERAL("sample_2x.pak")); |
340 | 342 |
341 { | 343 { |
342 // Create the pak files. | 344 // Create the pak files. |
343 ASSERT_EQ(file_util::WriteFile(locale_path, kEmptyPakContents, | 345 ASSERT_EQ(file_util::WriteFile(locale_path, kEmptyPakContents, |
344 kEmptyPakSize), static_cast<int>(kEmptyPakSize)); | 346 kEmptyPakSize), static_cast<int>(kEmptyPakSize)); |
345 CreateDataPackWithSingleBitmap(data_path, 10); | 347 CreateDataPackWithSingleBitmap(data_default_path, 10); |
348 CreateDataPackWithSingleBitmap(data_1x_path, 10); | |
346 CreateDataPackWithSingleBitmap(data_2x_path, 20); | 349 CreateDataPackWithSingleBitmap(data_2x_path, 20); |
347 | 350 |
348 // Load the regular and 2x pak files. | 351 // Load the regular and 2x pak files. |
349 ResourceBundle resource_bundle(NULL); | 352 ResourceBundle resource_bundle(NULL); |
350 resource_bundle.LoadTestResources(data_path, locale_path); | 353 resource_bundle.LoadTestResources(data_default_path, locale_path); |
354 resource_bundle.AddDataPackFromPath(data_1x_path, SCALE_FACTOR_100P); | |
351 resource_bundle.AddDataPackFromPath(data_2x_path, SCALE_FACTOR_200P); | 355 resource_bundle.AddDataPackFromPath(data_2x_path, SCALE_FACTOR_200P); |
352 | 356 |
353 gfx::ImageSkia* image_skia = resource_bundle.GetImageSkiaNamed(3); | 357 gfx::ImageSkia* image_skia = resource_bundle.GetImageSkiaNamed(3); |
354 | 358 |
359 EXPECT_EQ(ui::GetMaxScaleFactor(), | |
360 image_skia->image_reps()[0].scale_factor()); | |
361 | |
355 // Resource ID 3 exists in both 1x and 2x paks. Image reps should be | 362 // Resource ID 3 exists in both 1x and 2x paks. Image reps should be |
356 // available for both scale factors in |image_skia|. | 363 // available for both scale factors in |image_skia|. |
357 gfx::ImageSkiaRep image_rep = | 364 gfx::ImageSkiaRep image_rep = |
358 image_skia->GetRepresentation(ui::SCALE_FACTOR_100P); | 365 image_skia->GetRepresentation(ui::SCALE_FACTOR_100P); |
359 EXPECT_EQ(ui::SCALE_FACTOR_100P, image_rep.scale_factor()); | 366 EXPECT_EQ(ui::SCALE_FACTOR_100P, image_rep.scale_factor()); |
360 image_rep = image_skia->GetRepresentation(ui::SCALE_FACTOR_200P); | 367 image_rep = image_skia->GetRepresentation(ui::SCALE_FACTOR_200P); |
361 EXPECT_EQ(ui::SCALE_FACTOR_200P, image_rep.scale_factor()); | 368 EXPECT_EQ(ui::SCALE_FACTOR_200P, image_rep.scale_factor()); |
362 | 369 |
363 // The 1.4x pack was not loaded. Requesting the 1.4x resource should return | 370 // The 1.4x pack was not loaded. Requesting the 1.4x resource should return |
364 // either the 1x or the 2x resource. | 371 // either the 1x or the 2x resource. |
365 image_rep = image_skia->GetRepresentation(ui::SCALE_FACTOR_140P); | 372 image_rep = image_skia->GetRepresentation(ui::SCALE_FACTOR_140P); |
366 EXPECT_TRUE(image_rep.scale_factor() == ui::SCALE_FACTOR_100P || | 373 EXPECT_TRUE(image_rep.scale_factor() == ui::SCALE_FACTOR_100P || |
367 image_rep.scale_factor() == ui::SCALE_FACTOR_200P); | 374 image_rep.scale_factor() == ui::SCALE_FACTOR_200P); |
368 } | 375 } |
369 } | 376 } |
370 | 377 |
378 TEST(ResourceBundle, FallbackToNone) { | |
379 // On Windows, the default data is compiled into the binary so this does | |
380 // nothing. | |
381 ScopedTempDir dir; | |
382 ASSERT_TRUE(dir.CreateUniqueTempDir()); | |
383 | |
384 FilePath locale_path = dir.path().Append(FILE_PATH_LITERAL("empty.pak")); | |
sail
2012/11/05 23:46:39
use AppendASCII instead of FILE_PATH_LITERAL? same
oshima
2012/11/06 00:36:51
Done. changed all instance of this.
| |
385 FilePath data_default_path = | |
386 dir.path().Append(FILE_PATH_LITERAL("sample.pak")); | |
387 | |
388 { | |
sail
2012/11/05 23:46:39
do you really need this?
oshima
2012/11/06 00:36:51
removed here and above.
| |
389 // Create the pak files. | |
390 ASSERT_EQ(file_util::WriteFile(locale_path, kEmptyPakContents, | |
391 kEmptyPakSize), static_cast<int>(kEmptyPakSize)); | |
392 CreateDataPackWithSingleBitmap(data_default_path, 10); | |
393 | |
394 // Load the regular and 2x pak files. | |
sail
2012/11/05 23:46:39
I can't tell how this code loads both regular and
oshima
2012/11/06 00:36:51
fixed the comment.
| |
395 ResourceBundle resource_bundle(NULL); | |
396 resource_bundle.LoadTestResources(data_default_path, locale_path); | |
397 | |
398 gfx::ImageSkia* image_skia = resource_bundle.GetImageSkiaNamed(3); | |
399 EXPECT_EQ(1ui, image_skia->image_reps().size()); | |
400 EXPECT_EQ(ui::SCALE_FACTOR_100P, | |
401 image_skia->image_reps()[0].scale_factor()); | |
402 } | |
403 } | |
404 | |
371 } // namespace ui | 405 } // namespace ui |
OLD | NEW |