chromium/content/services/auction_worklet/auction_v8_helper_unittest.cc

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

#include "content/services/auction_worklet/auction_v8_helper.h"

#include <stdint.h>

#include <limits>
#include <optional>
#include <string>
#include <vector>

#include "base/functional/callback.h"
#include "base/strings/stringprintf.h"
#include "base/synchronization/lock.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/bind.h"
#include "base/test/task_environment.h"
#include "base/time/time.h"
#include "content/services/auction_worklet/public/mojom/bidder_worklet.mojom.h"
#include "content/services/auction_worklet/worklet_devtools_debug_test_util.h"
#include "content/services/auction_worklet/worklet_v8_debug_test_util.h"
#include "gin/converter.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
#include "testing/gmock/include/gmock/gmock-matchers.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/interest_group/ad_display_size.h"
#include "url/gurl.h"
#include "v8/include/v8-context.h"
#include "v8/include/v8-forward.h"
#include "v8/include/v8-wasm.h"

ElementsAre;
HasSubstr;
StartsWith;

namespace auction_worklet {

// The bytes of a minimal WebAssembly module, courtesy of
// v8/test/cctest/test-api-wasm.cc
const char kMinimalWasmModuleBytes[] =;

// ConnectDevToolsAgent takes an associated interface, which normally needs to
// be passed through a different pipe to be usable.  The usual way of testing
// this is by using BindNewEndpointAndPassDedicatedReceiver to force creation
// of a new pipe.  Unfortunately, this doesn't appear to be compatible with how
// our threads are setup.  So instead, we emulate how this would normally be
// used: by call to a worklet, and just have a mock implementation that only
// supports ConnectDevToolsAgent.
class DebugConnector : public auction_worklet::mojom::BidderWorklet {};

class AuctionV8HelperTest : public testing::Test {};

// Compile a script with the scratch context, and then run it in two different
// contexts.
TEST_F(AuctionV8HelperTest, Basic) {}

// Check that timing out scripts works.
TEST_F(AuctionV8HelperTest, Timeout) {}

// Make sure the when CreateContext() is used, there's no access to the time,
// which mitigates Specter-style attacks.
TEST_F(AuctionV8HelperTest, NoTime) {}

// A script that doesn't compile.
TEST_F(AuctionV8HelperTest, CompileError) {}

// Test for exception at runtime at top-level.
TEST_F(AuctionV8HelperTest, RunErrorTopLevel) {}

// Test for when desired function isn't found
TEST_F(AuctionV8HelperTest, TargetFunctionNotFound) {}

TEST_F(AuctionV8HelperTest, TargetFunctionError) {}

TEST_F(AuctionV8HelperTest, ConsoleLog) {}

TEST_F(AuctionV8HelperTest, FormatScriptName) {}

TEST_F(AuctionV8HelperTest, ContextIDs) {}

TEST_F(AuctionV8HelperTest, AllocWrap) {}

TEST_F(AuctionV8HelperTest, DebuggerBasics) {}

TEST_F(AuctionV8HelperTest, DebugCompileError) {}

TEST_F(AuctionV8HelperTest, DevToolsDebuggerBasics) {}

TEST_F(AuctionV8HelperTest, DevToolsAgentDebuggerInstrumentationBreakpoint) {}

TEST_F(AuctionV8HelperTest, DevToolsDebuggerInvalidCommand) {}

TEST_F(AuctionV8HelperTest, DevToolsDeleteSessionPipeLate) {}

class MockTimeAuctionV8HelperTest : public AuctionV8HelperTest {};

TEST_F(MockTimeAuctionV8HelperTest, TimelimitDebug) {}

TEST_F(AuctionV8HelperTest, DebugTimeout) {}

TEST_F(AuctionV8HelperTest, CompileWasm) {}

TEST_F(AuctionV8HelperTest, CompileWasmError) {}

TEST_F(AuctionV8HelperTest, CompileWasmDebug) {}

TEST_F(AuctionV8HelperTest, CloneWasmModule) {}

TEST_F(AuctionV8HelperTest, SerializeDeserialize) {}

TEST_F(AuctionV8HelperTest, ExtractJsonTimeout) {}

}  // namespace auction_worklet