Index: chrome/browser/autofill/form_structure_browsertest.cc |
=================================================================== |
--- chrome/browser/autofill/form_structure_browsertest.cc (revision 67097) |
+++ chrome/browser/autofill/form_structure_browsertest.cc (working copy) |
@@ -4,20 +4,27 @@ |
#include <vector> |
+#include "base/file_path.h" |
+#include "base/path_service.h" |
+#include "base/utf_string_conversions.h" |
#include "chrome/browser/autofill/autofill_manager.h" |
#include "chrome/browser/autofill/form_structure.h" |
#include "chrome/browser/tab_contents/tab_contents.h" |
#include "chrome/browser/ui/browser.h" |
+#include "chrome/common/chrome_paths.h" |
#include "chrome/test/in_process_browser_test.h" |
#include "chrome/test/ui_test_utils.h" |
#include "googleurl/src/gurl.h" |
-// Test class for verifying proper form structure as determined by AutoFill |
-// heuristics. After a test loads HTML content with a call to |NavigateToURL| |
-// the |AutoFillManager| associated with the tab contents is queried for the |
-// form structures that were loaded and parsed. |
-// These form structures are serialized to string form and compared with |
-// expected results. |
+// Test class for verifying proper international form structure as determined |
+// by AutoFill heuristics. A test inputs each i18n form file |
+// (form_[language_code].html) from input directory, then loads its HTML |
+// content with a call to |NavigateToURL|, the |AutoFillManager| associated |
+// with the tab contents is queried for the form structures that were loaded |
+// and parsed. These form structures are serialized to string form. If this is |
+// the first time test is run, a gold test result file is generated in output |
+// directory, else the form structures are compared again the existing gold |
+// result file. |
class FormStructureBrowserTest : public InProcessBrowserTest { |
public: |
FormStructureBrowserTest() {} |
@@ -162,55 +169,71 @@ |
default: |
NOTREACHED() << "Invalid AutoFillFieldType value."; |
} |
- |
return std::string(); |
} |
-IN_PROC_BROWSER_TEST_F(FormStructureBrowserTest, BasicFormStructure) { |
- ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
- ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
- browser(), GURL("data:text/html;charset=utf-8," |
- "<form action=\"http://www.google.com/\" method=\"POST\">" |
- "<label for=\"firstname\">First name:</label>" |
- " <input type=\"text\" id=\"firstname\"/><br />" |
- "<label for=\"lastname\">Last name:</label>" |
- " <input type=\"text\" id=\"lastname\" /><br />" |
- "<label for=\"address1\">Address line 1:</label>" |
- " <input type=\"text\" id=\"address1\" /><br />" |
- "<label for=\"address2\">Address line 2:</label>" |
- " <input type=\"text\" id=\"address2\" /><br />" |
- "<label for=\"city\">City:</label>" |
- " <input type=\"text\" id=\"city\" /><br />" |
- "</form>"))); |
+ FilePath GetInputFileDirectory() { |
dhollowa
2010/12/13 22:11:30
Please move this to top of the file and wrap it in
vivianz
2010/12/14 22:25:14
On 2010/12/13 22:11:30, dhollowa wrote:
Fixed
|
+ FilePath test_data_dir_; |
+ PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_); |
+ test_data_dir_ = test_data_dir_.AppendASCII("autofill_heuristics") |
+ .AppendASCII("input"); |
+ return test_data_dir_; |
+ } |
+ |
+ FilePath GetOutputFileDirectory() { |
+ FilePath test_data_dir_; |
+ PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_); |
+ test_data_dir_ = test_data_dir_.AppendASCII("autofill_heuristics") |
+ .AppendASCII("output"); |
+ return test_data_dir_; |
+ } |
- ASSERT_NO_FATAL_FAILURE(ui_test_utils::ClickOnView(browser(), |
- VIEW_ID_TAB_CONTAINER)); |
- ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), |
- VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
+ // Write |outputcontent| to |outputfile|. Returns true on success. |
+ bool WriteFile(const FilePath& outputfile, |
+ const std::string& outputcontent) { |
+ int write_size = file_util::WriteFile(outputfile, outputcontent.c_str(), |
+ outputcontent.length()); |
+ return write_size == static_cast<int>(outputcontent.length()); |
+ } |
- AutoFillManager* autofill_manager = |
- browser()->GetSelectedTabContents()->GetAutoFillManager(); |
- ASSERT_NE(static_cast<AutoFillManager*>(NULL), autofill_manager); |
- std::vector<FormStructure*> forms = GetFormStructures(*autofill_manager); |
- std::string expected("data:text/html;charset=utf-8," |
- "<form action=\"http://www.google.com/\"" |
- " method=\"POST\">" |
- "<label for=\"firstname\">First name:</label>" |
- " <input type=\"text\" id=\"firstname\"/><br />" |
- "<label for=\"lastname\">Last name:</label>" |
- " <input type=\"text\" id=\"lastname\" /><br />" |
- "<label for=\"address1\">Address line 1:</label>" |
- " <input type=\"text\" id=\"address1\" /><br />" |
- "<label for=\"address2\">Address line 2:</label>" |
- " <input type=\"text\" id=\"address2\" /><br />" |
- "<label for=\"city\">City:</label>" |
- " <input type=\"text\" id=\"city\" /><br />" |
- "</form>\n" |
- "NAME_FIRST\n" |
- "NAME_LAST\n" |
- "ADDRESS_HOME_LINE1\n" |
- "ADDRESS_HOME_LINE2\n" |
- "ADDRESS_HOME_CITY\n"); |
+IN_PROC_BROWSER_TEST_F(FormStructureBrowserTest, I18NFormStructure) { |
dhollowa
2010/12/13 22:11:30
Let's rename from I18NFormStructure to HTMLFiles.
vivianz
2010/12/14 22:25:14
On 2010/12/13 22:11:30, dhollowa wrote:
Done.
|
+ FilePath input_file_path = GetInputFileDirectory(); |
+ file_util::FileEnumerator input_file_enumerator(input_file_path, |
+ false, file_util::FileEnumerator::FILES); |
+ |
+ for (input_file_path = input_file_enumerator.Next(); |
+ !input_file_path.empty(); |
+ input_file_path = input_file_enumerator.Next()) { |
+ std::string input_file_source; |
+ ASSERT_TRUE(file_util::ReadFileToString(input_file_path, |
+ &input_file_source)); |
- EXPECT_EQ(expected, FormStructureBrowserTest::FormStructuresToString(forms)); |
+ ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
+ ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( |
+ browser(), GURL(UTF8ToUTF16(input_file_source)))); |
+ |
+ ASSERT_NO_FATAL_FAILURE(ui_test_utils::ClickOnView(browser(), |
+ VIEW_ID_TAB_CONTAINER)); |
+ ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), |
+ VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
+ |
+ AutoFillManager* autofill_manager = |
+ browser()->GetSelectedTabContents()->GetAutoFillManager(); |
+ ASSERT_NE(static_cast<AutoFillManager*>(NULL), autofill_manager); |
+ std::vector<FormStructure*> forms = GetFormStructures(*autofill_manager); |
+ |
+ FilePath output_file_directory = GetOutputFileDirectory(); |
+ FilePath output_file_path = output_file_directory.Append(input_file_path |
+ .BaseName().StripTrailingSeparators().ReplaceExtension(L".out")); |
dhollowa
2010/12/13 22:11:30
The "L" prefix is not cross-platform. You can use
vivianz
2010/12/14 22:25:14
On 2010/12/13 22:11:30, dhollowa wrote:
Done.
|
+ |
+ std::string output_file_source; |
+ if (file_util::ReadFileToString(output_file_path, &output_file_source)) { |
+ EXPECT_EQ(output_file_source, |
+ FormStructureBrowserTest::FormStructuresToString(forms)); |
+ |
+ } else { |
+ ASSERT_TRUE(WriteFile(output_file_path, |
+ FormStructureBrowserTest::FormStructuresToString(forms))); |
+ } |
+ } |
} |