Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | let FormHistory = (Components.utils.import("resource://gre/modules/FormHistory.jsm", {})).FormHistory; |
michael@0 | 6 | |
michael@0 | 7 | /** Test for Bug 472396 **/ |
michael@0 | 8 | function test() { |
michael@0 | 9 | // initialization |
michael@0 | 10 | waitForExplicitFinish(); |
michael@0 | 11 | let windowsToClose = []; |
michael@0 | 12 | let testURI = |
michael@0 | 13 | "http://example.com/tests/toolkit/components/satchel/test/subtst_privbrowsing.html"; |
michael@0 | 14 | |
michael@0 | 15 | function doTest(aIsPrivateMode, aShouldValueExist, aWindow, aCallback) { |
michael@0 | 16 | aWindow.gBrowser.selectedBrowser.addEventListener("load", function onLoad() { |
michael@0 | 17 | if (aWindow.content.location != testURI) { |
michael@0 | 18 | aWindow.gBrowser.selectedBrowser.loadURI(testURI); |
michael@0 | 19 | return; |
michael@0 | 20 | } |
michael@0 | 21 | aWindow.gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); |
michael@0 | 22 | |
michael@0 | 23 | let checks = 0; |
michael@0 | 24 | function doneCheck() { |
michael@0 | 25 | checks++; |
michael@0 | 26 | if (checks == 2) { |
michael@0 | 27 | executeSoon(aCallback); |
michael@0 | 28 | } |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | // Wait for the second load of the page to call the callback, |
michael@0 | 32 | // because the first load submits the form and the page reloads after |
michael@0 | 33 | // the form submission. |
michael@0 | 34 | aWindow.gBrowser.selectedBrowser.addEventListener("load", function onLoad() { |
michael@0 | 35 | aWindow.gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); |
michael@0 | 36 | doneCheck(); |
michael@0 | 37 | }, true); |
michael@0 | 38 | |
michael@0 | 39 | let count = 0; |
michael@0 | 40 | FormHistory.count({ fieldname: "field", value: "value" }, |
michael@0 | 41 | { handleResult: function(result) { |
michael@0 | 42 | count = result; |
michael@0 | 43 | }, |
michael@0 | 44 | handleError: function (error) { |
michael@0 | 45 | do_throw("Error occurred searching form history: " + error); |
michael@0 | 46 | }, |
michael@0 | 47 | handleCompletion: function(num) { |
michael@0 | 48 | is(count >= 1, aShouldValueExist, "Checking value exists in form history"); |
michael@0 | 49 | doneCheck(); |
michael@0 | 50 | } |
michael@0 | 51 | }); |
michael@0 | 52 | }, true); |
michael@0 | 53 | |
michael@0 | 54 | aWindow.gBrowser.selectedBrowser.loadURI(testURI); |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | function testOnWindow(aOptions, aCallback) { |
michael@0 | 58 | whenNewWindowLoaded(aOptions, function(aWin) { |
michael@0 | 59 | windowsToClose.push(aWin); |
michael@0 | 60 | executeSoon(function() aCallback(aWin)); |
michael@0 | 61 | }); |
michael@0 | 62 | }; |
michael@0 | 63 | |
michael@0 | 64 | registerCleanupFunction(function() { |
michael@0 | 65 | windowsToClose.forEach(function(aWin) { |
michael@0 | 66 | aWin.close(); |
michael@0 | 67 | }); |
michael@0 | 68 | }); |
michael@0 | 69 | |
michael@0 | 70 | |
michael@0 | 71 | testOnWindow({private: true}, function(aWin) { |
michael@0 | 72 | doTest(true, false, aWin, function() { |
michael@0 | 73 | // Test when not on private mode after visiting a site on private |
michael@0 | 74 | // mode. The form history should no exist. |
michael@0 | 75 | testOnWindow({}, function(aWin) { |
michael@0 | 76 | doTest(false, false, aWin, function() { |
michael@0 | 77 | finish(); |
michael@0 | 78 | }); |
michael@0 | 79 | }); |
michael@0 | 80 | }); |
michael@0 | 81 | }); |
michael@0 | 82 | } |