summaryrefslogtreecommitdiffstats
path: root/chrome/browser/webdata/web_database_unittest.cc
diff options
context:
space:
mode:
authorphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-16 11:12:13 +0000
committerphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-16 11:12:13 +0000
commit400d807b0c567a1df1087694627737174a13c8ad (patch)
tree49250804cbf635a2bb460937ac930d92dcf1b361 /chrome/browser/webdata/web_database_unittest.cc
parent97f756b5dcf7d1a6ffb4ea4e961ccb5fb12aeae2 (diff)
downloadchromium_src-400d807b0c567a1df1087694627737174a13c8ad.zip
chromium_src-400d807b0c567a1df1087694627737174a13c8ad.tar.gz
chromium_src-400d807b0c567a1df1087694627737174a13c8ad.tar.bz2
Porting in browser/webdata and template_url.
Review URL: http://codereview.chromium.org/14419 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@7052 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/webdata/web_database_unittest.cc')
-rw-r--r--chrome/browser/webdata/web_database_unittest.cc96
1 files changed, 46 insertions, 50 deletions
diff --git a/chrome/browser/webdata/web_database_unittest.cc b/chrome/browser/webdata/web_database_unittest.cc
index 1fe4ce4..349b803 100644
--- a/chrome/browser/webdata/web_database_unittest.cc
+++ b/chrome/browser/webdata/web_database_unittest.cc
@@ -2,11 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include <windows.h>
-
#include "base/file_util.h"
#include "base/path_service.h"
#include "base/string_util.h"
+#include "base/time.h"
#include "base/values.h"
#include "chrome/browser/template_url.h"
#include "chrome/browser/webdata/web_database.h"
@@ -24,19 +23,16 @@ class WebDatabaseTest : public testing::Test {
protected:
virtual void SetUp() {
- wchar_t b[32];
- _itow_s(static_cast<int>(GetTickCount()), b, arraysize(b), 10);
-
PathService::Get(chrome::DIR_TEST_DATA, &file_);
file_ += FilePath::kSeparators[0];
file_ += L"TestWebDatabase";
- file_ += b;
+ file_ += Int64ToWString(base::Time::Now().ToInternalValue());
file_ += L".db";
- DeleteFile(file_.c_str());
+ file_util::Delete(file_, false);
}
virtual void TearDown() {
- DeleteFile(file_.c_str());
+ file_util::Delete(file_, false);
}
static int GetKeyCount(const DictionaryValue& d) {
@@ -111,7 +107,7 @@ TEST_F(WebDatabaseTest, Keywords) {
std::vector<TemplateURL*> template_urls;
EXPECT_TRUE(db.GetKeywords(&template_urls));
- EXPECT_EQ(1, template_urls.size());
+ EXPECT_EQ(1U, template_urls.size());
const TemplateURL* restored_url = template_urls.front();
EXPECT_EQ(template_url.short_name(), restored_url->short_name());
@@ -132,7 +128,7 @@ TEST_F(WebDatabaseTest, Keywords) {
EXPECT_EQ(32, restored_url->usage_count());
- ASSERT_EQ(1, restored_url->input_encodings().size());
+ ASSERT_EQ(1U, restored_url->input_encodings().size());
EXPECT_EQ("UTF-8", restored_url->input_encodings()[0]);
EXPECT_EQ(10, restored_url->prepopulate_id());
@@ -142,7 +138,7 @@ TEST_F(WebDatabaseTest, Keywords) {
template_urls.clear();
EXPECT_TRUE(db.GetKeywords(&template_urls));
- EXPECT_EQ(0, template_urls.size());
+ EXPECT_EQ(0U, template_urls.size());
delete restored_url;
}
@@ -192,7 +188,7 @@ TEST_F(WebDatabaseTest, UpdateKeyword) {
std::vector<TemplateURL*> template_urls;
EXPECT_TRUE(db.GetKeywords(&template_urls));
- EXPECT_EQ(1, template_urls.size());
+ EXPECT_EQ(1U, template_urls.size());
const TemplateURL* restored_url = template_urls.front();
EXPECT_EQ(template_url.short_name(), restored_url->short_name());
@@ -211,7 +207,7 @@ TEST_F(WebDatabaseTest, UpdateKeyword) {
EXPECT_TRUE(originating_url2 == restored_url->originating_url());
- ASSERT_EQ(1, restored_url->input_encodings().size());
+ ASSERT_EQ(1U, restored_url->input_encodings().size());
ASSERT_EQ("Shift_JIS", restored_url->input_encodings()[0]);
EXPECT_EQ(template_url.suggestions_url()->url(),
@@ -240,7 +236,7 @@ TEST_F(WebDatabaseTest, KeywordWithNoFavicon) {
std::vector<TemplateURL*> template_urls;
EXPECT_TRUE(db.GetKeywords(&template_urls));
- EXPECT_EQ(1, template_urls.size());
+ EXPECT_EQ(1U, template_urls.size());
const TemplateURL* restored_url = template_urls.front();
EXPECT_EQ(template_url.short_name(), restored_url->short_name());
@@ -260,12 +256,12 @@ TEST_F(WebDatabaseTest, Logins) {
// Verify the database is empty.
EXPECT_TRUE(db.GetAllLogins(&result, true));
- EXPECT_EQ(0, result.size());
+ EXPECT_EQ(0U, result.size());
// Example password form.
PasswordForm form;
- form.origin = GURL(L"http://www.google.com/accounts/LoginAuth");
- form.action = GURL(L"http://www.google.com/accounts/Login");
+ form.origin = GURL("http://www.google.com/accounts/LoginAuth");
+ form.action = GURL("http://www.google.com/accounts/Login");
form.username_element = L"Email";
form.username_value = L"test@gmail.com";
form.password_element = L"Passwd";
@@ -279,34 +275,34 @@ TEST_F(WebDatabaseTest, Logins) {
// Add it and make sure it is there.
EXPECT_TRUE(db.AddLogin(form));
EXPECT_TRUE(db.GetAllLogins(&result, true));
- EXPECT_EQ(1, result.size());
+ EXPECT_EQ(1U, result.size());
delete result[0];
result.clear();
// Match against an exact copy.
EXPECT_TRUE(db.GetLogins(form, &result));
- EXPECT_EQ(1, result.size());
+ EXPECT_EQ(1U, result.size());
delete result[0];
result.clear();
// The example site changes...
PasswordForm form2(form);
- form2.origin = GURL(L"http://www.google.com/new/accounts/LoginAuth");
+ form2.origin = GURL("http://www.google.com/new/accounts/LoginAuth");
form2.submit_element = L"reallySignIn";
// Match against an inexact copy
EXPECT_TRUE(db.GetLogins(form2, &result));
- EXPECT_EQ(1, result.size());
+ EXPECT_EQ(1U, result.size());
delete result[0];
result.clear();
// Uh oh, the site changed origin & action URL's all at once!
PasswordForm form3(form2);
- form3.action = GURL(L"http://www.google.com/new/accounts/Login");
+ form3.action = GURL("http://www.google.com/new/accounts/Login");
// signon_realm is the same, should match.
EXPECT_TRUE(db.GetLogins(form3, &result));
- EXPECT_EQ(1, result.size());
+ EXPECT_EQ(1U, result.size());
delete result[0];
result.clear();
@@ -317,32 +313,32 @@ TEST_F(WebDatabaseTest, Logins) {
// We have only an http record, so no match for this.
EXPECT_TRUE(db.GetLogins(form4, &result));
- EXPECT_EQ(0, result.size());
+ EXPECT_EQ(0U, result.size());
// Let's imagine the user logs into the secure site.
EXPECT_TRUE(db.AddLogin(form4));
EXPECT_TRUE(db.GetAllLogins(&result, true));
- EXPECT_EQ(2, result.size());
+ EXPECT_EQ(2U, result.size());
delete result[0];
delete result[1];
result.clear();
// Now the match works
EXPECT_TRUE(db.GetLogins(form4, &result));
- EXPECT_EQ(1, result.size());
+ EXPECT_EQ(1U, result.size());
delete result[0];
result.clear();
// The user chose to forget the original but not the new.
EXPECT_TRUE(db.RemoveLogin(form));
EXPECT_TRUE(db.GetAllLogins(&result, true));
- EXPECT_EQ(1, result.size());
+ EXPECT_EQ(1U, result.size());
delete result[0];
result.clear();
// The old form wont match the new site (http vs https).
EXPECT_TRUE(db.GetLogins(form, &result));
- EXPECT_EQ(0, result.size());
+ EXPECT_EQ(0U, result.size());
// The user's request for the HTTPS site is intercepted
// by an attacker who presents an invalid SSL cert.
@@ -351,7 +347,7 @@ TEST_F(WebDatabaseTest, Logins) {
// It will match in this case.
EXPECT_TRUE(db.GetLogins(form5, &result));
- EXPECT_EQ(1, result.size());
+ EXPECT_EQ(1U, result.size());
delete result[0];
result.clear();
@@ -365,12 +361,12 @@ TEST_F(WebDatabaseTest, Logins) {
EXPECT_TRUE(db.UpdateLogin(form6));
// matches
EXPECT_TRUE(db.GetLogins(form5, &result));
- EXPECT_EQ(1, result.size());
+ EXPECT_EQ(1U, result.size());
delete result[0];
result.clear();
// Only one record.
EXPECT_TRUE(db.GetAllLogins(&result, true));
- EXPECT_EQ(1, result.size());
+ EXPECT_EQ(1U, result.size());
// password element was updated.
EXPECT_EQ(form6.password_value, result[0]->password_value);
// Preferred login.
@@ -381,7 +377,7 @@ TEST_F(WebDatabaseTest, Logins) {
// Make sure everything can disappear.
EXPECT_TRUE(db.RemoveLogin(form4));
EXPECT_TRUE(db.GetAllLogins(&result, true));
- EXPECT_EQ(0, result.size());
+ EXPECT_EQ(0U, result.size());
}
TEST_F(WebDatabaseTest, Autofill) {
@@ -434,7 +430,7 @@ TEST_F(WebDatabaseTest, Autofill) {
// no matter what they start with. The order that the names occur in the list
// should be decreasing order by count.
EXPECT_TRUE(db.GetFormValuesForElementName(L"Name", std::wstring(), &v, 6));
- EXPECT_EQ(3, v.size());
+ EXPECT_EQ(3U, v.size());
if (v.size() == 3) {
EXPECT_EQ(L"Clark Kent", v[0]);
EXPECT_EQ(L"Clark Sutter", v[1]);
@@ -444,7 +440,7 @@ TEST_F(WebDatabaseTest, Autofill) {
// If we query again limiting the list size to 1, we should only get the most
// frequent entry.
EXPECT_TRUE(db.GetFormValuesForElementName(L"Name", L"", &v, 1));
- EXPECT_EQ(1, v.size());
+ EXPECT_EQ(1U, v.size());
if (v.size() == 1) {
EXPECT_EQ(L"Clark Kent", v[0]);
}
@@ -452,7 +448,7 @@ TEST_F(WebDatabaseTest, Autofill) {
// Querying for suggestions given a prefix is case-insensitive, so the prefix
// "cLa" shoud get suggestions for both Clarks.
EXPECT_TRUE(db.GetFormValuesForElementName(L"Name", L"cLa", &v, 6));
- EXPECT_EQ(2, v.size());
+ EXPECT_EQ(2U, v.size());
if (v.size() == 2) {
EXPECT_EQ(L"Clark Kent", v[0]);
EXPECT_EQ(L"Clark Sutter", v[1]);
@@ -467,7 +463,7 @@ TEST_F(WebDatabaseTest, Autofill) {
EXPECT_EQ(0, count);
EXPECT_TRUE(db.GetFormValuesForElementName(L"Name", L"", &v, 6));
- EXPECT_EQ(0, v.size());
+ EXPECT_EQ(0U, v.size());
}
static bool AddTimestampedLogin(WebDatabase* db, std::string url,
@@ -500,7 +496,7 @@ TEST_F(WebDatabaseTest, ClearPrivateData_SavedPasswords) {
// Verify the database is empty.
EXPECT_TRUE(db.GetAllLogins(&result, true));
- EXPECT_EQ(0, result.size());
+ EXPECT_EQ(0U, result.size());
Time now = Time::Now();
TimeDelta one_day = TimeDelta::FromDays(1);
@@ -514,7 +510,7 @@ TEST_F(WebDatabaseTest, ClearPrivateData_SavedPasswords) {
// Verify inserts worked.
EXPECT_TRUE(db.GetAllLogins(&result, true));
- EXPECT_EQ(4, result.size());
+ EXPECT_EQ(4U, result.size());
ClearResults(&result);
// Delete everything from today's date and on.
@@ -522,7 +518,7 @@ TEST_F(WebDatabaseTest, ClearPrivateData_SavedPasswords) {
// Should have deleted half of what we inserted.
EXPECT_TRUE(db.GetAllLogins(&result, true));
- EXPECT_EQ(2, result.size());
+ EXPECT_EQ(2U, result.size());
ClearResults(&result);
// Delete with 0 date (should delete all).
@@ -530,7 +526,7 @@ TEST_F(WebDatabaseTest, ClearPrivateData_SavedPasswords) {
// Verify nothing is left.
EXPECT_TRUE(db.GetAllLogins(&result, true));
- EXPECT_EQ(0, result.size());
+ EXPECT_EQ(0U, result.size());
}
TEST_F(WebDatabaseTest, BlacklistedLogins) {
@@ -541,12 +537,12 @@ TEST_F(WebDatabaseTest, BlacklistedLogins) {
// Verify the database is empty.
EXPECT_TRUE(db.GetAllLogins(&result, true));
- ASSERT_EQ(0, result.size());
+ ASSERT_EQ(0U, result.size());
// Save a form as blacklisted.
PasswordForm form;
- form.origin = GURL(L"http://www.google.com/accounts/LoginAuth");
- form.action = GURL(L"http://www.google.com/accounts/Login");
+ form.origin = GURL("http://www.google.com/accounts/LoginAuth");
+ form.action = GURL("http://www.google.com/accounts/Login");
form.username_element = L"Email";
form.password_element = L"Passwd";
form.submit_element = L"signIn";
@@ -559,16 +555,16 @@ TEST_F(WebDatabaseTest, BlacklistedLogins) {
// Get all non-blacklisted logins (should be none).
EXPECT_TRUE(db.GetAllLogins(&result, false));
- ASSERT_EQ(0, result.size());
+ ASSERT_EQ(0U, result.size());
// GetLogins should give the blacklisted result.
EXPECT_TRUE(db.GetLogins(form, &result));
- EXPECT_EQ(1, result.size());
+ EXPECT_EQ(1U, result.size());
ClearResults(&result);
// So should GetAll including blacklisted.
EXPECT_TRUE(db.GetAllLogins(&result, true));
- EXPECT_EQ(1, result.size());
+ EXPECT_EQ(1U, result.size());
ClearResults(&result);
}
@@ -599,7 +595,7 @@ TEST_F(WebDatabaseTest, WebAppImages) {
// Web app should initially have no images.
std::vector<SkBitmap> images;
ASSERT_TRUE(db.GetWebAppImages(url, &images));
- ASSERT_EQ(0, images.size());
+ ASSERT_EQ(0U, images.size());
// Add an image.
SkBitmap image;
@@ -610,7 +606,7 @@ TEST_F(WebDatabaseTest, WebAppImages) {
// Make sure we get the image back.
ASSERT_TRUE(db.GetWebAppImages(url, &images));
- ASSERT_EQ(1, images.size());
+ ASSERT_EQ(1U, images.size());
ASSERT_EQ(16, images[0].width());
ASSERT_EQ(16, images[0].height());
@@ -623,7 +619,7 @@ TEST_F(WebDatabaseTest, WebAppImages) {
ASSERT_TRUE(db.SetWebAppImage(url, image));
images.clear();
ASSERT_TRUE(db.GetWebAppImages(url, &images));
- ASSERT_EQ(1, images.size());
+ ASSERT_EQ(1U, images.size());
ASSERT_EQ(16, images[0].width());
ASSERT_EQ(16, images[0].height());
images[0].lockPixels();
@@ -642,7 +638,7 @@ TEST_F(WebDatabaseTest, WebAppImages) {
// Make sure we get both images back.
images.clear();
ASSERT_TRUE(db.GetWebAppImages(url, &images));
- ASSERT_EQ(2, images.size());
+ ASSERT_EQ(2U, images.size());
if (images[0].width() == 16) {
ASSERT_EQ(16, images[0].width());
ASSERT_EQ(16, images[0].height());