Make sure webrtc::VideoSource is released when WebRtcVideoTrackAdapter is destroyed.
[chromium-blink-merge.git] / components / dom_distiller / core / dom_distiller_test_util.cc
blobf9164fd63be81574635264571fabe6b949ad1e90
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 {
11 namespace test {
12 namespace util {
14 namespace {
16 std::vector<ArticleEntry> EntryMapToList(const FakeDB::EntryMap& entries) {
17 std::vector<ArticleEntry> entry_list;
18 for (FakeDB::EntryMap::const_iterator it = entries.begin();
19 it != entries.end();
20 ++it) {
21 entry_list.push_back(it->second);
23 return entry_list;
25 } // namespace
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();
37 return false;
39 std::vector<DomDistillerObserver::ArticleUpdate>::const_iterator expected,
40 actual;
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;
47 return false;
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;
53 return false;
56 return true;
59 void ObserverUpdatesMatcher::DescribeUpdates(std::ostream* os) const {
60 bool start = true;
61 for (std::vector<DomDistillerObserver::ArticleUpdate>::const_iterator i =
62 expected_updates_.begin();
63 i != expected_updates_.end();
64 ++i) {
65 if (start) {
66 start = false;
67 } else {
68 *os << ", ";
70 *os << "( EntryId: " << i->entry_id << ", UpdateType: " << i->update_type
71 << " )";
75 void ObserverUpdatesMatcher::DescribeTo(std::ostream* os) const {
76 *os << " has updates: { ";
77 DescribeUpdates(os);
78 *os << "}";
80 void ObserverUpdatesMatcher::DescribeNegationTo(std::ostream* os) const {
81 *os << " does not have updates: { ";
82 DescribeUpdates(os);
83 *os << "}";
86 testing::Matcher<const std::vector<DomDistillerObserver::ArticleUpdate>&>
87 HasExpectedUpdates(
88 const std::vector<DomDistillerObserver::ArticleUpdate>& expected_updates) {
89 return testing::MakeMatcher(new ObserverUpdatesMatcher(expected_updates));
92 // static
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());
101 } // namespace util
102 } // namespace test
103 } // namespace dom_distiller