Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(166)

Side by Side Diff: content/test/test_content_client.cc

Issue 1217063002: Have test_content_client look for .pak file in the .apk as well as on disk (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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)
14 #include "base/android/apk_assets.h"
15 #endif
16
13 namespace content { 17 namespace content {
14 18
15 TestContentClient::TestContentClient() 19 TestContentClient::TestContentClient()
16 : data_pack_(ui::SCALE_FACTOR_100P) { 20 : data_pack_(ui::SCALE_FACTOR_100P) {
17 // 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.
18 #if !defined(OS_IOS) 22 #if !defined(OS_IOS)
19 base::FilePath content_shell_pack_path; 23 base::FilePath content_shell_pack_path;
20 #if defined(OS_ANDROID) 24 #if defined(OS_ANDROID)
25 base::MemoryMappedFile::Region region;
26 // Tests that don't yet use .isolate files require loading from within .apk.
27 int fd = base::android::OpenApkAsset("assets/content_shell.pak", &region);
28 if (fd >= 0) {
29 data_pack_.LoadFromFileRegion(base::File(fd), region);
30 return;
boliu 2015/06/29 20:24:32 This is making the structure here super brittle. E
agrieve 2015/06/29 20:38:04 Agree. Will address in a follow-up.
31 }
32
21 // on Android all pak files are inside the paks folder. 33 // on Android all pak files are inside the paks folder.
22 PathService::Get(base::DIR_ANDROID_APP_DATA, &content_shell_pack_path); 34 PathService::Get(base::DIR_ANDROID_APP_DATA, &content_shell_pack_path);
23 content_shell_pack_path = content_shell_pack_path.Append( 35 content_shell_pack_path = content_shell_pack_path.Append(
24 FILE_PATH_LITERAL("paks")); 36 FILE_PATH_LITERAL("paks"));
25 #else 37 #else
26 PathService::Get(base::DIR_MODULE, &content_shell_pack_path); 38 PathService::Get(base::DIR_MODULE, &content_shell_pack_path);
27 #endif 39 #endif
28 content_shell_pack_path = content_shell_pack_path.Append( 40 content_shell_pack_path = content_shell_pack_path.Append(
29 FILE_PATH_LITERAL("content_shell.pak")); 41 FILE_PATH_LITERAL("content_shell.pak"));
30 data_pack_.LoadFromPath(content_shell_pack_path); 42 data_pack_.LoadFromPath(content_shell_pack_path);
31 #endif 43 #endif
32 } 44 }
33 45
34 TestContentClient::~TestContentClient() { 46 TestContentClient::~TestContentClient() {
35 } 47 }
36 48
37 std::string TestContentClient::GetUserAgent() const { 49 std::string TestContentClient::GetUserAgent() const {
38 return std::string("TestContentClient"); 50 return std::string("TestContentClient");
39 } 51 }
40 52
41 base::StringPiece TestContentClient::GetDataResource( 53 base::StringPiece TestContentClient::GetDataResource(
42 int resource_id, 54 int resource_id,
43 ui::ScaleFactor scale_factor) const { 55 ui::ScaleFactor scale_factor) const {
44 base::StringPiece resource; 56 base::StringPiece resource;
45 data_pack_.GetStringPiece(resource_id, &resource); 57 data_pack_.GetStringPiece(resource_id, &resource);
46 return resource; 58 return resource;
47 } 59 }
48 60
49 } // namespace content 61 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698