| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 int write_size = file_util::WriteFile(file, content.c_str(), | 40 int write_size = file_util::WriteFile(file, content.c_str(), |
| 41 content.length()); | 41 content.length()); |
| 42 return write_size == static_cast<int>(content.length()); | 42 return write_size == static_cast<int>(content.length()); |
| 43 } | 43 } |
| 44 | 44 |
| 45 // Convert |html| to URL format, and return the converted string. | 45 // Convert |html| to URL format, and return the converted string. |
| 46 const std::string ConvertToURLFormat(const std::string& html) { | 46 const std::string ConvertToURLFormat(const std::string& html) { |
| 47 return std::string("data:text/html;charset=utf-8,") + html; | 47 return std::string("data:text/html;charset=utf-8,") + html; |
| 48 } | 48 } |
| 49 | 49 |
| 50 // Compare |output_file_source| with |form_string|. Returns true when they are | 50 // Convert strings with platform end-of-line characters with spaces. |
| 51 // identical. | 51 const std::string NormalizeText(const std::string& text) { |
| 52 bool CompareText(const std::string& output_file_source, | 52 std::string normalized = text; |
| 53 const std::string& form_string) { | 53 ReplaceSubstringsAfterOffset(&normalized, 0, "\r\n", " "); |
| 54 std::string output_file = output_file_source; | 54 ReplaceSubstringsAfterOffset(&normalized, 0, "\r", " "); |
| 55 std::string form = form_string; | 55 ReplaceSubstringsAfterOffset(&normalized, 0, "\n", " "); |
| 56 | 56 return normalized; |
| 57 ReplaceSubstringsAfterOffset(&output_file, 0, "\r\n", " "); | |
| 58 ReplaceSubstringsAfterOffset(&output_file, 0, "\r", " "); | |
| 59 ReplaceSubstringsAfterOffset(&output_file, 0, "\n", " "); | |
| 60 ReplaceSubstringsAfterOffset(&form, 0, "\n", " "); | |
| 61 | |
| 62 return (output_file == form); | |
| 63 } | 57 } |
| 64 | 58 |
| 65 } // namespace | 59 } // namespace |
| 66 | 60 |
| 67 // Test class for verifying proper form structure as determined by AutoFill | 61 // Test class for verifying proper form structure as determined by AutoFill |
| 68 // heuristics. A test inputs each form file(e.g. form_[language_code].html), | 62 // heuristics. A test inputs each form file(e.g. form_[language_code].html), |
| 69 // loads its HTML content with a call to |NavigateToURL|, the |AutoFillManager| | 63 // loads its HTML content with a call to |NavigateToURL|, the |AutoFillManager| |
| 70 // associated with the tab contents is queried for the form structures that | 64 // associated with the tab contents is queried for the form structures that |
| 71 // were loaded and parsed. These form structures are serialized to string form. | 65 // were loaded and parsed. These form structures are serialized to string form. |
| 72 // If this is the first time test is run, a gold test result file is generated | 66 // If this is the first time test is run, a gold test result file is generated |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 ASSERT_NE(static_cast<AutoFillManager*>(NULL), autofill_manager); | 240 ASSERT_NE(static_cast<AutoFillManager*>(NULL), autofill_manager); |
| 247 std::vector<FormStructure*> forms = GetFormStructures(*autofill_manager); | 241 std::vector<FormStructure*> forms = GetFormStructures(*autofill_manager); |
| 248 | 242 |
| 249 FilePath output_file_directory = GetOutputFileDirectory(); | 243 FilePath output_file_directory = GetOutputFileDirectory(); |
| 250 FilePath output_file_path = output_file_directory.Append( | 244 FilePath output_file_path = output_file_directory.Append( |
| 251 input_file_path.BaseName().StripTrailingSeparators().ReplaceExtension( | 245 input_file_path.BaseName().StripTrailingSeparators().ReplaceExtension( |
| 252 FILE_PATH_LITERAL(".out"))); | 246 FILE_PATH_LITERAL(".out"))); |
| 253 | 247 |
| 254 std::string output_file_source; | 248 std::string output_file_source; |
| 255 if (file_util::ReadFileToString(output_file_path, &output_file_source)) { | 249 if (file_util::ReadFileToString(output_file_path, &output_file_source)) { |
| 256 ASSERT_TRUE(CompareText( | 250 ASSERT_EQ(NormalizeText(output_file_source), |
| 257 output_file_source, | 251 NormalizeText( |
| 258 FormStructureBrowserTest::FormStructuresToString(forms))); | 252 FormStructureBrowserTest::FormStructuresToString(forms))); |
| 259 | 253 |
| 260 } else { | 254 } else { |
| 261 ASSERT_TRUE(WriteFile( | 255 ASSERT_TRUE(WriteFile( |
| 262 output_file_path, | 256 output_file_path, |
| 263 FormStructureBrowserTest::FormStructuresToString(forms))); | 257 FormStructureBrowserTest::FormStructuresToString(forms))); |
| 264 } | 258 } |
| 265 } | 259 } |
| 266 } | 260 } |
| OLD | NEW |