chromium/chrome/renderer/v8_unwinder_unittest.cc

// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/renderer/v8_unwinder.h"

#include <memory>
#include <utility>
#include <vector>

#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/location.h"
#include "base/profiler/module_cache.h"
#include "base/profiler/stack_sampling_profiler_test_util.h"
#include "base/synchronization/waitable_event.h"
#include "base/test/bind.h"
#include "base/test/task_environment.h"
#include "build/build_config.h"
#include "gin/public/isolate_holder.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "v8/include/v8.h"

namespace {

AllOf;
AnyOf;
Contains;
Eq;
Field;
NotNull;
Pointee;
Property;

v8::Local<v8::String> ToV8String(const char* str) {}

v8::Local<v8::Object> CreatePointerHolder(const void* ptr) {}

template <typename T>
T* GetPointerFromHolder(v8::Local<v8::Object> holder) {}

// Sets up the environment necessary to execute V8 code.
class ScopedV8Environment {};

// C++ function to be invoked from V8 which calls back into the provided closure
// pointer (passed via a holder object) to wait for a stack sample to be taken.
void WaitForSampleNative(const v8::FunctionCallbackInfo<v8::Value>& info) {}

// Causes a stack sample to be taken after setting up a call stack from C++ to
// JavaScript and back into C++.
base::FunctionAddressRange CallThroughV8(
    const base::RepeatingCallback<void(v8::Isolate*)>& report_isolate,
    base::OnceClosure wait_for_sample) {}

class UpdateModulesTestUnwinder : public V8Unwinder {};

v8::MemoryRange GetEmbeddedCodeRange(v8::Isolate* isolate) {}

}  // namespace

TEST(V8UnwinderTest, EmbeddedCodeRangeModule) {}

TEST(V8UnwinderTest, EmbeddedCodeRangeModulePreservedOnUpdate) {}

// Checks that the embedded code range is preserved even if it wasn't included
// in the code pages due to insufficient capacity.
TEST(V8UnwinderTest, EmbeddedCodeRangeModulePreservedOnOverCapacityUpdate) {}

TEST(V8UnwinderTest, UpdateModules_ModuleAdded) {}

// Check that modules added before the last module are propagated to the
// ModuleCache. This case takes a different code path in the implementation.
TEST(V8UnwinderTest, UpdateModules_ModuleAddedBeforeLast) {}

TEST(V8UnwinderTest, UpdateModules_ModuleRetained) {}

TEST(V8UnwinderTest, UpdateModules_ModuleRetainedWithDifferentSize) {}

TEST(V8UnwinderTest, UpdateModules_ModuleRemoved) {}

// Check that modules removed before the last module are propagated to the
// ModuleCache. This case takes a different code path in the implementation.
TEST(V8UnwinderTest, UpdateModules_ModuleRemovedBeforeLast) {}

TEST(V8UnwinderTest, UpdateModules_CapacityExceeded) {}

// Checks that the implementation can handle the capacity being exceeded by a
// large amount.
TEST(V8UnwinderTest, UpdateModules_CapacitySubstantiallyExceeded) {}

TEST(V8UnwinderTest, CanUnwindFrom_V8Module) {}

TEST(V8UnwinderTest, CanUnwindFrom_OtherModule) {}

TEST(V8UnwinderTest, CanUnwindFrom_NullModule) {}

// Checks that unwinding from C++ through JavaScript and back into C++ succeeds.
#if (BUILDFLAG(IS_WIN) && defined(ARCH_CPU_64_BITS)) || BUILDFLAG(IS_MAC) || \
    (BUILDFLAG(IS_ANDROID) && defined(ARCH_CPU_ARMEL))
#define MAYBE_UnwindThroughV8Frames
#else
#define MAYBE_UnwindThroughV8Frames
#endif
TEST(V8UnwinderTest, MAYBE_UnwindThroughV8Frames) {}