OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/path_service.h" | 6 #include "base/path_service.h" |
7 #include "base/stl_util-inl.h" | 7 #include "base/stl_util-inl.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/time.h" | 9 #include "base/time.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "chrome/browser/search_engines/template_url.h" | 11 #include "chrome/browser/search_engines/template_url.h" |
(...skipping 68 matching lines...) Loading... |
80 static void set_prepopulate_id(TemplateURL* url, int id) { | 80 static void set_prepopulate_id(TemplateURL* url, int id) { |
81 url->set_prepopulate_id(id); | 81 url->set_prepopulate_id(id); |
82 } | 82 } |
83 | 83 |
84 FilePath file_; | 84 FilePath file_; |
85 }; | 85 }; |
86 | 86 |
87 TEST_F(WebDatabaseTest, Keywords) { | 87 TEST_F(WebDatabaseTest, Keywords) { |
88 WebDatabase db; | 88 WebDatabase db; |
89 | 89 |
90 EXPECT_TRUE(db.Init(file_.ToWStringHack())); | 90 EXPECT_TRUE(db.Init(file_)); |
91 | 91 |
92 TemplateURL template_url; | 92 TemplateURL template_url; |
93 template_url.set_short_name(L"short_name"); | 93 template_url.set_short_name(L"short_name"); |
94 template_url.set_keyword(L"keyword"); | 94 template_url.set_keyword(L"keyword"); |
95 GURL favicon_url("http://favicon.url/"); | 95 GURL favicon_url("http://favicon.url/"); |
96 GURL originating_url("http://google.com/"); | 96 GURL originating_url("http://google.com/"); |
97 template_url.SetFavIconURL(favicon_url); | 97 template_url.SetFavIconURL(favicon_url); |
98 template_url.SetURL(L"http://url/", 0, 0); | 98 template_url.SetURL(L"http://url/", 0, 0); |
99 template_url.set_safe_for_autoreplace(true); | 99 template_url.set_safe_for_autoreplace(true); |
100 template_url.set_show_in_default_list(true); | 100 template_url.set_show_in_default_list(true); |
(...skipping 40 matching lines...) Loading... |
141 EXPECT_TRUE(db.GetKeywords(&template_urls)); | 141 EXPECT_TRUE(db.GetKeywords(&template_urls)); |
142 | 142 |
143 EXPECT_EQ(0U, template_urls.size()); | 143 EXPECT_EQ(0U, template_urls.size()); |
144 | 144 |
145 delete restored_url; | 145 delete restored_url; |
146 } | 146 } |
147 | 147 |
148 TEST_F(WebDatabaseTest, KeywordMisc) { | 148 TEST_F(WebDatabaseTest, KeywordMisc) { |
149 WebDatabase db; | 149 WebDatabase db; |
150 | 150 |
151 EXPECT_TRUE(db.Init(file_.ToWStringHack())); | 151 EXPECT_TRUE(db.Init(file_)); |
152 | 152 |
153 ASSERT_EQ(0, db.GetDefaulSearchProviderID()); | 153 ASSERT_EQ(0, db.GetDefaulSearchProviderID()); |
154 ASSERT_EQ(0, db.GetBuitinKeywordVersion()); | 154 ASSERT_EQ(0, db.GetBuitinKeywordVersion()); |
155 | 155 |
156 db.SetDefaultSearchProviderID(10); | 156 db.SetDefaultSearchProviderID(10); |
157 db.SetBuitinKeywordVersion(11); | 157 db.SetBuitinKeywordVersion(11); |
158 | 158 |
159 ASSERT_EQ(10, db.GetDefaulSearchProviderID()); | 159 ASSERT_EQ(10, db.GetDefaulSearchProviderID()); |
160 ASSERT_EQ(11, db.GetBuitinKeywordVersion()); | 160 ASSERT_EQ(11, db.GetBuitinKeywordVersion()); |
161 } | 161 } |
162 | 162 |
163 TEST_F(WebDatabaseTest, UpdateKeyword) { | 163 TEST_F(WebDatabaseTest, UpdateKeyword) { |
164 WebDatabase db; | 164 WebDatabase db; |
165 | 165 |
166 EXPECT_TRUE(db.Init(file_.ToWStringHack())); | 166 EXPECT_TRUE(db.Init(file_)); |
167 | 167 |
168 TemplateURL template_url; | 168 TemplateURL template_url; |
169 template_url.set_short_name(L"short_name"); | 169 template_url.set_short_name(L"short_name"); |
170 template_url.set_keyword(L"keyword"); | 170 template_url.set_keyword(L"keyword"); |
171 GURL favicon_url("http://favicon.url/"); | 171 GURL favicon_url("http://favicon.url/"); |
172 GURL originating_url("http://originating.url/"); | 172 GURL originating_url("http://originating.url/"); |
173 template_url.SetFavIconURL(favicon_url); | 173 template_url.SetFavIconURL(favicon_url); |
174 template_url.SetURL(L"http://url/", 0, 0); | 174 template_url.SetURL(L"http://url/", 0, 0); |
175 template_url.set_safe_for_autoreplace(true); | 175 template_url.set_safe_for_autoreplace(true); |
176 template_url.set_show_in_default_list(true); | 176 template_url.set_show_in_default_list(true); |
(...skipping 41 matching lines...) Loading... |
218 EXPECT_EQ(template_url.id(), restored_url->id()); | 218 EXPECT_EQ(template_url.id(), restored_url->id()); |
219 | 219 |
220 EXPECT_EQ(template_url.prepopulate_id(), restored_url->prepopulate_id()); | 220 EXPECT_EQ(template_url.prepopulate_id(), restored_url->prepopulate_id()); |
221 | 221 |
222 delete restored_url; | 222 delete restored_url; |
223 } | 223 } |
224 | 224 |
225 TEST_F(WebDatabaseTest, KeywordWithNoFavicon) { | 225 TEST_F(WebDatabaseTest, KeywordWithNoFavicon) { |
226 WebDatabase db; | 226 WebDatabase db; |
227 | 227 |
228 EXPECT_TRUE(db.Init(file_.ToWStringHack())); | 228 EXPECT_TRUE(db.Init(file_)); |
229 | 229 |
230 TemplateURL template_url; | 230 TemplateURL template_url; |
231 template_url.set_short_name(L"short_name"); | 231 template_url.set_short_name(L"short_name"); |
232 template_url.set_keyword(L"keyword"); | 232 template_url.set_keyword(L"keyword"); |
233 template_url.SetURL(L"http://url/", 0, 0); | 233 template_url.SetURL(L"http://url/", 0, 0); |
234 template_url.set_safe_for_autoreplace(true); | 234 template_url.set_safe_for_autoreplace(true); |
235 SetID(-100, &template_url); | 235 SetID(-100, &template_url); |
236 | 236 |
237 EXPECT_TRUE(db.AddKeyword(template_url)); | 237 EXPECT_TRUE(db.AddKeyword(template_url)); |
238 | 238 |
239 std::vector<TemplateURL*> template_urls; | 239 std::vector<TemplateURL*> template_urls; |
240 EXPECT_TRUE(db.GetKeywords(&template_urls)); | 240 EXPECT_TRUE(db.GetKeywords(&template_urls)); |
241 EXPECT_EQ(1U, template_urls.size()); | 241 EXPECT_EQ(1U, template_urls.size()); |
242 const TemplateURL* restored_url = template_urls.front(); | 242 const TemplateURL* restored_url = template_urls.front(); |
243 | 243 |
244 EXPECT_EQ(template_url.short_name(), restored_url->short_name()); | 244 EXPECT_EQ(template_url.short_name(), restored_url->short_name()); |
245 EXPECT_EQ(template_url.keyword(), restored_url->keyword()); | 245 EXPECT_EQ(template_url.keyword(), restored_url->keyword()); |
246 EXPECT_TRUE(!restored_url->GetFavIconURL().is_valid()); | 246 EXPECT_TRUE(!restored_url->GetFavIconURL().is_valid()); |
247 EXPECT_TRUE(restored_url->safe_for_autoreplace()); | 247 EXPECT_TRUE(restored_url->safe_for_autoreplace()); |
248 EXPECT_EQ(GetID(&template_url), GetID(restored_url)); | 248 EXPECT_EQ(GetID(&template_url), GetID(restored_url)); |
249 delete restored_url; | 249 delete restored_url; |
250 } | 250 } |
251 | 251 |
252 TEST_F(WebDatabaseTest, Logins) { | 252 TEST_F(WebDatabaseTest, Logins) { |
253 WebDatabase db; | 253 WebDatabase db; |
254 | 254 |
255 EXPECT_TRUE(db.Init(file_.ToWStringHack())); | 255 EXPECT_TRUE(db.Init(file_)); |
256 | 256 |
257 std::vector<PasswordForm*> result; | 257 std::vector<PasswordForm*> result; |
258 | 258 |
259 // Verify the database is empty. | 259 // Verify the database is empty. |
260 EXPECT_TRUE(db.GetAllLogins(&result, true)); | 260 EXPECT_TRUE(db.GetAllLogins(&result, true)); |
261 EXPECT_EQ(0U, result.size()); | 261 EXPECT_EQ(0U, result.size()); |
262 | 262 |
263 // Example password form. | 263 // Example password form. |
264 PasswordForm form; | 264 PasswordForm form; |
265 form.origin = GURL("http://www.google.com/accounts/LoginAuth"); | 265 form.origin = GURL("http://www.google.com/accounts/LoginAuth"); |
(...skipping 112 matching lines...) Loading... |
378 | 378 |
379 // Make sure everything can disappear. | 379 // Make sure everything can disappear. |
380 EXPECT_TRUE(db.RemoveLogin(form4)); | 380 EXPECT_TRUE(db.RemoveLogin(form4)); |
381 EXPECT_TRUE(db.GetAllLogins(&result, true)); | 381 EXPECT_TRUE(db.GetAllLogins(&result, true)); |
382 EXPECT_EQ(0U, result.size()); | 382 EXPECT_EQ(0U, result.size()); |
383 } | 383 } |
384 | 384 |
385 TEST_F(WebDatabaseTest, Autofill) { | 385 TEST_F(WebDatabaseTest, Autofill) { |
386 WebDatabase db; | 386 WebDatabase db; |
387 | 387 |
388 EXPECT_TRUE(db.Init(file_.ToWStringHack())); | 388 EXPECT_TRUE(db.Init(file_)); |
389 | 389 |
390 Time t1 = Time::Now(); | 390 Time t1 = Time::Now(); |
391 | 391 |
392 // Simulate the submission of a handful of entries in a field called "Name", | 392 // Simulate the submission of a handful of entries in a field called "Name", |
393 // some more often than others. | 393 // some more often than others. |
394 EXPECT_TRUE(db.AddAutofillFormElement( | 394 EXPECT_TRUE(db.AddAutofillFormElement( |
395 AutofillForm::Element(L"Name", L"Superman"))); | 395 AutofillForm::Element(L"Name", L"Superman"))); |
396 std::vector<std::wstring> v; | 396 std::vector<std::wstring> v; |
397 for (int i = 0; i < 5; i++) { | 397 for (int i = 0; i < 5; i++) { |
398 EXPECT_TRUE(db.AddAutofillFormElement( | 398 EXPECT_TRUE(db.AddAutofillFormElement( |
(...skipping 111 matching lines...) Loading... |
510 static void ClearResults(std::vector<PasswordForm*>* results) { | 510 static void ClearResults(std::vector<PasswordForm*>* results) { |
511 for (size_t i = 0; i < results->size(); ++i) { | 511 for (size_t i = 0; i < results->size(); ++i) { |
512 delete (*results)[i]; | 512 delete (*results)[i]; |
513 } | 513 } |
514 results->clear(); | 514 results->clear(); |
515 } | 515 } |
516 | 516 |
517 TEST_F(WebDatabaseTest, ClearPrivateData_SavedPasswords) { | 517 TEST_F(WebDatabaseTest, ClearPrivateData_SavedPasswords) { |
518 WebDatabase db; | 518 WebDatabase db; |
519 | 519 |
520 EXPECT_TRUE(db.Init(file_.ToWStringHack())); | 520 EXPECT_TRUE(db.Init(file_)); |
521 | 521 |
522 std::vector<PasswordForm*> result; | 522 std::vector<PasswordForm*> result; |
523 | 523 |
524 // Verify the database is empty. | 524 // Verify the database is empty. |
525 EXPECT_TRUE(db.GetAllLogins(&result, true)); | 525 EXPECT_TRUE(db.GetAllLogins(&result, true)); |
526 EXPECT_EQ(0U, result.size()); | 526 EXPECT_EQ(0U, result.size()); |
527 | 527 |
528 Time now = Time::Now(); | 528 Time now = Time::Now(); |
529 TimeDelta one_day = TimeDelta::FromDays(1); | 529 TimeDelta one_day = TimeDelta::FromDays(1); |
530 | 530 |
(...skipping 21 matching lines...) Loading... |
552 db.RemoveLoginsCreatedBetween(Time(), Time()); | 552 db.RemoveLoginsCreatedBetween(Time(), Time()); |
553 | 553 |
554 // Verify nothing is left. | 554 // Verify nothing is left. |
555 EXPECT_TRUE(db.GetAllLogins(&result, true)); | 555 EXPECT_TRUE(db.GetAllLogins(&result, true)); |
556 EXPECT_EQ(0U, result.size()); | 556 EXPECT_EQ(0U, result.size()); |
557 } | 557 } |
558 | 558 |
559 TEST_F(WebDatabaseTest, BlacklistedLogins) { | 559 TEST_F(WebDatabaseTest, BlacklistedLogins) { |
560 WebDatabase db; | 560 WebDatabase db; |
561 | 561 |
562 EXPECT_TRUE(db.Init(file_.ToWStringHack())); | 562 EXPECT_TRUE(db.Init(file_)); |
563 std::vector<PasswordForm*> result; | 563 std::vector<PasswordForm*> result; |
564 | 564 |
565 // Verify the database is empty. | 565 // Verify the database is empty. |
566 EXPECT_TRUE(db.GetAllLogins(&result, true)); | 566 EXPECT_TRUE(db.GetAllLogins(&result, true)); |
567 ASSERT_EQ(0U, result.size()); | 567 ASSERT_EQ(0U, result.size()); |
568 | 568 |
569 // Save a form as blacklisted. | 569 // Save a form as blacklisted. |
570 PasswordForm form; | 570 PasswordForm form; |
571 form.origin = GURL("http://www.google.com/accounts/LoginAuth"); | 571 form.origin = GURL("http://www.google.com/accounts/LoginAuth"); |
572 form.action = GURL("http://www.google.com/accounts/Login"); | 572 form.action = GURL("http://www.google.com/accounts/Login"); |
(...skipping 18 matching lines...) Loading... |
591 | 591 |
592 // So should GetAll including blacklisted. | 592 // So should GetAll including blacklisted. |
593 EXPECT_TRUE(db.GetAllLogins(&result, true)); | 593 EXPECT_TRUE(db.GetAllLogins(&result, true)); |
594 EXPECT_EQ(1U, result.size()); | 594 EXPECT_EQ(1U, result.size()); |
595 ClearResults(&result); | 595 ClearResults(&result); |
596 } | 596 } |
597 | 597 |
598 TEST_F(WebDatabaseTest, WebAppHasAllImages) { | 598 TEST_F(WebDatabaseTest, WebAppHasAllImages) { |
599 WebDatabase db; | 599 WebDatabase db; |
600 | 600 |
601 EXPECT_TRUE(db.Init(file_.ToWStringHack())); | 601 EXPECT_TRUE(db.Init(file_)); |
602 GURL url("http://google.com/"); | 602 GURL url("http://google.com/"); |
603 | 603 |
604 // Initial value for unknown web app should be false. | 604 // Initial value for unknown web app should be false. |
605 EXPECT_FALSE(db.GetWebAppHasAllImages(url)); | 605 EXPECT_FALSE(db.GetWebAppHasAllImages(url)); |
606 | 606 |
607 // Set the value and make sure it took. | 607 // Set the value and make sure it took. |
608 EXPECT_TRUE(db.SetWebAppHasAllImages(url, true)); | 608 EXPECT_TRUE(db.SetWebAppHasAllImages(url, true)); |
609 EXPECT_TRUE(db.GetWebAppHasAllImages(url)); | 609 EXPECT_TRUE(db.GetWebAppHasAllImages(url)); |
610 | 610 |
611 // Remove the app and make sure value reverts to default. | 611 // Remove the app and make sure value reverts to default. |
612 EXPECT_TRUE(db.RemoveWebApp(url)); | 612 EXPECT_TRUE(db.RemoveWebApp(url)); |
613 EXPECT_FALSE(db.GetWebAppHasAllImages(url)); | 613 EXPECT_FALSE(db.GetWebAppHasAllImages(url)); |
614 } | 614 } |
615 | 615 |
616 TEST_F(WebDatabaseTest, WebAppImages) { | 616 TEST_F(WebDatabaseTest, WebAppImages) { |
617 WebDatabase db; | 617 WebDatabase db; |
618 | 618 |
619 ASSERT_TRUE(db.Init(file_.ToWStringHack())); | 619 ASSERT_TRUE(db.Init(file_)); |
620 GURL url("http://google.com/"); | 620 GURL url("http://google.com/"); |
621 | 621 |
622 // Web app should initially have no images. | 622 // Web app should initially have no images. |
623 std::vector<SkBitmap> images; | 623 std::vector<SkBitmap> images; |
624 ASSERT_TRUE(db.GetWebAppImages(url, &images)); | 624 ASSERT_TRUE(db.GetWebAppImages(url, &images)); |
625 ASSERT_EQ(0U, images.size()); | 625 ASSERT_EQ(0U, images.size()); |
626 | 626 |
627 // Add an image. | 627 // Add an image. |
628 SkBitmap image; | 628 SkBitmap image; |
629 image.setConfig(SkBitmap::kARGB_8888_Config, 16, 16); | 629 image.setConfig(SkBitmap::kARGB_8888_Config, 16, 16); |
(...skipping 49 matching lines...) Loading... |
679 ASSERT_EQ(16, images[0].height()); | 679 ASSERT_EQ(16, images[0].height()); |
680 ASSERT_EQ(32, images[1].width()); | 680 ASSERT_EQ(32, images[1].width()); |
681 ASSERT_EQ(32, images[1].height()); | 681 ASSERT_EQ(32, images[1].height()); |
682 } else { | 682 } else { |
683 ASSERT_EQ(32, images[0].width()); | 683 ASSERT_EQ(32, images[0].width()); |
684 ASSERT_EQ(32, images[0].height()); | 684 ASSERT_EQ(32, images[0].height()); |
685 ASSERT_EQ(16, images[1].width()); | 685 ASSERT_EQ(16, images[1].width()); |
686 ASSERT_EQ(16, images[1].height()); | 686 ASSERT_EQ(16, images[1].height()); |
687 } | 687 } |
688 } | 688 } |
OLD | NEW |