1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "components/dom_distiller/core/dom_distiller_test_util.h"
7 #include "components/dom_distiller/core/dom_distiller_store.h"
8 #include "components/dom_distiller/core/fake_distiller.h"
10 namespace dom_distiller
{
16 std::vector
<ArticleEntry
> EntryMapToList(const FakeDB::EntryMap
& entries
) {
17 std::vector
<ArticleEntry
> entry_list
;
18 for (FakeDB::EntryMap::const_iterator it
= entries
.begin();
21 entry_list
.push_back(it
->second
);
27 ObserverUpdatesMatcher::ObserverUpdatesMatcher(
28 const std::vector
<DomDistillerObserver::ArticleUpdate
>& expected_updates
)
29 : expected_updates_(expected_updates
) {}
31 bool ObserverUpdatesMatcher::MatchAndExplain(
32 const std::vector
<DomDistillerObserver::ArticleUpdate
>& actual_updates
,
33 testing::MatchResultListener
* listener
) const {
34 if (actual_updates
.size() != expected_updates_
.size()) {
35 *listener
<< "Incorrect number of updates. Expected: "
36 << expected_updates_
.size() << " got: " << actual_updates
.size();
39 std::vector
<DomDistillerObserver::ArticleUpdate
>::const_iterator expected
,
41 for (expected
= expected_updates_
.begin(), actual
= actual_updates
.begin();
42 expected
!= expected_updates_
.end();
43 ++expected
, ++actual
) {
44 if (expected
->entry_id
!= actual
->entry_id
) {
45 *listener
<< " Mismatched entry id. Expected: " << expected
->entry_id
46 << " actual: " << actual
->entry_id
;
49 if (expected
->update_type
!= actual
->update_type
) {
50 *listener
<< " Mismatched update for entryid:" << expected
->entry_id
51 << ". Expected: " << expected
->update_type
52 << " actual: " << actual
->update_type
;
59 void ObserverUpdatesMatcher::DescribeUpdates(std::ostream
* os
) const {
61 for (std::vector
<DomDistillerObserver::ArticleUpdate
>::const_iterator i
=
62 expected_updates_
.begin();
63 i
!= expected_updates_
.end();
70 *os
<< "( EntryId: " << i
->entry_id
<< ", UpdateType: " << i
->update_type
75 void ObserverUpdatesMatcher::DescribeTo(std::ostream
* os
) const {
76 *os
<< " has updates: { ";
80 void ObserverUpdatesMatcher::DescribeNegationTo(std::ostream
* os
) const {
81 *os
<< " does not have updates: { ";
86 testing::Matcher
<const std::vector
<DomDistillerObserver::ArticleUpdate
>&>
88 const std::vector
<DomDistillerObserver::ArticleUpdate
>& expected_updates
) {
89 return testing::MakeMatcher(new ObserverUpdatesMatcher(expected_updates
));
93 DomDistillerStore
* CreateStoreWithFakeDB(FakeDB
* fake_db
,
94 const FakeDB::EntryMap
& store_model
) {
95 return new DomDistillerStore(
96 scoped_ptr
<DomDistillerDatabaseInterface
>(fake_db
),
97 EntryMapToList(store_model
),
98 FakeDB::DirectoryForTestDB());
103 } // namespace dom_distiller