OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "base/file_util.h" | 5 #include "base/file_util.h" |
6 #include "base/files/file_path.h" | 6 #include "base/files/file_path.h" |
7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 28 matching lines...) Expand all Loading... | |
39 const char* action; | 39 const char* action; |
40 const char* realm; | 40 const char* realm; |
41 const char* username_element; | 41 const char* username_element; |
42 const char* username; | 42 const char* username; |
43 const char* password_element; | 43 const char* password_element; |
44 const char* password; | 44 const char* password; |
45 bool blacklisted; | 45 bool blacklisted; |
46 }; | 46 }; |
47 | 47 |
48 struct KeywordInfo { | 48 struct KeywordInfo { |
49 const wchar_t* keyword; | 49 const wchar_t* keyword_in_sqlite; |
50 const wchar_t* keyword_in_json; | |
50 const char* url; | 51 const char* url; |
51 }; | 52 }; |
52 | 53 |
53 const BookmarkInfo kFirefoxBookmarks[] = { | 54 const BookmarkInfo kFirefoxBookmarks[] = { |
54 {true, 1, {"Bookmarks Toolbar"}, | 55 {true, 1, {"Bookmarks Toolbar"}, |
55 L"Toolbar", | 56 L"Toolbar", |
56 "http://site/"}, | 57 "http://site/"}, |
57 {false, 0, {}, | 58 {false, 0, {}, |
58 L"Title", | 59 L"Title", |
59 "http://www.google.com/"}, | 60 "http://www.google.com/"}, |
60 }; | 61 }; |
61 | 62 |
62 const PasswordInfo kFirefoxPasswords[] = { | 63 const PasswordInfo kFirefoxPasswords[] = { |
63 {"http://localhost:8080/", "http://localhost:8080/", "http://localhost:8080/", | 64 {"http://localhost:8080/", "http://localhost:8080/", "http://localhost:8080/", |
64 "loginuser", "abc", "loginpass", "123", false}, | 65 "loginuser", "abc", "loginpass", "123", false}, |
65 {"http://localhost:8080/", "", "http://localhost:8080/localhost", | 66 {"http://localhost:8080/", "", "http://localhost:8080/localhost", |
66 "", "http", "", "Http1+1abcdefg", false}, | 67 "", "http", "", "Http1+1abcdefg", false}, |
67 }; | 68 }; |
68 | 69 |
69 const KeywordInfo kFirefoxKeywords[] = { | 70 const KeywordInfo kFirefoxKeywords[] = { |
70 { L"amazon.com", | 71 {L"amazon.com", L"amazon.com", |
71 "http://www.amazon.com/exec/obidos/external-search/?field-keywords=" | 72 "http://www.amazon.com/exec/obidos/external-search/?field-keywords=" |
72 "{searchTerms}&mode=blended" }, | 73 "{searchTerms}&mode=blended"}, |
73 { L"answers.com", | 74 {L"answers.com", L"answers.com", |
74 "http://www.answers.com/main/ntquery?s={searchTerms}&gwp=13" }, | 75 "http://www.answers.com/main/ntquery?s={searchTerms}&gwp=13"}, |
75 { L"search.creativecommons.org", | 76 {L"search.creativecommons.org", L"search.creativecommons.org", |
76 "http://search.creativecommons.org/?q={searchTerms}" }, | 77 "http://search.creativecommons.org/?q={searchTerms}"}, |
77 { L"search.ebay.com", | 78 {L"search.ebay.com", L"search.ebay.com", |
78 "http://search.ebay.com/search/search.dll?query={searchTerms}&" | 79 "http://search.ebay.com/search/search.dll?query={searchTerms}&" |
79 "MfcISAPICommand=GetResult&ht=1&ebaytag1=ebayreg&srchdesc=n&" | 80 "MfcISAPICommand=GetResult&ht=1&ebaytag1=ebayreg&srchdesc=n&" |
80 "maxRecordsReturned=300&maxRecordsPerPage=50&SortProperty=MetaEndSort" }, | 81 "maxRecordsReturned=300&maxRecordsPerPage=50&SortProperty=MetaEndSort"}, |
81 { L"google.com", | 82 {L"google.com", L"google.com", |
82 "http://www.google.com/search?q={searchTerms}&ie=utf-8&oe=utf-8&aq=t" }, | 83 "http://www.google.com/search?q={searchTerms}&ie=utf-8&oe=utf-8&aq=t"}, |
83 { L"en.wikipedia.org", | 84 {L"en.wikipedia.org", L"wiki", |
84 "http://en.wikipedia.org/wiki/Special:Search?search={searchTerms}" }, | 85 "http://en.wikipedia.org/wiki/Special:Search?search={searchTerms}"}, |
85 { L"search.yahoo.com", | 86 {L"search.yahoo.com", L"search.yahoo.com", |
86 "http://search.yahoo.com/search?p={searchTerms}&ei=UTF-8" }, | 87 "http://search.yahoo.com/search?p={searchTerms}&ei=UTF-8"}, |
87 { L"flickr.com", | 88 {L"flickr.com", L"flickr.com", |
88 "http://www.flickr.com/photos/tags/?q={searchTerms}" }, | 89 "http://www.flickr.com/photos/tags/?q={searchTerms}"}, |
89 { L"imdb.com", | 90 {L"imdb.com", L"imdb.com", "http://www.imdb.com/find?q={searchTerms}"}, |
90 "http://www.imdb.com/find?q={searchTerms}" }, | 91 {L"webster.com", L"webster.com", |
91 { L"webster.com", | 92 "http://www.webster.com/cgi-bin/dictionary?va={searchTerms}"}, |
92 "http://www.webster.com/cgi-bin/dictionary?va={searchTerms}" }, | 93 // Search keywords. |
93 // Search keywords. | 94 {L"\x4E2D\x6587", L"\x4E2D\x6587", "http://www.google.com/"}, |
94 { L"\x4E2D\x6587", "http://www.google.com/" }, | |
95 }; | 95 }; |
96 | 96 |
97 class FirefoxObserver : public ProfileWriter, | 97 class FirefoxObserver : public ProfileWriter, |
98 public importer::ImporterProgressObserver { | 98 public importer::ImporterProgressObserver { |
99 public: | 99 public: |
100 FirefoxObserver() | 100 FirefoxObserver() |
101 : ProfileWriter(NULL), | 101 : ProfileWriter(NULL), |
102 bookmark_count_(0), | 102 bookmark_count_(0), |
103 history_count_(0), | 103 history_count_(0), |
104 password_count_(0), | 104 password_count_(0), |
105 keyword_count_(0) {} | 105 keyword_count_(0), |
106 is_sqlite_version_(false) {} | |
106 | 107 |
107 // importer::ImporterProgressObserver: | 108 // importer::ImporterProgressObserver: |
108 virtual void ImportStarted() OVERRIDE {} | 109 virtual void ImportStarted() OVERRIDE {} |
109 virtual void ImportItemStarted(importer::ImportItem item) OVERRIDE {} | 110 virtual void ImportItemStarted(importer::ImportItem item) OVERRIDE {} |
110 virtual void ImportItemEnded(importer::ImportItem item) OVERRIDE {} | 111 virtual void ImportItemEnded(importer::ImportItem item) OVERRIDE {} |
111 virtual void ImportEnded() OVERRIDE { | 112 virtual void ImportEnded() OVERRIDE { |
112 base::MessageLoop::current()->Quit(); | 113 base::MessageLoop::current()->Quit(); |
113 EXPECT_EQ(arraysize(kFirefoxBookmarks), bookmark_count_); | 114 EXPECT_EQ(arraysize(kFirefoxBookmarks), bookmark_count_); |
114 EXPECT_EQ(1U, history_count_); | 115 EXPECT_EQ(1U, history_count_); |
115 EXPECT_EQ(arraysize(kFirefoxPasswords), password_count_); | 116 EXPECT_EQ(arraysize(kFirefoxPasswords), password_count_); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
165 ++bookmark_count_; | 166 ++bookmark_count_; |
166 } | 167 } |
167 } | 168 } |
168 | 169 |
169 virtual void AddKeywords(ScopedVector<TemplateURL> template_urls, | 170 virtual void AddKeywords(ScopedVector<TemplateURL> template_urls, |
170 bool unique_on_host_and_path) OVERRIDE { | 171 bool unique_on_host_and_path) OVERRIDE { |
171 for (size_t i = 0; i < template_urls.size(); ++i) { | 172 for (size_t i = 0; i < template_urls.size(); ++i) { |
172 // The order might not be deterministic, look in the expected list for | 173 // The order might not be deterministic, look in the expected list for |
173 // that template URL. | 174 // that template URL. |
174 bool found = false; | 175 bool found = false; |
175 const base::string16& keyword = template_urls[i]->keyword(); | 176 const base::string16& imported_keyword = template_urls[i]->keyword(); |
176 for (size_t j = 0; j < arraysize(kFirefoxKeywords); ++j) { | 177 for (size_t j = 0; j < arraysize(kFirefoxKeywords); ++j) { |
177 if (keyword == base::WideToUTF16(kFirefoxKeywords[j].keyword)) { | 178 const base::string16& expected_keyword = |
Ilya Sherman
2014/08/13 20:14:17
nit: Hmm, you're defining a const-reference to an
Ilya Sherman
2014/08/13 20:18:43
FWIW, apparently this is indeed explicitly legal i
Nikhil
2014/08/14 09:13:08
Dropped reference.
| |
179 (is_sqlite_version_) | |
Peter Kasting
2014/08/13 17:32:01
Nit: Don't parenthesize an expression with only on
Nikhil
2014/08/14 09:13:08
Done.
| |
180 ? base::WideToUTF16(kFirefoxKeywords[j].keyword_in_sqlite) | |
Peter Kasting
2014/08/13 17:32:01
Nit: clang-format error: Wrap after '?' (and if ne
Nikhil
2014/08/14 09:13:08
Done.
| |
181 : base::WideToUTF16(kFirefoxKeywords[j].keyword_in_json); | |
182 if (expected_keyword == imported_keyword) { | |
Peter Kasting
2014/08/13 17:32:01
Nit: Maybe it's just me, but I expected this to re
Nikhil
2014/08/14 09:13:08
I've seen constants being used on left side of com
Ilya Sherman
2014/08/19 00:13:28
Constants on the left is an older style, which was
Nikhil
2014/08/19 05:57:46
Done.
| |
178 EXPECT_EQ(kFirefoxKeywords[j].url, template_urls[i]->url()); | 183 EXPECT_EQ(kFirefoxKeywords[j].url, template_urls[i]->url()); |
179 found = true; | 184 found = true; |
180 break; | 185 break; |
181 } | 186 } |
182 } | 187 } |
183 EXPECT_TRUE(found); | 188 EXPECT_TRUE(found); |
184 ++keyword_count_; | 189 ++keyword_count_; |
185 } | 190 } |
186 } | 191 } |
187 | 192 |
188 virtual void AddFavicons( | 193 virtual void AddFavicons( |
189 const std::vector<ImportedFaviconUsage>& favicons) OVERRIDE { | 194 const std::vector<ImportedFaviconUsage>& favicons) OVERRIDE { |
190 } | 195 } |
191 | 196 |
197 void set_sqlite_version(bool is_sqlite_version) { | |
Peter Kasting
2014/08/13 17:32:01
Nit: Instead of adding a member function to set th
Nikhil
2014/08/14 09:13:08
Done.
| |
198 is_sqlite_version_ = is_sqlite_version; | |
199 } | |
200 | |
192 private: | 201 private: |
193 virtual ~FirefoxObserver() {} | 202 virtual ~FirefoxObserver() {} |
194 | 203 |
195 size_t bookmark_count_; | 204 size_t bookmark_count_; |
196 size_t history_count_; | 205 size_t history_count_; |
197 size_t password_count_; | 206 size_t password_count_; |
198 size_t keyword_count_; | 207 size_t keyword_count_; |
208 | |
209 // If true, it means tests are run for Firefox version that uses | |
210 // search.sqlite to store search engines. Else, Firefox uses search.json to | |
211 // store search engines. | |
212 bool is_sqlite_version_; | |
Peter Kasting
2014/08/13 17:32:01
Nit: How about this:
// Newer versions of Firef
Nikhil
2014/08/14 09:13:08
Done.
| |
199 }; | 213 }; |
200 | 214 |
201 } // namespace | 215 } // namespace |
202 | 216 |
203 // These tests need to be browser tests in order to be able to run the OOP | 217 // These tests need to be browser tests in order to be able to run the OOP |
204 // import (via ExternalProcessImporterHost) which launches a utility process on | 218 // import (via ExternalProcessImporterHost) which launches a utility process on |
205 // supported platforms. | 219 // supported platforms. |
206 class FirefoxProfileImporterBrowserTest : public InProcessBrowserTest { | 220 class FirefoxProfileImporterBrowserTest : public InProcessBrowserTest { |
207 protected: | 221 protected: |
208 virtual void SetUp() OVERRIDE { | 222 virtual void SetUp() OVERRIDE { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
271 } | 285 } |
272 | 286 |
273 base::ScopedTempDir temp_dir_; | 287 base::ScopedTempDir temp_dir_; |
274 base::FilePath profile_path_; | 288 base::FilePath profile_path_; |
275 base::FilePath app_path_; | 289 base::FilePath app_path_; |
276 }; | 290 }; |
277 | 291 |
278 IN_PROC_BROWSER_TEST_F(FirefoxProfileImporterBrowserTest, | 292 IN_PROC_BROWSER_TEST_F(FirefoxProfileImporterBrowserTest, |
279 MAYBE_IMPORTER(Firefox30Importer)) { | 293 MAYBE_IMPORTER(Firefox30Importer)) { |
280 scoped_refptr<FirefoxObserver> observer(new FirefoxObserver()); | 294 scoped_refptr<FirefoxObserver> observer(new FirefoxObserver()); |
295 observer->set_sqlite_version(true); | |
281 FirefoxImporterBrowserTest( | 296 FirefoxImporterBrowserTest( |
282 "firefox3_profile", observer.get(), observer.get()); | 297 "firefox3_profile", observer.get(), observer.get()); |
283 } | 298 } |
284 | 299 |
285 IN_PROC_BROWSER_TEST_F(FirefoxProfileImporterBrowserTest, | 300 IN_PROC_BROWSER_TEST_F(FirefoxProfileImporterBrowserTest, |
286 MAYBE_IMPORTER(Firefox35Importer)) { | 301 MAYBE_IMPORTER(Firefox35Importer)) { |
287 scoped_refptr<FirefoxObserver> observer(new FirefoxObserver()); | 302 scoped_refptr<FirefoxObserver> observer(new FirefoxObserver()); |
303 observer->set_sqlite_version(true); | |
288 FirefoxImporterBrowserTest( | 304 FirefoxImporterBrowserTest( |
289 "firefox35_profile", observer.get(), observer.get()); | 305 "firefox35_profile", observer.get(), observer.get()); |
290 } | 306 } |
291 | 307 |
292 IN_PROC_BROWSER_TEST_F(FirefoxProfileImporterBrowserTest, | 308 IN_PROC_BROWSER_TEST_F(FirefoxProfileImporterBrowserTest, |
293 MAYBE_IMPORTER(FirefoxImporter)) { | 309 MAYBE_IMPORTER(FirefoxImporter)) { |
294 scoped_refptr<FirefoxObserver> observer(new FirefoxObserver()); | 310 scoped_refptr<FirefoxObserver> observer(new FirefoxObserver()); |
311 observer->set_sqlite_version(false); | |
295 FirefoxImporterBrowserTest("firefox_profile", observer.get(), observer.get()); | 312 FirefoxImporterBrowserTest("firefox_profile", observer.get(), observer.get()); |
296 } | 313 } |
OLD | NEW |