Simplify and extend commenting in test::ScopedCLDDynamicDataHarness

BUG=367239

Review URL: https://codereview.chromium.org/296943002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@272516 0039d316-1c4b-4281-b951-d872f2087c98
parent f2cef303
...@@ -35,7 +35,7 @@ void GetTestDataSourceDirectory(base::FilePath* out_path) { ...@@ -35,7 +35,7 @@ void GetTestDataSourceDirectory(base::FilePath* out_path) {
#if defined(CLD2_DYNAMIC_MODE) && !defined(CLD2_IS_COMPONENT) #if defined(CLD2_DYNAMIC_MODE) && !defined(CLD2_IS_COMPONENT)
void GetStandaloneDataFileSource(base::FilePath* out_path) { void GetStandaloneDataFileSource(base::FilePath* out_path) {
ASSERT_NO_FATAL_FAILURE(GetTestDataSourceDirectory(out_path)); GetTestDataSourceDirectory(out_path);
*out_path = out_path->Append(FILE_PATH_LITERAL("_platform_specific")) *out_path = out_path->Append(FILE_PATH_LITERAL("_platform_specific"))
.Append(FILE_PATH_LITERAL("all")) .Append(FILE_PATH_LITERAL("all"))
.Append(chrome::kCLDDataFilename); .Append(chrome::kCLDDataFilename);
...@@ -59,11 +59,11 @@ void DeleteStandaloneDataFile() { ...@@ -59,11 +59,11 @@ void DeleteStandaloneDataFile() {
void CopyStandaloneDataFile() { void CopyStandaloneDataFile() {
DeleteStandaloneDataFile(); // sanity: blow away any old copies. DeleteStandaloneDataFile(); // sanity: blow away any old copies.
base::FilePath target_file; base::FilePath target_file;
ASSERT_NO_FATAL_FAILURE(GetStandaloneDataFileDestination(&target_file)); GetStandaloneDataFileDestination(&target_file);
base::FilePath target_dir = target_file.DirName(); base::FilePath target_dir = target_file.DirName();
ASSERT_TRUE(base::CreateDirectoryAndGetError(target_dir, NULL)); ASSERT_TRUE(base::CreateDirectoryAndGetError(target_dir, NULL));
base::FilePath source_file; base::FilePath source_file;
ASSERT_NO_FATAL_FAILURE(GetStandaloneDataFileSource(&source_file)); GetStandaloneDataFileSource(&source_file);
DLOG(INFO) << "Copying CLD test data file from " << source_file.value() DLOG(INFO) << "Copying CLD test data file from " << source_file.value()
<< " to " << target_file.value(); << " to " << target_file.value();
ASSERT_TRUE(base::CopyFile(source_file, target_file)); ASSERT_TRUE(base::CopyFile(source_file, target_file));
...@@ -80,7 +80,7 @@ void GetExtractedComponentDestination(base::FilePath* out_path) { ...@@ -80,7 +80,7 @@ void GetExtractedComponentDestination(base::FilePath* out_path) {
} }
void GetComponentDataFileDestination(base::FilePath* out_path) { void GetComponentDataFileDestination(base::FilePath* out_path) {
ASSERT_NO_FATAL_FAILURE(GetExtractedComponentDestination(out_path)); GetExtractedComponentDestination(out_path);
*out_path = out_path->Append(kCrxVersion) *out_path = out_path->Append(kCrxVersion)
.Append(FILE_PATH_LITERAL("_platform_specific")) .Append(FILE_PATH_LITERAL("_platform_specific"))
.Append(FILE_PATH_LITERAL("all")) .Append(FILE_PATH_LITERAL("all"))
...@@ -97,16 +97,16 @@ void DeleteComponentTree() { ...@@ -97,16 +97,16 @@ void DeleteComponentTree() {
void CopyComponentTree() { void CopyComponentTree() {
DeleteComponentTree(); // sanity: blow away any old copies. DeleteComponentTree(); // sanity: blow away any old copies.
base::FilePath target_dir; base::FilePath target_dir;
ASSERT_NO_FATAL_FAILURE(GetExtractedComponentDestination(&target_dir)); GetExtractedComponentDestination(&target_dir);
base::FilePath source_dir; base::FilePath source_dir;
GetTestDataSourceDirectory(&source_dir);
DLOG(INFO) << "Copying CLD component test files from " << source_dir.value() DLOG(INFO) << "Copying CLD component test files from " << source_dir.value()
<< " to " << target_dir.value(); << " to " << target_dir.value();
ASSERT_NO_FATAL_FAILURE(GetTestDataSourceDirectory(&source_dir));
ASSERT_TRUE(base::CreateDirectoryAndGetError(target_dir, NULL)); ASSERT_TRUE(base::CreateDirectoryAndGetError(target_dir, NULL));
ASSERT_TRUE(base::CopyDirectory(source_dir, target_dir, true)); ASSERT_TRUE(base::CopyDirectory(source_dir, target_dir, true));
ASSERT_TRUE(base::PathExists(target_dir)); ASSERT_TRUE(base::PathExists(target_dir));
base::FilePath check_path; base::FilePath check_path;
ASSERT_NO_FATAL_FAILURE(GetComponentDataFileDestination(&check_path)); GetComponentDataFileDestination(&check_path);
ASSERT_TRUE(base::PathExists(check_path)); ASSERT_TRUE(base::PathExists(check_path));
} }
#endif // defined(CLD2_DYNAMIC_MODE) && defined(CLD2_IS_COMPONENT) #endif // defined(CLD2_DYNAMIC_MODE) && defined(CLD2_IS_COMPONENT)
...@@ -139,7 +139,7 @@ void ScopedCLDDynamicDataHarness::Init() { ...@@ -139,7 +139,7 @@ void ScopedCLDDynamicDataHarness::Init() {
// Dynamic data mode is enabled and we are using the component updater. // Dynamic data mode is enabled and we are using the component updater.
ASSERT_NO_FATAL_FAILURE(CopyComponentTree()); ASSERT_NO_FATAL_FAILURE(CopyComponentTree());
base::FilePath data_file; base::FilePath data_file;
ASSERT_NO_FATAL_FAILURE(GetComponentDataFileDestination(&data_file)); GetComponentDataFileDestination(&data_file);
component_updater::CldComponentInstallerTraits::SetLatestCldDataFile( component_updater::CldComponentInstallerTraits::SetLatestCldDataFile(
data_file); data_file);
base::FilePath result = component_updater::GetLatestCldDataFile(); base::FilePath result = component_updater::GetLatestCldDataFile();
......
...@@ -11,13 +11,12 @@ namespace test { ...@@ -11,13 +11,12 @@ namespace test {
// A utility class that sets up CLD dynamic data upon calling Init() and cleans // A utility class that sets up CLD dynamic data upon calling Init() and cleans
// it up when destroyed. // it up when destroyed.
// Test data lives under: src/chrome/test/data/cld2_component
// //
// This class is intended to be instantiated within IN_PROC_BROWSER_TEST_F // This class is intended to be instantiated within IN_PROC_BROWSER_TEST_F
// test fixtures; it uses ASSERT macros for correctness, so that tests will // test fixtures; it uses ASSERT macros for correctness, so that tests will
// fail gracefully in error conditions. Sample use: // fail gracefully in error conditions. Sample use:
// //
// #include "chrome/browser/translate/translate_browser_test_utils.h"
//
// IN_PROC_BROWSER_TEST_F(BrowserTest, PageLanguageDetection) { // IN_PROC_BROWSER_TEST_F(BrowserTest, PageLanguageDetection) {
// test::ScopedCLDDynamicDataHarness dynamic_data_scope; // test::ScopedCLDDynamicDataHarness dynamic_data_scope;
// ASSERT_NO_FATAL_FAILURE(dynamic_data_scope.Init()); // ASSERT_NO_FATAL_FAILURE(dynamic_data_scope.Init());
...@@ -26,9 +25,19 @@ namespace test { ...@@ -26,9 +25,19 @@ namespace test {
// //
// If you have a lot of tests that need language translation features, you can // If you have a lot of tests that need language translation features, you can
// add an instance of the ScopedCLDDynamicDataHarness to your test class' // add an instance of the ScopedCLDDynamicDataHarness to your test class'
// private member variables and add the call to Init() into your Setup method. // private member variables and add the call to Init() into SetUpOnMainThread.
// Sample use:
//
// class MyTestClass : public InProcessBrowserTest {
// public:
// virtual void SetUpOnMainThread() OVERRIDE {
// dynamic_data_scope.Init();
// InProcessBrowserTest::SetUpOnMainThread();
// }
// private:
// test::ScopedCLDDynamicDataHarness dynamic_data_scope;
// };
// //
// NB: Test data lives under src/chrome/test/data/cld2_component
class ScopedCLDDynamicDataHarness { class ScopedCLDDynamicDataHarness {
public: public:
// Constructs the object, but does nothing. Call Init() to prepare the // Constructs the object, but does nothing. Call Init() to prepare the
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment