OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "base/guid.h" | 9 #include "base/guid.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
188 void LoadDatabase(const FilePath::StringType& file); | 188 void LoadDatabase(const FilePath::StringType& file); |
189 | 189 |
190 private: | 190 private: |
191 MessageLoopForUI message_loop_for_ui_; | 191 MessageLoopForUI message_loop_for_ui_; |
192 content::TestBrowserThread ui_thread_; | 192 content::TestBrowserThread ui_thread_; |
193 base::ScopedTempDir temp_dir_; | 193 base::ScopedTempDir temp_dir_; |
194 | 194 |
195 DISALLOW_COPY_AND_ASSIGN(WebDatabaseMigrationTest); | 195 DISALLOW_COPY_AND_ASSIGN(WebDatabaseMigrationTest); |
196 }; | 196 }; |
197 | 197 |
198 const int WebDatabaseMigrationTest::kCurrentTestedVersionNumber = 47; | 198 const int WebDatabaseMigrationTest::kCurrentTestedVersionNumber = 48; |
199 | 199 |
200 void WebDatabaseMigrationTest::LoadDatabase(const FilePath::StringType& file) { | 200 void WebDatabaseMigrationTest::LoadDatabase(const FilePath::StringType& file) { |
201 std::string contents; | 201 std::string contents; |
202 ASSERT_TRUE(GetWebDatabaseData(FilePath(file), &contents)); | 202 ASSERT_TRUE(GetWebDatabaseData(FilePath(file), &contents)); |
203 | 203 |
204 sql::Connection connection; | 204 sql::Connection connection; |
205 ASSERT_TRUE(connection.Open(GetDatabasePath())); | 205 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
206 ASSERT_TRUE(connection.Execute(contents.data())); | 206 ASSERT_TRUE(connection.Execute(contents.data())); |
207 } | 207 } |
208 | 208 |
(...skipping 2096 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2305 // Check version. | 2305 // Check version. |
2306 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); | 2306 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); |
2307 | 2307 |
2308 // A new column should have been created. | 2308 // A new column should have been created. |
2309 EXPECT_TRUE(connection.DoesColumnExist("keywords", "alternate_urls")); | 2309 EXPECT_TRUE(connection.DoesColumnExist("keywords", "alternate_urls")); |
2310 | 2310 |
2311 // The backup table should be gone. | 2311 // The backup table should be gone. |
2312 EXPECT_FALSE(connection.DoesTableExist("keywords_backup")); | 2312 EXPECT_FALSE(connection.DoesTableExist("keywords_backup")); |
2313 } | 2313 } |
2314 } | 2314 } |
2315 | |
2316 #if !defined(GOOGLE_CHROME_BUILD) | |
2317 // Tests that the |search_terms_replacement_key| column is added to the keyword | |
2318 // table schema for a version 48 database. | |
2319 // | |
2320 // This is enabled on Chromium only because a valid signature is required for | |
2321 // this test, which makes it key-dependent. | |
2322 TEST_F(WebDatabaseMigrationTest, MigrateVersion47ToCurrent) { | |
2323 ASSERT_NO_FATAL_FAILURE( | |
2324 LoadDatabase(FILE_PATH_LITERAL("version_47.sql"))); | |
2325 | |
2326 // Verify pre-conditions. These are expectations for version 47 of the | |
2327 // database. | |
2328 { | |
2329 sql::Connection connection; | |
2330 ASSERT_TRUE(connection.Open(GetDatabasePath())); | |
2331 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); | |
2332 | |
2333 sql::MetaTable meta_table; | |
2334 ASSERT_TRUE(meta_table.Init(&connection, 47, 47)); | |
2335 | |
2336 ASSERT_FALSE(connection.DoesColumnExist("keywords", | |
2337 "search_terms_replacement_key")); | |
2338 ASSERT_FALSE(connection.DoesColumnExist("keywords_backup", | |
2339 "search_terms_replacement_key")); | |
2340 } | |
2341 | |
2342 // Load the database via the WebDatabase class and migrate the database to | |
2343 // the current version. | |
2344 { | |
2345 WebDatabase db; | |
2346 ASSERT_EQ(sql::INIT_OK, db.Init(GetDatabasePath())); | |
2347 ASSERT_FALSE(db.GetKeywordTable()->DidDefaultSearchProviderChange()); | |
2348 } | |
2349 | |
2350 // Verify post-conditions. These are expectations for current version of the | |
2351 // database. | |
2352 { | |
2353 sql::Connection connection; | |
2354 ASSERT_TRUE(connection.Open(GetDatabasePath())); | |
2355 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); | |
2356 | |
2357 // Check version. | |
2358 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); | |
2359 | |
2360 // A new column should have been created. | |
2361 EXPECT_TRUE(connection.DoesColumnExist("keywords", | |
2362 "search_terms_replacement_key")); | |
2363 ASSERT_TRUE(connection.DoesColumnExist("keywords_backup", | |
2364 "search_terms_replacement_key")); | |
2365 } | |
2366 } | |
2367 #endif // !defined(GOOGLE_CHROME_BUILD) | |
2368 | |
2369 // Like MigrateVersion47ToCurrent above, but with a corrupt backup signature. | |
2370 // This should result in us dropping the backup table but successfully migrating | |
2371 // otherwise. | |
2372 // | |
2373 // Because this test doesn't rely on a valid signature, we can run it on | |
dhollowa
2012/12/13 01:23:08
nit: This comment looks like a copy/paste error si
beaudoin
2012/12/13 17:14:53
"We _can_ run it on official builds as well." :)
| |
2374 // official builds as well. | |
2375 TEST_F(WebDatabaseMigrationTest, MigrateVersion47CorruptBackupToCurrent) { | |
2376 ASSERT_NO_FATAL_FAILURE( | |
2377 LoadDatabase(FILE_PATH_LITERAL("version_47_backup_corrupt.sql"))); | |
2378 | |
2379 // Verify pre-conditions. These are expectations for version 46 of the | |
2380 // database. | |
2381 { | |
2382 sql::Connection connection; | |
2383 ASSERT_TRUE(connection.Open(GetDatabasePath())); | |
2384 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); | |
2385 | |
2386 sql::MetaTable meta_table; | |
2387 ASSERT_TRUE(meta_table.Init(&connection, 47, 47)); | |
2388 | |
2389 ASSERT_FALSE(connection.DoesColumnExist("keywords", | |
2390 "search_terms_replacement_key")); | |
2391 ASSERT_FALSE(connection.DoesColumnExist("keywords_backup", | |
2392 "search_terms_replacement_key")); | |
2393 } | |
2394 | |
2395 // Load the database via the WebDatabase class and migrate the database to | |
2396 // the current version. | |
2397 { | |
2398 WebDatabase db; | |
2399 ASSERT_EQ(sql::INIT_OK, db.Init(GetDatabasePath())); | |
2400 // We should detect a "search provider change" as a side effect of dropping | |
2401 // the backup table. | |
2402 ASSERT_TRUE(db.GetKeywordTable()->DidDefaultSearchProviderChange()); | |
2403 } | |
2404 | |
2405 // Verify post-conditions. These are expectations for current version of the | |
2406 // database. | |
2407 { | |
2408 sql::Connection connection; | |
2409 ASSERT_TRUE(connection.Open(GetDatabasePath())); | |
2410 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); | |
2411 | |
2412 // Check version. | |
2413 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); | |
2414 | |
2415 // A new column should have been created. | |
2416 EXPECT_TRUE(connection.DoesColumnExist("keywords", | |
2417 "search_terms_replacement_key")); | |
2418 | |
2419 // The backup table should be gone. | |
2420 EXPECT_FALSE(connection.DoesTableExist("keywords_backup")); | |
2421 } | |
2422 } | |
OLD | NEW |