toolkit/components/downloads/test/browser/browser_download_history.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 /* 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 function test() {
michael@0 6 try {
michael@0 7 if (Services.prefs.getBoolPref("browser.download.useJSTransfer")) {
michael@0 8 return;
michael@0 9 }
michael@0 10 } catch (ex) { }
michael@0 11
michael@0 12 waitForExplicitFinish();
michael@0 13
michael@0 14 let privateWin = null;
michael@0 15 let itemCount = 0;
michael@0 16 let sourceURL =
michael@0 17 "http://example.org/tests/toolkit/components/downloads/test/browser/download.html";
michael@0 18 let linkURL =
michael@0 19 "http://mochi.test:8888/tests/toolkit/components/downloads/test/browser/download.test";
michael@0 20 let linkURI = Services.io.newURI(linkURL, null, null);
michael@0 21 let downloadDialogURL =
michael@0 22 "chrome://mozapps/content/downloads/unknownContentType.xul";
michael@0 23
michael@0 24 let downloadListener = {
michael@0 25 onDownloadStateChange: function(aState, aDownload) {
michael@0 26 switch (aDownload.state) {
michael@0 27 case Services.downloads.DOWNLOAD_FINISHED:
michael@0 28 info("Download finished");
michael@0 29 Services.downloads.removeListener(downloadListener);
michael@0 30 executeSoon(function() { checkDownload(aDownload); });
michael@0 31 break;
michael@0 32 }
michael@0 33 },
michael@0 34 onStateChange: function(a, b, c, d, e) { },
michael@0 35 onProgressChange: function(a, b, c, d, e, f, g) { },
michael@0 36 onSecurityChange: function(a, b, c, d) { }
michael@0 37 };
michael@0 38
michael@0 39 let historyObserver = {
michael@0 40 onVisit: function (aURI, aVisitID, aTime, aSessionID, aReferringID, aTransitionType) {
michael@0 41 ok(false, "Download should not fired a visit notification: " + aURI.spec);
michael@0 42 },
michael@0 43 onBeginUpdateBatch: function () {},
michael@0 44 onEndUpdateBatch: function () {},
michael@0 45 onTitleChanged: function () {},
michael@0 46 onBeforeDeleteURI: function () {},
michael@0 47 onDeleteURI: function () {},
michael@0 48 onClearHistory: function () {},
michael@0 49 onPageChanged: function () {},
michael@0 50 onDeleteVisits: function () {},
michael@0 51 QueryInterface: XPCOMUtils.generateQI([Ci.nsINavHistoryObserver])
michael@0 52 };
michael@0 53
michael@0 54 let windowListener = {
michael@0 55 onOpenWindow: function(aXULWindow) {
michael@0 56 info("Window opened");
michael@0 57 Services.wm.removeListener(windowListener);
michael@0 58
michael@0 59 let domWindow =
michael@0 60 aXULWindow.QueryInterface(Ci.nsIInterfaceRequestor).
michael@0 61 getInterface(Ci.nsIDOMWindow);
michael@0 62 waitForFocus(function() {
michael@0 63 is(domWindow.document.location.href, downloadDialogURL,
michael@0 64 "Should have seen the right window open");
michael@0 65
michael@0 66 executeSoon(function() {
michael@0 67 let button = domWindow.document.documentElement.getButton("accept");
michael@0 68 button.disabled = false;
michael@0 69 domWindow.document.documentElement.acceptDialog();
michael@0 70 });
michael@0 71 }, domWindow);
michael@0 72 },
michael@0 73 onCloseWindow: function(aXULWindow) {},
michael@0 74 onWindowTitleChange: function(aXULWindow, aNewTitle) {}
michael@0 75 };
michael@0 76
michael@0 77 registerCleanupFunction(function() {
michael@0 78 privateWin.close();
michael@0 79 Services.prefs.clearUserPref("browser.download.manager.showAlertOnComplete");
michael@0 80 });
michael@0 81
michael@0 82 function getHistoryItemCount() {
michael@0 83 let options = PlacesUtils.history.getNewQueryOptions();
michael@0 84 options.includeHidden = true;
michael@0 85 options.queryType = Ci.nsINavHistoryQueryOptions.QUERY_TYPE_HISTORY;
michael@0 86 let query = PlacesUtils.history.getNewQuery();
michael@0 87 let root = PlacesUtils.history.executeQuery(query, options).root;
michael@0 88 root.containerOpen = true;
michael@0 89 let cc = root.childCount;
michael@0 90 root.containerOpen = false;
michael@0 91 return cc;
michael@0 92 }
michael@0 93
michael@0 94 function whenNewWindowLoaded(aIsPrivate, aCallback) {
michael@0 95 let win = OpenBrowserWindow({private: aIsPrivate});
michael@0 96 win.addEventListener("load", function onLoad() {
michael@0 97 win.removeEventListener("load", onLoad, false);
michael@0 98 executeSoon(function() aCallback(win));
michael@0 99 }, false);
michael@0 100 }
michael@0 101
michael@0 102 function whenPageLoad(aWin, aURL, aCallback) {
michael@0 103 let browser = aWin.gBrowser.selectedBrowser;
michael@0 104 browser.addEventListener("load", function onLoad() {
michael@0 105 browser.removeEventListener("load", onLoad, true);
michael@0 106 executeSoon(function() aCallback(browser.contentDocument));
michael@0 107 }, true);
michael@0 108 browser.loadURI(aURL);
michael@0 109 }
michael@0 110
michael@0 111 function checkDownload(aDownload) {
michael@0 112 PlacesUtils.history.removeObserver(historyObserver);
michael@0 113 ok(aDownload.isPrivate, "Download should be private");
michael@0 114 is(getHistoryItemCount(), itemCount,
michael@0 115 "History items count should not change after a download");
michael@0 116 PlacesUtils.asyncHistory.isURIVisited(linkURI, function(aURI, aIsVisited) {
michael@0 117 is(aIsVisited, false, "Download source should not be set as visited");
michael@0 118 // Clean up
michael@0 119 if (aDownload.targetFile.exists()) {
michael@0 120 aDownload.targetFile.remove(false);
michael@0 121 }
michael@0 122 waitForFocus(function() {
michael@0 123 if (privateWin.DownloadsPanel.isPanelShowing) {
michael@0 124 privateWin.DownloadsPanel.hidePanel();
michael@0 125 }
michael@0 126 finish();
michael@0 127 }, privateWin);
michael@0 128 });
michael@0 129 }
michael@0 130
michael@0 131 // Disable alert service notifications
michael@0 132 Services.prefs.setBoolPref("browser.download.manager.showAlertOnComplete", false);
michael@0 133
michael@0 134 whenNewWindowLoaded(true, function(win) {
michael@0 135 info("Start listeners");
michael@0 136 privateWin = win;
michael@0 137 Services.wm.addListener(windowListener);
michael@0 138 Services.downloads.addPrivacyAwareListener(downloadListener);
michael@0 139 PlacesUtils.history.addObserver(historyObserver, false);
michael@0 140 info("Load test page");
michael@0 141 whenPageLoad(win, sourceURL, function(doc) {
michael@0 142 info("Start download");
michael@0 143 itemCount = getHistoryItemCount();
michael@0 144 doc.getElementById("download-link").click();
michael@0 145 });
michael@0 146 });
michael@0 147 }

mercurial