blob: a2218d998d020c9703be0d68ec9b161fcdec2d85 [file] [log] [blame]
[email protected]1771610d2014-02-27 06:08:241// Copyright 2014 The Chromium Authors. All rights reserved.
[email protected]a22998a2013-11-10 05:00:502// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]1771610d2014-02-27 06:08:245#include "gin/shell_runner.h"
[email protected]a22998a2013-11-10 05:00:506
7#include "base/compiler_specific.h"
fdoray09a43ef2017-05-08 16:26:578#include "base/test/scoped_task_environment.h"
altimin124814c2017-01-03 14:06:549#include "base/threading/thread_task_runner_handle.h"
jochen2f43f2c92014-09-10 23:47:3110#include "gin/array_buffer.h"
[email protected]a22998a2013-11-10 05:00:5011#include "gin/converter.h"
[email protected]f04b0e92013-11-22 14:20:5512#include "gin/public/isolate_holder.h"
oth05c26fde2015-04-05 14:30:5713#include "gin/v8_initializer.h"
[email protected]a22998a2013-11-10 05:00:5014#include "testing/gtest/include/gtest/gtest.h"
15
baixo3a3c88a2014-10-28 11:52:2116#ifdef V8_USE_EXTERNAL_STARTUP_DATA
17#include "gin/public/isolate_holder.h"
18#endif
19
[email protected]a22998a2013-11-10 05:00:5020using v8::Isolate;
21using v8::Object;
22using v8::Script;
23using v8::String;
24
25namespace gin {
[email protected]a22998a2013-11-10 05:00:5026
Yuzhu Shena9b25af2017-12-11 22:30:2627TEST(RunnerTest, Run) {
Gabriel Charette694c3c332019-08-19 14:53:0528 base::test::TaskEnvironment task_environment;
[email protected]97f21ca2013-11-17 17:46:0729 std::string source = "this.result = 'PASS';\n";
[email protected]a22998a2013-11-10 05:00:5030
baixo3a3c88a2014-10-28 11:52:2131#ifdef V8_USE_EXTERNAL_STARTUP_DATA
oth05c26fde2015-04-05 14:30:5732 gin::V8Initializer::LoadV8Snapshot();
erikcorryc94eff12015-06-08 11:29:1633 gin::V8Initializer::LoadV8Natives();
baixo3a3c88a2014-10-28 11:52:2134#endif
35
jochen2f43f2c92014-09-10 23:47:3136 gin::IsolateHolder::Initialize(gin::IsolateHolder::kStrictMode,
37 gin::ArrayBufferAllocator::SharedInstance());
Ulan Degenbaev51945ab2018-08-23 14:12:5838 gin::IsolateHolder instance(base::ThreadTaskRunnerHandle::Get(),
39 gin::IsolateHolder::IsolateType::kTest);
[email protected]1b93c232013-11-19 19:25:1240
[email protected]1771610d2014-02-27 06:08:2441 ShellRunnerDelegate delegate;
[email protected]1b93c232013-11-19 19:25:1242 Isolate* isolate = instance.isolate();
[email protected]1771610d2014-02-27 06:08:2443 ShellRunner runner(&delegate, isolate);
[email protected]a22998a2013-11-10 05:00:5044 Runner::Scope scope(&runner);
[email protected]2f703422013-11-25 21:26:1545 runner.Run(source, "test_data.js");
[email protected]a22998a2013-11-10 05:00:5046
47 std::string result;
Dan Elphickd7eeb4a2019-02-01 17:55:5648 EXPECT_TRUE(Converter<std::string>::FromV8(
49 isolate,
50 runner.global()
51 ->Get(isolate->GetCurrentContext(), StringToV8(isolate, "result"))
52 .ToLocalChecked(),
[email protected]a22998a2013-11-10 05:00:5053 &result));
54 EXPECT_EQ("PASS", result);
55}
56
57} // namespace gin