Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(840)

Side by Side Diff: components/webdata/common/web_database_migration_unittest.cc

Issue 212873003: Store the language code for the address in autofill profile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments. Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 // > .output version_nn.sql 241 // > .output version_nn.sql
242 // > .dump 242 // > .dump
243 void LoadDatabase(const base::FilePath::StringType& file); 243 void LoadDatabase(const base::FilePath::StringType& file);
244 244
245 private: 245 private:
246 base::ScopedTempDir temp_dir_; 246 base::ScopedTempDir temp_dir_;
247 247
248 DISALLOW_COPY_AND_ASSIGN(WebDatabaseMigrationTest); 248 DISALLOW_COPY_AND_ASSIGN(WebDatabaseMigrationTest);
249 }; 249 };
250 250
251 const int WebDatabaseMigrationTest::kCurrentTestedVersionNumber = 55; 251 const int WebDatabaseMigrationTest::kCurrentTestedVersionNumber = 56;
252 252
253 void WebDatabaseMigrationTest::LoadDatabase( 253 void WebDatabaseMigrationTest::LoadDatabase(
254 const base::FilePath::StringType& file) { 254 const base::FilePath::StringType& file) {
255 std::string contents; 255 std::string contents;
256 ASSERT_TRUE(GetWebDatabaseData(base::FilePath(file), &contents)); 256 ASSERT_TRUE(GetWebDatabaseData(base::FilePath(file), &contents));
257 257
258 sql::Connection connection; 258 sql::Connection connection;
259 ASSERT_TRUE(connection.Open(GetDatabasePath())); 259 ASSERT_TRUE(connection.Open(GetDatabasePath()));
260 ASSERT_TRUE(connection.Execute(contents.data())); 260 ASSERT_TRUE(connection.Execute(contents.data()));
261 } 261 }
(...skipping 2311 matching lines...) Expand 10 before | Expand all | Expand 10 after
2573 EXPECT_EQ(ASCIIToUTF16("john doe"), s.ColumnString16(1)); 2573 EXPECT_EQ(ASCIIToUTF16("john doe"), s.ColumnString16(1));
2574 EXPECT_EQ(ASCIIToUTF16("john doe"), s.ColumnString16(2)); 2574 EXPECT_EQ(ASCIIToUTF16("john doe"), s.ColumnString16(2));
2575 EXPECT_EQ(1384299200, s.ColumnInt64(3)); 2575 EXPECT_EQ(1384299200, s.ColumnInt64(3));
2576 EXPECT_EQ(1384299200, s.ColumnInt64(4)); 2576 EXPECT_EQ(1384299200, s.ColumnInt64(4));
2577 EXPECT_EQ(1, s.ColumnInt(5)); 2577 EXPECT_EQ(1, s.ColumnInt(5));
2578 2578
2579 // No more entries expected. 2579 // No more entries expected.
2580 ASSERT_FALSE(s.Step()); 2580 ASSERT_FALSE(s.Step());
2581 } 2581 }
2582 } 2582 }
2583
2584 // Tests that migrating from version 55 to version 56 adds the language_code
2585 // column to autofill_profiles table.
2586 TEST_F(WebDatabaseMigrationTest, MigrateVersion55ToCurrent) {
2587 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_55.sql")));
2588
2589 // Verify pre-conditions. These are expectations for version 55 of the
2590 // database.
2591 {
2592 sql::Connection connection;
2593 ASSERT_TRUE(connection.Open(GetDatabasePath()));
2594 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
2595
2596 EXPECT_FALSE(
2597 connection.DoesColumnExist("autofill_profiles", "language_code"));
2598 }
2599
2600 DoMigration();
2601
2602 // Verify post-conditions. These are expectations for current version of the
2603 // database.
2604 {
2605 sql::Connection connection;
2606 ASSERT_TRUE(connection.Open(GetDatabasePath()));
2607 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
2608
2609 // Check version.
2610 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
2611
2612 // The language_code column should have been added to autofill_profiles
2613 // table.
2614 EXPECT_TRUE(
2615 connection.DoesColumnExist("autofill_profiles", "language_code"));
2616
2617 // Data should have been preserved. Language code should have been set to
2618 // empty string.
2619 sql::Statement s_profiles(
2620 connection.GetUniqueStatement(
2621 "SELECT guid, company_name, street_address, dependent_locality,"
2622 " city, state, zipcode, sorting_code, country_code, language_code,"
2623 " date_modified, origin "
2624 "FROM autofill_profiles"));
2625
2626 ASSERT_TRUE(s_profiles.Step());
2627 EXPECT_EQ("00000000-0000-0000-0000-000000000001",
2628 s_profiles.ColumnString(0));
2629 EXPECT_EQ(ASCIIToUTF16("Google Inc"), s_profiles.ColumnString16(1));
2630 EXPECT_EQ(ASCIIToUTF16("340 Main St"),
2631 s_profiles.ColumnString16(2));
2632 EXPECT_EQ(base::string16(), s_profiles.ColumnString16(3));
2633 EXPECT_EQ(ASCIIToUTF16("Los Angeles"), s_profiles.ColumnString16(4));
2634 EXPECT_EQ(ASCIIToUTF16("CA"), s_profiles.ColumnString16(5));
2635 EXPECT_EQ(ASCIIToUTF16("90291"), s_profiles.ColumnString16(6));
2636 EXPECT_EQ(base::string16(), s_profiles.ColumnString16(7));
2637 EXPECT_EQ(ASCIIToUTF16("US"), s_profiles.ColumnString16(8));
2638 EXPECT_EQ(base::string16(), s_profiles.ColumnString16(9));
Ilya Sherman 2014/03/29 01:24:42 Is the datatype string16 or std::string?
please use gerrit instead 2014/04/02 21:54:52 std::string. Fixed.
2639 EXPECT_EQ(1395948829, s_profiles.ColumnInt(10));
2640 EXPECT_EQ(ASCIIToUTF16("Chrome settings"), s_profiles.ColumnString16(11));
2641
2642 // No more entries expected.
2643 ASSERT_FALSE(s_profiles.Step());
2644 }
2645 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698