OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/dom_distiller/content/dom_distiller_viewer_source.h" | 5 #include "components/dom_distiller/core/viewer.h" |
6 | 6 |
7 #include <vector> | |
8 | |
9 #include "base/callback.h" | |
10 #include "components/dom_distiller/core/article_distillation_update.h" | |
11 #include "components/dom_distiller/core/article_entry.h" | |
12 #include "components/dom_distiller/core/dom_distiller_service.h" | 7 #include "components/dom_distiller/core/dom_distiller_service.h" |
13 #include "components/dom_distiller/core/dom_distiller_store.h" | |
14 #include "components/dom_distiller/core/dom_distiller_test_util.h" | 8 #include "components/dom_distiller/core/dom_distiller_test_util.h" |
15 #include "components/dom_distiller/core/fake_db.h" | |
16 #include "components/dom_distiller/core/fake_distiller.h" | |
17 #include "components/dom_distiller/core/task_tracker.h" | 9 #include "components/dom_distiller/core/task_tracker.h" |
18 #include "components/dom_distiller/core/url_constants.h" | 10 #include "components/dom_distiller/core/url_constants.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
20 | 12 |
21 namespace dom_distiller { | 13 namespace dom_distiller { |
22 | 14 |
23 const char kTestScheme[] = "myscheme"; | 15 const char kTestScheme[] = "myscheme"; |
24 | 16 |
25 class FakeViewRequestDelegate : public ViewRequestDelegate { | 17 class FakeViewRequestDelegate : public ViewRequestDelegate { |
26 public: | 18 public: |
(...skipping 22 matching lines...) Expand all Loading... |
49 virtual scoped_ptr<ViewerHandle> ViewEntry(ViewRequestDelegate*, | 41 virtual scoped_ptr<ViewerHandle> ViewEntry(ViewRequestDelegate*, |
50 const std::string&) { | 42 const std::string&) { |
51 return scoped_ptr<ViewerHandle>(ViewEntryImpl()); | 43 return scoped_ptr<ViewerHandle>(ViewEntryImpl()); |
52 } | 44 } |
53 MOCK_METHOD0(RemoveEntryImpl, ArticleEntry*()); | 45 MOCK_METHOD0(RemoveEntryImpl, ArticleEntry*()); |
54 virtual scoped_ptr<ArticleEntry> RemoveEntry(const std::string&) { | 46 virtual scoped_ptr<ArticleEntry> RemoveEntry(const std::string&) { |
55 return scoped_ptr<ArticleEntry>(RemoveEntryImpl()); | 47 return scoped_ptr<ArticleEntry>(RemoveEntryImpl()); |
56 } | 48 } |
57 }; | 49 }; |
58 | 50 |
59 class DomDistillerViewerSourceTest : public testing::Test { | 51 class DomDistillerViewerTest : public testing::Test { |
60 public: | 52 public: |
61 virtual void SetUp() OVERRIDE { | 53 virtual void SetUp() OVERRIDE { |
62 service_.reset(new TestDomDistillerService()); | 54 service_.reset(new TestDomDistillerService()); |
63 source_.reset(new DomDistillerViewerSource(service_.get(), kTestScheme)); | |
64 } | 55 } |
65 | 56 |
66 protected: | 57 protected: |
67 scoped_ptr<ViewerHandle> CreateViewRequest( | 58 scoped_ptr<ViewerHandle> CreateViewRequest( |
68 const std::string& path, | 59 const std::string& path, |
69 ViewRequestDelegate* view_request_delegate) { | 60 ViewRequestDelegate* view_request_delegate) { |
70 return source_.get()->CreateViewRequest(path, view_request_delegate); | 61 return viewer::CreateViewRequest( |
| 62 service_.get(), path, view_request_delegate); |
71 } | 63 } |
72 | 64 |
73 scoped_ptr<TestDomDistillerService> service_; | 65 scoped_ptr<TestDomDistillerService> service_; |
74 scoped_ptr<DomDistillerViewerSource> source_; | |
75 }; | 66 }; |
76 | 67 |
77 TEST_F(DomDistillerViewerSourceTest, TestMimeType) { | 68 TEST_F(DomDistillerViewerTest, TestCreatingViewUrlRequest) { |
78 EXPECT_EQ("text/css", source_.get()->GetMimeType(kCssPath)); | |
79 EXPECT_EQ("text/html", source_.get()->GetMimeType("anythingelse")); | |
80 } | |
81 | |
82 TEST_F(DomDistillerViewerSourceTest, TestCreatingViewUrlRequest) { | |
83 scoped_ptr<FakeViewRequestDelegate> view_request_delegate( | 69 scoped_ptr<FakeViewRequestDelegate> view_request_delegate( |
84 new FakeViewRequestDelegate()); | 70 new FakeViewRequestDelegate()); |
85 ViewerHandle* viewer_handle(new ViewerHandle(ViewerHandle::CancelCallback())); | 71 ViewerHandle* viewer_handle(new ViewerHandle(ViewerHandle::CancelCallback())); |
86 EXPECT_CALL(*service_.get(), ViewUrlImpl()) | 72 EXPECT_CALL(*service_.get(), ViewUrlImpl()) |
87 .WillOnce(testing::Return(viewer_handle)); | 73 .WillOnce(testing::Return(viewer_handle)); |
88 EXPECT_CALL(*service_.get(), ViewEntryImpl()).Times(0); | 74 EXPECT_CALL(*service_.get(), ViewEntryImpl()).Times(0); |
89 CreateViewRequest( | 75 CreateViewRequest( |
90 std::string("?") + kUrlKey + "=http%3A%2F%2Fwww.example.com%2F", | 76 std::string("?") + kUrlKey + "=http%3A%2F%2Fwww.example.com%2F", |
91 view_request_delegate.get()); | 77 view_request_delegate.get()); |
92 } | 78 } |
93 | 79 |
94 TEST_F(DomDistillerViewerSourceTest, TestCreatingViewEntryRequest) { | 80 TEST_F(DomDistillerViewerTest, TestCreatingViewEntryRequest) { |
95 scoped_ptr<FakeViewRequestDelegate> view_request_delegate( | 81 scoped_ptr<FakeViewRequestDelegate> view_request_delegate( |
96 new FakeViewRequestDelegate()); | 82 new FakeViewRequestDelegate()); |
97 ViewerHandle* viewer_handle(new ViewerHandle(ViewerHandle::CancelCallback())); | 83 ViewerHandle* viewer_handle(new ViewerHandle(ViewerHandle::CancelCallback())); |
98 EXPECT_CALL(*service_.get(), ViewEntryImpl()) | 84 EXPECT_CALL(*service_.get(), ViewEntryImpl()) |
99 .WillOnce(testing::Return(viewer_handle)); | 85 .WillOnce(testing::Return(viewer_handle)); |
100 EXPECT_CALL(*service_.get(), ViewUrlImpl()).Times(0); | 86 EXPECT_CALL(*service_.get(), ViewUrlImpl()).Times(0); |
101 CreateViewRequest(std::string("?") + kEntryIdKey + "=abc-def", | 87 CreateViewRequest(std::string("?") + kEntryIdKey + "=abc-def", |
102 view_request_delegate.get()); | 88 view_request_delegate.get()); |
103 } | 89 } |
104 | 90 |
105 TEST_F(DomDistillerViewerSourceTest, TestCreatingInvalidViewRequest) { | 91 TEST_F(DomDistillerViewerTest, TestCreatingInvalidViewRequest) { |
106 scoped_ptr<FakeViewRequestDelegate> view_request_delegate( | 92 scoped_ptr<FakeViewRequestDelegate> view_request_delegate( |
107 new FakeViewRequestDelegate()); | 93 new FakeViewRequestDelegate()); |
108 EXPECT_CALL(*service_.get(), ViewEntryImpl()).Times(0); | 94 EXPECT_CALL(*service_.get(), ViewEntryImpl()).Times(0); |
109 EXPECT_CALL(*service_.get(), ViewUrlImpl()).Times(0); | 95 EXPECT_CALL(*service_.get(), ViewUrlImpl()).Times(0); |
110 // Specify none of the required query parameters. | 96 // Specify none of the required query parameters. |
111 CreateViewRequest("?foo=bar", view_request_delegate.get()); | 97 CreateViewRequest("?foo=bar", view_request_delegate.get()); |
112 // Specify both of the required query parameters. | 98 // Specify both of the required query parameters. |
113 CreateViewRequest("?" + std::string(kUrlKey) + | 99 CreateViewRequest("?" + std::string(kUrlKey) + |
114 "=http%3A%2F%2Fwww.example.com%2F&" + | 100 "=http%3A%2F%2Fwww.example.com%2F&" + |
115 std::string(kEntryIdKey) + "=abc-def", | 101 std::string(kEntryIdKey) + "=abc-def", |
116 view_request_delegate.get()); | 102 view_request_delegate.get()); |
117 // Specify an internal Chrome page. | 103 // Specify an internal Chrome page. |
118 CreateViewRequest("?" + std::string(kUrlKey) + "=chrome%3A%2F%2Fsettings%2F", | 104 CreateViewRequest("?" + std::string(kUrlKey) + "=chrome%3A%2F%2Fsettings%2F", |
119 view_request_delegate.get()); | 105 view_request_delegate.get()); |
120 // Specify a recursive URL. | 106 // Specify a recursive URL. |
121 CreateViewRequest("?" + std::string(kUrlKey) + "=" + | 107 CreateViewRequest("?" + std::string(kUrlKey) + "=" + |
122 std::string(kTestScheme) + "%3A%2F%2Fabc-def%2F", | 108 std::string(kTestScheme) + "%3A%2F%2Fabc-def%2F", |
123 view_request_delegate.get()); | 109 view_request_delegate.get()); |
124 } | 110 } |
125 | 111 |
126 } // namespace dom_distiller | 112 } // namespace dom_distiller |
OLD | NEW |