| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "gin/modules/timer.h" | 5 #include "gin/modules/timer.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "gin/handle.h" | 9 #include "gin/handle.h" |
| 10 #include "gin/object_template_builder.h" | 10 #include "gin/object_template_builder.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 int count_; | 50 int count_; |
| 51 }; | 51 }; |
| 52 | 52 |
| 53 WrapperInfo Result::kWrapperInfo = { gin::kEmbedderNativeGin }; | 53 WrapperInfo Result::kWrapperInfo = { gin::kEmbedderNativeGin }; |
| 54 | 54 |
| 55 struct TestHelper { | 55 struct TestHelper { |
| 56 TestHelper(v8::Isolate* isolate) | 56 TestHelper(v8::Isolate* isolate) |
| 57 : runner(new Runner(&delegate, isolate)), | 57 : runner(new Runner(&delegate, isolate)), |
| 58 scope(runner.get()), | 58 scope(runner.get()), |
| 59 timer_module(TimerModule::Create(isolate)), | 59 timer_module(TimerModule::Create(isolate)), |
| 60 result(Result::Create(isolate)), | 60 result(Result::Create(isolate)) { |
| 61 loop(base::MessageLoop::TYPE_DEFAULT) { | |
| 62 EXPECT_FALSE(runner->global().IsEmpty()); | 61 EXPECT_FALSE(runner->global().IsEmpty()); |
| 63 runner->global()->Set(StringToV8(isolate, "timer"), | 62 runner->global()->Set(StringToV8(isolate, "timer"), |
| 64 timer_module->GetWrapper(isolate)); | 63 timer_module->GetWrapper(isolate)); |
| 65 runner->global()->Set(StringToV8(isolate, "result"), | 64 runner->global()->Set(StringToV8(isolate, "result"), |
| 66 result->GetWrapper(isolate)); | 65 result->GetWrapper(isolate)); |
| 67 } | 66 } |
| 68 | 67 |
| 69 void QuitSoon() { | 68 void QuitSoon() { |
| 70 loop.PostDelayedTask(FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), | 69 loop.PostDelayedTask(FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), |
| 71 base::TimeDelta::FromMilliseconds(0)); | 70 base::TimeDelta::FromMilliseconds(0)); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 // Destroy runner, which should destroy the timer object we created. | 146 // Destroy runner, which should destroy the timer object we created. |
| 148 helper.QuitSoon(); | 147 helper.QuitSoon(); |
| 149 helper.runner.reset(NULL); | 148 helper.runner.reset(NULL); |
| 150 helper.loop.Run(); | 149 helper.loop.Run(); |
| 151 | 150 |
| 152 // Timer should not have run because it was deleted. | 151 // Timer should not have run because it was deleted. |
| 153 EXPECT_EQ(0, helper.result->count()); | 152 EXPECT_EQ(0, helper.result->count()); |
| 154 } | 153 } |
| 155 | 154 |
| 156 } // namespace gin | 155 } // namespace gin |
| OLD | NEW |