summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--base/mac_util.h3
-rw-r--r--base/mac_util.mm18
-rw-r--r--webkit/tools/test_shell/test_shell_mac.mm28
3 files changed, 44 insertions, 5 deletions
diff --git a/base/mac_util.h b/base/mac_util.h
index 47ec6b6..a6c81fa 100644
--- a/base/mac_util.h
+++ b/base/mac_util.h
@@ -14,6 +14,9 @@ namespace mac_util {
std::string PathFromFSRef(const FSRef& ref);
bool FSRefFromPath(const std::string& path, FSRef* ref);
+// Returns true if the application is running from a bundle
+bool AmIBundled();
+
} // namespace mac_util
#endif // BASE_MAC_UTIL_H_
diff --git a/base/mac_util.mm b/base/mac_util.mm
index 1f92e62..462d165 100644
--- a/base/mac_util.mm
+++ b/base/mac_util.mm
@@ -4,6 +4,7 @@
#include "base/mac_util.h"
+#include <Carbon/Carbon.h>
#import <Cocoa/Cocoa.h>
#include "base/scoped_cftyperef.h"
@@ -23,4 +24,21 @@ bool FSRefFromPath(const std::string& path, FSRef* ref) {
return status == noErr;
}
+// Adapted from http://developer.apple.com/carbon/tipsandtricks.html#AmIBundled
+bool AmIBundled() {
+ ProcessSerialNumber psn = {0, kCurrentProcess};
+
+ FSRef fsref;
+ if (GetProcessBundleLocation(&psn, &fsref) != noErr)
+ return false;
+
+ FSCatalogInfo info;
+ if (FSGetCatalogInfo(&fsref, kFSCatInfoNodeFlags, &info,
+ NULL, NULL, NULL) != noErr) {
+ return false;
+ }
+
+ return info.nodeFlags & kFSNodeIsDirectoryMask;
+}
+
} // namespace mac_util
diff --git a/webkit/tools/test_shell/test_shell_mac.mm b/webkit/tools/test_shell/test_shell_mac.mm
index eaec764..fd2bd99 100644
--- a/webkit/tools/test_shell/test_shell_mac.mm
+++ b/webkit/tools/test_shell/test_shell_mac.mm
@@ -138,12 +138,30 @@ void TestShell::InitializeTestShell(bool layout_test_mode) {
ResetWebPreferences();
// Load the Ahem font, which is used by layout tests.
- NSString* ahem_path = [[[NSBundle mainBundle] resourcePath]
- stringByAppendingPathComponent:@"AHEM____.TTF"];
- const char* ahem_path_c = [ahem_path fileSystemRepresentation];
+ const char* ahem_path_c;
+ FilePath ahem_path; // Ensure ahem_path_c storage is not freed too soon.
+ if (mac_util::AmIBundled()) {
+ // When bundled (in TestShell.app), expect to find the font in
+ // Contents/Resources.
+ NSString* ahem_path = [[[NSBundle mainBundle] resourcePath]
+ stringByAppendingPathComponent:@"AHEM____.TTF"];
+ ahem_path_c = [ahem_path fileSystemRepresentation];
+ } else {
+ // When not bundled (in test_shell_tests), look in the source tree for
+ // the font.
+ PathService::Get(base::DIR_SOURCE_ROOT, &ahem_path);
+ ahem_path = ahem_path.Append("webkit");
+ ahem_path = ahem_path.Append("tools");
+ ahem_path = ahem_path.Append("test_shell");
+ ahem_path = ahem_path.Append("resources");
+ ahem_path = ahem_path.Append("AHEM____.TTF");
+
+ ahem_path_c = ahem_path.value().c_str();
+ }
+
FSRef ahem_fsref;
if (!mac_util::FSRefFromPath(ahem_path_c, &ahem_fsref)) {
- DCHECK(false) << "FSRefFromPath " << ahem_path_c;
+ DLOG(FATAL) << "FSRefFromPath " << ahem_path_c;
} else {
// The last argument is an ATSFontContainerRef that can be passed to
// ATSFontDeactivate to unload the font. Since the font is only loaded
@@ -154,7 +172,7 @@ void TestShell::InitializeTestShell(bool layout_test_mode) {
NULL,
kATSOptionFlagsDefault,
NULL) != noErr) {
- DCHECK(false) << "ATSFontActivateFromFileReference " << ahem_path_c;
+ DLOG(FATAL) << "ATSFontActivateFromFileReference " << ahem_path_c;
}
}
}