OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "component_cld_data_harness.h" | 5 #include "chrome/browser/translate/component_cld_data_harness.h" |
6 | 6 |
7 #include "base/base_paths.h" | 7 #include "base/base_paths.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.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 "chrome/browser/component_updater/cld_component_installer.h" | 11 #include "chrome/browser/component_updater/cld_component_installer.h" |
12 #include "chrome/common/chrome_paths.h" | 12 #include "chrome/common/chrome_paths.h" |
| 13 #include "components/component_updater/component_updater_paths.h" |
| 14 #include "components/translate/content/common/cld_data_source.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
14 | 16 |
15 namespace { | 17 namespace { |
16 | 18 |
17 // This has to match what's in cld_component_installer.cc. | 19 // This has to match what's in cld_component_installer.cc. |
18 const base::FilePath::CharType kComponentDataFileName[] = | 20 const base::FilePath::CharType kComponentDataFileName[] = |
19 FILE_PATH_LITERAL("cld2_data.bin"); | 21 FILE_PATH_LITERAL("cld2_data.bin"); |
20 | 22 |
21 } // namespace | 23 } // namespace |
22 | 24 |
23 namespace test { | 25 namespace test { |
24 | 26 |
25 ComponentCldDataHarness::ComponentCldDataHarness() { | |
26 // Constructor does nothing in all cases. See Init() for initialization. | |
27 } | |
28 | |
29 ComponentCldDataHarness::~ComponentCldDataHarness() { | 27 ComponentCldDataHarness::~ComponentCldDataHarness() { |
30 DVLOG(1) << "Tearing down CLD data harness"; | 28 DVLOG(1) << "Tearing down CLD data harness"; |
31 // Dynamic data mode is enabled and we are using the component updater. | 29 // Dynamic data mode is enabled and we are using the component updater. |
32 component_updater::CldComponentInstallerTraits::SetLatestCldDataFile( | 30 component_updater::CldComponentInstallerTraits::SetLatestCldDataFile( |
33 base::FilePath()); | 31 base::FilePath()); |
34 ClearComponentDataFileState(); | 32 ClearComponentDataFileState(); |
35 DeleteComponentTree(); | 33 DeleteComponentTree(); |
36 } | 34 } |
37 | 35 |
38 void ComponentCldDataHarness::Init() { | 36 void ComponentCldDataHarness::Init() { |
39 DVLOG(1) << "Initializing CLD data harness"; | 37 DVLOG(1) << "Initializing CLD data harness"; |
40 // Dynamic data mode is enabled and we are using the component updater. | 38 // Dynamic data mode is enabled and we are using the component updater. |
| 39 translate::CldDataSource::Set( |
| 40 translate::CldDataSource::GetComponentDataSource()); |
41 ASSERT_NO_FATAL_FAILURE(CopyComponentTree()); | 41 ASSERT_NO_FATAL_FAILURE(CopyComponentTree()); |
42 base::FilePath data_file; | 42 base::FilePath data_file; |
43 GetComponentDataFileDestination(&data_file); | 43 GetComponentDataFileDestination(&data_file); |
44 component_updater::CldComponentInstallerTraits::SetLatestCldDataFile( | 44 component_updater::CldComponentInstallerTraits::SetLatestCldDataFile( |
45 data_file); | 45 data_file); |
46 } | 46 } |
47 | 47 |
48 void ComponentCldDataHarness::ClearComponentDataFileState() { | 48 void ComponentCldDataHarness::ClearComponentDataFileState() { |
49 DVLOG(1) << "Clearing component CLD data file state"; | 49 DVLOG(1) << "Clearing component CLD data file state"; |
50 base::FilePath nothing; | 50 base::FilePath nothing; |
51 component_updater::CldComponentInstallerTraits::SetLatestCldDataFile(nothing); | 51 component_updater::CldComponentInstallerTraits::SetLatestCldDataFile(nothing); |
52 } | 52 } |
53 | 53 |
54 // DIR_COMPONENT_CLD2 is also defined as being relative to USER_DATA_DIR, so | 54 // DIR_COMPONENT_CLD2 is also defined as being relative to USER_DATA_DIR, so |
55 // like GetStandaloneDataFileDestination, this is safe to run in multiple | 55 // like GetStandaloneDataFileDestination, this is safe to run in multiple |
56 // parallel test processes. | 56 // parallel test processes. |
57 void ComponentCldDataHarness::GetExtractedComponentDestination( | 57 void ComponentCldDataHarness::GetExtractedComponentDestination( |
58 base::FilePath* out_path) { | 58 base::FilePath* out_path) { |
59 ASSERT_TRUE(PathService::Get(chrome::DIR_COMPONENT_CLD2, out_path)); | 59 ASSERT_TRUE(PathService::Get(component_updater::DIR_COMPONENT_CLD2, |
| 60 out_path)); |
60 } | 61 } |
61 | 62 |
62 void ComponentCldDataHarness::GetComponentDataFileDestination( | 63 void ComponentCldDataHarness::GetComponentDataFileDestination( |
63 base::FilePath* out_path) { | 64 base::FilePath* out_path) { |
64 GetExtractedComponentDestination(out_path); | 65 GetExtractedComponentDestination(out_path); |
65 *out_path = out_path->Append(CldDataHarness::GetTestDataSourceCrxVersion()) | 66 *out_path = out_path->Append(CldDataHarness::GetTestDataSourceCrxVersion()) |
66 .Append(FILE_PATH_LITERAL("_platform_specific")) | 67 .Append(FILE_PATH_LITERAL("_platform_specific")) |
67 .Append(FILE_PATH_LITERAL("all")) | 68 .Append(FILE_PATH_LITERAL("all")) |
68 .Append(kComponentDataFileName); | 69 .Append(kComponentDataFileName); |
69 } | 70 } |
(...skipping 14 matching lines...) Expand all Loading... |
84 DVLOG(1) << "Copying CLD component test files from " << source_dir.value() | 85 DVLOG(1) << "Copying CLD component test files from " << source_dir.value() |
85 << " to " << target_dir.value(); | 86 << " to " << target_dir.value(); |
86 ASSERT_TRUE(base::CreateDirectoryAndGetError(target_dir, NULL)); | 87 ASSERT_TRUE(base::CreateDirectoryAndGetError(target_dir, NULL)); |
87 ASSERT_TRUE(base::CopyDirectory(source_dir, target_dir, true)); | 88 ASSERT_TRUE(base::CopyDirectory(source_dir, target_dir, true)); |
88 ASSERT_TRUE(base::PathExists(target_dir)); | 89 ASSERT_TRUE(base::PathExists(target_dir)); |
89 base::FilePath check_path; | 90 base::FilePath check_path; |
90 GetComponentDataFileDestination(&check_path); | 91 GetComponentDataFileDestination(&check_path); |
91 ASSERT_TRUE(base::PathExists(check_path)); | 92 ASSERT_TRUE(base::PathExists(check_path)); |
92 } | 93 } |
93 | 94 |
94 scoped_ptr<CldDataHarness> CreateCldDataHarness() { | |
95 scoped_ptr<CldDataHarness> result(new ComponentCldDataHarness()); | |
96 return result.Pass(); | |
97 } | |
98 | |
99 } // namespace test | 95 } // namespace test |
OLD | NEW |