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() { | 27 ComponentCldDataHarness::ComponentCldDataHarness() { |
26 // Constructor does nothing in all cases. See Init() for initialization. | 28 // Constructor does nothing in all cases. See Init() for initialization. |
27 } | 29 } |
28 | 30 |
29 ComponentCldDataHarness::~ComponentCldDataHarness() { | 31 ComponentCldDataHarness::~ComponentCldDataHarness() { |
30 VLOG(1) << "Tearing down CLD data harness"; | 32 VLOG(1) << "Tearing down CLD data harness"; |
31 // Dynamic data mode is enabled and we are using the component updater. | 33 // Dynamic data mode is enabled and we are using the component updater. |
32 component_updater::CldComponentInstallerTraits::SetLatestCldDataFile( | 34 component_updater::CldComponentInstallerTraits::SetLatestCldDataFile( |
33 base::FilePath()); | 35 base::FilePath()); |
34 ClearComponentDataFileState(); | 36 ClearComponentDataFileState(); |
35 DeleteComponentTree(); | 37 DeleteComponentTree(); |
36 } | 38 } |
37 | 39 |
38 void ComponentCldDataHarness::Init() { | 40 void ComponentCldDataHarness::Init() { |
39 VLOG(1) << "Initializing CLD data harness"; | 41 VLOG(1) << "Initializing CLD data harness"; |
40 // Dynamic data mode is enabled and we are using the component updater. | 42 // Dynamic data mode is enabled and we are using the component updater. |
| 43 translate::CldDataSource::Set(translate::CldDataSource::COMPONENT(), true); |
41 ASSERT_NO_FATAL_FAILURE(CopyComponentTree()); | 44 ASSERT_NO_FATAL_FAILURE(CopyComponentTree()); |
42 base::FilePath data_file; | 45 base::FilePath data_file; |
43 GetComponentDataFileDestination(&data_file); | 46 GetComponentDataFileDestination(&data_file); |
44 component_updater::CldComponentInstallerTraits::SetLatestCldDataFile( | 47 component_updater::CldComponentInstallerTraits::SetLatestCldDataFile( |
45 data_file); | 48 data_file); |
46 } | 49 } |
47 | 50 |
48 void ComponentCldDataHarness::ClearComponentDataFileState() { | 51 void ComponentCldDataHarness::ClearComponentDataFileState() { |
49 VLOG(1) << "Clearing component CLD data file state"; | 52 VLOG(1) << "Clearing component CLD data file state"; |
50 base::FilePath nothing; | 53 base::FilePath nothing; |
51 component_updater::CldComponentInstallerTraits::SetLatestCldDataFile(nothing); | 54 component_updater::CldComponentInstallerTraits::SetLatestCldDataFile(nothing); |
52 } | 55 } |
53 | 56 |
54 // DIR_COMPONENT_CLD2 is also defined as being relative to USER_DATA_DIR, so | 57 // DIR_COMPONENT_CLD2 is also defined as being relative to USER_DATA_DIR, so |
55 // like GetStandaloneDataFileDestination, this is safe to run in multiple | 58 // like GetStandaloneDataFileDestination, this is safe to run in multiple |
56 // parallel test processes. | 59 // parallel test processes. |
57 void ComponentCldDataHarness::GetExtractedComponentDestination( | 60 void ComponentCldDataHarness::GetExtractedComponentDestination( |
58 base::FilePath* out_path) { | 61 base::FilePath* out_path) { |
59 ASSERT_TRUE(PathService::Get(chrome::DIR_COMPONENT_CLD2, out_path)); | 62 ASSERT_TRUE(PathService::Get(component_updater::DIR_COMPONENT_CLD2, |
| 63 out_path)); |
60 } | 64 } |
61 | 65 |
62 void ComponentCldDataHarness::GetComponentDataFileDestination( | 66 void ComponentCldDataHarness::GetComponentDataFileDestination( |
63 base::FilePath* out_path) { | 67 base::FilePath* out_path) { |
64 GetExtractedComponentDestination(out_path); | 68 GetExtractedComponentDestination(out_path); |
65 *out_path = out_path->Append(CldDataHarness::GetTestDataSourceCrxVersion()) | 69 *out_path = out_path->Append(CldDataHarness::GetTestDataSourceCrxVersion()) |
66 .Append(FILE_PATH_LITERAL("_platform_specific")) | 70 .Append(FILE_PATH_LITERAL("_platform_specific")) |
67 .Append(FILE_PATH_LITERAL("all")) | 71 .Append(FILE_PATH_LITERAL("all")) |
68 .Append(kComponentDataFileName); | 72 .Append(kComponentDataFileName); |
69 } | 73 } |
(...skipping 14 matching lines...) Expand all Loading... |
84 VLOG(1) << "Copying CLD component test files from " << source_dir.value() | 88 VLOG(1) << "Copying CLD component test files from " << source_dir.value() |
85 << " to " << target_dir.value(); | 89 << " to " << target_dir.value(); |
86 ASSERT_TRUE(base::CreateDirectoryAndGetError(target_dir, NULL)); | 90 ASSERT_TRUE(base::CreateDirectoryAndGetError(target_dir, NULL)); |
87 ASSERT_TRUE(base::CopyDirectory(source_dir, target_dir, true)); | 91 ASSERT_TRUE(base::CopyDirectory(source_dir, target_dir, true)); |
88 ASSERT_TRUE(base::PathExists(target_dir)); | 92 ASSERT_TRUE(base::PathExists(target_dir)); |
89 base::FilePath check_path; | 93 base::FilePath check_path; |
90 GetComponentDataFileDestination(&check_path); | 94 GetComponentDataFileDestination(&check_path); |
91 ASSERT_TRUE(base::PathExists(check_path)); | 95 ASSERT_TRUE(base::PathExists(check_path)); |
92 } | 96 } |
93 | 97 |
94 scoped_ptr<CldDataHarness> CreateCldDataHarness() { | |
95 scoped_ptr<CldDataHarness> result(new ComponentCldDataHarness()); | |
96 return result.Pass(); | |
97 } | |
98 | |
99 } // namespace test | 98 } // namespace test |
OLD | NEW |