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/file_path.h"
8 #include "base/file_util.h"
9 #include "base/logging.h"
10 #include "base/path_service.h"
11 #include "base/string16.h"
12 #include "base/string_piece.h"
13 #include "grit/webkit_resources.h"
14 #include "ui/base/resource/resource_bundle.h"
15 #include "webkit/support/test_webkit_platform_support.h"
17 namespace webkit_support
{
19 // TODO(tkent): Implement some of the followings for platform-dependent tasks
20 // such as loading resource.
22 void BeforeInitialize(bool unit_test_mode
) {
25 void AfterInitialize(bool unit_test_mode
) {
27 PathService::Get(base::DIR_EXE
, &data_path
);
28 data_path
= data_path
.Append("DumpRenderTree.pak");
29 ResourceBundle::InitSharedInstanceWithPakPath(data_path
);
32 void BeforeShutdown() {
33 ResourceBundle::CleanupSharedInstance();
36 void AfterShutdown() {
39 } // namespace webkit_support
41 string16
TestWebKitPlatformSupport::GetLocalizedString(int message_id
) {
42 return ResourceBundle::GetSharedInstance().GetLocalizedString(message_id
);
45 base::StringPiece
TestWebKitPlatformSupport::GetDataResource(
47 ui::ScaleFactor scale_factor
) {
48 FilePath resources_path
;
49 PathService::Get(base::DIR_EXE
, &resources_path
);
50 resources_path
= resources_path
.Append("DumpRenderTree_resources");
51 switch (resource_id
) {
52 case IDR_BROKENIMAGE
: {
53 CR_DEFINE_STATIC_LOCAL(std::string
, broken_image_data
, ());
54 if (broken_image_data
.empty()) {
55 FilePath path
= resources_path
.Append("missingImage.gif");
56 bool success
= file_util::ReadFileToString(path
, &broken_image_data
);
58 LOG(FATAL
) << "Failed reading: " << path
.value();
60 return broken_image_data
;
62 case IDR_TEXTAREA_RESIZER
: {
63 CR_DEFINE_STATIC_LOCAL(std::string
, resize_corner_data
, ());
64 if (resize_corner_data
.empty()) {
65 FilePath path
= resources_path
.Append("textAreaResizeCorner.png");
66 bool success
= file_util::ReadFileToString(path
, &resize_corner_data
);
68 LOG(FATAL
) << "Failed reading: " << path
.value();
70 return resize_corner_data
;
74 return ResourceBundle::GetSharedInstance().GetRawDataResource(
75 resource_id
, scale_factor
);