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