OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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 "bindings/core/v8/ScriptController.h" |
| 6 |
| 7 #include "bindings/core/v8/ScriptSourceCode.h" |
| 8 #include "bindings/core/v8/V8BindingForTesting.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 |
| 11 namespace blink { |
| 12 namespace { |
| 13 |
| 14 TEST(ScriptControllerTest, CompileAndExecuteScriptInMainWorld) { |
| 15 V8TestingScope scope; |
| 16 ScriptController& script = scope.frame().script(); |
| 17 CompiledScript* compiled = script.compileScriptInMainWorld( |
| 18 ScriptSourceCode("x = 42;"), NotSharableCrossOrigin); |
| 19 script.executeScriptInMainWorld(*compiled); |
| 20 v8::Local<v8::Value> value = |
| 21 script.executeScriptInMainWorldAndReturnValue(ScriptSourceCode("x")); |
| 22 EXPECT_EQ(42, value->Int32Value()); |
| 23 } |
| 24 |
| 25 TEST(ScriptControllerTest, CompileAndExecuteScriptInMainWorldInterleaved) { |
| 26 V8TestingScope scope; |
| 27 ScriptController& script = scope.frame().script(); |
| 28 CompiledScript* compiled = script.compileScriptInMainWorld( |
| 29 ScriptSourceCode("x *= 2;"), NotSharableCrossOrigin); |
| 30 CompiledScript* compiled2 = script.compileScriptInMainWorld( |
| 31 ScriptSourceCode("x = 21;"), NotSharableCrossOrigin); |
| 32 script.executeScriptInMainWorld(*compiled2); |
| 33 script.executeScriptInMainWorld(*compiled); |
| 34 v8::Local<v8::Value> value = |
| 35 script.executeScriptInMainWorldAndReturnValue(ScriptSourceCode("x")); |
| 36 EXPECT_EQ(42, value->Int32Value()); |
| 37 } |
| 38 |
| 39 } // namespace |
| 40 } // namespace blink |
OLD | NEW |