Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(499)

Side by Side Diff: components/autofill/core/browser/data_driven_test.cc

Issue 2835233002: Fix integration tests in src/chrome and src/extensions so that we can turn on IO thread checks wi... (Closed)
Patch Set: ready for review Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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 "components/autofill/core/browser/data_driven_test.h" 5 #include "components/autofill/core/browser/data_driven_test.h"
6 6
7 #include "base/files/file_enumerator.h" 7 #include "base/files/file_enumerator.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/threading/thread_restrictions.h"
10 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
11 12
12 namespace autofill { 13 namespace autofill {
13 namespace { 14 namespace {
14 15
15 // Reads |file| into |content|, and converts Windows line-endings to Unix ones. 16 // Reads |file| into |content|, and converts Windows line-endings to Unix ones.
16 // Returns true on success. 17 // Returns true on success.
17 bool ReadFile(const base::FilePath& file, std::string* content) { 18 bool ReadFile(const base::FilePath& file, std::string* content) {
18 if (!base::ReadFileToString(file, content)) 19 if (!base::ReadFileToString(file, content))
19 return false; 20 return false;
20 21
21 base::ReplaceSubstringsAfterOffset(content, 0, "\r\n", "\n"); 22 base::ReplaceSubstringsAfterOffset(content, 0, "\r\n", "\n");
22 return true; 23 return true;
23 } 24 }
24 25
25 // Write |content| to |file|. Returns true on success. 26 // Write |content| to |file|. Returns true on success.
26 bool WriteFile(const base::FilePath& file, const std::string& content) { 27 bool WriteFile(const base::FilePath& file, const std::string& content) {
27 int write_size = base::WriteFile(file, content.c_str(), 28 int write_size = base::WriteFile(file, content.c_str(),
28 static_cast<int>(content.length())); 29 static_cast<int>(content.length()));
29 return write_size == static_cast<int>(content.length()); 30 return write_size == static_cast<int>(content.length());
30 } 31 }
31 32
32 } // namespace 33 } // namespace
33 34
34 void DataDrivenTest::RunDataDrivenTest( 35 void DataDrivenTest::RunDataDrivenTest(
35 const base::FilePath& input_directory, 36 const base::FilePath& input_directory,
36 const base::FilePath& output_directory, 37 const base::FilePath& output_directory,
37 const base::FilePath::StringType& file_name_pattern) { 38 const base::FilePath::StringType& file_name_pattern) {
39 base::ThreadRestrictions::ScopedAllowIO allow_io;
38 ASSERT_TRUE(base::DirectoryExists(input_directory)); 40 ASSERT_TRUE(base::DirectoryExists(input_directory));
39 ASSERT_TRUE(base::DirectoryExists(output_directory)); 41 ASSERT_TRUE(base::DirectoryExists(output_directory));
40 base::FileEnumerator input_files(input_directory, 42 base::FileEnumerator input_files(input_directory,
41 false, 43 false,
42 base::FileEnumerator::FILES, 44 base::FileEnumerator::FILES,
43 file_name_pattern); 45 file_name_pattern);
44 46
45 for (base::FilePath input_file = input_files.Next(); 47 for (base::FilePath input_file = input_files.Next();
46 !input_file.empty(); 48 !input_file.empty();
47 input_file = input_files.Next()) { 49 input_file = input_files.Next()) {
48 RunOneDataDrivenTest(input_file, output_directory); 50 RunOneDataDrivenTest(input_file, output_directory);
49 } 51 }
50 } 52 }
51 53
52 void DataDrivenTest::RunOneDataDrivenTest( 54 void DataDrivenTest::RunOneDataDrivenTest(
53 const base::FilePath& test_file_name, 55 const base::FilePath& test_file_name,
54 const base::FilePath& output_directory) { 56 const base::FilePath& output_directory) {
57 base::ThreadRestrictions::ScopedAllowIO allow_io;
55 // iOS doesn't get rid of removed test files. TODO(estade): remove this after 58 // iOS doesn't get rid of removed test files. TODO(estade): remove this after
56 // all iOS bots are clobbered. 59 // all iOS bots are clobbered.
57 if (test_file_name.BaseName().value() == FILE_PATH_LITERAL("multimerge.in")) 60 if (test_file_name.BaseName().value() == FILE_PATH_LITERAL("multimerge.in"))
58 return; 61 return;
59 62
60 ASSERT_TRUE(base::DirectoryExists(output_directory)); 63 ASSERT_TRUE(base::DirectoryExists(output_directory));
61 SCOPED_TRACE(test_file_name.BaseName().value()); 64 SCOPED_TRACE(test_file_name.BaseName().value());
62 65
63 std::string input; 66 std::string input;
64 ReadFile(test_file_name, &input); 67 ReadFile(test_file_name, &input);
65 68
66 std::string output; 69 std::string output;
70 base::ThreadRestrictions::SetIOAllowed(false);
67 GenerateResults(input, &output); 71 GenerateResults(input, &output);
72 base::ThreadRestrictions::SetIOAllowed(true);
68 73
69 base::FilePath output_file = output_directory.Append( 74 base::FilePath output_file = output_directory.Append(
70 test_file_name.BaseName().StripTrailingSeparators().ReplaceExtension( 75 test_file_name.BaseName().StripTrailingSeparators().ReplaceExtension(
71 FILE_PATH_LITERAL(".out"))); 76 FILE_PATH_LITERAL(".out")));
72 77
73 std::string output_file_contents; 78 std::string output_file_contents;
74 if (ReadFile(output_file, &output_file_contents)) 79 if (ReadFile(output_file, &output_file_contents))
75 EXPECT_EQ(output_file_contents, output); 80 EXPECT_EQ(output_file_contents, output);
76 else 81 else
77 ASSERT_TRUE(WriteFile(output_file, output)); 82 ASSERT_TRUE(WriteFile(output_file, output));
(...skipping 18 matching lines...) Expand all
96 } 101 }
97 102
98 DataDrivenTest::DataDrivenTest(const base::FilePath& test_data_directory) 103 DataDrivenTest::DataDrivenTest(const base::FilePath& test_data_directory)
99 : test_data_directory_(test_data_directory) { 104 : test_data_directory_(test_data_directory) {
100 } 105 }
101 106
102 DataDrivenTest::~DataDrivenTest() { 107 DataDrivenTest::~DataDrivenTest() {
103 } 108 }
104 109
105 } // namespace autofill 110 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/test/remoting/qunit_browser_test_runner.cc ('k') | components/drive/service/fake_drive_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698