Switch from using codec ids to codec name hashes.
[chromium-blink-merge.git] / content / child / worker_task_runner_unittest.cc
blob5e932b5d5e69ee3aa1465c822709b534a7459f76
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"
13 namespace content {
15 class WorkerTaskRunnerTest : public testing::Test {
16 public:
17 void FakeStart() { task_runner_.DidStartWorkerRunLoop(); }
18 void FakeStop() { task_runner_.WillStopWorkerRunLoop(); }
19 WorkerTaskRunner task_runner_;
21 private:
22 base::MessageLoop message_loop_;
25 class MockObserver : public WorkerThread::Observer {
26 public:
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());
38 MockObserver o;
39 EXPECT_CALL(o, WillStopCurrentWorkerThread()).Times(1);
40 FakeStart();
41 WorkerThread::AddObserver(&o);
42 ASSERT_LT(0, WorkerThread::GetCurrentId());
43 FakeStop();
46 TEST_F(WorkerTaskRunnerTest, CanRemoveSelfDuringNotification) {
47 MockObserver o;
48 o.RemoveSelfOnNotify();
49 o.runner_ = &task_runner_;
50 EXPECT_CALL(o, WillStopCurrentWorkerThread()).Times(1);
51 FakeStart();
52 WorkerThread::AddObserver(&o);
53 FakeStop();
56 } // namespace content