| 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" |
| 11 #include "gin/public/isolate_holder.h" | 11 #include "gin/public/isolate_holder.h" |
| 12 #include "gin/runner.h" | 12 #include "gin/shell_runner.h" |
| 13 #include "gin/test/v8_test.h" | 13 #include "gin/test/v8_test.h" |
| 14 #include "gin/try_catch.h" | 14 #include "gin/try_catch.h" |
| 15 #include "gin/wrappable.h" | 15 #include "gin/wrappable.h" |
| 16 #include "v8/include/v8.h" | 16 #include "v8/include/v8.h" |
| 17 | 17 |
| 18 namespace gin { | 18 namespace gin { |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 class Result : public Wrappable<Result> { | 22 class Result : public Wrappable<Result> { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 47 .SetMethod("quit", &Result::Quit); | 47 .SetMethod("quit", &Result::Quit); |
| 48 } | 48 } |
| 49 | 49 |
| 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 ShellRunner(&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 EXPECT_FALSE(runner->global().IsEmpty()); | 61 EXPECT_FALSE(runner->global().IsEmpty()); |
| 62 runner->global()->Set(StringToV8(isolate, "timer"), | 62 runner->global()->Set(StringToV8(isolate, "timer"), |
| 63 timer_module->GetWrapper(isolate)); | 63 timer_module->GetWrapper(isolate)); |
| 64 runner->global()->Set(StringToV8(isolate, "result"), | 64 runner->global()->Set(StringToV8(isolate, "result"), |
| 65 result->GetWrapper(isolate)); | 65 result->GetWrapper(isolate)); |
| 66 } | 66 } |
| 67 | 67 |
| 68 void QuitSoon() { | 68 void QuitSoon() { |
| 69 loop.PostDelayedTask(FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), | 69 loop.PostDelayedTask(FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), |
| 70 base::TimeDelta::FromMilliseconds(0)); | 70 base::TimeDelta::FromMilliseconds(0)); |
| 71 } | 71 } |
| 72 | 72 |
| 73 RunnerDelegate delegate; | 73 ShellRunnerDelegate delegate; |
| 74 scoped_ptr<Runner> runner; | 74 scoped_ptr<ShellRunner> runner; |
| 75 Runner::Scope scope; | 75 Runner::Scope scope; |
| 76 Handle<TimerModule> timer_module; | 76 Handle<TimerModule> timer_module; |
| 77 Handle<Result> result; | 77 Handle<Result> result; |
| 78 base::MessageLoop loop; | 78 base::MessageLoop loop; |
| 79 }; | 79 }; |
| 80 | 80 |
| 81 } // namespace | 81 } // namespace |
| 82 | 82 |
| 83 typedef V8Test TimerUnittest; | 83 typedef V8Test TimerUnittest; |
| 84 | 84 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 // Destroy runner, which should destroy the timer object we created. | 146 // Destroy runner, which should destroy the timer object we created. |
| 147 helper.QuitSoon(); | 147 helper.QuitSoon(); |
| 148 helper.runner.reset(NULL); | 148 helper.runner.reset(NULL); |
| 149 helper.loop.Run(); | 149 helper.loop.Run(); |
| 150 | 150 |
| 151 // Timer should not have run because it was deleted. | 151 // Timer should not have run because it was deleted. |
| 152 EXPECT_EQ(0, helper.result->count()); | 152 EXPECT_EQ(0, helper.result->count()); |
| 153 } | 153 } |
| 154 | 154 |
| 155 } // namespace gin | 155 } // namespace gin |
| OLD | NEW |