browser_oversize.js (3757B)
1 "use strict"; 2 3 const OVERSIZE_DOMAIN = "http://example.com/"; 4 const OVERSIZE_PATH = "browser/netwerk/cookie/test/browser/"; 5 const OVERSIZE_TOP_PAGE = OVERSIZE_DOMAIN + OVERSIZE_PATH + "oversize.sjs"; 6 7 add_task(async _ => { 8 const expected = []; 9 10 const consoleListener = { 11 observe(what) { 12 if (!(what instanceof Ci.nsIConsoleMessage)) { 13 return; 14 } 15 16 info("Console Listener: " + what); 17 for (let i = expected.length - 1; i >= 0; --i) { 18 const e = expected[i]; 19 20 if (what.message.includes(e.match)) { 21 ok(true, "Message received: " + e.match); 22 expected.splice(i, 1); 23 e.resolve(); 24 } 25 } 26 }, 27 }; 28 29 Services.console.registerListener(consoleListener); 30 31 registerCleanupFunction(() => 32 Services.console.unregisterListener(consoleListener) 33 ); 34 35 const netPromises = [ 36 new Promise(resolve => { 37 expected.push({ 38 resolve, 39 match: 40 "Cookie “a” is invalid because its size is too big. Max size is 4096 B.", 41 }); 42 }), 43 44 new Promise(resolve => { 45 expected.push({ 46 resolve, 47 match: 48 "The value of the attribute “path” for the cookie “b” has been rejected because its size is too big. Max size is 1024 B.", 49 }); 50 }), 51 52 new Promise(resolve => { 53 expected.push({ 54 resolve, 55 match: 56 "The value of the attribute “domain” for the cookie “c” has been rejected because its size is too big. Max size is 1024 B.", 57 }); 58 }), 59 60 new Promise(resolve => { 61 expected.push({ 62 resolve, 63 match: 64 "The value of the attribute “max-age” for the cookie “d” has been rejected because its size is too big. Max size is 1024 B.", 65 }); 66 }), 67 ]; 68 69 // Let's open our tab. 70 const tab = BrowserTestUtils.addTab(gBrowser, OVERSIZE_TOP_PAGE); 71 gBrowser.selectedTab = tab; 72 73 const browser = gBrowser.getBrowserForTab(tab); 74 await BrowserTestUtils.browserLoaded(browser); 75 76 // Let's wait for the first set of console events. 77 await Promise.all(netPromises); 78 79 // the DOM list of events. 80 const domPromises = [ 81 new Promise(resolve => { 82 expected.push({ 83 resolve, 84 match: 85 "Cookie “aa” is invalid because its size is too big. Max size is 4096 B.", 86 }); 87 }), 88 89 new Promise(resolve => { 90 expected.push({ 91 resolve, 92 match: 93 "The value of the attribute “path” for the cookie “bb” has been rejected because its size is too big. Max size is 1024 B.", 94 }); 95 }), 96 97 new Promise(resolve => { 98 expected.push({ 99 resolve, 100 match: 101 "The value of the attribute “domain” for the cookie “cc” has been rejected because its size is too big. Max size is 1024 B.", 102 }); 103 }), 104 105 new Promise(resolve => { 106 expected.push({ 107 resolve, 108 match: 109 "The value of the attribute “max-age” for the cookie “dd” has been rejected because its size is too big. Max size is 1024 B.", 110 }); 111 }), 112 ]; 113 114 // Let's use document.cookie 115 SpecialPowers.spawn(browser, [], () => { 116 const maxBytesPerCookie = 4096; 117 const maxBytesPerAttribute = 1024; 118 content.document.cookie = "aa=" + Array(maxBytesPerCookie + 1).join("x"); 119 content.document.cookie = 120 "bb=f; path=/" + Array(maxBytesPerAttribute + 1).join("x"); 121 content.document.cookie = 122 "cc=f; domain=" + Array(maxBytesPerAttribute + 1).join("x") + ".net"; 123 content.document.cookie = 124 "dd=f; max-age=" + Array(maxBytesPerAttribute + 2).join("x"); 125 }); 126 127 // Let's wait for the dom events. 128 await Promise.all(domPromises); 129 130 // Let's close the tab. 131 BrowserTestUtils.removeTab(tab); 132 });