OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 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. | |
4 | |
5 #include "base/logging.h" | |
6 #include "testing/gmock/include/gmock/gmock.h" | |
7 #include "testing/gtest/include/gtest/gtest.h" | |
8 #include "webkit/glue/worker_task_runner.h" | |
9 | |
10 namespace webkit_glue { | |
11 | |
12 class WorkerTaskRunnerTest : public testing::Test { | |
13 public: | |
14 void FakeStart() { | |
15 task_runner_.OnWorkerRunLoopStarted(WebKit::WebWorkerRunLoop()); | |
16 } | |
17 void FakeStop() { | |
18 task_runner_.OnWorkerRunLoopStopped(WebKit::WebWorkerRunLoop()); | |
19 } | |
20 WorkerTaskRunner task_runner_; | |
21 }; | |
22 | |
23 class MockObserver : public WorkerTaskRunner::Observer { | |
24 public: | |
25 MOCK_METHOD0(OnWorkerRunLoopStopped, void()); | |
26 void RemoveSelfOnNotify() { | |
27 ON_CALL(*this, OnWorkerRunLoopStopped()).WillByDefault( | |
28 testing::Invoke(this, &MockObserver::RemoveSelf)); | |
29 } | |
30 void RemoveSelf() { | |
31 runner_->RemoveStopObserver(this); | |
32 } | |
33 WorkerTaskRunner* runner_; | |
34 }; | |
35 | |
36 TEST_F(WorkerTaskRunnerTest, BasicObservingAndWorkerId) { | |
37 ASSERT_EQ(0, task_runner_.CurrentWorkerId()); | |
38 MockObserver o; | |
39 EXPECT_CALL(o, OnWorkerRunLoopStopped()).Times(1); | |
40 FakeStart(); | |
41 task_runner_.AddStopObserver(&o); | |
42 ASSERT_LT(0, task_runner_.CurrentWorkerId()); | |
43 FakeStop(); | |
44 } | |
45 | |
46 TEST_F(WorkerTaskRunnerTest, CanRemoveSelfDuringNotification) { | |
47 MockObserver o; | |
48 o.RemoveSelfOnNotify(); | |
49 o.runner_ = &task_runner_; | |
50 EXPECT_CALL(o, OnWorkerRunLoopStopped()).Times(1); | |
51 FakeStart(); | |
52 task_runner_.AddStopObserver(&o); | |
53 FakeStop(); | |
54 } | |
55 | |
56 } | |
OLD | NEW |