diff options
author | tapted@chromium.org <tapted@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-12 04:33:56 +0000 |
---|---|---|
committer | tapted@chromium.org <tapted@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-12 04:33:56 +0000 |
commit | b4c72667519699208beea04f88c8b3fdd27683d7 (patch) | |
tree | 6f3572410846ed8900c8a15d178045ebf80a2016 | |
parent | db8cf5249e2a6df9ce134894e95d8636567cc458 (diff) | |
download | chromium_src-b4c72667519699208beea04f88c8b3fdd27683d7.zip chromium_src-b4c72667519699208beea04f88c8b3fdd27683d7.tar.gz chromium_src-b4c72667519699208beea04f88c8b3fdd27683d7.tar.bz2 |
Introduce a mock ui_unittests Framework for loading resources.
This allows ui_unittests to stop depending on the chrome framework.
On Mac, this creates (e.g.)
- out/ui_unittests Framework.framework/
+-- Resources -> Versions/A/Resources
\-- Versions
\-- A
\-- Resources
+-- Info.plist
+-- am.lproj
| \-- locale.pak
+-- ...
+-- chrome_100_percent.pak -> ui_test.pak
+-- ...
+-- en.lproj
| \-- locale.pak
+-- ...
On other platforms, out/ui_test.pak is loaded directly and
out/ui_unittests_strings/ is set as the locale folder (for tests that
load en-US.pak from there). ui_unittests currently depends on
out/locales/ which is only created when Chrome is built.
Note that ui_unittests does not currently succeed in a clobber build
(crbug.com/347851), so that missing dependency is fixed by this change
as well.
BUG=331669, 35878, 347851
TEST=ui_unittests should build and run after clobbering the build folder
Previously Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=255512
Review URL: https://codereview.chromium.org/152543005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@256419 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | ui/base/l10n/time_format_unittest.cc | 15 | ||||
-rw-r--r-- | ui/base/strings/ui_strings.gyp | 2 | ||||
-rw-r--r-- | ui/base/test/framework-Info.plist | 18 | ||||
-rw-r--r-- | ui/base/test/run_all_unittests.cc | 43 | ||||
-rw-r--r-- | ui/ui_unittests.gyp | 20 | ||||
-rw-r--r-- | ui/ui_unittests_bundle.gypi | 55 |
6 files changed, 118 insertions, 35 deletions
diff --git a/ui/base/l10n/time_format_unittest.cc b/ui/base/l10n/time_format_unittest.cc index 69f8b4e..9a237b1 100644 --- a/ui/base/l10n/time_format_unittest.cc +++ b/ui/base/l10n/time_format_unittest.cc @@ -74,15 +74,6 @@ class TimeFormatTest : public ::testing::Test { {} protected: - static void SetUpTestCase() { - LoadLocale(ui::ResourceBundle::GetSharedInstance() - .GetLocaleFilePath("en-US", true)); - } - - static void TearDownTestCase() { - LoadLocale(base::FilePath()); - } - void TestStrings() { // Test English strings (simple, singular). EXPECT_EQ(ASCIIToUTF16("1 sec"), TimeFormat::Simple( @@ -229,12 +220,6 @@ class TimeFormatTest : public ::testing::Test { TimeDelta delta_1d12h_; TimeDelta delta_2d_; TimeDelta delta_2d1h_; - - private: - static void LoadLocale(const base::FilePath& file_path) { - ui::ResourceBundle::GetSharedInstance().OverrideLocalePakForTest(file_path); - ui::ResourceBundle::GetSharedInstance().ReloadLocaleResources("en-US"); - } }; TEST_F(TimeFormatTest, SimpleAndDetailedRounding) { diff --git a/ui/base/strings/ui_strings.gyp b/ui/base/strings/ui_strings.gyp index f8750c2..a9f2bf7 100644 --- a/ui/base/strings/ui_strings.gyp +++ b/ui/base/strings/ui_strings.gyp @@ -38,7 +38,7 @@ }, ], 'conditions': [ - ['os_posix == 1 and OS != "mac"', { + ['OS != "mac"', { 'targets': [{ 'target_name': 'ui_unittest_strings', 'type': 'none', diff --git a/ui/base/test/framework-Info.plist b/ui/base/test/framework-Info.plist new file mode 100644 index 0000000..f3b7fc7 --- /dev/null +++ b/ui/base/test/framework-Info.plist @@ -0,0 +1,18 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> +<dict> + <key>CFBundleDevelopmentRegion</key> + <string>en</string> + <key>CFBundleExecutable</key> + <string>${EXECUTABLE_NAME}</string> + <key>CFBundleIdentifier</key> + <string>${CHROMIUM_BUNDLE_ID}.framework</string> + <key>CFBundleInfoDictionaryVersion</key> + <string>6.0</string> + <key>CFBundlePackageType</key> + <string>FMWK</string> + <key>CFBundleSignature</key> + <string>????</string> +</dict> +</plist> diff --git a/ui/base/test/run_all_unittests.cc b/ui/base/test/run_all_unittests.cc index 0f94dac..9d40ebb 100644 --- a/ui/base/test/run_all_unittests.cc +++ b/ui/base/test/run_all_unittests.cc @@ -52,27 +52,34 @@ void UIBaseTestSuite::Initialize() { ui::RegisterPathProvider(); gfx::RegisterPathProvider(); + base::FilePath exe_path; + PathService::Get(base::DIR_EXE, &exe_path); + #if defined(OS_MACOSX) && !defined(OS_IOS) - // Look in the framework bundle for resources. - // TODO(port): make a resource bundle for non-app exes. What's done here - // isn't really right because this code needs to depend on chrome_dll - // being built. This is inappropriate in app. - base::FilePath path; - PathService::Get(base::DIR_EXE, &path); -#if defined(GOOGLE_CHROME_BUILD) - path = path.AppendASCII("Google Chrome Framework.framework"); -#elif defined(CHROMIUM_BUILD) - path = path.AppendASCII("Chromium Framework.framework"); -#else -#error Unknown branding -#endif - base::mac::SetOverrideFrameworkBundlePath(path); -#endif // defined(OS_MACOSX) && !defined(OS_IOS) + // On Mac, a test Framework bundle is created that links locale.pak and + // chrome_100_percent.pak at the appropriate places to ui_test.pak. + base::mac::SetOverrideFrameworkBundlePath( + exe_path.AppendASCII("ui_unittests Framework.framework")); + ui::ResourceBundle::InitSharedInstanceWithLocale("en-US", NULL); - // TODO(tfarina): This loads chrome_100_percent.pak and thus introduces a - // dependency on chrome/, we don't want that here, so change this to - // InitSharedInstanceWithPakPath(). +#elif defined(OS_IOS) || defined(OS_ANDROID) + // On iOS, the ui_unittests binary is itself a mini bundle, with resources + // built in. On Android, ui_unittests_apk provides the necessary framework. ui::ResourceBundle::InitSharedInstanceWithLocale("en-US", NULL); + +#else + // On other platforms, the (hardcoded) paths for chrome_100_percent.pak and + // locale.pak get populated by later build steps. To avoid clobbering them, + // load the test .pak files directly. + ui::ResourceBundle::InitSharedInstanceWithPakPath( + exe_path.AppendASCII("ui_test.pak")); + + // ui_unittests can't depend on the locales folder which Chrome will make + // later, so use the path created by ui_unittest_strings. + PathService::Override( + ui::DIR_LOCALES, + exe_path.AppendASCII("ui_unittests_strings")); +#endif } void UIBaseTestSuite::Shutdown() { diff --git a/ui/ui_unittests.gyp b/ui/ui_unittests.gyp index a96bc72..ed20e60 100644 --- a/ui/ui_unittests.gyp +++ b/ui/ui_unittests.gyp @@ -62,7 +62,6 @@ 'dependencies': [ '../base/base.gyp:base', '../base/base.gyp:test_support_base', - '../chrome/chrome_resources.gyp:packed_resources', '../skia/skia.gyp:skia', '../testing/gmock.gyp:gmock', '../testing/gtest.gyp:gtest', @@ -74,6 +73,7 @@ 'events/events.gyp:events_base', 'gfx/gfx.gyp:gfx_test_support', 'resources/ui_resources.gyp:ui_resources', + 'resources/ui_resources.gyp:ui_test_pak', 'ui.gyp:ui', 'ui_test_support', ], @@ -285,6 +285,11 @@ 'dependencies': [ 'events/events.gyp:events_test_support', 'gfx/gfx.gyp:gfx_test_support', + 'ui_unittests_bundle', + ], + }, { # OS!="mac" + 'dependencies': [ + 'base/strings/ui_strings.gyp:ui_unittest_strings', ], }], ['use_aura==1 or toolkit_views==1', { @@ -335,6 +340,19 @@ }, ], 'conditions': [ + # Mac target to build a test Framework bundle to mock out resource loading. + ['OS == "mac"', { + 'targets': [ + { + 'target_name': 'ui_unittests_bundle', + 'type': 'shared_library', + 'dependencies': [ + 'resources/ui_resources.gyp:ui_test_pak', + ], + 'includes': [ 'ui_unittests_bundle.gypi' ], + }, + ], + }], # Special target to wrap a gtest_target_type==shared_library # ui_unittests into an android apk for execution. # See base.gyp for TODO(jrg)s about this strategy. diff --git a/ui/ui_unittests_bundle.gypi b/ui/ui_unittests_bundle.gypi new file mode 100644 index 0000000..94ef939 --- /dev/null +++ b/ui/ui_unittests_bundle.gypi @@ -0,0 +1,55 @@ +# Copyright 2014 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# This file contains resources for the ui_unittests test bundle. +# See chrome_dll_bundle.gypi for a description of the techniques here. +{ + 'product_name': 'ui_unittests Framework', + 'variables': { + 'grit_out_dir': '<(SHARED_INTERMEDIATE_DIR)/ui', + + # There is no executable in the mock framework, and so nothing to strip. + 'mac_strip': 0, + }, + 'mac_bundle': 1, + 'xcode_settings': { + 'CHROMIUM_BUNDLE_ID': 'com.google.ChromiumUITests', + 'DYLIB_COMPATIBILITY_VERSION': '1.0.0', + 'DYLIB_CURRENT_VERSION': '1.0.0', + 'DYLIB_INSTALL_NAME_BASE': '@executable_path/../Versions/1.0.0.0', + 'LD_DYLIB_INSTALL_NAME': + '$(DYLIB_INSTALL_NAME_BASE:standardizepath)/$(WRAPPER_NAME)/$(PRODUCT_NAME)', + 'INFOPLIST_FILE': 'base/test/framework-Info.plist', + }, + 'mac_bundle_resources': [ + 'base/test/framework-Info.plist', + '<(PRODUCT_DIR)/ui_test.pak', + '<!@pymod_do_main(repack_locales -o -p <(OS) -g <(grit_out_dir) -s <(SHARED_INTERMEDIATE_DIR) -x <(SHARED_INTERMEDIATE_DIR) <(locales))', + ], + 'mac_bundle_resources!': [ + 'base/test/framework-Info.plist', + ], + 'postbuilds': [ + { + 'postbuild_name': 'Symlink Resources', + 'action': [ + 'ln', + '-fns', + 'Versions/A/Resources', + '${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/Resources' + ], + }, + { + # Resource bundle pak names are hardcoded. This allows ui_test.pak to be + # found while running the ResourceBundle tests. + 'postbuild_name': 'Symlink chrome_100_percent for test', + 'action': [ + 'ln', + '-fns', + 'ui_test.pak', + '${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/Versions/A/Resources/chrome_100_percent.pak' + ], + }, + ], +} |