Commit 11cfdb6e authored by Tom McKee's avatar Tom McKee Committed by Commit Bot

[UserTimingL3] Add unit tests for PerformanceMark

The added tests exercise the construction of PerformanceMark objects
and make sure that simple script values can round-trip through the
"detail" attribute.

An unnecessary parameter was also removed from PerformanceMark's
constructor.

Bug: 805566
Change-Id: I63e7980235a1d8f9c3b79ba06131bbbe5aee5ac3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1872455
Commit-Queue: Tom McKee <tommckee@chromium.org>
Reviewed-by: default avatarSteve Kobes <skobes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#707975}
parent a6ee75d9
......@@ -1574,6 +1574,7 @@ jumbo_source_set("unit_tests") {
"testing/sim/sim_test.cc",
"testing/sim/sim_test.h",
"timing/memory_info_test.cc",
"timing/performance_mark_test.cc",
"timing/performance_navigation_timing_test.cc",
"timing/performance_observer_test.cc",
"timing/performance_resource_timing_test.cc",
......
......@@ -17,7 +17,6 @@
namespace blink {
PerformanceMark::PerformanceMark(
ScriptState* script_state,
const AtomicString& name,
double start_time,
scoped_refptr<SerializedScriptValue> serialized_detail,
......@@ -41,9 +40,8 @@ PerformanceMark* PerformanceMark::Create(ScriptState* script_state,
if (exception_state.HadException())
return nullptr;
}
return MakeGarbageCollected<PerformanceMark>(script_state, name, start_time,
std::move(serialized_detail),
exception_state);
return MakeGarbageCollected<PerformanceMark>(
name, start_time, std::move(serialized_detail), exception_state);
}
// static
......
......@@ -54,8 +54,7 @@ class CORE_EXPORT PerformanceMark final : public PerformanceEntry {
PerformanceMarkOptions*,
ExceptionState&);
PerformanceMark(ScriptState*,
const AtomicString& name,
PerformanceMark(const AtomicString& name,
double start_time,
scoped_refptr<SerializedScriptValue>,
ExceptionState& exception_state);
......
// Copyright 2019 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 "third_party/blink/renderer/core/timing/performance_mark.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/renderer/bindings/core/v8/script_value.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_testing.h"
#include "third_party/blink/renderer/core/performance_entry_names.h"
#include "third_party/blink/renderer/core/timing/performance_mark_options.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/bindings/script_state.h"
namespace blink {
TEST(PerformanceMarkTest, CreateWithScriptValue) {
V8TestingScope scope;
ExceptionState& exception_state = scope.GetExceptionState();
ScriptState* script_state = scope.GetScriptState();
v8::Isolate* isolate = scope.GetIsolate();
scoped_refptr<SerializedScriptValue> payload_string =
SerializedScriptValue::Create(String("some-payload"));
ScriptValue script_value(isolate, payload_string->Deserialize(isolate));
PerformanceMark* pm = PerformanceMark::Create(script_state, "mark-name",
/*start_time=*/0.0,
script_value, exception_state);
ASSERT_EQ(pm->entryType(), performance_entry_names::kMark);
ASSERT_EQ(pm->EntryTypeEnum(), PerformanceEntry::EntryType::kMark);
ASSERT_EQ(payload_string->Deserialize(isolate),
pm->detail(script_state).V8Value());
}
TEST(PerformanceMarkTest, CreateWithOptions) {
V8TestingScope scope;
ExceptionState& exception_state = scope.GetExceptionState();
ScriptState* script_state = scope.GetScriptState();
v8::Isolate* isolate = scope.GetIsolate();
scoped_refptr<SerializedScriptValue> payload_string =
SerializedScriptValue::Create(String("some-payload"));
ScriptValue script_value(isolate, payload_string->Deserialize(isolate));
PerformanceMarkOptions* options = PerformanceMarkOptions::Create();
options->setDetail(script_value);
PerformanceMark* pm = PerformanceMark::Create(script_state, "mark-name",
options, exception_state);
ASSERT_EQ(pm->entryType(), performance_entry_names::kMark);
ASSERT_EQ(pm->EntryTypeEnum(), PerformanceEntry::EntryType::kMark);
ASSERT_EQ(payload_string->Deserialize(isolate),
pm->detail(script_state).V8Value());
}
TEST(PerformanceMarkTest, Construction) {
V8TestingScope scope;
ExceptionState& exception_state = scope.GetExceptionState();
ScriptState* script_state = scope.GetScriptState();
v8::Isolate* isolate = scope.GetIsolate();
PerformanceMark* pm = MakeGarbageCollected<PerformanceMark>(
"mark-name", 0, SerializedScriptValue::NullValue(), exception_state);
ASSERT_EQ(pm->entryType(), performance_entry_names::kMark);
ASSERT_EQ(pm->EntryTypeEnum(), PerformanceEntry::EntryType::kMark);
ASSERT_EQ(SerializedScriptValue::NullValue()->Deserialize(isolate),
pm->detail(script_state).V8Value());
}
TEST(PerformanceMarkTest, ConstructionWithDetail) {
V8TestingScope scope;
ExceptionState& exception_state = scope.GetExceptionState();
ScriptState* script_state = scope.GetScriptState();
v8::Isolate* isolate = scope.GetIsolate();
scoped_refptr<SerializedScriptValue> payload_string =
SerializedScriptValue::Create(String("some-payload"));
PerformanceMark* pm = MakeGarbageCollected<PerformanceMark>(
"mark-name", 0, payload_string, exception_state);
ASSERT_EQ(pm->entryType(), performance_entry_names::kMark);
ASSERT_EQ(pm->EntryTypeEnum(), PerformanceEntry::EntryType::kMark);
ASSERT_EQ(payload_string->Deserialize(isolate),
pm->detail(script_state).V8Value());
}
} // namespace blink
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment