Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1101)

Side by Side Diff: components/offline_pages/core/prefetch/prefetch_dispatcher_impl_unittest.cc

Issue 2879013002: Create skeleton for the Prefetching store and initial pipeline step. (Closed)
Patch Set: A couple of minor changes. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/offline_pages/core/prefetch/prefetch_dispatcher_impl.h" 5 #include "components/offline_pages/core/prefetch/prefetch_dispatcher_impl.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/test/test_simple_task_runner.h"
9 #include "base/threading/thread_task_runner_handle.h"
8 #include "components/offline_pages/core/client_namespace_constants.h" 10 #include "components/offline_pages/core/client_namespace_constants.h"
9 #include "components/offline_pages/core/prefetch/prefetch_dispatcher.h" 11 #include "components/offline_pages/core/prefetch/prefetch_test_store.h"
10 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
11 #include "url/gurl.h"
12 13
13 namespace offline_pages { 14 namespace offline_pages {
14 15
15 TEST(PrefetchDispatcherTest, DispatcherDoesNotCrash) { 16 class PrefetchDispatcherTest : public testing::Test {
16 PrefetchDispatcherImpl dispatcher; 17 public:
18 PrefetchDispatcherTest();
17 19
18 dispatcher.AddCandidatePrefetchURLs( 20 void SetUp() override;
19 std::vector<PrefetchDispatcher::PrefetchURL>()); 21 void TearDown() override;
20 dispatcher.RemoveAllUnprocessedPrefetchURLs(kSuggestedArticlesNamespace); 22
21 dispatcher.RemovePrefetchURLsByClientId({kSuggestedArticlesNamespace, "123"}); 23 PrefetchDispatcherImpl* dispatcher() { return dispatcher_.get(); }
24
25 TaskQueue* dispatcher_task_queue() { return &dispatcher()->task_queue_; }
26
27 private:
28 std::unique_ptr<PrefetchDispatcherImpl> dispatcher_;
29 scoped_refptr<base::TestSimpleTaskRunner> task_runner_;
30 base::ThreadTaskRunnerHandle task_runner_handle_;
31 };
32
33 PrefetchDispatcherTest::PrefetchDispatcherTest()
34 : task_runner_(new base::TestSimpleTaskRunner),
35 task_runner_handle_(task_runner_) {}
36
37 void PrefetchDispatcherTest::SetUp() {
38 ASSERT_EQ(base::ThreadTaskRunnerHandle::Get(), task_runner_);
39 ASSERT_FALSE(task_runner_->HasPendingTask());
40 std::unique_ptr<PrefetchStore> store = base::MakeUnique<PrefetchTestStore>();
41 dispatcher_ = base::MakeUnique<PrefetchDispatcherImpl>(std::move(store));
42 }
43
44 void PrefetchDispatcherTest::TearDown() {
45 task_runner_->ClearPendingTasks();
46 }
47
48 TEST_F(PrefetchDispatcherTest, DispatcherDoesNotCrash) {
49 dispatcher()->AddCandidatePrefetchURLs(kSuggestedArticlesNamespace,
50 std::vector<PrefetchURL>());
51 EXPECT_TRUE(dispatcher_task_queue()->HasPendingTasks());
52 EXPECT_TRUE(dispatcher_task_queue()->HasRunningTask());
53 dispatcher()->RemoveAllUnprocessedPrefetchURLs(kSuggestedArticlesNamespace);
54 dispatcher()->RemovePrefetchURLsByClientId(kSuggestedArticlesNamespace,
55 "123");
22 } 56 }
23 57
24 } // namespace offline_pages 58 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698