diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-14 15:57:25 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-14 15:57:25 +0000 |
commit | 43937670bc7772a2ad7e0971618169f51e7b440e (patch) | |
tree | e6c4044afa0873e8227f00e44cbec07cd6a13bd3 /chrome/browser/webdata/web_database_unittest.cc | |
parent | 60ff412b9c2794838d8bc2be149ea81cd000cc2f (diff) | |
download | chromium_src-43937670bc7772a2ad7e0971618169f51e7b440e.zip chromium_src-43937670bc7772a2ad7e0971618169f51e7b440e.tar.gz chromium_src-43937670bc7772a2ad7e0971618169f51e7b440e.tar.bz2 |
Adds support for a separate url for instant results.
BUG=58756
TEST=none
Review URL: http://codereview.chromium.org/3818001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@62558 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/webdata/web_database_unittest.cc')
-rw-r--r-- | chrome/browser/webdata/web_database_unittest.cc | 179 |
1 files changed, 152 insertions, 27 deletions
diff --git a/chrome/browser/webdata/web_database_unittest.cc b/chrome/browser/webdata/web_database_unittest.cc index 694e0d2..6132ad5 100644 --- a/chrome/browser/webdata/web_database_unittest.cc +++ b/chrome/browser/webdata/web_database_unittest.cc @@ -207,7 +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); + template_url.SetInstantURL("http://instant/", 0, 0); SetID(1, &template_url); EXPECT_TRUE(db.AddKeyword(template_url)); @@ -249,7 +249,8 @@ TEST_F(WebDatabaseTest, Keywords) { EXPECT_TRUE(restored_url->created_by_policy()); - EXPECT_FALSE(template_url.supports_instant()); + ASSERT_TRUE(restored_url->instant_url()); + EXPECT_EQ("http://instant/", restored_url->instant_url()->url()); EXPECT_TRUE(db.RemoveKeyword(restored_url->id())); @@ -291,7 +292,6 @@ 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)); @@ -303,7 +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); + template_url.SetInstantURL("http://instant2/", 0, 0); EXPECT_TRUE(db.UpdateKeyword(template_url)); std::vector<TemplateURL*> template_urls; @@ -340,7 +340,9 @@ TEST_F(WebDatabaseTest, UpdateKeyword) { EXPECT_EQ(template_url.logo_id(), restored_url->logo_id()); - EXPECT_TRUE(template_url.supports_instant()); + EXPECT_TRUE(restored_url->instant_url()); + EXPECT_EQ(template_url.instant_url()->url(), + restored_url->instant_url()->url()); delete restored_url; } @@ -1581,6 +1583,10 @@ class WebDatabaseMigrationTest : public testing::Test { void SetUpVersion25Database(); void SetUpVersion26Database(); void SetUpVersion27Database(); + void SetUpVersion28Database(); + + // Assertion testing for migrating from version 27 and 28. + void MigrateVersion28Assertions(); private: ScopedTempDir temp_dir_; @@ -1588,7 +1594,7 @@ class WebDatabaseMigrationTest : public testing::Test { DISALLOW_COPY_AND_ASSIGN(WebDatabaseMigrationTest); }; -const int WebDatabaseMigrationTest::kCurrentTestedVersionNumber = 28; +const int WebDatabaseMigrationTest::kCurrentTestedVersionNumber = 29; // 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 @@ -2009,6 +2015,131 @@ void WebDatabaseMigrationTest::SetUpVersion27Database() { ASSERT_TRUE(connection.CommitTransaction()); } +void WebDatabaseMigrationTest::SetUpVersion28Database() { + 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','28');" + "INSERT INTO \"meta\" VALUES('last_compatible_version','28');" + "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,supports_instant 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,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()); +} + +void WebDatabaseMigrationTest::MigrateVersion28Assertions() { + // 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)); + + // Make sure supports_instant was dropped and instant_url was added. + EXPECT_FALSE(connection.DoesColumnExist("keywords", "supports_instant")); + EXPECT_TRUE(connection.DoesColumnExist("keywords", "instant_url")); + + // Check that instant_url is empty. + std::string stmt = "SELECT instant_url FROM keywords"; + sql::Statement s(connection.GetUniqueStatement(stmt.c_str())); + ASSERT_TRUE(s.Step()); + EXPECT_EQ(std::string(), s.ColumnString(0)); + + // Verify the data made it over. + stmt = "SELECT id, short_name, keyword, favicon_url, url, " + "show_in_default_list, safe_for_autoreplace, originating_url, " + "date_created, usage_count, input_encodings, suggest_url, " + "prepopulate_id, autogenerate_keyword, logo_id, created_by_policy, " + "instant_url FROM keywords"; + sql::Statement s2(connection.GetUniqueStatement(stmt.c_str())); + ASSERT_TRUE(s2.Step()); + EXPECT_EQ(2, s2.ColumnInt(0)); + EXPECT_EQ("Google", s2.ColumnString(1)); + EXPECT_EQ("google.com", s2.ColumnString(2)); + EXPECT_EQ("http://www.google.com/favicon.ico", s2.ColumnString(3)); + EXPECT_EQ("{google:baseURL}search?{google:RLZ}{google:acceptedSuggestion}"\ + "{google:originalQueryForSuggestion}sourceid=chrome&ie={inputEncoding}"\ + "&q={searchTerms}", + s2.ColumnString(4)); + EXPECT_EQ(1, s2.ColumnInt(5)); + EXPECT_EQ(1, s2.ColumnInt(6)); + EXPECT_EQ(std::string(), s2.ColumnString(7)); + EXPECT_EQ(0, s2.ColumnInt(8)); + EXPECT_EQ(0, s2.ColumnInt(9)); + EXPECT_EQ(std::string("UTF-8"), s2.ColumnString(10)); + EXPECT_EQ(std::string("{google:baseSuggestURL}search?client=chrome&hl=" + "{language}&q={searchTerms}"), s2.ColumnString(11)); + EXPECT_EQ(1, s2.ColumnInt(12)); + EXPECT_EQ(1, s2.ColumnInt(13)); + EXPECT_EQ(6245, s2.ColumnInt(14)); + EXPECT_EQ(0, s2.ColumnInt(15)); + EXPECT_EQ(0, s2.ColumnInt(16)); + EXPECT_EQ(std::string(), s2.ColumnString(17)); + } +} + // 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 @@ -2360,43 +2491,37 @@ TEST_F(WebDatabaseMigrationTest, MigrateVersion26ToCurrentStringIDs) { } } -// Tests that the column supports_instant is correctly added to keywords. +// Tests migration from 27->current. This test is now the same as 28->current +// as the column added in 28 was nuked in 29. TEST_F(WebDatabaseMigrationTest, MigrateVersion27ToCurrent) { - // Initialize the database. SetUpVersion27Database(); - // Verify pre-conditions. These are expectations for version 27 of the + // Verify pre-conditions. These are expectations for version 28 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")); + ASSERT_FALSE(connection.DoesColumnExist("keywords", "instant_url")); } - // 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())); - } + MigrateVersion28Assertions(); +} - // Verify post-conditions. These are expectations for current version of the +// Makes sure instant_url is added correctly to keywords. +TEST_F(WebDatabaseMigrationTest, MigrateVersion28ToCurrent) { + SetUpVersion28Database(); + + // Verify pre-conditions. These are expectations for version 28 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)); + ASSERT_TRUE(connection.DoesColumnExist("keywords", "supports_instant")); + ASSERT_FALSE(connection.DoesColumnExist("keywords", "instant_url")); } + + MigrateVersion28Assertions(); } |