| 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/logging.h" | 10 #include "base/logging.h" |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 // for both scale factor requests. | 372 // for both scale factor requests. |
| 373 EXPECT_EQ("this is id 6", resource_bundle->GetRawDataResourceForScale(6, | 373 EXPECT_EQ("this is id 6", resource_bundle->GetRawDataResourceForScale(6, |
| 374 SCALE_FACTOR_100P)); | 374 SCALE_FACTOR_100P)); |
| 375 EXPECT_EQ("this is id 6", resource_bundle->GetRawDataResourceForScale(6, | 375 EXPECT_EQ("this is id 6", resource_bundle->GetRawDataResourceForScale(6, |
| 376 SCALE_FACTOR_200P)); | 376 SCALE_FACTOR_200P)); |
| 377 } | 377 } |
| 378 | 378 |
| 379 // Test requesting image reps at various scale factors from the image returned | 379 // Test requesting image reps at various scale factors from the image returned |
| 380 // via ResourceBundle::GetImageNamed(). | 380 // via ResourceBundle::GetImageNamed(). |
| 381 TEST_F(ResourceBundleImageTest, GetImageNamed) { | 381 TEST_F(ResourceBundleImageTest, GetImageNamed) { |
| 382 FilePath data_path = dir_path().Append(FILE_PATH_LITERAL("sample.pak")); | 382 std::vector<ScaleFactor> supported_factors; |
| 383 FilePath data_2x_path = dir_path().Append(FILE_PATH_LITERAL("sample_2x.pak")); | 383 supported_factors.push_back(SCALE_FACTOR_100P); |
| 384 supported_factors.push_back(SCALE_FACTOR_200P); |
| 385 test::SetSupportedScaleFactors(supported_factors); |
| 386 EXPECT_EQ(SCALE_FACTOR_200P, ui::GetMaxScaleFactor()); |
| 387 |
| 388 FilePath data_1x_path = dir_path().AppendASCII("sample_1x.pak"); |
| 389 FilePath data_2x_path = dir_path().AppendASCII("sample_2x.pak"); |
| 384 | 390 |
| 385 // Create the pak files. | 391 // Create the pak files. |
| 386 CreateDataPackWithSingleBitmap(data_path, 10); | 392 CreateDataPackWithSingleBitmap(data_1x_path, 10); |
| 387 CreateDataPackWithSingleBitmap(data_2x_path, 20); | 393 CreateDataPackWithSingleBitmap(data_2x_path, 20); |
| 388 | 394 |
| 389 // Load the regular and 2x pak files. | 395 // Load the regular and 2x pak files. |
| 390 ResourceBundle* resource_bundle = CreateResourceBundleWithEmptyLocalePak(); | 396 ResourceBundle* resource_bundle = CreateResourceBundleWithEmptyLocalePak(); |
| 391 resource_bundle->AddDataPackFromPath(data_path, SCALE_FACTOR_100P); | 397 resource_bundle->AddDataPackFromPath(data_1x_path, SCALE_FACTOR_100P); |
| 392 resource_bundle->AddDataPackFromPath(data_2x_path, SCALE_FACTOR_200P); | 398 resource_bundle->AddDataPackFromPath(data_2x_path, SCALE_FACTOR_200P); |
| 393 | 399 |
| 394 gfx::ImageSkia* image_skia = resource_bundle->GetImageSkiaNamed(3); | 400 gfx::ImageSkia* image_skia = resource_bundle->GetImageSkiaNamed(3); |
| 395 | 401 |
| 402 #if defined(OS_CHROMEOS) |
| 403 // ChromeOS loads highest scale factor first. |
| 404 EXPECT_EQ(ui::SCALE_FACTOR_200P, image_skia->image_reps()[0].scale_factor()); |
| 405 #endif |
| 406 |
| 396 // Resource ID 3 exists in both 1x and 2x paks. Image reps should be | 407 // Resource ID 3 exists in both 1x and 2x paks. Image reps should be |
| 397 // available for both scale factors in |image_skia|. | 408 // available for both scale factors in |image_skia|. |
| 398 gfx::ImageSkiaRep image_rep = | 409 gfx::ImageSkiaRep image_rep = |
| 399 image_skia->GetRepresentation(ui::SCALE_FACTOR_100P); | 410 image_skia->GetRepresentation(ui::SCALE_FACTOR_100P); |
| 400 EXPECT_EQ(ui::SCALE_FACTOR_100P, image_rep.scale_factor()); | 411 EXPECT_EQ(ui::SCALE_FACTOR_100P, image_rep.scale_factor()); |
| 401 image_rep = image_skia->GetRepresentation(ui::SCALE_FACTOR_200P); | 412 image_rep = image_skia->GetRepresentation(ui::SCALE_FACTOR_200P); |
| 402 EXPECT_EQ(ui::SCALE_FACTOR_200P, image_rep.scale_factor()); | 413 EXPECT_EQ(ui::SCALE_FACTOR_200P, image_rep.scale_factor()); |
| 403 | 414 |
| 404 // The 1.4x pack was not loaded. Requesting the 1.4x resource should return | 415 // The 1.4x pack was not loaded. Requesting the 1.4x resource should return |
| 405 // either the 1x or the 2x resource. | 416 // either the 1x or the 2x resource. |
| 406 image_rep = image_skia->GetRepresentation(ui::SCALE_FACTOR_140P); | 417 image_rep = image_skia->GetRepresentation(ui::SCALE_FACTOR_140P); |
| 407 EXPECT_TRUE(image_rep.scale_factor() == ui::SCALE_FACTOR_100P || | 418 EXPECT_TRUE(image_rep.scale_factor() == ui::SCALE_FACTOR_100P || |
| 408 image_rep.scale_factor() == ui::SCALE_FACTOR_200P); | 419 image_rep.scale_factor() == ui::SCALE_FACTOR_200P); |
| 409 } | 420 } |
| 410 | 421 |
| 422 TEST_F(ResourceBundleImageTest, FallbackToNone) { |
| 423 FilePath data_default_path = dir_path().AppendASCII("sample.pak"); |
| 424 |
| 425 // Create the pak files. |
| 426 CreateDataPackWithSingleBitmap(data_default_path, 10); |
| 427 |
| 428 // Load the regular pak files only. |
| 429 ResourceBundle* resource_bundle = CreateResourceBundleWithEmptyLocalePak(); |
| 430 resource_bundle->AddDataPackFromPath(data_default_path, SCALE_FACTOR_NONE); |
| 431 |
| 432 gfx::ImageSkia* image_skia = resource_bundle->GetImageSkiaNamed(3); |
| 433 EXPECT_EQ(1u, image_skia->image_reps().size()); |
| 434 EXPECT_EQ(ui::SCALE_FACTOR_100P, |
| 435 image_skia->image_reps()[0].scale_factor()); |
| 436 } |
| 437 |
| 411 } // namespace ui | 438 } // namespace ui |
| OLD | NEW |