forked from web-platform-tests/wpt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
compute pressure: Convert remaining web tests to test_driver
The purpose of this change is start using WebDriver and remove mock code. WebDriver commands for Compute Pressure are defined in https://www.w3.org/TR/compute-pressure/#automation In general, this involves renaming `*.any.js` tests to `*.window.js` ones to continue being able to test windows and dedicated workers from the same file (see README.md for a longer explanation of how this works around test_driver limitations) as well as replacing the mock PressureService calls with test_driver ones. While here, a few other changes had to be made: - compute_pressure_basic.https.window.js: Stop passing async functions to Promise constructors. async functions do not make much sense in this context, and we can just call reject() when some function calls fail and avoid having to explicitly wait for them because by the time we reach the PressureObserver callbacks they will by definition have finished running. - compute_pressure_rate_obfuscation_mitigation_not_triggered.https.window.js: The promise wrapping the majority of the test has been removed because it is not necessary. - compute_pressure_rate_obfuscation_mitigation_triggered.https.window.js: The wrapping promise has been removed for the same reason. The wait the code was structured also made the entire test exit early when resolve() was called, and we never got to test the loop conditions and the final assertion in this case. Now that we do, fix the checks in the loop (we need an AND, not an OR) and adjust the description of the final assert_true() call. Co-authored with [email protected] Bug: 347031400 Change-Id: I289292bd4d35f7f26d4531252e64c0aba571124e Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5898734 Reviewed-by: Reilly Grant <[email protected]> Commit-Queue: Raphael Kubo Da Costa <[email protected]> Auto-Submit: Raphael Kubo Da Costa <[email protected]> Cr-Commit-Position: refs/heads/main@{#1362281}
- Loading branch information
1 parent
47ff969
commit 3b5b938
Showing
30 changed files
with
624 additions
and
661 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
50 changes: 50 additions & 0 deletions
50
compute-pressure/compute_pressure_disconnect.https.window.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// META: variant=?globalScope=window | ||
// META: variant=?globalScope=dedicated_worker | ||
// META: script=/resources/testdriver.js | ||
// META: script=/resources/testdriver-vendor.js | ||
// META: script=/common/utils.js | ||
// META: script=/common/dispatcher/dispatcher.js | ||
// META: script=./resources/common.js | ||
|
||
'use strict'; | ||
|
||
pressure_test(async t => { | ||
const observer = new PressureObserver(() => { | ||
assert_unreached('The observer callback should not be called'); | ||
}); | ||
t.add_cleanup(() => observer.disconnect()); | ||
observer.disconnect(); | ||
}, 'Calling disconnect() immediately should not crash'); | ||
|
||
pressure_test(async t => { | ||
await create_virtual_pressure_source('cpu'); | ||
t.add_cleanup(async () => { | ||
await remove_virtual_pressure_source('cpu'); | ||
}); | ||
|
||
const observer1_changes = []; | ||
const observer1 = new PressureObserver(change => { | ||
observer1_changes.push(change); | ||
}); | ||
t.add_cleanup(() => observer1.disconnect()); | ||
// Ensure that observer1's schema gets registered before observer2 starts. | ||
await observer1.observe('cpu'); | ||
observer1.disconnect(); | ||
|
||
const observer2_promise = new Promise((resolve, reject) => { | ||
const observer = new PressureObserver(resolve); | ||
t.add_cleanup(() => observer.disconnect()); | ||
observer.observe('cpu').catch(reject); | ||
}); | ||
await update_virtual_pressure_source('cpu', 'critical'); | ||
const observer2_changes = await observer2_promise; | ||
|
||
assert_equals( | ||
observer1_changes.length, 0, | ||
'disconnected observers should not receive callbacks'); | ||
|
||
assert_equals(observer2_changes.length, 1); | ||
assert_equals(observer2_changes[0].state, 'critical'); | ||
}, 'Stopped PressureObserver do not receive changes'); | ||
|
||
mark_as_done(); |
37 changes: 0 additions & 37 deletions
37
compute-pressure/compute_pressure_disconnect_idempotent.https.any.js
This file was deleted.
Oops, something went wrong.
44 changes: 44 additions & 0 deletions
44
compute-pressure/compute_pressure_disconnect_idempotent.https.window.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// META: variant=?globalScope=window | ||
// META: variant=?globalScope=dedicated_worker | ||
// META: script=/resources/testdriver.js | ||
// META: script=/resources/testdriver-vendor.js | ||
// META: script=/common/utils.js | ||
// META: script=/common/dispatcher/dispatcher.js | ||
// META: script=./resources/common.js | ||
|
||
'use strict'; | ||
|
||
pressure_test(async t => { | ||
await create_virtual_pressure_source('cpu'); | ||
t.add_cleanup(async () => { | ||
await remove_virtual_pressure_source('cpu'); | ||
}); | ||
|
||
const observer1_changes = []; | ||
const observer1 = new PressureObserver(changes => { | ||
observer1_changes.push(changes); | ||
}); | ||
t.add_cleanup(() => observer1.disconnect()); | ||
// Ensure that observer1's schema gets registered before observer2 starts. | ||
const promise = observer1.observe('cpu'); | ||
observer1.disconnect(); | ||
observer1.disconnect(); | ||
await promise_rejects_dom(t, 'AbortError', promise); | ||
|
||
const observer2_promise = new Promise((resolve, reject) => { | ||
const observer = new PressureObserver(resolve); | ||
t.add_cleanup(() => observer.disconnect()); | ||
observer.observe('cpu').catch(reject); | ||
}); | ||
await update_virtual_pressure_source('cpu', 'critical'); | ||
const observer2_changes = await observer2_promise; | ||
|
||
assert_equals( | ||
observer1_changes.length, 0, | ||
'stopped observers should not receive callbacks'); | ||
|
||
assert_equals(observer2_changes.length, 1); | ||
assert_equals(observer2_changes[0].state, 'critical'); | ||
}, 'Stopped PressureObserver do not receive changes'); | ||
|
||
mark_as_done(); |
Oops, something went wrong.