| 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/runner.h" | 5 #include "gin/runner.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "gin/converter.h" | 8 #include "gin/converter.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| 11 using v8::Handle; | 11 using v8::Handle; |
| 12 using v8::Isolate; | 12 using v8::Isolate; |
| 13 using v8::Object; | 13 using v8::Object; |
| 14 using v8::Script; | 14 using v8::Script; |
| 15 using v8::String; | 15 using v8::String; |
| 16 | 16 |
| 17 namespace gin { | 17 namespace gin { |
| 18 namespace { | |
| 19 | |
| 20 class TestRunnerDelegate : public RunnerDelegate { | |
| 21 public: | |
| 22 virtual Handle<Object> CreateRootObject(Runner* runner) OVERRIDE { | |
| 23 Isolate* isolate = runner->isolate(); | |
| 24 Handle<Object> root = Object::New(); | |
| 25 root->Set(StringToV8(isolate, "foo"), StringToV8(isolate, "bar")); | |
| 26 return root; | |
| 27 } | |
| 28 virtual ~TestRunnerDelegate() {} | |
| 29 }; | |
| 30 | |
| 31 } | |
| 32 | 18 |
| 33 TEST(RunnerTest, Run) { | 19 TEST(RunnerTest, Run) { |
| 34 std::string source = | 20 std::string source = "this.result = 'PASS';\n"; |
| 35 "function main(root) {\n" | |
| 36 " if (root.foo)\n" | |
| 37 " this.result = 'PASS';\n" | |
| 38 " else\n" | |
| 39 " this.result = 'FAIL';\n" | |
| 40 "}\n"; | |
| 41 | 21 |
| 42 TestRunnerDelegate delegate; | 22 RunnerDelegate delegate; |
| 43 Isolate* isolate = Isolate::GetCurrent(); | 23 Isolate* isolate = Isolate::GetCurrent(); |
| 44 Runner runner(&delegate, isolate); | 24 Runner runner(&delegate, isolate); |
| 45 Runner::Scope scope(&runner); | 25 Runner::Scope scope(&runner); |
| 46 runner.Run(Script::New(StringToV8(isolate, source))); | 26 runner.Run(source); |
| 47 | 27 |
| 48 std::string result; | 28 std::string result; |
| 49 EXPECT_TRUE(Converter<std::string>::FromV8( | 29 EXPECT_TRUE(Converter<std::string>::FromV8( |
| 50 runner.global()->Get(StringToV8(isolate, "result")), | 30 runner.global()->Get(StringToV8(isolate, "result")), |
| 51 &result)); | 31 &result)); |
| 52 EXPECT_EQ("PASS", result); | 32 EXPECT_EQ("PASS", result); |
| 53 } | 33 } |
| 54 | 34 |
| 55 } // namespace gin | 35 } // namespace gin |
| OLD | NEW |