This commit is contained in:
Ryan VanderMeulen 2012-07-21 14:32:18 -04:00
Родитель 3c81b9ea78 f83e43c722
Коммит f46e1d75f3
47 изменённых файлов: 2727 добавлений и 868 удалений

Просмотреть файл

@ -142,68 +142,19 @@
<menu id="appmenu_webDeveloper"
label="&appMenuWebDeveloper.label;">
<menupopup id="appmenu_webDeveloper_popup">
<menuitem id="appmenu_devToolbar"
type="checkbox"
autocheck="false"
hidden="true"
label="&devToolbarMenu.label;"
command="Tools:DevToolbar"
key="key_devToolbar"/>
<menuitem id="appmenu_webConsole"
label="&webConsoleCmd.label;"
type="checkbox"
command="Tools:WebConsole"
key="key_webConsole"/>
<menuitem id="appmenu_pageInspect"
hidden="true"
label="&inspectMenu.label;"
type="checkbox"
command="Tools:Inspect"
key="key_inspect"/>
<menuitem id="appmenu_responsiveUI"
hidden="true"
label="&responsiveDesignTool.label;"
type="checkbox"
command="Tools:ResponsiveUI"
key="key_responsiveUI"/>
<menuitem id="appmenu_debugger"
hidden="true"
type="checkbox"
label="&debuggerMenu.label2;"
key="key_debugger"
command="Tools:Debugger"/>
<menuitem id="appmenu_remoteDebugger"
hidden="true"
label="&remoteDebuggerMenu.label;"
command="Tools:RemoteDebugger"/>
<menuitem id="appmenu_chromeDebugger"
hidden="true"
label="&chromeDebuggerMenu.label;"
command="Tools:ChromeDebugger"/>
<menuitem id="appmenu_scratchpad"
hidden="true"
label="&scratchpad.label;"
key="key_scratchpad"
command="Tools:Scratchpad"/>
<menuitem id="appmenu_styleeditor"
hidden="true"
type="checkbox"
label="&styleeditor.label;"
key="key_styleeditor"
command="Tools:StyleEditor"/>
<menuitem id="appmenu_pageSource"
label="&viewPageSourceCmd.label;"
command="View:PageSource"
key="key_viewSource"/>
<menuitem id="appmenu_errorConsole"
hidden="true"
label="&errorConsoleCmd.label;"
key="key_errorConsole"
oncommand="toJavaScriptConsole();"/>
<menuitem id="appmenu_devToolbar" observes="devtoolsMenuBroadcaster_DevToolbar"/>
<menuitem id="appmenu_webConsole" observes="devtoolsMenuBroadcaster_WebConsole"/>
<menuitem id="appmenu_pageinspect" observes="devtoolsMenuBroadcaster_Inspect"/>
<menuitem id="appmenu_responsiveUI" observes="devtoolsMenuBroadcaster_ResponsiveUI"/>
<menuitem id="appmenu_debugger" observes="devtoolsMenuBroadcaster_Debugger"/>
<menuitem id="appmenu_remoteDebugger" observes="devtoolsMenuBroadcaster_RemoteDebugger"/>
<menuitem id="appmenu_chromeDebugger" observes="devtoolsMenuBroadcaster_ChromeDebugger"/>
<menuitem id="appmenu_scratchpad" observes="devtoolsMenuBroadcaster_Scratchpad"/>
<menuitem id="appmenu_styleeditor" observes="devtoolsMenuBroadcaster_StyleEditor"/>
<menuitem id="appmenu_pageSource" observes="devtoolsMenuBroadcaster_PageSource"/>
<menuitem id="appmenu_errorConsole" observes="devtoolsMenuBroadcaster_ErrorConsole"/>
<menuseparator id="appmenu_devToolsEndSeparator"/>
<menuitem id="appmenu_getMoreDevtools"
label="&getMoreDevtoolsCmd.label;"
oncommand="openUILinkIn('https://addons.mozilla.org/firefox/collections/mozilla/webdeveloper/', 'tab');"/>
<menuitem id="appmenu_getMoreDevtools" observes="devtoolsMenuBroadcaster_GetMoreTools"/>
<menuseparator/>
#define ID_PREFIX appmenu_developer_
#define OMIT_ACCESSKEYS

Просмотреть файл

@ -514,77 +514,19 @@
label="&webDeveloperMenu.label;"
accesskey="&webDeveloperMenu.accesskey;">
<menupopup id="menuWebDeveloperPopup">
<menuitem id="menu_devToolbar"
type="checkbox"
autocheck="false"
hidden="true"
label="&devToolbarMenu.label;"
accesskey="&devToolbarMenu.accesskey;"
key="key_devToolbar"
command="Tools:DevToolbar"/>
<menuitem id="webConsole"
type="checkbox"
label="&webConsoleCmd.label;"
accesskey="&webConsoleCmd.accesskey;"
key="key_webConsole"
command="Tools:WebConsole"/>
<menuitem id="menu_pageinspect"
type="checkbox"
hidden="true"
label="&inspectMenu.label;"
accesskey="&inspectMenu.accesskey;"
key="key_inspect"
command="Tools:Inspect"/>
<menuitem id="menu_responsiveUI"
type="checkbox"
hidden="true"
label="&responsiveDesignTool.label;"
accesskey="&responsiveDesignTool.accesskey;"
key="key_responsiveUI"
command="Tools:ResponsiveUI"/>
<menuitem id="menu_debugger"
hidden="true"
type="checkbox"
label="&debuggerMenu.label2;"
key="key_debugger"
command="Tools:Debugger"/>
<menuitem id="menu_remoteDebugger"
hidden="true"
label="&remoteDebuggerMenu.label;"
command="Tools:RemoteDebugger"/>
<menuitem id="menu_chromeDebugger"
hidden="true"
label="&chromeDebuggerMenu.label;"
command="Tools:ChromeDebugger"/>
<menuitem id="menu_scratchpad"
hidden="true"
label="&scratchpad.label;"
accesskey="&scratchpad.accesskey;"
key="key_scratchpad"
command="Tools:Scratchpad"/>
<menuitem id="menu_styleeditor"
type="checkbox"
hidden="true"
label="&styleeditor.label;"
accesskey="&styleeditor.accesskey;"
key="key_styleeditor"
command="Tools:StyleEditor"/>
<menuitem id="menu_pageSource"
accesskey="&pageSourceCmd.accesskey;"
label="&pageSourceCmd.label;"
key="key_viewSource"
command="View:PageSource"/>
<menuitem id="javascriptConsole"
hidden="true"
label="&errorConsoleCmd.label;"
accesskey="&errorConsoleCmd.accesskey;"
key="key_errorConsole"
oncommand="toJavaScriptConsole();"/>
<menuitem id="menu_devToolbar" observes="devtoolsMenuBroadcaster_DevToolbar" accesskey="&devToolbarMenu.accesskey;"/>
<menuitem id="webConsole" observes="devtoolsMenuBroadcaster_WebConsole" accesskey="&webConsoleCmd.accesskey;"/>
<menuitem id="menu_pageinspect" observes="devtoolsMenuBroadcaster_Inspect" accesskey="&inspectMenu.accesskey;"/>
<menuitem id="menu_responsiveUI" observes="devtoolsMenuBroadcaster_ResponsiveUI" accesskey="&responsiveDesignTool.accesskey;"/>
<menuitem id="menu_debugger" observes="devtoolsMenuBroadcaster_Debugger"/>
<menuitem id="menu_remoteDebugger" observes="devtoolsMenuBroadcaster_RemoteDebugger"/>
<menuitem id="menu_chromeDebugger" observes="devtoolsMenuBroadcaster_ChromeDebugger"/>
<menuitem id="menu_scratchpad" observes="devtoolsMenuBroadcaster_Scratchpad" accesskey="&scratchpad.accesskey;"/>
<menuitem id="menu_styleeditor" observes="devtoolsMenuBroadcaster_StyleEditor" accesskey="&styleeditor.accesskey;"/>
<menuitem id="menu_pageSource" observes="devtoolsMenuBroadcaster_PageSource" accesskey="&pageSourceCmd.accesskey;"/>
<menuitem id="javascriptConsole" observes="devtoolsMenuBroadcaster_ErrorConsole" accesskey="&errorConsoleCmd.accesskey;"/>
<menuseparator id="devToolsEndSeparator"/>
<menuitem id="getMoreDevtools"
label="&getMoreDevtoolsCmd.label;"
accesskey="&getMoreDevtoolsCmd.accesskey;"
oncommand="openUILinkIn('https://addons.mozilla.org/firefox/collections/mozilla/webdeveloper/', 'tab');"/>
<menuitem id="getMoreDevtools" observes="devtoolsMenuBroadcaster_GetMoreTools" accesskey="&getMoreDevtoolsCmd.accesskey;"/>
</menupopup>
</menu>
<menuitem id="menu_pageInfo"

Просмотреть файл

@ -88,16 +88,16 @@
<command id="Tools:Search" oncommand="BrowserSearch.webSearch();"/>
<command id="Tools:Downloads" oncommand="BrowserDownloadsUI();"/>
<command id="Tools:DevToolbar" oncommand="DeveloperToolbar.toggle();" disabled="true"/>
<command id="Tools:DevToolbar" oncommand="DeveloperToolbar.toggle();"/>
<command id="Tools:DevToolbarFocus" oncommand="DeveloperToolbar.focus();" disabled="true"/>
<command id="Tools:WebConsole" oncommand="HUDConsoleUI.toggleHUD();"/>
<command id="Tools:Inspect" oncommand="InspectorUI.toggleInspectorUI();" disabled="true"/>
<command id="Tools:Debugger" oncommand="DebuggerUI.toggleDebugger();" disabled="true"/>
<command id="Tools:RemoteDebugger" oncommand="DebuggerUI.toggleRemoteDebugger();" disabled="true"/>
<command id="Tools:ChromeDebugger" oncommand="DebuggerUI.toggleChromeDebugger();" disabled="true"/>
<command id="Tools:Scratchpad" oncommand="Scratchpad.openScratchpad();" disabled="true"/>
<command id="Tools:StyleEditor" oncommand="StyleEditor.toggle();" disabled="true"/>
<command id="Tools:ResponsiveUI" oncommand="ResponsiveUI.toggle();" disabled="true"/>
<command id="Tools:Inspect" oncommand="InspectorUI.toggleInspectorUI();"/>
<command id="Tools:Debugger" oncommand="DebuggerUI.toggleDebugger();"/>
<command id="Tools:RemoteDebugger" oncommand="DebuggerUI.toggleRemoteDebugger();"/>
<command id="Tools:ChromeDebugger" oncommand="DebuggerUI.toggleChromeDebugger();"/>
<command id="Tools:Scratchpad" oncommand="Scratchpad.openScratchpad();"/>
<command id="Tools:StyleEditor" oncommand="StyleEditor.toggle();"/>
<command id="Tools:ResponsiveUI" oncommand="ResponsiveUI.toggle();"/>
<command id="Tools:Addons" oncommand="BrowserOpenAddonsMgr();"/>
<command id="Tools:Sanitize"
oncommand="Cc['@mozilla.org/browser/browserglue;1'].getService(Ci.nsIBrowserGlue).sanitize(window);"/>
@ -183,6 +183,68 @@
#endif
<broadcaster id="workOfflineMenuitemState"/>
<broadcaster id="socialSidebarBroadcaster" hidden="true"/>
<!-- DevTools broadcasters -->
<broadcaster id="devtoolsMenuBroadcaster_DevToolbar"
label="&devToolbarMenu.label;"
type="checkbox" autocheck="false"
command="Tools:DevToolbar"
key="key_devToolbar"
disabled="true" hidden="true"/>
<broadcaster id="devtoolsMenuBroadcaster_WebConsole"
label="&webConsoleCmd.label;"
type="checkbox" autocheck="false"
key="key_webConsole"
command="Tools:WebConsole"/>
<broadcaster id="devtoolsMenuBroadcaster_Inspect"
label="&inspectMenu.label;"
type="checkbox" autocheck="false"
command="Tools:Inspect"
key="key_inspect"
disabled="true" hidden="true"/>
<broadcaster id="devtoolsMenuBroadcaster_Debugger"
label="&debuggerMenu.label2;"
type="checkbox" autocheck="false"
command="Tools:Debugger"
key="key_debugger"
disabled="true" hidden="true"/>
<broadcaster id="devtoolsMenuBroadcaster_RemoteDebugger"
label="&remoteDebuggerMenu.label;"
command="Tools:RemoteDebugger"
disabled="true" hidden="true"/>
<broadcaster id="devtoolsMenuBroadcaster_ChromeDebugger"
label="&chromeDebuggerMenu.label;"
command="Tools:ChromeDebugger"
disabled="true" hidden="true"/>
<broadcaster id="devtoolsMenuBroadcaster_Scratchpad"
label="&scratchpad.label;"
command="Tools:Scratchpad"
key="key_scratchpad"
disabled="true" hidden="true"/>
<broadcaster id="devtoolsMenuBroadcaster_StyleEditor"
label="&styleeditor.label;"
type="checkbox" autocheck="false"
command="Tools:StyleEditor"
key="key_styleeditor"
disabled="true" hidden="true"/>
<broadcaster id="devtoolsMenuBroadcaster_ResponsiveUI"
label="&responsiveDesignTool.label;"
type="checkbox" autocheck="false"
command="Tools:ResponsiveUI"
key="key_responsiveUI"
disabled="true" hidden="true"/>
<broadcaster id="devtoolsMenuBroadcaster_PageSource"
label="&pageSourceCmd.label;"
key="key_viewSource"
command="View:PageSource"/>
<broadcaster id="devtoolsMenuBroadcaster_ErrorConsole"
hidden="true"
label="&errorConsoleCmd.label;"
key="key_errorConsole"
oncommand="toJavaScriptConsole();"/>
<broadcaster id="devtoolsMenuBroadcaster_GetMoreTools"
label="&getMoreDevtoolsCmd.label;"
oncommand="openUILinkIn('https://addons.mozilla.org/firefox/collections/mozilla/webdeveloper/', 'tab');"/>
</broadcasterset>
<keyset id="mainKeyset">

Просмотреть файл

