Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(546)

Side by Side Diff: ui/base/resource/resource_bundle_unittest.cc

Issue 652623005: Revert of Eliminate silently letting errors pass on pak loading. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/base/resource/resource_bundle_mac.mm ('k') | ui/base/ui_base_paths.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/big_endian.h" 8 #include "base/big_endian.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 ResourceBundle* resource_bundle = CreateResourceBundle(&delegate); 179 ResourceBundle* resource_bundle = CreateResourceBundle(&delegate);
180 180
181 base::FilePath pack_path(FILE_PATH_LITERAL("/path/to/test_path.pak")); 181 base::FilePath pack_path(FILE_PATH_LITERAL("/path/to/test_path.pak"));
182 ui::ScaleFactor pack_scale_factor = ui::SCALE_FACTOR_200P; 182 ui::ScaleFactor pack_scale_factor = ui::SCALE_FACTOR_200P;
183 183
184 EXPECT_CALL(delegate, 184 EXPECT_CALL(delegate,
185 GetPathForResourcePack( 185 GetPathForResourcePack(
186 Property(&base::FilePath::value, pack_path.value()), 186 Property(&base::FilePath::value, pack_path.value()),
187 pack_scale_factor)) 187 pack_scale_factor))
188 .Times(1) 188 .Times(1)
189 .WillOnce(Return(base::FilePath())); 189 .WillOnce(Return(pack_path));
190 190
191 resource_bundle->AddDataPackFromPath(pack_path, pack_scale_factor); 191 resource_bundle->AddDataPackFromPath(pack_path, pack_scale_factor);
192 } 192 }
193 193
194 #if defined(OS_LINUX) 194 #if defined(OS_LINUX)
195 // Fails consistently on Linux: crbug.com/161902 195 // Fails consistently on Linux: crbug.com/161902
196 #define MAYBE_DelegateGetPathForLocalePack DISABLED_DelegateGetPathForLocalePack 196 #define MAYBE_DelegateGetPathForLocalePack DISABLED_DelegateGetPathForLocalePack
197 #else 197 #else
198 #define MAYBE_DelegateGetPathForLocalePack DelegateGetPathForLocalePack 198 #define MAYBE_DelegateGetPathForLocalePack DelegateGetPathForLocalePack
199 #endif 199 #endif
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 const base::FilePath& dir_path() { return dir_.path(); } 407 const base::FilePath& dir_path() { return dir_.path(); }
408 408
409 private: 409 private:
410 scoped_ptr<DataPack> locale_pack_; 410 scoped_ptr<DataPack> locale_pack_;
411 base::ScopedTempDir dir_; 411 base::ScopedTempDir dir_;
412 412
413 DISALLOW_COPY_AND_ASSIGN(ResourceBundleImageTest); 413 DISALLOW_COPY_AND_ASSIGN(ResourceBundleImageTest);
414 }; 414 };
415 415
416 // Verify that we don't crash when trying to load a resource that is not found. 416 // Verify that we don't crash when trying to load a resource that is not found.
417 // In some cases, we fail to mmap resources.pak, but try to keep going anyway.
417 TEST_F(ResourceBundleImageTest, LoadDataResourceBytes) { 418 TEST_F(ResourceBundleImageTest, LoadDataResourceBytes) {
418 base::FilePath data_path = dir_path().Append(FILE_PATH_LITERAL("sample.pak")); 419 base::FilePath data_path = dir_path().Append(FILE_PATH_LITERAL("sample.pak"));
419 420
420 // Dump contents into the pak files. 421 // Dump contents into the pak files.
421 ASSERT_EQ(base::WriteFile(data_path, kEmptyPakContents, 422 ASSERT_EQ(base::WriteFile(data_path, kEmptyPakContents,
422 kEmptyPakSize), static_cast<int>(kEmptyPakSize)); 423 kEmptyPakSize), static_cast<int>(kEmptyPakSize));
423 424
424 // Create a resource bundle from the file. 425 // Create a resource bundle from the file.
425 ResourceBundle* resource_bundle = CreateResourceBundleWithEmptyLocalePak(); 426 ResourceBundle* resource_bundle = CreateResourceBundleWithEmptyLocalePak();
426 resource_bundle->AddDataPackFromPath(data_path, SCALE_FACTOR_100P); 427 resource_bundle->AddDataPackFromPath(data_path, SCALE_FACTOR_100P);
427 428
428 const int kUnfoundResourceId = 10000; 429 const int kUnfoundResourceId = 10000;
429 EXPECT_EQ(NULL, resource_bundle->LoadDataResourceBytes( 430 EXPECT_EQ(NULL, resource_bundle->LoadDataResourceBytes(
430 kUnfoundResourceId)); 431 kUnfoundResourceId));
432
433 // Give a .pak file that doesn't exist so we will fail to load it.
434 resource_bundle->AddDataPackFromPath(
435 base::FilePath(FILE_PATH_LITERAL("non-existant-file.pak")),
436 ui::SCALE_FACTOR_NONE);
437 EXPECT_EQ(NULL, resource_bundle->LoadDataResourceBytes(
438 kUnfoundResourceId));
431 } 439 }
432 440
433 TEST_F(ResourceBundleImageTest, GetRawDataResource) { 441 TEST_F(ResourceBundleImageTest, GetRawDataResource) {
434 base::FilePath data_path = dir_path().Append(FILE_PATH_LITERAL("sample.pak")); 442 base::FilePath data_path = dir_path().Append(FILE_PATH_LITERAL("sample.pak"));
435 base::FilePath data_2x_path = 443 base::FilePath data_2x_path =
436 dir_path().Append(FILE_PATH_LITERAL("sample_2x.pak")); 444 dir_path().Append(FILE_PATH_LITERAL("sample_2x.pak"));
437 445
438 // Dump contents into the pak files. 446 // Dump contents into the pak files.
439 ASSERT_EQ(base::WriteFile(data_path, kSamplePakContents, 447 ASSERT_EQ(base::WriteFile(data_path, kSamplePakContents,
440 kSamplePakSize), static_cast<int>(kSamplePakSize)); 448 kSamplePakSize), static_cast<int>(kSamplePakSize));
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 resource_bundle->AddDataPackFromPath(data_default_path, SCALE_FACTOR_NONE); 621 resource_bundle->AddDataPackFromPath(data_default_path, SCALE_FACTOR_NONE);
614 622
615 gfx::ImageSkia* image_skia = resource_bundle->GetImageSkiaNamed(3); 623 gfx::ImageSkia* image_skia = resource_bundle->GetImageSkiaNamed(3);
616 EXPECT_EQ(1u, image_skia->image_reps().size()); 624 EXPECT_EQ(1u, image_skia->image_reps().size());
617 EXPECT_TRUE(image_skia->image_reps()[0].unscaled()); 625 EXPECT_TRUE(image_skia->image_reps()[0].unscaled());
618 EXPECT_EQ(ui::SCALE_FACTOR_100P, 626 EXPECT_EQ(ui::SCALE_FACTOR_100P,
619 GetSupportedScaleFactor(image_skia->image_reps()[0].scale())); 627 GetSupportedScaleFactor(image_skia->image_reps()[0].scale()));
620 } 628 }
621 629
622 } // namespace ui 630 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/resource/resource_bundle_mac.mm ('k') | ui/base/ui_base_paths.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698