blob: d59a91187e838790a767f84c79c01ef2f8656c78 [file] [log] [blame]
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/test/test_content_client.h"
#include <utility>
#include "base/base_paths.h"
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/path_service.h"
#include "base/strings/string_piece.h"
#include "build/build_config.h"
#if defined(OS_ANDROID)
#include "base/android/apk_assets.h"
#endif
namespace content {
TestContentClient::TestContentClient()
: data_pack_(ui::SCALE_FACTOR_100P) {
// content_shell.pak is not built on iOS as it is not required.
base::FilePath content_shell_pack_path;
base::File pak_file;
base::MemoryMappedFile::Region pak_region;
#if defined(OS_ANDROID)
// Tests that don't yet use .isolate files require loading from within .apk.
pak_file = base::File(
base::android::OpenApkAsset("assets/content_shell.pak", &pak_region));
// on Android all pak files are inside the paks folder.
PathService::Get(base::DIR_ANDROID_APP_DATA, &content_shell_pack_path);
content_shell_pack_path = content_shell_pack_path.Append(
FILE_PATH_LITERAL("paks"));
#else
PathService::Get(base::DIR_MODULE, &content_shell_pack_path);
#endif // defined(OS_ANDROID)
if (pak_file.IsValid()) {
data_pack_.LoadFromFileRegion(std::move(pak_file), pak_region);
} else {
content_shell_pack_path = content_shell_pack_path.Append(
FILE_PATH_LITERAL("content_shell.pak"));
data_pack_.LoadFromPath(content_shell_pack_path);
}
}
TestContentClient::~TestContentClient() {
}
std::string TestContentClient::GetUserAgent() const {
return std::string("TestContentClient");
}
base::StringPiece TestContentClient::GetDataResource(
int resource_id,
ui::ScaleFactor scale_factor) const {
base::StringPiece resource;
data_pack_.GetStringPiece(resource_id, &resource);
return resource;
}
} // namespace content