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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
59 "http://www.google.com/"}, | 59 "http://www.google.com/"}, |
60 }; | 60 }; |
61 | 61 |
62 const PasswordInfo kFirefoxPasswords[] = { | 62 const PasswordInfo kFirefoxPasswords[] = { |
63 {"http://localhost:8080/", "http://localhost:8080/", "http://localhost:8080/", | 63 {"http://localhost:8080/", "http://localhost:8080/", "http://localhost:8080/", |
64 "loginuser", "abc", "loginpass", "123", false}, | 64 "loginuser", "abc", "loginpass", "123", false}, |
65 {"http://localhost:8080/", "", "http://localhost:8080/localhost", | 65 {"http://localhost:8080/", "", "http://localhost:8080/localhost", |
66 "", "http", "", "Http1+1abcdefg", false}, | 66 "", "http", "", "Http1+1abcdefg", false}, |
67 }; | 67 }; |
68 | 68 |
69 // These search engines are mentioned in both search.sqlite and search.json. | |
70 // These are required to test older versions of Firefox which use search.sqlite. | |
69 const KeywordInfo kFirefoxKeywords[] = { | 71 const KeywordInfo kFirefoxKeywords[] = { |
70 { L"amazon.com", | 72 {L"amazon.com", |
71 "http://www.amazon.com/exec/obidos/external-search/?field-keywords=" | 73 "http://www.amazon.com/exec/obidos/external-search/?field-keywords=" |
72 "{searchTerms}&mode=blended" }, | 74 "{searchTerms}&mode=blended"}, |
73 { L"answers.com", | 75 {L"answers.com", |
74 "http://www.answers.com/main/ntquery?s={searchTerms}&gwp=13" }, | 76 "http://www.answers.com/main/ntquery?s={searchTerms}&gwp=13"}, |
75 { L"search.creativecommons.org", | 77 {L"search.creativecommons.org", |
76 "http://search.creativecommons.org/?q={searchTerms}" }, | 78 "http://search.creativecommons.org/?q={searchTerms}"}, |
77 { L"search.ebay.com", | 79 {L"search.ebay.com", |
78 "http://search.ebay.com/search/search.dll?query={searchTerms}&" | 80 "http://search.ebay.com/search/search.dll?query={searchTerms}&" |
79 "MfcISAPICommand=GetResult&ht=1&ebaytag1=ebayreg&srchdesc=n&" | 81 "MfcISAPICommand=GetResult&ht=1&ebaytag1=ebayreg&srchdesc=n&" |
80 "maxRecordsReturned=300&maxRecordsPerPage=50&SortProperty=MetaEndSort" }, | 82 "maxRecordsReturned=300&maxRecordsPerPage=50&SortProperty=MetaEndSort"}, |
81 { L"google.com", | 83 {L"google.com", |
82 "http://www.google.com/search?q={searchTerms}&ie=utf-8&oe=utf-8&aq=t" }, | 84 "http://www.google.com/search?q={searchTerms}&ie=utf-8&oe=utf-8&aq=t"}, |
83 { L"en.wikipedia.org", | 85 {L"en.wikipedia.org", |
84 "http://en.wikipedia.org/wiki/Special:Search?search={searchTerms}" }, | 86 "http://en.wikipedia.org/wiki/Special:Search?search={searchTerms}"}, |
85 { L"search.yahoo.com", | 87 {L"search.yahoo.com", |
86 "http://search.yahoo.com/search?p={searchTerms}&ei=UTF-8" }, | 88 "http://search.yahoo.com/search?p={searchTerms}&ei=UTF-8"}, |
87 { L"flickr.com", | 89 {L"flickr.com", "http://www.flickr.com/photos/tags/?q={searchTerms}"}, |
88 "http://www.flickr.com/photos/tags/?q={searchTerms}" }, | 90 {L"imdb.com", "http://www.imdb.com/find?q={searchTerms}"}, |
89 { L"imdb.com", | 91 {L"webster.com", |
90 "http://www.imdb.com/find?q={searchTerms}" }, | 92 "http://www.webster.com/cgi-bin/dictionary?va={searchTerms}"}, |
91 { L"webster.com", | 93 // Search keywords. |
92 "http://www.webster.com/cgi-bin/dictionary?va={searchTerms}" }, | 94 {L"\x4E2D\x6587", "http://www.google.com/"}}; |
93 // Search keywords. | 95 |
94 { L"\x4E2D\x6587", "http://www.google.com/" }, | 96 // These use search-metadata.json for storing keywords. |
95 }; | 97 const KeywordInfo kFirefoxSearchEnginesWithCustomKeywords[] = { |
Peter Kasting
2014/07/31 18:28:21
This looks like a duplicate of the list above plus
Nikhil
2014/08/04 12:15:11
I've now slightly changed the approach based on yo
| |
98 {L"amazon.com", | |
99 "http://www.amazon.com/exec/obidos/external-search/?field-keywords=" | |
100 "{searchTerms}&mode=blended"}, | |
101 {L"answers.com", | |
102 "http://www.answers.com/main/ntquery?s={searchTerms}&gwp=13"}, | |
103 {L"search.creativecommons.org", | |
104 "http://search.creativecommons.org/?q={searchTerms}"}, | |
105 {L"search.ebay.com", | |
106 "http://search.ebay.com/search/search.dll?query={searchTerms}&" | |
107 "MfcISAPICommand=GetResult&ht=1&ebaytag1=ebayreg&srchdesc=n&" | |
108 "maxRecordsReturned=300&maxRecordsPerPage=50&SortProperty=MetaEndSort"}, | |
109 {L"google.com", | |
110 "http://www.google.com/search?q={searchTerms}&ie=utf-8&oe=utf-8&aq=t"}, | |
111 {L"en.wikipedia.org", | |
112 "http://en.wikipedia.org/wiki/Special:Search?search={searchTerms}"}, | |
113 {L"search.yahoo.com", | |
114 "http://search.yahoo.com/search?p={searchTerms}&ei=UTF-8"}, | |
115 {L"flickr.com", "http://www.flickr.com/photos/tags/?q={searchTerms}"}, | |
116 {L"imdb.com", "http://www.imdb.com/find?q={searchTerms}"}, | |
117 {L"webster.com", | |
118 "http://www.webster.com/cgi-bin/dictionary?va={searchTerms}"}, | |
119 {L"\x4E2D\x6587", "http://www.google.com/"}, | |
120 {L"tweet", | |
121 "https://twitter.com/search?q={searchTerms}&source=desktop-search"}}; | |
96 | 122 |
97 class FirefoxObserver : public ProfileWriter, | 123 class FirefoxObserver : public ProfileWriter, |
98 public importer::ImporterProgressObserver { | 124 public importer::ImporterProgressObserver { |
99 public: | 125 public: |
100 FirefoxObserver() | 126 FirefoxObserver() |
101 : ProfileWriter(NULL), | 127 : ProfileWriter(NULL), |
102 bookmark_count_(0), | 128 bookmark_count_(0), |
103 history_count_(0), | 129 history_count_(0), |
104 password_count_(0), | 130 password_count_(0), |
105 keyword_count_(0) {} | 131 keyword_count_(0), |
132 has_custom_keyword_(false) {} | |
Peter Kasting
2014/07/31 18:28:21
This isn't a good variable name for this. This na
Nikhil
2014/08/04 12:15:11
Done.
| |
106 | 133 |
107 // importer::ImporterProgressObserver: | 134 // importer::ImporterProgressObserver: |
108 virtual void ImportStarted() OVERRIDE {} | 135 virtual void ImportStarted() OVERRIDE {} |
109 virtual void ImportItemStarted(importer::ImportItem item) OVERRIDE {} | 136 virtual void ImportItemStarted(importer::ImportItem item) OVERRIDE {} |
110 virtual void ImportItemEnded(importer::ImportItem item) OVERRIDE {} | 137 virtual void ImportItemEnded(importer::ImportItem item) OVERRIDE {} |
111 virtual void ImportEnded() OVERRIDE { | 138 virtual void ImportEnded() OVERRIDE { |
112 base::MessageLoop::current()->Quit(); | 139 base::MessageLoop::current()->Quit(); |
113 EXPECT_EQ(arraysize(kFirefoxBookmarks), bookmark_count_); | 140 EXPECT_EQ(arraysize(kFirefoxBookmarks), bookmark_count_); |
114 EXPECT_EQ(1U, history_count_); | 141 EXPECT_EQ(1U, history_count_); |
115 EXPECT_EQ(arraysize(kFirefoxPasswords), password_count_); | 142 EXPECT_EQ(arraysize(kFirefoxPasswords), password_count_); |
116 EXPECT_EQ(arraysize(kFirefoxKeywords), keyword_count_); | 143 if (!has_custom_keyword_) { |
144 EXPECT_EQ(arraysize(kFirefoxKeywords), keyword_count_); | |
145 } else { | |
146 EXPECT_EQ(arraysize(kFirefoxSearchEnginesWithCustomKeywords), | |
147 keyword_count_); | |
148 } | |
117 } | 149 } |
118 | 150 |
119 virtual bool BookmarkModelIsLoaded() const OVERRIDE { | 151 virtual bool BookmarkModelIsLoaded() const OVERRIDE { |
120 // Profile is ready for writing. | 152 // Profile is ready for writing. |
121 return true; | 153 return true; |
122 } | 154 } |
123 | 155 |
124 virtual bool TemplateURLServiceIsLoaded() const OVERRIDE { | 156 virtual bool TemplateURLServiceIsLoaded() const OVERRIDE { |
125 return true; | 157 return true; |
126 } | 158 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
166 } | 198 } |
167 } | 199 } |
168 | 200 |
169 virtual void AddKeywords(ScopedVector<TemplateURL> template_urls, | 201 virtual void AddKeywords(ScopedVector<TemplateURL> template_urls, |
170 bool unique_on_host_and_path) OVERRIDE { | 202 bool unique_on_host_and_path) OVERRIDE { |
171 for (size_t i = 0; i < template_urls.size(); ++i) { | 203 for (size_t i = 0; i < template_urls.size(); ++i) { |
172 // The order might not be deterministic, look in the expected list for | 204 // The order might not be deterministic, look in the expected list for |
173 // that template URL. | 205 // that template URL. |
174 bool found = false; | 206 bool found = false; |
175 const base::string16& keyword = template_urls[i]->keyword(); | 207 const base::string16& keyword = template_urls[i]->keyword(); |
208 if (!has_custom_keyword_) { | |
176 for (size_t j = 0; j < arraysize(kFirefoxKeywords); ++j) { | 209 for (size_t j = 0; j < arraysize(kFirefoxKeywords); ++j) { |
Peter Kasting
2014/07/31 18:28:21
Indenting (unless Rietveld isn't properly showing
Nikhil
2014/08/04 12:15:11
Done.
| |
177 if (keyword == base::WideToUTF16(kFirefoxKeywords[j].keyword)) { | 210 if (keyword == base::WideToUTF16(kFirefoxKeywords[j].keyword)) { |
178 EXPECT_EQ(kFirefoxKeywords[j].url, template_urls[i]->url()); | 211 EXPECT_EQ(kFirefoxKeywords[j].url, template_urls[i]->url()); |
179 found = true; | 212 found = true; |
180 break; | 213 break; |
181 } | 214 } |
182 } | 215 } |
183 EXPECT_TRUE(found); | 216 EXPECT_TRUE(found); |
184 ++keyword_count_; | 217 ++keyword_count_; |
218 } else { | |
219 for (size_t j = 0; | |
Peter Kasting
2014/07/31 18:28:21
Again, don't copy this code. Find a way to write
Nikhil
2014/08/04 12:15:11
Done.
| |
220 j < arraysize(kFirefoxSearchEnginesWithCustomKeywords); | |
221 ++j) { | |
222 if (keyword == | |
223 base::WideToUTF16( | |
224 kFirefoxSearchEnginesWithCustomKeywords[j].keyword)) { | |
225 EXPECT_EQ(kFirefoxSearchEnginesWithCustomKeywords[j].url, | |
226 template_urls[i]->url()); | |
227 found = true; | |
228 break; | |
229 } | |
230 } | |
231 EXPECT_TRUE(found); | |
232 ++keyword_count_; | |
233 } | |
185 } | 234 } |
186 } | 235 } |
187 | 236 |
188 virtual void AddFavicons( | 237 virtual void AddFavicons( |
189 const std::vector<ImportedFaviconUsage>& favicons) OVERRIDE { | 238 const std::vector<ImportedFaviconUsage>& favicons) OVERRIDE { |
190 } | 239 } |
191 | 240 |
241 void SetHasCustomKeyword(bool has_custom_keyword) { | |
Peter Kasting
2014/07/31 18:28:21
Cheap inline accessors should be named unix_hacker
Nikhil
2014/08/04 12:15:11
Done.
| |
242 has_custom_keyword_ = has_custom_keyword; | |
243 } | |
244 | |
192 private: | 245 private: |
193 virtual ~FirefoxObserver() {} | 246 virtual ~FirefoxObserver() {} |
194 | 247 |
195 size_t bookmark_count_; | 248 size_t bookmark_count_; |
196 size_t history_count_; | 249 size_t history_count_; |
197 size_t password_count_; | 250 size_t password_count_; |
198 size_t keyword_count_; | 251 size_t keyword_count_; |
252 | |
253 // If true, we verify keyword based on search-metadata.json. | |
254 bool has_custom_keyword_; | |
199 }; | 255 }; |
200 | 256 |
201 } // namespace | 257 } // namespace |
202 | 258 |
203 // These tests need to be browser tests in order to be able to run the OOP | 259 // 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 | 260 // import (via ExternalProcessImporterHost) which launches a utility process on |
205 // supported platforms. | 261 // supported platforms. |
206 class FirefoxProfileImporterBrowserTest : public InProcessBrowserTest { | 262 class FirefoxProfileImporterBrowserTest : public InProcessBrowserTest { |
207 protected: | 263 protected: |
208 virtual void SetUp() OVERRIDE { | 264 virtual void SetUp() OVERRIDE { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
285 IN_PROC_BROWSER_TEST_F(FirefoxProfileImporterBrowserTest, | 341 IN_PROC_BROWSER_TEST_F(FirefoxProfileImporterBrowserTest, |
286 MAYBE_IMPORTER(Firefox35Importer)) { | 342 MAYBE_IMPORTER(Firefox35Importer)) { |
287 scoped_refptr<FirefoxObserver> observer(new FirefoxObserver()); | 343 scoped_refptr<FirefoxObserver> observer(new FirefoxObserver()); |
288 FirefoxImporterBrowserTest( | 344 FirefoxImporterBrowserTest( |
289 "firefox35_profile", observer.get(), observer.get()); | 345 "firefox35_profile", observer.get(), observer.get()); |
290 } | 346 } |
291 | 347 |
292 IN_PROC_BROWSER_TEST_F(FirefoxProfileImporterBrowserTest, | 348 IN_PROC_BROWSER_TEST_F(FirefoxProfileImporterBrowserTest, |
293 MAYBE_IMPORTER(FirefoxImporter)) { | 349 MAYBE_IMPORTER(FirefoxImporter)) { |
294 scoped_refptr<FirefoxObserver> observer(new FirefoxObserver()); | 350 scoped_refptr<FirefoxObserver> observer(new FirefoxObserver()); |
351 observer->SetHasCustomKeyword(true); | |
295 FirefoxImporterBrowserTest("firefox_profile", observer.get(), observer.get()); | 352 FirefoxImporterBrowserTest("firefox_profile", observer.get(), observer.get()); |
296 } | 353 } |
354 | |
355 IN_PROC_BROWSER_TEST_F(FirefoxProfileImporterBrowserTest, | |
356 MAYBE_IMPORTER(ImportCustomKeywords)) { | |
Peter Kasting
2014/07/31 18:28:21
It's not clear why you added a test that is identi
Nikhil
2014/08/04 12:15:11
Removed it.
| |
357 scoped_refptr<FirefoxObserver> observer(new FirefoxObserver()); | |
358 observer->SetHasCustomKeyword(true); | |
359 FirefoxImporterBrowserTest("firefox_profile", observer.get(), observer.get()); | |
360 } | |
OLD | NEW |