Commit 09c428d5 authored by thomasvl@chromium.org's avatar thomasvl@chromium.org

properly initialize resource manager on mac for unittests.

Review URL: http://codereview.chromium.org/28185

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10479 0039d316-1c4b-4281-b951-d872f2087c98
parent 0972da02
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/file_path.h" #include "base/file_path.h"
#include "base/file_util.h" #include "base/file_util.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/mac_util.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "base/string_piece.h" #include "base/string_piece.h"
#include "base/string_util.h" #include "base/string_util.h"
...@@ -18,6 +19,7 @@ ...@@ -18,6 +19,7 @@
#include "chrome/common/gfx/chrome_font.h" #include "chrome/common/gfx/chrome_font.h"
#include "chrome/common/l10n_util.h" #include "chrome/common/l10n_util.h"
ResourceBundle::~ResourceBundle() { ResourceBundle::~ResourceBundle() {
FreeImages(); FreeImages();
...@@ -34,8 +36,33 @@ namespace { ...@@ -34,8 +36,33 @@ namespace {
base::DataPack *LoadResourceDataPack(NSString *name) { base::DataPack *LoadResourceDataPack(NSString *name) {
base::DataPack *resource_pack = NULL; base::DataPack *resource_pack = NULL;
NSString *const pakExt = @"pak";
// TODO(thomasvl): THIS SUCKS! We need to remove this gate. It's here
// because of the unittests, but we have no other way to find our resources.
if (!mac_util::AmIBundled()) {
FilePath path;
PathService::Get(base::DIR_EXE, &path);
path = path.AppendASCII("Chromium.app");
path = path.AppendASCII("Contents");
path = path.AppendASCII("Resources");
if ([name isEqual:@"locale"]) {
path = path.AppendASCII("English.lproj");
}
NSString *pakName = [name stringByAppendingPathExtension:pakExt];
path = path.Append([pakName fileSystemRepresentation]);
resource_pack = new base::DataPack;
bool success = resource_pack->Load(path);
DCHECK(success) << "failed to load chrome.pak";
if (!success) {
delete resource_pack;
resource_pack = NULL;
}
return resource_pack;
}
NSString *resource_path = [[NSBundle mainBundle] pathForResource:name NSString *resource_path = [[NSBundle mainBundle] pathForResource:name
ofType:@"pak"]; ofType:pakExt];
if (resource_path) { if (resource_path) {
FilePath resources_pak_path([resource_path fileSystemRepresentation]); FilePath resources_pak_path([resource_path fileSystemRepresentation]);
resource_pack = new base::DataPack; resource_pack = new base::DataPack;
...@@ -53,8 +80,8 @@ base::DataPack *LoadResourceDataPack(NSString *name) { ...@@ -53,8 +80,8 @@ base::DataPack *LoadResourceDataPack(NSString *name) {
} // namespace } // namespace
void ResourceBundle::LoadResources(const std::wstring& pref_locale) { void ResourceBundle::LoadResources(const std::wstring& pref_locale) {
DCHECK(pref_locale.size() == 0) DLOG_IF(WARNING, pref_locale.size() != 0)
<< "ignoring requested locale in favore of NSBundle's selection"; << "ignoring requested locale in favor of NSBundle's selection";
DCHECK(resources_data_ == NULL) << "resource data already loaded!"; DCHECK(resources_data_ == NULL) << "resource data already loaded!";
resources_data_ = LoadResourceDataPack(@"chrome"); resources_data_ = LoadResourceDataPack(@"chrome");
......
...@@ -16,10 +16,7 @@ ...@@ -16,10 +16,7 @@
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#if defined(OS_WIN) || defined(OS_LINUX)
// TODO(port): Remove the #ifdef when ResourceBundle is ported.
#include "chrome/common/resource_bundle.h" #include "chrome/common/resource_bundle.h"
#endif
#include "chrome/test/testing_browser_process.h" #include "chrome/test/testing_browser_process.h"
class ChromeTestSuite : public TestSuite { class ChromeTestSuite : public TestSuite {
...@@ -50,14 +47,10 @@ protected: ...@@ -50,14 +47,10 @@ protected:
if (!user_data_dir.empty()) if (!user_data_dir.empty())
PathService::Override(chrome::DIR_USER_DATA, user_data_dir); PathService::Override(chrome::DIR_USER_DATA, user_data_dir);
#if defined(OS_WIN) || defined(OS_LINUX)
// TODO(port): Remove the #ifdef when ResourceBundle is ported.
//
// Force unittests to run using en-us so if we test against string // Force unittests to run using en-us so if we test against string
// output, it'll pass regardless of the system language. // output, it'll pass regardless of the system language.
ResourceBundle::InitSharedInstance(L"en-us"); ResourceBundle::InitSharedInstance(L"en-us");
ResourceBundle::GetSharedInstance().LoadThemeResources(); ResourceBundle::GetSharedInstance().LoadThemeResources();
#endif
// initialize the global StatsTable for unit_tests // initialize the global StatsTable for unit_tests
std::string statsfile = "unit_tests"; std::string statsfile = "unit_tests";
...@@ -68,10 +61,8 @@ protected: ...@@ -68,10 +61,8 @@ protected:
} }
virtual void Shutdown() { virtual void Shutdown() {
#if defined(OS_WIN) || defined(OS_LINUX)
// TODO(port): Remove the #ifdef when ResourceBundle is ported. // TODO(port): Remove the #ifdef when ResourceBundle is ported.
ResourceBundle::CleanupSharedInstance(); ResourceBundle::CleanupSharedInstance();
#endif
delete g_browser_process; delete g_browser_process;
g_browser_process = NULL; g_browser_process = NULL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment