browser_sessionHistory_partitionedPrincipalToInherit.js (5475B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 add_task(async function test_partitioned_principal_to_inherit() { 7 if (!Services.appinfo.sessionHistoryInParent) { 8 ok(true, "sessionHistoryInParent is not enabled, skipping the test."); 9 return; 10 } 11 12 // Create a new tab. 13 let tab = await BrowserTestUtils.openNewForegroundTab( 14 gBrowser, 15 "https://example.com" 16 ); 17 let browser = tab.linkedBrowser; 18 19 // Get the last entry in the session history. 20 let sh = browser.browsingContext.sessionHistory; 21 let entry = sh.getEntryAtIndex(sh.count - 1); 22 let partitionedPrincipalToInherit = entry.partitionedPrincipalToInherit; 23 24 // Check that the partitioned principal to inherit is properly set. 25 ok(partitionedPrincipalToInherit, "partitionedPrincipalToInherit is set"); 26 is( 27 partitionedPrincipalToInherit.originAttributes.partitionKey, 28 "(https,example.com)", 29 "correct partitionKey" 30 ); 31 32 BrowserTestUtils.removeTab(tab); 33 }); 34 35 add_task(async function test_partitioned_Principal_to_inherit_in_iframe() { 36 if (!Services.appinfo.sessionHistoryInParent) { 37 ok(true, "sessionHistoryInParent is not enabled, skipping the test."); 38 return; 39 } 40 41 // Create a new tab. 42 let tab = await BrowserTestUtils.openNewForegroundTab( 43 gBrowser, 44 "https://example.com" 45 ); 46 let browser = tab.linkedBrowser; 47 48 // Load a same-origin iframe 49 await SpecialPowers.spawn(browser, [], async _ => { 50 let iframe = content.document.createElement("iframe"); 51 iframe.src = "https://example.com"; 52 53 await new content.Promise(resolve => { 54 iframe.onload = resolve; 55 content.document.body.appendChild(iframe); 56 }); 57 }); 58 59 // Get the last child entry in the session history for the same-origin iframe. 60 let sh = browser.browsingContext.sessionHistory; 61 let entry = sh.getEntryAtIndex(sh.count - 1); 62 let childEntry = entry.GetChildAt(entry.childCount - 1); 63 let partitionedPrincipalToInherit = childEntry.partitionedPrincipalToInherit; 64 65 // Check that the partitioned principal to inherit is properly set. 66 ok(partitionedPrincipalToInherit, "partitionedPrincipalToInherit is set"); 67 is( 68 partitionedPrincipalToInherit.originNoSuffix, 69 "https://example.com", 70 "correct originNoSuffix in the same-origin iframe" 71 ); 72 is( 73 partitionedPrincipalToInherit.originAttributes.partitionKey, 74 "(https,example.com)", 75 "correct partitionKey in the same-origin iframe" 76 ); 77 78 // Load a cross-site iframe. 79 await SpecialPowers.spawn(browser, [], async _ => { 80 let iframe = content.document.createElement("iframe"); 81 iframe.src = "https://example.net"; 82 83 await new content.Promise(resolve => { 84 iframe.onload = resolve; 85 content.document.body.appendChild(iframe); 86 }); 87 }); 88 89 // Get the last child entry in the session history for the cross-site iframe. 90 entry = sh.getEntryAtIndex(sh.count - 1); 91 childEntry = entry.GetChildAt(entry.childCount - 1); 92 partitionedPrincipalToInherit = childEntry.partitionedPrincipalToInherit; 93 94 // Check that the partitioned principal to inherit is properly set. 95 ok(partitionedPrincipalToInherit, "partitionedPrincipalToInherit is set"); 96 is( 97 partitionedPrincipalToInherit.originNoSuffix, 98 "https://example.net", 99 "correct originNoSuffix in the cross-site iframe" 100 ); 101 is( 102 partitionedPrincipalToInherit.originAttributes.partitionKey, 103 "(https,example.com)", 104 "correct partitionKey in the cross-site iframe" 105 ); 106 107 BrowserTestUtils.removeTab(tab); 108 }); 109 110 add_task(async function test_partitioned_Principal_to_inherit_in_ABA_iframe() { 111 if (!Services.appinfo.sessionHistoryInParent) { 112 ok(true, "sessionHistoryInParent is not enabled, skipping the test."); 113 return; 114 } 115 116 // Create a new tab. 117 let tab = await BrowserTestUtils.openNewForegroundTab( 118 gBrowser, 119 "https://example.com" 120 ); 121 let browser = tab.linkedBrowser; 122 123 // Load a ABA iframe 124 await SpecialPowers.spawn(browser, [], async () => { 125 let iframe = content.document.createElement("iframe"); 126 iframe.src = "https://example.net"; 127 128 await new content.Promise(resolve => { 129 iframe.onload = resolve; 130 content.document.body.appendChild(iframe); 131 }); 132 133 await SpecialPowers.spawn(iframe, [], async () => { 134 let nestedIframe = content.document.createElement("iframe"); 135 nestedIframe.src = "https://example.com"; 136 137 await new content.Promise(resolve => { 138 nestedIframe.onload = resolve; 139 content.document.body.appendChild(nestedIframe); 140 }); 141 }); 142 }); 143 144 // Get the last child entry in the session history for the same-origin iframe. 145 let sh = browser.browsingContext.sessionHistory; 146 let entry = sh.getEntryAtIndex(sh.count - 1); 147 let childEntry = entry.GetChildAt(entry.childCount - 1); 148 let nestedChildEntry = childEntry.GetChildAt(childEntry.childCount - 1); 149 let partitionedPrincipalToInherit = 150 nestedChildEntry.partitionedPrincipalToInherit; 151 152 // Check that the partitioned principal to inherit is properly set. 153 ok(partitionedPrincipalToInherit, "partitionedPrincipalToInherit is set"); 154 is( 155 partitionedPrincipalToInherit.originNoSuffix, 156 "https://example.com", 157 "correct originNoSuffix in the ABA iframe" 158 ); 159 is( 160 partitionedPrincipalToInherit.originAttributes.partitionKey, 161 "(https,example.com,f)", 162 "correct partitionKey in the ABA iframe" 163 ); 164 165 BrowserTestUtils.removeTab(tab); 166 });