blob: 851b0fd4fb9fd588e23607564d552c53e12326df [file] [log] [blame]
// Copyright 2017 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.addResult(`Tests that console preserves scroll position when switching away.\n`);
await TestRunner.loadModule('console_test_runner');
await TestRunner.showPanel('console');
// Do not use ConsoleTestRunner.fixConsoleViewportDimensions because fixing the height will affect
// tests that may cause scrolling while the console moves into/out of the drawer.
UI.inspectorView.element.style.maxHeight = '600px';
await ConsoleTestRunner.waitUntilConsoleEditorLoaded();
await TestRunner.evaluateInPagePromise(`
for (var i = 0; i < 100; i++)
console.log('foo' + i);
`);
await ConsoleTestRunner.waitForConsoleMessagesPromise(100);
var consoleView = Console.ConsoleView.instance();
var viewport = consoleView._viewport;
viewport.setStickToBottom(false);
// Avoid flakiness by ensuring that messages in visibleViewMessages are in DOM.
viewport.invalidate();
viewport.element.scrollTop = 10;
dumpScrollTop();
UI.inspectorView._tabbedPane.addEventListener(UI.TabbedPane.Events.TabSelected, () => {
TestRunner.addResult('Panel ' + UI.inspectorView._tabbedPane._currentTab.id + ' was opened.');
});
TestRunner.runTestSuite([
async function testSwitchToAnotherPanel(next) {
await TestRunner.showPanel('sources');
await TestRunner.showPanel('console');
dumpScrollTop();
next();
},
async function testClickLinkToRevealAnotherPanel(next) {
consoleView._visibleViewMessages[0]._element.querySelector('.devtools-link').click();
await UI.inspectorView._tabbedPane.once(UI.TabbedPane.Events.TabSelected);
await TestRunner.showPanel('console');
dumpScrollTop();
next();
},
async function testConsolePanelToDrawer(next) {
await TestRunner.showPanel('console');
await showDrawerPromise();
TestRunner.addResult('Drawer panel set to ' + UI.inspectorView._drawerTabbedPane._currentTab.id);
await TestRunner.showPanel('sources');
dumpScrollTop();
await TestRunner.showPanel('console');
dumpScrollTop();
next();
},
async function testCloseDrawerFromConsolePanelAndOpenFromAnotherPanel(next) {
await TestRunner.showPanel('console');
TestRunner.addSniffer(UI.SplitWidget.prototype, '_showFinishedForTest', async () => {
await TestRunner.showPanel('sources');
await showDrawerPromise();
TestRunner.addResult('Drawer panel set to ' + UI.inspectorView._drawerTabbedPane._currentTab.id);
dumpScrollTop();
next();
});
// Close the drawer with animation.
UI.inspectorView._drawerSplitWidget.hideSidebar(true /* animate */);
}
]);
function dumpScrollTop() {
TestRunner.addResult(`Console scrollTop: ${viewport.element.scrollTop}`);
}
async function showDrawerPromise() {
// Restoring scroll positions may occur during materialization, which is
// done asynchronously for TabbedPane contents.
return new Promise((resolve, reject) => {
UI.inspectorView._showDrawer(true);
TestRunner.addSniffer(UI.ViewManager._ContainerWidget.prototype, '_wasShownForTest', resolve);
});
}
})();