chromium/content/services/auction_worklet/worklet_loader_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/worklet_loader.h"

#include <string>
#include <utility>

#include "base/functional/bind.h"
#include "base/run_loop.h"
#include "base/synchronization/waitable_event.h"
#include "base/test/bind.h"
#include "base/test/task_environment.h"
#include "base/test/test_future.h"
#include "base/time/time.h"
#include "content/services/auction_worklet/auction_v8_helper.h"
#include "content/services/auction_worklet/worklet_test_util.h"
#include "content/services/auction_worklet/worklet_v8_debug_test_util.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "net/http/http_status_code.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "services/network/test/test_url_loader_factory.h"
#include "testing/gmock/include/gmock/gmock-matchers.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
#include "v8/include/v8-context.h"
#include "v8/include/v8-wasm.h"

ElementsAre;
HasSubstr;
StartsWith;

namespace auction_worklet {
namespace {

const char kValidScript[] =;
const char kInvalidScript[] =;

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

// None of these tests make sure the right script is compiled, these tests
// merely check success/failure of trying to load a worklet.
class WorkletLoaderTest : public testing::Test {};

TEST_F(WorkletLoaderTest, NetworkError) {}

TEST_F(WorkletLoaderTest, TwoV8Helpers_NetworkError) {}

TEST_F(WorkletLoaderTest, CompileError) {}

TEST_F(WorkletLoaderTest, TwoV8Helpers_CompileError) {}

TEST_F(WorkletLoaderTest, CompileErrorWithDebugger) {}

TEST_F(WorkletLoaderTest, TwoV8Helpers_CompileErrorWithDebugger) {}

TEST_F(WorkletLoaderTest, Success) {}

TEST_F(WorkletLoaderTest, TwoV8Helpers_Success) {}

// Make sure the V8 isolate is released before the callback is invoked on
// success, so that the loader and helper can be torn down without crashing
// during the callback.
TEST_F(WorkletLoaderTest, DeleteDuringCallbackSuccess) {}

// Make sure the V8 isolate is released before the callback is invoked on
// compile failure, so that the loader and helper can be torn down without
// crashing during the callback.
TEST_F(WorkletLoaderTest, DeleteDuringCallbackCompileError) {}

// Testcase where the loader is deleted after it queued the parsing of
// the script on V8 thread, but before that parsing completes.
//
// Also make sure that in this case we can cleanup without relying on main
// thread event loop spinning, as that's needed for synchronizing with
// v8 shutdown.
// (See https://crbug.com/1421754)
TEST_F(WorkletLoaderTest, DeleteBeforeCallback) {}

TEST_F(WorkletLoaderTest, LoadWasmSuccess) {}

TEST_F(WorkletLoaderTest, TwoV8Helpers_LoadWasmSuccess) {}

TEST_F(WorkletLoaderTest, LoadWasmError) {}

TEST_F(WorkletLoaderTest, TwoV8Helpers_LoadWasmError) {}

TEST_F(WorkletLoaderTest, TrustedSignalsHeader) {}

// Test that a response with Ad-Auction-Allow-Trusted-Scoring-Signals-From but
// no Ad-Auction-Allowed does not invoke the trusted signals permissions
// callback, only just a regular failure.
TEST_F(WorkletLoaderTest, TrustedSignalsHeaderNoAllowed) {}

// List headers are combined in the usual HTTP way when specified more than
// once.
TEST_F(WorkletLoaderTest, TrustedSignalsHeaderCombine) {}

TEST_F(WorkletLoaderTest, ParseAllowTrustedScoringSignalsFromHeader) {}

}  // namespace
}  // namespace auction_worklet