Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / components / autofill / core / browser / data_driven_test.h
blobde44554847e10c0cc440642dbb3a6f5b4925de9d
1 // Copyright 2013 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.
5 #ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_DATA_DRIVEN_TEST_H_
6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_DATA_DRIVEN_TEST_H_
8 #include <string>
10 #include "base/files/file_path.h"
11 #include "base/strings/string16.h"
13 namespace autofill {
15 // A convenience class for implementing data-driven tests. Subclassers need only
16 // implement the conversion of serialized input data to serialized output data
17 // and provide a set of input files. For each input file, on the first run, a
18 // gold output file is generated; for subsequent runs, the test ouptut is
19 // compared to this gold output.
20 class DataDrivenTest {
21 public:
22 // For each file in |input_directory| whose filename matches
23 // |file_name_pattern|, slurps in the file contents and calls into
24 // |GenerateResults()|. If the corresponding output file already exists in
25 // the |output_directory|, verifies that the results match the file contents;
26 // otherwise, writes a gold result file to the |output_directory|.
27 void RunDataDrivenTest(const base::FilePath& input_directory,
28 const base::FilePath& output_directory,
29 const base::FilePath::StringType& file_name_pattern);
31 // As above, but runs a test for a single file, the full path of which is
32 // given by |test_file_name|.
33 void RunOneDataDrivenTest(const base::FilePath& test_file_name,
34 const base::FilePath& output_directory);
36 // Given the |input| data, generates the |output| results. The output results
37 // must be stable across runs.
38 // Note: The return type is |void| so that googletest |ASSERT_*| macros will
39 // compile.
40 virtual void GenerateResults(const std::string& input,
41 std::string* output) = 0;
43 // Return |base::FilePath|s to the test input and output subdirectories
44 // ../autofill/|test_name|/input and ../autofill/|test_name|/output.
45 base::FilePath GetInputDirectory(const base::FilePath::StringType& test_name);
46 base::FilePath GetOutputDirectory(
47 const base::FilePath::StringType& test_name);
49 protected:
50 DataDrivenTest(const base::FilePath& test_data_directory);
51 virtual ~DataDrivenTest();
53 private:
54 base::FilePath test_data_directory_;
56 DISALLOW_COPY_AND_ASSIGN(DataDrivenTest);
59 } // namespace autofill
61 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_DATA_DRIVEN_TEST_H_