diff options
author | yfriedman@chromium.org <yfriedman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-14 13:40:32 +0000 |
---|---|---|
committer | yfriedman@chromium.org <yfriedman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-14 13:40:32 +0000 |
commit | 2eb48e684368d538564e253a6eb6c33f88132326 (patch) | |
tree | 9e77f55d0b0b9195daaa1bce6bdb01acb016cdc1 /components | |
parent | 03fae593b4ecd610248d6260262a556beaad8b6a (diff) | |
download | chromium_src-2eb48e684368d538564e253a6eb6c33f88132326.zip chromium_src-2eb48e684368d538564e253a6eb6c33f88132326.tar.gz chromium_src-2eb48e684368d538564e253a6eb6c33f88132326.tar.bz2 |
Implement initial of chrome.readingListPrivate api.
For experimentation with the dom distiller component, this provides a minimal API wrapping the functions of DomDistillerService.
Sketch proposal:
https://docs.google.com/a/google.com/document/d/1zLTKNAOkTyFpgeJqWg3Jn17Ayc-sYafyftBE6KUldV4/edit
BUG=288015
TBR=joi
Review URL: https://codereview.chromium.org/116553005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@244681 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'components')
-rw-r--r-- | components/components_tests.gyp | 7 | ||||
-rw-r--r-- | components/dom_distiller.gypi | 20 | ||||
-rw-r--r-- | components/dom_distiller/core/dom_distiller_service.cc | 15 | ||||
-rw-r--r-- | components/dom_distiller/core/dom_distiller_service.h | 2 | ||||
-rw-r--r-- | components/dom_distiller/core/dom_distiller_service_unittest.cc | 21 | ||||
-rw-r--r-- | components/dom_distiller/core/fake_distiller.cc | 3 | ||||
-rw-r--r-- | components/dom_distiller/core/fake_distiller.h | 6 | ||||
-rw-r--r-- | components/dom_distiller/core/task_tracker_unittest.cc | 6 |
8 files changed, 51 insertions, 29 deletions
diff --git a/components/components_tests.gyp b/components/components_tests.gyp index d16e68b..291b548 100644 --- a/components/components_tests.gyp +++ b/components/components_tests.gyp @@ -31,12 +31,6 @@ 'dom_distiller/core/dom_distiller_model_unittest.cc', 'dom_distiller/core/dom_distiller_service_unittest.cc', 'dom_distiller/core/dom_distiller_store_unittest.cc', - 'dom_distiller/core/dom_distiller_test_util.cc', - 'dom_distiller/core/dom_distiller_test_util.h', - 'dom_distiller/core/fake_db.cc', - 'dom_distiller/core/fake_db.h', - 'dom_distiller/core/fake_distiller.cc', - 'dom_distiller/core/fake_distiller.h', 'dom_distiller/core/task_tracker_unittest.cc', 'json_schema/json_schema_validator_unittest.cc', 'json_schema/json_schema_validator_unittest_base.cc', @@ -97,6 +91,7 @@ # Dependencies of dom_distiller 'components.gyp:distilled_page_proto', 'components.gyp:dom_distiller_core', + 'components.gyp:dom_distiller_test_support', # Dependencies of encryptor 'components.gyp:encryptor', diff --git a/components/dom_distiller.gypi b/components/dom_distiller.gypi index 3966835..978fddf 100644 --- a/components/dom_distiller.gypi +++ b/components/dom_distiller.gypi @@ -89,6 +89,26 @@ ], }, { + 'target_name': 'dom_distiller_test_support', + 'type': 'static_library', + 'dependencies': [ + 'dom_distiller_core', + '../sync/sync.gyp:sync', + '../testing/gmock.gyp:gmock', + ], + 'include_dirs': [ + '..', + ], + 'sources': [ + 'dom_distiller/core/dom_distiller_test_util.cc', + 'dom_distiller/core/dom_distiller_test_util.h', + 'dom_distiller/core/fake_db.cc', + 'dom_distiller/core/fake_db.h', + 'dom_distiller/core/fake_distiller.cc', + 'dom_distiller/core/fake_distiller.h', + ], + }, + { 'target_name': 'distilled_page_proto', 'type': 'static_library', 'sources': [ diff --git a/components/dom_distiller/core/dom_distiller_service.cc b/components/dom_distiller/core/dom_distiller_service.cc index 65791c4f..797827b 100644 --- a/components/dom_distiller/core/dom_distiller_service.cc +++ b/components/dom_distiller/core/dom_distiller_service.cc @@ -87,19 +87,22 @@ std::vector<ArticleEntry> DomDistillerService::GetEntries() const { return store_->GetEntries(); } -void DomDistillerService::RemoveEntry( +scoped_ptr<ArticleEntry> DomDistillerService::RemoveEntry( const std::string& entry_id) { - ArticleEntry entry; - if (!store_->GetEntryById(entry_id, &entry)) { - return; + scoped_ptr<ArticleEntry> entry(new ArticleEntry); + if (!store_->GetEntryById(entry_id, entry.get())) { + return scoped_ptr<ArticleEntry>(); } - TaskTracker* task_tracker = GetTaskTrackerForEntry(entry); + TaskTracker* task_tracker = GetTaskTrackerForEntry(*entry); if (task_tracker != NULL) { task_tracker->CancelSaveCallbacks(); } - store_->RemoveEntry(entry); + if (store_->RemoveEntry(*entry)) { + return entry.Pass(); + } + return scoped_ptr<ArticleEntry>(); } scoped_ptr<ViewerHandle> DomDistillerService::ViewEntry( diff --git a/components/dom_distiller/core/dom_distiller_service.h b/components/dom_distiller/core/dom_distiller_service.h index d730cf6..ed045cd 100644 --- a/components/dom_distiller/core/dom_distiller_service.h +++ b/components/dom_distiller/core/dom_distiller_service.h @@ -51,7 +51,7 @@ class DomDistillerService { std::vector<ArticleEntry> GetEntries() const; // Removes the specified entry from the dom distiller store. - void RemoveEntry(const std::string& entry_id); + scoped_ptr<ArticleEntry> RemoveEntry(const std::string& entry_id); // Request to view an article by entry id. Returns a null pointer if no entry // with |entry_id| exists. The ViewerHandle should be destroyed before the diff --git a/components/dom_distiller/core/dom_distiller_service_unittest.cc b/components/dom_distiller/core/dom_distiller_service_unittest.cc index e010821..4719cd2 100644 --- a/components/dom_distiller/core/dom_distiller_service_unittest.cc +++ b/components/dom_distiller/core/dom_distiller_service_unittest.cc @@ -5,6 +5,7 @@ #include "components/dom_distiller/core/dom_distiller_service.h" #include "base/bind.h" +#include "base/callback.h" #include "base/containers/hash_tables.h" #include "base/message_loop/message_loop.h" #include "base/run_loop.h" @@ -90,7 +91,7 @@ class DomDistillerServiceTest : public testing::Test { }; TEST_F(DomDistillerServiceTest, TestViewEntry) { - FakeDistiller* distiller = new FakeDistiller(); + FakeDistiller* distiller = new FakeDistiller(false); EXPECT_CALL(*distiller_factory_, CreateDistillerImpl()) .WillOnce(Return(distiller)); @@ -115,7 +116,7 @@ TEST_F(DomDistillerServiceTest, TestViewEntry) { } TEST_F(DomDistillerServiceTest, TestViewUrl) { - FakeDistiller* distiller = new FakeDistiller(); + FakeDistiller* distiller = new FakeDistiller(false); EXPECT_CALL(*distiller_factory_, CreateDistillerImpl()) .WillOnce(Return(distiller)); @@ -133,8 +134,8 @@ TEST_F(DomDistillerServiceTest, TestViewUrl) { } TEST_F(DomDistillerServiceTest, TestMultipleViewUrl) { - FakeDistiller* distiller = new FakeDistiller(); - FakeDistiller* distiller2 = new FakeDistiller(); + FakeDistiller* distiller = new FakeDistiller(false); + FakeDistiller* distiller2 = new FakeDistiller(false); EXPECT_CALL(*distiller_factory_, CreateDistillerImpl()) .WillOnce(Return(distiller)) .WillOnce(Return(distiller2)); @@ -166,7 +167,7 @@ TEST_F(DomDistillerServiceTest, TestMultipleViewUrl) { } TEST_F(DomDistillerServiceTest, TestViewUrlCancelled) { - FakeDistiller* distiller = new FakeDistiller(); + FakeDistiller* distiller = new FakeDistiller(false); EXPECT_CALL(*distiller_factory_, CreateDistillerImpl()) .WillOnce(Return(distiller)); @@ -191,7 +192,7 @@ TEST_F(DomDistillerServiceTest, TestViewUrlCancelled) { } TEST_F(DomDistillerServiceTest, TestAddAndRemoveEntry) { - FakeDistiller* distiller = new FakeDistiller(); + FakeDistiller* distiller = new FakeDistiller(false); EXPECT_CALL(*distiller_factory_, CreateDistillerImpl()) .WillOnce(Return(distiller)); @@ -220,7 +221,7 @@ TEST_F(DomDistillerServiceTest, TestAddAndRemoveEntry) { } TEST_F(DomDistillerServiceTest, TestCancellation) { - FakeDistiller* distiller = new FakeDistiller(); + FakeDistiller* distiller = new FakeDistiller(false); MockDistillerObserver observer; service_->AddObserver(&observer); @@ -251,7 +252,7 @@ TEST_F(DomDistillerServiceTest, TestCancellation) { } TEST_F(DomDistillerServiceTest, TestMultipleObservers) { - FakeDistiller* distiller = new FakeDistiller(); + FakeDistiller* distiller = new FakeDistiller(false); EXPECT_CALL(*distiller_factory_, CreateDistillerImpl()) .WillOnce(Return(distiller)); @@ -297,7 +298,7 @@ TEST_F(DomDistillerServiceTest, TestMultipleObservers) { } TEST_F(DomDistillerServiceTest, TestMultipleCallbacks) { - FakeDistiller* distiller = new FakeDistiller(); + FakeDistiller* distiller = new FakeDistiller(false); EXPECT_CALL(*distiller_factory_, CreateDistillerImpl()) .WillOnce(Return(distiller)); @@ -329,7 +330,7 @@ TEST_F(DomDistillerServiceTest, TestMultipleCallbacks) { } TEST_F(DomDistillerServiceTest, TestMultipleCallbacksOnRemove) { - FakeDistiller* distiller = new FakeDistiller(); + FakeDistiller* distiller = new FakeDistiller(false); EXPECT_CALL(*distiller_factory_, CreateDistillerImpl()) .WillOnce(Return(distiller)); diff --git a/components/dom_distiller/core/fake_distiller.cc b/components/dom_distiller/core/fake_distiller.cc index 93659b3..3f1f976 100644 --- a/components/dom_distiller/core/fake_distiller.cc +++ b/components/dom_distiller/core/fake_distiller.cc @@ -14,7 +14,8 @@ namespace test { MockDistillerFactory::MockDistillerFactory() {} MockDistillerFactory::~MockDistillerFactory() {} -FakeDistiller::FakeDistiller() { +FakeDistiller::FakeDistiller(bool execute_callback) : + execute_callback_(execute_callback) { EXPECT_CALL(*this, Die()).Times(testing::AnyNumber()); } diff --git a/components/dom_distiller/core/fake_distiller.h b/components/dom_distiller/core/fake_distiller.h index ef9126c..dbb00d6 100644 --- a/components/dom_distiller/core/fake_distiller.h +++ b/components/dom_distiller/core/fake_distiller.h @@ -27,7 +27,7 @@ class MockDistillerFactory : public DistillerFactory { class FakeDistiller : public Distiller { public: - FakeDistiller(); + FakeDistiller(bool execute_callback); virtual ~FakeDistiller(); MOCK_METHOD0(Die, void()); @@ -35,6 +35,9 @@ class FakeDistiller : public Distiller { const DistillerCallback& callback) OVERRIDE { url_ = url; callback_ = callback; + if (execute_callback_) { + RunDistillerCallback(make_scoped_ptr(new DistilledPageProto)); + } } void RunDistillerCallback(scoped_ptr<DistilledPageProto> proto); @@ -46,6 +49,7 @@ class FakeDistiller : public Distiller { private: void RunDistillerCallbackInternal(scoped_ptr<DistilledPageProto> proto); + bool execute_callback_; GURL url_; DistillerCallback callback_; }; diff --git a/components/dom_distiller/core/task_tracker_unittest.cc b/components/dom_distiller/core/task_tracker_unittest.cc index 2d3ad8a..f659fc1 100644 --- a/components/dom_distiller/core/task_tracker_unittest.cc +++ b/components/dom_distiller/core/task_tracker_unittest.cc @@ -119,7 +119,7 @@ TEST_F(DomDistillerTaskTrackerTest, TestViewerCancelledWithSaveRequest) { TEST_F(DomDistillerTaskTrackerTest, TestViewerNotifiedOnDistillationComplete) { MockDistillerFactory distiller_factory; - FakeDistiller* distiller = new FakeDistiller(); + FakeDistiller* distiller = new FakeDistiller(true); EXPECT_CALL(distiller_factory, CreateDistillerImpl()) .WillOnce(Return(distiller)); TestCancelCallback cancel_callback; @@ -132,7 +132,6 @@ TEST_F(DomDistillerTaskTrackerTest, TestViewerNotifiedOnDistillationComplete) { EXPECT_CALL(viewer_delegate, OnArticleReady(_)); task_tracker.StartDistiller(&distiller_factory); - distiller->RunDistillerCallback(make_scoped_ptr(new DistilledPageProto)); base::RunLoop().RunUntilIdle(); EXPECT_FALSE(cancel_callback.Cancelled()); @@ -141,7 +140,7 @@ TEST_F(DomDistillerTaskTrackerTest, TestViewerNotifiedOnDistillationComplete) { TEST_F(DomDistillerTaskTrackerTest, TestSaveCallbackCalledOnDistillationComplete) { MockDistillerFactory distiller_factory; - FakeDistiller* distiller = new FakeDistiller(); + FakeDistiller* distiller = new FakeDistiller(true); EXPECT_CALL(distiller_factory, CreateDistillerImpl()) .WillOnce(Return(distiller)); TestCancelCallback cancel_callback; @@ -155,7 +154,6 @@ TEST_F(DomDistillerTaskTrackerTest, EXPECT_CALL(save_callback, Save(_, _, _)); task_tracker.StartDistiller(&distiller_factory); - distiller->RunDistillerCallback(make_scoped_ptr(new DistilledPageProto)); base::RunLoop().RunUntilIdle(); EXPECT_TRUE(cancel_callback.Cancelled()); |