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 "base/files/scoped_temp_dir.h" | 5 #include "base/files/scoped_temp_dir.h" |
6 #include "base/format_macros.h" | 6 #include "base/format_macros.h" |
7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
11 #include "chrome/browser/history/shortcuts_database.h" | 11 #include "chrome/browser/history/shortcuts_database.h" |
12 #include "chrome/common/chrome_constants.h" | 12 #include "chrome/common/chrome_constants.h" |
13 #include "chrome/common/chrome_paths.h" | 13 #include "chrome/common/chrome_paths.h" |
14 #include "chrome/test/base/testing_profile.h" | 14 #include "chrome/test/base/testing_profile.h" |
15 #include "components/omnibox/autocomplete_match_type.h" | 15 #include "components/omnibox/autocomplete_match_type.h" |
16 #include "content/public/common/page_transition_types.h" | |
17 #include "sql/statement.h" | 16 #include "sql/statement.h" |
18 #include "sql/test/test_helpers.h" | 17 #include "sql/test/test_helpers.h" |
19 | |
20 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #include "ui/base/page_transition_types.h" |
21 | 20 |
22 using base::ASCIIToUTF16; | 21 using base::ASCIIToUTF16; |
23 | 22 |
24 // Helpers -------------------------------------------------------------------- | 23 // Helpers -------------------------------------------------------------------- |
25 | 24 |
26 namespace { | 25 namespace { |
27 | 26 |
28 struct ShortcutsDatabaseTestInfo { | 27 struct ShortcutsDatabaseTestInfo { |
29 std::string guid; | 28 std::string guid; |
30 std::string text; | 29 std::string text; |
31 std::string fill_into_edit; | 30 std::string fill_into_edit; |
32 std::string destination_url; | 31 std::string destination_url; |
33 std::string contents; | 32 std::string contents; |
34 std::string contents_class; | 33 std::string contents_class; |
35 std::string description; | 34 std::string description; |
36 std::string description_class; | 35 std::string description_class; |
37 content::PageTransition transition; | 36 ui::PageTransition transition; |
38 AutocompleteMatchType::Type type; | 37 AutocompleteMatchType::Type type; |
39 std::string keyword; | 38 std::string keyword; |
40 int days_from_now; | 39 int days_from_now; |
41 int number_of_hits; | 40 int number_of_hits; |
42 } shortcut_test_db[] = { | 41 } shortcut_test_db[] = { |
43 { "BD85DBA2-8C29-49F9-84AE-48E1E90880DF", "goog", "www.google.com", | 42 { "BD85DBA2-8C29-49F9-84AE-48E1E90880DF", "goog", "www.google.com", |
44 "http://www.google.com/", "Google", "0,1,4,0", "Google", "0,1", | 43 "http://www.google.com/", "Google", "0,1,4,0", "Google", "0,1", |
45 content::PAGE_TRANSITION_GENERATED, AutocompleteMatchType::SEARCH_HISTORY, | 44 ui::PAGE_TRANSITION_GENERATED, AutocompleteMatchType::SEARCH_HISTORY, |
46 "google.com", 1, 100, }, | 45 "google.com", 1, 100, }, |
47 { "BD85DBA2-8C29-49F9-84AE-48E1E90880E0", "slash", "slashdot.org", | 46 { "BD85DBA2-8C29-49F9-84AE-48E1E90880E0", "slash", "slashdot.org", |
48 "http://slashdot.org/", "slashdot.org", "0,1", | 47 "http://slashdot.org/", "slashdot.org", "0,1", |
49 "Slashdot - News for nerds, stuff that matters", "0,0", | 48 "Slashdot - News for nerds, stuff that matters", "0,0", |
50 content::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "", 0, | 49 ui::PAGE_TRANSITION_TYPED, AutocompleteMatchType::HISTORY_URL, "", 0, |
51 100}, | 50 100}, |
52 { "BD85DBA2-8C29-49F9-84AE-48E1E90880E1", "news", "slashdot.org", | 51 { "BD85DBA2-8C29-49F9-84AE-48E1E90880E1", "news", "slashdot.org", |
53 "http://slashdot.org/", "slashdot.org", "0,1", | 52 "http://slashdot.org/", "slashdot.org", "0,1", |
54 "Slashdot - News for nerds, stuff that matters", "0,0", | 53 "Slashdot - News for nerds, stuff that matters", "0,0", |
55 content::PAGE_TRANSITION_LINK, AutocompleteMatchType::HISTORY_TITLE, "", 0, | 54 ui::PAGE_TRANSITION_LINK, AutocompleteMatchType::HISTORY_TITLE, "", 0, |
56 5}, | 55 5}, |
57 }; | 56 }; |
58 | 57 |
59 typedef testing::Test ShortcutsDatabaseMigrationTest; | 58 typedef testing::Test ShortcutsDatabaseMigrationTest; |
60 | 59 |
61 // Checks that the database at |db| has the version 2 columns iff |is_v2|. | 60 // Checks that the database at |db| has the version 2 columns iff |is_v2|. |
62 void CheckV2ColumnExistence(const base::FilePath& db_path, bool is_v2) { | 61 void CheckV2ColumnExistence(const base::FilePath& db_path, bool is_v2) { |
63 sql::Connection connection; | 62 sql::Connection connection; |
64 ASSERT_TRUE(connection.Open(db_path)); | 63 ASSERT_TRUE(connection.Open(db_path)); |
65 EXPECT_EQ(is_v2, connection.DoesColumnExist("omni_box_shortcuts", | 64 EXPECT_EQ(is_v2, connection.DoesColumnExist("omni_box_shortcuts", |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 ASSERT_TRUE(connection.Open(db_path)); | 250 ASSERT_TRUE(connection.Open(db_path)); |
252 sql::Statement statement(connection.GetUniqueStatement( | 251 sql::Statement statement(connection.GetUniqueStatement( |
253 "SELECT fill_into_edit, url, transition, type, keyword " | 252 "SELECT fill_into_edit, url, transition, type, keyword " |
254 "FROM omni_box_shortcuts")); | 253 "FROM omni_box_shortcuts")); |
255 ASSERT_TRUE(statement.is_valid()); | 254 ASSERT_TRUE(statement.is_valid()); |
256 while (statement.Step()) { | 255 while (statement.Step()) { |
257 // |fill_into_edit| should have been copied from the |url|. | 256 // |fill_into_edit| should have been copied from the |url|. |
258 EXPECT_EQ(statement.ColumnString(1), statement.ColumnString(0)); | 257 EXPECT_EQ(statement.ColumnString(1), statement.ColumnString(0)); |
259 | 258 |
260 // The other three columns have default values. | 259 // The other three columns have default values. |
261 EXPECT_EQ(content::PAGE_TRANSITION_TYPED, | 260 EXPECT_EQ(ui::PAGE_TRANSITION_TYPED, |
262 static_cast<content::PageTransition>(statement.ColumnInt(2))); | 261 ui::PageTransitionFromInt(statement.ColumnInt(2))); |
263 EXPECT_EQ(AutocompleteMatchType::HISTORY_TITLE, | 262 EXPECT_EQ(AutocompleteMatchType::HISTORY_TITLE, |
264 static_cast<AutocompleteMatchType::Type>(statement.ColumnInt(3))); | 263 static_cast<AutocompleteMatchType::Type>(statement.ColumnInt(3))); |
265 EXPECT_TRUE(statement.ColumnString(4).empty()); | 264 EXPECT_TRUE(statement.ColumnString(4).empty()); |
266 } | 265 } |
267 EXPECT_TRUE(statement.Succeeded()); | 266 EXPECT_TRUE(statement.Succeeded()); |
268 #if !defined(OS_WIN) | 267 #if !defined(OS_WIN) |
269 EXPECT_TRUE(temp_dir.Delete()); | 268 EXPECT_TRUE(temp_dir.Delete()); |
270 #endif | 269 #endif |
271 } | 270 } |
272 | 271 |
(...skipping 22 matching lines...) Expand all Loading... |
295 ASSERT_TRUE(statement.is_valid()); | 294 ASSERT_TRUE(statement.is_valid()); |
296 while (statement.Step()) | 295 while (statement.Step()) |
297 EXPECT_EQ(0, statement.ColumnInt(0)); | 296 EXPECT_EQ(0, statement.ColumnInt(0)); |
298 EXPECT_TRUE(statement.Succeeded()); | 297 EXPECT_TRUE(statement.Succeeded()); |
299 #if !defined(OS_WIN) | 298 #if !defined(OS_WIN) |
300 EXPECT_TRUE(temp_dir.Delete()); | 299 EXPECT_TRUE(temp_dir.Delete()); |
301 #endif | 300 #endif |
302 } | 301 } |
303 | 302 |
304 } // namespace history | 303 } // namespace history |
OLD | NEW |