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

Side by Side Diff: components/dom_distiller/content/dom_distiller_viewer_source_unittest.cc

Issue 151003006: Add support for distilling arbitrary URLs in DOM Distiller Viewer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added new strings to iOS whitelist Created 6 years, 9 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 | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 #include "components/dom_distiller/content/dom_distiller_viewer_source.h"
6
7 #include "base/callback.h"
8 #include "components/dom_distiller/core/article_entry.h"
9 #include "components/dom_distiller/core/dom_distiller_service.h"
10 #include "components/dom_distiller/core/dom_distiller_store.h"
11 #include "components/dom_distiller/core/dom_distiller_test_util.h"
12 #include "components/dom_distiller/core/fake_db.h"
13 #include "components/dom_distiller/core/fake_distiller.h"
14 #include "components/dom_distiller/core/task_tracker.h"
15 #include "components/dom_distiller/core/url_constants.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17
18 namespace dom_distiller {
19
20 const char kTestScheme[] = "myscheme";
21
22 class FakeViewRequestDelegate : public ViewRequestDelegate {
23 public:
24 virtual ~FakeViewRequestDelegate() {}
25 MOCK_METHOD1(OnArticleReady, void(const DistilledArticleProto* proto));
26 };
27
28 class TestDomDistillerService : public DomDistillerServiceInterface {
29 public:
30 TestDomDistillerService() {}
31 virtual ~TestDomDistillerService() {}
32
33 MOCK_CONST_METHOD0(GetSyncableService, syncer::SyncableService*());
34 MOCK_METHOD2(AddToList,
35 const std::string(const GURL&, const ArticleAvailableCallback&));
36 MOCK_CONST_METHOD0(GetEntries, std::vector<ArticleEntry>());
37 MOCK_METHOD1(AddObserver, void(DomDistillerObserver*));
38 MOCK_METHOD1(RemoveObserver, void(DomDistillerObserver*));
39 MOCK_METHOD0(ViewUrlImpl, ViewerHandle*());
40 virtual scoped_ptr<ViewerHandle> ViewUrl(ViewRequestDelegate*, const GURL&) {
41 return scoped_ptr<ViewerHandle>(ViewUrlImpl());
42 }
43 MOCK_METHOD0(ViewEntryImpl, ViewerHandle*());
44 virtual scoped_ptr<ViewerHandle> ViewEntry(ViewRequestDelegate*,
45 const std::string&) {
46 return scoped_ptr<ViewerHandle>(ViewEntryImpl());
47 }
48 MOCK_METHOD0(RemoveEntryImpl, ArticleEntry*());
49 virtual scoped_ptr<ArticleEntry> RemoveEntry(const std::string&) {
50 return scoped_ptr<ArticleEntry>(RemoveEntryImpl());
51 }
52 };
53
54 class DomDistillerViewerSourceTest : public testing::Test {
55 public:
56 virtual void SetUp() OVERRIDE {
57 service_.reset(new TestDomDistillerService());
58 source_.reset(new DomDistillerViewerSource(service_.get(), kTestScheme));
59 }
60
61 protected:
62 scoped_ptr<ViewerHandle> CreateViewRequest(
63 const std::string& path,
64 ViewRequestDelegate* view_request_delegate) {
65 return source_.get()->CreateViewRequest(path, view_request_delegate);
66 }
67
68 scoped_ptr<TestDomDistillerService> service_;
69 scoped_ptr<DomDistillerViewerSource> source_;
70 };
71
72 TEST_F(DomDistillerViewerSourceTest, TestMimeType) {
73 EXPECT_EQ("text/css", source_.get()->GetMimeType(kCssPath));
74 EXPECT_EQ("text/html", source_.get()->GetMimeType("anythingelse"));
75 }
76
77 TEST_F(DomDistillerViewerSourceTest, TestCreatingViewUrlRequest) {
78 scoped_ptr<FakeViewRequestDelegate> view_request_delegate(
79 new FakeViewRequestDelegate());
80 ViewerHandle* viewer_handle(new ViewerHandle(ViewerHandle::CancelCallback()));
81 EXPECT_CALL(*service_.get(), ViewUrlImpl())
82 .WillOnce(testing::Return(viewer_handle));
83 EXPECT_CALL(*service_.get(), ViewEntryImpl()).Times(0);
84 CreateViewRequest(
85 std::string("?") + kUrlKey + "=http%3A%2F%2Fwww.example.com%2F",
86 view_request_delegate.get());
87 }
88
89 TEST_F(DomDistillerViewerSourceTest, TestCreatingViewEntryRequest) {
90 scoped_ptr<FakeViewRequestDelegate> view_request_delegate(
91 new FakeViewRequestDelegate());
92 ViewerHandle* viewer_handle(new ViewerHandle(ViewerHandle::CancelCallback()));
93 EXPECT_CALL(*service_.get(), ViewEntryImpl())
94 .WillOnce(testing::Return(viewer_handle));
95 EXPECT_CALL(*service_.get(), ViewUrlImpl()).Times(0);
96 CreateViewRequest(std::string("?") + kEntryIdKey + "=abc-def",
97 view_request_delegate.get());
98 }
99
100 TEST_F(DomDistillerViewerSourceTest, TestCreatingInvalidViewRequest) {
101 scoped_ptr<FakeViewRequestDelegate> view_request_delegate(
102 new FakeViewRequestDelegate());
103 EXPECT_CALL(*service_.get(), ViewEntryImpl()).Times(0);
104 EXPECT_CALL(*service_.get(), ViewUrlImpl()).Times(0);
105 // Specify none of the required query parameters.
106 CreateViewRequest("?foo=bar", view_request_delegate.get());
107 // Specify both of the required query parameters.
108 CreateViewRequest("?" + std::string(kUrlKey) +
109 "=http%3A%2F%2Fwww.example.com%2F&" +
110 std::string(kEntryIdKey) + "=abc-def",
111 view_request_delegate.get());
112 // Specify an internal Chrome page.
113 CreateViewRequest("?" + std::string(kUrlKey) + "=chrome%3A%2F%2Fsettings%2F",
114 view_request_delegate.get());
115 // Specify a recursive URL.
116 CreateViewRequest("?" + std::string(kUrlKey) + "=" +
117 std::string(kTestScheme) + "%3A%2F%2Fabc-def%2F",
118 view_request_delegate.get());
119 }
120
121 } // namespace dom_distiller
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698