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

Unified 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 side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698