| 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/core/viewer.h" | 5 #include "components/dom_distiller/core/viewer.h" |
| 6 | 6 |
| 7 #include "components/dom_distiller/core/distilled_page_prefs.h" | 7 #include "components/dom_distiller/core/distilled_page_prefs.h" |
| 8 #include "components/dom_distiller/core/dom_distiller_service.h" | 8 #include "components/dom_distiller/core/dom_distiller_service.h" |
| 9 #include "components/dom_distiller/core/dom_distiller_test_util.h" | 9 #include "components/dom_distiller/core/dom_distiller_test_util.h" |
| 10 #include "components/dom_distiller/core/task_tracker.h" | 10 #include "components/dom_distiller/core/task_tracker.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 TestDomDistillerService() {} | 28 TestDomDistillerService() {} |
| 29 ~TestDomDistillerService() override {} | 29 ~TestDomDistillerService() override {} |
| 30 | 30 |
| 31 MOCK_CONST_METHOD0(GetSyncableService, syncer::SyncableService*()); | 31 MOCK_CONST_METHOD0(GetSyncableService, syncer::SyncableService*()); |
| 32 MOCK_METHOD3(AddToList, | 32 MOCK_METHOD3(AddToList, |
| 33 const std::string(const GURL&, | 33 const std::string(const GURL&, |
| 34 DistillerPage*, | 34 DistillerPage*, |
| 35 const ArticleAvailableCallback&)); | 35 const ArticleAvailableCallback&)); |
| 36 const std::string AddToList( | 36 const std::string AddToList( |
| 37 const GURL& url, | 37 const GURL& url, |
| 38 scoped_ptr<DistillerPage> distiller_page, | 38 std::unique_ptr<DistillerPage> distiller_page, |
| 39 const ArticleAvailableCallback& article_cb) override { | 39 const ArticleAvailableCallback& article_cb) override { |
| 40 return AddToList(url, distiller_page.get(), article_cb); | 40 return AddToList(url, distiller_page.get(), article_cb); |
| 41 } | 41 } |
| 42 MOCK_METHOD1(HasEntry, bool(const std::string&)); | 42 MOCK_METHOD1(HasEntry, bool(const std::string&)); |
| 43 MOCK_METHOD1(GetUrlForEntry, std::string(const std::string&)); | 43 MOCK_METHOD1(GetUrlForEntry, std::string(const std::string&)); |
| 44 MOCK_CONST_METHOD0(GetEntries, std::vector<ArticleEntry>()); | 44 MOCK_CONST_METHOD0(GetEntries, std::vector<ArticleEntry>()); |
| 45 MOCK_METHOD1(AddObserver, void(DomDistillerObserver*)); | 45 MOCK_METHOD1(AddObserver, void(DomDistillerObserver*)); |
| 46 MOCK_METHOD1(RemoveObserver, void(DomDistillerObserver*)); | 46 MOCK_METHOD1(RemoveObserver, void(DomDistillerObserver*)); |
| 47 MOCK_METHOD0(ViewUrlImpl, ViewerHandle*()); | 47 MOCK_METHOD0(ViewUrlImpl, ViewerHandle*()); |
| 48 scoped_ptr<ViewerHandle> ViewUrl( | 48 std::unique_ptr<ViewerHandle> ViewUrl( |
| 49 ViewRequestDelegate*, | 49 ViewRequestDelegate*, |
| 50 scoped_ptr<DistillerPage> distiller_page, | 50 std::unique_ptr<DistillerPage> distiller_page, |
| 51 const GURL&) override { | 51 const GURL&) override { |
| 52 return scoped_ptr<ViewerHandle>(ViewUrlImpl()); | 52 return std::unique_ptr<ViewerHandle>(ViewUrlImpl()); |
| 53 } | 53 } |
| 54 MOCK_METHOD0(ViewEntryImpl, ViewerHandle*()); | 54 MOCK_METHOD0(ViewEntryImpl, ViewerHandle*()); |
| 55 scoped_ptr<ViewerHandle> ViewEntry( | 55 std::unique_ptr<ViewerHandle> ViewEntry( |
| 56 ViewRequestDelegate*, | 56 ViewRequestDelegate*, |
| 57 scoped_ptr<DistillerPage> distiller_page, | 57 std::unique_ptr<DistillerPage> distiller_page, |
| 58 const std::string&) override { | 58 const std::string&) override { |
| 59 return scoped_ptr<ViewerHandle>(ViewEntryImpl()); | 59 return std::unique_ptr<ViewerHandle>(ViewEntryImpl()); |
| 60 } | 60 } |
| 61 MOCK_METHOD0(RemoveEntryImpl, ArticleEntry*()); | 61 MOCK_METHOD0(RemoveEntryImpl, ArticleEntry*()); |
| 62 scoped_ptr<ArticleEntry> RemoveEntry(const std::string&) override { | 62 std::unique_ptr<ArticleEntry> RemoveEntry(const std::string&) override { |
| 63 return scoped_ptr<ArticleEntry>(RemoveEntryImpl()); | 63 return std::unique_ptr<ArticleEntry>(RemoveEntryImpl()); |
| 64 } | 64 } |
| 65 scoped_ptr<DistillerPage> CreateDefaultDistillerPage( | 65 std::unique_ptr<DistillerPage> CreateDefaultDistillerPage( |
| 66 const gfx::Size& render_view_size) override { | 66 const gfx::Size& render_view_size) override { |
| 67 return scoped_ptr<DistillerPage>(); | 67 return std::unique_ptr<DistillerPage>(); |
| 68 } | 68 } |
| 69 scoped_ptr<DistillerPage> CreateDefaultDistillerPageWithHandle( | 69 std::unique_ptr<DistillerPage> CreateDefaultDistillerPageWithHandle( |
| 70 scoped_ptr<SourcePageHandle> handle) override { | 70 std::unique_ptr<SourcePageHandle> handle) override { |
| 71 return scoped_ptr<DistillerPage>(); | 71 return std::unique_ptr<DistillerPage>(); |
| 72 } | 72 } |
| 73 DistilledPagePrefs* GetDistilledPagePrefs() override; | 73 DistilledPagePrefs* GetDistilledPagePrefs() override; |
| 74 }; | 74 }; |
| 75 | 75 |
| 76 class DomDistillerViewerTest : public testing::Test { | 76 class DomDistillerViewerTest : public testing::Test { |
| 77 public: | 77 public: |
| 78 void SetUp() override { service_.reset(new TestDomDistillerService()); } | 78 void SetUp() override { service_.reset(new TestDomDistillerService()); } |
| 79 | 79 |
| 80 protected: | 80 protected: |
| 81 scoped_ptr<ViewerHandle> CreateViewRequest( | 81 std::unique_ptr<ViewerHandle> CreateViewRequest( |
| 82 const std::string& path, | 82 const std::string& path, |
| 83 ViewRequestDelegate* view_request_delegate) { | 83 ViewRequestDelegate* view_request_delegate) { |
| 84 return viewer::CreateViewRequest( | 84 return viewer::CreateViewRequest( |
| 85 service_.get(), path, view_request_delegate, gfx::Size()); | 85 service_.get(), path, view_request_delegate, gfx::Size()); |
| 86 } | 86 } |
| 87 | 87 |
| 88 scoped_ptr<TestDomDistillerService> service_; | 88 std::unique_ptr<TestDomDistillerService> service_; |
| 89 }; | 89 }; |
| 90 | 90 |
| 91 TEST_F(DomDistillerViewerTest, TestCreatingViewUrlRequest) { | 91 TEST_F(DomDistillerViewerTest, TestCreatingViewUrlRequest) { |
| 92 scoped_ptr<FakeViewRequestDelegate> view_request_delegate( | 92 std::unique_ptr<FakeViewRequestDelegate> view_request_delegate( |
| 93 new FakeViewRequestDelegate()); | 93 new FakeViewRequestDelegate()); |
| 94 ViewerHandle* viewer_handle(new ViewerHandle(ViewerHandle::CancelCallback())); | 94 ViewerHandle* viewer_handle(new ViewerHandle(ViewerHandle::CancelCallback())); |
| 95 EXPECT_CALL(*service_.get(), ViewUrlImpl()) | 95 EXPECT_CALL(*service_.get(), ViewUrlImpl()) |
| 96 .WillOnce(testing::Return(viewer_handle)); | 96 .WillOnce(testing::Return(viewer_handle)); |
| 97 EXPECT_CALL(*service_.get(), ViewEntryImpl()).Times(0); | 97 EXPECT_CALL(*service_.get(), ViewEntryImpl()).Times(0); |
| 98 CreateViewRequest( | 98 CreateViewRequest( |
| 99 std::string("?") + kUrlKey + "=http%3A%2F%2Fwww.example.com%2F", | 99 std::string("?") + kUrlKey + "=http%3A%2F%2Fwww.example.com%2F", |
| 100 view_request_delegate.get()); | 100 view_request_delegate.get()); |
| 101 } | 101 } |
| 102 | 102 |
| 103 TEST_F(DomDistillerViewerTest, TestCreatingViewEntryRequest) { | 103 TEST_F(DomDistillerViewerTest, TestCreatingViewEntryRequest) { |
| 104 scoped_ptr<FakeViewRequestDelegate> view_request_delegate( | 104 std::unique_ptr<FakeViewRequestDelegate> view_request_delegate( |
| 105 new FakeViewRequestDelegate()); | 105 new FakeViewRequestDelegate()); |
| 106 ViewerHandle* viewer_handle(new ViewerHandle(ViewerHandle::CancelCallback())); | 106 ViewerHandle* viewer_handle(new ViewerHandle(ViewerHandle::CancelCallback())); |
| 107 EXPECT_CALL(*service_.get(), ViewEntryImpl()) | 107 EXPECT_CALL(*service_.get(), ViewEntryImpl()) |
| 108 .WillOnce(testing::Return(viewer_handle)); | 108 .WillOnce(testing::Return(viewer_handle)); |
| 109 EXPECT_CALL(*service_.get(), ViewUrlImpl()).Times(0); | 109 EXPECT_CALL(*service_.get(), ViewUrlImpl()).Times(0); |
| 110 CreateViewRequest(std::string("?") + kEntryIdKey + "=abc-def", | 110 CreateViewRequest(std::string("?") + kEntryIdKey + "=abc-def", |
| 111 view_request_delegate.get()); | 111 view_request_delegate.get()); |
| 112 } | 112 } |
| 113 | 113 |
| 114 TEST_F(DomDistillerViewerTest, TestCreatingInvalidViewRequest) { | 114 TEST_F(DomDistillerViewerTest, TestCreatingInvalidViewRequest) { |
| 115 scoped_ptr<FakeViewRequestDelegate> view_request_delegate( | 115 std::unique_ptr<FakeViewRequestDelegate> view_request_delegate( |
| 116 new FakeViewRequestDelegate()); | 116 new FakeViewRequestDelegate()); |
| 117 EXPECT_CALL(*service_.get(), ViewEntryImpl()).Times(0); | 117 EXPECT_CALL(*service_.get(), ViewEntryImpl()).Times(0); |
| 118 EXPECT_CALL(*service_.get(), ViewUrlImpl()).Times(0); | 118 EXPECT_CALL(*service_.get(), ViewUrlImpl()).Times(0); |
| 119 // Specify none of the required query parameters. | 119 // Specify none of the required query parameters. |
| 120 CreateViewRequest("?foo=bar", view_request_delegate.get()); | 120 CreateViewRequest("?foo=bar", view_request_delegate.get()); |
| 121 // Specify both of the required query parameters. | 121 // Specify both of the required query parameters. |
| 122 CreateViewRequest("?" + std::string(kUrlKey) + | 122 CreateViewRequest("?" + std::string(kUrlKey) + |
| 123 "=http%3A%2F%2Fwww.example.com%2F&" + | 123 "=http%3A%2F%2Fwww.example.com%2F&" + |
| 124 std::string(kEntryIdKey) + "=abc-def", | 124 std::string(kEntryIdKey) + "=abc-def", |
| 125 view_request_delegate.get()); | 125 view_request_delegate.get()); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 0); | 160 0); |
| 161 EXPECT_EQ(kMonospaceJsFontFamily.compare(viewer::GetDistilledPageFontFamilyJs( | 161 EXPECT_EQ(kMonospaceJsFontFamily.compare(viewer::GetDistilledPageFontFamilyJs( |
| 162 DistilledPagePrefs::MONOSPACE)), | 162 DistilledPagePrefs::MONOSPACE)), |
| 163 0); | 163 0); |
| 164 EXPECT_EQ(kSansSerifJsFontFamily.compare(viewer::GetDistilledPageFontFamilyJs( | 164 EXPECT_EQ(kSansSerifJsFontFamily.compare(viewer::GetDistilledPageFontFamilyJs( |
| 165 DistilledPagePrefs::SANS_SERIF)), | 165 DistilledPagePrefs::SANS_SERIF)), |
| 166 0); | 166 0); |
| 167 } | 167 } |
| 168 | 168 |
| 169 } // namespace dom_distiller | 169 } // namespace dom_distiller |
| OLD | NEW |