summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-04 19:09:51 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-04 19:09:51 +0000
commita4081efac60ef7562660bb3e00536f87a51b9e53 (patch)
tree3ea47050d502f1f9bf05c5c3abc9c27453eafb14 /chrome
parent581125c6afa5ab170a16ff1d8fd42dae4100a7a5 (diff)
downloadchromium_src-a4081efac60ef7562660bb3e00536f87a51b9e53.zip
chromium_src-a4081efac60ef7562660bb3e00536f87a51b9e53.tar.gz
chromium_src-a4081efac60ef7562660bb3e00536f87a51b9e53.tar.bz2
Makes TemplateURL::supports_instant persisted to the webdb.
BUG=54833 TEST=none Review URL: http://codereview.chromium.org/3560008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@61399 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/search_engines/template_url.cc3
-rw-r--r--chrome/browser/search_engines/template_url.h9
-rw-r--r--chrome/browser/webdata/web_database.cc39
-rw-r--r--chrome/browser/webdata/web_database_unittest.cc122
4 files changed, 160 insertions, 13 deletions
diff --git a/chrome/browser/search_engines/template_url.cc b/chrome/browser/search_engines/template_url.cc
index 015a2f3..923b647 100644
--- a/chrome/browser/search_engines/template_url.cc
+++ b/chrome/browser/search_engines/template_url.cc
@@ -564,7 +564,8 @@ TemplateURL::TemplateURL()
usage_count_(0),
search_engine_type_(TemplateURLPrepopulateData::SEARCH_ENGINE_OTHER),
logo_id_(0),
- prepopulate_id_(0) {
+ prepopulate_id_(0),
+ supports_instant_(false) {
}
TemplateURL::~TemplateURL() {
diff --git a/chrome/browser/search_engines/template_url.h b/chrome/browser/search_engines/template_url.h
index 7a4f12d..b48da25 100644
--- a/chrome/browser/search_engines/template_url.h
+++ b/chrome/browser/search_engines/template_url.h
@@ -297,9 +297,9 @@ class TemplateURL {
}
const std::wstring& short_name() const { return short_name_; }
- // Returns true if this search engine supports showing instant results.
- // TODO(sky): make this real.
- bool supports_instant() const { return false; }
+ // Whether the search engine supports instant.
+ void set_supports_instant(bool value) { supports_instant_ = value; }
+ bool supports_instant() const { return supports_instant_; }
// An accessor for the short_name, but adjusted so it can be appropriately
// displayed even if it is LTR and the UI is RTL.
@@ -506,6 +506,9 @@ class TemplateURL {
int logo_id_;
int prepopulate_id_;
+ // See description above setter.
+ bool supports_instant_;
+
// TODO(sky): Add date last parsed OSD file.
};
diff --git a/chrome/browser/webdata/web_database.cc b/chrome/browser/webdata/web_database.cc
index dccf6d7..205af00 100644
--- a/chrome/browser/webdata/web_database.cc
+++ b/chrome/browser/webdata/web_database.cc
@@ -68,6 +68,8 @@ using webkit_glue::PasswordForm;
// logo_id See TemplateURL::logo_id
// created_by_policy See TemplateURL::created_by_policy. This was added
// in version 26.
+// supports_instant See TemplateURL::supports_instant. This was added
+// in version 28.
//
// logins
// origin_url
@@ -169,9 +171,11 @@ typedef std::vector<Tuple3<int64, string16, string16> > AutofillElementList;
// Current version number. Note: when changing the current version number,
// corresponding changes must happen in the unit tests, and new migration test
// added. See |WebDatabaseMigrationTest::kCurrentTestedVersionNumber|.
-const int kCurrentVersionNumber = 27;
-const int kCompatibleVersionNumber = 27;
-const int kUrlIdPosition = 15;
+const int kCurrentVersionNumber = 28;
+const int kCompatibleVersionNumber = 28;
+
+// ID of the url column in keywords.
+const int kUrlIdPosition = 16;
// Keys used in the meta table.
const char* kDefaultSearchProviderKey = "Default Search Provider ID";
@@ -213,6 +217,7 @@ void BindURLToStatement(const TemplateURL& url, sql::Statement* s) {
s->BindInt(12, url.autogenerate_keyword() ? 1 : 0);
s->BindInt(13, url.logo_id());
s->BindBool(14, url.created_by_policy());
+ s->BindBool(15, url.supports_instant());
}
void InitPasswordFormFromStatement(PasswordForm* form, sql::Statement* s) {
@@ -629,7 +634,8 @@ bool WebDatabase::InitKeywordsTable() {
"prepopulate_id INTEGER DEFAULT 0,"
"autogenerate_keyword INTEGER DEFAULT 0,"
"logo_id INTEGER DEFAULT 0,"
- "created_by_policy INTEGER DEFAULT 0)")) {
+ "created_by_policy INTEGER DEFAULT 0,"
+ "supports_instant INTEGER DEFAULT 0)")) {
NOTREACHED();
return false;
}
@@ -836,8 +842,9 @@ bool WebDatabase::AddKeyword(const TemplateURL& url) {
"(short_name, keyword, favicon_url, url, safe_for_autoreplace, "
"originating_url, date_created, usage_count, input_encodings, "
"show_in_default_list, suggest_url, prepopulate_id, "
- "autogenerate_keyword, logo_id, created_by_policy, id) VALUES "
- "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"));
+ "autogenerate_keyword, logo_id, created_by_policy, supports_instant, "
+ "id) VALUES "
+ "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"));
if (!s) {
NOTREACHED() << "Statement prepare failed";
return false;
@@ -868,7 +875,7 @@ bool WebDatabase::GetKeywords(std::vector<TemplateURL*>* urls) {
"safe_for_autoreplace, originating_url, date_created, "
"usage_count, input_encodings, show_in_default_list, "
"suggest_url, prepopulate_id, autogenerate_keyword, logo_id, "
- "created_by_policy "
+ "created_by_policy, supports_instant "
"FROM keywords ORDER BY id ASC"));
if (!s) {
NOTREACHED() << "Statement prepare failed";
@@ -920,6 +927,8 @@ bool WebDatabase::GetKeywords(std::vector<TemplateURL*>* urls) {
template_url->set_created_by_policy(s.ColumnBool(15));
+ template_url->set_supports_instant(s.ColumnBool(16));
+
urls->push_back(template_url);
}
return s.Succeeded();
@@ -934,7 +943,7 @@ bool WebDatabase::UpdateKeyword(const TemplateURL& url) {
"safe_for_autoreplace=?, originating_url=?, date_created=?, "
"usage_count=?, input_encodings=?, show_in_default_list=?, "
"suggest_url=?, prepopulate_id=?, autogenerate_keyword=?, "
- "logo_id=?, created_by_policy=? WHERE id=?"));
+ "logo_id=?, created_by_policy=?, supports_instant=? WHERE id=?"));
if (!s) {
NOTREACHED() << "Statement prepare failed";
return false;
@@ -2158,6 +2167,20 @@ void WebDatabase::MigrateOldVersionsAsNeeded(){
// FALL THROUGH
}
+ case 27:
+ // Add the created_by_policy column.
+ if (!db_.Execute("ALTER TABLE keywords ADD COLUMN supports_instant "
+ "INTEGER DEFAULT 0")) {
+ NOTREACHED();
+ LOG(WARNING) << "Unable to update web database to version 28.";
+ return;
+ }
+ meta_table_.SetVersionNumber(28);
+ meta_table_.SetCompatibleVersionNumber(
+ std::min(28, kCompatibleVersionNumber));
+
+ // FALL THROUGH
+
// Add successive versions here. Each should set the version number and
// compatible version number as appropriate, then fall through to the next
// case.
diff --git a/chrome/browser/webdata/web_database_unittest.cc b/chrome/browser/webdata/web_database_unittest.cc
index 4bfa827..694e0d2 100644
--- a/chrome/browser/webdata/web_database_unittest.cc
+++ b/chrome/browser/webdata/web_database_unittest.cc
@@ -207,6 +207,7 @@ TEST_F(WebDatabaseTest, Keywords) {
set_prepopulate_id(&template_url, 10);
set_logo_id(&template_url, 1000);
template_url.set_created_by_policy(true);
+ template_url.set_supports_instant(false);
SetID(1, &template_url);
EXPECT_TRUE(db.AddKeyword(template_url));
@@ -248,6 +249,8 @@ TEST_F(WebDatabaseTest, Keywords) {
EXPECT_TRUE(restored_url->created_by_policy());
+ EXPECT_FALSE(template_url.supports_instant());
+
EXPECT_TRUE(db.RemoveKeyword(restored_url->id()));
template_urls.clear();
@@ -288,6 +291,7 @@ TEST_F(WebDatabaseTest, UpdateKeyword) {
template_url.set_safe_for_autoreplace(true);
template_url.set_show_in_default_list(true);
template_url.SetSuggestionsURL("url2", 0, 0);
+ template_url.set_supports_instant(false);
SetID(1, &template_url);
EXPECT_TRUE(db.AddKeyword(template_url));
@@ -299,6 +303,7 @@ TEST_F(WebDatabaseTest, UpdateKeyword) {
template_url.add_input_encoding("Shift_JIS");
set_prepopulate_id(&template_url, 5);
set_logo_id(&template_url, 2000);
+ template_url.set_supports_instant(true);
EXPECT_TRUE(db.UpdateKeyword(template_url));
std::vector<TemplateURL*> template_urls;
@@ -335,6 +340,8 @@ TEST_F(WebDatabaseTest, UpdateKeyword) {
EXPECT_EQ(template_url.logo_id(), restored_url->logo_id());
+ EXPECT_TRUE(template_url.supports_instant());
+
delete restored_url;
}
@@ -1573,6 +1580,7 @@ class WebDatabaseMigrationTest : public testing::Test {
void SetUpVersion24Database();
void SetUpVersion25Database();
void SetUpVersion26Database();
+ void SetUpVersion27Database();
private:
ScopedTempDir temp_dir_;
@@ -1580,7 +1588,7 @@ class WebDatabaseMigrationTest : public testing::Test {
DISALLOW_COPY_AND_ASSIGN(WebDatabaseMigrationTest);
};
-const int WebDatabaseMigrationTest::kCurrentTestedVersionNumber = 27;
+const int WebDatabaseMigrationTest::kCurrentTestedVersionNumber = 28;
// This schema is taken from a build prior to the addition of the |credit_card|
// table. Version 22 of the schema. Contrast this with the corrupt version
@@ -1930,6 +1938,77 @@ void WebDatabaseMigrationTest::SetUpVersion26Database() {
ASSERT_TRUE(connection.CommitTransaction());
}
+void WebDatabaseMigrationTest::SetUpVersion27Database() {
+ sql::Connection connection;
+ ASSERT_TRUE(connection.Open(GetDatabasePath()));
+ ASSERT_TRUE(connection.BeginTransaction());
+ ASSERT_TRUE(connection.Execute(
+ "CREATE TABLE meta(key LONGVARCHAR NOT NULL UNIQUE PRIMARY "
+ "KEY,value LONGVARCHAR);"
+ "INSERT INTO \"meta\" VALUES('version','27');"
+ "INSERT INTO \"meta\" VALUES('last_compatible_version','27');"
+ "INSERT INTO \"meta\" VALUES('Default Search Provider ID','2');"
+ "INSERT INTO \"meta\" VALUES('Builtin Keyword Version','29');"
+ "CREATE TABLE keywords (id INTEGER PRIMARY KEY,short_name VARCHAR "
+ "NOT NULL,keyword VARCHAR NOT NULL,favicon_url VARCHAR NOT "
+ "NULL,url VARCHAR NOT NULL,show_in_default_list "
+ "INTEGER,safe_for_autoreplace INTEGER,originating_url "
+ "VARCHAR,date_created INTEGER DEFAULT 0,usage_count INTEGER "
+ "DEFAULT 0,input_encodings VARCHAR,suggest_url "
+ "VARCHAR,prepopulate_id INTEGER DEFAULT 0,autogenerate_keyword "
+ "INTEGER DEFAULT 0,logo_id INTEGER DEFAULT 0,created_by_policy "
+ "INTEGER DEFAULT 0);"
+ "INSERT INTO \"keywords\" "
+ "VALUES(2,'Google','google.com','http://www.google.com/favicon.ico',"
+ "'{google:baseURL}search?{google:RLZ}{google:acceptedSuggestion}"
+ "{google:originalQueryForSuggestion}sourceid=chrome&ie={inputEncoding}"
+ "&q={searchTerms}',1,1,'',0,0,'UTF-8',"
+ "'{google:baseSuggestURL}search?client=chrome&hl={language}"
+ "&q={searchTerms}',1,1,6245,0);"
+ "CREATE TABLE logins (origin_url VARCHAR NOT NULL, action_url "
+ "VARCHAR, username_element VARCHAR, username_value VARCHAR, "
+ "password_element VARCHAR, password_value BLOB, submit_element "
+ "VARCHAR, signon_realm VARCHAR NOT NULL,ssl_valid INTEGER NOT "
+ "NULL,preferred INTEGER NOT NULL,date_created INTEGER NOT "
+ "NULL,blacklisted_by_user INTEGER NOT NULL,scheme INTEGER NOT "
+ "NULL,UNIQUE (origin_url, username_element, username_value, "
+ "password_element, submit_element, signon_realm));"
+ "CREATE TABLE ie7_logins (url_hash VARCHAR NOT NULL, "
+ "password_value BLOB, date_created INTEGER NOT NULL,UNIQUE "
+ "(url_hash));"
+ "CREATE TABLE web_app_icons (url LONGVARCHAR,width int,height "
+ "int,image BLOB, UNIQUE (url, width, height));"
+ "CREATE TABLE web_apps (url LONGVARCHAR UNIQUE,has_all_images "
+ "INTEGER NOT NULL);"
+ "CREATE TABLE autofill (name VARCHAR, value VARCHAR, value_lower "
+ "VARCHAR, pair_id INTEGER PRIMARY KEY, count INTEGER DEFAULT "
+ "1);"
+ "CREATE TABLE autofill_dates ( pair_id INTEGER DEFAULT 0, "
+ "date_created INTEGER DEFAULT 0);"
+ "CREATE TABLE autofill_profiles ( label VARCHAR, unique_id INTEGER "
+ "PRIMARY KEY, first_name VARCHAR, middle_name VARCHAR, last_name "
+ "VARCHAR, email VARCHAR, company_name VARCHAR, address_line_1 "
+ "VARCHAR, address_line_2 VARCHAR, city VARCHAR, state VARCHAR, "
+ "zipcode VARCHAR, country VARCHAR, phone VARCHAR, fax VARCHAR);"
+ "CREATE TABLE credit_cards ( label VARCHAR, unique_id INTEGER "
+ "PRIMARY KEY, name_on_card VARCHAR, type VARCHAR, card_number "
+ "VARCHAR, expiration_month INTEGER, expiration_year INTEGER, "
+ "verification_code VARCHAR, billing_address VARCHAR, "
+ "shipping_address VARCHAR, card_number_encrypted BLOB, "
+ "verification_code_encrypted BLOB);"
+ "CREATE TABLE token_service (service VARCHAR PRIMARY KEY NOT "
+ "NULL,encrypted_token BLOB);"
+ "CREATE INDEX logins_signon ON logins (signon_realm);"
+ "CREATE INDEX ie7_logins_hash ON ie7_logins (url_hash);"
+ "CREATE INDEX web_apps_url_index ON web_apps (url);"
+ "CREATE INDEX autofill_name ON autofill (name);"
+ "CREATE INDEX autofill_name_value_lower ON autofill (name, value_lower);"
+ "CREATE INDEX autofill_dates_pair_id ON autofill_dates (pair_id);"
+ "CREATE INDEX autofill_profiles_label_index ON autofill_profiles (label);"
+ "CREATE INDEX credit_cards_label_index ON credit_cards (label);"));
+ ASSERT_TRUE(connection.CommitTransaction());
+}
+
// Tests that the all migrations from an empty database succeed.
TEST_F(WebDatabaseMigrationTest, MigrateEmptyToCurrent) {
// Load the database via the WebDatabase class and migrate the database to
@@ -2280,3 +2359,44 @@ TEST_F(WebDatabaseMigrationTest, MigrateVersion26ToCurrentStringIDs) {
// The remaining columns are unused or blobs.
}
}
+
+// Tests that the column supports_instant is correctly added to keywords.
+TEST_F(WebDatabaseMigrationTest, MigrateVersion27ToCurrent) {
+ // Initialize the database.
+ SetUpVersion27Database();
+
+ // Verify pre-conditions. These are expectations for version 27 of the
+ // database.
+ {
+ sql::Connection connection;
+ ASSERT_TRUE(connection.Open(GetDatabasePath()));
+
+ // supports_instant is new to 28, make sure it isn't in 27.
+ ASSERT_FALSE(connection.DoesColumnExist("keywords", "supports_instant"));
+ }
+
+ // Load the database via the WebDatabase class and migrate the database to
+ // the current version.
+ {
+ WebDatabase db;
+ ASSERT_EQ(sql::INIT_OK, db.Init(GetDatabasePath()));
+ }
+
+ // Verify post-conditions. These are expectations for current version of the
+ // database.
+ {
+ sql::Connection connection;
+ ASSERT_TRUE(connection.Open(GetDatabasePath()));
+
+ // Check version.
+ EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
+ EXPECT_TRUE(connection.DoesColumnExist("keywords", "supports_instant"));
+
+ // Check that supports_instant gets set to false.
+ std::string stmt = "SELECT supports_instant FROM keywords";
+ sql::Statement s(connection.GetUniqueStatement(stmt.c_str()));
+ ASSERT_TRUE(s.Step());
+ EXPECT_EQ(s.ColumnType(0), sql::COLUMN_TYPE_INTEGER);
+ EXPECT_FALSE(s.ColumnBool(0));
+ }
+}