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 "base/message_loop/message_loop.h"
9 #include "testing/gmock/include/gmock/gmock.h"
10 #include "testing/gtest/include/gtest/gtest.h"
14 class WorkerTaskRunnerTest
: public testing::Test
{
17 task_runner_
.OnWorkerRunLoopStarted();
20 task_runner_
.OnWorkerRunLoopStopped();
22 WorkerTaskRunner task_runner_
;
25 base::MessageLoop message_loop_
;
28 class MockObserver
: public WorkerTaskRunner::Observer
{
30 MOCK_METHOD0(OnWorkerRunLoopStopped
, void());
31 void RemoveSelfOnNotify() {
32 ON_CALL(*this, OnWorkerRunLoopStopped()).WillByDefault(
33 testing::Invoke(this, &MockObserver::RemoveSelf
));
36 runner_
->RemoveStopObserver(this);
38 WorkerTaskRunner
* runner_
;
41 TEST_F(WorkerTaskRunnerTest
, BasicObservingAndWorkerId
) {
42 ASSERT_EQ(0, task_runner_
.CurrentWorkerId());
44 EXPECT_CALL(o
, OnWorkerRunLoopStopped()).Times(1);
46 task_runner_
.AddStopObserver(&o
);
47 ASSERT_LT(0, task_runner_
.CurrentWorkerId());
51 TEST_F(WorkerTaskRunnerTest
, CanRemoveSelfDuringNotification
) {
53 o
.RemoveSelfOnNotify();
54 o
.runner_
= &task_runner_
;
55 EXPECT_CALL(o
, OnWorkerRunLoopStopped()).Times(1);
57 task_runner_
.AddStopObserver(&o
);
61 } // namespace content