-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert shim correctness tests to puppeteer
- Loading branch information
Showing
10 changed files
with
450 additions
and
4,646 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"features": { | ||
"webCompat": { | ||
"state": "enabled", | ||
"settings": { | ||
"mediaSession": "enabled", | ||
"presentation": "enabled" | ||
} | ||
} | ||
} | ||
} |
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,129 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width"> | ||
<title>Webcompat shims</title> | ||
<link rel="stylesheet" href="../../shared/style.css"> | ||
</head> | ||
<body> | ||
<script src="../../shared/utils.js"></script> | ||
<p><a href="../index.html">[Webcompat shims]</a></p> | ||
|
||
<p>This page verifies that shims created with shim APIs have correct descriptors</p> | ||
|
||
<script> | ||
/** | ||
* assert that two descriptors are similar, allowing different values | ||
* @param {import('../src/wrapper-utils').StrictPropertyDescriptor} origDesc | ||
* @param {import('../src/wrapper-utils').StrictPropertyDescriptor} newDesc | ||
* @returns {string} - the error message if the test fails | ||
*/ | ||
function compareDescriptorShape (origDesc, newDesc) { | ||
const origKeys = Object.keys(origDesc) | ||
const newKeys = Object.keys(newDesc) | ||
// verify that both descriptors have the same keys | ||
if (origKeys.sort().join(',') !== newKeys.sort().join(',')) | ||
return 'property keys do not match'; | ||
|
||
for (const key of origKeys) { | ||
if (key === 'get' || key === 'set' || key === 'value') { | ||
if (typeof newDesc[key] !== typeof origDesc[key]) | ||
return `property ${key} does not match`; | ||
} else { | ||
if (newDesc[key] !== origDesc[key]) | ||
return `property ${key} does not match`; | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Use this function to test the interfaces shimmed in the web-compat feature | ||
* @param {string} interfaceName - the name of the interface to test. It should be available in the global scope | ||
* @param {import('../src/wrapper-utils').StrictPropertyDescriptor} origInterfaceDescriptor - the descriptor of the original interface | ||
* @returns {string} - the error message if the test fails | ||
*/ | ||
function testInterfaceShimCorrectness (interfaceName, origInterfaceDescriptor) { | ||
if (!interfaceName) { | ||
return 'Nothing to test.'; | ||
} | ||
|
||
if (!globalThis[interfaceName]) | ||
return 'native class is not found after shimming'; | ||
if (globalThis[interfaceName][globalThis.ddgShimMark] !== true) | ||
return 'class should be marked as shimmed'; | ||
|
||
const newInterfaceDescriptor = Object.getOwnPropertyDescriptor(globalThis, interfaceName) | ||
|
||
return compareDescriptorShape(origInterfaceDescriptor, newInterfaceDescriptor) | ||
} | ||
|
||
/** | ||
* Use this function to test the global properties shimmed in the web-compat feature | ||
* @param {any} instanceHost - object under which the global instance is defined | ||
* @param {string} instanceProp - the name of the instance property | ||
* @param {import('../src/wrapper-utils').StrictPropertyDescriptor} origInstanceDescriptor - the descriptor of the original instance property | ||
* @returns {string} - the error message if the test fails | ||
*/ | ||
function testInstanceShimCorrectness (instanceHost, instanceProp, origInstanceDescriptor) { | ||
if (!instanceHost || !instanceProp) { | ||
return 'Nothing to test.'; | ||
} | ||
|
||
if (!instanceHost[instanceProp]) | ||
return 'global instance is not found after shimming'; | ||
|
||
const newInstanceDescriptor = Object.getOwnPropertyDescriptor(instanceHost, instanceProp) | ||
|
||
return compareDescriptorShape(origInstanceDescriptor, newInstanceDescriptor) | ||
} | ||
|
||
|
||
test('Interface shims', async () => { | ||
const results = []; | ||
results.push({ | ||
name: 'origInterfaceDescriptors found', | ||
result: Boolean(globalThis.origInterfaceDescriptors), | ||
expected: true | ||
}); | ||
results.push({ | ||
name: 'ddgShimMark found', | ||
result: Boolean(globalThis.ddgShimMark), | ||
expected: true | ||
}); | ||
|
||
for (const [interfaceName, origDescriptor] of Object.entries(globalThis.origInterfaceDescriptors)) { | ||
results.push({ | ||
name: `${interfaceName}'s descriptor is correct`, | ||
result: testInterfaceShimCorrectness(interfaceName, origDescriptor), | ||
expected: undefined | ||
}); | ||
} | ||
|
||
return results; | ||
}); | ||
|
||
test('Instance shims', async () => { | ||
const results = []; | ||
results.push({ | ||
name: 'origPropDescriptors found', | ||
result: Boolean(globalThis.origPropDescriptors), | ||
expected: true | ||
}); | ||
|
||
for (const [instanceHost, instanceProp, origDescriptor] of globalThis.origPropDescriptors) { | ||
results.push({ | ||
name: `${instanceHost}.${instanceProp}'s descriptor is correct`, | ||
result: testInstanceShimCorrectness(instanceHost, instanceProp, origDescriptor), | ||
expected: undefined | ||
}); | ||
} | ||
|
||
return results; | ||
}); | ||
|
||
// eslint-disable-next-line no-undef | ||
renderResults(); | ||
</script> | ||
</body> | ||
</html> |
Oops, something went wrong.