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 // 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 // Delegate class for when we create a backend without a HistoryService. | 86 // Delegate class for when we create a backend without a HistoryService. |
87 // | 87 // |
88 // This must be outside the anonymous namespace for the friend statement in | 88 // This must be outside the anonymous namespace for the friend statement in |
89 // HistoryBackendDBTest to work. | 89 // HistoryBackendDBTest to work. |
90 class BackendDelegate : public HistoryBackend::Delegate { | 90 class BackendDelegate : public HistoryBackend::Delegate { |
91 public: | 91 public: |
92 explicit BackendDelegate(HistoryBackendDBTest* history_test) | 92 explicit BackendDelegate(HistoryBackendDBTest* history_test) |
93 : history_test_(history_test) { | 93 : history_test_(history_test) { |
94 } | 94 } |
95 | 95 |
96 virtual void NotifyProfileError(sql::InitStatus init_status) override {} | 96 void NotifyProfileError(sql::InitStatus init_status) override {} |
97 virtual void SetInMemoryBackend( | 97 void SetInMemoryBackend(scoped_ptr<InMemoryHistoryBackend> backend) override; |
98 scoped_ptr<InMemoryHistoryBackend> backend) override; | 98 void NotifyAddVisit(const BriefVisitInfo& info) override {} |
99 virtual void NotifyAddVisit(const BriefVisitInfo& info) override {} | 99 void NotifyFaviconChanged(const std::set<GURL>& url) override {} |
100 virtual void NotifyFaviconChanged(const std::set<GURL>& url) override {} | 100 void NotifyURLVisited(ui::PageTransition transition, |
101 virtual void NotifyURLVisited(ui::PageTransition transition, | 101 const URLRow& row, |
102 const URLRow& row, | 102 const RedirectList& redirects, |
103 const RedirectList& redirects, | 103 base::Time visit_time) override {} |
104 base::Time visit_time) override {} | 104 void BroadcastNotifications(int type, |
105 virtual void BroadcastNotifications( | 105 scoped_ptr<HistoryDetails> details) override; |
106 int type, | 106 void DBLoaded() override {} |
107 scoped_ptr<HistoryDetails> details) override; | |
108 virtual void DBLoaded() override {} | |
109 | 107 |
110 private: | 108 private: |
111 HistoryBackendDBTest* history_test_; | 109 HistoryBackendDBTest* history_test_; |
112 }; | 110 }; |
113 | 111 |
114 // This must be outside the anonymous namespace for the friend statement in | 112 // This must be outside the anonymous namespace for the friend statement in |
115 // HistoryBackend to work. | 113 // HistoryBackend to work. |
116 class HistoryBackendDBTest : public HistoryUnitTestBase { | 114 class HistoryBackendDBTest : public HistoryUnitTestBase { |
117 public: | 115 public: |
118 HistoryBackendDBTest() : db_(NULL) { | 116 HistoryBackendDBTest() : db_(NULL) { |
(...skipping 1381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1500 // returned from RunOnDBThread which should stop RunOnDBThread from being | 1498 // returned from RunOnDBThread which should stop RunOnDBThread from being |
1501 // invoked again. When DoneRunOnMainThread is invoked, done_invoked is set to | 1499 // invoked again. When DoneRunOnMainThread is invoked, done_invoked is set to |
1502 // true. | 1500 // true. |
1503 class HistoryDBTaskImpl : public HistoryDBTask { | 1501 class HistoryDBTaskImpl : public HistoryDBTask { |
1504 public: | 1502 public: |
1505 static const int kWantInvokeCount; | 1503 static const int kWantInvokeCount; |
1506 | 1504 |
1507 HistoryDBTaskImpl(int* invoke_count, bool* done_invoked) | 1505 HistoryDBTaskImpl(int* invoke_count, bool* done_invoked) |
1508 : invoke_count_(invoke_count), done_invoked_(done_invoked) {} | 1506 : invoke_count_(invoke_count), done_invoked_(done_invoked) {} |
1509 | 1507 |
1510 virtual bool RunOnDBThread(HistoryBackend* backend, | 1508 bool RunOnDBThread(HistoryBackend* backend, HistoryDatabase* db) override { |
1511 HistoryDatabase* db) override { | |
1512 return (++*invoke_count_ == kWantInvokeCount); | 1509 return (++*invoke_count_ == kWantInvokeCount); |
1513 } | 1510 } |
1514 | 1511 |
1515 virtual void DoneRunOnMainThread() override { | 1512 void DoneRunOnMainThread() override { |
1516 *done_invoked_ = true; | 1513 *done_invoked_ = true; |
1517 base::MessageLoop::current()->Quit(); | 1514 base::MessageLoop::current()->Quit(); |
1518 } | 1515 } |
1519 | 1516 |
1520 int* invoke_count_; | 1517 int* invoke_count_; |
1521 bool* done_invoked_; | 1518 bool* done_invoked_; |
1522 | 1519 |
1523 private: | 1520 private: |
1524 virtual ~HistoryDBTaskImpl() {} | 1521 ~HistoryDBTaskImpl() override {} |
1525 | 1522 |
1526 DISALLOW_COPY_AND_ASSIGN(HistoryDBTaskImpl); | 1523 DISALLOW_COPY_AND_ASSIGN(HistoryDBTaskImpl); |
1527 }; | 1524 }; |
1528 | 1525 |
1529 // static | 1526 // static |
1530 const int HistoryDBTaskImpl::kWantInvokeCount = 2; | 1527 const int HistoryDBTaskImpl::kWantInvokeCount = 2; |
1531 | 1528 |
1532 } // namespace | 1529 } // namespace |
1533 | 1530 |
1534 TEST_F(HistoryTest, HistoryDBTask) { | 1531 TEST_F(HistoryTest, HistoryDBTask) { |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1870 std::vector<PageUsageData*> results; | 1867 std::vector<PageUsageData*> results; |
1871 db_->QuerySegmentUsage(segment_time, 10, &results); | 1868 db_->QuerySegmentUsage(segment_time, 10, &results); |
1872 ASSERT_EQ(1u, results.size()); | 1869 ASSERT_EQ(1u, results.size()); |
1873 EXPECT_EQ(url, results[0]->GetURL()); | 1870 EXPECT_EQ(url, results[0]->GetURL()); |
1874 EXPECT_EQ(segment_id, results[0]->GetID()); | 1871 EXPECT_EQ(segment_id, results[0]->GetID()); |
1875 EXPECT_EQ(title, results[0]->GetTitle()); | 1872 EXPECT_EQ(title, results[0]->GetTitle()); |
1876 STLDeleteElements(&results); | 1873 STLDeleteElements(&results); |
1877 } | 1874 } |
1878 | 1875 |
1879 } // namespace history | 1876 } // namespace history |
OLD | NEW |