OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "mojo/public/bindings/js/v8_runner.h" |
| 6 |
| 7 #include "mojo/public/bindings/js/v8_string.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 |
| 10 namespace mojo { |
| 11 namespace js { |
| 12 namespace { |
| 13 |
| 14 std::string ReadGlobal(v8::Isolate* isolate, |
| 15 v8::Handle<v8::Context> context, |
| 16 std::string property) { |
| 17 v8::Handle<v8::String> v8_property = |
| 18 Wrapper<std::string>::ToObject(isolate, property); |
| 19 return Wrapper<std::string>::ToNative(context->Global()->Get(v8_property)); |
| 20 } |
| 21 |
| 22 TEST(Runner, Basic) { |
| 23 std::string source = |
| 24 "function main(mojo) {\n" |
| 25 " if (mojo.createMessagePipe)\n" |
| 26 " this.result = 'PASS';\n" |
| 27 " else\n" |
| 28 " this.result = 'FAIL';\n" |
| 29 "}\n"; |
| 30 |
| 31 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 32 Runner runner(isolate); |
| 33 Runner::Scope scope(&runner); |
| 34 runner.Run(v8::Script::New(Wrapper<std::string>::ToObject(isolate, source))); |
| 35 |
| 36 std::string result = ReadGlobal(isolate, runner.context(isolate), "result"); |
| 37 EXPECT_EQ("PASS", result); |
| 38 } |
| 39 |
| 40 } // namespace |
| 41 } // namespace js |
| 42 } // namespace mojo |
OLD | NEW |