| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
| 6 | 6 |
| 7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/string16.h" |
| 10 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 11 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 12 #include "chrome/browser/importer/firefox2_importer.h" | 13 #include "chrome/browser/importer/firefox2_importer.h" |
| 13 #include "chrome/browser/importer/firefox_importer_unittest_utils.h" | 14 #include "chrome/browser/importer/firefox_importer_unittest_utils.h" |
| 14 #include "chrome/browser/importer/firefox_importer_utils.h" | 15 #include "chrome/browser/importer/firefox_importer_utils.h" |
| 15 #include "chrome/browser/importer/nss_decryptor.h" | 16 #include "chrome/browser/importer/nss_decryptor.h" |
| 16 #include "chrome/common/chrome_paths.h" | 17 #include "chrome/common/chrome_paths.h" |
| 17 | 18 |
| 18 // The following 2 tests require the use of the NSSDecryptor, on OSX this needs | 19 // The following 2 tests require the use of the NSSDecryptor, on OSX this needs |
| 19 // to run in a separate process, so we use a proxy object so we can share the | 20 // to run in a separate process, so we use a proxy object so we can share the |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 EXPECT_TRUE(result); | 92 EXPECT_TRUE(result); |
| 92 EXPECT_EQ(ASCIIToUTF16("< > & \" ' \\ /"), folder_name); | 93 EXPECT_EQ(ASCIIToUTF16("< > & \" ' \\ /"), folder_name); |
| 93 EXPECT_FALSE(is_toolbar_folder); | 94 EXPECT_FALSE(is_toolbar_folder); |
| 94 EXPECT_TRUE(base::Time::FromTimeT(1207558707) == folder_add_date); | 95 EXPECT_TRUE(base::Time::FromTimeT(1207558707) == folder_add_date); |
| 95 | 96 |
| 96 // Empty name and toolbar folder attribute. | 97 // Empty name and toolbar folder attribute. |
| 97 result = Firefox2Importer::ParseFolderNameFromLine( | 98 result = Firefox2Importer::ParseFolderNameFromLine( |
| 98 "<DT><H3 PERSONAL_TOOLBAR_FOLDER=\"true\"></H3>", | 99 "<DT><H3 PERSONAL_TOOLBAR_FOLDER=\"true\"></H3>", |
| 99 charset, &folder_name, &is_toolbar_folder, &folder_add_date); | 100 charset, &folder_name, &is_toolbar_folder, &folder_add_date); |
| 100 EXPECT_TRUE(result); | 101 EXPECT_TRUE(result); |
| 101 EXPECT_EQ(ASCIIToUTF16(""), folder_name); | 102 EXPECT_EQ(string16(), folder_name); |
| 102 EXPECT_TRUE(is_toolbar_folder); | 103 EXPECT_TRUE(is_toolbar_folder); |
| 103 | 104 |
| 104 // Unicode characters in title and shortcut. | 105 // Unicode characters in title and shortcut. |
| 105 string16 title; | 106 string16 title; |
| 106 GURL url, favicon; | 107 GURL url, favicon; |
| 107 string16 shortcut; | 108 string16 shortcut; |
| 108 string16 post_data; | 109 string16 post_data; |
| 109 base::Time add_date; | 110 base::Time add_date; |
| 110 result = Firefox2Importer::ParseBookmarkFromLine( | 111 result = Firefox2Importer::ParseBookmarkFromLine( |
| 111 "<DT><A HREF=\"http://chinese.site.cn/path?query=1#ref\" " | 112 "<DT><A HREF=\"http://chinese.site.cn/path?query=1#ref\" " |
| 112 "SHORTCUTURL=\"\xE4\xB8\xAD\">\xE4\xB8\xAD\xE6\x96\x87</A>", | 113 "SHORTCUTURL=\"\xE4\xB8\xAD\">\xE4\xB8\xAD\xE6\x96\x87</A>", |
| 113 charset, &title, &url, &favicon, &shortcut, &add_date, &post_data); | 114 charset, &title, &url, &favicon, &shortcut, &add_date, &post_data); |
| 114 EXPECT_TRUE(result); | 115 EXPECT_TRUE(result); |
| 115 EXPECT_EQ(L"\x4E2D\x6587", UTF16ToWide(title)); | 116 EXPECT_EQ(L"\x4E2D\x6587", UTF16ToWide(title)); |
| 116 EXPECT_EQ("http://chinese.site.cn/path?query=1#ref", url.spec()); | 117 EXPECT_EQ("http://chinese.site.cn/path?query=1#ref", url.spec()); |
| 117 EXPECT_EQ(L"\x4E2D", UTF16ToWide(shortcut)); | 118 EXPECT_EQ(L"\x4E2D", UTF16ToWide(shortcut)); |
| 118 EXPECT_EQ(ASCIIToUTF16(""), post_data); | 119 EXPECT_EQ(string16(), post_data); |
| 119 EXPECT_TRUE(base::Time() == add_date); | 120 EXPECT_TRUE(base::Time() == add_date); |
| 120 | 121 |
| 121 // No shortcut, and url contains %22 ('"' character). | 122 // No shortcut, and url contains %22 ('"' character). |
| 122 result = Firefox2Importer::ParseBookmarkFromLine( | 123 result = Firefox2Importer::ParseBookmarkFromLine( |
| 123 "<DT><A HREF=\"http://domain.com/?q=%22<>%22\">name</A>", | 124 "<DT><A HREF=\"http://domain.com/?q=%22<>%22\">name</A>", |
| 124 charset, &title, &url, &favicon, &shortcut, &add_date, &post_data); | 125 charset, &title, &url, &favicon, &shortcut, &add_date, &post_data); |
| 125 EXPECT_TRUE(result); | 126 EXPECT_TRUE(result); |
| 126 EXPECT_EQ(ASCIIToUTF16("name"), title); | 127 EXPECT_EQ(ASCIIToUTF16("name"), title); |
| 127 EXPECT_EQ("http://domain.com/?q=%22%3C%3E%22", url.spec()); | 128 EXPECT_EQ("http://domain.com/?q=%22%3C%3E%22", url.spec()); |
| 128 EXPECT_EQ(ASCIIToUTF16(""), shortcut); | 129 EXPECT_EQ(string16(), shortcut); |
| 129 EXPECT_EQ(ASCIIToUTF16(""), post_data); | 130 EXPECT_EQ(string16(), post_data); |
| 130 EXPECT_TRUE(base::Time() == add_date); | 131 EXPECT_TRUE(base::Time() == add_date); |
| 131 | 132 |
| 132 result = Firefox2Importer::ParseBookmarkFromLine( | 133 result = Firefox2Importer::ParseBookmarkFromLine( |
| 133 "<DT><A HREF=\"http://domain.com/?g="\"\">name</A>", | 134 "<DT><A HREF=\"http://domain.com/?g="\"\">name</A>", |
| 134 charset, &title, &url, &favicon, &shortcut, &add_date, &post_data); | 135 charset, &title, &url, &favicon, &shortcut, &add_date, &post_data); |
| 135 EXPECT_TRUE(result); | 136 EXPECT_TRUE(result); |
| 136 EXPECT_EQ(ASCIIToUTF16("name"), title); | 137 EXPECT_EQ(ASCIIToUTF16("name"), title); |
| 137 EXPECT_EQ("http://domain.com/?g=%22", url.spec()); | 138 EXPECT_EQ("http://domain.com/?g=%22", url.spec()); |
| 138 EXPECT_EQ(ASCIIToUTF16(""), shortcut); | 139 EXPECT_EQ(string16(), shortcut); |
| 139 EXPECT_EQ(ASCIIToUTF16(""), post_data); | 140 EXPECT_EQ(string16(), post_data); |
| 140 EXPECT_TRUE(base::Time() == add_date); | 141 EXPECT_TRUE(base::Time() == add_date); |
| 141 | 142 |
| 142 // Creation date. | 143 // Creation date. |
| 143 result = Firefox2Importer::ParseBookmarkFromLine( | 144 result = Firefox2Importer::ParseBookmarkFromLine( |
| 144 "<DT><A HREF=\"http://site/\" ADD_DATE=\"1121301154\">name</A>", | 145 "<DT><A HREF=\"http://site/\" ADD_DATE=\"1121301154\">name</A>", |
| 145 charset, &title, &url, &favicon, &shortcut, &add_date, &post_data); | 146 charset, &title, &url, &favicon, &shortcut, &add_date, &post_data); |
| 146 EXPECT_TRUE(result); | 147 EXPECT_TRUE(result); |
| 147 EXPECT_EQ(ASCIIToUTF16("name"), title); | 148 EXPECT_EQ(ASCIIToUTF16("name"), title); |
| 148 EXPECT_EQ(GURL("http://site/"), url); | 149 EXPECT_EQ(GURL("http://site/"), url); |
| 149 EXPECT_EQ(ASCIIToUTF16(""), shortcut); | 150 EXPECT_EQ(string16(), shortcut); |
| 150 EXPECT_EQ(ASCIIToUTF16(""), post_data); | 151 EXPECT_EQ(string16(), post_data); |
| 151 EXPECT_TRUE(base::Time::FromTimeT(1121301154) == add_date); | 152 EXPECT_TRUE(base::Time::FromTimeT(1121301154) == add_date); |
| 152 | 153 |
| 153 // Post-data | 154 // Post-data |
| 154 result = Firefox2Importer::ParseBookmarkFromLine( | 155 result = Firefox2Importer::ParseBookmarkFromLine( |
| 155 "<DT><A HREF=\"http://localhost:8080/test/hello.html\" ADD_DATE=\"" | 156 "<DT><A HREF=\"http://localhost:8080/test/hello.html\" ADD_DATE=\"" |
| 156 "1212447159\" LAST_VISIT=\"1212447251\" LAST_MODIFIED=\"1212447248\"" | 157 "1212447159\" LAST_VISIT=\"1212447251\" LAST_MODIFIED=\"1212447248\"" |
| 157 "SHORTCUTURL=\"post\" ICON=\"data:\" POST_DATA=\"lname%3D%25s\"" | 158 "SHORTCUTURL=\"post\" ICON=\"data:\" POST_DATA=\"lname%3D%25s\"" |
| 158 "LAST_CHARSET=\"UTF-8\" ID=\"rdf:#$weKaR3\">Test Post keyword</A>", | 159 "LAST_CHARSET=\"UTF-8\" ID=\"rdf:#$weKaR3\">Test Post keyword</A>", |
| 159 charset, &title, &url, &favicon, &shortcut, &add_date, &post_data); | 160 charset, &title, &url, &favicon, &shortcut, &add_date, &post_data); |
| 160 EXPECT_TRUE(result); | 161 EXPECT_TRUE(result); |
| 161 EXPECT_EQ(ASCIIToUTF16("Test Post keyword"), title); | 162 EXPECT_EQ(ASCIIToUTF16("Test Post keyword"), title); |
| 162 EXPECT_EQ("http://localhost:8080/test/hello.html", url.spec()); | 163 EXPECT_EQ("http://localhost:8080/test/hello.html", url.spec()); |
| 163 EXPECT_EQ(ASCIIToUTF16("post"), shortcut); | 164 EXPECT_EQ(ASCIIToUTF16("post"), shortcut); |
| 164 EXPECT_EQ(ASCIIToUTF16("lname%3D%25s"), post_data); | 165 EXPECT_EQ(ASCIIToUTF16("lname%3D%25s"), post_data); |
| 165 EXPECT_TRUE(base::Time::FromTimeT(1212447159) == add_date); | 166 EXPECT_TRUE(base::Time::FromTimeT(1212447159) == add_date); |
| 166 | 167 |
| 167 // Invalid case. | 168 // Invalid case. |
| 168 result = Firefox2Importer::ParseBookmarkFromLine( | 169 result = Firefox2Importer::ParseBookmarkFromLine( |
| 169 "<DT><A HREF=\"http://domain.com/?q=%22", | 170 "<DT><A HREF=\"http://domain.com/?q=%22", |
| 170 charset, &title, &url, &favicon, &shortcut, &add_date, &post_data); | 171 charset, &title, &url, &favicon, &shortcut, &add_date, &post_data); |
| 171 EXPECT_FALSE(result); | 172 EXPECT_FALSE(result); |
| 172 EXPECT_EQ(ASCIIToUTF16(""), title); | 173 EXPECT_EQ(string16(), title); |
| 173 EXPECT_EQ("", url.spec()); | 174 EXPECT_EQ("", url.spec()); |
| 174 EXPECT_EQ(ASCIIToUTF16(""), shortcut); | 175 EXPECT_EQ(string16(), shortcut); |
| 175 EXPECT_EQ(ASCIIToUTF16(""), post_data); | 176 EXPECT_EQ(string16(), post_data); |
| 176 EXPECT_TRUE(base::Time() == add_date); | 177 EXPECT_TRUE(base::Time() == add_date); |
| 177 | 178 |
| 178 // Epiphany format. | 179 // Epiphany format. |
| 179 result = Firefox2Importer::ParseMinimumBookmarkFromLine( | 180 result = Firefox2Importer::ParseMinimumBookmarkFromLine( |
| 180 "<dt><a href=\"http://www.google.com/\">Google</a></dt>", | 181 "<dt><a href=\"http://www.google.com/\">Google</a></dt>", |
| 181 charset, &title, &url); | 182 charset, &title, &url); |
| 182 EXPECT_TRUE(result); | 183 EXPECT_TRUE(result); |
| 183 EXPECT_EQ(ASCIIToUTF16("Google"), title); | 184 EXPECT_EQ(ASCIIToUTF16("Google"), title); |
| 184 EXPECT_EQ("http://www.google.com/", url.spec()); | 185 EXPECT_EQ("http://www.google.com/", url.spec()); |
| 185 } | 186 } |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 EXPECT_EQ("http://www.tamurayukari.com/", entry.url.spec()); | 289 EXPECT_EQ("http://www.tamurayukari.com/", entry.url.spec()); |
| 289 EXPECT_EQ(0U, entry.path.size()); | 290 EXPECT_EQ(0U, entry.path.size()); |
| 290 entry = *it++; | 291 entry = *it++; |
| 291 EXPECT_EQ(ASCIIToUTF16("Google"), entry.title); | 292 EXPECT_EQ(ASCIIToUTF16("Google"), entry.title); |
| 292 EXPECT_EQ("http://www.google.com/", entry.url.spec()); | 293 EXPECT_EQ("http://www.google.com/", entry.url.spec()); |
| 293 EXPECT_EQ(0U, entry.path.size()); | 294 EXPECT_EQ(0U, entry.path.size()); |
| 294 } | 295 } |
| 295 | 296 |
| 296 importer->Release(); | 297 importer->Release(); |
| 297 } | 298 } |
| OLD | NEW |