|
| 1 | +<!DOCTYPE html> |
| 2 | +<html> |
| 3 | +<head> |
| 4 | + <meta charset="utf-8"> |
| 5 | + <meta name="viewport" content="width=device-width"> |
| 6 | + <title>Conditional Matching</title> |
| 7 | + <link rel="stylesheet" href="../../shared/style.css"> |
| 8 | +</head> |
| 9 | +<body> |
| 10 | + <script src="../../shared/utils.js"></script> |
| 11 | + <p><a href="../index.html">[Infra]</a></p> |
| 12 | + |
| 13 | + <p>This page verifies that APIs get modified</p> |
| 14 | + |
| 15 | + <script> |
| 16 | + test('Conditional matching', async () => { |
| 17 | + const results = [ |
| 18 | + { |
| 19 | + name: "APIs changing, expecting to always match", |
| 20 | + result: navigator.hardwareConcurrency, |
| 21 | + expected: 222 |
| 22 | + } |
| 23 | + ]; |
| 24 | + const oldPathname = window.location.pathname; |
| 25 | + const newUrl = new URL(window.location.href); |
| 26 | + newUrl.pathname = "/test/test/path"; |
| 27 | + window.history.pushState(null, '', newUrl.href); |
| 28 | + await new Promise(resolve => requestIdleCallback(resolve)); |
| 29 | + results.push({ |
| 30 | + name: "Expect URL to be changed", |
| 31 | + result: window.location.pathname, |
| 32 | + expected: '/test/test/path' |
| 33 | + }) |
| 34 | + results.push({ |
| 35 | + name: "APIs changing, expecting to match only when the URL is correct", |
| 36 | + result: navigator.hardwareConcurrency, |
| 37 | + expected: 333 |
| 38 | + }) |
| 39 | + const popStatePromise = new Promise(resolve => { |
| 40 | + window.addEventListener('popstate', resolve, { once: true }); |
| 41 | + }); |
| 42 | + // Call pop state to revert the URL |
| 43 | + window.history.back(); |
| 44 | + await popStatePromise; |
| 45 | + results.push({ |
| 46 | + name: "Expect URL to be reverted", |
| 47 | + result: window.location.pathname, |
| 48 | + expected: oldPathname |
| 49 | + }) |
| 50 | + results.push({ |
| 51 | + name: "APIs changing, expecting to match only when the URL is correct", |
| 52 | + result: navigator.hardwareConcurrency, |
| 53 | + expected: 222 |
| 54 | + }) |
| 55 | + |
| 56 | + return results; |
| 57 | + }); |
| 58 | + |
| 59 | + |
| 60 | + // eslint-disable-next-line no-undef |
| 61 | + renderResults(); |
| 62 | + </script> |
| 63 | +</body> |
| 64 | +</html> |
0 commit comments