Make USB permissions work in the new permission message system
[chromium-blink-merge.git] / content / child / worker_task_runner_unittest.cc
blob20eddfb9c4755e7206f26baee307af71ef254211
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"
12 namespace content {
14 class WorkerTaskRunnerTest : public testing::Test {
15 public:
16 void FakeStart() {
17 task_runner_.OnWorkerRunLoopStarted();
19 void FakeStop() {
20 task_runner_.OnWorkerRunLoopStopped();
22 WorkerTaskRunner task_runner_;
24 private:
25 base::MessageLoop message_loop_;
28 class MockObserver : public WorkerTaskRunner::Observer {
29 public:
30 MOCK_METHOD0(OnWorkerRunLoopStopped, void());
31 void RemoveSelfOnNotify() {
32 ON_CALL(*this, OnWorkerRunLoopStopped()).WillByDefault(
33 testing::Invoke(this, &MockObserver::RemoveSelf));
35 void RemoveSelf() {
36 runner_->RemoveStopObserver(this);
38 WorkerTaskRunner* runner_;
41 TEST_F(WorkerTaskRunnerTest, BasicObservingAndWorkerId) {
42 ASSERT_EQ(0, task_runner_.CurrentWorkerId());
43 MockObserver o;
44 EXPECT_CALL(o, OnWorkerRunLoopStopped()).Times(1);
45 FakeStart();
46 task_runner_.AddStopObserver(&o);
47 ASSERT_LT(0, task_runner_.CurrentWorkerId());
48 FakeStop();
51 TEST_F(WorkerTaskRunnerTest, CanRemoveSelfDuringNotification) {
52 MockObserver o;
53 o.RemoveSelfOnNotify();
54 o.runner_ = &task_runner_;
55 EXPECT_CALL(o, OnWorkerRunLoopStopped()).Times(1);
56 FakeStart();
57 task_runner_.AddStopObserver(&o);
58 FakeStop();
61 } // namespace content