Chromium Code Reviews| 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_component_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/browser/component_updater/cld_component_installer.h" | |
| 12 #include "chrome/common/chrome_paths.h" | |
| 13 #include "testing/gtest/include/gtest/gtest.h" | |
| 14 | |
| 15 | |
| 16 namespace { | |
| 17 | |
| 18 // This comes from cld_component_installer.cc | |
|
Takashi Toyoshima
2014/06/23 08:50:00
You can remove a following duplicated constant str
Andrew Hayden (chromium.org)
2014/06/23 13:20:35
I've removed that method completely, as it was lef
| |
| 19 const base::FilePath::CharType kComponentDataFileName[] = | |
| 20 FILE_PATH_LITERAL("cld2_data.bin"); | |
| 21 | |
| 22 } // namespace | |
| 23 | |
| 24 namespace test { | |
| 25 | |
| 26 ScopedCldComponentDataHarness::ScopedCldComponentDataHarness() { | |
| 27 // Constructor does nothing in all cases. See Init() for initialization. | |
| 28 } | |
| 29 | |
| 30 ScopedCldComponentDataHarness::~ScopedCldComponentDataHarness() { | |
| 31 VLOG(1) << "Tearing down CLD data harness"; | |
| 32 // Dynamic data mode is enabled and we are using the component updater. | |
| 33 component_updater::CldComponentInstallerTraits::SetLatestCldDataFile( | |
| 34 base::FilePath()); | |
| 35 ClearComponentDataFileState(); | |
| 36 DeleteComponentTree(); | |
| 37 } | |
| 38 | |
| 39 void ScopedCldComponentDataHarness::Init() { | |
| 40 VLOG(1) << "Initializing CLD data harness"; | |
| 41 // Dynamic data mode is enabled and we are using the component updater. | |
| 42 ASSERT_NO_FATAL_FAILURE(CopyComponentTree()); | |
| 43 base::FilePath data_file; | |
| 44 GetComponentDataFileDestination(&data_file); | |
| 45 component_updater::CldComponentInstallerTraits::SetLatestCldDataFile( | |
| 46 data_file); | |
| 47 } | |
| 48 | |
| 49 void ScopedCldComponentDataHarness::ClearComponentDataFileState() { | |
| 50 VLOG(1) << "Clearing component CLD data file state"; | |
| 51 base::FilePath nothing; | |
| 52 component_updater::CldComponentInstallerTraits::SetLatestCldDataFile(nothing); | |
| 53 } | |
| 54 | |
| 55 // DIR_COMPONENT_CLD2 is also defined as being relative to USER_DATA_DIR, so | |
| 56 // like GetStandaloneDataFileDestination, this is safe to run in multiple | |
| 57 // parallel test processes. | |
| 58 void ScopedCldComponentDataHarness::GetExtractedComponentDestination( | |
| 59 base::FilePath* out_path) { | |
| 60 ASSERT_TRUE(PathService::Get(chrome::DIR_COMPONENT_CLD2, out_path)); | |
| 61 } | |
| 62 | |
| 63 void ScopedCldComponentDataHarness::GetComponentDataFileDestination( | |
| 64 base::FilePath* out_path) { | |
| 65 GetExtractedComponentDestination(out_path); | |
| 66 *out_path = out_path->Append( | |
| 67 ScopedCldDataHarness::GetTestDataSourceCrxVersion()) | |
| 68 .Append(FILE_PATH_LITERAL("_platform_specific")) | |
| 69 .Append(FILE_PATH_LITERAL("all")) | |
| 70 .Append(kComponentDataFileName); | |
| 71 } | |
| 72 | |
| 73 void ScopedCldComponentDataHarness::DeleteComponentTree() { | |
| 74 base::FilePath tree_path; | |
| 75 ASSERT_NO_FATAL_FAILURE(GetExtractedComponentDestination(&tree_path)); | |
| 76 VLOG(1) << "Deleting CLD component test files from " << tree_path.value(); | |
| 77 base::DeleteFile(tree_path, true); | |
| 78 } | |
| 79 | |
| 80 void ScopedCldComponentDataHarness::CopyComponentTree() { | |
| 81 DeleteComponentTree(); // sanity: blow away any old copies. | |
| 82 base::FilePath target_dir; | |
| 83 GetExtractedComponentDestination(&target_dir); | |
| 84 base::FilePath source_dir; | |
| 85 ScopedCldDataHarness::GetTestDataSourceDirectory(&source_dir); | |
| 86 VLOG(1) << "Copying CLD component test files from " << source_dir.value() | |
| 87 << " to " << target_dir.value(); | |
| 88 ASSERT_TRUE(base::CreateDirectoryAndGetError(target_dir, NULL)); | |
| 89 ASSERT_TRUE(base::CopyDirectory(source_dir, target_dir, true)); | |
| 90 ASSERT_TRUE(base::PathExists(target_dir)); | |
| 91 base::FilePath check_path; | |
| 92 GetComponentDataFileDestination(&check_path); | |
| 93 ASSERT_TRUE(base::PathExists(check_path)); | |
| 94 } | |
| 95 | |
| 96 scoped_ptr<ScopedCldDataHarness> | |
|
Takashi Toyoshima
2014/06/23 08:50:00
no line break here
Andrew Hayden (chromium.org)
2014/06/23 13:20:35
Done.
| |
| 97 CreateScopedCldDataHarness() { | |
| 98 scoped_ptr<ScopedCldDataHarness> result(new ScopedCldComponentDataHarness()); | |
| 99 return result.Pass(); | |
| 100 } | |
| 101 | |
| 102 } // namespace test | |
| OLD | NEW |