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

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: Addressed comments. added unit tests Created 6 years, 10 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 class FakeViewRequestDelegate : public ViewRequestDelegate {
21 public:
22 virtual ~FakeViewRequestDelegate() {}
23 MOCK_METHOD1(OnArticleReady, void(const DistilledArticleProto* proto));
24 };
25
26 class TestDomDistillerService : public DomDistillerServiceInterface {
27 public:
28 TestDomDistillerService() {}
29 virtual ~TestDomDistillerService() {}
30
31 MOCK_CONST_METHOD0(GetSyncableService, syncer::SyncableService*());
32 MOCK_METHOD2(AddToList,
33 const std::string(const GURL&, const ArticleAvailableCallback&));
34 MOCK_CONST_METHOD0(GetEntries, std::vector<ArticleEntry>());
35 MOCK_METHOD1(AddObserver, void(DomDistillerObserver*));
36 MOCK_METHOD1(RemoveObserver, void(DomDistillerObserver*));
37 MOCK_METHOD0(ViewUrlImpl, ViewerHandle*());
38 virtual scoped_ptr<ViewerHandle> ViewUrl(ViewRequestDelegate*, const GURL&) {
39 return scoped_ptr<ViewerHandle>(ViewUrlImpl());
40 }
41 MOCK_METHOD0(ViewEntryImpl, ViewerHandle*());
42 virtual scoped_ptr<ViewerHandle> ViewEntry(ViewRequestDelegate*,
43 const std::string&) {
44 return scoped_ptr<ViewerHandle>(ViewEntryImpl());
45 }
46 MOCK_METHOD0(RemoveEntryImpl, ArticleEntry*());
47 virtual scoped_ptr<ArticleEntry> RemoveEntry(const std::string&) {
48 return scoped_ptr<ArticleEntry>(RemoveEntryImpl());
49 }
50 };
51
52 class DomDistillerViewerSourceTest : public testing::Test {};
53
54 TEST_F(DomDistillerViewerSourceTest, TestMimeType) {
55 scoped_ptr<TestDomDistillerService> service(new TestDomDistillerService());
56 DomDistillerViewerSource source(service.get(), "myscheme");
57 EXPECT_EQ("text/css", source.GetMimeType(kCssPath));
58 EXPECT_EQ("text/html", source.GetMimeType("anythingelse"));
59 }
60
61 TEST_F(DomDistillerViewerSourceTest, TestPathUtil) {
62 scoped_ptr<TestDomDistillerService> service(new TestDomDistillerService());
63 DomDistillerViewerSource source(service.get(), "myscheme");
64 const std::string single_key = "mypath?foo=bar";
65 EXPECT_EQ("bar", source.GetValueForKeyInURLPathQuery(single_key, "foo"));
66 const std::string two_keys = "mypath?key1=foo&key2=bar";
67 EXPECT_EQ("foo", source.GetValueForKeyInURLPathQuery(two_keys, "key1"));
68 EXPECT_EQ("bar", source.GetValueForKeyInURLPathQuery(two_keys, "key2"));
69 const std::string multiple_same_key = "mypath?key=foo&key=bar";
70 EXPECT_EQ("foo",
71 source.GetValueForKeyInURLPathQuery(multiple_same_key, "key"));
72 }
73
74 TEST_F(DomDistillerViewerSourceTest, TestCreatingViewUrlRequest) {
75 scoped_ptr<TestDomDistillerService> service(new TestDomDistillerService());
76 DomDistillerViewerSource source(service.get(), "myscheme");
77 scoped_ptr<FakeViewRequestDelegate> view_request_delegate(
78 new FakeViewRequestDelegate());
79 ViewerHandle* viewer_handle(new ViewerHandle(ViewerHandle::CancelCallback()));
80 EXPECT_CALL(*service.get(), ViewUrlImpl())
81 .WillOnce(testing::Return(viewer_handle));
82 EXPECT_CALL(*service.get(), ViewEntryImpl()).Times(0);
83 source.CreateViewRequest(
84 std::string("?") + kUrlKey + "=http%3A%2F%2Fwww.example.com%2F",
85 view_request_delegate.get());
86 }
87
88 TEST_F(DomDistillerViewerSourceTest, TestCreatingViewEntryRequest) {
89 scoped_ptr<TestDomDistillerService> service(new TestDomDistillerService());
90 DomDistillerViewerSource source(service.get(), "myscheme");
91 scoped_ptr<FakeViewRequestDelegate> view_request_delegate(
92 new FakeViewRequestDelegate());
93 ViewerHandle* viewer_handle(new ViewerHandle(ViewerHandle::CancelCallback()));
94 EXPECT_CALL(*service.get(), ViewEntryImpl())
95 .WillOnce(testing::Return(viewer_handle));
96 EXPECT_CALL(*service.get(), ViewUrlImpl()).Times(0);
97 source.CreateViewRequest(std::string("?") + kEntryIdKey + "=abc-def",
98 view_request_delegate.get());
99 }
100
101 TEST_F(DomDistillerViewerSourceTest, TestCreatingInvalidViewRequest) {
102 scoped_ptr<TestDomDistillerService> service(new TestDomDistillerService());
103 DomDistillerViewerSource source(service.get(), "myscheme");
104 scoped_ptr<FakeViewRequestDelegate> view_request_delegate(
105 new FakeViewRequestDelegate());
106 EXPECT_CALL(*service.get(), ViewEntryImpl()).Times(0);
107 EXPECT_CALL(*service.get(), ViewUrlImpl()).Times(0);
108 // Specify none of the required query parameters.
109 source.CreateViewRequest("?foo=bar", view_request_delegate.get());
110 // Specify both of the required query parameters.
111 source.CreateViewRequest("?" + std::string(kUrlKey) +
112 "=http%3A%2F%2Fwww.example.com%2F&" +
113 std::string(kEntryIdKey) + "=abc-def",
114 view_request_delegate.get());
shashi 2014/02/25 21:48:08 Thank you for adding these tests :). I was thinki
nyquist 2014/02/27 00:07:37 Added a unit test for both internal chrome:// page
115 }
116
117 } // namespace dom_distiller
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698