Commit 5e52a691 authored by Tom McKee's avatar Tom McKee Committed by Commit Bot

Make WindowPerformanceTest use one object-under-test

WindowPerformanceTest exists to check the behaviour of WindowPerformance
instances. It used to mock a page with DummyPageHolder (which, by way of
a LocalDOMWindow, would end up owning a WindowPerformance instance) as
well as construct its own WindowPerformance instance. This lead to the
mock objects referring to a separate, intrinsic WindowPerformance than
the one being directly manipulated by the tests.

This change removes the one-off constructed WindowPerformance and
exercises the WindowPerformance from the mock objects instead.

Change-Id: I90980074362c36b630252a82f58b973ae1963965
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1965942Reviewed-by: default avatarNicolás Peña Moreno <npm@chromium.org>
Commit-Queue: Tom McKee <tommckee@chromium.org>
Cr-Commit-Position: refs/heads/master@{#728547}
parent 11794d47
...@@ -80,8 +80,9 @@ class WindowPerformanceTest : public testing::Test { ...@@ -80,8 +80,9 @@ class WindowPerformanceTest : public testing::Test {
void ResetPerformance() { void ResetPerformance() {
page_holder_ = std::make_unique<DummyPageHolder>(IntSize(800, 600)); page_holder_ = std::make_unique<DummyPageHolder>(IntSize(800, 600));
page_holder_->GetDocument().SetURL(KURL("https://example.com")); page_holder_->GetDocument().SetURL(KURL("https://example.com"));
performance_ = MakeGarbageCollected<WindowPerformance>(
page_holder_->GetDocument().domWindow()); LocalDOMWindow* window = LocalDOMWindow::From(GetScriptState());
performance_ = DOMWindowPerformance::performance(*window);
unified_clock_ = std::make_unique<Performance::UnifiedClock>( unified_clock_ = std::make_unique<Performance::UnifiedClock>(
test_task_runner_->GetMockClock(), test_task_runner_->GetMockClock(),
test_task_runner_->GetMockTickClock()); test_task_runner_->GetMockTickClock());
...@@ -89,6 +90,10 @@ class WindowPerformanceTest : public testing::Test { ...@@ -89,6 +90,10 @@ class WindowPerformanceTest : public testing::Test {
performance_->time_origin_ = GetTimeOrigin(); performance_->time_origin_ = GetTimeOrigin();
} }
ScriptState* GetScriptState() const {
return ToScriptStateForMainWorld(page_holder_->GetDocument().GetFrame());
}
Persistent<WindowPerformance> performance_; Persistent<WindowPerformance> performance_;
std::unique_ptr<DummyPageHolder> page_holder_; std::unique_ptr<DummyPageHolder> page_holder_;
scoped_refptr<base::TestMockTimeTaskRunner> test_task_runner_; scoped_refptr<base::TestMockTimeTaskRunner> test_task_runner_;
...@@ -190,7 +195,10 @@ TEST(PerformanceLifetimeTest, SurviveContextSwitch) { ...@@ -190,7 +195,10 @@ TEST(PerformanceLifetimeTest, SurviveContextSwitch) {
// Make sure the output entries with the same timestamps follow the insertion // Make sure the output entries with the same timestamps follow the insertion
// order. (http://crbug.com/767560) // order. (http://crbug.com/767560)
TEST_F(WindowPerformanceTest, EnsureEntryListOrder) { TEST_F(WindowPerformanceTest, EnsureEntryListOrder) {
V8TestingScope scope; // Need to have an active V8 context for ScriptValues to operate.
v8::HandleScope handle_scope(GetScriptState()->GetIsolate());
v8::Local<v8::Context> context = GetScriptState()->GetContext();
v8::Context::Scope context_scope(context);
auto initial_offset = auto initial_offset =
test_task_runner_->NowTicks().since_origin().InSecondsF(); test_task_runner_->NowTicks().since_origin().InSecondsF();
test_task_runner_->FastForwardBy(GetTimeOrigin() - base::TimeTicks()); test_task_runner_->FastForwardBy(GetTimeOrigin() - base::TimeTicks());
...@@ -198,12 +206,12 @@ TEST_F(WindowPerformanceTest, EnsureEntryListOrder) { ...@@ -198,12 +206,12 @@ TEST_F(WindowPerformanceTest, EnsureEntryListOrder) {
DummyExceptionStateForTesting exception_state; DummyExceptionStateForTesting exception_state;
test_task_runner_->FastForwardBy(base::TimeDelta::FromSeconds(2)); test_task_runner_->FastForwardBy(base::TimeDelta::FromSeconds(2));
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
performance_->mark(scope.GetScriptState(), AtomicString::Number(i), nullptr, performance_->mark(GetScriptState(), AtomicString::Number(i), nullptr,
exception_state); exception_state);
} }
test_task_runner_->FastForwardBy(base::TimeDelta::FromSeconds(2)); test_task_runner_->FastForwardBy(base::TimeDelta::FromSeconds(2));
for (int i = 8; i < 17; i++) { for (int i = 8; i < 17; i++) {
performance_->mark(scope.GetScriptState(), AtomicString::Number(i), nullptr, performance_->mark(GetScriptState(), AtomicString::Number(i), nullptr,
exception_state); exception_state);
} }
PerformanceEntryVector entries = performance_->getEntries(); PerformanceEntryVector entries = performance_->getEntries();
......
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