[Android] Allow multiple --install in bb_device_steps.py.
[chromium-blink-merge.git] / chrome / browser / translate / standalone_cld_data_harness.cc
blob018f4a1095855ed0472773bc7359954958b74803
1 // Copyright 2014 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 "standalone_cld_data_harness.h"
7 #include "base/base_paths.h"
8 #include "base/files/file_util.h"
9 #include "base/logging.h"
10 #include "base/path_service.h"
11 #include "chrome/common/chrome_paths.h"
12 #include "components/translate/content/common/cld_data_source.h"
13 #include "testing/gtest/include/gtest/gtest.h"
15 namespace {
17 // This has to match what's in chrome_translate_client.cc
18 const base::FilePath::CharType kStandaloneDataFileName[] =
19 FILE_PATH_LITERAL("cld2_data.bin");
21 } // namespace
23 namespace test {
25 StandaloneCldDataHarness::~StandaloneCldDataHarness() {
26 DVLOG(1) << "Tearing down CLD data harness";
27 DeleteStandaloneDataFile();
30 void StandaloneCldDataHarness::Init() {
31 DVLOG(1) << "Initializing CLD data harness";
32 // Dynamic data mode is enabled and we are using a standalone file.
33 translate::CldDataSource::Set(
34 translate::CldDataSource::GetStandaloneDataSource());
35 ASSERT_NO_FATAL_FAILURE(CopyStandaloneDataFile());
38 void StandaloneCldDataHarness::GetStandaloneDataFileSource(
39 base::FilePath* out_path) {
40 CldDataHarness::GetTestDataSourceDirectory(out_path);
41 *out_path = out_path->Append(FILE_PATH_LITERAL("_platform_specific"))
42 .Append(FILE_PATH_LITERAL("all"))
43 .Append(kStandaloneDataFileName);
46 // Using the USER_DATA_DIR not only mimics true functionality, but also is
47 // important to test isolation. Each test gets its own USER_DATA_DIR, which
48 // ensures proper isolation between test processes running in parallel.
49 void StandaloneCldDataHarness::GetStandaloneDataFileDestination(
50 base::FilePath* out_path) {
51 ASSERT_TRUE(PathService::Get(chrome::DIR_USER_DATA, out_path));
52 *out_path = out_path->Append(kStandaloneDataFileName);
55 void StandaloneCldDataHarness::DeleteStandaloneDataFile() {
56 base::FilePath path;
57 ASSERT_NO_FATAL_FAILURE(GetStandaloneDataFileDestination(&path));
58 DVLOG(1) << "Deleting CLD test data file from " << path.value();
59 base::DeleteFile(path, false);
62 void StandaloneCldDataHarness::CopyStandaloneDataFile() {
63 DeleteStandaloneDataFile(); // sanity: blow away any old copies.
64 base::FilePath target_file;
65 GetStandaloneDataFileDestination(&target_file);
66 base::FilePath target_dir = target_file.DirName();
67 ASSERT_TRUE(base::CreateDirectoryAndGetError(target_dir, NULL));
68 base::FilePath source_file;
69 GetStandaloneDataFileSource(&source_file);
70 DVLOG(1) << "Copying CLD test data file from " << source_file.value()
71 << " to " << target_file.value();
72 ASSERT_TRUE(base::CopyFile(source_file, target_file));
73 ASSERT_TRUE(base::PathExists(target_file));
76 } // namespace test