ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / content / browser / service_worker / service_worker_cache_scheduler_unittest.cc
blob0520ca2fb9059b7bdfba26ba0aad77bcd816ca60
1 // Copyright 2015 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.
5 #include "content/browser/service_worker/service_worker_cache_scheduler.h"
7 #include "base/bind.h"
8 #include "base/callback.h"
9 #include "base/run_loop.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 namespace content {
14 namespace {
16 class JobStats {
17 public:
18 JobStats(ServiceWorkerCacheScheduler* scheduler)
19 : scheduler_(scheduler), callback_count_(0) {}
21 virtual void Run() = 0;
23 int callback_count() const { return callback_count_; }
25 protected:
26 ServiceWorkerCacheScheduler* scheduler_;
27 int callback_count_;
30 class SyncJob : public JobStats {
31 public:
32 SyncJob(ServiceWorkerCacheScheduler* scheduler) : JobStats(scheduler) {}
34 void Run() override {
35 callback_count_++;
36 scheduler_->CompleteOperationAndRunNext();
40 class AsyncJob : public JobStats {
41 public:
42 AsyncJob(ServiceWorkerCacheScheduler* scheduler) : JobStats(scheduler) {}
44 void Run() override { callback_count_++; }
45 void Done() { scheduler_->CompleteOperationAndRunNext(); }
48 } // namespace
50 class ServiceWorkerCacheSchedulerTest : public testing::Test {
51 protected:
52 ServiceWorkerCacheSchedulerTest()
53 : async_job_(AsyncJob(&scheduler_)), sync_job_(SyncJob(&scheduler_)) {}
55 ServiceWorkerCacheScheduler scheduler_;
56 AsyncJob async_job_;
57 SyncJob sync_job_;
60 TEST_F(ServiceWorkerCacheSchedulerTest, ScheduleOne) {
61 scheduler_.ScheduleOperation(
62 base::Bind(&JobStats::Run, base::Unretained(&sync_job_)));
63 EXPECT_EQ(1, sync_job_.callback_count());
66 TEST_F(ServiceWorkerCacheSchedulerTest, ScheduleTwo) {
67 scheduler_.ScheduleOperation(
68 base::Bind(&JobStats::Run, base::Unretained(&sync_job_)));
69 scheduler_.ScheduleOperation(
70 base::Bind(&JobStats::Run, base::Unretained(&sync_job_)));
71 EXPECT_EQ(2, sync_job_.callback_count());
74 TEST_F(ServiceWorkerCacheSchedulerTest, Block) {
75 scheduler_.ScheduleOperation(
76 base::Bind(&JobStats::Run, base::Unretained(&async_job_)));
77 EXPECT_EQ(1, async_job_.callback_count());
78 scheduler_.ScheduleOperation(
79 base::Bind(&JobStats::Run, base::Unretained(&sync_job_)));
80 EXPECT_EQ(0, sync_job_.callback_count());
81 async_job_.Done();
82 EXPECT_EQ(1, sync_job_.callback_count());
85 } // namespace content