blob: a7d5ac3b241f0213c91cb578ca07d16904d54250 [file] [log] [blame]
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <string.h>
#include "build/build_config.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/renderer/platform/bindings/name_client.h"
#include "third_party/blink/renderer/platform/heap/name_traits.h"
namespace blink {
namespace {
class ClassWithoutName final {
ClassWithoutName() = default;
class ClassWithName final : public NameClient {
explicit ClassWithName(const char* name) : name_(name) {}
const char* NameInHeapSnapshot() const final { return name_; }
const char* name_;
} // namespace
TEST(NameTraitTest, InternalNamesHiddenInOfficialBuild) {
// Use a test instead of static_assert to allow local builds but block
// enabling the feature accidentally through the waterfall.
// Do not include such type information in official builds to
// (a) safe binary size on string literals, and
// (b) avoid exposing internal types until it has been clarified whether
// exposing internals in DevTools is fine.
#if defined(OFFICIAL_BUILD)
TEST(NameTraitTest, InternalNamesHiddenWhenFlagIsTurnedOff) {
TEST(NameTraitTest, DefaultName) {
ClassWithoutName no_name;
const char* name = NameTrait<ClassWithoutName>::GetName(&no_name).value;
if (NameClient::HideInternalName()) {
EXPECT_EQ(0, strcmp(name, "InternalNode"));
} else {
EXPECT_NE(nullptr, strstr(name, "ClassWithoutName"));
TEST(NameTraitTest, CustomName) {
ClassWithName with_name("CustomName");
const char* name = NameTrait<ClassWithName>::GetName(&with_name).value;
EXPECT_EQ(0, strcmp(name, "CustomName"));
} // namespace blink