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

Side by Side Diff: components/history/core/browser/url_database_unittest.cc

Issue 2721713002: [sync] Add typed url sync metadata to the history db (Closed)
Patch Set: update for comments Created 3 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/file_path.h" 5 #include "base/files/file_path.h"
6 #include "base/files/scoped_temp_dir.h" 6 #include "base/files/scoped_temp_dir.h"
7 #include "base/strings/string_util.h" 7 #include "base/strings/string_util.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "components/history/core/browser/keyword_search_term.h" 9 #include "components/history/core/browser/keyword_search_term.h"
10 #include "components/history/core/browser/url_database.h" 10 #include "components/history/core/browser/url_database.h"
(...skipping 20 matching lines...) Expand all
31 } 31 }
32 32
33 } // namespace 33 } // namespace
34 34
35 class URLDatabaseTest : public testing::Test, 35 class URLDatabaseTest : public testing::Test,
36 public URLDatabase { 36 public URLDatabase {
37 public: 37 public:
38 URLDatabaseTest() { 38 URLDatabaseTest() {
39 } 39 }
40 40
41 void CreateVersion33URLTable() {
42 EXPECT_TRUE(GetDB().Execute("DROP TABLE urls"));
43
44 std::string sql;
45 // create a version 33 urls table
46 sql.append(
47 "CREATE TABLE urls ("
48 "id INTEGER PRIMARY KEY,"
49 "url LONGVARCHAR,"
50 "title LONGVARCHAR,"
51 "visit_count INTEGER DEFAULT 0 NOT NULL,"
52 "typed_count INTEGER DEFAULT 0 NOT NULL,"
53 "last_visit_time INTEGER NOT NULL,"
54 "hidden INTEGER DEFAULT 0 NOT NULL,"
55 "favicon_id INTEGER DEFAULT 0 NOT NULL)"); // favicon_id is not used
56 // now.
57 EXPECT_TRUE(GetDB().Execute(sql.c_str()));
58 }
59
41 protected: 60 protected:
42 // Provided for URL/VisitDatabase. 61 // Provided for URL/VisitDatabase.
43 sql::Connection& GetDB() override { return db_; } 62 sql::Connection& GetDB() override { return db_; }
44 63
45 private: 64 private:
46 // Test setup. 65 // Test setup.
47 void SetUp() override { 66 void SetUp() override {
48 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 67 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
49 base::FilePath db_file = temp_dir_.GetPath().AppendASCII("URLTest.db"); 68 base::FilePath db_file = temp_dir_.GetPath().AppendASCII("URLTest.db");
50 69
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 ASSERT_TRUE(GetKeywordSearchTermRows(keyword2, &rows)); 340 ASSERT_TRUE(GetKeywordSearchTermRows(keyword2, &rows));
322 ASSERT_EQ(1u, rows.size()); 341 ASSERT_EQ(1u, rows.size());
323 EXPECT_EQ(keyword2, rows[0].term); 342 EXPECT_EQ(keyword2, rows[0].term);
324 EXPECT_EQ(url_id3, rows[0].url_id); 343 EXPECT_EQ(url_id3, rows[0].url_id);
325 rows.clear(); 344 rows.clear();
326 // No row for keyword. 345 // No row for keyword.
327 ASSERT_TRUE(GetKeywordSearchTermRows(keyword, &rows)); 346 ASSERT_TRUE(GetKeywordSearchTermRows(keyword, &rows));
328 EXPECT_TRUE(rows.empty()); 347 EXPECT_TRUE(rows.empty());
329 } 348 }
330 349
350 // Test for migration of update URL table, verify AUTOINCREMENT is working
351 // properly.
352 TEST_F(URLDatabaseTest, MigrationURLTableForAddingAUTOINCREMENT) {
353 CreateVersion33URLTable();
354 // First, add two URLs.
355 const GURL url1("http://www.google.com/");
356 URLRow url_info1(url1);
357 url_info1.set_title(base::UTF8ToUTF16("Google"));
358 url_info1.set_visit_count(4);
359 url_info1.set_typed_count(2);
360 url_info1.set_last_visit(Time::Now() - TimeDelta::FromDays(1));
361 url_info1.set_hidden(false);
362 URLID id1_initially = AddURL(url_info1);
363 EXPECT_TRUE(id1_initially);
364
365 const GURL url2("http://mail.google.com/");
366 URLRow url_info2(url2);
367 url_info2.set_title(base::UTF8ToUTF16("Google Mail"));
368 url_info2.set_visit_count(3);
369 url_info2.set_typed_count(0);
370 url_info2.set_last_visit(Time::Now() - TimeDelta::FromDays(2));
371 url_info2.set_hidden(true);
372 EXPECT_TRUE(AddURL(url_info2));
373
374 // Verify both are added.
375 URLRow info1;
376 EXPECT_TRUE(GetRowForURL(url1, &info1));
377 EXPECT_TRUE(IsURLRowEqual(url_info1, info1));
378 URLRow info2;
379 EXPECT_TRUE(GetRowForURL(url2, &info2));
380 EXPECT_TRUE(IsURLRowEqual(url_info2, info2));
381
382 // Delete second URL, and add a new URL, verify id got re-used.
383 EXPECT_TRUE(DeleteURLRow(info2.id()));
384
385 const GURL url3("http://maps.google.com/");
386 URLRow url_info3(url3);
387 url_info3.set_title(base::UTF8ToUTF16("Google Maps"));
388 url_info3.set_visit_count(7);
389 url_info3.set_typed_count(6);
390 url_info3.set_last_visit(Time::Now() - TimeDelta::FromDays(3));
391 url_info3.set_hidden(false);
392 EXPECT_TRUE(AddURL(url_info3));
393
394 URLRow info3;
395 EXPECT_TRUE(GetRowForURL(url3, &info3));
396 EXPECT_TRUE(IsURLRowEqual(url_info3, info3));
397 // Verify the id re-used.
398 EXPECT_EQ(info2.id(), info3.id());
399
400 // Upgrade urls table.
401 RecreateURLTableWithAllContents();
402
403 // Verify all data keeped.
404 EXPECT_TRUE(GetRowForURL(url1, &info1));
405 EXPECT_TRUE(IsURLRowEqual(url_info1, info1));
406 EXPECT_FALSE(GetRowForURL(url2, &info2));
407 EXPECT_TRUE(GetRowForURL(url3, &info3));
408 EXPECT_TRUE(IsURLRowEqual(url_info3, info3));
409
410 // Add a new URL
411 const GURL url4("http://plus.google.com/");
412 URLRow url_info4(url4);
413 url_info4.set_title(base::UTF8ToUTF16("Google Plus"));
414 url_info4.set_visit_count(4);
415 url_info4.set_typed_count(3);
416 url_info4.set_last_visit(Time::Now() - TimeDelta::FromDays(4));
417 url_info4.set_hidden(false);
418 EXPECT_TRUE(AddURL(url_info4));
419
420 // Verify The URL are added.
421 URLRow info4;
422 EXPECT_TRUE(GetRowForURL(url4, &info4));
423 EXPECT_TRUE(IsURLRowEqual(url_info4, info4));
424
425 // Delete the newest URL, and add a new URL, verify id is not re-used.
426 EXPECT_TRUE(DeleteURLRow(info4.id()));
427
428 const GURL url5("http://docs.google.com/");
429 URLRow url_info5(url5);
430 url_info5.set_title(base::UTF8ToUTF16("Google Docs"));
431 url_info5.set_visit_count(9);
432 url_info5.set_typed_count(2);
433 url_info5.set_last_visit(Time::Now() - TimeDelta::FromDays(5));
434 url_info5.set_hidden(false);
435 EXPECT_TRUE(AddURL(url_info5));
436
437 URLRow info5;
438 EXPECT_TRUE(GetRowForURL(url5, &info5));
439 EXPECT_TRUE(IsURLRowEqual(url_info5, info5));
440 // Verify the id is not re-used.
441 EXPECT_NE(info4.id(), info5.id());
442 }
443
331 } // namespace history 444 } // namespace history
OLDNEW
« no previous file with comments | « components/history/core/browser/url_database.cc ('k') | components/test/data/omnibox/in_memory_url_index_test.db.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698