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 "chrome/browser/dom_distiller/dom_distiller_service_factory.h" 6 #include "chrome/browser/extensions/api/reading_list_private/reading_list_private_api.h" 7 #include "chrome/browser/extensions/extension_apitest.h" 8 #include "chrome/browser/profiles/profile.h" 9 #include "components/dom_distiller/core/article_entry.h" 10 #include "components/dom_distiller/core/dom_distiller_service.h" 11 #include "components/dom_distiller/core/dom_distiller_store.h" 12 #include "components/dom_distiller/core/dom_distiller_test_util.h" 13 #include "components/dom_distiller/core/fake_distiller.h" 14 #include "components/dom_distiller/core/fake_distiller_page.h" 15 #include "components/leveldb_proto/testing/fake_db.h" 16 17 using dom_distiller::ArticleEntry; 18 using dom_distiller::test::FakeDistiller; 19 using dom_distiller::test::util::CreateStoreWithFakeDB; 20 using dom_distiller::DomDistillerContextKeyedService; 21 using dom_distiller::DomDistillerService; 22 using dom_distiller::DistillerFactory; 23 using dom_distiller::DistillerPageFactory; 24 using dom_distiller::DomDistillerStoreInterface; 25 using dom_distiller::test::MockDistillerFactory; 26 using dom_distiller::test::MockDistillerPage; 27 using dom_distiller::test::MockDistillerPageFactory; 28 using leveldb_proto::test::FakeDB; 29 30 class ReadingListPrivateApiTest : public ExtensionApiTest { 31 public: Build(content::BrowserContext * context)32 static KeyedService* Build(content::BrowserContext* context) { 33 FakeDB<ArticleEntry>* fake_db = 34 new FakeDB<ArticleEntry>(new FakeDB<ArticleEntry>::EntryMap); 35 FakeDistiller* distiller = new FakeDistiller(true); 36 MockDistillerPage* distiller_page = new MockDistillerPage(); 37 MockDistillerFactory* distiller_factory = new MockDistillerFactory(); 38 MockDistillerPageFactory* distiller_page_factory = 39 new MockDistillerPageFactory(); 40 DomDistillerContextKeyedService* service = 41 new DomDistillerContextKeyedService( 42 scoped_ptr<DomDistillerStoreInterface>( 43 CreateStoreWithFakeDB(fake_db, 44 FakeDB<ArticleEntry>::EntryMap())), 45 scoped_ptr<DistillerFactory>(distiller_factory), 46 scoped_ptr<DistillerPageFactory>(distiller_page_factory)); 47 fake_db->InitCallback(true); 48 fake_db->LoadCallback(true); 49 EXPECT_CALL(*distiller_factory, CreateDistillerImpl()) 50 .WillOnce(testing::Return(distiller)); 51 EXPECT_CALL(*distiller_page_factory, CreateDistillerPageImpl()) 52 .WillOnce(testing::Return(distiller_page)); 53 return service; 54 } 55 }; 56 IN_PROC_BROWSER_TEST_F(ReadingListPrivateApiTest,ReadingListPrivate)57IN_PROC_BROWSER_TEST_F(ReadingListPrivateApiTest, ReadingListPrivate) { 58 dom_distiller::DomDistillerServiceFactory::GetInstance()->SetTestingFactory( 59 profile(), &ReadingListPrivateApiTest::Build); 60 ASSERT_TRUE(RunComponentExtensionTest("reading_list_private")) << message_; 61 } 62