| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "webkit/support/platform_support.h" | |
| 6 | |
| 7 #include "base/android/jni_android.h" | |
| 8 #include "base/file_util.h" | |
| 9 #include "base/files/file_path.h" | |
| 10 #include "base/logging.h" | |
| 11 #include "base/path_service.h" | |
| 12 #include "base/strings/string16.h" | |
| 13 #include "base/strings/string_piece.h" | |
| 14 #include "base/test/test_support_android.h" | |
| 15 #include "googleurl/src/gurl.h" | |
| 16 #include "grit/webkit_resources.h" | |
| 17 #include "media/base/android/media_jni_registrar.h" | |
| 18 #include "net/android/net_jni_registrar.h" | |
| 19 #include "net/android/network_library.h" | |
| 20 #include "ui/android/ui_jni_registrar.h" | |
| 21 #include "ui/base/resource/resource_bundle.h" | |
| 22 #include "ui/gl/android/gl_jni_registrar.h" | |
| 23 #include "webkit/support/simple_resource_loader_bridge.h" | |
| 24 #include "webkit/support/test_webkit_platform_support.h" | |
| 25 | |
| 26 namespace { | |
| 27 | |
| 28 // The place where the Android layout test script will put the required tools | |
| 29 // and resources. Must keep consistent with DEVICE_DRT_DIR in | |
| 30 // WebKit/Tools/Scripts/webkitpy/layout_tests/port/chromium_android.py. | |
| 31 const char kDumpRenderTreeDir[] = "/data/local/tmp/drt"; | |
| 32 | |
| 33 } | |
| 34 | |
| 35 namespace webkit_support { | |
| 36 | |
| 37 void BeforeInitialize() { | |
| 38 base::InitAndroidTestPaths(); | |
| 39 | |
| 40 // Place cache under kDumpRenderTreeDir to allow the NRWT script to clear it. | |
| 41 base::FilePath path(kDumpRenderTreeDir); | |
| 42 path = path.Append("cache"); | |
| 43 PathService::Override(base::DIR_CACHE, path); | |
| 44 | |
| 45 // Set XML_CATALOG_FILES environment variable to blank to prevent libxml from | |
| 46 // loading and complaining the non-exsistent /etc/xml/catalog file. | |
| 47 setenv("XML_CATALOG_FILES", "", 0); | |
| 48 | |
| 49 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 50 net::android::RegisterNetworkLibrary(env); | |
| 51 } | |
| 52 | |
| 53 void AfterInitialize() { | |
| 54 base::FilePath data_path(kDumpRenderTreeDir); | |
| 55 data_path = data_path.Append("DumpRenderTree.pak"); | |
| 56 ResourceBundle::InitSharedInstanceWithPakPath(data_path); | |
| 57 } | |
| 58 | |
| 59 void BeforeShutdown() { | |
| 60 ResourceBundle::CleanupSharedInstance(); | |
| 61 } | |
| 62 | |
| 63 void AfterShutdown() { | |
| 64 } | |
| 65 | |
| 66 } // namespace webkit_support | |
| 67 | |
| 68 base::string16 TestWebKitPlatformSupport::GetLocalizedString(int message_id) { | |
| 69 return ResourceBundle::GetSharedInstance().GetLocalizedString(message_id); | |
| 70 } | |
| 71 | |
| 72 base::StringPiece TestWebKitPlatformSupport::GetDataResource( | |
| 73 int resource_id, | |
| 74 ui::ScaleFactor scale_factor) { | |
| 75 base::FilePath resources_path(kDumpRenderTreeDir); | |
| 76 resources_path = resources_path.Append("DumpRenderTree_resources"); | |
| 77 switch (resource_id) { | |
| 78 case IDR_BROKENIMAGE: { | |
| 79 CR_DEFINE_STATIC_LOCAL(std::string, broken_image_data, ()); | |
| 80 if (broken_image_data.empty()) { | |
| 81 base::FilePath path = resources_path.Append("missingImage.gif"); | |
| 82 bool success = file_util::ReadFileToString(path, &broken_image_data); | |
| 83 if (!success) | |
| 84 LOG(FATAL) << "Failed reading: " << path.value(); | |
| 85 } | |
| 86 return broken_image_data; | |
| 87 } | |
| 88 case IDR_TEXTAREA_RESIZER: { | |
| 89 CR_DEFINE_STATIC_LOCAL(std::string, resize_corner_data, ()); | |
| 90 if (resize_corner_data.empty()) { | |
| 91 base::FilePath path = resources_path.Append("textAreaResizeCorner.png"); | |
| 92 bool success = file_util::ReadFileToString(path, &resize_corner_data); | |
| 93 if (!success) | |
| 94 LOG(FATAL) << "Failed reading: " << path.value(); | |
| 95 } | |
| 96 return resize_corner_data; | |
| 97 } | |
| 98 } | |
| 99 | |
| 100 return ResourceBundle::GetSharedInstance().GetRawDataResourceForScale( | |
| 101 resource_id, scale_factor); | |
| 102 } | |
| OLD | NEW |