common.js (1676B)
1 'use strict'; 2 3 async function loadBfCacheTestHelperResources() { 4 await loadScript('/common/utils.js'); 5 await loadScript('/common/dispatcher/dispatcher.js'); 6 await loadScript( 7 '/html/browsers/browsing-the-web/back-forward-cache/resources/helper.sub.js'); 8 } 9 await loadBfCacheTestHelperResources(); 10 11 // Runs BFCache tests for embed elements, specifically <embed> and <object>. 12 // 1. Attaches the target element to first page. 13 // 2. Navigates away, then back via bfcache if this case is supported by the 14 // browser. 15 // @param {Object} testCase - The target element's attributes to test with. 16 export function runBfcacheTestForEmbeds(testCase) { 17 assert_implements(runBfcacheTest, '`runBfcacheTest()` is unavailable.'); 18 assert_implements(originSameOrigin, '`originSameOrigin` is unavailable.'); 19 20 const tags = [ 21 {'name': 'embed', 'srcAttr': 'src'}, 22 {'name': 'object', 'srcAttr': 'data'}, 23 ]; 24 for (const tag of tags) { 25 runBfcacheTest( 26 { 27 targetOrigin: originSameOrigin, 28 shouldBeCached: true, 29 funcBeforeNavigation: (tag, attrs) => { 30 let e = document.createElement(tag.name); 31 // Only sets defined attributes to match the intended test behavior 32 // like embedded-type-only.html test. 33 if ('type' in attrs) { 34 e.type = attrs.type; 35 } 36 if ('src' in attrs) { 37 e[tag.srcAttr] = attrs.src; 38 } 39 document.body.append(e); 40 }, 41 argsBeforeNavigation: [tag, testCase] 42 }, 43 `Page with <${tag.name} ` + 44 `type=${testCase.type} ${tag.srcAttr}=${testCase.src}>`); 45 } 46 }