toolkit/devtools/server/tests/unit/test_nesting-02.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /* -*- Mode: javascript; js-indent-level: 2; -*- */
michael@0 2 /* Any copyright is dedicated to the Public Domain.
michael@0 3 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 4
michael@0 5 // Test that we can nest event loops and then automatically exit nested event
michael@0 6 // loops when requested.
michael@0 7
michael@0 8 var gClient;
michael@0 9 var gThreadActor;
michael@0 10
michael@0 11 function run_test() {
michael@0 12 initTestDebuggerServer();
michael@0 13 let gDebuggee = addTestGlobal("test-nesting");
michael@0 14 gClient = new DebuggerClient(DebuggerServer.connectPipe());
michael@0 15 gClient.connect(function () {
michael@0 16 attachTestTabAndResume(gClient, "test-nesting", function (aResponse, aTabClient, aThreadClient) {
michael@0 17 // Reach over the protocol connection and get a reference to the thread actor.
michael@0 18 gThreadActor = aThreadClient._transport._serverConnection.getActor(aThreadClient._actor);
michael@0 19
michael@0 20 test_nesting();
michael@0 21 });
michael@0 22 });
michael@0 23 do_test_pending();
michael@0 24 }
michael@0 25
michael@0 26 function test_nesting() {
michael@0 27 const thread = gThreadActor;
michael@0 28 const { resolve, reject, promise: p } = promise.defer();
michael@0 29
michael@0 30 // The following things should happen (in order):
michael@0 31 // 1. In the new event loop (created by synchronize)
michael@0 32 // 2. Resolve the promise (shouldn't exit any event loops)
michael@0 33 // 3. Exit the event loop (should also then exit synchronize's event loop)
michael@0 34 // 4. Be after the synchronize call
michael@0 35 let currentStep = 0;
michael@0 36
michael@0 37 executeSoon(function () {
michael@0 38 let eventLoop;
michael@0 39
michael@0 40 executeSoon(function () {
michael@0 41 // Should be at step 2
michael@0 42 do_check_eq(++currentStep, 2);
michael@0 43 // Before resolving, should have the synchronize event loop and the one just created.
michael@0 44 do_check_eq(thread._nestedEventLoops.size, 2);
michael@0 45
michael@0 46 executeSoon(function () {
michael@0 47 // Should be at step 3
michael@0 48 do_check_eq(++currentStep, 3);
michael@0 49 // Before exiting the manually created event loop, should have the
michael@0 50 // synchronize event loop and the manual event loop.
michael@0 51 do_check_eq(thread._nestedEventLoops.size, 2);
michael@0 52 // Should have the event loop
michael@0 53 do_check_true(!!eventLoop);
michael@0 54 eventLoop.resolve();
michael@0 55 });
michael@0 56
michael@0 57 resolve(true);
michael@0 58 // Shouldn't exit any event loops because a new one started since the call to synchronize
michael@0 59 do_check_eq(thread._nestedEventLoops.size, 2);
michael@0 60 });
michael@0 61
michael@0 62 // Should be at step 1
michael@0 63 do_check_eq(++currentStep, 1);
michael@0 64 // Should have only the synchronize event loop
michael@0 65 do_check_eq(thread._nestedEventLoops.size, 1);
michael@0 66 eventLoop = thread._nestedEventLoops.push();
michael@0 67 eventLoop.enter();
michael@0 68 });
michael@0 69
michael@0 70 do_check_eq(thread.synchronize(p), true);
michael@0 71
michael@0 72 // Should be on the fourth step
michael@0 73 do_check_eq(++currentStep, 4);
michael@0 74 // There shouldn't be any nested event loops anymore
michael@0 75 do_check_eq(thread._nestedEventLoops.size, 0);
michael@0 76
michael@0 77 finishClient(gClient);
michael@0 78 }

mercurial