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 "content/public/child/worker_thread.h"
10 #include "testing/gmock/include/gmock/gmock.h"
11 #include "testing/gtest/include/gtest/gtest.h"
15 class WorkerTaskRunnerTest
: public testing::Test
{
17 void FakeStart() { task_runner_
.DidStartWorkerRunLoop(); }
18 void FakeStop() { task_runner_
.WillStopWorkerRunLoop(); }
19 WorkerTaskRunner task_runner_
;
22 base::MessageLoop message_loop_
;
25 class MockObserver
: public WorkerThread::Observer
{
27 MOCK_METHOD0(WillStopCurrentWorkerThread
, void());
28 void RemoveSelfOnNotify() {
29 ON_CALL(*this, WillStopCurrentWorkerThread())
30 .WillByDefault(testing::Invoke(this, &MockObserver::RemoveSelf
));
32 void RemoveSelf() { WorkerThread::RemoveObserver(this); }
33 WorkerTaskRunner
* runner_
;
36 TEST_F(WorkerTaskRunnerTest
, BasicObservingAndWorkerId
) {
37 ASSERT_EQ(0, WorkerThread::GetCurrentId());
39 EXPECT_CALL(o
, WillStopCurrentWorkerThread()).Times(1);
41 WorkerThread::AddObserver(&o
);
42 ASSERT_LT(0, WorkerThread::GetCurrentId());
46 TEST_F(WorkerTaskRunnerTest
, CanRemoveSelfDuringNotification
) {
48 o
.RemoveSelfOnNotify();
49 o
.runner_
= &task_runner_
;
50 EXPECT_CALL(o
, WillStopCurrentWorkerThread()).Times(1);
52 WorkerThread::AddObserver(&o
);
56 } // namespace content