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 "base/android/jni_android.h" |
7 #include "base/file_path.h" | 8 #include "base/file_path.h" |
8 #include "base/file_util.h" | 9 #include "base/file_util.h" |
9 #include "base/logging.h" | 10 #include "base/logging.h" |
10 #include "base/path_service.h" | 11 #include "base/path_service.h" |
11 #include "base/string16.h" | 12 #include "base/string16.h" |
12 #include "base/string_piece.h" | 13 #include "base/string_piece.h" |
13 #include "base/test/test_stub_android.h" | 14 #include "base/test/test_support_android.h" |
14 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
15 #include "grit/webkit_resources.h" | 16 #include "grit/webkit_resources.h" |
| 17 #include "net/android/network_library.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 InitAndroidTestPaths(); |
| 37 |
24 // Set XML_CATALOG_FILES environment variable to blank to prevent libxml from | 38 // Set XML_CATALOG_FILES environment variable to blank to prevent libxml from |
25 // loading and complaining the non-exsistent /etc/xml/catalog file. | 39 // loading and complaining the non-exsistent /etc/xml/catalog file. |
26 setenv("XML_CATALOG_FILES", "", 0); | 40 setenv("XML_CATALOG_FILES", "", 0); |
| 41 |
| 42 JNIEnv* env = base::android::AttachCurrentThread(); |
| 43 net::android::RegisterNetworkLibrary(env); |
27 } | 44 } |
28 | 45 |
29 void AfterInitialize(bool unit_test_mode) { | 46 void AfterInitialize(bool unit_test_mode) { |
30 if (unit_test_mode) | 47 if (unit_test_mode) |
31 return; // We don't have a resource pack when running the unit-tests. | 48 return; // We don't have a resource pack when running the unit-tests. |
32 | 49 |
33 FilePath data_path; | 50 FilePath data_path(kDumpRenderTreeDir); |
34 PathService::Get(base::DIR_EXE, &data_path); | |
35 data_path = data_path.Append("DumpRenderTree.pak"); | 51 data_path = data_path.Append("DumpRenderTree.pak"); |
36 ResourceBundle::InitSharedInstanceWithPakFile(data_path); | 52 ResourceBundle::InitSharedInstanceWithPakFile(data_path); |
37 | 53 |
38 // We enable file-over-http to bridge the file protocol to http protocol | 54 // We enable file-over-http to bridge the file protocol to http protocol |
39 // in here, which can | 55 // in here, which can |
40 // (1) run the layout tests on android target device, but never need to | 56 // (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 | 57 // push the test files and corresponding resources to device, which saves |
42 // huge running time. | 58 // huge running time. |
43 // (2) still run non-http layout (tests not under LayoutTests/http) tests | 59 // (2) still run non-http layout (tests not under LayoutTests/http) tests |
44 // via file protocol without breaking test environment / convention of webkit | 60 // via file protocol without breaking test environment / convention of webkit |
(...skipping 12 matching lines...) Expand all Loading... |
57 | 73 |
58 } // namespace webkit_support | 74 } // namespace webkit_support |
59 | 75 |
60 string16 TestWebKitPlatformSupport::GetLocalizedString(int message_id) { | 76 string16 TestWebKitPlatformSupport::GetLocalizedString(int message_id) { |
61 return ResourceBundle::GetSharedInstance().GetLocalizedString(message_id); | 77 return ResourceBundle::GetSharedInstance().GetLocalizedString(message_id); |
62 } | 78 } |
63 | 79 |
64 base::StringPiece TestWebKitPlatformSupport::GetDataResource( | 80 base::StringPiece TestWebKitPlatformSupport::GetDataResource( |
65 int resource_id, | 81 int resource_id, |
66 ui::ScaleFactor scale_factor) { | 82 ui::ScaleFactor scale_factor) { |
67 FilePath resources_path; | 83 FilePath resources_path(kDumpRenderTreeDir); |
68 PathService::Get(base::DIR_EXE, &resources_path); | |
69 resources_path = resources_path.Append("DumpRenderTree_resources"); | 84 resources_path = resources_path.Append("DumpRenderTree_resources"); |
70 switch (resource_id) { | 85 switch (resource_id) { |
71 case IDR_BROKENIMAGE: { | 86 case IDR_BROKENIMAGE: { |
72 static std::string broken_image_data; | 87 CR_DEFINE_STATIC_LOCAL(std::string, broken_image_data, ()); |
73 if (broken_image_data.empty()) { | 88 if (broken_image_data.empty()) { |
74 FilePath path = resources_path.Append("missingImage.gif"); | 89 FilePath path = resources_path.Append("missingImage.gif"); |
75 bool success = file_util::ReadFileToString(path, &broken_image_data); | 90 bool success = file_util::ReadFileToString(path, &broken_image_data); |
76 if (!success) | 91 if (!success) |
77 LOG(FATAL) << "Failed reading: " << path.value(); | 92 LOG(FATAL) << "Failed reading: " << path.value(); |
78 } | 93 } |
79 return broken_image_data; | 94 return broken_image_data; |
80 } | 95 } |
81 case IDR_TEXTAREA_RESIZER: { | 96 case IDR_TEXTAREA_RESIZER: { |
82 static std::string resize_corner_data; | 97 CR_DEFINE_STATIC_LOCAL(std::string, resize_corner_data, ()); |
83 if (resize_corner_data.empty()) { | 98 if (resize_corner_data.empty()) { |
84 FilePath path = resources_path.Append("textAreaResizeCorner.png"); | 99 FilePath path = resources_path.Append("textAreaResizeCorner.png"); |
85 bool success = file_util::ReadFileToString(path, &resize_corner_data); | 100 bool success = file_util::ReadFileToString(path, &resize_corner_data); |
86 if (!success) | 101 if (!success) |
87 LOG(FATAL) << "Failed reading: " << path.value(); | 102 LOG(FATAL) << "Failed reading: " << path.value(); |
88 } | 103 } |
89 return resize_corner_data; | 104 return resize_corner_data; |
90 } | 105 } |
91 } | 106 } |
92 | 107 |
93 return ResourceBundle::GetSharedInstance().GetRawDataResource( | 108 return ResourceBundle::GetSharedInstance().GetRawDataResource( |
94 resource_id, scale_factor); | 109 resource_id, scale_factor); |
95 } | 110 } |
OLD | NEW |