@ -578,6 +578,12 @@ html|*#gcli-output-frame,
-moz-box-pack: center;
}
/* We don't show the Style Editor button in the developer toolbar for now.
See bug 771203 */
#developer-toolbar-styleeditor {
display: none;
}
/* Responsive Mode */
vbox[anonid=browserContainer][responsivemode] {

Просмотреть файл

@ -1402,12 +1402,10 @@ var gBrowserInit = {
// Enable developer toolbar?
let devToolbarEnabled = gPrefService.getBoolPref("devtools.toolbar.enabled");
if (devToolbarEnabled) {
document.getElementById("menu_devToolbar").hidden = false;
document.getElementById("Tools:DevToolbar").removeAttribute("disabled");
let broadcaster = document.getElementById("devtoolsMenuBroadcaster_DevToolbar");
broadcaster.removeAttribute("disabled");
broadcaster.removeAttribute("hidden");
document.getElementById("Tools:DevToolbarFocus").removeAttribute("disabled");
#ifdef MENUBAR_CAN_AUTOHIDE
document.getElementById("appmenu_devToolbar").hidden = false;
#endif
// Show the toolbar if it was previously visible
if (gPrefService.getBoolPref("devtools.toolbar.visible")) {
@ -1418,33 +1416,25 @@ var gBrowserInit = {
// Enable Inspector?
let enabled = gPrefService.getBoolPref("devtools.inspector.enabled");
if (enabled) {
document.getElementById("menu_pageinspect").hidden = false;
document.getElementById("Tools:Inspect").removeAttribute("disabled");
#ifdef MENUBAR_CAN_AUTOHIDE
document.getElementById("appmenu_pageInspect").hidden = false;
#endif
document.getElementById("developer-toolbar-inspector").hidden = false;
let broadcaster = document.getElementById("devtoolsMenuBroadcaster_Inspect");
broadcaster.removeAttribute("disabled");
broadcaster.removeAttribute("hidden");
}
// Enable Debugger?
let enabled = gPrefService.getBoolPref("devtools.debugger.enabled");
if (enabled) {
document.getElementById("menu_debugger").hidden = false;
document.getElementById("Tools:Debugger").removeAttribute("disabled");
#ifdef MENUBAR_CAN_AUTOHIDE
document.getElementById("appmenu_debugger").hidden = false;
#endif
document.getElementById("developer-toolbar-debugger").hidden = false;
let broadcaster = document.getElementById("devtoolsMenuBroadcaster_Debugger");
broadcaster.removeAttribute("disabled");
broadcaster.removeAttribute("hidden");
}
// Enable Remote Debugger?
let enabled = gPrefService.getBoolPref("devtools.debugger.remote-enabled");
if (enabled) {
document.getElementById("menu_remoteDebugger").hidden = false;
document.getElementById("Tools:RemoteDebugger").removeAttribute("disabled");
#ifdef MENUBAR_CAN_AUTOHIDE
document.getElementById("appmenu_remoteDebugger").hidden = false;
#endif
let broadcaster = document.getElementById("devtoolsMenuBroadcaster_RemoteDebugger");
broadcaster.removeAttribute("disabled");
broadcaster.removeAttribute("hidden");
}
// Enable Chrome Debugger?
@ -1452,45 +1442,34 @@ var gBrowserInit = {
gPrefService.getBoolPref("devtools.debugger.chrome-enabled") &&
gPrefService.getBoolPref("devtools.debugger.remote-enabled");
if (enabled) {
document.getElementById("menu_chromeDebugger").hidden = false;
document.getElementById("Tools:ChromeDebugger").removeAttribute("disabled");
#ifdef MENUBAR_CAN_AUTOHIDE
document.getElementById("appmenu_chromeDebugger").hidden = false;
#endif
let broadcaster = document.getElementById("devtoolsMenuBroadcaster_ChromeDebugger");
broadcaster.removeAttribute("disabled");
broadcaster.removeAttribute("hidden");
}
// Enable Error Console?
// XXX Temporarily always-enabled, see bug 601201
let consoleEnabled = true || gPrefService.getBoolPref("devtools.errorconsole.enabled");
if (consoleEnabled) {
document.getElementById("javascriptConsole").hidden = false;
document.getElementById("key_errorConsole").removeAttribute("disabled");
#ifdef MENUBAR_CAN_AUTOHIDE
document.getElementById("appmenu_errorConsole").hidden = false;
#endif
let broadcaster = document.getElementById("devtoolsMenuBroadcaster_ErrorConsole");
broadcaster.removeAttribute("disabled");
broadcaster.removeAttribute("hidden");
}
// Enable Scratchpad in the UI, if the preference allows this.
let scratchpadEnabled = gPrefService.getBoolPref(Scratchpad.prefEnabledName);
if (scratchpadEnabled) {
document.getElementById("menu_scratchpad").hidden = false;
document.getElementById("Tools:Scratchpad").removeAttribute("disabled");
#ifdef MENUBAR_CAN_AUTOHIDE
document.getElementById("appmenu_scratchpad").hidden = false;
#endif
let broadcaster = document.getElementById("devtoolsMenuBroadcaster_Scratchpad");
broadcaster.removeAttribute("disabled");
broadcaster.removeAttribute("hidden");
}
// Enable Style Editor?
let styleEditorEnabled = gPrefService.getBoolPref(StyleEditor.prefEnabledName);
if (styleEditorEnabled) {
document.getElementById("menu_styleeditor").hidden = false;
document.getElementById("Tools:StyleEditor").removeAttribute("disabled");
#ifdef MENUBAR_CAN_AUTOHIDE
document.getElementById("appmenu_styleeditor").hidden = false;
#endif
// We don't show the Style Editor button in the developer toolbar for now.
// See bug 771203
// document.getElementById("developer-toolbar-styleeditor").hidden = false;
let broadcaster = document.getElementById("devtoolsMenuBroadcaster_StyleEditor");
broadcaster.removeAttribute("disabled");
broadcaster.removeAttribute("hidden");
}
#ifdef MENUBAR_CAN_AUTOHIDE
@ -1505,11 +1484,9 @@ var gBrowserInit = {
// Enable Responsive UI?
let responsiveUIEnabled = gPrefService.getBoolPref("devtools.responsiveUI.enabled");
if (responsiveUIEnabled) {
document.getElementById("menu_responsiveUI").hidden = false;
document.getElementById("Tools:ResponsiveUI").removeAttribute("disabled");
#ifdef MENUBAR_CAN_AUTOHIDE
document.getElementById("appmenu_responsiveUI").hidden = false;
#endif
let broadcaster = document.getElementById("devtoolsMenuBroadcaster_ResponsiveUI");
broadcaster.removeAttribute("disabled");
broadcaster.removeAttribute("hidden");
}
let appMenuButton = document.getElementById("appmenu-button");

Просмотреть файл

@ -1155,24 +1155,35 @@
<textbox class="gclitoolbar-input-node" rows="1"/>
</stack>
<toolbarbutton id="developer-toolbar-webconsole"
label="&webConsoleButton.label;"
class="developer-toolbar-button"
command="Tools:WebConsole"/>
observes="devtoolsMenuBroadcaster_WebConsole"/>
<toolbarbutton id="developer-toolbar-inspector"
label="&inspectorButton.label;"
class="developer-toolbar-button"
hidden="true"
command="Tools:Inspect"/>
observes="devtoolsMenuBroadcaster_Inspect"/>
<toolbarbutton id="developer-toolbar-styleeditor"
label="&styleeditor.label;"
class="developer-toolbar-button"
hidden="true"
command="Tools:StyleEditor"/>
observes="devtoolsMenuBroadcaster_StyleEditor"/>
<toolbarbutton id="developer-toolbar-debugger"
label="&debuggerMenu.label2;"
class="developer-toolbar-button"
hidden="true"
command="Tools:Debugger"/>
observes="devtoolsMenuBroadcaster_Debugger"/>
<toolbarbutton id="developer-toolbar-other-tools"
type="menu"
class="developer-toolbar-button"
label="&devToolbarOtherToolsButton.label;">
<menupopup position="before_end">
<menuitem observes="devtoolsMenuBroadcaster_DevToolbar"/>
<menuitem observes="devtoolsMenuBroadcaster_ResponsiveUI"/>
<menuitem observes="devtoolsMenuBroadcaster_RemoteDebugger"/>
<menuitem observes="devtoolsMenuBroadcaster_ChromeDebugger"/>
<menuitem observes="devtoolsMenuBroadcaster_Scratchpad"/>
<menuitem observes="devtoolsMenuBroadcaster_StyleEditor"/>
<menuitem observes="devtoolsMenuBroadcaster_PageSource"/>
<menuitem observes="devtoolsMenuBroadcaster_ErrorConsole"/>
<menuseparator/>
<menuitem observes="devtoolsMenuBroadcaster_GetMoreTools"/>
</menupopup>
</toolbarbutton>
#ifndef XP_MACOSX
<toolbarbutton id="developer-toolbar-closebutton"
class="devtools-closebutton"

Просмотреть файл

@ -20,10 +20,6 @@ MOCHITEST_BROWSER_FILES = \
browser_privatebrowsing_concurrent.js \
browser_privatebrowsing_concurrent_page.html \
browser_privatebrowsing_crh.js \
browser_privatebrowsing_downloadLastDir.js \
browser_privatebrowsing_downloadLastDir_c.js \
browser_privatebrowsing_downloadLastDir_toggle.js \
browser_privatebrowsing_DownloadLastDirWithCPS.js \
browser_privatebrowsing_fastswitch.js \
browser_privatebrowsing_findbar.js \
browser_privatebrowsing_forgetthissite.js \

Просмотреть файл

@ -1,222 +0,0 @@
/* -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
let downloadModule = {};
Cu.import("resource://gre/modules/DownloadLastDir.jsm", downloadModule);
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/FileUtils.jsm");
let gDownloadLastDir = new downloadModule.DownloadLastDir(window);
let pb = Cc["@mozilla.org/privatebrowsing;1"].
getService(Ci.nsIPrivateBrowsingService);
function test() {
function clearHistory() {
// simulate clearing the private data
Services.obs.notifyObservers(null, "browser:purge-session-history", "");
}
is(typeof gDownloadLastDir, "object", "gDownloadLastDir should be a valid object");
is(gDownloadLastDir.file, null, "LastDir pref should be null to start with");
let tmpDir = FileUtils.getDir("TmpD", [], true);
let uri1 = Services.io.newURI("http://test1.com/", null, null);
let uri2 = Services.io.newURI("http://test2.com/", null, null);
let uri3 = Services.io.newURI("http://test3.com/", null, null);
let uri4 = Services.io.newURI("http://test4.com/", null, null);
function newDir() {
let dir = tmpDir.clone();
dir.append("testdir");
dir.createUnique(Ci.nsIFile.DIRECTORY_TYPE, 0700);
return dir;
}
let dir1 = newDir();
let dir2 = newDir();
let dir3 = newDir();
try {
{ // set up last dir
gDownloadLastDir.setFile(null, tmpDir);
is(gDownloadLastDir.file.path, tmpDir.path, "LastDir should point to the tmpDir");
isnot(gDownloadLastDir.file, tmpDir, "gDownloadLastDir.file should not be pointing to tmpDir");
}
{ // set uri1 to dir1, all should now return dir1
// also check that a new object is returned
gDownloadLastDir.setFile(uri1, dir1);
is(gDownloadLastDir.file.path, dir1.path, "gDownloadLastDir should return dir1");
isnot(gDownloadLastDir.file, dir1, "gDownloadLastDir.file should not return dir1");
is(gDownloadLastDir.getFile(uri1).path, dir1.path, "uri1 should return dir1"); // set in CPS
isnot(gDownloadLastDir.getFile(uri1), dir1, "getFile on uri1 should not return dir1");
is(gDownloadLastDir.getFile(uri2).path, dir1.path, "uri2 should return dir1"); // fallback
isnot(gDownloadLastDir.getFile(uri2), dir1, "getFile on uri2 should not return dir1");
is(gDownloadLastDir.getFile(uri3).path, dir1.path, "uri3 should return dir1"); // fallback
isnot(gDownloadLastDir.getFile(uri3), dir1, "getFile on uri3 should not return dir1");
is(gDownloadLastDir.getFile(uri4).path, dir1.path, "uri4 should return dir1"); // fallback
isnot(gDownloadLastDir.getFile(uri4), dir1, "getFile on uri4 should not return dir1");
}
{ // set uri2 to dir2, all except uri1 should now return dir2
gDownloadLastDir.setFile(uri2, dir2);
is(gDownloadLastDir.file.path, dir2.path, "gDownloadLastDir should point to dir2");
is(gDownloadLastDir.getFile(uri1).path, dir1.path, "uri1 should return dir1"); // set in CPS
is(gDownloadLastDir.getFile(uri2).path, dir2.path, "uri2 should return dir2"); // set in CPS
is(gDownloadLastDir.getFile(uri3).path, dir2.path, "uri3 should return dir2"); // fallback
is(gDownloadLastDir.getFile(uri4).path, dir2.path, "uri4 should return dir2"); // fallback
}
{ // set uri3 to dir3, all except uri1 and uri2 should now return dir3
gDownloadLastDir.setFile(uri3, dir3);
is(gDownloadLastDir.file.path, dir3.path, "gDownloadLastDir should point to dir3");
is(gDownloadLastDir.getFile(uri1).path, dir1.path, "uri1 should return dir1"); // set in CPS
is(gDownloadLastDir.getFile(uri2).path, dir2.path, "uri2 should return dir2"); // set in CPS
is(gDownloadLastDir.getFile(uri3).path, dir3.path, "uri3 should return dir3"); // set in CPS
is(gDownloadLastDir.getFile(uri4).path, dir3.path, "uri4 should return dir4"); // fallback
}
{ // set uri1 to dir2, all except uri3 should now return dir2
gDownloadLastDir.setFile(uri1, dir2);
is(gDownloadLastDir.file.path, dir2.path, "gDownloadLastDir should point to dir2");
is(gDownloadLastDir.getFile(uri1).path, dir2.path, "uri1 should return dir2"); // set in CPS
is(gDownloadLastDir.getFile(uri2).path, dir2.path, "uri2 should return dir2"); // set in CPS
is(gDownloadLastDir.getFile(uri3).path, dir3.path, "uri3 should return dir3"); // set in CPS
is(gDownloadLastDir.getFile(uri4).path, dir2.path, "uri4 should return dir2"); // fallback
}
{ // check clearHistory removes all data
clearHistory();
is(gDownloadLastDir.file, null, "clearHistory removes all data");
is(Services.contentPrefs.hasPref(uri1, "browser.download.lastDir"), false, "LastDir preference should be absent");
is(gDownloadLastDir.getFile(uri1), null, "uri1 should point to null");
is(gDownloadLastDir.getFile(uri2), null, "uri2 should point to null");
is(gDownloadLastDir.getFile(uri3), null, "uri3 should point to null");
is(gDownloadLastDir.getFile(uri4), null, "uri4 should point to null");
}
Services.prefs.setBoolPref("browser.privatebrowsing.keep_current_session", true);
{ // check data set outside PB mode is remembered
gDownloadLastDir.setFile(null, tmpDir);
pb.privateBrowsingEnabled = true;
is(gDownloadLastDir.file.path, tmpDir.path, "LastDir should point to tmpDir inside PB mode");
is(gDownloadLastDir.getFile(uri1).path, tmpDir.path, "uri1 should return tmpDir inside PB mode");
pb.privateBrowsingEnabled = false;
is(gDownloadLastDir.file.path, tmpDir.path, "LastDir should point to tmpDir outside PB mode");
is(gDownloadLastDir.getFile(uri1).path, tmpDir.path, "uri1 should return tmpDir outside PB mode");
clearHistory();
}
{ // check data set using CPS outside PB mode is remembered
gDownloadLastDir.setFile(uri1, dir1);
pb.privateBrowsingEnabled = true;
is(gDownloadLastDir.file.path, dir1.path, "LastDir should point to dir1 inside PB mode");
is(gDownloadLastDir.getFile(uri1).path, dir1.path, "uri1 should return dir1 inside PB mode");
pb.privateBrowsingEnabled = false;
is(gDownloadLastDir.file.path, dir1.path, "LastDir should point to dir1 outside PB mode");
is(gDownloadLastDir.getFile(uri1).path, dir1.path, "uri1 should return dir1 outside PB mode");
clearHistory();
}
{ // check data set inside PB mode is forgotten
pb.privateBrowsingEnabled = true;
gDownloadLastDir.setFile(null, tmpDir);
is(gDownloadLastDir.file.path, tmpDir.path, "LastDir should return tmpDir inside PB mode");
is(gDownloadLastDir.getFile(uri1).path, tmpDir.path, "uri1 should return tmpDir inside PB mode");
pb.privateBrowsingEnabled = false;
is(gDownloadLastDir.file, null, "LastDir should be null outside PB mode");
is(gDownloadLastDir.getFile(uri1), null, "uri1 should return null outside PB mode");
clearHistory();
}
{ // check data set using CPS inside PB mode is forgotten
pb.privateBrowsingEnabled = true;
gDownloadLastDir.setFile(uri1, dir1);
is(gDownloadLastDir.file.path, dir1.path, "LastDir should point to dir1 inside PB mode");
is(gDownloadLastDir.getFile(uri1).path, dir1.path, "uri1 should return dir1 inside PB mode");
pb.privateBrowsingEnabled = false;
is(gDownloadLastDir.file, null, "LastDir should point to null outside PB mode");
is(gDownloadLastDir.getFile(uri1), null, "uri1 should return null outside PB mode");
clearHistory();
}
{ // check data set outside PB mode but changed inside is remembered correctly
gDownloadLastDir.setFile(uri1, dir1);
pb.privateBrowsingEnabled = true;
gDownloadLastDir.setFile(uri1, dir2);
is(gDownloadLastDir.file.path, dir2.path, "LastDir should point to dir2 inside PB mode");
is(gDownloadLastDir.getFile(uri1).path, dir2.path, "uri1 should return dir2 inside PB mode");
pb.privateBrowsingEnabled = false;
is(gDownloadLastDir.file.path, dir1.path, "LastDir should point to dir1 outside PB mode");
is(gDownloadLastDir.getFile(uri1).path, dir1.path, "uri1 should return dir1 outside PB mode");
// check that the last dir store got cleared
pb.privateBrowsingEnabled = true;
is(gDownloadLastDir.file.path, dir1.path, "LastDir should be cleared");
is(gDownloadLastDir.getFile(uri1).path, dir1.path, "uri1 should return dir1");
pb.privateBrowsingEnabled = false;
clearHistory();
}
{ // check clearHistory inside PB mode clears data outside PB mode
pb.privateBrowsingEnabled = true;
gDownloadLastDir.setFile(uri1, dir2);
clearHistory();
is(gDownloadLastDir.file, null, "LastDir should be null afer clearing history");
is(gDownloadLastDir.getFile(uri1), null, "uri1 should return null");
pb.privateBrowsingEnabled = false;
is(gDownloadLastDir.file, null, "LastDir should be null");
is(gDownloadLastDir.getFile(uri1), null, "uri1 should return null");
}
{ // check that disabling CPS works
Services.prefs.setBoolPref("browser.download.lastDir.savePerSite", false);
gDownloadLastDir.setFile(uri1, dir1);
is(gDownloadLastDir.file.path, dir1.path, "LastDir should be set to dir1");
is(gDownloadLastDir.getFile(uri1).path, dir1.path, "uri1 should return dir1");
is(gDownloadLastDir.getFile(uri2).path, dir1.path, "uri2 should return dir1");
is(gDownloadLastDir.getFile(uri3).path, dir1.path, "uri3 should return dir1");
is(gDownloadLastDir.getFile(uri4).path, dir1.path, "uri4 should return dir1");
gDownloadLastDir.setFile(uri2, dir2);
is(gDownloadLastDir.file.path, dir2.path, "LastDir should be set to dir2");
is(gDownloadLastDir.getFile(uri1).path, dir2.path, "uri1 should return dir2");
is(gDownloadLastDir.getFile(uri2).path, dir2.path, "uri2 should return dir2");
is(gDownloadLastDir.getFile(uri3).path, dir2.path, "uri3 should return dir2");
is(gDownloadLastDir.getFile(uri4).path, dir2.path, "uri4 should return dir2");
Services.prefs.clearUserPref("browser.download.lastDir.savePerSite");
}
{ // check that passing null to setFile clears the stored value
gDownloadLastDir.setFile(uri3, dir3);
is(gDownloadLastDir.getFile(uri3).path, dir3.path, "LastDir should be set to dir3");
gDownloadLastDir.setFile(uri3, null);
is(gDownloadLastDir.getFile(uri3), null, "uri3 should return null");
}
} finally {
dir1.remove(true);
dir2.remove(true);
dir3.remove(true);
Services.prefs.clearUserPref("browser.download.lastDir.savePerSite");
Services.prefs.clearUserPref("browser.download.lastDir");
gDownloadLastDir.cleanupPrivateFile();
delete FileUtils;
}
}

Просмотреть файл

@ -1,98 +0,0 @@
/* -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
let downloadModule = {};
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/DownloadLastDir.jsm", downloadModule);
Cu.import("resource://gre/modules/FileUtils.jsm");
Cu.import("resource://mochikit/MockFilePicker.jsm");
let launcher = {
source: Services.io.newURI("http://test1.com/file", null, null)
};
let pb = Cc["@mozilla.org/privatebrowsing;1"].
getService(Ci.nsIPrivateBrowsingService);
let gDownloadLastDir = new downloadModule.DownloadLastDir(window);
MockFilePicker.init();
MockFilePicker.returnValue = Ci.nsIFilePicker.returnOK;
function test() {
Services.prefs.setBoolPref("browser.privatebrowsing.keep_current_session", true);
let prefs = Services.prefs.getBranch("browser.download.");
let launcherDialog = Cc["@mozilla.org/helperapplauncherdialog;1"].
getService(Ci.nsIHelperAppLauncherDialog);
let tmpDir = FileUtils.getDir("TmpD", [], true);
function newDirectory() {
let dir = tmpDir.clone();
dir.append("testdir");
dir.createUnique(Ci.nsIFile.DIRECTORY_TYPE, 0700);
return dir;
}
function newFileInDirectory(dir) {
let file = dir.clone();
file.append("testfile");
file.createUnique(Ci.nsIFile.DIRECTORY_TYPE, 0600);
return file;
}
let dir1 = newDirectory();
let dir2 = newDirectory();
let dir3 = newDirectory();
let file1 = newFileInDirectory(dir1);
let file2 = newFileInDirectory(dir2);
let file3 = newFileInDirectory(dir3);
// cleanup functions registration
registerCleanupFunction(function () {
Services.prefs.clearUserPref("browser.privatebrowsing.keep_current_session");
Services.prefs.clearUserPref("browser.download.lastDir");
[dir1, dir2, dir3].forEach(function(dir) dir.remove(true));
MockFilePicker.cleanup();
gDownloadLastDir.cleanupPrivateFile();
delete FileUtils;
});
let context = gBrowser.selectedBrowser.contentWindow;
prefs.setComplexValue("lastDir", Ci.nsIFile, tmpDir);
MockFilePicker.returnFiles = [file1];
let file = launcherDialog.promptForSaveToFile(launcher, context, null, null, null);
ok(!!file, "promptForSaveToFile correctly returned a file");
// file picker should start with browser.download.lastDir
is(MockFilePicker.displayDirectory.path, tmpDir.path, "File picker should start with browser.download.lastDir");
// browser.download.lastDir should be modified before entering the private browsing mode
is(prefs.getComplexValue("lastDir", Ci.nsIFile).path, dir1.path, "LastDir should be modified before entering the PB mode");
// gDownloadLastDir should be usable outside of the private browsing mode
is(gDownloadLastDir.file.path, dir1.path, "gDownloadLastDir should be usable outside of the PB mode");
pb.privateBrowsingEnabled = true;
is(prefs.getComplexValue("lastDir", Ci.nsIFile).path, dir1.path, "LastDir should be that set before entering PB mode");
MockFilePicker.returnFiles = [file2];
MockFilePicker.displayDirectory = null;
file = launcherDialog.promptForSaveToFile(launcher, context, null, null, null);
ok(!!file, "promptForSaveToFile correctly returned a file");
// file picker should start with browser.download.lastDir as set before entering the private browsing mode
is(MockFilePicker.displayDirectory.path, dir1.path, "Start with LastDir as set before entering the PB mode");
// browser.download.lastDir should not be modified inside the private browsing mode
is(prefs.getComplexValue("lastDir", Ci.nsIFile).path, dir1.path, "LastDir should not be modified inside the PB mode");
// but gDownloadLastDir should be modified
is(gDownloadLastDir.file.path, dir2.path, "gDownloadLastDir should be modified inside PB mode");
pb.privateBrowsingEnabled = false;
// gDownloadLastDir should be cleared after leaving the private browsing mode
is(gDownloadLastDir.file.path, dir1.path, "gDownloadLastDir should be cleared after leaving the PB mode");
MockFilePicker.returnFiles = [file3];
MockFilePicker.displayDirectory = null;
file = launcherDialog.promptForSaveToFile(launcher, context, null, null, null);
ok(!!file, "promptForSaveToFile correctly returned a file");
// file picker should start with browser.download.lastDir as set before entering the private browsing mode
is(MockFilePicker.displayDirectory.path, dir1.path, "Start with LastDir as set before entering the PB mode");
// browser.download.lastDir should be modified after leaving the private browsing mode
is(prefs.getComplexValue("lastDir", Ci.nsIFile).path, dir3.path, "LastDir should be modified after leaving the PB mode");
// gDownloadLastDir should be usable after leaving the private browsing mode
is(gDownloadLastDir.file.path, dir3.path, "gDownloadLastDir should be usable after leaving the PB mode");
}

Просмотреть файл

@ -1,112 +0,0 @@
/* -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
let downloadModule = {};
Cu.import("resource://gre/modules/DownloadLastDir.jsm", downloadModule);
Cu.import("resource://gre/modules/FileUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://mochikit/MockFilePicker.jsm");
let pb = Cc["@mozilla.org/privatebrowsing;1"].
getService(Ci.nsIPrivateBrowsingService);
let gDownloadLastDir = new downloadModule.DownloadLastDir(window);
MockFilePicker.init();
MockFilePicker.returnValue = Ci.nsIFilePicker.returnOK;
function test() {
let stringBundleToRestore = ContentAreaUtils.stringBundle;
let validateFileNameToRestore = validateFileName;
Services.prefs.setBoolPref("browser.privatebrowsing.keep_current_session", true);
let prefs = Services.prefs.getBranch("browser.download.");
let tmpDir = FileUtils.getDir("TmpD", [], true);
function newDirectory() {
let dir = tmpDir.clone();
dir.append("testdir");
dir.createUnique(Ci.nsIFile.DIRECTORY_TYPE, 0700);
return dir;
}
function newFileInDirectory(dir) {
let file = dir.clone();
file.append("testfile");
file.createUnique(Ci.nsIFile.DIRECTORY_TYPE, 0600);
return file;
}
let dir1 = newDirectory();
let dir2 = newDirectory();
let dir3 = newDirectory();
let file1 = newFileInDirectory(dir1);
let file2 = newFileInDirectory(dir2);
let file3 = newFileInDirectory(dir3);
// cleanup function registration
registerCleanupFunction(function () {
Services.prefs.clearUserPref("browser.privatebrowsing.keep_current_session");
Services.prefs.clearUserPref("browser.download.lastDir");
[dir1, dir2, dir3].forEach(function(dir) dir.remove(true));
MockFilePicker.cleanup();
ContentAreaUtils.stringBundle = stringBundleToRestore;
validateFileName = validateFileNameToRestore;
gDownloadLastDir.cleanupPrivateFile();
delete FileUtils;
});
// Overwrite stringBundle to return an object masquerading as a string bundle
delete ContentAreaUtils.stringBundle;
ContentAreaUtils.stringBundle = {
GetStringFromName: function() ""
};
// Overwrite validateFileName to validate everything
validateFileName = function(foo) foo;
let params = {
fpTitleKey: "test",
fileInfo: new FileInfo("test.txt", "test.txt", "test", "txt", "http://mozilla.org/test.txt"),
contentType: "text/plain",
saveMode: SAVEMODE_FILEONLY,
saveAsType: kSaveAsType_Complete,
file: null
};
prefs.setComplexValue("lastDir", Ci.nsIFile, tmpDir);
MockFilePicker.returnFiles = [file1];
MockFilePicker.displayDirectory = null;
ok(getTargetFile(params), "Show the file picker dialog with given params");
// file picker should start with browser.download.lastDir
is(MockFilePicker.displayDirectory.path, tmpDir.path, "file picker should start with browser.download.lastDir");
// browser.download.lastDir should be modified before entering the private browsing mode
is(prefs.getComplexValue("lastDir", Ci.nsIFile).path, dir1.path, "LastDir should be modified before entering PB mode");
// gDownloadLastDir should be usable outside of the private browsing mode
is(gDownloadLastDir.file.path, dir1.path, "gDownloadLastDir should be usable outside of the PB mode");
pb.privateBrowsingEnabled = true;
is(prefs.getComplexValue("lastDir", Ci.nsIFile).path, dir1.path, "LastDir should be that set before PB mode");
MockFilePicker.returnFiles = [file2];
MockFilePicker.displayDirectory = null;
ok(getTargetFile(params), "Show the file picker dialog with the given params");
// file picker should start with browser.download.lastDir as set before entering the private browsing mode
is(MockFilePicker.displayDirectory.path, dir1.path, "File picker should start with LastDir set before entering PB mode");
// browser.download.lastDir should not be modified inside the private browsing mode
is(prefs.getComplexValue("lastDir", Ci.nsIFile).path, dir1.path, "LastDir should not be modified inside PB mode");
// but gDownloadLastDir should be modified
is(gDownloadLastDir.file.path, dir2.path, "gDownloadLastDir should be modified");
pb.privateBrowsingEnabled = false;
// gDownloadLastDir should be cleared after leaving the private browsing mode
is(gDownloadLastDir.file.path, dir1.path, "gDownloadLastDir should be cleared after leaving PB mode");
MockFilePicker.returnFiles = [file3];
MockFilePicker.displayDirectory = null;
ok(getTargetFile(params), "Show the file picker dialog with the given params");
// file picker should start with browser.download.lastDir as set before entering the private browsing mode
is(MockFilePicker.displayDirectory.path, dir1.path, "File picker should start with LastDir set before PB mode");
// browser.download.lastDir should be modified after leaving the private browsing mode
is(prefs.getComplexValue("lastDir", Ci.nsIFile).path, dir3.path, "LastDir should be modified after leaving PB mode");
// gDownloadLastDir should be usable after leaving the private browsing mode
is(gDownloadLastDir.file.path, dir3.path, "gDownloadLastDir should be usable after leaving PB mode");
}

Просмотреть файл

@ -1,74 +0,0 @@
/* -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
let downloadModule = {};
Cu.import("resource://gre/modules/DownloadLastDir.jsm", downloadModule);
Cu.import("resource://gre/modules/FileUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
let gDownloadLastDir = new downloadModule.DownloadLastDir(window);
let pb = Cc["@mozilla.org/privatebrowsing;1"].
getService(Ci.nsIPrivateBrowsingService);
function test() {
function clearHistory() {
// simulate clearing the private data
Services.obs.notifyObservers(null, "browser:purge-session-history", "");
}
is(typeof gDownloadLastDir, "object", "gDownloadLastDir should be a valid object");
is(gDownloadLastDir.file, null, "gDownloadLastDir.file should be null to start with");
let tmpDir = FileUtils.getDir("TmpD", [], true);
let newDir = tmpDir.clone();
registerCleanupFunction(function () {
Services.prefs.clearUserPref("browser.privatebrowsing.keep_current_session");
Services.prefs.clearUserPref("browser.download.lastDir");
newDir.remove(true);
gDownloadLastDir.cleanupPrivateFile();
delete FileUtils;
});
newDir.append("testdir");
newDir.createUnique(Ci.nsIFile.DIRECTORY_TYPE, 0700);
gDownloadLastDir.file = tmpDir;
is(gDownloadLastDir.file.path, tmpDir.path, "LastDir should point to the temporary directory");
isnot(gDownloadLastDir.file, tmpDir, "gDownloadLastDir.file should not be pointing to the tmpDir");
gDownloadLastDir.file = 1; // not an nsIFile
is(gDownloadLastDir.file, null, "gDownloadLastDir.file should be null");
gDownloadLastDir.file = tmpDir;
clearHistory();
is(gDownloadLastDir.file, null, "gDownloadLastDir.file should be null");
gDownloadLastDir.file = tmpDir;
Services.prefs.setBoolPref("browser.privatebrowsing.keep_current_session", true);
pb.privateBrowsingEnabled = true;
is(gDownloadLastDir.file.path, tmpDir.path, "LastDir should point to the temporary directory");
isnot(gDownloadLastDir.file, tmpDir, "gDownloadLastDir.file should not be pointing to the tmpDir");
pb.privateBrowsingEnabled = false;
is(gDownloadLastDir.file.path, tmpDir.path, "LastDir should point to the tmpDir");
pb.privateBrowsingEnabled = true;
gDownloadLastDir.file = newDir;
is(gDownloadLastDir.file.path, newDir.path, "gDownloadLastDir should be modified in PB mode");
isnot(gDownloadLastDir.file, newDir, "gDownloadLastDir should not point to the newDir");
pb.privateBrowsingEnabled = false;
is(gDownloadLastDir.file.path, tmpDir.path, "gDownloadLastDir should point to the earlier directory outside PB mode");
isnot(gDownloadLastDir.file, tmpDir, "gDownloadLastDir should not be modifief outside PB mode");
pb.privateBrowsingEnabled = true;
isnot(gDownloadLastDir.file, null, "gDownloadLastDir should not be null inside PB mode");
clearHistory();
is(gDownloadLastDir.file, null, "gDownloadLastDir should be null after clearing history");
pb.privateBrowsingEnabled = false;
is(gDownloadLastDir.file, null, "gDownloadLastDir should be null outside PB mode");
}

Просмотреть файл

@ -388,7 +388,7 @@ Rule.prototype = {
eltText += "#" + this.inherited.id;
}
this._inheritedSource =
CssLogic._strings.formatStringFromName("rule.inheritedSource", [eltText], 1);
CssLogic._strings.formatStringFromName("rule.inheritedFrom", [eltText], 1);
}
return this._inheritedSource;
},

Просмотреть файл

@ -241,6 +241,7 @@ These should match what Safari and other Apple applications use on OS X Lion. --
<!ENTITY devToolbarMenu.accesskey "v">
<!ENTITY devToolbar.keycode "VK_F2">
<!ENTITY devToolbar.keytext "F2">
<!ENTITY devToolbarOtherToolsButton.label "More Tools">
<!ENTITY webConsoleButton.label "Web Console">
<!ENTITY inspectorButton.label "Inspector">

Просмотреть файл

@ -30,11 +30,11 @@ rule.status.UNMATCHED=Unmatched
rule.sourceInline=inline
rule.sourceElement=element
# LOCALIZATION NOTE (rule.inheritedSource): Shown for CSS rules
# that were inherited from a parent node. Will be passed a node
# identifier and a source location.
# LOCALIZATION NOTE (rule.inheritedFrom): Shown for CSS rules
# that were inherited from a parent node. Will be passed a node
# identifier of the parent node.
# e.g "Inherited from body#bodyID"
rule.inheritedSource=Inherited from %S
rule.inheritedFrom=Inherited from %S
# LOCALIZATION NOTE (style.highlighter.button): These strings are used inside
# sidebar of the Highlighter for the style inspector button.

Просмотреть файл

@ -2565,6 +2565,7 @@ stack[anonid=browserStack][responsivemode] {
list-style-image: url("chrome://browser/skin/devtools/tools-icons-small.png");
}
.developer-toolbar-button[open=true],
.developer-toolbar-button:active:hover,
.developer-toolbar-button[checked=true] {
border-color: hsla(210,8%,5%,.6);
@ -2594,6 +2595,14 @@ stack[anonid=browserStack][responsivemode] {
-moz-image-region: rect(48px, 16px, 64px, 0);
}
#developer-toolbar-other-tools {
-moz-image-region: rect(64px, 16px, 80px, 0);
}
#developer-toolbar-other-tools > .toolbarbutton-menu-dropmarker {
display: none;
}
/* Error counter */
#developer-toolbar-webconsole[error-count]:before {

Просмотреть файл

@ -3319,6 +3319,7 @@ stack[anonid=browserStack][responsivemode] {
list-style-image: url("chrome://browser/skin/devtools/tools-icons-small.png");
}
.developer-toolbar-button[open=true],
.developer-toolbar-button:active:hover,
.developer-toolbar-button[checked=true] {
border-color: hsla(210,8%,5%,.6);
@ -3348,6 +3349,14 @@ stack[anonid=browserStack][responsivemode] {
-moz-image-region: rect(48px, 16px, 64px, 0);
}
#developer-toolbar-other-tools {
-moz-image-region: rect(64px, 16px, 80px, 0);
}
#developer-toolbar-other-tools > .toolbarbutton-menu-dropmarker {
display: none;
}
/* Error counter */
#developer-toolbar-webconsole[error-count]:before {

Просмотреть файл

@ -3246,6 +3246,7 @@ stack[anonid=browserStack][responsivemode] {
list-style-image: url("chrome://browser/skin/devtools/tools-icons-small.png");
}
.developer-toolbar-button[open=true],
.developer-toolbar-button:active:hover,
.developer-toolbar-button[checked=true] {
border-color: hsla(210,8%,5%,.6);
@ -3275,6 +3276,14 @@ stack[anonid=browserStack][responsivemode] {
-moz-image-region: rect(48px, 16px, 64px, 0);
}
#developer-toolbar-other-tools {
-moz-image-region: rect(64px, 16px, 80px, 0);
}
#developer-toolbar-other-tools > .toolbarbutton-menu-dropmarker {
display: none;
}
/* Error counter */
#developer-toolbar-webconsole[error-count]:before {

Просмотреть файл

@ -1451,16 +1451,10 @@ RasterImage::AddSourceData(const char *aBuffer, PRUint32 aCount)
// This call should come straight from necko - no reentrancy allowed
NS_ABORT_IF_FALSE(!mInDecoder, "Re-entrant call to AddSourceData!");
// The decoder is not accepting data, we shouldn't be getting it, but it could
// be extra garbage data at the end of a file.
if (!mDecoder || mDecoder->GetDecodeDone()) {
return NS_OK;
}
// Starting a new part's frames, let's clean up before we add any
// This needs to happen just before we start getting EnsureFrame() call(s),
// so that there's no gap for anything to miss us.
if (mMultipart && mBytesDecoded == 0) {
if (mBytesDecoded == 0) {
// Our previous state may have been animated, so let's clean up
if (mAnimating) {
StopAnimation();

Просмотреть файл

@ -12,7 +12,6 @@ relativesrcdir = image/test/mochitest
include $(DEPTH)/config/autoconf.mk
MOCHITEST_FILES = imgutils.js \
animationPolling.js \
lime100x100.svg \
test_bug399925.html \
bug399925.gif \
@ -58,9 +57,6 @@ MOCHITEST_FILES = imgutils.js \
bug733553-iframe.html \
bug733553.sjs \
animated-gif2.gif \
test_bug767779.html \
bug767779.sjs \
animated-gif_trailing-garbage.gif \
test_error_events.html \
error-early.png \
test_drawDiscardedImage.html \

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 3.9 KiB

Просмотреть файл

@ -1,56 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
var timer = Components.classes["@mozilla.org/timer;1"];
var partTimer = timer.createInstance(Components.interfaces.nsITimer);
function getFileAsInputStream(aFilename) {
var file = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties)
.get("CurWorkD", Components.interfaces.nsIFile);
file.append("tests");
file.append("image");
file.append("test");
file.append("mochitest");
file.append(aFilename);
var fileStream = Components.classes['@mozilla.org/network/file-input-stream;1']
.createInstance(Components.interfaces.nsIFileInputStream);
fileStream.init(file, 1, 0, false);
return fileStream;
}
function handleRequest(request, response)
{
response.setHeader("Content-Type", "image/gif", false);
response.setHeader("Cache-Control", "no-cache", false);
response.setStatusLine(request.httpVersion, 200, "OK");
// We're sending data off in a delayed fashion
response.processAsync();
var inputStream = getFileAsInputStream("animated-gif_trailing-garbage.gif");
var available = inputStream.available(); // = 4029 bytes
// Send the good data at once
response.bodyOutputStream.writeFrom(inputStream, 285);
sendParts(inputStream, response);
}
function sendParts(inputStream, response) {
// 3744 left, send in 8 chunks of 468 each
partTimer.initWithCallback(getSendNextPart(inputStream, response), 500,
Components.interfaces.nsITimer.TYPE_ONE_SHOT);
}
function getSendNextPart(inputStream, response) {
return function () {
response.bodyOutputStream.writeFrom(inputStream, 468);
if (!inputStream.available()) {
inputStream.close();
response.finish();
} else {
sendParts(inputStream, response);
}
};
}

Просмотреть файл

@ -1,44 +0,0 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=767779
-->
<head>
<title>Test for Bug 767779</title>
<script type="application/javascript" src="/MochiKit/MochiKit.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/WindowSnapshot.js"></script>
<script type="application/javascript" src="imgutils.js"></script>
<script type="application/javascript" src="animationPolling.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=767779">Mozilla Bug 767779</a>
<p id="display"></p>
<pre id="test">
<script type="application/javascript">
const FAILURE_TIMEOUT = 30000; // Fail early after 30 seconds
function main()
{
// referenceDiv's size and color correspond to the last frame of the GIF
var animTest = new AnimationTest(20, FAILURE_TIMEOUT, 'referenceDiv',
'animatedGif', 'debug');
animTest.beginTest();
}
window.onload = main;
</script>
</pre>
<div id="content"> <!-- style="display: none" -->
<div id="referenceDiv" style="height: 40px; width: 40px;
display: none; background: #18ff00;"></div>
<div id="animatedImage">
<img id="animatedGif" src="bug767779.sjs" style="display: none;"/>
<div id="text-descr"></div>
</div>
<div id="debug" style="display:none">
</div>
</div>
</body>
</html>

Просмотреть файл

@ -23,6 +23,7 @@
[include:toolkit/components/commandlines/test/unit/xpcshell.ini]
[include:toolkit/components/contentprefs/tests/unit/xpcshell.ini]
[include:toolkit/devtools/debugger/tests/unit/xpcshell.ini]
[include:toolkit/devtools/sourcemap/tests/unit/xpcshell.ini]
[include:toolkit/components/passwordmgr/test/unit/xpcshell.ini]
# Bug 676989: tests hang on Android
skip-if = os == "android"

Просмотреть файл

@ -1,4 +1,4 @@
# -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
# -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
@ -431,7 +431,7 @@ function internalPersist(persistArgs)
* Structure for holding info about automatically supplied parameters for
* internalSave(...). This allows parameters to be supplied so the user does not
* need to be prompted for file info.
* @param aFileAutoChosen This is an nsIFile object that has been
* @param aFileAutoChosen This is an nsILocalFile object that has been
* pre-determined as the filename for the target to save to
* @param aUriAutoChosen This is the nsIURI object for the target
*/
@ -525,13 +525,13 @@ function initFileInfo(aFI, aURL, aURLCharset, aDocument,
*/
function getTargetFile(aFpP, /* optional */ aSkipPrompt, /* optional */ aRelatedURI)
{
let downloadModule = {};
Components.utils.import("resource://gre/modules/DownloadLastDir.jsm", downloadModule);
var gDownloadLastDir = new downloadModule.DownloadLastDir(window);
if (!getTargetFile.gDownloadLastDir)
Components.utils.import("resource://gre/modules/DownloadLastDir.jsm", getTargetFile);
var gDownloadLastDir = getTargetFile.gDownloadLastDir;
var prefs = getPrefsBrowserDownload("browser.download.");
var useDownloadDir = prefs.getBoolPref("useDownloadDir");
const nsIFile = Components.interfaces.nsIFile;
const nsILocalFile = Components.interfaces.nsILocalFile;
if (!aSkipPrompt)
useDownloadDir = false;
@ -568,7 +568,7 @@ function getTargetFile(aFpP, /* optional */ aSkipPrompt, /* optional */ aRelated
// Default to desktop.
var fileLocator = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties);
dir = fileLocator.get("Desk", nsIFile);
dir = fileLocator.get("Desk", nsILocalFile);
}
var fp = makeFilePicker();
@ -600,11 +600,11 @@ function getTargetFile(aFpP, /* optional */ aSkipPrompt, /* optional */ aRelated
prefs.setIntPref("save_converter_index", fp.filterIndex);
// Do not store the last save directory as a pref inside the private browsing mode
var directory = fp.file.parent.QueryInterface(nsIFile);
var directory = fp.file.parent.QueryInterface(nsILocalFile);
gDownloadLastDir.setFile(aRelatedURI, directory);
fp.file.leafName = validateFileName(fp.file.leafName);
aFpP.saveAsType = fp.filterIndex;
aFpP.file = fp.file;
aFpP.fileURL = fp.fileURL;

Просмотреть файл

@ -0,0 +1,130 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const Ci = Components.interfaces;
const Cc = Components.classes;
function loadUtilsScript() {
let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
getService(Ci.mozIJSSubScriptLoader);
loader.loadSubScript("chrome://global/content/contentAreaUtils.js");
Components.utils.import("resource://gre/modules/DownloadLastDir.jsm");
}
do_get_profile();
let window = {};
function run_test()
{
let pb;
try {
pb = Cc["@mozilla.org/privatebrowsing;1"].
getService(Ci.nsIPrivateBrowsingService);
} catch (e) {
print("PB service is not available, bail out");
return;
}
loadUtilsScript();
let prefsService = Cc["@mozilla.org/preferences-service;1"].
getService(Ci.nsIPrefService).
QueryInterface(Ci.nsIPrefBranch);
prefsService.setBoolPref("browser.privatebrowsing.keep_current_session", true);
let prefs = prefsService.getBranch("browser.download.");
let dirSvc = Cc["@mozilla.org/file/directory_service;1"].
getService(Ci.nsIProperties);
let tmpDir = dirSvc.get("TmpD", Ci.nsILocalFile);
function newDirectory() {
let dir = tmpDir.clone();
dir.append("testdir" + Math.floor(Math.random() * 10000));
dir.createUnique(Ci.nsIFile.DIRECTORY_TYPE, 0700);
return dir;
}
function newFileInDirectory(dir) {
let file = dir.clone();
file.append("testfile" + Math.floor(Math.random() * 10000));
file.createUnique(Ci.nsIFile.DIRECTORY_TYPE, 0600);
return file;
}
let dir1 = newDirectory();
let dir2 = newDirectory();
let dir3 = newDirectory();
let file1 = newFileInDirectory(dir1);
let file2 = newFileInDirectory(dir2);
let file3 = newFileInDirectory(dir3);
// overwrite makeFilePicker, as we don't want to create a real filepicker object
let fp = {
appendFilter: function() {},
appendFilters: function() {},
init: function() {},
show: function() Ci.nsIFilePicker.returnOK,
displayDirectory: null,
file: file1
};
makeFilePicker = function() fp;
// Overwrite stringBundle to return an object masquerading as a string bundle
delete ContentAreaUtils.stringBundle;
ContentAreaUtils.stringBundle = {
GetStringFromName: function() ""
};
// Overwrite validateFileName to validate everything
validateFileName = function(foo) foo;
let params = {
fpTitleKey: "test",
fileInfo: new FileInfo("test.txt", "test.txt", "test", "txt", "http://mozilla.org/test.txt"),
contentType: "text/plain",
saveMode: SAVEMODE_FILEONLY,
saveAsType: kSaveAsType_Complete,
file: null
};
prefs.setComplexValue("lastDir", Ci.nsILocalFile, tmpDir);
do_check_true(getTargetFile(params));
// file picker should start with browser.download.lastDir
do_check_eq(fp.displayDirectory.path, tmpDir.path);
// browser.download.lastDir should be modified before entering the private browsing mode
do_check_eq(prefs.getComplexValue("lastDir", Ci.nsILocalFile).path, dir1.path);
// gDownloadLastDir should be usable outside of the private browsing mode
do_check_eq(gDownloadLastDir.file.path, dir1.path);
pb.privateBrowsingEnabled = true;
do_check_eq(prefs.getComplexValue("lastDir", Ci.nsILocalFile).path, dir1.path);
fp.file = file2;
fp.displayDirectory = null;
do_check_true(getTargetFile(params));
// file picker should start with browser.download.lastDir as set before entering the private browsing mode
do_check_eq(fp.displayDirectory.path, dir1.path);
// browser.download.lastDir should not be modified inside the private browsing mode
do_check_eq(prefs.getComplexValue("lastDir", Ci.nsILocalFile).path, dir1.path);
// but gDownloadLastDir should be modified
do_check_eq(gDownloadLastDir.file.path, dir2.path);
pb.privateBrowsingEnabled = false;
// gDownloadLastDir should be cleared after leaving the private browsing mode
do_check_eq(gDownloadLastDir.file.path, dir1.path);
fp.file = file3;
fp.displayDirectory = null;
do_check_true(getTargetFile(params));
// file picker should start with browser.download.lastDir as set before entering the private browsing mode
do_check_eq(fp.displayDirectory.path, dir1.path);
// browser.download.lastDir should be modified after leaving the private browsing mode
do_check_eq(prefs.getComplexValue("lastDir", Ci.nsILocalFile).path, dir3.path);
// gDownloadLastDir should be usable after leaving the private browsing mode
do_check_eq(gDownloadLastDir.file.path, dir3.path);
// cleanup
Cc["@mozilla.org/observer-service;1"]
.getService(Ci.nsIObserverService)
.notifyObservers(null, "quit-application", null);
prefsService.clearUserPref("browser.privatebrowsing.keep_current_session");
[dir1, dir2, dir3].forEach(function(dir) dir.remove(true));
}

Просмотреть файл

@ -4,4 +4,5 @@ tail =
[test_contentAreaUtils.js]
[test_dict.js]
[test_privatebrowsing_downloadLastDir_c.js]
[test_propertyListsUtils.js]

Просмотреть файл

@ -11,6 +11,7 @@ include $(topsrcdir)/config/config.mk
PARALLEL_DIRS += \
debugger \
sourcemap \
$(NULL)
include $(topsrcdir)/config/rules.mk

Просмотреть файл

@ -0,0 +1,19 @@
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
# No tests yet
TEST_DIRS += tests
include $(topsrcdir)/config/rules.mk
libs::
$(NSINSTALL) $(srcdir)/*.jsm $(FINAL_TARGET)/modules/devtools

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -0,0 +1,17 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
DEPTH = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
relativesrcdir = toolkit/devtools/sourcemap/tests
include $(DEPTH)/config/autoconf.mk
MODULE = test_sourcemap
XPCSHELL_TESTS = unit
include $(topsrcdir)/config/rules.mk

Просмотреть файл

@ -0,0 +1,152 @@
/* -*- Mode: js; js-indent-level: 2; -*- */
/*
* Copyright 2011 Mozilla Foundation and contributors
* Licensed under the New BSD license. See LICENSE or:
* http://opensource.org/licenses/BSD-3-Clause
*/
/*
* WARNING!
*
* Do not edit this file directly, it is built from the sources at
* https://github.com/mozilla/source-map/
*/
Components.utils.import('resource:///modules/devtools/Require.jsm');
Components.utils.import('resource:///modules/devtools/SourceMap.jsm');
let EXPORTED_SYMBOLS = [ "define", "runSourceMapTests" ];
/* -*- Mode: js; js-indent-level: 2; -*- */
/*
* Copyright 2011 Mozilla Foundation and contributors
* Licensed under the New BSD license. See LICENSE or:
* http://opensource.org/licenses/BSD-3-Clause
*/
define('test/source-map/assert', ['exports'], function (exports) {
let do_throw = function (msg) {
throw new Error(msg);
};
exports.init = function (throw_fn) {
do_throw = throw_fn;
};
exports.doesNotThrow = function (fn) {
try {
fn();
}
catch (e) {
do_throw(e.message);
}
};
exports.equal = function (actual, expected, msg) {
msg = msg || String(actual) + ' != ' + String(expected);
if (actual != expected) {
do_throw(msg);
}
};
exports.ok = function (val, msg) {
msg = msg || String(val) + ' is falsey';
if (!Boolean(val)) {
do_throw(msg);
}
};
exports.strictEqual = function (actual, expected, msg) {
msg = msg || String(actual) + ' !== ' + String(expected);
if (actual !== expected) {
do_throw(msg);
}
};
exports.throws = function (fn) {
try {
fn();
do_throw('Expected an error to be thrown, but it wasn\'t.');
}
catch (e) {
}
};
});
/* -*- Mode: js; js-indent-level: 2; -*- */
/*
* Copyright 2011 Mozilla Foundation and contributors
* Licensed under the New BSD license. See LICENSE or:
* http://opensource.org/licenses/BSD-3-Clause
*/
define('test/source-map/util', ['require', 'exports', 'module' ], function(require, exports, module) {
// This is a test mapping which maps functions from two different files
// (one.js and two.js) to a minified generated source.
//
// Here is one.js:
//
// ONE.foo = function (bar) {
// return baz(bar);
// };
//
// Here is two.js:
//
// TWO.inc = function (n) {
// return n + 1;
// };
//
// And here is the generated code (min.js):
//
// ONE.foo=function(a){return baz(a);};
// TWO.inc=function(a){return a+1;};
exports.testMap = {
version: 3,
file: 'min.js',
names: ['bar', 'baz', 'n'],
sources: ['one.js', 'two.js'],
sourceRoot: '/the/root',
mappings: 'CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID;CCDb,IAAI,IAAM,SAAUE,GAClB,OAAOA'
};
function assertMapping(generatedLine, generatedColumn, originalSource,
originalLine, originalColumn, name, map, assert) {
var mapping = map.originalPositionFor({
line: generatedLine,
column: generatedColumn
});
assert.equal(mapping.name, name,
'Incorrect name, expected ' + JSON.stringify(name)
+ ', got ' + JSON.stringify(mapping.name));
assert.equal(mapping.line, originalLine,
'Incorrect line, expected ' + JSON.stringify(originalLine)
+ ', got ' + JSON.stringify(mapping.line));
assert.equal(mapping.column, originalColumn,
'Incorrect column, expected ' + JSON.stringify(originalColumn)
+ ', got ' + JSON.stringify(mapping.column));
assert.equal(mapping.source, originalSource,
'Incorrect source, expected ' + JSON.stringify(originalSource)
+ ', got ' + JSON.stringify(mapping.source));
}
exports.assertMapping = assertMapping;
});
/* -*- Mode: js; js-indent-level: 2; -*- */
/*
* Copyright 2011 Mozilla Foundation and contributors
* Licensed under the New BSD license. See LICENSE or:
* http://opensource.org/licenses/BSD-3-Clause
*/
function runSourceMapTests(modName, do_throw) {
let mod = require(modName);
let assert = require('test/source-map/assert');
let util = require('test/source-map/util');
assert.init(do_throw);
for (let k in mod) {
if (/^test/.test(k)) {
mod[k](assert, util);
}
}
}

Просмотреть файл

@ -0,0 +1,8 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;
const Cr = Components.results;

Просмотреть файл

@ -0,0 +1,71 @@
/*
* WARNING!
*
* Do not edit this file directly, it is built from the sources at
* https://github.com/mozilla/source-map/
*/
Components.utils.import('resource://test/Utils.jsm');
/* -*- Mode: js; js-indent-level: 2; -*- */
/*
* Copyright 2011 Mozilla Foundation and contributors
* Licensed under the New BSD license. See LICENSE or:
* http://opensource.org/licenses/BSD-3-Clause
*/
define("test/source-map/test-array-set", ["require", "exports", "module"], function (require, exports, module) {
var ArraySet = require('source-map/array-set').ArraySet;
function makeTestSet() {
var set = new ArraySet();
for (var i = 0; i < 100; i++) {
set.add(String(i));
}
return set;
}
exports['test .has() membership'] = function (assert, util) {
var set = makeTestSet();
for (var i = 0; i < 100; i++) {
assert.ok(set.has(String(i)));
}
};
exports['test .indexOf() elements'] = function (assert, util) {
var set = makeTestSet();
for (var i = 0; i < 100; i++) {
assert.strictEqual(set.indexOf(String(i)), i);
}
};
exports['test .at() indexing'] = function (assert, util) {
var set = makeTestSet();
for (var i = 0; i < 100; i++) {
assert.strictEqual(set.at(i), String(i));
}
};
exports['test creating from an array'] = function (assert, util) {
var set = ArraySet.fromArray(['foo', 'bar', 'baz', 'quux', 'hasOwnProperty']);
assert.ok(set.has('foo'));
assert.ok(set.has('bar'));
assert.ok(set.has('baz'));
assert.ok(set.has('quux'));
assert.ok(set.has('hasOwnProperty'));
assert.strictEqual(set.indexOf('foo'), 0);
assert.strictEqual(set.indexOf('bar'), 1);
assert.strictEqual(set.indexOf('baz'), 2);
assert.strictEqual(set.indexOf('quux'), 3);
assert.strictEqual(set.at(0), 'foo');
assert.strictEqual(set.at(1), 'bar');
assert.strictEqual(set.at(2), 'baz');
assert.strictEqual(set.at(3), 'quux');
};
});
function run_test() {
runSourceMapTests('test/source-map/test-array-set', do_throw);
}

Просмотреть файл

@ -0,0 +1,43 @@
/*
* WARNING!
*
* Do not edit this file directly, it is built from the sources at
* https://github.com/mozilla/source-map/
*/
Components.utils.import('resource://test/Utils.jsm');
/* -*- Mode: js; js-indent-level: 2; -*- */
/*
* Copyright 2011 Mozilla Foundation and contributors
* Licensed under the New BSD license. See LICENSE or:
* http://opensource.org/licenses/BSD-3-Clause
*/
define("test/source-map/test-base64", ["require", "exports", "module"], function (require, exports, module) {
var base64 = require('source-map/base64');
exports['test out of range encoding'] = function (assert, util) {
assert.throws(function () {
base64.encode(-1);
});
assert.throws(function () {
base64.encode(64);
});
};
exports['test out of range decoding'] = function (assert, util) {
assert.throws(function () {
base64.decode('=');
});
};
exports['test normal encoding and decoding'] = function (assert, util) {
for (var i = 0; i < 64; i++) {
assert.equal(base64.decode(base64.encode(i)), i);
}
};
});
function run_test() {
runSourceMapTests('test/source-map/test-base64', do_throw);
}

Просмотреть файл

@ -0,0 +1,32 @@
/*
* WARNING!
*
* Do not edit this file directly, it is built from the sources at
* https://github.com/mozilla/source-map/
*/
Components.utils.import('resource://test/Utils.jsm');
/* -*- Mode: js; js-indent-level: 2; -*- */
/*
* Copyright 2011 Mozilla Foundation and contributors
* Licensed under the New BSD license. See LICENSE or:
* http://opensource.org/licenses/BSD-3-Clause
*/
define("test/source-map/test-base64-vlq", ["require", "exports", "module"], function (require, exports, module) {
var base64VLQ = require('source-map/base64-vlq');
exports['test normal encoding and decoding'] = function (assert, util) {
var result;
for (var i = -255; i < 256; i++) {
result = base64VLQ.decode(base64VLQ.encode(i));
assert.ok(result);
assert.equal(result.value, i);
assert.equal(result.rest, "");
}
};
});
function run_test() {
runSourceMapTests('test/source-map/test-base64-vlq', do_throw);
}

Просмотреть файл

@ -0,0 +1,62 @@
/*
* WARNING!
*
* Do not edit this file directly, it is built from the sources at
* https://github.com/mozilla/source-map/
*/
Components.utils.import('resource://test/Utils.jsm');
/* -*- Mode: js; js-indent-level: 2; -*- */
/*
* Copyright 2011 Mozilla Foundation and contributors
* Licensed under the New BSD license. See LICENSE or:
* http://opensource.org/licenses/BSD-3-Clause
*/
define("test/source-map/test-binary-search", ["require", "exports", "module"], function (require, exports, module) {
var binarySearch = require('source-map/binary-search');
function numberCompare(a, b) {
return a - b;
}
exports['test too high'] = function (assert, util) {
var needle = 30;
var haystack = [2,4,6,8,10,12,14,16,18,20];
assert.doesNotThrow(function () {
binarySearch.search(needle, haystack, numberCompare);
});
assert.equal(binarySearch.search(needle, haystack, numberCompare), 20);
};
exports['test too low'] = function (assert, util) {
var needle = 1;
var haystack = [2,4,6,8,10,12,14,16,18,20];
assert.doesNotThrow(function () {
binarySearch.search(needle, haystack, numberCompare);
});
assert.equal(binarySearch.search(needle, haystack, numberCompare), null);
};
exports['test exact search'] = function (assert, util) {
var needle = 4;
var haystack = [2,4,6,8,10,12,14,16,18,20];
assert.equal(binarySearch.search(needle, haystack, numberCompare), 4);
};
exports['test fuzzy search'] = function (assert, util) {
var needle = 19;
var haystack = [2,4,6,8,10,12,14,16,18,20];
assert.equal(binarySearch.search(needle, haystack, numberCompare), 18);
};
});
function run_test() {
runSourceMapTests('test/source-map/test-binary-search', do_throw);
}

Просмотреть файл

@ -0,0 +1,72 @@
/*
* WARNING!
*
* Do not edit this file directly, it is built from the sources at
* https://github.com/mozilla/source-map/
*/
Components.utils.import('resource://test/Utils.jsm');
/* -*- Mode: js; js-indent-level: 2; -*- */
/*
* Copyright 2011 Mozilla Foundation and contributors
* Licensed under the New BSD license. See LICENSE or:
* http://opensource.org/licenses/BSD-3-Clause
*/
define("test/source-map/test-dog-fooding", ["require", "exports", "module"], function (require, exports, module) {
var SourceMapConsumer = require('source-map/source-map-consumer').SourceMapConsumer;
var SourceMapGenerator = require('source-map/source-map-generator').SourceMapGenerator;
exports['test eating our own dog food'] = function (assert, util) {
var smg = new SourceMapGenerator({
file: 'testing.js',
sourceRoot: '/wu/tang'
});
smg.addMapping({
source: 'gza.coffee',
original: { line: 1, column: 0 },
generated: { line: 2, column: 2 }
});
smg.addMapping({
source: 'gza.coffee',
original: { line: 2, column: 0 },
generated: { line: 3, column: 2 }
});
smg.addMapping({
source: 'gza.coffee',
original: { line: 3, column: 0 },
generated: { line: 4, column: 2 }
});
smg.addMapping({
source: 'gza.coffee',
original: { line: 4, column: 0 },
generated: { line: 5, column: 2 }
});
var smc = new SourceMapConsumer(smg.toString());
// Exact
util.assertMapping(2, 2, '/wu/tang/gza.coffee', 1, 0, null, smc, assert);
util.assertMapping(3, 2, '/wu/tang/gza.coffee', 2, 0, null, smc, assert);
util.assertMapping(4, 2, '/wu/tang/gza.coffee', 3, 0, null, smc, assert);
util.assertMapping(5, 2, '/wu/tang/gza.coffee', 4, 0, null, smc, assert);
// Fuzzy
util.assertMapping(2, 0, null, null, null, null, smc, assert);
util.assertMapping(2, 9, '/wu/tang/gza.coffee', 1, 0, null, smc, assert);
util.assertMapping(3, 0, '/wu/tang/gza.coffee', 1, 0, null, smc, assert);
util.assertMapping(3, 9, '/wu/tang/gza.coffee', 2, 0, null, smc, assert);
util.assertMapping(4, 0, '/wu/tang/gza.coffee', 2, 0, null, smc, assert);
util.assertMapping(4, 9, '/wu/tang/gza.coffee', 3, 0, null, smc, assert);
util.assertMapping(5, 0, '/wu/tang/gza.coffee', 3, 0, null, smc, assert);
util.assertMapping(5, 9, '/wu/tang/gza.coffee', 4, 0, null, smc, assert);
};
});
function run_test() {
runSourceMapTests('test/source-map/test-dog-fooding', do_throw);
}

Просмотреть файл

@ -0,0 +1,75 @@
/*
* WARNING!
*
* Do not edit this file directly, it is built from the sources at
* https://github.com/mozilla/source-map/
*/
Components.utils.import('resource://test/Utils.jsm');
/* -*- Mode: js; js-indent-level: 2; -*- */
/*
* Copyright 2011 Mozilla Foundation and contributors
* Licensed under the New BSD license. See LICENSE or:
* http://opensource.org/licenses/BSD-3-Clause
*/
define("test/source-map/test-source-map-consumer", ["require", "exports", "module"], function (require, exports, module) {
var SourceMapConsumer = require('source-map/source-map-consumer').SourceMapConsumer;
exports['test that we can instantiate with a string or an objects'] = function (assert, util) {
assert.doesNotThrow(function () {
var map = new SourceMapConsumer(util.testMap);
});
assert.doesNotThrow(function () {
var map = new SourceMapConsumer(JSON.stringify(util.testMap));
});
};
exports['test that the source root is reflected in a mapping\'s source field'] = function (assert, util) {
var map = new SourceMapConsumer(util.testMap);
var mapping;
mapping = map.originalPositionFor({
line: 2,
column: 1
});
assert.equal(mapping.source, '/the/root/two.js');
mapping = map.originalPositionFor({
line: 1,
column: 1
});
assert.equal(mapping.source, '/the/root/one.js');
};
exports['test mapping tokens back exactly'] = function (assert, util) {
var map = new SourceMapConsumer(util.testMap);
util.assertMapping(1, 1, '/the/root/one.js', 1, 1, null, map, assert);
util.assertMapping(1, 5, '/the/root/one.js', 1, 5, null, map, assert);
util.assertMapping(1, 9, '/the/root/one.js', 1, 11, null, map, assert);
util.assertMapping(1, 18, '/the/root/one.js', 1, 21, 'bar', map, assert);
util.assertMapping(1, 21, '/the/root/one.js', 2, 3, null, map, assert);
util.assertMapping(1, 28, '/the/root/one.js', 2, 10, 'baz', map, assert);
util.assertMapping(1, 32, '/the/root/one.js', 2, 14, 'bar', map, assert);
util.assertMapping(2, 1, '/the/root/two.js', 1, 1, null, map, assert);
util.assertMapping(2, 5, '/the/root/two.js', 1, 5, null, map, assert);
util.assertMapping(2, 9, '/the/root/two.js', 1, 11, null, map, assert);
util.assertMapping(2, 18, '/the/root/two.js', 1, 21, 'n', map, assert);
util.assertMapping(2, 21, '/the/root/two.js', 2, 3, null, map, assert);
util.assertMapping(2, 28, '/the/root/two.js', 2, 10, 'n', map, assert);
};
exports['test mapping tokens back fuzzy'] = function (assert, util) {
var map = new SourceMapConsumer(util.testMap);
util.assertMapping(1, 20, '/the/root/one.js', 1, 21, 'bar', map, assert);
util.assertMapping(1, 30, '/the/root/one.js', 2, 10, 'baz', map, assert);
util.assertMapping(2, 12, '/the/root/two.js', 1, 11, null, map, assert);
};
});
function run_test() {
runSourceMapTests('test/source-map/test-source-map-consumer', do_throw);
}

Просмотреть файл

@ -0,0 +1,187 @@
/*
* WARNING!
*
* Do not edit this file directly, it is built from the sources at
* https://github.com/mozilla/source-map/
*/
Components.utils.import('resource://test/Utils.jsm');
/* -*- Mode: js; js-indent-level: 2; -*- */
/*
* Copyright 2011 Mozilla Foundation and contributors
* Licensed under the New BSD license. See LICENSE or:
* http://opensource.org/licenses/BSD-3-Clause
*/
define("test/source-map/test-source-map-generator", ["require", "exports", "module"], function (require, exports, module) {
var SourceMapGenerator = require('source-map/source-map-generator').SourceMapGenerator;
exports['test some simple stuff'] = function (assert, util) {
var map = new SourceMapGenerator({
file: 'foo.js',
sourceRoot: '.'
});
assert.ok(true);
};
exports['test adding mappings (case 1)'] = function (assert, util) {
var map = new SourceMapGenerator({
file: 'generated-foo.js',
sourceRoot: '.'
});
assert.doesNotThrow(function () {
map.addMapping({
generated: { line: 1, column: 1 }
});
});
};
exports['test adding mappings (case 2)'] = function (assert, util) {
var map = new SourceMapGenerator({
file: 'generated-foo.js',
sourceRoot: '.'
});
assert.doesNotThrow(function () {
map.addMapping({
generated: { line: 1, column: 1 },
source: 'bar.js',
original: { line: 1, column: 1 }
});
});
};
exports['test adding mappings (case 3)'] = function (assert, util) {
var map = new SourceMapGenerator({
file: 'generated-foo.js',
sourceRoot: '.'
});
assert.doesNotThrow(function () {
map.addMapping({
generated: { line: 1, column: 1 },
source: 'bar.js',
original: { line: 1, column: 1 },
name: 'someToken'
});
});
};
exports['test adding mappings (invalid)'] = function (assert, util) {
var map = new SourceMapGenerator({
file: 'generated-foo.js',
sourceRoot: '.'
});
// Not enough info.
assert.throws(function () {
map.addMapping({});
});
// Original file position, but no source.
assert.throws(function () {
map.addMapping({
generated: { line: 1, column: 1 },
original: { line: 1, column: 1 }
});
});
};
exports['test that the correct mappings are being generated'] = function (assert, util) {
var map = new SourceMapGenerator({
file: 'min.js',
sourceRoot: '/the/root'
});
map.addMapping({
generated: { line: 1, column: 1 },
original: { line: 1, column: 1 },
source: 'one.js'
});
map.addMapping({
generated: { line: 1, column: 5 },
original: { line: 1, column: 5 },
source: 'one.js'
});
map.addMapping({
generated: { line: 1, column: 9 },
original: { line: 1, column: 11 },
source: 'one.js'
});
map.addMapping({
generated: { line: 1, column: 18 },
original: { line: 1, column: 21 },
source: 'one.js',
name: 'bar'
});
map.addMapping({
generated: { line: 1, column: 21 },
original: { line: 2, column: 3 },
source: 'one.js'
});
map.addMapping({
generated: { line: 1, column: 28 },
original: { line: 2, column: 10 },
source: 'one.js',
name: 'baz'
});
map.addMapping({
generated: { line: 1, column: 32 },
original: { line: 2, column: 14 },
source: 'one.js',
name: 'bar'
});
map.addMapping({
generated: { line: 2, column: 1 },
original: { line: 1, column: 1 },
source: 'two.js'
});
map.addMapping({
generated: { line: 2, column: 5 },
original: { line: 1, column: 5 },
source: 'two.js'
});
map.addMapping({
generated: { line: 2, column: 9 },
original: { line: 1, column: 11 },
source: 'two.js'
});
map.addMapping({
generated: { line: 2, column: 18 },
original: { line: 1, column: 21 },
source: 'two.js',
name: 'n'
});
map.addMapping({
generated: { line: 2, column: 21 },
original: { line: 2, column: 3 },
source: 'two.js'
});
map.addMapping({
generated: { line: 2, column: 28 },
original: { line: 2, column: 10 },
source: 'two.js',
name: 'n'
});
map = JSON.parse(map.toString());
assert.equal(map.version, 3);
assert.equal(map.file, 'min.js');
assert.equal(map.names.length, 3);
assert.equal(map.names[0], 'bar');
assert.equal(map.names[1], 'baz');
assert.equal(map.names[2], 'n');
assert.equal(map.sources.length, 2);
assert.equal(map.sources[0], 'one.js');
assert.equal(map.sources[1], 'two.js');
assert.equal(map.sourceRoot, '/the/root');
assert.equal(map.mappings, 'CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID;CCDb,IAAI,IAAM,SAAUE,GAClB,OAAOA');
};
});
function run_test() {
runSourceMapTests('test/source-map/test-source-map-generator', do_throw);
}

Просмотреть файл

@ -0,0 +1,155 @@
/*
* WARNING!
*
* Do not edit this file directly, it is built from the sources at
* https://github.com/mozilla/source-map/
*/
Components.utils.import('resource://test/Utils.jsm');
/* -*- Mode: js; js-indent-level: 2; -*- */
/*
* Copyright 2011 Mozilla Foundation and contributors
* Licensed under the New BSD license. See LICENSE or:
* http://opensource.org/licenses/BSD-3-Clause
*/
define("test/source-map/test-source-node", ["require", "exports", "module"], function (require, exports, module) {
var SourceMapGenerator = require('source-map/source-map-generator').SourceMapGenerator;
var SourceMapConsumer = require('source-map/source-map-consumer').SourceMapConsumer;
var SourceNode = require('source-map/source-node').SourceNode;
exports['test .add()'] = function (assert, util) {
var node = new SourceNode(null, null, null);
// Adding a string works.
node.add('function noop() {}');
// Adding another source node works.
node.add(new SourceNode(null, null, null));
// Adding an array works.
node.add(['function foo() {',
new SourceNode(null, null, null,
'return 10;'),
'}']);
// Adding other stuff doesn't.
assert.throws(function () {
node.add({});
});
assert.throws(function () {
node.add(function () {});
});
};
exports['test .prepend()'] = function (assert, util) {
var node = new SourceNode(null, null, null);
// Prepending a string works.
node.prepend('function noop() {}');
assert.equal(node.children[0], 'function noop() {}');
assert.equal(node.children.length, 1);
// Prepending another source node works.
node.prepend(new SourceNode(null, null, null));
assert.equal(node.children[0], '');
assert.equal(node.children[1], 'function noop() {}');
assert.equal(node.children.length, 2);
// Prepending an array works.
node.prepend(['function foo() {',
new SourceNode(null, null, null,
'return 10;'),
'}']);
assert.equal(node.children[0], 'function foo() {');
assert.equal(node.children[1], 'return 10;');
assert.equal(node.children[2], '}');
assert.equal(node.children[3], '');
assert.equal(node.children[4], 'function noop() {}');
assert.equal(node.children.length, 5);
// Prepending other stuff doesn't.
assert.throws(function () {
node.prepend({});
});
assert.throws(function () {
node.prepend(function () {});
});
};
exports['test .toString()'] = function (assert, util) {
assert.equal((new SourceNode(null, null, null,
['function foo() {',
new SourceNode(null, null, null, 'return 10;'),
'}'])).toString(),
'function foo() {return 10;}');
};
exports['test .join()'] = function (assert, util) {
assert.equal((new SourceNode(null, null, null,
['a', 'b', 'c', 'd'])).join(', ').toString(),
'a, b, c, d');
};
exports['test .walk()'] = function (assert, util) {
var node = new SourceNode(null, null, null,
['(function () {\n',
' ', new SourceNode(1, 0, 'a.js', ['someCall()']), ';\n',
' ', new SourceNode(2, 0, 'b.js', ['if (foo) bar()']), ';\n',
'}());']);
var expected = [
{ str: '(function () {\n', source: null, line: null, column: null },
{ str: ' ', source: null, line: null, column: null },
{ str: 'someCall()', source: 'a.js', line: 1, column: 0 },
{ str: ';\n', source: null, line: null, column: null },
{ str: ' ', source: null, line: null, column: null },
{ str: 'if (foo) bar()', source: 'b.js', line: 2, column: 0 },
{ str: ';\n', source: null, line: null, column: null },
{ str: '}());', source: null, line: null, column: null },
];
var i = 0;
node.walk(function (chunk, loc) {
assert.equal(expected[i].str, chunk);
assert.equal(expected[i].source, loc.source);
assert.equal(expected[i].line, loc.line);
assert.equal(expected[i].column, loc.column);
i++;
});
};
exports['test .toStringWithSourceMap()'] = function (assert, util) {
var node = new SourceNode(null, null, null,
['(function () {\n',
' ', new SourceNode(1, 0, 'a.js', ['someCall()']), ';\n',
' ', new SourceNode(2, 0, 'b.js', ['if (foo) bar()']), ';\n',
'}());']);
var map = node.toStringWithSourceMap({
file: 'foo.js'
}).map;
assert.ok(map instanceof SourceMapGenerator, 'map instanceof SourceMapGenerator');
map = new SourceMapConsumer(map.toString());
var actual;
actual = map.originalPositionFor({
line: 2,
column: 2
});
assert.equal(actual.source, 'a.js');
assert.equal(actual.line, 1);
assert.equal(actual.column, 0);
actual = map.originalPositionFor({
line: 3,
column: 2
});
assert.equal(actual.source, 'b.js');
assert.equal(actual.line, 2);
assert.equal(actual.column, 0);
};
});
function run_test() {
runSourceMapTests('test/source-map/test-source-node', do_throw);
}

Просмотреть файл

@ -0,0 +1,12 @@
[DEFAULT]
head = head_sourcemap.js
tail =
[test_source_node.js]
[test_source_map_generator.js]
[test_source_map_consumer.js]
[test_dog_fooding.js]
[test_binary_search.js]
[test_base64_vlq.js]
[test_base64.js]
[test_array_set.js]

Просмотреть файл

@ -1,4 +1,3 @@
/* -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
@ -26,12 +25,18 @@
const LAST_DIR_PREF = "browser.download.lastDir";
const SAVE_PER_SITE_PREF = LAST_DIR_PREF + ".savePerSite";
const nsIFile = Components.interfaces.nsIFile;
const PBSVC_CID = "@mozilla.org/privatebrowsing;1";
const nsILocalFile = Components.interfaces.nsILocalFile;
var EXPORTED_SYMBOLS = [ "DownloadLastDir" ];
var EXPORTED_SYMBOLS = [ "gDownloadLastDir" ];
Components.utils.import("resource://gre/modules/Services.jsm");
Components.utils.import("resource://gre/modules/PrivateBrowsingUtils.jsm");
let pbSvc = null;
if (PBSVC_CID in Components.classes) {
pbSvc = Components.classes[PBSVC_CID]
.getService(Components.interfaces.nsIPrivateBrowsingService);
}
let observer = {
QueryInterface: function (aIID) {
@ -43,8 +48,12 @@ let observer = {
},
observe: function (aSubject, aTopic, aData) {
switch (aTopic) {
case "last-pb-context-exited":
gDownloadLastDirFile = null;
case "private-browsing":
if (aData == "enter")
gDownloadLastDirFile = readLastDirPref();
else if (aData == "exit") {
gDownloadLastDirFile = null;
}
break;
case "browser:purge-session-history":
gDownloadLastDirFile = null;
@ -58,12 +67,12 @@ let observer = {
let os = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
os.addObserver(observer, "last-pb-context-exited", true);
os.addObserver(observer, "private-browsing", true);
os.addObserver(observer, "browser:purge-session-history", true);
function readLastDirPref() {
try {
return Services.prefs.getComplexValue(LAST_DIR_PREF, nsIFile);
return Services.prefs.getComplexValue(LAST_DIR_PREF, nsILocalFile);
}
catch (e) {
return null;
@ -73,34 +82,23 @@ function readLastDirPref() {
function isContentPrefEnabled() {
try {
return Services.prefs.getBoolPref(SAVE_PER_SITE_PREF);
}
}
catch (e) {
return true;
}
}
let gDownloadLastDirFile = readLastDirPref();
function DownloadLastDir(aWindow) {
this.window = aWindow;
}
DownloadLastDir.prototype = {
isPrivate: function DownloadLastDir_isPrivate() {
return PrivateBrowsingUtils.isWindowPrivate(this.window);
},
let gDownloadLastDir = {
// compat shims
get file() { return this.getFile(); },
set file(val) { this.setFile(null, val); },
cleanupPrivateFile: function () {
gDownloadLastDirFile = null;
},
getFile: function (aURI) {
if (aURI && isContentPrefEnabled()) {
let lastDir = Services.contentPrefs.getPref(aURI, LAST_DIR_PREF);
if (lastDir) {
var lastDirFile = Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsIFile);
.createInstance(Components.interfaces.nsILocalFile);
lastDirFile.initWithPath(lastDir);
return lastDirFile;
}
@ -108,11 +106,8 @@ DownloadLastDir.prototype = {
if (gDownloadLastDirFile && !gDownloadLastDirFile.exists())
gDownloadLastDirFile = null;
if (this.isPrivate()) {
if (!gDownloadLastDirFile)
gDownloadLastDirFile = readLastDirPref();
if (pbSvc && pbSvc.privateBrowsingEnabled)
return gDownloadLastDirFile;
}
else
return readLastDirPref();
},
@ -123,14 +118,14 @@ DownloadLastDir.prototype = {
else
Services.contentPrefs.removePref(aURI, LAST_DIR_PREF);
}
if (this.isPrivate()) {
if (pbSvc && pbSvc.privateBrowsingEnabled) {
if (aFile instanceof Components.interfaces.nsIFile)
gDownloadLastDirFile = aFile.clone();
else
gDownloadLastDirFile = null;
} else {
if (aFile instanceof Components.interfaces.nsIFile)
Services.prefs.setComplexValue(LAST_DIR_PREF, nsIFile, aFile);
Services.prefs.setComplexValue(LAST_DIR_PREF, nsILocalFile, aFile);
else if (Services.prefs.prefHasUserValue(LAST_DIR_PREF))
Services.prefs.clearUserPref(LAST_DIR_PREF);
}

Просмотреть файл

@ -1,4 +1,4 @@
/* -*- Mode: javascript; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/*
# This Source Code Form is subject to the terms of the Mozilla Public
@ -97,9 +97,8 @@ nsUnknownContentTypeDialogProgressListener.prototype = {
const PREF_BD_USEDOWNLOADDIR = "browser.download.useDownloadDir";
const nsITimer = Components.interfaces.nsITimer;
let downloadModule = {};
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
Components.utils.import("resource://gre/modules/DownloadLastDir.jsm", downloadModule);
Components.utils.import("resource://gre/modules/DownloadLastDir.jsm");
Components.utils.import("resource://gre/modules/DownloadPaths.jsm");
Components.utils.import("resource://gre/modules/DownloadUtils.jsm");
@ -246,8 +245,6 @@ nsUnknownContentTypeDialog.prototype = {
picker.init(parent, windowTitle, nsIFilePicker.modeSave);
picker.defaultString = aDefaultFile;
let gDownloadLastDir = new downloadModule.DownloadLastDir(parent);
if (aSuggestedFileExtension) {
// aSuggestedFileExtension includes the period, so strip it
picker.defaultExtension = aSuggestedFileExtension.substring(1);

Просмотреть файл

@ -0,0 +1,82 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
function run_test()
{
let Cc = Components.classes;
let Ci = Components.interfaces;
let Cu = Components.utils;
do_get_profile();
Cu.import("resource://gre/modules/DownloadLastDir.jsm");
function clearHistory() {
// simulate clearing the private data
Cc["@mozilla.org/observer-service;1"].
getService(Ci.nsIObserverService).
notifyObservers(null, "browser:purge-session-history", "");
}
do_check_eq(typeof gDownloadLastDir, "object");
do_check_eq(gDownloadLastDir.file, null);
let dirSvc = Cc["@mozilla.org/file/directory_service;1"].
getService(Ci.nsIProperties);
let tmpDir = dirSvc.get("TmpD", Ci.nsILocalFile);
let newDir = tmpDir.clone();
newDir.append("testdir" + Math.floor(Math.random() * 10000));
newDir.QueryInterface(Ci.nsILocalFile);
newDir.createUnique(Ci.nsIFile.DIRECTORY_TYPE, 0700);
gDownloadLastDir.file = tmpDir;
do_check_eq(gDownloadLastDir.file.path, tmpDir.path);
do_check_neq(gDownloadLastDir.file, tmpDir);
gDownloadLastDir.file = 1; // not an nsIFile
do_check_eq(gDownloadLastDir.file, null);
gDownloadLastDir.file = tmpDir;
clearHistory();
do_check_eq(gDownloadLastDir.file, null);
gDownloadLastDir.file = tmpDir;
let pb;
try {
pb = Cc["@mozilla.org/privatebrowsing;1"].
getService(Ci.nsIPrivateBrowsingService);
} catch (e) {
print("PB service is not available, bail out");
return;
}
let prefs = Cc["@mozilla.org/preferences-service;1"].
getService(Ci.nsIPrefBranch);
prefs.setBoolPref("browser.privatebrowsing.keep_current_session", true);
pb.privateBrowsingEnabled = true;
do_check_eq(gDownloadLastDir.file.path, tmpDir.path);
do_check_neq(gDownloadLastDir.file, tmpDir);
pb.privateBrowsingEnabled = false;
do_check_eq(gDownloadLastDir.file.path, tmpDir.path);
pb.privateBrowsingEnabled = true;
gDownloadLastDir.file = newDir;
do_check_eq(gDownloadLastDir.file.path, newDir.path);
do_check_neq(gDownloadLastDir.file, newDir);
pb.privateBrowsingEnabled = false;
do_check_eq(gDownloadLastDir.file.path, tmpDir.path);
do_check_neq(gDownloadLastDir.file, tmpDir);
pb.privateBrowsingEnabled = true;
do_check_neq(gDownloadLastDir.file, null);
clearHistory();
do_check_eq(gDownloadLastDir.file, null);
pb.privateBrowsingEnabled = false;
do_check_eq(gDownloadLastDir.file, null);
prefs.clearUserPref("browser.privatebrowsing.keep_current_session");
newDir.remove(true);
}

Просмотреть файл

@ -0,0 +1,228 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;
Cu.import("resource://gre/modules/DownloadLastDir.jsm");
Cu.import("resource://gre/modules/Services.jsm");
do_get_profile();
function run_test() {
function clearHistory() {
// simulate clearing the private data
Services.obs.notifyObservers(null, "browser:purge-session-history", "");
}
do_check_eq(typeof gDownloadLastDir, "object");
do_check_eq(gDownloadLastDir.file, null);
let tmpDir = Services.dirsvc.get("TmpD", Ci.nsILocalFile);
let uri1 = Services.io.newURI("http://test1.com/", null, null);
let uri2 = Services.io.newURI("http://test2.com/", null, null);
let uri3 = Services.io.newURI("http://test3.com/", null, null);
let uri4 = Services.io.newURI("http://test4.com/", null, null);
function newDir() {
let dir = tmpDir.clone();
dir.append("testdir" + Math.floor(Math.random() * 10000));
dir.QueryInterface(Ci.nsILocalFile);
dir.createUnique(Ci.nsIFile.DIRECTORY_TYPE, 0700);
return dir;
}
let dir1 = newDir();
let dir2 = newDir();
let dir3 = newDir();
try {
{ // set up last dir
gDownloadLastDir.setFile(null, tmpDir);
do_check_eq(gDownloadLastDir.file.path, tmpDir.path);
do_check_neq(gDownloadLastDir.file, tmpDir);
}
{ // set uri1 to dir1, all should now return dir1
// also check that a new object is returned
gDownloadLastDir.setFile(uri1, dir1);
do_check_eq(gDownloadLastDir.file.path, dir1.path);
do_check_neq(gDownloadLastDir.file, dir1);
do_check_eq(gDownloadLastDir.getFile(uri1).path, dir1.path); // set in CPS
do_check_neq(gDownloadLastDir.getFile(uri1), dir1);
do_check_eq(gDownloadLastDir.getFile(uri2).path, dir1.path); // fallback
do_check_neq(gDownloadLastDir.getFile(uri2), dir1);
do_check_eq(gDownloadLastDir.getFile(uri3).path, dir1.path); // fallback
do_check_neq(gDownloadLastDir.getFile(uri3), dir1);
do_check_eq(gDownloadLastDir.getFile(uri4).path, dir1.path); // fallback
do_check_neq(gDownloadLastDir.getFile(uri4), dir1);
}
{ // set uri2 to dir2, all except uri1 should now return dir2
gDownloadLastDir.setFile(uri2, dir2);
do_check_eq(gDownloadLastDir.file.path, dir2.path);
do_check_eq(gDownloadLastDir.getFile(uri1).path, dir1.path); // set in CPS
do_check_eq(gDownloadLastDir.getFile(uri2).path, dir2.path); // set in CPS
do_check_eq(gDownloadLastDir.getFile(uri3).path, dir2.path); // fallback
do_check_eq(gDownloadLastDir.getFile(uri4).path, dir2.path); // fallback
}
{ // set uri3 to dir3, all except uri1 and uri2 should now return dir3
gDownloadLastDir.setFile(uri3, dir3);
do_check_eq(gDownloadLastDir.file.path, dir3.path);
do_check_eq(gDownloadLastDir.getFile(uri1).path, dir1.path); // set in CPS
do_check_eq(gDownloadLastDir.getFile(uri2).path, dir2.path); // set in CPS
do_check_eq(gDownloadLastDir.getFile(uri3).path, dir3.path); // set in CPS
do_check_eq(gDownloadLastDir.getFile(uri4).path, dir3.path); // fallback
}
{ // set uri1 to dir2, all except uri3 should now return dir2
gDownloadLastDir.setFile(uri1, dir2);
do_check_eq(gDownloadLastDir.file.path, dir2.path);
do_check_eq(gDownloadLastDir.getFile(uri1).path, dir2.path); // set in CPS
do_check_eq(gDownloadLastDir.getFile(uri2).path, dir2.path); // set in CPS
do_check_eq(gDownloadLastDir.getFile(uri3).path, dir3.path); // set in CPS
do_check_eq(gDownloadLastDir.getFile(uri4).path, dir2.path); // fallback
}
{ // check clearHistory removes all data
clearHistory();
do_check_eq(gDownloadLastDir.file, null);
do_check_eq(Services.contentPrefs.hasPref(uri1, "browser.download.lastDir"), false);
do_check_eq(gDownloadLastDir.getFile(uri1), null);
do_check_eq(gDownloadLastDir.getFile(uri2), null);
do_check_eq(gDownloadLastDir.getFile(uri3), null);
do_check_eq(gDownloadLastDir.getFile(uri4), null);
}
let pb;
try {
pb = Cc["@mozilla.org/privatebrowsing;1"].getService(Ci.nsIPrivateBrowsingService);
} catch (e) {
print("PB service is not available, bail out");
return;
}
Services.prefs.setBoolPref("browser.privatebrowsing.keep_current_session", true);
{ // check data set outside PB mode is remembered
gDownloadLastDir.setFile(null, tmpDir);
pb.privateBrowsingEnabled = true;
do_check_eq(gDownloadLastDir.file.path, tmpDir.path);
do_check_eq(gDownloadLastDir.getFile(uri1).path, tmpDir.path);
pb.privateBrowsingEnabled = false;
do_check_eq(gDownloadLastDir.file.path, tmpDir.path);
do_check_eq(gDownloadLastDir.getFile(uri1).path, tmpDir.path);
clearHistory();
}
{ // check data set using CPS outside PB mode is remembered
gDownloadLastDir.setFile(uri1, dir1);
pb.privateBrowsingEnabled = true;
do_check_eq(gDownloadLastDir.file.path, dir1.path);
do_check_eq(gDownloadLastDir.getFile(uri1).path, dir1.path);
pb.privateBrowsingEnabled = false;
do_check_eq(gDownloadLastDir.file.path, dir1.path);
do_check_eq(gDownloadLastDir.getFile(uri1).path, dir1.path);
clearHistory();
}
{ // check data set inside PB mode is forgotten
pb.privateBrowsingEnabled = true;
gDownloadLastDir.setFile(null, tmpDir);
do_check_eq(gDownloadLastDir.file.path, tmpDir.path);
do_check_eq(gDownloadLastDir.getFile(uri1).path, tmpDir.path);
pb.privateBrowsingEnabled = false;
do_check_eq(gDownloadLastDir.file, null);
do_check_eq(gDownloadLastDir.getFile(uri1), null);
clearHistory();
}
{ // check data set using CPS inside PB mode is forgotten
pb.privateBrowsingEnabled = true;
gDownloadLastDir.setFile(uri1, dir1);
do_check_eq(gDownloadLastDir.file.path, dir1.path);
do_check_eq(gDownloadLastDir.getFile(uri1).path, dir1.path);
pb.privateBrowsingEnabled = false;
do_check_eq(gDownloadLastDir.file, null);
do_check_eq(gDownloadLastDir.getFile(uri1), null);
clearHistory();
}
{ // check data set outside PB mode but changed inside is remembered correctly
gDownloadLastDir.setFile(uri1, dir1);
pb.privateBrowsingEnabled = true;
gDownloadLastDir.setFile(uri1, dir2);
do_check_eq(gDownloadLastDir.file.path, dir2.path);
do_check_eq(gDownloadLastDir.getFile(uri1).path, dir2.path);
pb.privateBrowsingEnabled = false;
do_check_eq(gDownloadLastDir.file.path, dir1.path);
do_check_eq(gDownloadLastDir.getFile(uri1).path, dir1.path);
// check that the last dir store got cleared
pb.privateBrowsingEnabled = true;
do_check_eq(gDownloadLastDir.file.path, dir1.path);
do_check_eq(gDownloadLastDir.getFile(uri1).path, dir1.path);
pb.privateBrowsingEnabled = false;
clearHistory();
}
{ // check clearHistory inside PB mode clears data outside PB mode
pb.privateBrowsingEnabled = true;
gDownloadLastDir.setFile(uri1, dir2);
clearHistory();
do_check_eq(gDownloadLastDir.file, null);
do_check_eq(gDownloadLastDir.getFile(uri1), null);
pb.privateBrowsingEnabled = false;
do_check_eq(gDownloadLastDir.file, null);
do_check_eq(gDownloadLastDir.getFile(uri1), null);
}
{ // check that disabling CPS works
Services.prefs.setBoolPref("browser.download.lastDir.savePerSite", false);
gDownloadLastDir.setFile(uri1, dir1);
do_check_eq(gDownloadLastDir.file.path, dir1.path);
do_check_eq(gDownloadLastDir.getFile(uri1).path, dir1.path);
do_check_eq(gDownloadLastDir.getFile(uri2).path, dir1.path);
do_check_eq(gDownloadLastDir.getFile(uri3).path, dir1.path);
do_check_eq(gDownloadLastDir.getFile(uri4).path, dir1.path);
gDownloadLastDir.setFile(uri2, dir2);
do_check_eq(gDownloadLastDir.file.path, dir2.path);
do_check_eq(gDownloadLastDir.getFile(uri1).path, dir2.path);
do_check_eq(gDownloadLastDir.getFile(uri2).path, dir2.path);
do_check_eq(gDownloadLastDir.getFile(uri3).path, dir2.path);
do_check_eq(gDownloadLastDir.getFile(uri4).path, dir2.path);
Services.prefs.clearUserPref("browser.download.lastDir.savePerSite");
}
{ // check that passing null to setFile clears the stored value
gDownloadLastDir.setFile(uri3, dir3);
do_check_eq(gDownloadLastDir.getFile(uri3).path, dir3.path);
gDownloadLastDir.setFile(uri3, null);
do_check_eq(gDownloadLastDir.getFile(uri3), null);
}
} finally {
dir1.remove(true);
dir2.remove(true);
dir3.remove(true);
Services.prefs.clearUserPref("browser.download.lastDir.savePerSite");
}
}

Просмотреть файл

@ -0,0 +1,114 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const Ci = Components.interfaces;
const Cc = Components.classes;
const Cu = Components.utils;
const Cr = Components.results;
do_get_profile();
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/DownloadLastDir.jsm");
let context = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsIInterfaceRequestor]),
getInterface: XPCOMUtils.generateQI([Ci.nsIDOMWindow])
};
let launcher = {
source: Services.io.newURI("http://test1.com/file", null, null)
};
Cu.import("resource://test/MockFilePicker.jsm");
MockFilePicker.init();
MockFilePicker.returnValue = Ci.nsIFilePicker.returnOK;
function run_test()
{
let pb;
try {
pb = Cc["@mozilla.org/privatebrowsing;1"].
getService(Ci.nsIPrivateBrowsingService);
} catch (e) {
print("PB service is not available, bail out");
return;
}
let prefsService = Cc["@mozilla.org/preferences-service;1"].
getService(Ci.nsIPrefService).
QueryInterface(Ci.nsIPrefBranch);
prefsService.setBoolPref("browser.privatebrowsing.keep_current_session", true);
let prefs = prefsService.getBranch("browser.download.");
let launcherDialog = Cc["@mozilla.org/helperapplauncherdialog;1"].
getService(Ci.nsIHelperAppLauncherDialog);
let dirSvc = Cc["@mozilla.org/file/directory_service;1"].
getService(Ci.nsIProperties);
let tmpDir = dirSvc.get("TmpD", Ci.nsILocalFile);
function newDirectory() {
let dir = tmpDir.clone();
dir.append("testdir" + Math.floor(Math.random() * 10000));
dir.createUnique(Ci.nsIFile.DIRECTORY_TYPE, 0700);
return dir;
}
function newFileInDirectory(dir) {
let file = dir.clone();
file.append("testfile" + Math.floor(Math.random() * 10000));
file.createUnique(Ci.nsIFile.DIRECTORY_TYPE, 0600);
return file;
}
let dir1 = newDirectory();
let dir2 = newDirectory();
let dir3 = newDirectory();
let file1 = newFileInDirectory(dir1);
let file2 = newFileInDirectory(dir2);
let file3 = newFileInDirectory(dir3);
prefs.setComplexValue("lastDir", Ci.nsILocalFile, tmpDir);
MockFilePicker.returnFiles = [file1];
let file = launcherDialog.promptForSaveToFile(launcher, context, null, null, null);
do_check_true(!!file);
// file picker should start with browser.download.lastDir
do_check_eq(MockFilePicker.displayDirectory.path, tmpDir.path);
// browser.download.lastDir should be modified before entering the private browsing mode
do_check_eq(prefs.getComplexValue("lastDir", Ci.nsILocalFile).path, dir1.path);
// gDownloadLastDir should be usable outside of the private browsing mode
do_check_eq(gDownloadLastDir.file.path, dir1.path);
pb.privateBrowsingEnabled = true;
do_check_eq(prefs.getComplexValue("lastDir", Ci.nsILocalFile).path, dir1.path);
MockFilePicker.returnFiles = [file2];
MockFilePicker.displayDirectory = null;
file = launcherDialog.promptForSaveToFile(launcher, context, null, null, null);
do_check_true(!!file);
// file picker should start with browser.download.lastDir as set before entering the private browsing mode
do_check_eq(MockFilePicker.displayDirectory.path, dir1.path);
// browser.download.lastDir should not be modified inside the private browsing mode
do_check_eq(prefs.getComplexValue("lastDir", Ci.nsILocalFile).path, dir1.path);
// but gDownloadLastDir should be modified
do_check_eq(gDownloadLastDir.file.path, dir2.path);
pb.privateBrowsingEnabled = false;
// gDownloadLastDir should be cleared after leaving the private browsing mode
do_check_eq(gDownloadLastDir.file.path, dir1.path);
MockFilePicker.returnFiles = [file3];
MockFilePicker.displayDirectory = null;
file = launcherDialog.promptForSaveToFile(launcher, context, null, null, null);
do_check_true(!!file);
// file picker should start with browser.download.lastDir as set before entering the private browsing mode
do_check_eq(MockFilePicker.displayDirectory.path, dir1.path);
// browser.download.lastDir should be modified after leaving the private browsing mode
do_check_eq(prefs.getComplexValue("lastDir", Ci.nsILocalFile).path, dir3.path);
// gDownloadLastDir should be usable after leaving the private browsing mode
do_check_eq(gDownloadLastDir.file.path, dir3.path);
// cleanup
prefsService.clearUserPref("browser.privatebrowsing.keep_current_session");
[dir1, dir2, dir3].forEach(function(dir) dir.remove(true));
MockFilePicker.cleanup();
}

Просмотреть файл

@ -2,8 +2,11 @@
head = head_downloads.js
tail =
[test_DownloadLastDir.js]
[test_DownloadLastDirWithCPS.js]
[test_DownloadPaths.js]
[test_DownloadUtils.js]
[test_lowMinutes.js]
[test_privatebrowsing_downloadLastDir.js]
[test_syncedDownloadUtils.js]
[test_unspecified_arguments.js]