| 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" |
| 11 #include "base/path_service.h" | |
| 12 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 13 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
| 14 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 17 #include "base/values.h" | 16 #include "base/values.h" |
| 18 #include "chrome/browser/webdata/keyword_table.h" | 17 #include "chrome/browser/webdata/keyword_table.h" |
| 19 #include "chrome/browser/webdata/logins_table.h" | 18 #include "chrome/browser/webdata/logins_table.h" |
| 20 #include "chrome/browser/webdata/token_service_table.h" | 19 #include "chrome/browser/webdata/token_service_table.h" |
| 21 #include "chrome/browser/webdata/web_apps_table.h" | 20 #include "chrome/browser/webdata/web_apps_table.h" |
| 22 #include "chrome/browser/webdata/web_intents_table.h" | 21 #include "chrome/browser/webdata/web_intents_table.h" |
| 22 #include "chrome/test/base/ui_test_utils.h" |
| 23 #include "components/autofill/core/browser/autofill_country.h" | 23 #include "components/autofill/core/browser/autofill_country.h" |
| 24 #include "components/autofill/core/browser/autofill_profile.h" | 24 #include "components/autofill/core/browser/autofill_profile.h" |
| 25 #include "components/autofill/core/browser/autofill_type.h" | 25 #include "components/autofill/core/browser/autofill_type.h" |
| 26 #include "components/autofill/core/browser/credit_card.h" | 26 #include "components/autofill/core/browser/credit_card.h" |
| 27 #include "components/autofill/core/browser/webdata/autofill_change.h" | 27 #include "components/autofill/core/browser/webdata/autofill_change.h" |
| 28 #include "components/autofill/core/browser/webdata/autofill_entry.h" | 28 #include "components/autofill/core/browser/webdata/autofill_entry.h" |
| 29 #include "components/autofill/core/browser/webdata/autofill_table.h" | 29 #include "components/autofill/core/browser/webdata/autofill_table.h" |
| 30 #include "components/webdata/common/web_database.h" | 30 #include "components/webdata/common/web_database.h" |
| 31 #include "sql/statement.h" | 31 #include "sql/statement.h" |
| 32 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 // number and a new migration test added below. | 200 // number and a new migration test added below. |
| 201 static const int kCurrentTestedVersionNumber; | 201 static const int kCurrentTestedVersionNumber; |
| 202 | 202 |
| 203 base::FilePath GetDatabasePath() { | 203 base::FilePath GetDatabasePath() { |
| 204 const base::FilePath::CharType kWebDatabaseFilename[] = | 204 const base::FilePath::CharType kWebDatabaseFilename[] = |
| 205 FILE_PATH_LITERAL("TestWebDatabase.sqlite3"); | 205 FILE_PATH_LITERAL("TestWebDatabase.sqlite3"); |
| 206 return temp_dir_.path().Append(base::FilePath(kWebDatabaseFilename)); | 206 return temp_dir_.path().Append(base::FilePath(kWebDatabaseFilename)); |
| 207 } | 207 } |
| 208 | 208 |
| 209 // The textual contents of |file| are read from | 209 // The textual contents of |file| are read from |
| 210 // "components/test/data/web_database" and returned in the string |contents|. | 210 // "chrome/test/data/web_database" and returned in the string |contents|. |
| 211 // Returns true if the file exists and is read successfully, false otherwise. | 211 // Returns true if the file exists and is read successfully, false otherwise. |
| 212 bool GetWebDatabaseData(const base::FilePath& file, std::string* contents) { | 212 bool GetWebDatabaseData(const base::FilePath& file, std::string* contents) { |
| 213 base::FilePath source_path; | 213 base::FilePath path = ui_test_utils::GetTestFilePath( |
| 214 PathService::Get(base::DIR_SOURCE_ROOT, &source_path); | 214 base::FilePath(FILE_PATH_LITERAL("web_database")), file); |
| 215 source_path = source_path.AppendASCII("components"); | 215 return file_util::PathExists(path) && |
| 216 source_path = source_path.AppendASCII("test"); | 216 file_util::ReadFileToString(path, contents); |
| 217 source_path = source_path.AppendASCII("data"); | |
| 218 source_path = source_path.AppendASCII("web_database"); | |
| 219 source_path = source_path.Append(file); | |
| 220 return file_util::PathExists(source_path) && | |
| 221 file_util::ReadFileToString(source_path, contents); | |
| 222 } | 217 } |
| 223 | 218 |
| 224 static int VersionFromConnection(sql::Connection* connection) { | 219 static int VersionFromConnection(sql::Connection* connection) { |
| 225 // Get version. | 220 // Get version. |
| 226 sql::Statement s(connection->GetUniqueStatement( | 221 sql::Statement s(connection->GetUniqueStatement( |
| 227 "SELECT value FROM meta WHERE key='version'")); | 222 "SELECT value FROM meta WHERE key='version'")); |
| 228 if (!s.Step()) | 223 if (!s.Step()) |
| 229 return 0; | 224 return 0; |
| 230 return s.ColumnInt(0); | 225 return s.ColumnInt(0); |
| 231 } | 226 } |
| (...skipping 1786 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2018 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); | 2013 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); |
| 2019 | 2014 |
| 2020 // Check version. | 2015 // Check version. |
| 2021 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); | 2016 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); |
| 2022 | 2017 |
| 2023 // A new column should have been created in both tables. | 2018 // A new column should have been created in both tables. |
| 2024 EXPECT_TRUE(connection.DoesColumnExist("autofill_profiles", "origin")); | 2019 EXPECT_TRUE(connection.DoesColumnExist("autofill_profiles", "origin")); |
| 2025 EXPECT_TRUE(connection.DoesColumnExist("credit_cards", "origin")); | 2020 EXPECT_TRUE(connection.DoesColumnExist("credit_cards", "origin")); |
| 2026 } | 2021 } |
| 2027 } | 2022 } |
| OLD | NEW |