Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "webkit/support/platform_support.h" | 5 #include "webkit/support/platform_support.h" |
| 6 | 6 |
| 7 #include <locale.h> | |
| 8 | |
| 7 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 8 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| 9 #include "base/logging.h" | 11 #include "base/logging.h" |
| 10 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 11 #include "base/string16.h" | 13 #include "base/string16.h" |
| 12 #include "base/string_piece.h" | 14 #include "base/string_piece.h" |
| 13 #include "base/test/test_stub_android.h" | 15 #include "base/test/test_support_android.h" |
| 14 #include "googleurl/src/gurl.h" | 16 #include "googleurl/src/gurl.h" |
| 15 #include "grit/webkit_resources.h" | 17 #include "grit/webkit_resources.h" |
| 16 #include "ui/base/resource/resource_bundle.h" | 18 #include "ui/base/resource/resource_bundle.h" |
| 17 #include "webkit/support/test_webkit_platform_support.h" | 19 #include "webkit/support/test_webkit_platform_support.h" |
| 18 #include "webkit/tools/test_shell/simple_resource_loader_bridge.h" | 20 #include "webkit/tools/test_shell/simple_resource_loader_bridge.h" |
| 19 | 21 |
| 22 namespace { | |
| 23 | |
| 24 // The place where the Android layout test script will put the required tools | |
| 25 // and resources. Must keep consistent with DEVICE_DRT_DIR in | |
| 26 // WebKit/Tools/Scripts/webkitpy/layout_tests/port/chromium_android.py. | |
| 27 // TODO(wangxianzhu): Allow running DRT on non-rooted device by putting | |
| 28 // the tools and resources into the apk or under /data/local/tmp. | |
| 29 const char kDumpRenderTreeDir[] = "/data/drt"; | |
| 30 | |
| 31 } | |
| 32 | |
| 20 namespace webkit_support { | 33 namespace webkit_support { |
| 21 | 34 |
| 22 void BeforeInitialize(bool unit_test_mode) { | 35 void BeforeInitialize(bool unit_test_mode) { |
| 23 InitAndroidOSPathStub(); | 36 // Some tests rely on this to produce proper number format etc., |
| 37 // e.g. fast/speech/input-appearance-numberandspeech.html. | |
| 38 setlocale(LC_CTYPE, "en_US"); | |
|
Paweł Hajdan Jr.
2012/05/25 19:06:08
Is this ever used in non-test code? If so, this lo
Xianzhu
2012/05/29 17:15:55
This is only for layout tests. Just verified that
| |
| 39 | |
| 40 InitAndroidTestPaths(); | |
| 41 | |
| 24 // Set XML_CATALOG_FILES environment variable to blank to prevent libxml from | 42 // Set XML_CATALOG_FILES environment variable to blank to prevent libxml from |
| 25 // loading and complaining the non-exsistent /etc/xml/catalog file. | 43 // loading and complaining the non-exsistent /etc/xml/catalog file. |
| 26 setenv("XML_CATALOG_FILES", "", 0); | 44 setenv("XML_CATALOG_FILES", "", 0); |
| 27 } | 45 } |
| 28 | 46 |
| 29 void AfterInitialize(bool unit_test_mode) { | 47 void AfterInitialize(bool unit_test_mode) { |
| 30 if (unit_test_mode) | 48 if (unit_test_mode) |
| 31 return; // We don't have a resource pack when running the unit-tests. | 49 return; // We don't have a resource pack when running the unit-tests. |
| 32 | 50 |
| 33 FilePath data_path; | 51 FilePath data_path(kDumpRenderTreeDir); |
| 34 PathService::Get(base::DIR_EXE, &data_path); | |
| 35 data_path = data_path.Append("DumpRenderTree.pak"); | 52 data_path = data_path.Append("DumpRenderTree.pak"); |
| 36 ResourceBundle::InitSharedInstanceWithPakFile(data_path); | 53 ResourceBundle::InitSharedInstanceWithPakFile(data_path); |
| 37 | 54 |
| 38 // We enable file-over-http to bridge the file protocol to http protocol | 55 // We enable file-over-http to bridge the file protocol to http protocol |
| 39 // in here, which can | 56 // in here, which can |
| 40 // (1) run the layout tests on android target device, but never need to | 57 // (1) run the layout tests on android target device, but never need to |
| 41 // push the test files and corresponding resources to device, which saves | 58 // push the test files and corresponding resources to device, which saves |
| 42 // huge running time. | 59 // huge running time. |
| 43 // (2) still run non-http layout (tests not under LayoutTests/http) tests | 60 // (2) still run non-http layout (tests not under LayoutTests/http) tests |
| 44 // via file protocol without breaking test environment / convention of webkit | 61 // via file protocol without breaking test environment / convention of webkit |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 57 | 74 |
| 58 } // namespace webkit_support | 75 } // namespace webkit_support |
| 59 | 76 |
| 60 string16 TestWebKitPlatformSupport::GetLocalizedString(int message_id) { | 77 string16 TestWebKitPlatformSupport::GetLocalizedString(int message_id) { |
| 61 return ResourceBundle::GetSharedInstance().GetLocalizedString(message_id); | 78 return ResourceBundle::GetSharedInstance().GetLocalizedString(message_id); |
| 62 } | 79 } |
| 63 | 80 |
| 64 base::StringPiece TestWebKitPlatformSupport::GetDataResource( | 81 base::StringPiece TestWebKitPlatformSupport::GetDataResource( |
| 65 int resource_id, | 82 int resource_id, |
| 66 ui::ScaleFactor scale_factor) { | 83 ui::ScaleFactor scale_factor) { |
| 67 FilePath resources_path; | 84 FilePath resources_path(kDumpRenderTreeDir); |
| 68 PathService::Get(base::DIR_EXE, &resources_path); | |
| 69 resources_path = resources_path.Append("DumpRenderTree_resources"); | 85 resources_path = resources_path.Append("DumpRenderTree_resources"); |
| 70 switch (resource_id) { | 86 switch (resource_id) { |
| 71 case IDR_BROKENIMAGE: { | 87 case IDR_BROKENIMAGE: { |
| 72 static std::string broken_image_data; | 88 CR_DEFINE_STATIC_LOCAL(std::string, broken_image_data, ()); |
| 73 if (broken_image_data.empty()) { | 89 if (broken_image_data.empty()) { |
| 74 FilePath path = resources_path.Append("missingImage.gif"); | 90 FilePath path = resources_path.Append("missingImage.gif"); |
| 75 bool success = file_util::ReadFileToString(path, &broken_image_data); | 91 bool success = file_util::ReadFileToString(path, &broken_image_data); |
| 76 if (!success) | 92 if (!success) |
| 77 LOG(FATAL) << "Failed reading: " << path.value(); | 93 LOG(FATAL) << "Failed reading: " << path.value(); |
| 78 } | 94 } |
| 79 return broken_image_data; | 95 return broken_image_data; |
| 80 } | 96 } |
| 81 case IDR_TEXTAREA_RESIZER: { | 97 case IDR_TEXTAREA_RESIZER: { |
| 82 static std::string resize_corner_data; | 98 CR_DEFINE_STATIC_LOCAL(std::string, resize_corner_data, ()); |
| 83 if (resize_corner_data.empty()) { | 99 if (resize_corner_data.empty()) { |
| 84 FilePath path = resources_path.Append("textAreaResizeCorner.png"); | 100 FilePath path = resources_path.Append("textAreaResizeCorner.png"); |
| 85 bool success = file_util::ReadFileToString(path, &resize_corner_data); | 101 bool success = file_util::ReadFileToString(path, &resize_corner_data); |
| 86 if (!success) | 102 if (!success) |
| 87 LOG(FATAL) << "Failed reading: " << path.value(); | 103 LOG(FATAL) << "Failed reading: " << path.value(); |
| 88 } | 104 } |
| 89 return resize_corner_data; | 105 return resize_corner_data; |
| 90 } | 106 } |
| 91 } | 107 } |
| 92 | 108 |
| 93 return ResourceBundle::GetSharedInstance().GetRawDataResource( | 109 return ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 94 resource_id, scale_factor); | 110 resource_id, scale_factor); |
| 95 } | 111 } |
| OLD | NEW |