OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #include "scoped_cld_standalone_data_harness.h" | |
6 | |
7 #include "base/base_paths.h" | |
8 #include "base/file_util.h" | |
9 #include "base/logging.h" | |
10 #include "base/path_service.h" | |
11 #include "chrome/common/chrome_paths.h" | |
12 #include "testing/gtest/include/gtest/gtest.h" | |
13 | |
14 | |
15 namespace { | |
16 | |
17 // This comes from chrome_translate_client.cc | |
18 const base::FilePath::CharType kStandaloneDataFileName[] = | |
19 FILE_PATH_LITERAL("cld2_data.bin"); | |
20 | |
21 } // namespace | |
22 | |
23 namespace test { | |
24 | |
25 ScopedCldStandaloneDataHarness::ScopedCldStandaloneDataHarness() { | |
26 // Constructor does nothing in all cases. See Init() for initialization. | |
27 } | |
28 | |
29 ScopedCldStandaloneDataHarness::~ScopedCldStandaloneDataHarness() { | |
30 VLOG(1) << "Tearing down CLD data harness"; | |
31 DeleteStandaloneDataFile(); | |
32 } | |
33 | |
34 void ScopedCldStandaloneDataHarness::Init() { | |
35 VLOG(1) << "Initializing CLD data harness"; | |
36 // Dynamic data mode is enabled and we are using a standalone file. | |
37 ASSERT_NO_FATAL_FAILURE(CopyStandaloneDataFile()); | |
38 } | |
39 | |
40 void ScopedCldStandaloneDataHarness::GetStandaloneDataFileSource( | |
41 base::FilePath* out_path) { | |
42 ScopedCldDataHarness::GetTestDataSourceDirectory(out_path); | |
43 *out_path = out_path->Append(FILE_PATH_LITERAL("_platform_specific")) | |
44 .Append(FILE_PATH_LITERAL("all")) | |
45 .Append(kStandaloneDataFileName); | |
46 } | |
47 | |
48 // Using the USER_DATA_DIR not only mimics true functionality, but also is | |
49 // important to test isolation. Each test gets its own USER_DATA_DIR, which | |
50 // ensures proper isolation between test processes running in parallel. | |
51 void ScopedCldStandaloneDataHarness::GetStandaloneDataFileDestination( | |
52 base::FilePath* out_path) { | |
53 ASSERT_TRUE(PathService::Get(chrome::DIR_USER_DATA, out_path)); | |
54 *out_path = out_path->Append(kStandaloneDataFileName); | |
55 } | |
56 | |
57 void ScopedCldStandaloneDataHarness::DeleteStandaloneDataFile() { | |
58 base::FilePath path; | |
59 ASSERT_NO_FATAL_FAILURE(GetStandaloneDataFileDestination(&path)); | |
60 VLOG(1) << "Deleting CLD test data file from " << path.value(); | |
61 base::DeleteFile(path, false); | |
62 } | |
63 | |
64 void ScopedCldStandaloneDataHarness::CopyStandaloneDataFile() { | |
65 DeleteStandaloneDataFile(); // sanity: blow away any old copies. | |
66 base::FilePath target_file; | |
67 GetStandaloneDataFileDestination(&target_file); | |
68 base::FilePath target_dir = target_file.DirName(); | |
69 ASSERT_TRUE(base::CreateDirectoryAndGetError(target_dir, NULL)); | |
70 base::FilePath source_file; | |
71 GetStandaloneDataFileSource(&source_file); | |
72 VLOG(1) << "Copying CLD test data file from " << source_file.value() | |
73 << " to " << target_file.value(); | |
Takashi Toyoshima
2014/06/23 08:50:01
The first '<<' should be aligned with the first '<
Andrew Hayden (chromium.org)
2014/06/23 13:20:35
Sorry, this is due to refactoring DLOG(INFO) -> VL
| |
74 ASSERT_TRUE(base::CopyFile(source_file, target_file)); | |
75 ASSERT_TRUE(base::PathExists(target_file)); | |
76 } | |
77 | |
78 scoped_ptr<ScopedCldDataHarness> | |
Takashi Toyoshima
2014/06/23 08:50:01
no line break here
Andrew Hayden (chromium.org)
2014/06/23 13:20:36
Done.
| |
79 CreateScopedCldDataHarness() { | |
80 scoped_ptr<ScopedCldDataHarness> result(new ScopedCldStandaloneDataHarness()); | |
81 return result.Pass(); | |
82 } | |
83 | |
84 } // namespace test | |
OLD | NEW |