Commit 3d11d003 authored by John Emau's avatar John Emau Committed by Commit Bot

DevTools: add web audio context selector tests

This change adds basic tests that capture current behavior around the
Audio Context Selector.

It is meant as a start and not a complete list of tests,
more tests should be added in the future.

This also indirectly tests the UI.ListModel, UI.SoftDropDown, and
UI.ToolbarItem.

Change-Id: I7506c06e6cf8b865ab2645c9e9e4004df162e629
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1824060Reviewed-by: default avatarYang Guo <yangguo@chromium.org>
Reviewed-by: default avatarHongchan Choi <hongchan@chromium.org>
Reviewed-by: default avatarMandy Chen <mandy.chen@microsoft.com>
Commit-Queue: John Emau <John.Emau@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#704456}
parent 43c06dab
Tests the AudioContextSelector.
Running: testStartsEmpty
Number of contexts (items): 0
Selected Context: null
Running: testSelectsCreatedContext
Number of contexts (items): 1
Selected Context: {
"contextId": "924c4ee4-4cae-4e62-b4c6-71603edc39fd",
"contextType": "realtime"
}
Running: testResetClearsList
Number of contexts (items): 0
Selected Context: {
"contextId": "924c4ee4-4cae-4e62-b4c6-71603edc39fd",
"contextType": "realtime"
}
Running: testReSelectsCreatedContextAfterChange
Number of contexts (items): 1
Selected Context: {
"contextId": "924c4ee4-4cae-4e62-b4c6-71603edc39fd",
"contextType": "realtime"
}
Running: testFirstCreatedContextStaysSelected
Number of contexts (items): 2
Selected Context: {
"contextId": "924c4ee4-4cae-4e62-b4c6-71603edc39fd",
"contextType": "realtime"
}
Running: testChangingContextDoesNotChangeSelection
Number of contexts (items): 2
Selected Context: {
"contextId": "924c4ee4-4cae-4e62-b4c6-71603edc39fd",
"contextType": "realtime"
}
Running: testSelectedContextBecomesSelected
Number of contexts (items): 2
Selected Context: {
"contextId": "78a3e94e-4968-4bf6-8905-325109695c9e",
"contextType": "realtime"
}
Running: testOnListItemReplacedCalled
_onListItemReplaced called with contexts (items) count: 1
_onListItemReplaced called with contexts (items) count: 0
_onListItemReplaced called with contexts (items) count: 1
Number of contexts (items): 1
Selected Context: {
"contextId": "924c4ee4-4cae-4e62-b4c6-71603edc39fd",
"contextType": "realtime"
}
// 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.
(async function() {
TestRunner.addResult(`Tests the AudioContextSelector.`);
await TestRunner.loadModule('web_audio');
/** @type {!Protocol.WebAudio.BaseAudioContext} */
const context1 = {
contextId: '924c4ee4-4cae-4e62-b4c6-71603edc39fd',
contextType: 'realtime'
};
/** @type {!Protocol.WebAudio.BaseAudioContext} */
const context2 = {
contextId: '78a3e94e-4968-4bf6-8905-325109695c9e',
contextType: 'realtime'
};
function dumpSelectorState(
/** @type {!WebAudio.AudioContextSelector} */ selector) {
TestRunner.addResult(`
Number of contexts (items): ${selector._items.length}
Selected Context: ${JSON.stringify(selector.selectedContext(), null, 3)}
`);
}
TestRunner.runAsyncTestSuite([
async function testStartsEmpty() {
const selector = new WebAudio.AudioContextSelector();
dumpSelectorState(selector);
},
async function testSelectsCreatedContext() {
const selector = new WebAudio.AudioContextSelector();
selector.contextCreated({data: context1});
dumpSelectorState(selector);
},
async function testResetClearsList() {
const selector = new WebAudio.AudioContextSelector();
selector.contextCreated({data: context1});
selector.reset();
dumpSelectorState(selector);
},
async function testReSelectsCreatedContextAfterChange() {
const selector = new WebAudio.AudioContextSelector();
selector.contextCreated({data: context1});
selector.contextChanged({data: context1});
dumpSelectorState(selector);
},
async function testFirstCreatedContextStaysSelected() {
const selector = new WebAudio.AudioContextSelector();
selector.contextCreated({data: context1});
selector.contextCreated({data: context2});
dumpSelectorState(selector);
},
async function testChangingContextDoesNotChangeSelection() {
const selector = new WebAudio.AudioContextSelector();
selector.contextCreated({data: context1});
selector.contextCreated({data: context2});
selector.contextChanged({data: context2});
dumpSelectorState(selector);
},
async function testSelectedContextBecomesSelected() {
const selector = new WebAudio.AudioContextSelector();
selector.contextCreated({data: context1});
selector.contextCreated({data: context2});
selector.itemSelected(context2);
dumpSelectorState(selector);
},
async function testOnListItemReplacedCalled() {
function dumpItemCount() {
TestRunner.addResult(
`_onListItemReplaced called with contexts (items) count: ${
this._items.length}`);
}
TestRunner.addSniffer(
WebAudio.AudioContextSelector.prototype, '_onListItemReplaced',
dumpItemCount);
const selector = new WebAudio.AudioContextSelector();
selector.contextCreated({data: context1});
selector.contextChanged({data: context1});
dumpSelectorState(selector);
},
]);
})();
\ No newline at end of file
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