Index: components/offline_pages/core/prefetch/prefetch_dispatcher_impl_unittest.cc |
diff --git a/components/offline_pages/core/prefetch/prefetch_dispatcher_impl_unittest.cc b/components/offline_pages/core/prefetch/prefetch_dispatcher_impl_unittest.cc |
index 0a0bd961d48bad5e40043b5722d0a71b2c1c900c..10634b2879448997271427fe765b89ec5a44d6f8 100644 |
--- a/components/offline_pages/core/prefetch/prefetch_dispatcher_impl_unittest.cc |
+++ b/components/offline_pages/core/prefetch/prefetch_dispatcher_impl_unittest.cc |
@@ -5,20 +5,54 @@ |
#include "components/offline_pages/core/prefetch/prefetch_dispatcher_impl.h" |
#include "base/memory/ptr_util.h" |
+#include "base/test/test_simple_task_runner.h" |
+#include "base/threading/thread_task_runner_handle.h" |
#include "components/offline_pages/core/client_namespace_constants.h" |
-#include "components/offline_pages/core/prefetch/prefetch_dispatcher.h" |
+#include "components/offline_pages/core/prefetch/prefetch_test_store.h" |
#include "testing/gtest/include/gtest/gtest.h" |
-#include "url/gurl.h" |
namespace offline_pages { |
-TEST(PrefetchDispatcherTest, DispatcherDoesNotCrash) { |
- PrefetchDispatcherImpl dispatcher; |
+class PrefetchDispatcherTest : public testing::Test { |
+ public: |
+ PrefetchDispatcherTest(); |
- dispatcher.AddCandidatePrefetchURLs( |
- std::vector<PrefetchDispatcher::PrefetchURL>()); |
- dispatcher.RemoveAllUnprocessedPrefetchURLs(kSuggestedArticlesNamespace); |
- dispatcher.RemovePrefetchURLsByClientId({kSuggestedArticlesNamespace, "123"}); |
+ void SetUp() override; |
+ void TearDown() override; |
+ |
+ PrefetchDispatcherImpl* dispatcher() { return dispatcher_.get(); } |
+ |
+ TaskQueue* dispatcher_task_queue() { return &dispatcher()->task_queue_; } |
+ |
+ private: |
+ std::unique_ptr<PrefetchDispatcherImpl> dispatcher_; |
+ scoped_refptr<base::TestSimpleTaskRunner> task_runner_; |
+ base::ThreadTaskRunnerHandle task_runner_handle_; |
+}; |
+ |
+PrefetchDispatcherTest::PrefetchDispatcherTest() |
+ : task_runner_(new base::TestSimpleTaskRunner), |
+ task_runner_handle_(task_runner_) {} |
+ |
+void PrefetchDispatcherTest::SetUp() { |
+ ASSERT_EQ(base::ThreadTaskRunnerHandle::Get(), task_runner_); |
+ ASSERT_FALSE(task_runner_->HasPendingTask()); |
+ std::unique_ptr<PrefetchStore> store = base::MakeUnique<PrefetchTestStore>(); |
+ dispatcher_ = base::MakeUnique<PrefetchDispatcherImpl>(std::move(store)); |
+} |
+ |
+void PrefetchDispatcherTest::TearDown() { |
+ task_runner_->ClearPendingTasks(); |
+} |
+ |
+TEST_F(PrefetchDispatcherTest, DispatcherDoesNotCrash) { |
+ dispatcher()->AddCandidatePrefetchURLs(kSuggestedArticlesNamespace, |
+ std::vector<PrefetchURL>()); |
+ EXPECT_TRUE(dispatcher_task_queue()->HasPendingTasks()); |
+ EXPECT_TRUE(dispatcher_task_queue()->HasRunningTask()); |
+ dispatcher()->RemoveAllUnprocessedPrefetchURLs(kSuggestedArticlesNamespace); |
+ dispatcher()->RemovePrefetchURLsByClientId(kSuggestedArticlesNamespace, |
+ "123"); |
} |
} // namespace offline_pages |