Display new Autofill UI Contents in Views
[chromium-blink-merge.git] / webkit / support / platform_support_android.cc
blob278e517eb5c08f57136f930e677b9730a8ba0d41
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.
5 #include "webkit/support/platform_support.h"
7 #include "base/android/jni_android.h"
8 #include "base/file_path.h"
9 #include "base/file_util.h"
10 #include "base/logging.h"
11 #include "base/path_service.h"
12 #include "base/string16.h"
13 #include "base/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 "net/android/network_library.h"
18 #include "net/android/net_jni_registrar.h"
19 #include "media/base/android/media_jni_registrar.h"
20 #include "ui/base/resource/resource_bundle.h"
21 #include "webkit/support/test_webkit_platform_support.h"
22 #include "webkit/tools/test_shell/simple_resource_loader_bridge.h"
24 namespace {
26 // The place where the Android layout test script will put the required tools
27 // and resources. Must keep consistent with DEVICE_DRT_DIR in
28 // WebKit/Tools/Scripts/webkitpy/layout_tests/port/chromium_android.py.
29 const char kDumpRenderTreeDir[] = "/data/local/tmp/drt";
33 namespace webkit_support {
35 void BeforeInitialize(bool unit_test_mode) {
36 base::InitAndroidTestPaths();
38 // Place cache under kDumpRenderTreeDir to allow the NRWT script to clear it.
39 FilePath path(kDumpRenderTreeDir);
40 path = path.Append("cache");
41 PathService::Override(base::DIR_CACHE, path);
43 // Set XML_CATALOG_FILES environment variable to blank to prevent libxml from
44 // loading and complaining the non-exsistent /etc/xml/catalog file.
45 setenv("XML_CATALOG_FILES", "", 0);
47 JNIEnv* env = base::android::AttachCurrentThread();
48 net::android::RegisterNetworkLibrary(env);
50 // Chromium binaries will register their Jni bindings through the library
51 // loader that is part of content/. WebKit uses a different path, so the
52 // bindings have to be initialized separately as well.
53 if (!unit_test_mode) {
54 media::RegisterJni(env);
55 net::android::RegisterJni(env);
59 void AfterInitialize(bool unit_test_mode) {
60 FilePath data_path(kDumpRenderTreeDir);
61 data_path = data_path.Append("DumpRenderTree.pak");
62 ResourceBundle::InitSharedInstanceWithPakPath(data_path);
64 if (unit_test_mode)
65 return;
67 // We enable file-over-http to bridge the file protocol to http protocol
68 // in here, which can
69 // (1) run the layout tests on android target device, but never need to
70 // push the test files and corresponding resources to device, which saves
71 // huge running time.
72 // (2) still run non-http layout (tests not under LayoutTests/http) tests
73 // via file protocol without breaking test environment / convention of webkit
74 // layout tests, which are followed by current all webkit ports.
75 SimpleResourceLoaderBridge::AllowFileOverHTTP(
76 "third_party/WebKit/LayoutTests/",
77 GURL("http://127.0.0.1:8000/all-tests/"));
80 void BeforeShutdown() {
81 ResourceBundle::CleanupSharedInstance();
84 void AfterShutdown() {
87 } // namespace webkit_support
89 string16 TestWebKitPlatformSupport::GetLocalizedString(int message_id) {
90 return ResourceBundle::GetSharedInstance().GetLocalizedString(message_id);
93 base::StringPiece TestWebKitPlatformSupport::GetDataResource(
94 int resource_id,
95 ui::ScaleFactor scale_factor) {
96 FilePath resources_path(kDumpRenderTreeDir);
97 resources_path = resources_path.Append("DumpRenderTree_resources");
98 switch (resource_id) {
99 case IDR_BROKENIMAGE: {
100 CR_DEFINE_STATIC_LOCAL(std::string, broken_image_data, ());
101 if (broken_image_data.empty()) {
102 FilePath path = resources_path.Append("missingImage.gif");
103 bool success = file_util::ReadFileToString(path, &broken_image_data);
104 if (!success)
105 LOG(FATAL) << "Failed reading: " << path.value();
107 return broken_image_data;
109 case IDR_TEXTAREA_RESIZER: {
110 CR_DEFINE_STATIC_LOCAL(std::string, resize_corner_data, ());
111 if (resize_corner_data.empty()) {
112 FilePath path = resources_path.Append("textAreaResizeCorner.png");
113 bool success = file_util::ReadFileToString(path, &resize_corner_data);
114 if (!success)
115 LOG(FATAL) << "Failed reading: " << path.value();
117 return resize_corner_data;
121 return ResourceBundle::GetSharedInstance().GetRawDataResource(
122 resource_id, scale_factor);