diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /netwerk/test/unit/test_dns_originAttributes.js | |
parent | Initial commit. (diff) | |
download | firefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'netwerk/test/unit/test_dns_originAttributes.js')
-rw-r--r-- | netwerk/test/unit/test_dns_originAttributes.js | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/netwerk/test/unit/test_dns_originAttributes.js b/netwerk/test/unit/test_dns_originAttributes.js new file mode 100644 index 0000000000..39e2a4f0f1 --- /dev/null +++ b/netwerk/test/unit/test_dns_originAttributes.js @@ -0,0 +1,93 @@ +"use strict"; + +var prefs = Services.prefs; +var mainThread = Services.tm.currentThread; + +var listener1 = { + onLookupComplete(inRequest, inRecord, inStatus) { + Assert.equal(inStatus, Cr.NS_OK); + inRecord.QueryInterface(Ci.nsIDNSAddrRecord); + var answer = inRecord.getNextAddrAsString(); + Assert.ok(answer == "127.0.0.1" || answer == "::1"); + test2(); + do_test_finished(); + }, +}; + +var listener2 = { + onLookupComplete(inRequest, inRecord, inStatus) { + Assert.equal(inStatus, Cr.NS_OK); + inRecord.QueryInterface(Ci.nsIDNSAddrRecord); + var answer = inRecord.getNextAddrAsString(); + Assert.ok(answer == "127.0.0.1" || answer == "::1"); + test3(); + do_test_finished(); + }, +}; + +var listener3 = { + onLookupComplete(inRequest, inRecord, inStatus) { + Assert.equal(inStatus, Cr.NS_ERROR_OFFLINE); + cleanup(); + do_test_finished(); + }, +}; + +const firstOriginAttributes = { userContextId: 1 }; +const secondOriginAttributes = { userContextId: 2 }; + +// First, we resolve the address normally for first originAttributes. +function run_test() { + do_test_pending(); + prefs.setBoolPref("network.proxy.allow_hijacking_localhost", true); + Services.dns.asyncResolve( + "localhost", + Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT, + 0, + null, // resolverInfo + listener1, + mainThread, + firstOriginAttributes + ); +} + +// Second, we resolve the same address offline to see whether its DNS cache works +// correctly. +function test2() { + do_test_pending(); + Services.dns.asyncResolve( + "localhost", + Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT, + Ci.nsIDNSService.RESOLVE_OFFLINE, + null, // resolverInfo + listener2, + mainThread, + firstOriginAttributes + ); +} + +// Third, we resolve the same address offline again with different originAttributes. +// This resolving should fail since the DNS cache of the given address is not exist +// for this originAttributes. +function test3() { + do_test_pending(); + try { + Services.dns.asyncResolve( + "localhost", + Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT, + Ci.nsIDNSService.RESOLVE_OFFLINE, + null, // resolverInfo + listener3, + mainThread, + secondOriginAttributes + ); + } catch (e) { + Assert.equal(e.result, Cr.NS_ERROR_OFFLINE); + cleanup(); + do_test_finished(); + } +} + +function cleanup() { + prefs.clearUserPref("network.proxy.allow_hijacking_localhost"); +} |