Commit 0fac10b6 authored by alokp's avatar alokp Committed by Commit Bot

Reland of Moves mojo_js_integration_tests into blink. (patchset #1 id:1 of...

Reland of Moves mojo_js_integration_tests into blink. (patchset #1 id:1 of https://codereview.chromium.org/2926143002/ )

Reason for revert:
Fixed failing tests.

Original issue's description:
> Revert of Moves mojo_js_integration_tests into blink. (patchset #11 id:190001 of https://codereview.chromium.org/2734783008/ )
>
> Reason for revert:
> Seems related to webkit failures of the JsToCpp tests. E.x. https://build.chromium.org/p/chromium.webkit/builders/WebKit%20Mac10.10/builds/34530.
>
> Original issue's description:
> > Moves mojo_js_integration_tests into blink.
> >
> > BUG=699569
> >
> > Review-Url: https://codereview.chromium.org/2734783008
> > Cr-Commit-Position: refs/heads/master@{#477549}
> > Committed: https://chromium.googlesource.com/chromium/src/+/dd57fa764813de09d159a232eeef1bb21b0ccc1e
>
> TBR=jbroman@chromium.org,dpranke@chromium.org,yzshen@chromium.org,alokp@chromium.org
> # Skipping CQ checks because original CL landed less than 1 days ago.
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=699569
>
> Review-Url: https://codereview.chromium.org/2926143002
> Cr-Commit-Position: refs/heads/master@{#477653}
> Committed: https://chromium.googlesource.com/chromium/src/+/6536a56d25c245bd109e32ed49240bfc04f8890f

TBR=jbroman@chromium.org,dpranke@chromium.org,yzshen@chromium.org,jwd@chromium.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=699569

Review-Url: https://codereview.chromium.org/2920383004
Cr-Commit-Position: refs/heads/master@{#478820}
parent f1e4c0cc
......@@ -15,44 +15,10 @@ import("//testing/test.gni")
group("tests") {
testonly = true
deps = [
":mojo_js_integration_tests",
":mojo_js_unittests",
]
}
test("mojo_js_integration_tests") {
deps = [
":js_to_cpp_bindings",
"//base/test:test_support",
"//gin:gin_test",
"//mojo/common",
"//mojo/edk/js",
"//mojo/edk/test:run_all_unittests",
"//mojo/public/cpp/bindings",
"//mojo/public/cpp/system",
"//mojo/public/js:bindings",
]
sources = [
"js_to_cpp_tests.cc",
]
data = [
"js_to_cpp_tests.js",
]
configs += [ "//v8:external_startup_data" ]
}
mojom("js_to_cpp_bindings") {
sources = [
"js_to_cpp.mojom",
]
# TODO(crbug.com/699569): Convert to use the new JS bindings.
use_new_js_bindings = false
}
test("mojo_js_unittests") {
deps = [
"//base",
......
......@@ -3963,12 +3963,6 @@
},
"test": "mojo_common_unittests"
},
{
"swarming": {
"can_use_on_swarming_builders": true
},
"test": "mojo_js_integration_tests"
},
{
"swarming": {
"can_use_on_swarming_builders": true
......@@ -4644,12 +4638,6 @@
},
"test": "mojo_common_unittests"
},
{
"swarming": {
"can_use_on_swarming_builders": true
},
"test": "mojo_js_integration_tests"
},
{
"swarming": {
"can_use_on_swarming_builders": true
......
......@@ -232,12 +232,6 @@
},
"test": "media_blink_unittests"
},
{
"swarming": {
"can_use_on_swarming_builders": true
},
"test": "mojo_js_integration_tests"
},
{
"swarming": {
"can_use_on_swarming_builders": true
......
......@@ -708,10 +708,6 @@
"label": "//mojo/common:mojo_common_unittests",
"type": "console_test_launcher",
},
"mojo_js_integration_tests": {
"label": "//mojo/edk/js/tests:mojo_js_integration_tests",
"type": "console_test_launcher",
},
"mojo_js_unittests": {
"label": "//mojo/edk/js/tests:mojo_js_unittests",
"type": "console_test_launcher",
......
......@@ -1447,6 +1447,7 @@ source_set("unit_tests") {
"//testing/gmock",
"//testing/gtest",
"//third_party/WebKit/Source/core/editing:unit_tests",
"//third_party/WebKit/Source/core/mojo:unit_tests",
]
}
......
......@@ -2,6 +2,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//mojo/public/tools/bindings/mojom.gni")
import("//third_party/WebKit/Source/core/core.gni")
blink_core_sources("mojo") {
......@@ -23,3 +24,39 @@ blink_core_sources("mojo") {
"//services/service_manager/public/cpp",
]
}
source_set("unit_tests") {
testonly = true
sources = [
"tests/JsToCppTest.cpp",
]
data = [
"tests/JsToCppTest.js",
]
configs += [
"//third_party/WebKit/Source/core:blink_core_pch",
"//third_party/WebKit/Source:config",
"//third_party/WebKit/Source:inside_blink",
]
deps = [
":test_bindings_blink",
"//mojo/public/cpp/bindings",
"//testing/gtest",
"//third_party/WebKit/Source/core:core",
"//third_party/WebKit/Source/core:testing",
]
data_deps = [
":test_bindings", # For JS bindings: crbug.com/729649.
"//mojo/public/js:new_bindings",
]
}
mojom("test_bindings") {
sources = [
"tests/JsToCpp.mojom",
]
}
......@@ -2,42 +2,27 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <stddef.h>
#include <stdint.h>
#include <string>
#include <utility>
#include "base/at_exit.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/macros.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/scoped_task_environment.h"
#include "base/threading/thread_task_runner_handle.h"
#include "gin/array_buffer.h"
#include "gin/public/isolate_holder.h"
#include "gin/v8_initializer.h"
#include "mojo/common/data_pipe_utils.h"
#include "mojo/edk/js/mojo_runner_delegate.h"
#include "mojo/edk/js/tests/js_to_cpp.mojom.h"
#include "bindings/core/v8/ScriptController.h"
#include "bindings/core/v8/ScriptSourceCode.h"
#include "bindings/core/v8/V8BindingForCore.h"
#include "bindings/core/v8/V8BindingForTesting.h"
#include "bindings/core/v8/V8ScriptRunner.h"
#include "core/frame/Settings.h"
#include "core/mojo/MojoHandle.h"
#include "core/page/Page.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/bindings/lib/validation_errors.h"
#include "mojo/public/cpp/system/core.h"
#include "mojo/public/cpp/system/wait.h"
#include "platform/testing/UnitTestHelpers.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/WebKit/Source/core/mojo/tests/JsToCpp.mojom-blink.h"
namespace mojo {
namespace edk {
namespace js {
namespace blink {
namespace {
// Global value updated by some checks to prevent compilers from optimizing
// reads out of existence.
uint32_t g_waste_accumulator = 0;
namespace {
// Negative numbers with different values in each byte, the last of
// which can survive promotion to double and back.
const int8_t kExpectedInt8Value = -65;
......@@ -63,24 +48,53 @@ const float kExpectedFloatNan = std::numeric_limits<float>::quiet_NaN();
// NaN has the property that it is not equal to itself.
#define EXPECT_NAN(x) EXPECT_NE(x, x)
void CheckDataPipe(ScopedDataPipeConsumerHandle data_pipe_handle) {
std::string buffer;
bool result = common::BlockingCopyToString(std::move(data_pipe_handle),
&buffer);
EXPECT_TRUE(result);
EXPECT_EQ(64u, buffer.size());
for (int i = 0; i < 64; ++i) {
EXPECT_EQ(i, buffer[i]);
String MojoBindingsScriptPath() {
String filepath = testing::ExecutableDir();
filepath.append("/gen/mojo/public/js/mojo_bindings.js");
return filepath;
}
String TestBindingsScriptPath() {
String filepath = testing::ExecutableDir();
filepath.append(
"/gen/third_party/WebKit/Source/core/mojo/tests/JsToCpp.mojom.js");
return filepath;
}
String TestScriptPath() {
String filepath = testing::BlinkRootDir();
filepath.append("/Source/core/mojo/tests/JsToCppTest.js");
return filepath;
}
v8::Local<v8::Value> ExecuteScript(const String& script_path,
LocalFrame& frame) {
RefPtr<SharedBuffer> script_src = testing::ReadFromFile(script_path);
return frame.GetScriptController().ExecuteScriptInMainWorldAndReturnValue(
ScriptSourceCode(String(script_src->Data(), script_src->size())));
}
void CheckDataPipe(mojo::DataPipeConsumerHandle data_pipe_handle) {
const void* buffer = nullptr;
unsigned num_bytes = 0;
MojoResult result = Wait(data_pipe_handle, MOJO_HANDLE_SIGNAL_READABLE);
EXPECT_EQ(MOJO_RESULT_OK, result);
result = BeginReadDataRaw(data_pipe_handle, &buffer, &num_bytes,
MOJO_READ_DATA_FLAG_NONE);
EXPECT_EQ(MOJO_RESULT_OK, result);
EXPECT_EQ(64u, num_bytes);
for (unsigned i = 0; i < num_bytes; ++i) {
EXPECT_EQ(i, static_cast<unsigned>(static_cast<const char*>(buffer)[i]));
}
EndReadDataRaw(data_pipe_handle, num_bytes);
}
void CheckMessagePipe(MessagePipeHandle message_pipe_handle) {
void CheckMessagePipe(mojo::MessagePipeHandle message_pipe_handle) {
unsigned char buffer[100];
uint32_t buffer_size = static_cast<uint32_t>(sizeof(buffer));
MojoResult result = Wait(message_pipe_handle, MOJO_HANDLE_SIGNAL_READABLE);
EXPECT_EQ(MOJO_RESULT_OK, result);
result = ReadMessageRaw(
message_pipe_handle, buffer, &buffer_size, 0, 0, 0);
result = ReadMessageRaw(message_pipe_handle, buffer, &buffer_size, 0, 0, 0);
EXPECT_EQ(MOJO_RESULT_OK, result);
EXPECT_EQ(64u, buffer_size);
for (int i = 0; i < 64; ++i) {
......@@ -88,8 +102,8 @@ void CheckMessagePipe(MessagePipeHandle message_pipe_handle) {
}
}
js_to_cpp::EchoArgsPtr BuildSampleEchoArgs() {
js_to_cpp::EchoArgsPtr args(js_to_cpp::EchoArgs::New());
js_to_cpp::blink::EchoArgsPtr BuildSampleEchoArgs() {
auto args = js_to_cpp::blink::EchoArgs::New();
args->si64 = kExpectedInt64Value;
args->si32 = kExpectedInt32Value;
args->si16 = kExpectedInt16Value;
......@@ -104,7 +118,7 @@ js_to_cpp::EchoArgsPtr BuildSampleEchoArgs() {
args->double_val = kExpectedDoubleVal;
args->double_inf = kExpectedDoubleInf;
args->double_nan = kExpectedDoubleNan;
args->name.emplace("coming");
args->name = "coming";
args->string_array.emplace(3);
(*args->string_array)[0] = "one";
(*args->string_array)[1] = "two";
......@@ -112,7 +126,7 @@ js_to_cpp::EchoArgsPtr BuildSampleEchoArgs() {
return args;
}
void CheckSampleEchoArgs(js_to_cpp::EchoArgsPtr arg) {
void CheckSampleEchoArgs(const js_to_cpp::blink::EchoArgsPtr& arg) {
EXPECT_EQ(kExpectedInt64Value, arg->si64);
EXPECT_EQ(kExpectedInt32Value, arg->si32);
EXPECT_EQ(kExpectedInt16Value, arg->si16);
......@@ -127,77 +141,70 @@ void CheckSampleEchoArgs(js_to_cpp::EchoArgsPtr arg) {
EXPECT_EQ(kExpectedDoubleVal, arg->double_val);
EXPECT_EQ(kExpectedDoubleInf, arg->double_inf);
EXPECT_NAN(arg->double_nan);
EXPECT_EQ(std::string("coming"), *arg->name);
EXPECT_EQ(std::string("one"), (*arg->string_array)[0]);
EXPECT_EQ(std::string("two"), (*arg->string_array)[1]);
EXPECT_EQ(std::string("three"), (*arg->string_array)[2]);
CheckDataPipe(std::move(arg->data_handle));
EXPECT_EQ(String("coming"), arg->name);
EXPECT_EQ(String("one"), (*arg->string_array)[0]);
EXPECT_EQ(String("two"), (*arg->string_array)[1]);
EXPECT_EQ(String("three"), (*arg->string_array)[2]);
CheckDataPipe(arg->data_handle.get());
CheckMessagePipe(arg->message_handle.get());
}
void CheckSampleEchoArgsList(const js_to_cpp::EchoArgsListPtr& list) {
void CheckSampleEchoArgsList(const js_to_cpp::blink::EchoArgsListPtr& list) {
if (list.is_null())
return;
CheckSampleEchoArgs(std::move(list->item));
CheckSampleEchoArgs(list->item);
CheckSampleEchoArgsList(list->next);
}
// More forgiving checks are needed in the face of potentially corrupt
// messages. The values don't matter so long as all accesses are within
// bounds.
void CheckCorruptedString(const std::string& arg) {
for (size_t i = 0; i < arg.size(); ++i)
void CheckCorruptedString(const String& arg) {
for (size_t i = 0; i < arg.length(); ++i)
g_waste_accumulator += arg[i];
}
void CheckCorruptedString(const base::Optional<std::string>& arg) {
if (!arg)
return;
CheckCorruptedString(*arg);
}
void CheckCorruptedStringArray(
const base::Optional<std::vector<std::string>>& string_array) {
void CheckCorruptedStringArray(const Optional<Vector<String>>& string_array) {
if (!string_array)
return;
for (size_t i = 0; i < string_array->size(); ++i)
CheckCorruptedString((*string_array)[i]);
}
void CheckCorruptedDataPipe(MojoHandle data_pipe_handle) {
void CheckCorruptedDataPipe(mojo::DataPipeConsumerHandle data_pipe_handle) {
unsigned char buffer[100];
uint32_t buffer_size = static_cast<uint32_t>(sizeof(buffer));
MojoResult result = MojoReadData(
data_pipe_handle, buffer, &buffer_size, MOJO_READ_DATA_FLAG_NONE);
MojoResult result = ReadDataRaw(data_pipe_handle, buffer, &buffer_size,
MOJO_READ_DATA_FLAG_NONE);
if (result != MOJO_RESULT_OK)
return;
for (uint32_t i = 0; i < buffer_size; ++i)
g_waste_accumulator += buffer[i];
}
void CheckCorruptedMessagePipe(MojoHandle message_pipe_handle) {
void CheckCorruptedMessagePipe(mojo::MessagePipeHandle message_pipe_handle) {
unsigned char buffer[100];
uint32_t buffer_size = static_cast<uint32_t>(sizeof(buffer));
MojoResult result = MojoReadMessage(
message_pipe_handle, buffer, &buffer_size, 0, 0, 0);
MojoResult result =
ReadMessageRaw(message_pipe_handle, buffer, &buffer_size, 0, 0, 0);
if (result != MOJO_RESULT_OK)
return;
for (uint32_t i = 0; i < buffer_size; ++i)
g_waste_accumulator += buffer[i];
}
void CheckCorruptedEchoArgs(const js_to_cpp::EchoArgsPtr& arg) {
void CheckCorruptedEchoArgs(const js_to_cpp::blink::EchoArgsPtr& arg) {
if (arg.is_null())
return;
CheckCorruptedString(arg->name);
CheckCorruptedStringArray(arg->string_array);
if (arg->data_handle.is_valid())
CheckCorruptedDataPipe(arg->data_handle.get().value());
CheckCorruptedDataPipe(arg->data_handle.get());
if (arg->message_handle.is_valid())
CheckCorruptedMessagePipe(arg->message_handle.get().value());
CheckCorruptedMessagePipe(arg->message_handle.get());
}
void CheckCorruptedEchoArgsList(const js_to_cpp::EchoArgsListPtr& list) {
void CheckCorruptedEchoArgsList(const js_to_cpp::blink::EchoArgsListPtr& list) {
if (list.is_null())
return;
CheckCorruptedEchoArgs(list->item);
......@@ -207,22 +214,17 @@ void CheckCorruptedEchoArgsList(const js_to_cpp::EchoArgsListPtr& list) {
// Base Provider implementation class. It's expected that tests subclass and
// override the appropriate Provider functions. When test is done quit the
// run_loop().
class CppSideConnection : public js_to_cpp::CppSide {
class CppSideConnection : public js_to_cpp::blink::CppSide {
public:
CppSideConnection()
: run_loop_(nullptr),
js_side_(nullptr),
mishandled_messages_(0),
binding_(this) {}
CppSideConnection() : mishandled_messages_(0), binding_(this) {}
~CppSideConnection() override {}
void set_run_loop(base::RunLoop* run_loop) { run_loop_ = run_loop; }
base::RunLoop* run_loop() { return run_loop_; }
void set_js_side(js_to_cpp::JsSide* js_side) { js_side_ = js_side; }
js_to_cpp::JsSide* js_side() { return js_side_; }
void set_js_side(js_to_cpp::blink::JsSidePtr js_side) {
js_side_ = std::move(js_side);
}
js_to_cpp::blink::JsSide* js_side() { return js_side_.get(); }
void Bind(InterfaceRequest<js_to_cpp::CppSide> request) {
void Bind(mojo::InterfaceRequest<js_to_cpp::blink::CppSide> request) {
binding_.Bind(std::move(request));
// Keep the pipe open even after validation errors.
binding_.EnableTestingMode();
......@@ -235,28 +237,24 @@ class CppSideConnection : public js_to_cpp::CppSide {
void PingResponse() override { mishandled_messages_ += 1; }
void EchoResponse(js_to_cpp::EchoArgsListPtr list) override {
void EchoResponse(js_to_cpp::blink::EchoArgsListPtr list) override {
mishandled_messages_ += 1;
}
void BitFlipResponse(
js_to_cpp::EchoArgsListPtr list,
js_to_cpp::ForTestingAssociatedPtrInfo not_used) override {
js_to_cpp::blink::EchoArgsListPtr list,
js_to_cpp::blink::ForTestingAssociatedPtrInfo not_used) override {
mishandled_messages_ += 1;
}
void BackPointerResponse(js_to_cpp::EchoArgsListPtr list) override {
void BackPointerResponse(js_to_cpp::blink::EchoArgsListPtr list) override {
mishandled_messages_ += 1;
}
protected:
base::RunLoop* run_loop_;
js_to_cpp::JsSide* js_side_;
js_to_cpp::blink::JsSidePtr js_side_;
int mishandled_messages_;
mojo::Binding<js_to_cpp::CppSide> binding_;
private:
DISALLOW_COPY_AND_ASSIGN(CppSideConnection);
mojo::Binding<js_to_cpp::blink::CppSide> binding_;
};
// Trivial test to verify a message sent from JS is received.
......@@ -270,25 +268,19 @@ class PingCppSideConnection : public CppSideConnection {
void PingResponse() override {
got_message_ = true;
run_loop()->Quit();
testing::ExitRunLoop();
}
bool DidSucceed() {
return got_message_ && !mishandled_messages_;
}
bool DidSucceed() { return got_message_ && !mishandled_messages_; }
private:
bool got_message_;
DISALLOW_COPY_AND_ASSIGN(PingCppSideConnection);
};
// Test that parameters are passed with correct values.
class EchoCppSideConnection : public CppSideConnection {
public:
EchoCppSideConnection() :
message_count_(0),
termination_seen_(false) {
}
EchoCppSideConnection() : message_count_(0), termination_seen_(false) {}
~EchoCppSideConnection() override {}
// js_to_cpp::CppSide:
......@@ -296,33 +288,35 @@ class EchoCppSideConnection : public CppSideConnection {
js_side_->Echo(kExpectedMessageCount, BuildSampleEchoArgs());
}
void EchoResponse(js_to_cpp::EchoArgsListPtr list) override {
const js_to_cpp::EchoArgsPtr& special_arg = list->item;
void EchoResponse(js_to_cpp::blink::EchoArgsListPtr list) override {
message_count_ += 1;
const js_to_cpp::blink::EchoArgsPtr& special_arg = list->item;
EXPECT_EQ(-1, special_arg->si64);
EXPECT_EQ(-1, special_arg->si32);
EXPECT_EQ(-1, special_arg->si16);
EXPECT_EQ(-1, special_arg->si8);
EXPECT_EQ(std::string("going"), *special_arg->name);
EXPECT_EQ(String("going"), special_arg->name);
CheckDataPipe(special_arg->data_handle.get());
CheckMessagePipe(special_arg->message_handle.get());
CheckSampleEchoArgsList(list->next);
}
void TestFinished() override {
termination_seen_ = true;
run_loop()->Quit();
testing::ExitRunLoop();
}
bool DidSucceed() {
return termination_seen_ &&
!mishandled_messages_ &&
message_count_ == kExpectedMessageCount;
return termination_seen_ && !mishandled_messages_ &&
message_count_ == kExpectedMessageCount;
}
private:
static const int kExpectedMessageCount = 10;
int message_count_;
bool termination_seen_;
DISALLOW_COPY_AND_ASSIGN(EchoCppSideConnection);
};
// Test that corrupted messages don't wreak havoc.
......@@ -335,23 +329,20 @@ class BitFlipCppSideConnection : public CppSideConnection {
void StartTest() override { js_side_->BitFlip(BuildSampleEchoArgs()); }
void BitFlipResponse(
js_to_cpp::EchoArgsListPtr list,
js_to_cpp::ForTestingAssociatedPtrInfo not_used) override {
js_to_cpp::blink::EchoArgsListPtr list,
js_to_cpp::blink::ForTestingAssociatedPtrInfo not_used) override {
CheckCorruptedEchoArgsList(list);
}
void TestFinished() override {
termination_seen_ = true;
run_loop()->Quit();
testing::ExitRunLoop();
}
bool DidSucceed() {
return termination_seen_;
}
bool DidSucceed() { return termination_seen_; }
private:
bool termination_seen_;
DISALLOW_COPY_AND_ASSIGN(BitFlipCppSideConnection);
};
// Test that severely random messages don't wreak havoc.
......@@ -363,76 +354,62 @@ class BackPointerCppSideConnection : public CppSideConnection {
// js_to_cpp::CppSide:
void StartTest() override { js_side_->BackPointer(BuildSampleEchoArgs()); }
void BackPointerResponse(js_to_cpp::EchoArgsListPtr list) override {
void BackPointerResponse(js_to_cpp::blink::EchoArgsListPtr list) override {
CheckCorruptedEchoArgsList(list);
}
void TestFinished() override {
termination_seen_ = true;
run_loop()->Quit();
testing::ExitRunLoop();
}
bool DidSucceed() {
return termination_seen_;
}
bool DidSucceed() { return termination_seen_; }
private:
bool termination_seen_;
DISALLOW_COPY_AND_ASSIGN(BackPointerCppSideConnection);
};
} // namespace
class JsToCppTest : public testing::Test {
class JsToCppTest : public ::testing::Test {
public:
JsToCppTest() {}
void RunTest(const std::string& test, CppSideConnection* cpp_side) {
cpp_side->set_run_loop(&run_loop_);
js_to_cpp::JsSidePtr js_side;
auto js_side_proxy = MakeRequest(&js_side);
cpp_side->set_js_side(js_side.get());
js_to_cpp::CppSidePtr cpp_side_ptr;
void RunTest(CppSideConnection* cpp_side) {
js_to_cpp::blink::CppSidePtr cpp_side_ptr;
cpp_side->Bind(MakeRequest(&cpp_side_ptr));
js_side->SetCppSide(std::move(cpp_side_ptr));
#ifdef V8_USE_EXTERNAL_STARTUP_DATA
gin::V8Initializer::LoadV8Snapshot();
gin::V8Initializer::LoadV8Natives();
#endif
gin::IsolateHolder::Initialize(gin::IsolateHolder::kStrictMode,
gin::IsolateHolder::kStableV8Extras,
gin::ArrayBufferAllocator::SharedInstance());
gin::IsolateHolder instance(base::ThreadTaskRunnerHandle::Get());
MojoRunnerDelegate delegate;
gin::ShellRunner runner(&delegate, instance.isolate());
delegate.Start(&runner, js_side_proxy.PassMessagePipe().release().value(),
test);
run_loop_.Run();
js_to_cpp::blink::JsSidePtr js_side_ptr;
auto js_side_request = MakeRequest(&js_side_ptr);
js_side_ptr->SetCppSide(std::move(cpp_side_ptr));
cpp_side->set_js_side(std::move(js_side_ptr));
V8TestingScope scope;
scope.GetPage().GetSettings().SetScriptEnabled(true);
ExecuteScript(MojoBindingsScriptPath(), scope.GetFrame());
ExecuteScript(TestBindingsScriptPath(), scope.GetFrame());
v8::Local<v8::Value> start_fn =
ExecuteScript(TestScriptPath(), scope.GetFrame());
ASSERT_FALSE(start_fn.IsEmpty());
ASSERT_TRUE(start_fn->IsFunction());
v8::Local<v8::Object> global_proxy = scope.GetContext()->Global();
v8::Local<v8::Value> args[1] = {
ToV8(MojoHandle::Create(
mojo::ScopedHandle::From(js_side_request.PassMessagePipe())),
global_proxy, scope.GetIsolate())};
V8ScriptRunner::CallFunction(
start_fn.As<v8::Function>(), scope.GetExecutionContext(), global_proxy,
WTF_ARRAY_LENGTH(args), args, scope.GetIsolate());
testing::EnterRunLoop();
}
private:
base::ShadowingAtExitManager at_exit_;
base::test::ScopedTaskEnvironment scoped_task_environment_;
base::RunLoop run_loop_;
DISALLOW_COPY_AND_ASSIGN(JsToCppTest);
};
TEST_F(JsToCppTest, Ping) {
PingCppSideConnection cpp_side_connection;
RunTest("mojo/edk/js/tests/js_to_cpp_tests", &cpp_side_connection);
RunTest(&cpp_side_connection);
EXPECT_TRUE(cpp_side_connection.DidSucceed());
}
TEST_F(JsToCppTest, Echo) {
EchoCppSideConnection cpp_side_connection;
RunTest("mojo/edk/js/tests/js_to_cpp_tests", &cpp_side_connection);
RunTest(&cpp_side_connection);
EXPECT_TRUE(cpp_side_connection.DidSucceed());
}
......@@ -441,7 +418,7 @@ TEST_F(JsToCppTest, BitFlip) {
mojo::internal::ScopedSuppressValidationErrorLoggingForTests log_suppression;
BitFlipCppSideConnection cpp_side_connection;
RunTest("mojo/edk/js/tests/js_to_cpp_tests", &cpp_side_connection);
RunTest(&cpp_side_connection);
EXPECT_TRUE(cpp_side_connection.DidSucceed());
}
......@@ -450,10 +427,9 @@ TEST_F(JsToCppTest, BackPointer) {
mojo::internal::ScopedSuppressValidationErrorLoggingForTests log_suppression;
BackPointerCppSideConnection cpp_side_connection;
RunTest("mojo/edk/js/tests/js_to_cpp_tests", &cpp_side_connection);
RunTest(&cpp_side_connection);
EXPECT_TRUE(cpp_side_connection.DidSucceed());
}
} // namespace js
} // namespace edk
} // namespace mojo
} // namespace
} // namespace blink
......@@ -2,26 +2,18 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
define('mojo/edk/js/tests/js_to_cpp_tests', [
'console',
'mojo/edk/js/tests/js_to_cpp.mojom',
'mojo/public/js/bindings',
'mojo/public/js/connector',
'mojo/public/js/core',
], function (console, jsToCpp, bindings, connector, core) {
(function () {
var retainedJsSide;
var retainedJsSideStub;
var sampleData;
var sampleMessage;
var BAD_VALUE = 13;
var DATA_PIPE_PARAMS = {
flags: core.CREATE_DATA_PIPE_OPTIONS_FLAG_NONE,
elementNumBytes: 1,
capacityNumBytes: 64
};
function JsSideConnection() {
this.binding = new bindings.Binding(jsToCpp.JsSide, this);
this.binding = new mojo.Binding(jsToCpp.JsSide, this);
}
JsSideConnection.prototype.setCppSide = function(cppSide) {
......@@ -55,13 +47,13 @@ define('mojo/edk/js/tests/js_to_cpp_tests', [
arg.si8 = BAD_VALUE;
for (i = 0; i < numIterations; ++i) {
dataPipe1 = core.createDataPipe(DATA_PIPE_PARAMS);
dataPipe2 = core.createDataPipe(DATA_PIPE_PARAMS);
messagePipe1 = core.createMessagePipe();
messagePipe2 = core.createMessagePipe();
dataPipe1 = Mojo.createDataPipe(DATA_PIPE_PARAMS);
dataPipe2 = Mojo.createDataPipe(DATA_PIPE_PARAMS);
messagePipe1 = Mojo.createMessagePipe();
messagePipe2 = Mojo.createMessagePipe();
arg.data_handle = dataPipe1.consumerHandle;
arg.message_handle = messagePipe1.handle1;
arg.dataHandle = dataPipe1.consumer;
arg.messageHandle = messagePipe1.handle1;
specialArg = new jsToCpp.EchoArgs();
specialArg.si64 = -1;
......@@ -69,20 +61,19 @@ define('mojo/edk/js/tests/js_to_cpp_tests', [
specialArg.si16 = -1;
specialArg.si8 = -1;
specialArg.name = 'going';
specialArg.data_handle = dataPipe2.consumerHandle;
specialArg.message_handle = messagePipe2.handle1;
specialArg.dataHandle = dataPipe2.consumer;
specialArg.messageHandle = messagePipe2.handle1;
writeDataPipe(dataPipe1, sampleData);
writeDataPipe(dataPipe2, sampleData);
writeMessagePipe(messagePipe1, sampleMessage);
writeMessagePipe(messagePipe2, sampleMessage);
this.cppSide_.echoResponse(createEchoArgsList(specialArg, arg));
core.close(dataPipe1.producerHandle);
core.close(dataPipe2.producerHandle);
core.close(messagePipe1.handle0);
core.close(messagePipe2.handle0);
dataPipe1.producer.close();
dataPipe2.producer.close();
messagePipe1.handle0.close();
messagePipe2.handle0.close();
}
this.cppSide_.testFinished();
};
......@@ -91,7 +82,7 @@ define('mojo/edk/js/tests/js_to_cpp_tests', [
var iteration = 0;
var dataPipe;
var messagePipe;
var proto = connector.Connector.prototype;
var proto = mojo.internal.Connector.prototype;
var stopSignalled = false;
proto.realAccept = proto.accept;
......@@ -110,13 +101,13 @@ define('mojo/edk/js/tests/js_to_cpp_tests', [
};
while (!stopSignalled) {
messagePipe = core.createMessagePipe();
messagePipe = Mojo.createMessagePipe();
writeMessagePipe(messagePipe, sampleMessage);
arg.message_handle = messagePipe.handle1;
arg.messageHandle = messagePipe.handle1;
this.cppSide_.bitFlipResponse(createEchoArgsList(arg), null);
core.close(messagePipe.handle0);
messagePipe.handle0.close();
iteration += 1;
}
......@@ -129,7 +120,7 @@ define('mojo/edk/js/tests/js_to_cpp_tests', [
var iteration = 0;
var dataPipe;
var messagePipe;
var proto = connector.Connector.prototype;
var proto = mojo.internal.Connector.prototype;
var stopSignalled = false;
proto.realAccept = proto.accept;
......@@ -146,13 +137,13 @@ define('mojo/edk/js/tests/js_to_cpp_tests', [
};
while (!stopSignalled) {
messagePipe = core.createMessagePipe();
messagePipe = Mojo.createMessagePipe();
writeMessagePipe(messagePipe, sampleMessage);
arg.message_handle = messagePipe.handle1;
arg.messageHandle = messagePipe.handle1;
this.cppSide_.backPointerResponse(createEchoArgsList(arg));
core.close(messagePipe.handle0);
messagePipe.handle0.close();
iteration += 1;
}
......@@ -162,10 +153,9 @@ define('mojo/edk/js/tests/js_to_cpp_tests', [
};
function writeDataPipe(pipe, data) {
var writeResult = core.writeData(
pipe.producerHandle, data, core.WRITE_DATA_FLAG_ALL_OR_NONE);
var writeResult = pipe.producer.writeData(data);
if (writeResult.result != core.RESULT_OK) {
if (writeResult.result != Mojo.RESULT_OK) {
console.log('ERROR: Data pipe write result was ' + writeResult.result);
return false;
}
......@@ -177,8 +167,8 @@ define('mojo/edk/js/tests/js_to_cpp_tests', [
}
function writeMessagePipe(pipe, arrayBuffer) {
var result = core.writeMessage(pipe.handle0, arrayBuffer, [], 0);
if (result != core.RESULT_OK) {
var result = pipe.handle0.writeMessage(arrayBuffer, []);
if (result != Mojo.RESULT_OK) {
console.log('ERROR: Message pipe write result was ' + result);
return false;
}
......@@ -212,4 +202,4 @@ define('mojo/edk/js/tests/js_to_cpp_tests', [
retainedJsSide = new JsSideConnection;
retainedJsSide.binding.bind(jsSideRequestHandle);
};
});
})();
per-file *.mojom=set noparent
per-file *.mojom=file://ipc/SECURITY_OWNERS
......@@ -89,6 +89,12 @@ String BlinkRootDir() {
return FilePathToWebString(BlinkRootFilePath());
}
String ExecutableDir() {
base::FilePath path;
base::PathService::Get(base::DIR_EXE, &path);
return FilePathToWebString(base::MakeAbsoluteFilePath(path));
}
String WebTestDataPath(const String& relative_path) {
return FilePathToWebString(
BlinkRootFilePath()
......
......@@ -52,6 +52,9 @@ void YieldCurrentThread();
// /src/third_party/WebKit.
String BlinkRootDir();
// Returns directory containing the current executable as absolute path.
String ExecutableDir();
// Returns test data absolute path for webkit_unit_tests, i.e.
// <blinkRootDir>/Source/web/tests/data/<relativePath>.
// It returns the top web test directory if |relativePath| was not specified.
......
......@@ -119,7 +119,6 @@
'message_center_unittests',
'midi_unittests',
'mojo_common_unittests',
'mojo_js_integration_tests',
'mojo_js_unittests',
'mojo_public_bindings_unittests',
'mojo_public_system_unittests',
......@@ -276,7 +275,6 @@
'midi_unittests.exe',
'mini_installer.exe',
'mksnapshot.exe',
'mojo_js_integration_tests.exe',
'mojo_js_unittests.exe',
'mojo_message_pipe_perftests.exe',
'mojo_public_bindings_perftests.exe',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment