Make sure webrtc::VideoSource is released when WebRtcVideoTrackAdapter is destroyed.
[chromium-blink-merge.git] / components / dom_distiller / core / viewer_unittest.cc
blob7c1b0752849aebde6b3869573a164f2c7be3936a
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
3 // found in the LICENSE file.
5 #include "components/dom_distiller/core/viewer.h"
7 #include "components/dom_distiller/core/dom_distiller_service.h"
8 #include "components/dom_distiller/core/dom_distiller_test_util.h"
9 #include "components/dom_distiller/core/task_tracker.h"
10 #include "components/dom_distiller/core/url_constants.h"
11 #include "testing/gtest/include/gtest/gtest.h"
13 namespace dom_distiller {
15 const char kTestScheme[] = "myscheme";
17 class FakeViewRequestDelegate : public ViewRequestDelegate {
18 public:
19 virtual ~FakeViewRequestDelegate() {}
20 MOCK_METHOD1(OnArticleReady, void(const DistilledArticleProto* proto));
21 MOCK_METHOD1(OnArticleUpdated,
22 void(ArticleDistillationUpdate article_update));
25 class TestDomDistillerService : public DomDistillerServiceInterface {
26 public:
27 TestDomDistillerService() {}
28 virtual ~TestDomDistillerService() {}
30 MOCK_CONST_METHOD0(GetSyncableService, syncer::SyncableService*());
31 MOCK_METHOD3(AddToList,
32 const std::string(const GURL&,
33 DistillerPage*,
34 const ArticleAvailableCallback&));
35 virtual const std::string AddToList(
36 const GURL& url,
37 scoped_ptr<DistillerPage> distiller_page,
38 const ArticleAvailableCallback& article_cb) {
39 return AddToList(url, distiller_page.get(), article_cb);
41 MOCK_CONST_METHOD0(GetEntries, std::vector<ArticleEntry>());
42 MOCK_METHOD1(AddObserver, void(DomDistillerObserver*));
43 MOCK_METHOD1(RemoveObserver, void(DomDistillerObserver*));
44 MOCK_METHOD0(ViewUrlImpl, ViewerHandle*());
45 virtual scoped_ptr<ViewerHandle> ViewUrl(
46 ViewRequestDelegate*,
47 scoped_ptr<DistillerPage> distiller_page,
48 const GURL&) {
49 return scoped_ptr<ViewerHandle>(ViewUrlImpl());
51 MOCK_METHOD0(ViewEntryImpl, ViewerHandle*());
52 virtual scoped_ptr<ViewerHandle> ViewEntry(
53 ViewRequestDelegate*,
54 scoped_ptr<DistillerPage> distiller_page,
55 const std::string&) {
56 return scoped_ptr<ViewerHandle>(ViewEntryImpl());
58 MOCK_METHOD0(RemoveEntryImpl, ArticleEntry*());
59 virtual scoped_ptr<ArticleEntry> RemoveEntry(const std::string&) {
60 return scoped_ptr<ArticleEntry>(RemoveEntryImpl());
62 virtual scoped_ptr<DistillerPage> CreateDefaultDistillerPage() {
63 return scoped_ptr<DistillerPage>();
65 virtual scoped_ptr<DistillerPage> CreateDefaultDistillerPageWithHandle(
66 scoped_ptr<SourcePageHandle> handle) {
67 return scoped_ptr<DistillerPage>();
71 class DomDistillerViewerTest : public testing::Test {
72 public:
73 virtual void SetUp() OVERRIDE {
74 service_.reset(new TestDomDistillerService());
77 protected:
78 scoped_ptr<ViewerHandle> CreateViewRequest(
79 const std::string& path,
80 ViewRequestDelegate* view_request_delegate) {
81 return viewer::CreateViewRequest(
82 service_.get(), path, view_request_delegate);
85 scoped_ptr<TestDomDistillerService> service_;
88 TEST_F(DomDistillerViewerTest, TestCreatingViewUrlRequest) {
89 scoped_ptr<FakeViewRequestDelegate> view_request_delegate(
90 new FakeViewRequestDelegate());
91 ViewerHandle* viewer_handle(new ViewerHandle(ViewerHandle::CancelCallback()));
92 EXPECT_CALL(*service_.get(), ViewUrlImpl())
93 .WillOnce(testing::Return(viewer_handle));
94 EXPECT_CALL(*service_.get(), ViewEntryImpl()).Times(0);
95 CreateViewRequest(
96 std::string("?") + kUrlKey + "=http%3A%2F%2Fwww.example.com%2F",
97 view_request_delegate.get());
100 TEST_F(DomDistillerViewerTest, TestCreatingViewEntryRequest) {
101 scoped_ptr<FakeViewRequestDelegate> view_request_delegate(
102 new FakeViewRequestDelegate());
103 ViewerHandle* viewer_handle(new ViewerHandle(ViewerHandle::CancelCallback()));
104 EXPECT_CALL(*service_.get(), ViewEntryImpl())
105 .WillOnce(testing::Return(viewer_handle));
106 EXPECT_CALL(*service_.get(), ViewUrlImpl()).Times(0);
107 CreateViewRequest(std::string("?") + kEntryIdKey + "=abc-def",
108 view_request_delegate.get());
111 TEST_F(DomDistillerViewerTest, TestCreatingInvalidViewRequest) {
112 scoped_ptr<FakeViewRequestDelegate> view_request_delegate(
113 new FakeViewRequestDelegate());
114 EXPECT_CALL(*service_.get(), ViewEntryImpl()).Times(0);
115 EXPECT_CALL(*service_.get(), ViewUrlImpl()).Times(0);
116 // Specify none of the required query parameters.
117 CreateViewRequest("?foo=bar", view_request_delegate.get());
118 // Specify both of the required query parameters.
119 CreateViewRequest("?" + std::string(kUrlKey) +
120 "=http%3A%2F%2Fwww.example.com%2F&" +
121 std::string(kEntryIdKey) + "=abc-def",
122 view_request_delegate.get());
123 // Specify an internal Chrome page.
124 CreateViewRequest("?" + std::string(kUrlKey) + "=chrome%3A%2F%2Fsettings%2F",
125 view_request_delegate.get());
126 // Specify a recursive URL.
127 CreateViewRequest("?" + std::string(kUrlKey) + "=" +
128 std::string(kTestScheme) + "%3A%2F%2Fabc-def%2F",
129 view_request_delegate.get());
132 } // namespace dom_distiller