Commit 6a7ccf89 authored by Pavel Feldman's avatar Pavel Feldman

Headless: port more tests to the new protocol harness.

Change-Id: I4746041f5ff8285e21322c99c897fb9e2e2da19c
Reviewed-on: https://chromium-review.googlesource.com/1066700Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#560074}
parent a5b4ac95
......@@ -83,94 +83,6 @@ class VirtualTimeBrowserTest : public HeadlessAsyncDevTooledBrowserTest,
bool runtime_enabled = false;
};
class VirtualTimeBaseTest : public VirtualTimeBrowserTest {
public:
VirtualTimeBaseTest() {
EXPECT_TRUE(embedded_test_server()->Start());
SetInitialURL(embedded_test_server()->GetURL("/blank.html").spec());
}
void SetVirtualTimePolicy() override {
// Set to paused initially.
devtools_client_->GetEmulation()->GetExperimental()->SetVirtualTimePolicy(
emulation::SetVirtualTimePolicyParams::Builder()
.SetPolicy(emulation::VirtualTimePolicy::PAUSE)
.Build(),
base::BindRepeating(&VirtualTimeBaseTest::SetFirstVirtualTimePolicyDone,
base::Unretained(this)));
}
void SetFirstVirtualTimePolicyDone(
std::unique_ptr<emulation::SetVirtualTimePolicyResult> result) {
// Should have enabled virtual time, and returned a valid time base.
virtual_time_ticks_base_ = result->GetVirtualTimeTicksBase();
EXPECT_NE(0, virtual_time_ticks_base_);
// Set with wait_for_navigation, the returned time base shouldn't change.
devtools_client_->GetEmulation()->GetExperimental()->SetVirtualTimePolicy(
emulation::SetVirtualTimePolicyParams::Builder()
.SetPolicy(
emulation::VirtualTimePolicy::PAUSE_IF_NETWORK_FETCHES_PENDING)
.SetBudget(1000)
.SetWaitForNavigation(true)
.Build(),
base::BindRepeating(
&VirtualTimeBaseTest::SetSecondVirtualTimePolicyDone,
base::Unretained(this)));
}
void SetSecondVirtualTimePolicyDone(
std::unique_ptr<emulation::SetVirtualTimePolicyResult> result) {
EXPECT_EQ(virtual_time_ticks_base_, result->GetVirtualTimeTicksBase());
SetVirtualTimePolicyDone(std::move(result));
}
// emulation::Observer implementation:
void OnVirtualTimeBudgetExpired(
const emulation::VirtualTimeBudgetExpiredParams& params) override {
FinishAsynchronousTest();
}
private:
double virtual_time_ticks_base_ = 0;
};
HEADLESS_ASYNC_DEVTOOLED_TEST_F(VirtualTimeBaseTest);
class MaxVirtualTimeTaskStarvationCountTest : public VirtualTimeBrowserTest {
public:
MaxVirtualTimeTaskStarvationCountTest() {
EXPECT_TRUE(embedded_test_server()->Start());
SetInitialURL(embedded_test_server()
->GetURL("/virtual_time_starvation_test.html")
.spec());
}
void SetVirtualTimePolicy() override {
devtools_client_->GetEmulation()->GetExperimental()->SetVirtualTimePolicy(
emulation::SetVirtualTimePolicyParams::Builder()
.SetPolicy(
emulation::VirtualTimePolicy::PAUSE_IF_NETWORK_FETCHES_PENDING)
.SetBudget(4001)
.SetMaxVirtualTimeTaskStarvationCount(100)
.SetWaitForNavigation(true)
.Build(),
base::BindRepeating(&VirtualTimeBrowserTest::SetVirtualTimePolicyDone,
base::Unretained(this)));
}
// emulation::Observer implementation:
void OnVirtualTimeBudgetExpired(
const emulation::VirtualTimeBudgetExpiredParams& params) override {
// If SetMaxVirtualTimeTaskStarvationCount was not set, this callback would
// never fire.
FinishAsynchronousTest();
}
};
HEADLESS_ASYNC_DEVTOOLED_TEST_F(MaxVirtualTimeTaskStarvationCountTest);
namespace {
static constexpr char kIndexHtml[] = R"(
<html>
......@@ -267,112 +179,6 @@ class FrameDetatchWithPendingResourceLoadVirtualTimeTest
HEADLESS_ASYNC_DEVTOOLED_TEST_F(
FrameDetatchWithPendingResourceLoadVirtualTimeTest);
class VirtualTimeLocalStorageTest : public VirtualTimeBrowserTest {
public:
VirtualTimeLocalStorageTest() {
EXPECT_TRUE(embedded_test_server()->Start());
SetInitialURL(embedded_test_server()
->GetURL("/virtual_time_local_storage.html")
.spec());
}
void OnConsoleAPICalled(
const runtime::ConsoleAPICalledParams& params) override {
EXPECT_EQ(runtime::ConsoleAPICalledType::LOG, params.GetType());
ASSERT_EQ(1u, params.GetArgs()->size());
ASSERT_EQ(runtime::RemoteObjectType::STRING,
(*params.GetArgs())[0]->GetType());
std::string count_string = (*params.GetArgs())[0]->GetValue()->GetString();
int count;
ASSERT_TRUE(base::StringToInt(count_string, &count)) << count_string;
EXPECT_EQ(count, 400);
console_log_seen_ = true;
}
// emulation::Observer implementation:
void OnVirtualTimeBudgetExpired(
const emulation::VirtualTimeBudgetExpiredParams& params) override {
// If SetMaxVirtualTimeTaskStarvationCount was not set, this callback would
// never fire.
EXPECT_TRUE(console_log_seen_);
FinishAsynchronousTest();
}
bool console_log_seen_ = false;
};
HEADLESS_ASYNC_DEVTOOLED_TEST_F(VirtualTimeLocalStorageTest);
class VirtualTimeSessionStorageTest : public VirtualTimeBrowserTest {
public:
VirtualTimeSessionStorageTest() {
EXPECT_TRUE(embedded_test_server()->Start());
SetInitialURL(embedded_test_server()
->GetURL("/virtual_time_session_storage.html")
.spec());
}
void OnConsoleAPICalled(
const runtime::ConsoleAPICalledParams& params) override {
EXPECT_EQ(runtime::ConsoleAPICalledType::LOG, params.GetType());
ASSERT_EQ(1u, params.GetArgs()->size());
ASSERT_EQ(runtime::RemoteObjectType::STRING,
(*params.GetArgs())[0]->GetType());
std::string count_string = (*params.GetArgs())[0]->GetValue()->GetString();
int count;
ASSERT_TRUE(base::StringToInt(count_string, &count)) << count_string;
EXPECT_EQ(count, 400);
console_log_seen_ = true;
}
// emulation::Observer implementation:
void OnVirtualTimeBudgetExpired(
const emulation::VirtualTimeBudgetExpiredParams& params) override {
// If SetMaxVirtualTimeTaskStarvationCount was not set, this callback would
// never fire.
EXPECT_TRUE(console_log_seen_);
FinishAsynchronousTest();
}
bool console_log_seen_ = false;
};
HEADLESS_ASYNC_DEVTOOLED_TEST_F(VirtualTimeSessionStorageTest);
class DeferredLoadDoesntBlockVirtualTimeTest : public VirtualTimeBrowserTest {
public:
DeferredLoadDoesntBlockVirtualTimeTest() {
EXPECT_TRUE(embedded_test_server()->Start());
SetInitialURL(embedded_test_server()->GetURL("/video.html").spec());
}
// emulation::Observer implementation:
void OnVirtualTimeBudgetExpired(
const emulation::VirtualTimeBudgetExpiredParams& params) override {
// The video should not block virtual time.
FinishAsynchronousTest();
}
};
HEADLESS_ASYNC_DEVTOOLED_TEST_F(DeferredLoadDoesntBlockVirtualTimeTest);
class Http404DoesntBlockVirtualTimeTest : public VirtualTimeBrowserTest {
public:
Http404DoesntBlockVirtualTimeTest() {
EXPECT_TRUE(embedded_test_server()->Start());
SetInitialURL(embedded_test_server()->GetURL("/NoSuchFile.html").spec());
}
// emulation::Observer implementation:
void OnVirtualTimeBudgetExpired(
const emulation::VirtualTimeBudgetExpiredParams& params) override {
// The video should not block virtual time.
FinishAsynchronousTest();
}
};
HEADLESS_ASYNC_DEVTOOLED_TEST_F(Http404DoesntBlockVirtualTimeTest);
class RedirectVirtualTimeTest : public VirtualTimeBrowserTest {
public:
RedirectVirtualTimeTest() { SetInitialURL("http://test.com/index.html"); }
......
<!doctype html>
<head>
<script>
// Note define() defines a module in the mojo module dependency
// system. While we don't expose our module, the callback below only
// fires after the requested modules have been loaded.
define([
'headless/lib/embedder_test.mojom',
'content/public/renderer/frame_interfaces',
], function(embedderMojom, frameInterfaces) {
var testEmbedderService = new embedderMojom.TestEmbedderServicePtr(
frameInterfaces.getInterface(embedderMojom.TestEmbedderService.name));
// Send a message to the embedder!
testEmbedderService.returnTestResult('page one');
});
</script>
</head>
<body><h1>Page one</h1></body>
<!doctype html>
<head>
<script>
// Note define() defines a module in the mojo module dependency
// system. While we don't expose our module, the callback below only
// fires after the requested modules have been loaded.
define([
'headless/lib/embedder_test.mojom',
'content/public/renderer/frame_interfaces',
], function(embedderMojom, frameInterfaces) {
var testEmbedderService = new embedderMojom.TestEmbedderServicePtr(
frameInterfaces.getInterface(embedderMojom.TestEmbedderService.name));
// Send a message to the embedder!
testEmbedderService.returnTestResult('page two');
});
</script>
</head>
<body><h1>Page two</h1></body>
......@@ -8,7 +8,7 @@
window.addEventListener('message', callback, false);
window.postMessage('message', '*');
window.setTimeout(function() {
console.log('event count: ' + event_count);
console.log('Timer Fired, alot of events seen: ' + (event_count > 1));
}, 4000);
</script>
</html>
<!DOCTYPE html>
<html>
<body>
<video controls>
<source src="video.webm" type="audio/webm">
</video>
</body>
</html>
Tests virtual time is not blocked by 404 page.
\ No newline at end of file
// 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.
(async function(testRunner) {
var {page, session, dp} = await testRunner.startBlank(
`Tests virtual time is not blocked by 404 page.`);
dp.Emulation.onVirtualTimeBudgetExpired(data => testRunner.completeTest());
await dp.Emulation.setVirtualTimePolicy({policy: 'pause'});
dp.Page.navigate({url: testRunner.url('/no-such-file.html')});
await dp.Emulation.setVirtualTimePolicy({
policy: 'pauseIfNetworkFetchesPending',
budget: 5000, waitForNavigation: true});
})
Tests virtual time basics.
\ No newline at end of file
// 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.
(async function(testRunner) {
var {page, session, dp} = await testRunner.startBlank(
`Tests virtual time basics.`);
dp.Emulation.onVirtualTimeBudgetExpired(data => testRunner.completeTest());
await dp.Emulation.setVirtualTimePolicy({policy: 'pause'});
dp.Page.navigate({url: testRunner.url('/resources/blank.html')});
await dp.Emulation.setVirtualTimePolicy({
policy: 'pauseIfNetworkFetchesPending',
budget: 1000, waitForNavigation: true});
})
Tests virtual time with local storage.
400
\ No newline at end of file
// 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.
(async function(testRunner) {
var {page, session, dp} = await testRunner.startBlank(
`Tests virtual time with local storage.`);
await dp.Runtime.enable();
dp.Runtime.onConsoleAPICalled(data => {
const text = data.params.args[0].value;
testRunner.log(text);
});
dp.Emulation.onVirtualTimeBudgetExpired(data => testRunner.completeTest());
await dp.Emulation.setVirtualTimePolicy({policy: 'pause'});
dp.Page.navigate({url: testRunner.url('resources/virtual-time-local-storage.html')});
await dp.Emulation.setVirtualTimePolicy({
policy: 'pauseIfNetworkFetchesPending',
budget: 5000, waitForNavigation: true});
})
Tests virtual time with session storage.
400
\ No newline at end of file
// 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.
(async function(testRunner) {
var {page, session, dp} = await testRunner.startBlank(
`Tests virtual time with session storage.`);
await dp.Runtime.enable();
dp.Runtime.onConsoleAPICalled(data => {
const text = data.params.args[0].value;
testRunner.log(text);
});
dp.Emulation.onVirtualTimeBudgetExpired(data => testRunner.completeTest());
await dp.Emulation.setVirtualTimePolicy({policy: 'pause'});
dp.Page.navigate({url: testRunner.url('resources/virtual-time-session-storage.html')});
await dp.Emulation.setVirtualTimePolicy({
policy: 'pauseIfNetworkFetchesPending',
budget: 5000, waitForNavigation: true});
})
Tests that virtual time advances.
Timer Fired, alot of events seen: true
\ No newline at end of file
// 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.
(async function(testRunner) {
var {page, session, dp} = await testRunner.startBlank(`Tests that virtual time advances.`);
await dp.Page.enable();
await dp.Runtime.enable();
// If there is no starvation, budget never expires.
dp.Emulation.onVirtualTimeBudgetExpired(data => testRunner.completeTest());
dp.Runtime.onConsoleAPICalled(data => {
const text = data.params.args[0].value;
testRunner.log(text);
});
await dp.Emulation.setVirtualTimePolicy({policy: 'pause'});
dp.Page.navigate({url: testRunner.url('resources/virtual-time-starvation.html')});
await dp.Emulation.setVirtualTimePolicy({
policy: 'pauseIfNetworkFetchesPending', budget: 4011, waitForNavigation: true,
maxVirtualTimeTaskStarvationCount: 100});
})
Tests that video does not block virtual time.
\ No newline at end of file
// 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.
(async function(testRunner) {
var {page, session, dp} = await testRunner.startBlank(
`Tests that video does not block virtual time.`);
dp.Emulation.onVirtualTimeBudgetExpired(data => testRunner.completeTest());
await dp.Emulation.setVirtualTimePolicy({policy: 'pause'});
dp.Page.navigate({url: testRunner.url('resources/virtual-time-video.html')});
await dp.Emulation.setVirtualTimePolicy({
policy: 'pauseIfNetworkFetchesPending',
budget: 5000, waitForNavigation: true});
})
......@@ -157,7 +157,16 @@ class HeadlessProtocolBrowserTest
// Headless-specific tests
HEADLESS_PROTOCOL_TEST(VirtualTimeAdvance, "emulation/virtual-time-advance.js");
HEADLESS_PROTOCOL_TEST(VirtualTimeBasics, "emulation/virtual-time-basics.js");
HEADLESS_PROTOCOL_TEST(VirtualTimeErrorLoop,
"emulation/virtual-time-error-loop.js");
HEADLESS_PROTOCOL_TEST(VirtualTimeNoBlock404, "emulation/virtual-time-404.js");
HEADLESS_PROTOCOL_TEST(VirtualTimeLocalStorage,
"emulation/virtual-time-local-storage.js");
HEADLESS_PROTOCOL_TEST(VirtualTimeSessionStorage,
"emulation/virtual-time-session-storage.js");
HEADLESS_PROTOCOL_TEST(VirtualTimeStarvation,
"emulation/virtual-time-starvation.js");
HEADLESS_PROTOCOL_TEST(VirtualTimeVideo, "emulation/virtual-time-video.js");
} // namespace headless
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