Mandoline: ConnectToApplication and ConnectToService should fail gracefully
[chromium-blink-merge.git] / content / test / test_content_client.cc
blob16b8ad449d9aa38157015edff7bfb5bc83192f99
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 "content/test/test_content_client.h"
7 #include "base/base_paths.h"
8 #include "base/files/file_path.h"
9 #include "base/logging.h"
10 #include "base/path_service.h"
11 #include "base/strings/string_piece.h"
13 #if defined(OS_ANDROID)
14 #include "base/android/apk_assets.h"
15 #endif
17 namespace content {
19 TestContentClient::TestContentClient()
20 : data_pack_(ui::SCALE_FACTOR_100P) {
21 // content_shell.pak is not built on iOS as it is not required.
22 #if !defined(OS_IOS)
23 base::FilePath content_shell_pack_path;
24 base::File pak_file;
25 base::MemoryMappedFile::Region pak_region;
27 #if defined(OS_ANDROID)
28 // Tests that don't yet use .isolate files require loading from within .apk.
29 pak_file = base::File(
30 base::android::OpenApkAsset("assets/content_shell.pak", &pak_region));
32 // on Android all pak files are inside the paks folder.
33 PathService::Get(base::DIR_ANDROID_APP_DATA, &content_shell_pack_path);
34 content_shell_pack_path = content_shell_pack_path.Append(
35 FILE_PATH_LITERAL("paks"));
36 #else
37 PathService::Get(base::DIR_MODULE, &content_shell_pack_path);
38 #endif // defined(OS_ANDROID)
40 if (pak_file.IsValid()) {
41 data_pack_.LoadFromFileRegion(pak_file.Pass(), pak_region);
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);
47 #endif // !defined(OS_IOS)
50 TestContentClient::~TestContentClient() {
53 std::string TestContentClient::GetUserAgent() const {
54 return std::string("TestContentClient");
57 base::StringPiece TestContentClient::GetDataResource(
58 int resource_id,
59 ui::ScaleFactor scale_factor) const {
60 base::StringPiece resource;
61 data_pack_.GetStringPiece(resource_id, &resource);
62 return resource;
65 } // namespace content