Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(108)

Side by Side Diff: webkit/glue/worker_task_runner_unittest.cc

Issue 8785013: Track webcore worker message loops in chromium. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove debug code Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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(OnWorkerRunLoopStarted, void());
26 MOCK_METHOD0(OnWorkerRunLoopStopped, void());
27 void RemoveSelfOnNotify() {
28 ON_CALL(*this, OnWorkerRunLoopStarted()).WillByDefault(
29 testing::Invoke(this, &MockObserver::RemoveSelf));
30 }
31 void RemoveSelf() {
32 runner_->RemoveObserver(this);
33 }
34 WorkerTaskRunner* runner_;
35 };
36
37 TEST_F(WorkerTaskRunnerTest, BasicObservingAndWorkerId) {
38 ASSERT_EQ(0, task_runner_.CurrentWorkerId());
39 MockObserver o;
40 EXPECT_CALL(o, OnWorkerRunLoopStarted()).Times(1);
41 EXPECT_CALL(o, OnWorkerRunLoopStopped()).Times(1);
42 task_runner_.AddObserver(&o);
43 FakeStart();
44 ASSERT_LT(0, task_runner_.CurrentWorkerId());
45 FakeStop();
46 }
47
48 TEST_F(WorkerTaskRunnerTest, RegisterAfterStart) {
49 MockObserver o;
50 EXPECT_CALL(o, OnWorkerRunLoopStarted()).Times(0);
51 EXPECT_CALL(o, OnWorkerRunLoopStopped()).Times(1);
52 FakeStart();
53 task_runner_.AddObserver(&o);
54 FakeStop();
55 }
56
57 TEST_F(WorkerTaskRunnerTest, CanRemoveSelfDuringNotification) {
58 MockObserver o;
59 o.RemoveSelfOnNotify();
60 o.runner_ = &task_runner_;
61 EXPECT_CALL(o, OnWorkerRunLoopStarted()).Times(1);
62 EXPECT_CALL(o, OnWorkerRunLoopStopped()).Times(0);
63 task_runner_.AddObserver(&o);
64 FakeStart();
65 FakeStop();
66 }
67
68 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698