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 "content/test/test_content_client.h" | 5 #include "content/test/test_content_client.h" |
6 | 6 |
7 #include "base/base_paths.h" | 7 #include "base/base_paths.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
11 #include "base/strings/string_piece.h" | 11 #include "base/strings/string_piece.h" |
12 | 12 |
13 #if defined(OS_ANDROID) | 13 #if defined(OS_ANDROID) |
14 #include "base/android/apk_assets.h" | 14 #include "base/android/apk_assets.h" |
15 #endif | 15 #endif |
16 | 16 |
17 namespace content { | 17 namespace content { |
18 | 18 |
19 TestContentClient::TestContentClient() | 19 TestContentClient::TestContentClient() |
20 : data_pack_(ui::SCALE_FACTOR_100P) { | 20 : data_pack_(ui::SCALE_FACTOR_100P) { |
21 // content_shell.pak is not built on iOS as it is not required. | 21 // content_shell.pak is not built on iOS as it is not required. |
22 #if !defined(OS_IOS) | 22 #if !defined(OS_IOS) |
23 base::FilePath content_shell_pack_path; | 23 base::FilePath content_shell_pack_path; |
| 24 base::File pak_file; |
| 25 base::MemoryMappedFile::Region pak_region; |
| 26 |
24 #if defined(OS_ANDROID) | 27 #if defined(OS_ANDROID) |
25 base::MemoryMappedFile::Region region; | |
26 // Tests that don't yet use .isolate files require loading from within .apk. | 28 // Tests that don't yet use .isolate files require loading from within .apk. |
27 int fd = base::android::OpenApkAsset("assets/content_shell.pak", ®ion); | 29 pak_file = base::File( |
28 if (fd >= 0) { | 30 base::android::OpenApkAsset("assets/content_shell.pak", &pak_region)); |
29 data_pack_.LoadFromFileRegion(base::File(fd), region); | |
30 return; | |
31 } | |
32 | 31 |
33 // on Android all pak files are inside the paks folder. | 32 // on Android all pak files are inside the paks folder. |
34 PathService::Get(base::DIR_ANDROID_APP_DATA, &content_shell_pack_path); | 33 PathService::Get(base::DIR_ANDROID_APP_DATA, &content_shell_pack_path); |
35 content_shell_pack_path = content_shell_pack_path.Append( | 34 content_shell_pack_path = content_shell_pack_path.Append( |
36 FILE_PATH_LITERAL("paks")); | 35 FILE_PATH_LITERAL("paks")); |
37 #else | 36 #else |
38 PathService::Get(base::DIR_MODULE, &content_shell_pack_path); | 37 PathService::Get(base::DIR_MODULE, &content_shell_pack_path); |
39 #endif | 38 #endif // defined(OS_ANDROID) |
40 content_shell_pack_path = content_shell_pack_path.Append( | 39 |
41 FILE_PATH_LITERAL("content_shell.pak")); | 40 if (pak_file.IsValid()) { |
42 data_pack_.LoadFromPath(content_shell_pack_path); | 41 data_pack_.LoadFromFileRegion(pak_file.Pass(), pak_region); |
43 #endif | 42 } else { |
| 43 content_shell_pack_path = content_shell_pack_path.Append( |
| 44 FILE_PATH_LITERAL("content_shell.pak")); |
| 45 data_pack_.LoadFromPath(content_shell_pack_path); |
| 46 } |
| 47 #endif // !defined(OS_IOS) |
44 } | 48 } |
45 | 49 |
46 TestContentClient::~TestContentClient() { | 50 TestContentClient::~TestContentClient() { |
47 } | 51 } |
48 | 52 |
49 std::string TestContentClient::GetUserAgent() const { | 53 std::string TestContentClient::GetUserAgent() const { |
50 return std::string("TestContentClient"); | 54 return std::string("TestContentClient"); |
51 } | 55 } |
52 | 56 |
53 base::StringPiece TestContentClient::GetDataResource( | 57 base::StringPiece TestContentClient::GetDataResource( |
54 int resource_id, | 58 int resource_id, |
55 ui::ScaleFactor scale_factor) const { | 59 ui::ScaleFactor scale_factor) const { |
56 base::StringPiece resource; | 60 base::StringPiece resource; |
57 data_pack_.GetStringPiece(resource_id, &resource); | 61 data_pack_.GetStringPiece(resource_id, &resource); |
58 return resource; | 62 return resource; |
59 } | 63 } |
60 | 64 |
61 } // namespace content | 65 } // namespace content |
OLD | NEW |