1 // Copyright 2014 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/child/worker_task_runner.h"
7 #include "base/logging.h"
8 #include "testing/gmock/include/gmock/gmock.h"
9 #include "testing/gtest/include/gtest/gtest.h"
13 class WorkerTaskRunnerTest
: public testing::Test
{
16 task_runner_
.OnWorkerRunLoopStarted(blink::WebWorkerRunLoop());
19 task_runner_
.OnWorkerRunLoopStopped(blink::WebWorkerRunLoop());
21 WorkerTaskRunner task_runner_
;
24 class MockObserver
: public WorkerTaskRunner::Observer
{
26 MOCK_METHOD0(OnWorkerRunLoopStopped
, void());
27 void RemoveSelfOnNotify() {
28 ON_CALL(*this, OnWorkerRunLoopStopped()).WillByDefault(
29 testing::Invoke(this, &MockObserver::RemoveSelf
));
32 runner_
->RemoveStopObserver(this);
34 WorkerTaskRunner
* runner_
;
37 TEST_F(WorkerTaskRunnerTest
, BasicObservingAndWorkerId
) {
38 ASSERT_EQ(0, task_runner_
.CurrentWorkerId());
40 EXPECT_CALL(o
, OnWorkerRunLoopStopped()).Times(1);
42 task_runner_
.AddStopObserver(&o
);
43 ASSERT_LT(0, task_runner_
.CurrentWorkerId());
47 TEST_F(WorkerTaskRunnerTest
, CanRemoveSelfDuringNotification
) {
49 o
.RemoveSelfOnNotify();
50 o
.runner_
= &task_runner_
;
51 EXPECT_CALL(o
, OnWorkerRunLoopStopped()).Times(1);
53 task_runner_
.AddStopObserver(&o
);
57 } // namespace content