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

Side by Side Diff: chrome/browser/history/history_unittest.cc

Issue 833033002: Remove dependency on //content from history DownloadDatabase (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix unit tests and move download_database.{cc,h} Created 5 years, 11 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 (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 // History unit tests come in two flavors: 5 // History unit tests come in two flavors:
6 // 6 //
7 // 1. The more complicated style is that the unit test creates a full history 7 // 1. The more complicated style is that the unit test creates a full history
8 // service. This spawns a background thread for the history backend, and 8 // service. This spawns a background thread for the history backend, and
9 // all communication is asynchronous. This is useful for testing more 9 // all communication is asynchronous. This is useful for testing more
10 // complicated things or end-to-end behavior. 10 // complicated things or end-to-end behavior.
(...skipping 24 matching lines...) Expand all
35 #include "base/memory/scoped_ptr.h" 35 #include "base/memory/scoped_ptr.h"
36 #include "base/memory/scoped_vector.h" 36 #include "base/memory/scoped_vector.h"
37 #include "base/message_loop/message_loop.h" 37 #include "base/message_loop/message_loop.h"
38 #include "base/path_service.h" 38 #include "base/path_service.h"
39 #include "base/strings/string_util.h" 39 #include "base/strings/string_util.h"
40 #include "base/strings/stringprintf.h" 40 #include "base/strings/stringprintf.h"
41 #include "base/strings/utf_string_conversions.h" 41 #include "base/strings/utf_string_conversions.h"
42 #include "base/task/cancelable_task_tracker.h" 42 #include "base/task/cancelable_task_tracker.h"
43 #include "base/threading/platform_thread.h" 43 #include "base/threading/platform_thread.h"
44 #include "base/time/time.h" 44 #include "base/time/time.h"
45 #include "chrome/browser/history/download_row.h"
46 #include "chrome/browser/history/history_backend.h" 45 #include "chrome/browser/history/history_backend.h"
47 #include "chrome/browser/history/history_database.h" 46 #include "chrome/browser/history/history_database.h"
48 #include "chrome/browser/history/history_notifications.h" 47 #include "chrome/browser/history/history_notifications.h"
49 #include "chrome/browser/history/history_service.h" 48 #include "chrome/browser/history/history_service.h"
50 #include "chrome/browser/history/history_unittest_base.h" 49 #include "chrome/browser/history/history_unittest_base.h"
51 #include "chrome/browser/history/in_memory_history_backend.h" 50 #include "chrome/browser/history/in_memory_history_backend.h"
52 #include "chrome/common/chrome_constants.h" 51 #include "chrome/common/chrome_constants.h"
53 #include "chrome/common/chrome_paths.h" 52 #include "chrome/common/chrome_paths.h"
54 #include "chrome/tools/profiles/thumbnail-inl.h" 53 #include "chrome/tools/profiles/thumbnail-inl.h"
54 #include "components/history/core/browser/download_constants.h"
55 #include "components/history/core/browser/download_row.h"
55 #include "components/history/core/browser/history_constants.h" 56 #include "components/history/core/browser/history_constants.h"
56 #include "components/history/core/browser/history_db_task.h" 57 #include "components/history/core/browser/history_db_task.h"
57 #include "components/history/core/browser/in_memory_database.h" 58 #include "components/history/core/browser/in_memory_database.h"
58 #include "components/history/core/browser/page_usage_data.h" 59 #include "components/history/core/browser/page_usage_data.h"
59 #include "components/history/core/common/thumbnail_score.h" 60 #include "components/history/core/common/thumbnail_score.h"
60 #include "content/public/browser/download_item.h" 61 #include "content/public/browser/download_item.h"
61 #include "content/public/browser/notification_details.h" 62 #include "content/public/browser/notification_details.h"
62 #include "content/public/browser/notification_source.h" 63 #include "content/public/browser/notification_source.h"
63 #include "sql/connection.h" 64 #include "sql/connection.h"
64 #include "sql/statement.h" 65 #include "sql/statement.h"
(...skipping 774 matching lines...) Expand 10 before | Expand all | Expand 10 after
839 sql::Connection db; 840 sql::Connection db;
840 ASSERT_TRUE(db.Open(history_dir_.Append(kHistoryFilename))); 841 ASSERT_TRUE(db.Open(history_dir_.Append(kHistoryFilename)));
841 sql::Statement statement(db.GetUniqueStatement( 842 sql::Statement statement(db.GetUniqueStatement(
842 "Select Count(*) from downloads")); 843 "Select Count(*) from downloads"));
843 EXPECT_TRUE(statement.Step()); 844 EXPECT_TRUE(statement.Step());
844 EXPECT_EQ(1, statement.ColumnInt(0)); 845 EXPECT_EQ(1, statement.ColumnInt(0));
845 846
846 sql::Statement statement1(db.GetUniqueStatement( 847 sql::Statement statement1(db.GetUniqueStatement(
847 "Select state, interrupt_reason from downloads")); 848 "Select state, interrupt_reason from downloads"));
848 EXPECT_TRUE(statement1.Step()); 849 EXPECT_TRUE(statement1.Step());
849 EXPECT_EQ(DownloadDatabase::kStateInProgress, statement1.ColumnInt(0)); 850 EXPECT_EQ(kStateInProgress, statement1.ColumnInt(0));
850 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_NONE, statement1.ColumnInt(1)); 851 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_NONE, statement1.ColumnInt(1));
851 EXPECT_FALSE(statement1.Step()); 852 EXPECT_FALSE(statement1.Step());
852 } 853 }
853 854
854 // Read in the DB through query downloads, then test that the 855 // Read in the DB through query downloads, then test that the
855 // right transformation was returned. 856 // right transformation was returned.
856 CreateBackendAndDatabase(); 857 CreateBackendAndDatabase();
857 std::vector<DownloadRow> results; 858 std::vector<DownloadRow> results;
858 db_->QueryDownloads(&results); 859 db_->QueryDownloads(&results);
859 ASSERT_EQ(1u, results.size()); 860 ASSERT_EQ(1u, results.size());
860 EXPECT_EQ(content::DownloadItem::INTERRUPTED, results[0].state); 861 EXPECT_EQ(content::DownloadItem::INTERRUPTED, results[0].state);
861 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_CRASH, 862 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_CRASH,
862 results[0].interrupt_reason); 863 results[0].interrupt_reason);
863 864
864 // Allow the update to propagate, shut down the DB, and confirm that 865 // Allow the update to propagate, shut down the DB, and confirm that
865 // the query updated the on disk database as well. 866 // the query updated the on disk database as well.
866 base::MessageLoop::current()->RunUntilIdle(); 867 base::MessageLoop::current()->RunUntilIdle();
867 DeleteBackend(); 868 DeleteBackend();
868 { 869 {
869 sql::Connection db; 870 sql::Connection db;
870 ASSERT_TRUE(db.Open(history_dir_.Append(kHistoryFilename))); 871 ASSERT_TRUE(db.Open(history_dir_.Append(kHistoryFilename)));
871 sql::Statement statement(db.GetUniqueStatement( 872 sql::Statement statement(db.GetUniqueStatement(
872 "Select Count(*) from downloads")); 873 "Select Count(*) from downloads"));
873 EXPECT_TRUE(statement.Step()); 874 EXPECT_TRUE(statement.Step());
874 EXPECT_EQ(1, statement.ColumnInt(0)); 875 EXPECT_EQ(1, statement.ColumnInt(0));
875 876
876 sql::Statement statement1(db.GetUniqueStatement( 877 sql::Statement statement1(db.GetUniqueStatement(
877 "Select state, interrupt_reason from downloads")); 878 "Select state, interrupt_reason from downloads"));
878 EXPECT_TRUE(statement1.Step()); 879 EXPECT_TRUE(statement1.Step());
879 EXPECT_EQ(DownloadDatabase::kStateInterrupted, statement1.ColumnInt(0)); 880 EXPECT_EQ(kStateInterrupted, statement1.ColumnInt(0));
880 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_CRASH, 881 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_CRASH,
881 statement1.ColumnInt(1)); 882 statement1.ColumnInt(1));
882 EXPECT_FALSE(statement1.Step()); 883 EXPECT_FALSE(statement1.Step());
883 } 884 }
884 } 885 }
885 886
886 struct InterruptReasonAssociation { 887 struct InterruptReasonAssociation {
887 std::string name; 888 std::string name;
888 int value; 889 int value;
889 }; 890 };
(...skipping 973 matching lines...) Expand 10 before | Expand all | Expand 10 after
1863 std::vector<PageUsageData*> results; 1864 std::vector<PageUsageData*> results;
1864 db_->QuerySegmentUsage(segment_time, 10, &results); 1865 db_->QuerySegmentUsage(segment_time, 10, &results);
1865 ASSERT_EQ(1u, results.size()); 1866 ASSERT_EQ(1u, results.size());
1866 EXPECT_EQ(url, results[0]->GetURL()); 1867 EXPECT_EQ(url, results[0]->GetURL());
1867 EXPECT_EQ(segment_id, results[0]->GetID()); 1868 EXPECT_EQ(segment_id, results[0]->GetID());
1868 EXPECT_EQ(title, results[0]->GetTitle()); 1869 EXPECT_EQ(title, results[0]->GetTitle());
1869 STLDeleteElements(&results); 1870 STLDeleteElements(&results);
1870 } 1871 }
1871 1872
1872 } // namespace history 1873 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698