15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved.
25d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// found in the LICENSE file.
45d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
55d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/dom_distiller/dom_distiller_service_factory.h"
65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/extensions/api/reading_list_private/reading_list_private_api.h"
75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/extensions/extension_apitest.h"
85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/profiles/profile.h"
9f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#include "components/dom_distiller/core/article_entry.h"
10116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "components/dom_distiller/core/distilled_page_prefs.h"
115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "components/dom_distiller/core/dom_distiller_service.h"
125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "components/dom_distiller/core/dom_distiller_store.h"
135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "components/dom_distiller/core/dom_distiller_test_util.h"
145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "components/dom_distiller/core/fake_distiller.h"
155c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#include "components/dom_distiller/core/fake_distiller_page.h"
16f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#include "components/leveldb_proto/testing/fake_db.h"
17116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "components/pref_registry/testing_pref_service_syncable.h"
185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
19f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)using dom_distiller::ArticleEntry;
205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)using dom_distiller::test::FakeDistiller;
215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)using dom_distiller::test::util::CreateStoreWithFakeDB;
225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)using dom_distiller::DomDistillerContextKeyedService;
235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)using dom_distiller::DomDistillerService;
245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)using dom_distiller::DistillerFactory;
255c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liuusing dom_distiller::DistillerPageFactory;
265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)using dom_distiller::DomDistillerStoreInterface;
275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)using dom_distiller::test::MockDistillerFactory;
285c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liuusing dom_distiller::test::MockDistillerPage;
295c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liuusing dom_distiller::test::MockDistillerPageFactory;
30f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)using leveldb_proto::test::FakeDB;
315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class ReadingListPrivateApiTest : public ExtensionApiTest {
335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) public:
34a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  static KeyedService* Build(content::BrowserContext* context) {
35f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    FakeDB<ArticleEntry>* fake_db =
36f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)        new FakeDB<ArticleEntry>(new FakeDB<ArticleEntry>::EntryMap);
375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    FakeDistiller* distiller = new FakeDistiller(true);
385c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    MockDistillerPage* distiller_page = new MockDistillerPage();
395c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    MockDistillerFactory* distiller_factory = new MockDistillerFactory();
405c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    MockDistillerPageFactory* distiller_page_factory =
415c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu        new MockDistillerPageFactory();
42116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
43116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    // Setting up pref service for DistilledPagePrefs.
44116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    user_prefs::TestingPrefServiceSyncable* pref_service =
45116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch        new user_prefs::TestingPrefServiceSyncable();
46116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    dom_distiller::DistilledPagePrefs::RegisterProfilePrefs(
47116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch        pref_service->registry());
48116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    DomDistillerContextKeyedService* service =
505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        new DomDistillerContextKeyedService(
515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)            scoped_ptr<DomDistillerStoreInterface>(
52f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                CreateStoreWithFakeDB(fake_db,
53f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                                      FakeDB<ArticleEntry>::EntryMap())),
545c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu            scoped_ptr<DistillerFactory>(distiller_factory),
55116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch            scoped_ptr<DistillerPageFactory>(distiller_page_factory),
56116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch            scoped_ptr<dom_distiller::DistilledPagePrefs>(
57116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch                new dom_distiller::DistilledPagePrefs(pref_service)));
585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    fake_db->InitCallback(true);
595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    fake_db->LoadCallback(true);
605c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    EXPECT_CALL(*distiller_factory, CreateDistillerImpl())
615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        .WillOnce(testing::Return(distiller));
625c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    EXPECT_CALL(*distiller_page_factory, CreateDistillerPageImpl())
635c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu        .WillOnce(testing::Return(distiller_page));
645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return service;
655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)};
675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(ReadingListPrivateApiTest, ReadingListPrivate) {
695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  dom_distiller::DomDistillerServiceFactory::GetInstance()->SetTestingFactory(
705c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      profile(), &ReadingListPrivateApiTest::Build);
715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ASSERT_TRUE(RunComponentExtensionTest("reading_list_private")) << message_;
725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
73