diff --git a/.gn b/.gn index a691fa339b..fc34662e1a 100644 --- a/.gn +++ b/.gn @@ -19,7 +19,8 @@ no_check_targets = [ "//:cppgc_base", "//:v8_internal_headers", "//src/inspector:inspector", - "//test/cctest:cctest_sources", + "//test/cctest:cctest_sources", # 15 errors + "//test/unittests:inspector_unittests_sources", # 2 errors "//third_party/icu:*", ] diff --git a/test/cctest/BUILD.gn b/test/cctest/BUILD.gn index ec04517a11..3635fe88bf 100644 --- a/test/cctest/BUILD.gn +++ b/test/cctest/BUILD.gn @@ -185,7 +185,6 @@ v8_source_set("cctest_sources") { "test-icache.cc", "test-ignition-statistics-extension.cc", "test-inobject-slack-tracking.cc", - "test-inspector.cc", "test-js-weak-refs.cc", "test-liveedit.cc", "test-lockers.cc", diff --git a/test/unittests/BUILD.gn b/test/unittests/BUILD.gn index 4bcdcb7372..041b013bc6 100644 --- a/test/unittests/BUILD.gn +++ b/test/unittests/BUILD.gn @@ -190,6 +190,7 @@ v8_executable("unittests") { } deps = [ + ":inspector_unittests_sources", ":unittests_sources", ":v8_heap_base_unittests_sources", "../..:v8_for_testing", @@ -708,6 +709,24 @@ v8_source_set("unittests_sources") { } } +v8_source_set("inspector_unittests_sources") { + testonly = true + + sources = [ "inspector/inspector-unittest.cc" ] + + configs = [ + "../..:external_config", + "../..:internal_config_base", + ":gcc_warnings_not_errors", + ] + + deps = [ + "../..:v8_for_testing", + "//testing/gmock", + "//testing/gtest", + ] +} + v8_executable("generate-bytecode-expectations") { testonly = true diff --git a/test/cctest/test-inspector.cc b/test/unittests/inspector/inspector-unittest.cc similarity index 84% rename from test/cctest/test-inspector.cc rename to test/unittests/inspector/inspector-unittest.cc index 29bd9f5193..442c32a118 100644 --- a/test/cctest/test-inspector.cc +++ b/test/unittests/inspector/inspector-unittest.cc @@ -9,7 +9,8 @@ #include "include/v8-primitive.h" #include "src/inspector/string-util.h" #include "src/inspector/v8-inspector-impl.h" -#include "test/cctest/cctest.h" +#include "test/unittests/test-utils.h" +#include "testing/gtest/include/gtest/gtest.h" using v8_inspector::String16; using v8_inspector::StringBuffer; @@ -20,6 +21,11 @@ using v8_inspector::V8ContextInfo; using v8_inspector::V8Inspector; using v8_inspector::V8InspectorSession; +namespace v8 { +namespace internal { + +using InspectorTest = TestWithContext; + namespace { class NoopChannel : public V8Inspector::Channel { @@ -42,9 +48,8 @@ void WrapOnInterrupt(v8::Isolate* isolate, void* data) { } // namespace -TEST(WrapInsideWrapOnInterrupt) { - LocalContext env; - v8::Isolate* isolate = env->GetIsolate(); +TEST_F(InspectorTest, WrapInsideWrapOnInterrupt) { + v8::Isolate* isolate = v8_isolate(); v8::HandleScope handle_scope(isolate); v8_inspector::V8InspectorClient default_client; @@ -52,7 +57,7 @@ TEST(WrapInsideWrapOnInterrupt) { V8Inspector::create(isolate, &default_client); const char* name = ""; StringView name_view(reinterpret_cast(name), strlen(name)); - V8ContextInfo context_info(env.local(), 1, name_view); + V8ContextInfo context_info(v8_context(), 1, name_view); inspector->contextCreated(context_info); NoopChannel channel; @@ -65,10 +70,11 @@ TEST(WrapInsideWrapOnInterrupt) { StringView object_group_view(reinterpret_cast(object_group), strlen(object_group)); isolate->RequestInterrupt(&WrapOnInterrupt, session.get()); - session->wrapObject(env.local(), v8::Null(isolate), object_group_view, false); + session->wrapObject(v8_context(), v8::Null(isolate), object_group_view, + false); } -TEST(BinaryFromBase64) { +TEST_F(InspectorTest, BinaryFromBase64) { auto checkBinary = [](const v8_inspector::protocol::Binary& binary, const std::vector& values) { std::vector binary_vector(binary.data(), @@ -133,7 +139,7 @@ TEST(BinaryFromBase64) { } } -TEST(BinaryToBase64) { +TEST_F(InspectorTest, BinaryToBase64) { uint8_t input[] = {'a', 'b', 'c'}; { auto binary = v8_inspector::protocol::Binary::fromSpan(input, 0); @@ -157,7 +163,7 @@ TEST(BinaryToBase64) { } } -TEST(BinaryBase64RoundTrip) { +TEST_F(InspectorTest, BinaryBase64RoundTrip) { std::array values; for (uint16_t b = 0x0; b <= 0xFF; ++b) values[b] = b; auto binary = @@ -173,20 +179,18 @@ TEST(BinaryBase64RoundTrip) { } } -TEST(NoInterruptOnGetAssociatedData) { - LocalContext env; - v8::Isolate* isolate = env->GetIsolate(); +TEST_F(InspectorTest, NoInterruptOnGetAssociatedData) { + v8::Isolate* isolate = v8_isolate(); v8::HandleScope handle_scope(isolate); v8_inspector::V8InspectorClient default_client; std::unique_ptr inspector( new v8_inspector::V8InspectorImpl(isolate, &default_client)); - v8::Local context = env->GetIsolate()->GetCurrentContext(); - v8::Local error = v8::Exception::Error(v8_str("custom error")); - v8::Local key = v8_str("key"); - v8::Local value = v8_str("value"); - inspector->associateExceptionData(context, error, key, value); + v8::Local error = v8::Exception::Error(NewString("custom error")); + v8::Local key = NewString("key"); + v8::Local value = NewString("value"); + inspector->associateExceptionData(v8_context(), error, key, value); struct InterruptRecorder { static void handler(v8::Isolate* isolate, void* data) { @@ -202,21 +206,20 @@ TEST(NoInterruptOnGetAssociatedData) { inspector->getAssociatedExceptionData(error).ToLocalChecked(); CHECK(!recorder.WasInvoked); - CHECK_EQ(data->Get(context, key).ToLocalChecked(), value); + CHECK_EQ(data->Get(v8_context(), key).ToLocalChecked(), value); - CompileRun("0"); + TryRunJS("0"); CHECK(recorder.WasInvoked); } -TEST(NoConsoleAPIForUntrustedClient) { - LocalContext env; - v8::Isolate* isolate = env->GetIsolate(); +TEST_F(InspectorTest, NoConsoleAPIForUntrustedClient) { + v8::Isolate* isolate = v8_isolate(); v8::HandleScope handle_scope(isolate); v8_inspector::V8InspectorClient default_client; std::unique_ptr inspector = V8Inspector::create(isolate, &default_client); - V8ContextInfo context_info(env.local(), 1, toStringView("")); + V8ContextInfo context_info(v8_context(), 1, toStringView("")); inspector->contextCreated(context_info); class TestChannel : public V8Inspector::Channel { @@ -255,16 +258,15 @@ TEST(NoConsoleAPIForUntrustedClient) { untrusted_session->dispatchProtocolMessage(toStringView(kCommand)); } -TEST(ApiCreatedTasksAreCleanedUp) { +TEST_F(InspectorTest, ApiCreatedTasksAreCleanedUp) { i::FLAG_experimental_async_stack_tagging_api = true; - LocalContext env; - v8::Isolate* isolate = env->GetIsolate(); + v8::Isolate* isolate = v8_isolate(); v8::HandleScope handle_scope(isolate); v8_inspector::V8InspectorClient default_client; std::unique_ptr inspector = std::make_unique(isolate, &default_client); - V8ContextInfo context_info(env.local(), 1, toStringView("")); + V8ContextInfo context_info(v8_context(), 1, toStringView("")); inspector->contextCreated(context_info); // Trigger V8Console creation. @@ -273,19 +275,22 @@ TEST(ApiCreatedTasksAreCleanedUp) { { v8::HandleScope handle_scope(isolate); - v8::MaybeLocal result = CompileRun(env.local(), R"( + v8::MaybeLocal result = TryRunJS(isolate, NewString(R"( globalThis['task'] = console.createTask('Task'); - )"); + )")); CHECK(!result.IsEmpty()); // Run GC and check that the task is still here. - CcTest::CollectAllGarbage(); + CollectAllGarbage(); CHECK_EQ(console->AllConsoleTasksForTest().size(), 1); } // Get rid of the task on the context, run GC and check we no longer have // the TaskInfo in the inspector. - env->Global()->Delete(env.local(), v8_str("task")).Check(); - CcTest::CollectAllGarbage(); + v8_context()->Global()->Delete(v8_context(), NewString("task")).Check(); + CollectAllGarbage(); CHECK_EQ(console->AllConsoleTasksForTest().size(), 0); } + +} // namespace internal +} // namespace v8