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

Unified Diff: webkit/support/platform_support_mac.mm

Issue 18429012: Don't load resources for test (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 7 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webkit/support/platform_support_linux.cc ('k') | webkit/support/platform_support_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/support/platform_support_mac.mm
diff --git a/webkit/support/platform_support_mac.mm b/webkit/support/platform_support_mac.mm
index a1235f4effce0c4ba9c67a2def0c9d1bf77bec2b..6d96ec13cf83ddfaa79c7fb1a9c8864dff529267 100644
--- a/webkit/support/platform_support_mac.mm
+++ b/webkit/support/platform_support_mac.mm
@@ -12,8 +12,6 @@
#include "base/base_paths.h"
#include "base/file_util.h"
#include "base/logging.h"
-#include "base/mac/bundle_locations.h"
-#include "base/mac/mac_util.h"
#include "base/path_service.h"
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
@@ -23,8 +21,6 @@
#import "webkit/support/mac/DumpRenderTreePasteboard.h"
#include "webkit/support/test_webkit_platform_support.h"
-static ui::DataPack* g_resource_data_pack = NULL;
-
namespace webkit_support {
static NSAutoreleasePool* autorelease_pool;
@@ -35,82 +31,7 @@ void BeforeInitialize() {
DCHECK(autorelease_pool);
}
-#if OBJC_API_VERSION == 2
-static void SwizzleAllMethods(Class imposter, Class original) {
- unsigned int imposterMethodCount = 0;
- Method* imposterMethods =
- class_copyMethodList(imposter, &imposterMethodCount);
-
- unsigned int originalMethodCount = 0;
- Method* originalMethods =
- class_copyMethodList(original, &originalMethodCount);
-
- for (unsigned int i = 0; i < imposterMethodCount; i++) {
- SEL imposterMethodName = method_getName(imposterMethods[i]);
-
- // Attempt to add the method to the original class. If it fails, the method
- // already exists and we should instead exchange the implementations.
- if (class_addMethod(original,
- imposterMethodName,
- method_getImplementation(originalMethods[i]),
- method_getTypeEncoding(originalMethods[i]))) {
- continue;
- }
-
- unsigned int j = 0;
- for (; j < originalMethodCount; j++) {
- SEL originalMethodName = method_getName(originalMethods[j]);
- if (sel_isEqual(imposterMethodName, originalMethodName)) {
- break;
- }
- }
-
- // If class_addMethod failed above then the method must exist on the
- // original class.
- DCHECK(j < originalMethodCount) << "method wasn't found?";
- method_exchangeImplementations(imposterMethods[i], originalMethods[j]);
- }
-
- if (imposterMethods) {
- free(imposterMethods);
- }
- if (originalMethods) {
- free(originalMethods);
- }
-}
-#endif
-
-static void SwizzleNSPasteboard() {
- // We replace NSPaseboard w/ the shim (from WebKit) that avoids having
- // sideeffects w/ whatever the user does at the same time.
-
- Class imposterClass = objc_getClass("DumpRenderTreePasteboard");
- Class originalClass = objc_getClass("NSPasteboard");
-#if OBJC_API_VERSION == 0
- class_poseAs(imposterClass, originalClass);
-#else
- // Swizzle instance methods...
- SwizzleAllMethods(imposterClass, originalClass);
- // and then class methods.
- SwizzleAllMethods(object_getClass(imposterClass),
- object_getClass(originalClass));
-#endif
-}
-
void AfterInitialize() {
- // Load a data pack.
- g_resource_data_pack = new ui::DataPack(ui::SCALE_FACTOR_100P);
- base::FilePath resources_pak_path;
- PathService::Get(base::DIR_EXE, &resources_pak_path);
- resources_pak_path = resources_pak_path.Append("Content Shell.app")
- .Append("Contents")
- .Append("Frameworks")
- .Append("Content Shell Framework.framework")
- .Append("Resources")
- .Append("content_shell.pak");
- if (!g_resource_data_pack->LoadFromPath(resources_pak_path)) {
- LOG(FATAL) << "failed to load DumpRenderTree.pak";
- }
}
void BeforeShutdown() {
@@ -119,88 +40,7 @@ void BeforeShutdown() {
void AfterShutdown() {
[DumpRenderTreePasteboard releaseLocalPasteboards];
[autorelease_pool drain];
- delete g_resource_data_pack;
}
} // namespace webkit_support
-base::string16 TestWebKitPlatformSupport::GetLocalizedString(int message_id) {
- // |g_resource_data_pack| is null on unit tests.
- // But som unit tests reach GetLocalizedString().
- if (!g_resource_data_pack)
- return base::string16();
- base::StringPiece res;
- if (!g_resource_data_pack->GetStringPiece(message_id, &res)) {
- LOG(FATAL) << "failed to load webkit string with id " << message_id;
- }
-
- // Data packs hold strings as either UTF8 or UTF16.
- base::string16 msg;
- switch (g_resource_data_pack->GetTextEncodingType()) {
- case ui::DataPack::UTF8:
- msg = UTF8ToUTF16(res);
- break;
- case ui::DataPack::UTF16:
- msg = base::string16(reinterpret_cast<const char16*>(res.data()),
- res.length() / 2);
- break;
- case ui::DataPack::BINARY:
- NOTREACHED();
- break;
- }
-
- return msg;
-}
-
-// Helper method for getting the path to the test shell resources directory.
-static base::FilePath GetResourcesFilePath() {
- base::FilePath path;
- // We assume the application is bundled.
- if (!base::mac::AmIBundled()) {
- LOG(FATAL) << "Failed to locate resources. The applicaiton is not bundled.";
- }
- PathService::Get(base::DIR_EXE, &path);
- path = path.Append(base::FilePath::kParentDirectory);
- return path.AppendASCII("Resources");
-}
-
-base::StringPiece TestWebKitPlatformSupport::GetDataResource(
- int resource_id,
- ui::ScaleFactor scale_factor) {
- switch (resource_id) {
- case IDR_BROKENIMAGE: {
- // Use webkit's broken image icon (16x16)
- CR_DEFINE_STATIC_LOCAL(std::string, broken_image_data, ());
- if (broken_image_data.empty()) {
- base::FilePath path = GetResourcesFilePath();
- // In order to match WebKit's colors for the missing image, we have to
- // use a PNG. The GIF doesn't have the color range needed to correctly
- // match the TIFF they use in Safari.
- path = base::MakeAbsoluteFilePath(path.AppendASCII("missingImage.png"));
- bool success = file_util::ReadFileToString(path, &broken_image_data);
- if (!success) {
- LOG(FATAL) << "Failed reading: " << path.value();
- }
- }
- return broken_image_data;
- }
- case IDR_TEXTAREA_RESIZER: {
- // Use webkit's text area resizer image.
- CR_DEFINE_STATIC_LOCAL(std::string, resize_corner_data, ());
- if (resize_corner_data.empty()) {
- base::FilePath path = GetResourcesFilePath();
- path = base::MakeAbsoluteFilePath(
- path.AppendASCII("textAreaResizeCorner.png"));
- bool success = file_util::ReadFileToString(path, &resize_corner_data);
- if (!success) {
- LOG(FATAL) << "Failed reading: " << path.value();
- }
- }
- return resize_corner_data;
- }
- }
- base::StringPiece res;
- if (g_resource_data_pack)
- g_resource_data_pack->GetStringPiece(resource_id, &res);
- return res;
-}
« no previous file with comments | « webkit/support/platform_support_linux.cc ('k') | webkit/support/platform_support_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698