forked from mirrors/gecko-dev
Merge mozilla-central to inbound. a=merge CLOSED TREE
This commit is contained in:
commit
1cc1d33847
150 changed files with 3558 additions and 1133 deletions
|
|
@ -22,7 +22,6 @@ extensions/spellcheck/**
|
|||
extensions/universalchardet/**
|
||||
image/**
|
||||
layout/**
|
||||
modules/**
|
||||
netwerk/cookie/test/browser/**
|
||||
netwerk/test/browser/**
|
||||
netwerk/test/mochitests/**
|
||||
|
|
|
|||
|
|
@ -958,7 +958,7 @@ ROLE(NON_NATIVE_DOCUMENT,
|
|||
"non-native document",
|
||||
ATK_ROLE_DOCUMENT_FRAME,
|
||||
NSAccessibilityGroupRole,
|
||||
USE_ROLE_STRING,
|
||||
ROLE_SYSTEM_DOCUMENT,
|
||||
ROLE_SYSTEM_DOCUMENT,
|
||||
java::SessionAccessibility::CLASSNAME_VIEW,
|
||||
eNoNameRule)
|
||||
|
|
|
|||
|
|
@ -77,7 +77,8 @@ DocAccessibleWrap::get_accValue(VARIANT aVarChild, BSTR __RPC_FAR* aValue) {
|
|||
// If document is being used to create a widget, don't use the URL hack
|
||||
roles::Role role = Role();
|
||||
if (role != roles::DOCUMENT && role != roles::APPLICATION &&
|
||||
role != roles::DIALOG && role != roles::ALERT)
|
||||
role != roles::DIALOG && role != roles::ALERT &&
|
||||
role != roles::NON_NATIVE_DOCUMENT)
|
||||
return hr;
|
||||
|
||||
nsAutoString url;
|
||||
|
|
|
|||
|
|
@ -674,6 +674,10 @@ async function sanitizeOnShutdown(progress) {
|
|||
await Sanitizer.sanitize(itemsToClear, { progress });
|
||||
}
|
||||
|
||||
// Here is the list of principals with site data.
|
||||
progress.advancement = "get-principals";
|
||||
let principals = await getAllPrincipals(progress);
|
||||
|
||||
// Clear out QuotaManager storage for principals that have been marked as
|
||||
// session only. The cookie service has special logic that avoids writing
|
||||
// such cookies to disk, but QuotaManager always touches disk, so we need to
|
||||
|
|
@ -700,8 +704,8 @@ async function sanitizeOnShutdown(progress) {
|
|||
Ci.nsICookieService.ACCEPT_NORMALLY) == Ci.nsICookieService.ACCEPT_SESSION) {
|
||||
log("Session-only configuration detected");
|
||||
progress.advancement = "session-only";
|
||||
let principals = await getAllPrincipals(progress);
|
||||
await maybeSanitizeSessionPrincipals(progress, principals);
|
||||
return;
|
||||
}
|
||||
|
||||
progress.advancement = "session-permission";
|
||||
|
|
@ -721,8 +725,8 @@ async function sanitizeOnShutdown(progress) {
|
|||
log("Custom session cookie permission detected for: " + permission.principal.URI.spec);
|
||||
|
||||
// We use just the URI here, because permissions ignore OriginAttributes.
|
||||
let principals = await getAllPrincipals(progress, permission.principal.URI);
|
||||
await maybeSanitizeSessionPrincipals(progress, principals);
|
||||
let selectedPrincipals = extractMatchingPrincipals(principals, permission.principal.URI);
|
||||
await maybeSanitizeSessionPrincipals(progress, selectedPrincipals);
|
||||
}
|
||||
|
||||
if (Sanitizer.shouldSanitizeNewTabContainer) {
|
||||
|
|
@ -741,10 +745,8 @@ async function sanitizeOnShutdown(progress) {
|
|||
progress.advancement = "done";
|
||||
}
|
||||
|
||||
// Retrieve the list of nsIPrincipals with site data. If matchUri is not null,
|
||||
// it returns only the principals matching that URI, ignoring the
|
||||
// OriginAttributes.
|
||||
async function getAllPrincipals(progress, matchUri = null) {
|
||||
// Retrieve the list of nsIPrincipals with site data.
|
||||
async function getAllPrincipals(progress) {
|
||||
progress.step = "principals-quota-manager";
|
||||
let principals = await new Promise(resolve => {
|
||||
quotaManagerService.getUsage(request => {
|
||||
|
|
@ -759,11 +761,7 @@ async function getAllPrincipals(progress, matchUri = null) {
|
|||
for (let item of request.result) {
|
||||
let principal = Services.scriptSecurityManager.createCodebasePrincipalFromOrigin(item.origin);
|
||||
let uri = principal.URI;
|
||||
if (!isSupportedURI(uri)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!matchUri || Services.eTLD.hasRootDomain(matchUri.host, uri.host)) {
|
||||
if (isSupportedURI(uri)) {
|
||||
list.push(principal);
|
||||
}
|
||||
}
|
||||
|
|
@ -775,22 +773,17 @@ async function getAllPrincipals(progress, matchUri = null) {
|
|||
let serviceWorkers = serviceWorkerManager.getAllRegistrations();
|
||||
for (let i = 0; i < serviceWorkers.length; i++) {
|
||||
let sw = serviceWorkers.queryElementAt(i, Ci.nsIServiceWorkerRegistrationInfo);
|
||||
let uri = sw.principal.URI;
|
||||
// We don't need to check the scheme. SW are just exposed to http/https URLs.
|
||||
if (!matchUri || Services.eTLD.hasRootDomain(matchUri.host, uri.host)) {
|
||||
principals.push(sw.principal);
|
||||
}
|
||||
}
|
||||
|
||||
// Let's take the list of unique hosts+OA from cookies.
|
||||
progress.step = "principals-cookies";
|
||||
let enumerator = Services.cookies.enumerator;
|
||||
let hosts = new Set();
|
||||
for (let cookie of enumerator) {
|
||||
if (!matchUri || Services.eTLD.hasRootDomain(matchUri.host, cookie.rawHost)) {
|
||||
hosts.add(cookie.rawHost + ChromeUtils.originAttributesToSuffix(cookie.originAttributes));
|
||||
}
|
||||
}
|
||||
|
||||
progress.step = "principals-host-cookie";
|
||||
hosts.forEach(host => {
|
||||
|
|
@ -804,6 +797,13 @@ async function getAllPrincipals(progress, matchUri = null) {
|
|||
return principals;
|
||||
}
|
||||
|
||||
// Extracts the principals matching matchUri as root domain.
|
||||
function extractMatchingPrincipals(principals, matchUri) {
|
||||
return principals.filter(principal => {
|
||||
return Services.eTLD.hasRootDomain(matchUri.host, principal.URI.host);
|
||||
});
|
||||
}
|
||||
|
||||
// This method receives a list of principals and it checks if some of them or
|
||||
// some of their sub-domain need to be sanitize.
|
||||
async function maybeSanitizeSessionPrincipals(progress, principals) {
|
||||
|
|
|
|||
|
|
@ -3190,13 +3190,11 @@ nsresult Selection::NotifySelectionListeners() {
|
|||
if (newEditingHost && newEditingHost != focusedElement) {
|
||||
MOZ_ASSERT(!newEditingHost->IsInNativeAnonymousSubtree());
|
||||
// Note that don't steal focus from focused window if the window doesn't
|
||||
// have focus and if the window isn't focused window, shouldn't be
|
||||
// scrolled to the new focused element.
|
||||
uint32_t flags = nsIFocusManager::FLAG_NOSWITCHFRAME;
|
||||
if (focusedWindow != fm->GetFocusedWindow()) {
|
||||
flags |= nsIFocusManager::FLAG_NOSCROLL;
|
||||
}
|
||||
fm->SetFocus(newEditingHost, flags);
|
||||
// have focus. Additionally, although when an element gets focus, we
|
||||
// usually scroll to the element, but in this case, we shouldn't do it
|
||||
// because Chrome does not do so.
|
||||
fm->SetFocus(newEditingHost, nsIFocusManager::FLAG_NOSWITCHFRAME |
|
||||
nsIFocusManager::FLAG_NOSCROLL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5733,6 +5733,13 @@ bool CanvasRenderingContext2D::ShouldForceInactiveLayer(
|
|||
return !aManager->CanUseCanvasLayerForSize(GetSize());
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2D::SetWriteOnly() {
|
||||
mWriteOnly = true;
|
||||
if (mCanvasElement) {
|
||||
mCanvasElement->SetWriteOnly();
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(CanvasPath, AddRef)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(CanvasPath, Release)
|
||||
|
||||
|
|
|
|||
|
|
@ -1114,7 +1114,7 @@ class CanvasRenderingContext2D final : public nsICanvasRenderingContextInternal,
|
|||
friend class CanvasDrawObserver;
|
||||
friend class ImageBitmap;
|
||||
|
||||
void SetWriteOnly() { mWriteOnly = true; }
|
||||
void SetWriteOnly();
|
||||
|
||||
bool IsWriteOnly() const { return mWriteOnly; }
|
||||
|
||||
|
|
|
|||
|
|
@ -1283,7 +1283,7 @@ tags = suspend
|
|||
skip-if = toolkit == 'android' # bug 1346705
|
||||
tags = suspend
|
||||
[test_background_video_resume_after_end_show_last_frame.html]
|
||||
skip-if = toolkit == 'android' # bug 1346705
|
||||
skip-if = toolkit == 'android' || ( webrender && os == "linux") # bug 1346705, bug 1516043
|
||||
tags = suspend
|
||||
[test_background_video_suspend.html]
|
||||
skip-if = toolkit == 'android' # android(bug 1304480)
|
||||
|
|
|
|||
|
|
@ -1198,6 +1198,13 @@ void AudioContext::Unmute() const {
|
|||
}
|
||||
}
|
||||
|
||||
void AudioContext::SetParamMapForWorkletName(
|
||||
const nsAString& aName, AudioParamDescriptorMap* aParamMap) {
|
||||
MOZ_ASSERT(!mWorkletParamDescriptors.GetValue(aName));
|
||||
Unused << mWorkletParamDescriptors.Put(aName, std::move(*aParamMap),
|
||||
fallible);
|
||||
}
|
||||
|
||||
size_t AudioContext::SizeOfIncludingThis(
|
||||
mozilla::MallocSizeOf aMallocSizeOf) const {
|
||||
// AudioNodes are tracked separately because we do not want the AudioContext
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
#ifndef AudioContext_h_
|
||||
#define AudioContext_h_
|
||||
|
||||
#include "AudioParamDescriptorMap.h"
|
||||
#include "mozilla/dom/OfflineAudioContextBinding.h"
|
||||
#include "MediaBufferDecoder.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
|
|
@ -311,6 +312,14 @@ class AudioContext final : public DOMEventTargetHelper,
|
|||
|
||||
bool CheckClosed(ErrorResult& aRv);
|
||||
|
||||
// Steals from |aParamMap|
|
||||
void SetParamMapForWorkletName(const nsAString& aName,
|
||||
AudioParamDescriptorMap* aParamMap);
|
||||
const AudioParamDescriptorMap* GetParamMapForWorkletName(
|
||||
const nsAString& aName) {
|
||||
return mWorkletParamDescriptors.GetValue(aName);
|
||||
}
|
||||
|
||||
void Dispatch(already_AddRefed<nsIRunnable>&& aRunnable);
|
||||
|
||||
private:
|
||||
|
|
@ -371,6 +380,8 @@ class AudioContext final : public DOMEventTargetHelper,
|
|||
nsTHashtable<nsRefPtrHashKey<AudioNode>> mActiveNodes;
|
||||
// Raw (non-owning) references to all AudioNodes for this AudioContext.
|
||||
nsTHashtable<nsPtrHashKey<AudioNode>> mAllNodes;
|
||||
nsDataHashtable<nsStringHashKey, AudioParamDescriptorMap>
|
||||
mWorkletParamDescriptors;
|
||||
// Cache to avoid recomputing basic waveforms all the time.
|
||||
RefPtr<BasicWaveFormCache> mBasicWaveFormCache;
|
||||
// Number of channels passed in the OfflineAudioContext ctor.
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@
|
|||
|
||||
#include "AudioWorkletGlobalScope.h"
|
||||
|
||||
#include "AudioNodeEngine.h"
|
||||
#include "AudioNodeStream.h"
|
||||
#include "AudioWorkletImpl.h"
|
||||
#include "jsapi.h"
|
||||
#include "mozilla/dom/AudioWorkletGlobalScopeBinding.h"
|
||||
|
|
@ -186,10 +188,17 @@ void AudioWorkletGlobalScope::RegisterProcessor(JSContext* aCx,
|
|||
if (aRv.Failed()) {
|
||||
return;
|
||||
}
|
||||
// TODO: we don't have a proper mechanism to communicate with the
|
||||
// control thread currently. See
|
||||
// https://bugzilla.mozilla.org/show_bug.cgi?id=1473467#c3
|
||||
// and https://bugzilla.mozilla.org/show_bug.cgi?id=1492014
|
||||
|
||||
NS_DispatchToMainThread(NS_NewRunnableFunction(
|
||||
"AudioWorkletGlobalScope: parameter descriptors",
|
||||
[impl = mImpl, name = nsString(aName), map = std::move(map)]() mutable {
|
||||
AudioNode* destinationNode =
|
||||
impl->DestinationStream()->Engine()->NodeMainThread();
|
||||
if (!destinationNode) {
|
||||
return;
|
||||
}
|
||||
destinationNode->Context()->SetParamMapForWorkletName(name, &map);
|
||||
}));
|
||||
}
|
||||
|
||||
WorkletImpl* AudioWorkletGlobalScope::Impl() const { return mImpl; }
|
||||
|
|
|
|||
|
|
@ -29,6 +29,9 @@ class AudioWorkletImpl final : public WorkletImpl {
|
|||
|
||||
nsresult SendControlMessage(already_AddRefed<nsIRunnable> aRunnable) override;
|
||||
|
||||
// Any thread:
|
||||
AudioNodeStream* DestinationStream() { return mDestinationStream; }
|
||||
|
||||
protected:
|
||||
// Execution thread only.
|
||||
already_AddRefed<dom::WorkletGlobalScope> ConstructGlobalScope() override;
|
||||
|
|
|
|||
|
|
@ -48,6 +48,17 @@ AudioWorkletNode::AudioWorkletNode(AudioContext* aAudioContext,
|
|||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 2. If nodeName does not exists as a key in the BaseAudioContext’s node
|
||||
* name to parameter descriptor map, throw a NotSupportedError exception
|
||||
* and abort these steps.
|
||||
*/
|
||||
const AudioParamDescriptorMap* parameterDescriptors =
|
||||
aAudioContext.GetParamMapForWorkletName(aName);
|
||||
if (!parameterDescriptors) {
|
||||
aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RefPtr<AudioWorkletNode> audioWorkletNode =
|
||||
new AudioWorkletNode(&aAudioContext, aName);
|
||||
|
|
|
|||
|
|
@ -267,7 +267,7 @@ public:
|
|||
|
||||
cairo_font_face_t* GetCairoFontFace() const { return fFontFace; }
|
||||
|
||||
private:
|
||||
private:
|
||||
~SkCairoFTTypeface()
|
||||
{
|
||||
cairo_font_face_destroy(fFontFace);
|
||||
|
|
@ -283,7 +283,8 @@ private:
|
|||
};
|
||||
|
||||
static bool FindByCairoFontFace(SkTypeface* typeface, void* context) {
|
||||
return static_cast<SkCairoFTTypeface*>(typeface)->GetCairoFontFace() == static_cast<cairo_font_face_t*>(context);
|
||||
return static_cast<SkCairoFTTypeface*>(typeface)->GetCairoFontFace() ==
|
||||
static_cast<cairo_font_face_t*>(context);
|
||||
}
|
||||
|
||||
SkTypeface* SkCreateTypefaceFromCairoFTFontWithFontconfig(cairo_scaled_font_t* scaledFont, FcPattern* pattern)
|
||||
|
|
@ -292,7 +293,8 @@ SkTypeface* SkCreateTypefaceFromCairoFTFontWithFontconfig(cairo_scaled_font_t* s
|
|||
SkASSERT(cairo_font_face_status(fontFace) == CAIRO_STATUS_SUCCESS);
|
||||
SkASSERT(cairo_font_face_get_type(fontFace) == CAIRO_FONT_TYPE_FT);
|
||||
|
||||
SkTypeface* typeface = SkTypefaceCache::FindByProcAndRef(FindByCairoFontFace, fontFace);
|
||||
SkTypeface* typeface =
|
||||
SkTypefaceCache::FindByProcAndRef(FindByCairoFontFace, fontFace);
|
||||
if (!typeface) {
|
||||
typeface = new SkCairoFTTypeface(fontFace, pattern);
|
||||
SkTypefaceCache::Add(typeface);
|
||||
|
|
|
|||
1930
intl/l10n/FluentSyntax.jsm
Normal file
1930
intl/l10n/FluentSyntax.jsm
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -11,6 +11,10 @@ EXTRA_JS_MODULES += [
|
|||
'Localization.jsm',
|
||||
]
|
||||
|
||||
TESTING_JS_MODULES += [
|
||||
'FluentSyntax.jsm',
|
||||
]
|
||||
|
||||
XPIDL_SOURCES += [
|
||||
'mozIDOMLocalization.idl',
|
||||
]
|
||||
|
|
|
|||
|
|
@ -256,8 +256,8 @@ class CxxCodeGen(CodePrinter, Visitor):
|
|||
self.write(' = 0')
|
||||
|
||||
def visitMethodDefn(self, md):
|
||||
if md.decl.methodspec == MethodSpec.PURE:
|
||||
return
|
||||
# Method specifiers are for decls, not defns.
|
||||
assert md.decl.methodspec == MethodSpec.NONE
|
||||
|
||||
self.printdent()
|
||||
md.decl.accept(self)
|
||||
|
|
|
|||
|
|
@ -4827,16 +4827,22 @@ methodDefns."""
|
|||
|
||||
for i, stmt in enumerate(cls.stmts):
|
||||
if isinstance(stmt, MethodDefn) and not stmt.decl.force_inline:
|
||||
decl, defn = _splitMethodDefn(stmt, cls)
|
||||
decl, defn = _splitMethodDeclDefn(stmt, cls)
|
||||
cls.stmts[i] = StmtDecl(decl)
|
||||
if defn:
|
||||
defns.addstmts([defn, Whitespace.NL])
|
||||
|
||||
return cls, defns
|
||||
|
||||
|
||||
def _splitMethodDefn(md, cls):
|
||||
def _splitMethodDeclDefn(md, cls):
|
||||
# Pure methods have decls but no defns.
|
||||
if md.decl.methodspec == MethodSpec.PURE:
|
||||
return md.decl, None
|
||||
|
||||
saveddecl = deepcopy(md.decl)
|
||||
md.decl.cls = cls
|
||||
# Don't emit method specifiers on method defns.
|
||||
md.decl.methodspec = MethodSpec.NONE
|
||||
md.decl.warn_unused = False
|
||||
md.decl.only_for_definition = True
|
||||
|
|
|
|||
|
|
@ -7443,12 +7443,12 @@ gcstats::ZoneGCStats GCRuntime::scanZonesBeforeGC() {
|
|||
zoneStats.compartmentCount += zone->compartments().length();
|
||||
if (zone->canCollect()) {
|
||||
zoneStats.collectableZoneCount++;
|
||||
}
|
||||
if (zone->isGCScheduled()) {
|
||||
zoneStats.collectedZoneCount++;
|
||||
zoneStats.collectedCompartmentCount += zone->compartments().length();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return zoneStats;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -318,7 +318,7 @@ fuzzy-if(Android,0-3,0-50) fuzzy-if(skiaContent,0-1,0-133) == 273681-1.html 2736
|
|||
== 283686-2.html 283686-2-ref.html
|
||||
== 283686-3.html about:blank
|
||||
== 289384-1.xhtml 289384-ref.xhtml
|
||||
random-if(d2d) fuzzy-if(Android,0-8,0-1439) fuzzy-if(webrender,0-6,0-1124) HTTP == 289480.html#top 289480-ref.html # basically-verbatim acid2 test, HTTP for a 404 page -- bug 578114 for the d2d failures
|
||||
random-if(d2d) fuzzy-if(Android,0-8,0-1439) fuzzy-if(webrender,0-6,0-1124) skip-if(webrender&>kWidget) HTTP == 289480.html#top 289480-ref.html # basically-verbatim acid2 test, HTTP for a 404 page -- bug 578114 for the d2d failures
|
||||
== 290129-1.html 290129-1-ref.html
|
||||
== 291078-1.html 291078-1-ref.html
|
||||
== 291078-2.html 291078-2-ref.html
|
||||
|
|
|
|||
|
|
@ -1277,6 +1277,7 @@ void Channel::OnRtpPacket(const RtpPacketReceived& packet) {
|
|||
rtp_payload_registry_->GetPayloadTypeFrequency(header.payloadType);
|
||||
if (header.payload_type_frequency >= 0) {
|
||||
bool in_order = IsPacketInOrder(header);
|
||||
statistics_proxy_->OnSendCodecFrequencyChanged(header.payload_type_frequency);
|
||||
rtp_receive_statistics_->IncomingPacket(
|
||||
header, packet.size(), IsPacketRetransmitted(header, in_order));
|
||||
rtp_payload_registry_->SetIncomingPayloadType(header);
|
||||
|
|
|
|||
|
|
@ -133,7 +133,7 @@ class InfallibleAllocPolicy {
|
|||
return p;
|
||||
}
|
||||
|
||||
static void* calloc_(size_t aSize) {
|
||||
static void* calloc_(size_t aCount, size_t aSize) {
|
||||
void* p = gMallocTable.calloc(1, aSize);
|
||||
ExitOnFailure(p);
|
||||
return p;
|
||||
|
|
@ -1127,9 +1127,12 @@ static void* replace_calloc(size_t aCount, size_t aSize) {
|
|||
|
||||
Thread* t = Thread::Fetch();
|
||||
if (t->InterceptsAreBlocked()) {
|
||||
return InfallibleAllocPolicy::calloc_(aCount * aSize);
|
||||
return InfallibleAllocPolicy::calloc_(aCount, aSize);
|
||||
}
|
||||
|
||||
// |aCount * aSize| could overflow, but if that happens then
|
||||
// |gMallocTable.calloc()| will return nullptr and |AllocCallback()| will
|
||||
// return immediately without using the overflowed value.
|
||||
void* ptr = gMallocTable.calloc(aCount, aSize);
|
||||
AllocCallback(ptr, aCount * aSize, t);
|
||||
return ptr;
|
||||
|
|
|
|||
|
|
@ -195,7 +195,10 @@ public class LauncherActivity extends Activity {
|
|||
return;
|
||||
}
|
||||
final String deepLink = intent.getData().getHost();
|
||||
final String uid = intent.getData().getQueryParameter("uid").replaceAll("\\n", "");
|
||||
String uid = intent.getData().getQueryParameter("uid");
|
||||
if (uid != null) {
|
||||
uid = uid.replaceAll("\\n", "");
|
||||
}
|
||||
final String localUid = MmaDelegate.getDeviceId(LauncherActivity.this);
|
||||
final boolean isMmaDeepLink = uid != null && localUid != null && uid.equals(localUid);
|
||||
|
||||
|
|
|
|||
|
|
@ -21,18 +21,18 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1173171
|
|||
// __xhr(method, url, responseType__.
|
||||
// A simple async XMLHttpRequest call.
|
||||
// Returns a promise with the response.
|
||||
let xhr = function (method, url, responseType) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open(method, url, true);
|
||||
xhr.onload = function () {
|
||||
resolve(xhr.response);
|
||||
let xhr = function(method, url, responseType) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
let xhrInstance = new XMLHttpRequest();
|
||||
xhrInstance.open(method, url, true);
|
||||
xhrInstance.onload = function() {
|
||||
resolve(xhrInstance.response);
|
||||
};
|
||||
xhr.onerror = function() {
|
||||
xhrInstance.onerror = function() {
|
||||
resolve(null);
|
||||
};
|
||||
xhr.responseType = responseType;
|
||||
xhr.send();
|
||||
xhrInstance.responseType = responseType;
|
||||
xhrInstance.send();
|
||||
});
|
||||
};
|
||||
|
||||
|
|
@ -40,7 +40,6 @@ let jarURL = "jar:http://mochi.test:8888/tests/modules/libjar/test/mochitest/bug
|
|||
|
||||
// Test behavior when blocking is deactivated and activated.
|
||||
add_task(async function() {
|
||||
let shouldBlock = true;
|
||||
let response = await xhr("GET", jarURL, "document");
|
||||
is(response, null, "Remote jars should be blocked.");
|
||||
});
|
||||
|
|
|
|||
|
|
@ -4,15 +4,14 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
const {NetUtil} = ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
|
||||
|
||||
// Check that reading non existant inner jars results in the right error
|
||||
|
||||
add_task(async function() {
|
||||
var file = do_get_file("data/test_bug597702.zip");
|
||||
var ios = Cc["@mozilla.org/network/io-service;1"].
|
||||
getService(Ci.nsIIOService);
|
||||
var outerJarBase = "jar:" + ios.newFileURI(file).spec + "!/";
|
||||
var outerJarBase = "jar:" + Services.io.newFileURI(file).spec + "!/";
|
||||
var goodSpec = "jar:" + outerJarBase + "inner.jar!/hello#!/ignore%20this%20part";
|
||||
var goodChannel = NetUtil.newChannel({uri: goodSpec, loadUsingSystemPrincipal: true});
|
||||
var instr = goodChannel.open();
|
||||
|
|
@ -22,9 +21,7 @@ add_task(async function() {
|
|||
|
||||
add_task(async function() {
|
||||
var file = do_get_file("data/test_bug597702.zip");
|
||||
var ios = Cc["@mozilla.org/network/io-service;1"].
|
||||
getService(Ci.nsIIOService);
|
||||
var outerJarBase = "jar:" + ios.newFileURI(file).spec + "!/";
|
||||
var outerJarBase = "jar:" + Services.io.newFileURI(file).spec + "!/";
|
||||
var goodSpec = "jar:" + outerJarBase + "inner.jar!/hello?ignore%20this%20part!/";
|
||||
var goodChannel = NetUtil.newChannel({uri: goodSpec, loadUsingSystemPrincipal: true});
|
||||
var instr = goodChannel.open();
|
||||
|
|
@ -34,9 +31,7 @@ add_task(async function() {
|
|||
|
||||
add_task(async function() {
|
||||
var file = do_get_file("data/test_bug597702.zip");
|
||||
var ios = Cc["@mozilla.org/network/io-service;1"].
|
||||
getService(Ci.nsIIOService);
|
||||
var outerJarBase = "jar:" + ios.newFileURI(file).spec + "!/";
|
||||
var outerJarBase = "jar:" + Services.io.newFileURI(file).spec + "!/";
|
||||
var goodSpec = "jar:" + outerJarBase + "inner.jar!/hello?ignore#this!/part";
|
||||
var goodChannel = NetUtil.newChannel({uri: goodSpec, loadUsingSystemPrincipal: true});
|
||||
var instr = goodChannel.open();
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
// Regression test for bug 278262 - JAR URIs should resolve relative URIs in the base section.
|
||||
|
||||
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
const path = "data/test_bug333423.zip";
|
||||
|
||||
function test_relative_sub() {
|
||||
var ios = Cc["@mozilla.org/network/io-service;1"].
|
||||
getService(Ci.nsIIOService);
|
||||
|
||||
var ios = Services.io;
|
||||
var spec = "jar:" + ios.newFileURI(do_get_file(path)).spec + "!/";
|
||||
var base = ios.newURI(spec);
|
||||
var uri = ios.newURI("../modules/libjar", null, base);
|
||||
|
|
@ -18,9 +18,7 @@ function test_relative_sub() {
|
|||
}
|
||||
|
||||
function test_relative_base() {
|
||||
var ios = Cc["@mozilla.org/network/io-service;1"].
|
||||
getService(Ci.nsIIOService);
|
||||
|
||||
var ios = Services.io;
|
||||
var base = ios.newFileURI(do_get_file("data/empty"));
|
||||
var uri = ios.newURI("jar:../" + path + "!/", null, base);
|
||||
|
||||
|
|
|
|||
|
|
@ -14,6 +14,6 @@ function run_test() {
|
|||
createInstance(Ci.nsIZipReader);
|
||||
zipreader.open(file);
|
||||
zipreader.close();
|
||||
var entries = zipreader.findEntries('*.*');
|
||||
var entries = zipreader.findEntries("*.*");
|
||||
Assert.ok(!entries.hasMore()); // this shouldn't crash
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,12 @@
|
|||
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
const {NetUtil} = ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
|
||||
|
||||
// Regression test for bug 370103 - crash when passing a null listener to
|
||||
// nsIChannel.asyncOpen
|
||||
function run_test() {
|
||||
// Compose the jar: url
|
||||
var ioService = Cc["@mozilla.org/network/io-service;1"].
|
||||
getService(Ci.nsIIOService);
|
||||
var file = do_get_file("data/test_bug370103.jar");
|
||||
var url = ioService.newFileURI(file).spec;
|
||||
var url = Services.io.newFileURI(file).spec;
|
||||
url = "jar:" + url + "!/test_bug370103";
|
||||
|
||||
// Try opening channel with null listener
|
||||
|
|
@ -16,8 +15,7 @@ function run_test() {
|
|||
var exception = false;
|
||||
try {
|
||||
channel.asyncOpen(null);
|
||||
}
|
||||
catch(e) {
|
||||
} catch (e) {
|
||||
exception = true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ function run_test() {
|
|||
createInstance(Ci.nsIZipReader);
|
||||
zipReader.open(file);
|
||||
var entry = zipReader.getEntry(ENTRY_NAME);
|
||||
var diff = Math.abs(entry.lastModifiedTime - ENTRY_TIME.getTime()*1000);
|
||||
var diff = Math.abs(entry.lastModifiedTime - ENTRY_TIME.getTime() * 1000);
|
||||
zipReader.close();
|
||||
if (diff >= MAX_TIME_DIFF)
|
||||
do_throw(diff);
|
||||
|
|
|
|||
|
|
@ -1,18 +1,16 @@
|
|||
// Make sure we behave appropriately when asking for content-disposition
|
||||
|
||||
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
const {NetUtil} = ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
|
||||
|
||||
const path = "data/test_bug589292.zip";
|
||||
|
||||
function run_test() {
|
||||
var ios = Cc["@mozilla.org/network/io-service;1"].
|
||||
getService(Ci.nsIIOService);
|
||||
var spec = "jar:" + ios.newFileURI(do_get_file(path)).spec + "!/foo.txt";
|
||||
var spec = "jar:" + Services.io.newFileURI(do_get_file(path)).spec + "!/foo.txt";
|
||||
var channel = NetUtil.newChannel({uri: spec, loadUsingSystemPrincipal: true});
|
||||
instr = channel.open();
|
||||
var val;
|
||||
channel.open();
|
||||
try {
|
||||
val = channel.contentDisposition;
|
||||
channel.contentDisposition;
|
||||
Assert.ok(false, "The channel has content disposition?!");
|
||||
} catch (e) {
|
||||
// This is what we want to happen - there's no underlying channel, so no
|
||||
|
|
|
|||
|
|
@ -2,31 +2,29 @@
|
|||
* 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 {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
const {NetUtil} = ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
|
||||
|
||||
// Check that reading non existant inner jars results in the right error
|
||||
|
||||
function run_test() {
|
||||
var file = do_get_file("data/test_bug597702.zip");
|
||||
var ios = Cc["@mozilla.org/network/io-service;1"].
|
||||
getService(Ci.nsIIOService);
|
||||
var outerJarBase = "jar:" + ios.newFileURI(file).spec + "!/";
|
||||
var outerJarBase = "jar:" + Services.io.newFileURI(file).spec + "!/";
|
||||
var goodSpec = "jar:" + outerJarBase + "inner.jar!/hello";
|
||||
var badSpec = "jar:" + outerJarBase + "jar_that_isnt_in_the.jar!/hello";
|
||||
var goodChannel = NetUtil.newChannel({uri: goodSpec, loadUsingSystemPrincipal: true});
|
||||
var badChannel = NetUtil.newChannel({uri: badSpec, loadUsingSystemPrincipal: true});
|
||||
|
||||
try {
|
||||
instr = goodChannel.open();
|
||||
goodChannel.open();
|
||||
} catch (e) {
|
||||
do_throw("Failed to open file in inner jar");
|
||||
}
|
||||
|
||||
try {
|
||||
instr = badChannel.open();
|
||||
badChannel.open();
|
||||
do_throw("Failed to report that file doesn't exist");
|
||||
} catch (e) {
|
||||
Assert.ok(e.name == "NS_ERROR_FILE_NOT_FOUND");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,25 +2,23 @@
|
|||
* 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 {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
const {NetUtil} = ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
|
||||
|
||||
// Check that the zip cache can expire entries from nested jars
|
||||
var ios = Cc["@mozilla.org/network/io-service;1"].
|
||||
getService(Ci.nsIIOService);
|
||||
|
||||
function open_inner_zip(base, idx) {
|
||||
var spec = "jar:" + base + "inner" + idx + ".zip!/foo";
|
||||
var channel = NetUtil.newChannel({uri: spec, loadUsingSystemPrincipal: true});
|
||||
var stream = channel.open();
|
||||
channel.open();
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
var file = do_get_file("data/test_bug637286.zip");
|
||||
var outerJarBase = "jar:" + ios.newFileURI(file).spec + "!/";
|
||||
var outerJarBase = "jar:" + Services.io.newFileURI(file).spec + "!/";
|
||||
|
||||
for (var i = 0; i < 40; i++) {
|
||||
open_inner_zip(outerJarBase, i);
|
||||
gc();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,19 +2,18 @@
|
|||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
const {NetUtil} = ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
|
||||
|
||||
// Check that we don't crash on reading a directory entry signature
|
||||
var ios = Cc["@mozilla.org/network/io-service;1"].
|
||||
getService(Ci.nsIIOService);
|
||||
|
||||
function run_test() {
|
||||
var file = do_get_file("data/test_bug658093.zip");
|
||||
var spec = "jar:" + ios.newFileURI(file).spec + "!/0000";
|
||||
var spec = "jar:" + Services.io.newFileURI(file).spec + "!/0000";
|
||||
var channel = NetUtil.newChannel({uri: spec, loadUsingSystemPrincipal: true});
|
||||
var failed = false;
|
||||
try {
|
||||
var stream = channel.open();
|
||||
channel.open();
|
||||
} catch (e) {
|
||||
failed = true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,11 +12,11 @@ function run_test() {
|
|||
zipreader.open(file);
|
||||
|
||||
var failed = false;
|
||||
for (let entryPath of zipreader.findEntries('*')) {
|
||||
for (let entryPath of zipreader.findEntries("*")) {
|
||||
let entry = zipreader.getEntry(entryPath);
|
||||
if (!entry.isDirectory) {
|
||||
try {
|
||||
let inputStream = zipreader.getInputStream(entryPath);
|
||||
zipreader.getInputStream(entryPath);
|
||||
} catch (e) {
|
||||
failed = true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,8 +2,7 @@
|
|||
* 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 wrapInputStream(input)
|
||||
{
|
||||
function wrapInputStream(input) {
|
||||
var nsIScriptableInputStream = Ci.nsIScriptableInputStream;
|
||||
var factory = Cc["@mozilla.org/scriptableinputstream;1"];
|
||||
var wrapper = factory.createInstance(nsIScriptableInputStream);
|
||||
|
|
|
|||
|
|
@ -4,8 +4,7 @@
|
|||
* 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 wrapInputStream(input)
|
||||
{
|
||||
function wrapInputStream(input) {
|
||||
let nsIScriptableInputStream = Ci.nsIScriptableInputStream;
|
||||
let factory = Cc["@mozilla.org/scriptableinputstream;1"];
|
||||
let wrapper = factory.createInstance(nsIScriptableInputStream);
|
||||
|
|
@ -27,10 +26,10 @@ function run_test() {
|
|||
zipreader.test(null);
|
||||
return true;
|
||||
}
|
||||
Assert.ok(check_archive_crc())
|
||||
let entries = zipreader.findEntries(null);
|
||||
let stream = wrapInputStream(zipreader.getInputStream("modules/libjar/test/Makefile.in"))
|
||||
let dirstream= wrapInputStream(zipreader.getInputStream("modules/libjar/test/"))
|
||||
Assert.ok(check_archive_crc());
|
||||
zipreader.findEntries(null);
|
||||
let stream = wrapInputStream(zipreader.getInputStream("modules/libjar/test/Makefile.in"));
|
||||
let dirstream = wrapInputStream(zipreader.getInputStream("modules/libjar/test/"));
|
||||
zipreader.close();
|
||||
zipreader = null;
|
||||
Cu.forceGC();
|
||||
|
|
|
|||
|
|
@ -7,21 +7,14 @@
|
|||
*/
|
||||
|
||||
|
||||
const {classes: Cc,
|
||||
interfaces: Ci,
|
||||
results: Cr,
|
||||
utils: Cu,
|
||||
Constructor: ctor
|
||||
} = Components;
|
||||
const {Constructor: ctor} = Components;
|
||||
|
||||
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
const {NetUtil} = ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
|
||||
|
||||
const ios = Cc["@mozilla.org/network/io-service;1"].
|
||||
getService(Ci.nsIIOService);
|
||||
const dirSvc = Cc["@mozilla.org/file/directory_service;1"].
|
||||
getService(Ci.nsIProperties);
|
||||
const obs = Cc["@mozilla.org/observer-service;1"].
|
||||
getService(Ci.nsIObserverService);
|
||||
const ios = Services.io;
|
||||
const dirSvc = Services.dirsvc;
|
||||
const obs = Services.obs;
|
||||
|
||||
const nsIBinaryInputStream = ctor("@mozilla.org/binaryinputstream;1",
|
||||
"nsIBinaryInputStream",
|
||||
|
|
@ -40,33 +33,27 @@ Listener.prototype = {
|
|||
gotStartRequest: false,
|
||||
available: -1,
|
||||
gotStopRequest: false,
|
||||
QueryInterface: function(iid) {
|
||||
if (iid.equals(Ci.nsISupports) ||
|
||||
iid.equals(Ci.nsIRequestObserver))
|
||||
return this;
|
||||
throw Cr.NS_ERROR_NO_INTERFACE;
|
||||
},
|
||||
onDataAvailable: function(request, ctx, stream, offset, count) {
|
||||
QueryInterface: ChromeUtils.generateQI(["nsIRequestObserver"]),
|
||||
onDataAvailable(request, ctx, stream, offset, count) {
|
||||
try {
|
||||
this.available = stream.available();
|
||||
Assert.equal(this.available, count);
|
||||
// Need to consume stream to avoid assertion
|
||||
new nsIBinaryInputStream(stream).readBytes(count);
|
||||
}
|
||||
catch (ex) {
|
||||
} catch (ex) {
|
||||
do_throw(ex);
|
||||
}
|
||||
},
|
||||
onStartRequest: function(request, ctx) {
|
||||
onStartRequest(request, ctx) {
|
||||
this.gotStartRequest = true;
|
||||
},
|
||||
onStopRequest: function(request, ctx, status) {
|
||||
onStopRequest(request, ctx, status) {
|
||||
this.gotStopRequest = true;
|
||||
Assert.equal(status, 0);
|
||||
if (this._callback) {
|
||||
this._callback.call(null, this);
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -74,7 +61,7 @@ Listener.prototype = {
|
|||
*/
|
||||
function testAsync() {
|
||||
var uri = jarBase + "/inner40.zip";
|
||||
var chan = NetUtil.newChannel({uri: uri, loadUsingSystemPrincipal: true});
|
||||
var chan = NetUtil.newChannel({uri, loadUsingSystemPrincipal: true});
|
||||
Assert.ok(chan.contentLength < 0);
|
||||
chan.asyncOpen(new Listener(function(l) {
|
||||
Assert.ok(chan.contentLength > 0);
|
||||
|
|
@ -95,7 +82,7 @@ add_test(testAsync);
|
|||
*/
|
||||
function testZipEntry() {
|
||||
var uri = jarBase + "/inner40.zip";
|
||||
var chan = NetUtil.newChannel({uri: uri, loadUsingSystemPrincipal: true})
|
||||
var chan = NetUtil.newChannel({uri, loadUsingSystemPrincipal: true})
|
||||
.QueryInterface(Ci.nsIJARChannel);
|
||||
var entry = chan.zipEntry;
|
||||
Assert.ok(entry.CRC32 == 0x8b635486);
|
||||
|
|
@ -111,7 +98,7 @@ add_test(testZipEntry);
|
|||
*/
|
||||
add_test(function testSync() {
|
||||
var uri = jarBase + "/inner40.zip";
|
||||
var chan = NetUtil.newChannel({uri: uri, loadUsingSystemPrincipal: true});
|
||||
var chan = NetUtil.newChannel({uri, loadUsingSystemPrincipal: true});
|
||||
var stream = chan.open();
|
||||
Assert.ok(chan.contentLength > 0);
|
||||
Assert.equal(stream.available(), chan.contentLength);
|
||||
|
|
@ -127,7 +114,7 @@ add_test(function testSync() {
|
|||
*/
|
||||
add_test(function testSyncNested() {
|
||||
var uri = "jar:" + jarBase + "/inner40.zip!/foo";
|
||||
var chan = NetUtil.newChannel({uri: uri, loadUsingSystemPrincipal: true});
|
||||
var chan = NetUtil.newChannel({uri, loadUsingSystemPrincipal: true});
|
||||
var stream = chan.open();
|
||||
Assert.ok(chan.contentLength > 0);
|
||||
Assert.equal(stream.available(), chan.contentLength);
|
||||
|
|
@ -142,7 +129,7 @@ add_test(function testSyncNested() {
|
|||
*/
|
||||
add_test(function testAsyncNested(next) {
|
||||
var uri = "jar:" + jarBase + "/inner40.zip!/foo";
|
||||
var chan = NetUtil.newChannel({uri: uri, loadUsingSystemPrincipal: true});
|
||||
var chan = NetUtil.newChannel({uri, loadUsingSystemPrincipal: true});
|
||||
chan.asyncOpen(new Listener(function(l) {
|
||||
Assert.ok(chan.contentLength > 0);
|
||||
Assert.ok(l.gotStartRequest);
|
||||
|
|
@ -162,7 +149,7 @@ add_test(function testSyncCloseUnlocks() {
|
|||
copy.append(fileBase);
|
||||
file.copyTo(copy.parent, copy.leafName);
|
||||
var uri = "jar:" + ios.newFileURI(copy).spec + "!/inner40.zip";
|
||||
var chan = NetUtil.newChannel({uri: uri, loadUsingSystemPrincipal: true});
|
||||
var chan = NetUtil.newChannel({uri, loadUsingSystemPrincipal: true});
|
||||
var stream = chan.open();
|
||||
Assert.ok(chan.contentLength > 0);
|
||||
stream.close();
|
||||
|
|
@ -172,8 +159,7 @@ add_test(function testSyncCloseUnlocks() {
|
|||
|
||||
try {
|
||||
copy.remove(false);
|
||||
}
|
||||
catch (ex) {
|
||||
} catch (ex) {
|
||||
do_throw(ex);
|
||||
}
|
||||
|
||||
|
|
@ -190,9 +176,9 @@ add_test(function testAsyncCloseUnlocks() {
|
|||
file.copyTo(copy.parent, copy.leafName);
|
||||
|
||||
var uri = "jar:" + ios.newFileURI(copy).spec + "!/inner40.zip";
|
||||
var chan = NetUtil.newChannel({uri: uri, loadUsingSystemPrincipal: true});
|
||||
var chan = NetUtil.newChannel({uri, loadUsingSystemPrincipal: true});
|
||||
|
||||
chan.asyncOpen(new Listener(function (l) {
|
||||
chan.asyncOpen(new Listener(function(l) {
|
||||
Assert.ok(chan.contentLength > 0);
|
||||
|
||||
// Drop any jar caches
|
||||
|
|
@ -200,8 +186,7 @@ add_test(function testAsyncCloseUnlocks() {
|
|||
|
||||
try {
|
||||
copy.remove(false);
|
||||
}
|
||||
catch (ex) {
|
||||
} catch (ex) {
|
||||
do_throw(ex);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,8 +4,7 @@
|
|||
* 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 wrapInputStream(input)
|
||||
{
|
||||
function wrapInputStream(input) {
|
||||
var nsIScriptableInputStream = Ci.nsIScriptableInputStream;
|
||||
var factory = Cc["@mozilla.org/scriptableinputstream;1"];
|
||||
var wrapper = factory.createInstance(nsIScriptableInputStream);
|
||||
|
|
@ -26,10 +25,10 @@ function run_test() {
|
|||
zipreader.test(null);
|
||||
return true;
|
||||
}
|
||||
Assert.ok(check_archive_crc())
|
||||
var entries = zipreader.findEntries(null);
|
||||
var stream = wrapInputStream(zipreader.getInputStream("modules/libjar/test/Makefile.in"))
|
||||
var dirstream= wrapInputStream(zipreader.getInputStream("modules/libjar/test/"))
|
||||
Assert.ok(check_archive_crc());
|
||||
zipreader.findEntries(null);
|
||||
var stream = wrapInputStream(zipreader.getInputStream("modules/libjar/test/Makefile.in"));
|
||||
var dirstream = wrapInputStream(zipreader.getInputStream("modules/libjar/test/"));
|
||||
zipreader.close();
|
||||
zipreader = null;
|
||||
Cu.forceGC();
|
||||
|
|
|
|||
|
|
@ -1,20 +1,19 @@
|
|||
// Should report file not found on non-existent files
|
||||
|
||||
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
const {NetUtil} = ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
|
||||
const path = "data/test_bug333423.zip";
|
||||
|
||||
function run_test() {
|
||||
var ios = Cc["@mozilla.org/network/io-service;1"].
|
||||
getService(Ci.nsIIOService);
|
||||
var spec = "jar:" + ios.newFileURI(do_get_file(path)).spec + "!/";
|
||||
var spec = "jar:" + Services.io.newFileURI(do_get_file(path)).spec + "!/";
|
||||
var channel = NetUtil.newChannel({
|
||||
uri: spec + "file_that_isnt_in.archive",
|
||||
loadUsingSystemPrincipal: true
|
||||
loadUsingSystemPrincipal: true,
|
||||
});
|
||||
try {
|
||||
instr = channel.open();
|
||||
do_throw("Failed to report that file doesn't exist")
|
||||
channel.open();
|
||||
do_throw("Failed to report that file doesn't exist");
|
||||
} catch (e) {
|
||||
Assert.ok(e.name == "NS_ERROR_FILE_NOT_FOUND")
|
||||
Assert.ok(e.name == "NS_ERROR_FILE_NOT_FOUND");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
function run_test() {
|
||||
var dirService = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
|
||||
var tmpDir = dirService.get("TmpD", Ci.nsIFile);
|
||||
var tmpDir = Services.dirsvc.get("TmpD", Ci.nsIFile);
|
||||
|
||||
var zipfile = do_get_file("data/test_umlaute.zip");
|
||||
|
||||
|
|
|
|||
|
|
@ -5,20 +5,20 @@
|
|||
|
||||
const NS_ERROR_IN_PROGRESS = 2152398863;
|
||||
|
||||
const PR_RDONLY = 0x01
|
||||
const PR_WRONLY = 0x02
|
||||
const PR_RDWR = 0x04
|
||||
const PR_CREATE_FILE = 0x08
|
||||
const PR_APPEND = 0x10
|
||||
const PR_TRUNCATE = 0x20
|
||||
const PR_SYNC = 0x40
|
||||
const PR_EXCL = 0x80
|
||||
const PR_RDONLY = 0x01;
|
||||
const PR_WRONLY = 0x02;
|
||||
const PR_RDWR = 0x04;
|
||||
const PR_CREATE_FILE = 0x08;
|
||||
const PR_APPEND = 0x10;
|
||||
const PR_TRUNCATE = 0x20;
|
||||
const PR_SYNC = 0x40;
|
||||
const PR_EXCL = 0x80;
|
||||
|
||||
const ZIP_EOCDR_HEADER_SIZE = 22;
|
||||
const ZIP_FILE_HEADER_SIZE = 30;
|
||||
const ZIP_CDS_HEADER_SIZE = 46;
|
||||
const ZIP_METHOD_STORE = 0
|
||||
const ZIP_METHOD_DEFLATE = 8
|
||||
const ZIP_METHOD_STORE = 0;
|
||||
const ZIP_METHOD_DEFLATE = 8;
|
||||
const ZIP_EXTENDED_TIMESTAMP_SIZE = 9;
|
||||
|
||||
const PR_USEC_PER_MSEC = 1000;
|
||||
|
|
@ -27,8 +27,8 @@ const PR_MSEC_PER_SEC = 1000;
|
|||
|
||||
const DATA_DIR = "data/";
|
||||
|
||||
var ioSvc = Cc["@mozilla.org/network/io-service;1"]
|
||||
.getService(Ci.nsIIOService);
|
||||
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
var ioSvc = Services.io;
|
||||
|
||||
var ZipWriter = Components.Constructor("@mozilla.org/zipwriter;1",
|
||||
"nsIZipWriter");
|
||||
|
|
|
|||
|
|
@ -11,44 +11,40 @@ const time = 1199145600000; // Jan 1st 2008
|
|||
var TESTS = [
|
||||
{
|
||||
name: "test.txt",
|
||||
compression: Ci.nsIZipWriter.COMPRESSION_DEFAULT
|
||||
compression: Ci.nsIZipWriter.COMPRESSION_DEFAULT,
|
||||
},
|
||||
{
|
||||
name: "test.png",
|
||||
compression: Ci.nsIZipWriter.COMPRESSION_NONE
|
||||
}
|
||||
compression: Ci.nsIZipWriter.COMPRESSION_NONE,
|
||||
},
|
||||
];
|
||||
|
||||
function swap16(n)
|
||||
{
|
||||
function swap16(n) {
|
||||
return (((n >> 8) & 0xFF) << 0) |
|
||||
(((n >> 0) & 0xFF) << 8);
|
||||
}
|
||||
|
||||
function swap32(n)
|
||||
{
|
||||
function swap32(n) {
|
||||
return (((n >> 24) & 0xFF) << 0) |
|
||||
(((n >> 16) & 0xFF) << 8) |
|
||||
(((n >> 8) & 0xFF) << 16) |
|
||||
(((n >> 0) & 0xFF) << 24);
|
||||
}
|
||||
|
||||
function move_to_data(bis, offset)
|
||||
{
|
||||
function move_to_data(bis, offset) {
|
||||
bis.readBytes(18); // Move to compressed size
|
||||
var size = swap32(bis.read32());
|
||||
bis.readBytes(4);
|
||||
var file_len = swap16(bis.read16());
|
||||
var extra_len = swap16(bis.read16());
|
||||
var file = bis.readBytes(file_len);
|
||||
bis.readBytes(file_len);
|
||||
bis.readBytes(extra_len);
|
||||
offset += ZIP_FILE_HEADER_SIZE + file_len + extra_len;
|
||||
|
||||
return {offset: offset, size: size};
|
||||
return {offset, size};
|
||||
}
|
||||
|
||||
function test_alignment(align_size)
|
||||
{
|
||||
function test_alignment(align_size) {
|
||||
// Create zip for testing.
|
||||
zipW.open(tmpFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE);
|
||||
for (var i = 0; i < TESTS.length; i++) {
|
||||
|
|
@ -65,7 +61,7 @@ function test_alignment(align_size)
|
|||
|
||||
// Check data can be decompressed.
|
||||
var zipR = new ZipReader(tmpFile);
|
||||
var stream = Cc["@mozilla.org/scriptableinputstream;1"]
|
||||
stream = Cc["@mozilla.org/scriptableinputstream;1"]
|
||||
.createInstance(Ci.nsIScriptableInputStream);
|
||||
stream.init(zipR.getInputStream(FILENAME));
|
||||
var result = stream.read(DATA.length);
|
||||
|
|
@ -95,7 +91,7 @@ function test_alignment(align_size)
|
|||
|
||||
ret = move_to_data(bis, offset); // "test_data.txt"
|
||||
offset = ret.offset;
|
||||
var result = bis.readBytes(DATA.length);
|
||||
result = bis.readBytes(DATA.length);
|
||||
Assert.equal(result, DATA);
|
||||
Assert.equal(offset % align_size, 0);
|
||||
|
||||
|
|
@ -103,8 +99,7 @@ function test_alignment(align_size)
|
|||
bis.close();
|
||||
}
|
||||
|
||||
function run_test()
|
||||
{
|
||||
function run_test() {
|
||||
test_alignment(2);
|
||||
test_alignment(4);
|
||||
test_alignment(16);
|
||||
|
|
|
|||
|
|
@ -10,24 +10,22 @@ var TESTS = [
|
|||
{
|
||||
name: "test.txt",
|
||||
size: 232,
|
||||
crc: 0x0373ac26
|
||||
crc: 0x0373ac26,
|
||||
},
|
||||
{
|
||||
name: "test.png",
|
||||
size: 3402,
|
||||
crc: 0x504a5c30
|
||||
}
|
||||
crc: 0x504a5c30,
|
||||
},
|
||||
];
|
||||
|
||||
var size = 0;
|
||||
|
||||
var observer = {
|
||||
onStartRequest: function(request, context)
|
||||
{
|
||||
onStartRequest(request, context) {
|
||||
},
|
||||
|
||||
onStopRequest: function(request, context, status)
|
||||
{
|
||||
onStopRequest(request, context, status) {
|
||||
Assert.equal(status, Cr.NS_OK);
|
||||
|
||||
zipW.close();
|
||||
|
|
@ -57,47 +55,43 @@ var observer = {
|
|||
|
||||
zipR.close();
|
||||
do_test_finished();
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
var methods = {
|
||||
file: function method_file(entry, source)
|
||||
{
|
||||
file: function method_file(entry, source) {
|
||||
zipW.addEntryFile(entry, Ci.nsIZipWriter.COMPRESSION_NONE, source,
|
||||
true);
|
||||
},
|
||||
channel: function method_channel(entry, source)
|
||||
{
|
||||
channel: function method_channel(entry, source) {
|
||||
zipW.addEntryChannel(entry, source.lastModifiedTime * PR_MSEC_PER_SEC,
|
||||
Ci.nsIZipWriter.COMPRESSION_NONE,
|
||||
NetUtil.newChannel({
|
||||
uri: ioSvc.newFileURI(source),
|
||||
loadUsingSystemPrincipal: true
|
||||
loadUsingSystemPrincipal: true,
|
||||
}), true);
|
||||
},
|
||||
stream: function method_stream(entry, source)
|
||||
{
|
||||
stream: function method_stream(entry, source) {
|
||||
zipW.addEntryStream(entry, source.lastModifiedTime * PR_MSEC_PER_SEC,
|
||||
Ci.nsIZipWriter.COMPRESSION_NONE,
|
||||
NetUtil.newChannel({
|
||||
uri: ioSvc.newFileURI(source),
|
||||
loadUsingSystemPrincipal: true
|
||||
loadUsingSystemPrincipal: true,
|
||||
}).open(), true);
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
function run_test()
|
||||
{
|
||||
function run_test() {
|
||||
zipW.open(tmpFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE);
|
||||
|
||||
for (var i = 0; i < TESTS.length; i++) {
|
||||
var source = do_get_file(DATA_DIR+TESTS[i].name);
|
||||
var source = do_get_file(DATA_DIR + TESTS[i].name);
|
||||
for (let method in methods) {
|
||||
var entry = method + "/" + TESTS[i].name;
|
||||
methods[method](entry, source);
|
||||
size += ZIP_FILE_HEADER_SIZE + ZIP_CDS_HEADER_SIZE +
|
||||
(ZIP_EXTENDED_TIMESTAMP_SIZE * 2) +
|
||||
(entry.length*2) + TESTS[i].size;
|
||||
(entry.length * 2) + TESTS[i].size;
|
||||
}
|
||||
}
|
||||
do_test_pending();
|
||||
|
|
|
|||
|
|
@ -6,21 +6,18 @@
|
|||
const FILENAME = "missing.txt";
|
||||
|
||||
var observer = {
|
||||
onStartRequest: function(request, context)
|
||||
{
|
||||
onStartRequest(request, context) {
|
||||
},
|
||||
|
||||
onStopRequest: function(request, context, status)
|
||||
{
|
||||
onStopRequest(request, context, status) {
|
||||
Assert.equal(status, Cr.NS_ERROR_FILE_NOT_FOUND);
|
||||
zipW.close();
|
||||
Assert.equal(ZIP_EOCDR_HEADER_SIZE, tmpFile.fileSize);
|
||||
do_test_finished();
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
function run_test()
|
||||
{
|
||||
function run_test() {
|
||||
zipW.open(tmpFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE);
|
||||
|
||||
var source = tmpDir.clone();
|
||||
|
|
|
|||
|
|
@ -6,21 +6,18 @@
|
|||
const FILENAME = "missing.txt";
|
||||
|
||||
var observer = {
|
||||
onStartRequest: function(request, context)
|
||||
{
|
||||
onStartRequest(request, context) {
|
||||
},
|
||||
|
||||
onStopRequest: function(request, context, status)
|
||||
{
|
||||
onStopRequest(request, context, status) {
|
||||
Assert.equal(status, Cr.NS_ERROR_FILE_NOT_FOUND);
|
||||
zipW.close();
|
||||
Assert.equal(ZIP_EOCDR_HEADER_SIZE, tmpFile.fileSize);
|
||||
do_test_finished();
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
function run_test()
|
||||
{
|
||||
function run_test() {
|
||||
zipW.open(tmpFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE);
|
||||
zipW.removeEntry(FILENAME, true);
|
||||
do_test_pending();
|
||||
|
|
|
|||
|
|
@ -5,16 +5,14 @@
|
|||
|
||||
var TESTS = [
|
||||
"test.txt",
|
||||
"test.png"
|
||||
"test.png",
|
||||
];
|
||||
|
||||
var observer = {
|
||||
onStartRequest: function(request, context)
|
||||
{
|
||||
onStartRequest(request, context) {
|
||||
},
|
||||
|
||||
onStopRequest: function(request, context, status)
|
||||
{
|
||||
onStopRequest(request, context, status) {
|
||||
Assert.equal(status, Cr.NS_OK);
|
||||
|
||||
zipW.close();
|
||||
|
|
@ -23,11 +21,10 @@ var observer = {
|
|||
var newTmpFile = tmpFile.clone();
|
||||
Assert.equal(newTmpFile.fileSize, ZIP_EOCDR_HEADER_SIZE);
|
||||
do_test_finished();
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
function run_test()
|
||||
{
|
||||
function run_test() {
|
||||
// Copy our test zip to the tmp dir so we can modify it
|
||||
var testzip = do_get_file(DATA_DIR + "test.zip");
|
||||
testzip.copyTo(tmpDir, tmpFile.leafName);
|
||||
|
|
|
|||
|
|
@ -21,17 +21,17 @@ BinaryComparer.prototype = {
|
|||
length: null,
|
||||
callback: null,
|
||||
|
||||
onStartRequest: function(aRequest, aContext) {
|
||||
onStartRequest(aRequest, aContext) {
|
||||
},
|
||||
|
||||
onStopRequest: function(aRequest, aContext, aStatusCode) {
|
||||
onStopRequest(aRequest, aContext, aStatusCode) {
|
||||
this.fileStream.close();
|
||||
Assert.equal(aStatusCode, Cr.NS_OK);
|
||||
Assert.equal(this.offset, this.length);
|
||||
this.callback();
|
||||
},
|
||||
|
||||
onDataAvailable: function(aRequest, aContext, aInputStream, aOffset, aCount) {
|
||||
onDataAvailable(aRequest, aContext, aInputStream, aOffset, aCount) {
|
||||
var stream = Cc["@mozilla.org/binaryinputstream;1"].
|
||||
createInstance(Ci.nsIBinaryInputStream);
|
||||
stream.setInputStream(aInputStream);
|
||||
|
|
@ -39,30 +39,26 @@ BinaryComparer.prototype = {
|
|||
for (var i = 0; i < aCount; i++) {
|
||||
try {
|
||||
source = this.fileStream.read8();
|
||||
}
|
||||
catch (e) {
|
||||
} catch (e) {
|
||||
do_throw("Unable to read from file at offset " + this.offset + " " + e);
|
||||
}
|
||||
try {
|
||||
actual = stream.read8();
|
||||
}
|
||||
catch (e) {
|
||||
} catch (e) {
|
||||
do_throw("Unable to read from converted stream at offset " + this.offset + " " + e);
|
||||
}
|
||||
if (source != actual)
|
||||
do_throw("Invalid value " + actual + " at offset " + this.offset + ", should have been " + source);
|
||||
this.offset++;
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
function comparer_callback()
|
||||
{
|
||||
function comparer_callback() {
|
||||
do_test_finished();
|
||||
}
|
||||
|
||||
function run_test()
|
||||
{
|
||||
function run_test() {
|
||||
var source = do_get_file(DATA_DIR + "test_bug399727.html");
|
||||
var comparer = new BinaryComparer(do_get_file(DATA_DIR + "test_bug399727.zlib"),
|
||||
comparer_callback);
|
||||
|
|
|
|||
|
|
@ -9,8 +9,7 @@ const CRC = 0x00000000;
|
|||
// XXX Must use a constant time here away from DST changes. See bug 402434.
|
||||
const time = 1199145600000; // Jan 1st 2008
|
||||
|
||||
function testpass(source)
|
||||
{
|
||||
function testpass(source) {
|
||||
// Should exist.
|
||||
Assert.ok(source.hasEntry(FILENAME));
|
||||
|
||||
|
|
@ -31,8 +30,7 @@ function testpass(source)
|
|||
Assert.equal(entry.CRC32, CRC);
|
||||
}
|
||||
|
||||
function run_test()
|
||||
{
|
||||
function run_test() {
|
||||
zipW.open(tmpFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE);
|
||||
|
||||
// Shouldn't be there to start with.
|
||||
|
|
@ -59,7 +57,7 @@ function run_test()
|
|||
var zipR = new ZipReader(tmpFile);
|
||||
testpass(zipR);
|
||||
zipR.test(FILENAME);
|
||||
var stream = Cc["@mozilla.org/scriptableinputstream;1"]
|
||||
stream = Cc["@mozilla.org/scriptableinputstream;1"]
|
||||
.createInstance(Ci.nsIScriptableInputStream);
|
||||
stream.init(zipR.getInputStream(FILENAME));
|
||||
var result = stream.read(DATA.length);
|
||||
|
|
|
|||
|
|
@ -8,8 +8,7 @@ const FILENAME = "test.txt";
|
|||
const CRC = 0x00000000;
|
||||
const time = Date.now();
|
||||
|
||||
function testpass(source)
|
||||
{
|
||||
function testpass(source) {
|
||||
// Should exist.
|
||||
Assert.ok(source.hasEntry(FILENAME));
|
||||
|
||||
|
|
@ -28,8 +27,7 @@ function testpass(source)
|
|||
Assert.equal(entry.CRC32, CRC);
|
||||
}
|
||||
|
||||
function run_test()
|
||||
{
|
||||
function run_test() {
|
||||
zipW.open(tmpFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE);
|
||||
|
||||
// Shouldn't be there to start with.
|
||||
|
|
|
|||
|
|
@ -6,8 +6,7 @@
|
|||
const DIRNAME = "test/";
|
||||
const time = Date.now();
|
||||
|
||||
function run_test()
|
||||
{
|
||||
function run_test() {
|
||||
// Copy in the test file.
|
||||
var source = do_get_file("data/test.zip");
|
||||
source.copyTo(tmpFile.parent, tmpFile.leafName);
|
||||
|
|
|
|||
|
|
@ -3,71 +3,61 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
function run_test()
|
||||
{
|
||||
var test;
|
||||
function run_test() {
|
||||
// zipW is an uninitialised zipwriter at this point.
|
||||
try {
|
||||
test = zipW.file;
|
||||
zipW.file;
|
||||
do_throw("Should have thrown uninitialized error.");
|
||||
}
|
||||
catch (e) {
|
||||
} catch (e) {
|
||||
Assert.equal(e.result, Cr.NS_ERROR_NOT_INITIALIZED);
|
||||
}
|
||||
|
||||
try {
|
||||
test = zipW.comment;
|
||||
zipW.comment;
|
||||
do_throw("Should have thrown uninitialized error.");
|
||||
}
|
||||
catch (e) {
|
||||
} catch (e) {
|
||||
Assert.equal(e.result, Cr.NS_ERROR_NOT_INITIALIZED);
|
||||
}
|
||||
|
||||
try {
|
||||
zipW.comment = "test";
|
||||
do_throw("Should have thrown uninitialized error.");
|
||||
}
|
||||
catch (e) {
|
||||
} catch (e) {
|
||||
Assert.equal(e.result, Cr.NS_ERROR_NOT_INITIALIZED);
|
||||
}
|
||||
|
||||
try {
|
||||
zipW.addEntryDirectory("test", 0, false);
|
||||
do_throw("Should have thrown uninitialized error.");
|
||||
}
|
||||
catch (e) {
|
||||
} catch (e) {
|
||||
Assert.equal(e.result, Cr.NS_ERROR_NOT_INITIALIZED);
|
||||
}
|
||||
|
||||
try {
|
||||
zipW.addEntryFile("test", Ci.nsIZipWriter.COMPRESSION_DEFAULT, tmpDir, false);
|
||||
do_throw("Should have thrown uninitialized error.");
|
||||
}
|
||||
catch (e) {
|
||||
} catch (e) {
|
||||
Assert.equal(e.result, Cr.NS_ERROR_NOT_INITIALIZED);
|
||||
}
|
||||
|
||||
try {
|
||||
zipW.removeEntry("test", false);
|
||||
do_throw("Should have thrown uninitialized error.");
|
||||
}
|
||||
catch (e) {
|
||||
} catch (e) {
|
||||
Assert.equal(e.result, Cr.NS_ERROR_NOT_INITIALIZED);
|
||||
}
|
||||
|
||||
try {
|
||||
zipW.processQueue(null, null);
|
||||
do_throw("Should have thrown uninitialized error.");
|
||||
}
|
||||
catch (e) {
|
||||
} catch (e) {
|
||||
Assert.equal(e.result, Cr.NS_ERROR_NOT_INITIALIZED);
|
||||
}
|
||||
|
||||
try {
|
||||
zipW.close();
|
||||
do_throw("Should have thrown uninitialized error.");
|
||||
}
|
||||
catch (e) {
|
||||
} catch (e) {
|
||||
Assert.equal(e.result, Cr.NS_ERROR_NOT_INITIALIZED);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,7 @@ function run_test() {
|
|||
}
|
||||
|
||||
// Add |file| to the zip. |path| is the current path for the file.
|
||||
function AddToZip(zipWriter, path, file)
|
||||
{
|
||||
function AddToZip(zipWriter, path, file) {
|
||||
var currentPath = path + file.leafName;
|
||||
|
||||
if (file.isDirectory()) {
|
||||
|
|
@ -28,8 +27,7 @@ function AddToZip(zipWriter, path, file)
|
|||
// ...otherwise, we're done
|
||||
}
|
||||
|
||||
function RecursivelyZipDirectory(bundle)
|
||||
{
|
||||
function RecursivelyZipDirectory(bundle) {
|
||||
zipW.open(tmpFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE);
|
||||
AddToZip(zipW, "", bundle);
|
||||
zipW.close();
|
||||
|
|
|
|||
|
|
@ -3,8 +3,7 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
function run_test()
|
||||
{
|
||||
function run_test() {
|
||||
// In this test we try to open some files that aren't archives:
|
||||
// - An empty file, that is certainly not an archive.
|
||||
// - A file that couldn't be mistaken for archive, since it is too small.
|
||||
|
|
|
|||
|
|
@ -20,17 +20,17 @@ BinaryComparer.prototype = {
|
|||
length: null,
|
||||
callback: null,
|
||||
|
||||
onStartRequest: function(aRequest, aContext) {
|
||||
onStartRequest(aRequest, aContext) {
|
||||
},
|
||||
|
||||
onStopRequest: function(aRequest, aContext, aStatusCode) {
|
||||
onStopRequest(aRequest, aContext, aStatusCode) {
|
||||
this.fileStream.close();
|
||||
Assert.equal(aStatusCode, Cr.NS_OK);
|
||||
Assert.equal(this.offset, this.length);
|
||||
this.callback();
|
||||
},
|
||||
|
||||
onDataAvailable: function(aRequest, aContext, aInputStream, aOffset, aCount) {
|
||||
onDataAvailable(aRequest, aContext, aInputStream, aOffset, aCount) {
|
||||
var stream = Cc["@mozilla.org/binaryinputstream;1"].
|
||||
createInstance(Ci.nsIBinaryInputStream);
|
||||
stream.setInputStream(aInputStream);
|
||||
|
|
@ -38,37 +38,34 @@ BinaryComparer.prototype = {
|
|||
for (var i = 0; i < aCount; i++) {
|
||||
try {
|
||||
source = this.fileStream.read8();
|
||||
}
|
||||
catch (e) {
|
||||
} catch (e) {
|
||||
do_throw("Unable to read from file at offset " + this.offset + " " + e);
|
||||
}
|
||||
try {
|
||||
actual = stream.read8();
|
||||
}
|
||||
catch (e) {
|
||||
do_throw("Unable to read from converted stream at offset " + this.offset + " " + e);
|
||||
} catch (e) {
|
||||
do_throw("Unable to read from converted stream at offset " +
|
||||
this.offset + " " + e);
|
||||
}
|
||||
// The byte at offset 9 is the OS byte (see RFC 1952, section 2.3), which
|
||||
// can legitimately differ when the source is compressed on different
|
||||
// operating systems. The actual .gz for this test was created on a Unix
|
||||
// system, but we want the test to work correctly everywhere. So ignore
|
||||
// the byte at offset 9.
|
||||
if (this.offset == 9)
|
||||
;
|
||||
else if (source != actual)
|
||||
do_throw("Invalid value " + actual + " at offset " + this.offset + ", should have been " + source);
|
||||
if (this.offset != 9 && source != actual) {
|
||||
do_throw("Invalid value " + actual + " at offset " +
|
||||
this.offset + ", should have been " + source);
|
||||
}
|
||||
this.offset++;
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
function comparer_callback()
|
||||
{
|
||||
function comparer_callback() {
|
||||
do_test_finished();
|
||||
}
|
||||
|
||||
function run_test()
|
||||
{
|
||||
function run_test() {
|
||||
var source = do_get_file(DATA_DIR + "test_bug717061.html");
|
||||
var comparer = new BinaryComparer(do_get_file(DATA_DIR + "test_bug717061.gz"),
|
||||
comparer_callback);
|
||||
|
|
|
|||
|
|
@ -3,8 +3,7 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
function run_test()
|
||||
{
|
||||
function run_test() {
|
||||
zipW.open(tmpFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE);
|
||||
zipW.close();
|
||||
|
||||
|
|
|
|||
|
|
@ -9,8 +9,7 @@ const CRC = 0xe6164331;
|
|||
// XXX Must use a constant time here away from DST changes. See bug 402434.
|
||||
const time = 1199145600000; // Jan 1st 2008
|
||||
|
||||
function run_test()
|
||||
{
|
||||
function run_test() {
|
||||
zipW.open(tmpFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE);
|
||||
|
||||
// Shouldn't be there to start with.
|
||||
|
|
@ -42,7 +41,7 @@ function run_test()
|
|||
|
||||
zipR.test(FILENAME);
|
||||
|
||||
var stream = Cc["@mozilla.org/scriptableinputstream;1"]
|
||||
stream = Cc["@mozilla.org/scriptableinputstream;1"]
|
||||
.createInstance(Ci.nsIScriptableInputStream);
|
||||
stream.init(zipR.getInputStream(FILENAME));
|
||||
var result = stream.read(DATA.length);
|
||||
|
|
|
|||
|
|
@ -8,8 +8,7 @@ const DIRNAME1_CORRECT = "test/";
|
|||
const DIRNAME2 = "test2/";
|
||||
const time = Date.now();
|
||||
|
||||
function run_test()
|
||||
{
|
||||
function run_test() {
|
||||
zipW.open(tmpFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE);
|
||||
|
||||
zipW.addEntryDirectory(DIRNAME1, time * PR_USEC_PER_MSEC, false);
|
||||
|
|
|
|||
|
|
@ -9,19 +9,18 @@ var TESTS = [
|
|||
name: "test.txt",
|
||||
size: 232,
|
||||
crc: 0x0373ac26,
|
||||
time: Date.UTC(2007, 4, 1, 20, 44, 55)
|
||||
time: Date.UTC(2007, 4, 1, 20, 44, 55),
|
||||
},
|
||||
{
|
||||
name: "test.png",
|
||||
size: 3402,
|
||||
crc: 0x504a5c30,
|
||||
time: Date.UTC(2007, 4, 1, 20, 49, 39)
|
||||
}
|
||||
time: Date.UTC(2007, 4, 1, 20, 49, 39),
|
||||
},
|
||||
];
|
||||
var BADENTRY = "unknown.txt";
|
||||
|
||||
function run_test()
|
||||
{
|
||||
function run_test() {
|
||||
// Copy our test zip to the tmp dir so we can modify it
|
||||
var testzip = do_get_file(DATA_DIR + "test.zip");
|
||||
testzip.copyTo(tmpDir, tmpFile.leafName);
|
||||
|
|
@ -30,7 +29,7 @@ function run_test()
|
|||
|
||||
zipW.open(tmpFile, PR_RDWR);
|
||||
|
||||
for (var i = 0; i < TESTS.length; i++) {
|
||||
for (let i = 0; i < TESTS.length; i++) {
|
||||
Assert.ok(zipW.hasEntry(TESTS[i].name));
|
||||
var entry = zipW.getEntry(TESTS[i].name);
|
||||
Assert.ok(entry != null);
|
||||
|
|
@ -43,12 +42,11 @@ function run_test()
|
|||
try {
|
||||
zipW.removeEntry(BADENTRY, false);
|
||||
do_throw("shouldn't be able to remove an entry that doesn't exist");
|
||||
}
|
||||
catch (e) {
|
||||
} catch (e) {
|
||||
Assert.equal(e.result, Cr.NS_ERROR_FILE_NOT_FOUND);
|
||||
}
|
||||
|
||||
for (var i = 0; i < TESTS.length; i++) {
|
||||
for (let i = 0; i < TESTS.length; i++) {
|
||||
zipW.removeEntry(TESTS[i].name, false);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,8 +10,7 @@ const CRC = 0xe6164331;
|
|||
// XXX Must use a constant time here away from DST changes. See bug 402434.
|
||||
const time = 1199145600000; // Jan 1st 2008
|
||||
|
||||
function testpass(source)
|
||||
{
|
||||
function testpass(source) {
|
||||
// Should exist.
|
||||
Assert.ok(source.hasEntry(FILENAME));
|
||||
|
||||
|
|
@ -34,8 +33,7 @@ function testpass(source)
|
|||
Assert.equal(entry.CRC32, CRC);
|
||||
}
|
||||
|
||||
function run_test()
|
||||
{
|
||||
function run_test() {
|
||||
zipW.open(tmpFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE);
|
||||
|
||||
// Shouldn't be there to start with.
|
||||
|
|
@ -67,7 +65,7 @@ function run_test()
|
|||
var zipR = new ZipReader(tmpFile);
|
||||
testpass(zipR);
|
||||
zipR.test(FILENAME);
|
||||
var stream = Cc["@mozilla.org/scriptableinputstream;1"]
|
||||
stream = Cc["@mozilla.org/scriptableinputstream;1"]
|
||||
.createInstance(Ci.nsIScriptableInputStream);
|
||||
stream.init(zipR.getInputStream(FILENAME));
|
||||
var result = stream.read(DATA.length);
|
||||
|
|
|
|||
|
|
@ -8,27 +8,26 @@ var TESTS = [
|
|||
{
|
||||
name: "test.txt",
|
||||
size: 232,
|
||||
crc: 0x0373ac26
|
||||
crc: 0x0373ac26,
|
||||
},
|
||||
{
|
||||
name: "test.png",
|
||||
size: 3402,
|
||||
crc: 0x504a5c30
|
||||
}
|
||||
crc: 0x504a5c30,
|
||||
},
|
||||
];
|
||||
|
||||
function run_test()
|
||||
{
|
||||
function run_test() {
|
||||
zipW.open(tmpFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE);
|
||||
|
||||
var size = 0;
|
||||
for (var i = 0; i < TESTS.length; i++) {
|
||||
var source = do_get_file(DATA_DIR + TESTS[i].name);
|
||||
for (let i = 0; i < TESTS.length; i++) {
|
||||
let source = do_get_file(DATA_DIR + TESTS[i].name);
|
||||
zipW.addEntryFile(TESTS[i].name, Ci.nsIZipWriter.COMPRESSION_NONE, source,
|
||||
false);
|
||||
size += ZIP_FILE_HEADER_SIZE + ZIP_CDS_HEADER_SIZE +
|
||||
(ZIP_EXTENDED_TIMESTAMP_SIZE * 2) +
|
||||
(TESTS[i].name.length*2) + TESTS[i].size;
|
||||
(TESTS[i].name.length * 2) + TESTS[i].size;
|
||||
}
|
||||
|
||||
zipW.close();
|
||||
|
|
@ -39,8 +38,8 @@ function run_test()
|
|||
// Test the stored data with the zipreader
|
||||
var zipR = new ZipReader(tmpFile);
|
||||
|
||||
for (var i = 0; i < TESTS.length; i++) {
|
||||
var source = do_get_file(DATA_DIR + TESTS[i].name);
|
||||
for (let i = 0; i < TESTS.length; i++) {
|
||||
let source = do_get_file(DATA_DIR + TESTS[i].name);
|
||||
Assert.ok(zipR.hasEntry(TESTS[i].name));
|
||||
|
||||
var entry = zipR.getEntry(TESTS[i].name);
|
||||
|
|
|
|||
|
|
@ -6,31 +6,29 @@
|
|||
// Values taken from using zipinfo to list the test.zip contents
|
||||
var TESTS = [
|
||||
"test.txt",
|
||||
"test.png"
|
||||
"test.png",
|
||||
];
|
||||
|
||||
function run_test()
|
||||
{
|
||||
function run_test() {
|
||||
zipW.open(tmpFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE);
|
||||
|
||||
for (var i = 0; i < TESTS.length; i++) {
|
||||
var source = do_get_file(DATA_DIR + TESTS[i]);
|
||||
for (let i = 0; i < TESTS.length; i++) {
|
||||
let source = do_get_file(DATA_DIR + TESTS[i]);
|
||||
zipW.addEntryFile(TESTS[i], Ci.nsIZipWriter.COMPRESSION_NONE, source,
|
||||
false);
|
||||
}
|
||||
|
||||
try {
|
||||
var source = do_get_file(DATA_DIR + TESTS[0]);
|
||||
let source = do_get_file(DATA_DIR + TESTS[0]);
|
||||
zipW.addEntryFile(TESTS[0], Ci.nsIZipWriter.COMPRESSION_NONE, source,
|
||||
false);
|
||||
do_throw("Should not be able to add the same file twice");
|
||||
}
|
||||
catch (e) {
|
||||
} catch (e) {
|
||||
Assert.equal(e.result, Cr.NS_ERROR_FILE_ALREADY_EXISTS);
|
||||
}
|
||||
|
||||
// Remove all the tests and see if we are left with an empty zip
|
||||
for (var i = 0; i < TESTS.length; i++) {
|
||||
for (let i = 0; i < TESTS.length; i++) {
|
||||
zipW.removeEntry(TESTS[i], false);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,8 +6,7 @@
|
|||
const DATA = "ZIP WRITER TEST COMMENT";
|
||||
const DATA2 = "ANOTHER ONE";
|
||||
|
||||
function run_test()
|
||||
{
|
||||
function run_test() {
|
||||
zipW.open(tmpFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE);
|
||||
zipW.comment = DATA;
|
||||
zipW.close();
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ function build_tests() {
|
|||
for (let o = 0; o <= 7; o++) {
|
||||
TESTS[id] = {
|
||||
name: "test" + u + g + o,
|
||||
permission: (u << 6) + (g << 3) + o
|
||||
permission: (u << 6) + (g << 3) + o,
|
||||
};
|
||||
id++;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
function run_test() {
|
||||
|
||||
/**
|
||||
* Creates MAR from the passed files, compares it to the reference MAR.
|
||||
*
|
||||
|
|
@ -102,7 +101,7 @@ function run_test() {
|
|||
if (outMAR.exists()) {
|
||||
outMAR.remove(false);
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
// Run all the tests
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
function run_test() {
|
||||
|
||||
/**
|
||||
* Extracts a MAR and makes sure each file matches the reference files.
|
||||
*
|
||||
|
|
@ -137,7 +136,7 @@ function run_test() {
|
|||
if (outDir.exists()) {
|
||||
outDir.remove(true);
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
// Run all the tests
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
function run_test() {
|
||||
|
||||
/**
|
||||
* Signs a MAR file.
|
||||
*
|
||||
|
|
@ -568,7 +567,7 @@ function run_test() {
|
|||
},
|
||||
// Between each test make sure the out MAR does not exist.
|
||||
cleanup_per_test: function _cleanup_per_test() {
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
cleanup();
|
||||
|
|
|
|||
|
|
@ -2375,7 +2375,6 @@ pref("network.proxy.failover_timeout", 1800); // 30 minutes
|
|||
pref("network.online", true); //online/offline
|
||||
pref("network.cookie.thirdparty.sessionOnly", false);
|
||||
pref("network.cookie.thirdparty.nonsecureSessionOnly", false);
|
||||
pref("network.cookie.leave-secure-alone", true);
|
||||
pref("network.cookie.same-site.enabled", true); // Honor the SameSite cookie attribute
|
||||
|
||||
// Cookie lifetime policy. Possible values:
|
||||
|
|
|
|||
|
|
@ -4,8 +4,7 @@
|
|||
|
||||
const NS_APP_USER_PROFILE_50_DIR = "ProfD";
|
||||
|
||||
function do_check_throws(f, result, stack)
|
||||
{
|
||||
function do_check_throws(f, result, stack) {
|
||||
if (!stack)
|
||||
stack = Components.stack.caller;
|
||||
|
||||
|
|
@ -18,22 +17,16 @@ function do_check_throws(f, result, stack)
|
|||
ok(false, "expected result " + result + ", none thrown");
|
||||
}
|
||||
|
||||
var dirSvc = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
|
||||
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
// Register current test directory as provider for the profile directory.
|
||||
var provider = {
|
||||
getFile: function(prop, persistent) {
|
||||
getFile(prop, persistent) {
|
||||
persistent.value = true;
|
||||
if (prop == NS_APP_USER_PROFILE_50_DIR)
|
||||
return dirSvc.get("CurProcD", Ci.nsIFile);
|
||||
return Services.dirsvc.get("CurProcD", Ci.nsIFile);
|
||||
throw Components.Exception("Tried to get test directory '" + prop + "'", Cr.NS_ERROR_FAILURE);
|
||||
},
|
||||
QueryInterface: function(iid) {
|
||||
if (iid.equals(Ci.nsIDirectoryServiceProvider) ||
|
||||
iid.equals(Ci.nsISupports)) {
|
||||
return this;
|
||||
}
|
||||
throw Cr.NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
QueryInterface: ChromeUtils.generateQI(["nsIDirectoryServiceProvider"]),
|
||||
};
|
||||
dirSvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider);
|
||||
Services.dirsvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider);
|
||||
|
|
|
|||
|
|
@ -9,15 +9,13 @@ function run_test() {
|
|||
const FLOAT = 9.674;
|
||||
const FUDGE = 0.001;
|
||||
|
||||
let ps = Cc["@mozilla.org/preferences-service;1"]
|
||||
.getService(Ci.nsIPrefService);
|
||||
let prefs = ps.getDefaultBranch(null);
|
||||
let prefs = Services.prefs.getDefaultBranch(null);
|
||||
|
||||
/* Test with a non-default branch */
|
||||
prefs.setCharPref(FULL_PREF_NAME, FLOAT);
|
||||
let pb = ps.getBranch(BRANCH);
|
||||
let pb = Services.prefs.getBranch(BRANCH);
|
||||
|
||||
let floatPref = pb.getFloatPref(PREF_NAME);
|
||||
Assert.ok(FLOAT+FUDGE >= floatPref);
|
||||
Assert.ok(FLOAT-FUDGE <= floatPref);
|
||||
Assert.ok(FLOAT + FUDGE >= floatPref);
|
||||
Assert.ok(FLOAT - FUDGE <= floatPref);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,27 +6,20 @@
|
|||
function run_test() {
|
||||
const PREF_NAME = "testPref";
|
||||
|
||||
var prefs = Cc["@mozilla.org/preferences-service;1"]
|
||||
.getService(Ci.nsIPrefBranch);
|
||||
var observer = {
|
||||
QueryInterface: function QueryInterface(aIID) {
|
||||
if (aIID.equals(Ci.nsIObserver) ||
|
||||
aIID.equals(Ci.nsISupports))
|
||||
return this;
|
||||
throw Cr.NS_NOINTERFACE;
|
||||
},
|
||||
QueryInterface: ChromeUtils.generateQI(["nsIObserver"]),
|
||||
|
||||
observe: function observe(aSubject, aTopic, aState) {
|
||||
prefs.removeObserver(PREF_NAME, observer);
|
||||
}
|
||||
}
|
||||
prefs.addObserver(PREF_NAME, observer);
|
||||
Services.prefs.removeObserver(PREF_NAME, observer);
|
||||
},
|
||||
};
|
||||
Services.prefs.addObserver(PREF_NAME, observer);
|
||||
|
||||
prefs.setCharPref(PREF_NAME, "test0")
|
||||
Services.prefs.setCharPref(PREF_NAME, "test0");
|
||||
// This second call isn't needed on a clean profile: it makes sure
|
||||
// the observer gets called even if the pref already had the value
|
||||
// "test0" before this test.
|
||||
prefs.setCharPref(PREF_NAME, "test1")
|
||||
Services.prefs.setCharPref(PREF_NAME, "test1");
|
||||
|
||||
Assert.ok(true);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,10 +4,8 @@
|
|||
function run_test() {
|
||||
const PREF_NAME = "testPref";
|
||||
|
||||
var ps = Cc["@mozilla.org/preferences-service;1"]
|
||||
.getService(Ci.nsIPrefService);
|
||||
var prefs = ps.getDefaultBranch(null);
|
||||
var userprefs = ps.getBranch(null);
|
||||
var prefs = Services.prefs.getDefaultBranch(null);
|
||||
var userprefs = Services.prefs.getBranch(null);
|
||||
|
||||
prefs.setCharPref(PREF_NAME, "test0");
|
||||
prefs.lockPref(PREF_NAME);
|
||||
|
|
@ -16,11 +14,11 @@ function run_test() {
|
|||
|
||||
var file = do_get_profile();
|
||||
file.append("prefs.js");
|
||||
ps.savePrefFile(file);
|
||||
Services.prefs.savePrefFile(file);
|
||||
|
||||
prefs.unlockPref(PREF_NAME);
|
||||
prefs.setCharPref(PREF_NAME, "test1");
|
||||
ps.readUserPrefsFromFile(file);
|
||||
Services.prefs.readUserPrefsFromFile(file);
|
||||
|
||||
Assert.equal("test1", userprefs.getCharPref(PREF_NAME));
|
||||
Assert.equal(false, userprefs.prefHasUserValue(PREF_NAME));
|
||||
|
|
|
|||
|
|
@ -3,26 +3,15 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
function run_test() {
|
||||
var ps = Cc["@mozilla.org/preferences-service;1"].
|
||||
getService(Ci.nsIPrefService);
|
||||
|
||||
var pb = Cc["@mozilla.org/preferences-service;1"].
|
||||
getService(Ci.nsIPrefBranch);
|
||||
|
||||
var observer = {
|
||||
QueryInterface: function QueryInterface(aIID) {
|
||||
if (aIID.equals(Ci.nsIObserver) ||
|
||||
aIID.equals(Ci.nsISupports))
|
||||
return this;
|
||||
throw Cr.NS_NOINTERFACE;
|
||||
},
|
||||
QueryInterface: ChromeUtils.generateQI(["nsIObserver"]),
|
||||
|
||||
observe: function observe(aSubject, aTopic, aState) {
|
||||
// Don't do anything.
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
/* Set the same pref twice. This shouldn't leak. */
|
||||
pb.addObserver("UserPref.nonexistent.setIntPref", observer);
|
||||
pb.addObserver("UserPref.nonexistent.setIntPref", observer);
|
||||
Services.prefs.addObserver("UserPref.nonexistent.setIntPref", observer);
|
||||
Services.prefs.addObserver("UserPref.nonexistent.setIntPref", observer);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,10 +4,8 @@
|
|||
function run_test() {
|
||||
const PREF_NAME = "testPref";
|
||||
|
||||
var ps = Cc["@mozilla.org/preferences-service;1"]
|
||||
.getService(Ci.nsIPrefService);
|
||||
var prefs = ps.getDefaultBranch(null);
|
||||
var userprefs = ps.getBranch(null);
|
||||
var prefs = Services.prefs.getDefaultBranch(null);
|
||||
var userprefs = Services.prefs.getBranch(null);
|
||||
|
||||
/* First, test to make sure we can parse a float from a string properly. */
|
||||
prefs.setCharPref(PREF_NAME, "9.674");
|
||||
|
|
@ -15,8 +13,8 @@ function run_test() {
|
|||
var myFloat = 9.674;
|
||||
var fudge = 0.001;
|
||||
var floatPref = userprefs.getFloatPref(PREF_NAME);
|
||||
Assert.ok(myFloat+fudge >= floatPref);
|
||||
Assert.ok(myFloat-fudge <= floatPref);
|
||||
Assert.ok(myFloat + fudge >= floatPref);
|
||||
Assert.ok(myFloat - fudge <= floatPref);
|
||||
|
||||
/* Now test some failure conditions. */
|
||||
prefs.unlockPref(PREF_NAME);
|
||||
|
|
|
|||
|
|
@ -10,9 +10,7 @@ const PREF_INT = 64;
|
|||
const PREF_STRING = 32;
|
||||
|
||||
function run_test() {
|
||||
|
||||
var ps = Cc["@mozilla.org/preferences-service;1"].
|
||||
getService(Ci.nsIPrefService);
|
||||
var ps = Services.prefs;
|
||||
|
||||
let defaultBranch = ps.getDefaultBranch("");
|
||||
let userBranch = ps.getBranch("");
|
||||
|
|
@ -52,47 +50,65 @@ function run_test() {
|
|||
// We only have a default value, and we try to set a default value of a
|
||||
// different type --> fails.
|
||||
do_check_throws(function() {
|
||||
defaultBranch.setCharPref("TypeTest.default.bool", "boo"); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
defaultBranch.setCharPref("TypeTest.default.bool", "boo");
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
defaultBranch.setIntPref("TypeTest.default.bool", 5); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
defaultBranch.setIntPref("TypeTest.default.bool", 5);
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
defaultBranch.setCharPref("TypeTest.default.int", "boo"); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
defaultBranch.setCharPref("TypeTest.default.int", "boo");
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
defaultBranch.setBoolPref("TypeTest.default.int", true); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
defaultBranch.setBoolPref("TypeTest.default.int", true);
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
defaultBranch.setBoolPref("TypeTest.default.char", true); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
defaultBranch.setBoolPref("TypeTest.default.char", true);
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
defaultBranch.setIntPref("TypeTest.default.char", 6); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
defaultBranch.setIntPref("TypeTest.default.char", 6);
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
|
||||
// We only have a default value, and we try to set a user value of a
|
||||
// different type --> fails.
|
||||
do_check_throws(function() {
|
||||
userBranch.setCharPref("TypeTest.default.bool", "boo"); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
userBranch.setCharPref("TypeTest.default.bool", "boo");
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
userBranch.setIntPref("TypeTest.default.bool", 5); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
userBranch.setIntPref("TypeTest.default.bool", 5);
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
userBranch.setCharPref("TypeTest.default.int", "boo"); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
userBranch.setCharPref("TypeTest.default.int", "boo");
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
userBranch.setBoolPref("TypeTest.default.int", true); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
userBranch.setBoolPref("TypeTest.default.int", true);
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
userBranch.setBoolPref("TypeTest.default.char", true); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
userBranch.setBoolPref("TypeTest.default.char", true);
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
userBranch.setIntPref("TypeTest.default.char", 6); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
userBranch.setIntPref("TypeTest.default.char", 6);
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
|
||||
// We only have a user value, and we try to set a default value of a
|
||||
// different type --> fails.
|
||||
do_check_throws(function() {
|
||||
defaultBranch.setCharPref("TypeTest.user.bool", "boo"); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
defaultBranch.setCharPref("TypeTest.user.bool", "boo");
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
defaultBranch.setIntPref("TypeTest.user.bool", 5); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
defaultBranch.setIntPref("TypeTest.user.bool", 5);
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
defaultBranch.setCharPref("TypeTest.user.int", "boo"); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
defaultBranch.setCharPref("TypeTest.user.int", "boo");
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
defaultBranch.setBoolPref("TypeTest.user.int", true); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
defaultBranch.setBoolPref("TypeTest.user.int", true);
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
defaultBranch.setBoolPref("TypeTest.user.char", true); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
defaultBranch.setBoolPref("TypeTest.user.char", true);
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
defaultBranch.setIntPref("TypeTest.user.char", 6); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
defaultBranch.setIntPref("TypeTest.user.char", 6);
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
|
||||
// We only have a user value, and we try to set a user value of a
|
||||
// different type --> SUCCEEDS.
|
||||
|
|
@ -112,30 +128,42 @@ function run_test() {
|
|||
// We have both a default value and user value, and we try to set a default
|
||||
// value of a different type --> fails.
|
||||
do_check_throws(function() {
|
||||
defaultBranch.setCharPref("TypeTest.both.bool", "boo"); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
defaultBranch.setCharPref("TypeTest.both.bool", "boo");
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
defaultBranch.setIntPref("TypeTest.both.bool", 5); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
defaultBranch.setIntPref("TypeTest.both.bool", 5);
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
defaultBranch.setCharPref("TypeTest.both.int", "boo"); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
defaultBranch.setCharPref("TypeTest.both.int", "boo");
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
defaultBranch.setBoolPref("TypeTest.both.int", true); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
defaultBranch.setBoolPref("TypeTest.both.int", true);
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
defaultBranch.setBoolPref("TypeTest.both.char", true); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
defaultBranch.setBoolPref("TypeTest.both.char", true);
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
defaultBranch.setIntPref("TypeTest.both.char", 6); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
defaultBranch.setIntPref("TypeTest.both.char", 6);
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
|
||||
// We have both a default value and user value, and we try to set a user
|
||||
// value of a different type --> fails.
|
||||
do_check_throws(function() {
|
||||
userBranch.setCharPref("TypeTest.both.bool", "boo"); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
userBranch.setCharPref("TypeTest.both.bool", "boo");
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
userBranch.setIntPref("TypeTest.both.bool", 5); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
userBranch.setIntPref("TypeTest.both.bool", 5);
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
userBranch.setCharPref("TypeTest.both.int", "boo"); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
userBranch.setCharPref("TypeTest.both.int", "boo");
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
userBranch.setBoolPref("TypeTest.both.int", true); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
userBranch.setBoolPref("TypeTest.both.int", true);
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
userBranch.setBoolPref("TypeTest.both.char", true); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
userBranch.setBoolPref("TypeTest.both.char", true);
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
userBranch.setIntPref("TypeTest.both.char", 6); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
userBranch.setIntPref("TypeTest.both.char", 6);
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,10 +5,7 @@
|
|||
/* Tests for providing a default value to get{Bool,Char,Float,Int}Pref */
|
||||
|
||||
function run_test() {
|
||||
var ps = Cc["@mozilla.org/preferences-service;1"]
|
||||
.getService(Ci.nsIPrefService)
|
||||
.QueryInterface(Ci.nsIPrefBranch);
|
||||
|
||||
const ps = Services.prefs;
|
||||
let prefName = "test.default.values.bool";
|
||||
do_check_throws(function() { ps.getBoolPref(prefName); },
|
||||
Cr.NS_ERROR_UNEXPECTED);
|
||||
|
|
|
|||
|
|
@ -10,9 +10,7 @@ const PREF_INT = 64;
|
|||
const PREF_STRING = 32;
|
||||
|
||||
function run_test() {
|
||||
|
||||
var ps = Cc["@mozilla.org/preferences-service;1"].
|
||||
getService(Ci.nsIPrefService);
|
||||
const ps = Services.prefs;
|
||||
|
||||
let defaultBranch = ps.getDefaultBranch("");
|
||||
let userBranch = ps.getBranch("");
|
||||
|
|
@ -20,7 +18,7 @@ function run_test() {
|
|||
let prefFile = do_get_profile();
|
||||
prefFile.append("prefs.js");
|
||||
|
||||
//**************************************************************************//
|
||||
//* *************************************************************************//
|
||||
// prefs are not dirty after a write
|
||||
ps.savePrefFile(null);
|
||||
Assert.ok(!ps.dirty);
|
||||
|
|
@ -58,7 +56,8 @@ function run_test() {
|
|||
Assert.ok(!ps.dirty);
|
||||
// Fail to change type of a pref with default value -> not dirty
|
||||
do_check_throws(function() {
|
||||
userBranch.setCharPref("DirtyTest.existing.bool", "boo"); }, Cr.NS_ERROR_UNEXPECTED);
|
||||
userBranch.setCharPref("DirtyTest.existing.bool", "boo");
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
Assert.ok(!ps.dirty);
|
||||
|
||||
// Set user value same as default, not dirty
|
||||
|
|
|
|||
|
|
@ -9,153 +9,163 @@ const PREF_STRING = 32;
|
|||
|
||||
const MAX_PREF_LENGTH = 1 * 1024 * 1024;
|
||||
|
||||
function makeList(a)
|
||||
{
|
||||
function makeList(a) {
|
||||
var o = {};
|
||||
for(var i=0; i<a.length; i++)
|
||||
{
|
||||
o[a[i]] = '';
|
||||
for (var i = 0; i < a.length; i++) {
|
||||
o[a[i]] = "";
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
const ps = Services.prefs;
|
||||
|
||||
var ps = Cc["@mozilla.org/preferences-service;1"].
|
||||
getService(Ci.nsIPrefService);
|
||||
|
||||
var pb2= Cc["@mozilla.org/preferences-service;1"].
|
||||
getService(Ci.nsIPrefBranch);
|
||||
|
||||
var pb = Cc["@mozilla.org/preferences-service;1"].
|
||||
getService(Ci.nsIPrefBranch);
|
||||
|
||||
//**************************************************************************//
|
||||
//* *************************************************************************//
|
||||
// Nullsafety
|
||||
|
||||
do_check_throws(function() {
|
||||
pb.getPrefType(null); }, Cr.NS_ERROR_INVALID_ARG);
|
||||
ps.getPrefType(null);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
do_check_throws(function() {
|
||||
pb.getBoolPref(null); }, Cr.NS_ERROR_INVALID_ARG);
|
||||
ps.getBoolPref(null);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
do_check_throws(function() {
|
||||
pb.setBoolPref(null, false); }, Cr.NS_ERROR_INVALID_ARG);
|
||||
ps.setBoolPref(null, false);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
do_check_throws(function() {
|
||||
pb.getIntPref(null); }, Cr.NS_ERROR_INVALID_ARG);
|
||||
ps.getIntPref(null);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
do_check_throws(function() {
|
||||
pb.setIntPref(null, 0); }, Cr.NS_ERROR_INVALID_ARG);
|
||||
ps.setIntPref(null, 0);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
do_check_throws(function() {
|
||||
pb.getCharPref(null); }, Cr.NS_ERROR_INVALID_ARG);
|
||||
ps.getCharPref(null);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
do_check_throws(function() {
|
||||
pb.setCharPref(null, null); }, Cr.NS_ERROR_INVALID_ARG);
|
||||
ps.setCharPref(null, null);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
do_check_throws(function() {
|
||||
pb.getStringPref(null); }, Cr.NS_ERROR_INVALID_ARG);
|
||||
ps.getStringPref(null);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
do_check_throws(function() {
|
||||
pb.setStringPref(null, null); }, Cr.NS_ERROR_INVALID_ARG);
|
||||
ps.setStringPref(null, null);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
do_check_throws(function() {
|
||||
pb.clearUserPref(null); }, Cr.NS_ERROR_INVALID_ARG);
|
||||
ps.clearUserPref(null);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
do_check_throws(function() {
|
||||
pb.prefHasUserValue(null); }, Cr.NS_ERROR_INVALID_ARG);
|
||||
ps.prefHasUserValue(null);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
do_check_throws(function() {
|
||||
pb.lockPref(null); }, Cr.NS_ERROR_INVALID_ARG);
|
||||
ps.lockPref(null);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
do_check_throws(function() {
|
||||
pb.prefIsLocked(null); }, Cr.NS_ERROR_INVALID_ARG);
|
||||
ps.prefIsLocked(null);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
do_check_throws(function() {
|
||||
pb.unlockPref(null); }, Cr.NS_ERROR_INVALID_ARG);
|
||||
ps.unlockPref(null);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
do_check_throws(function() {
|
||||
pb.deleteBranch(null); }, Cr.NS_ERROR_INVALID_ARG);
|
||||
ps.deleteBranch(null);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
do_check_throws(function() {
|
||||
pb.getChildList(null); }, Cr.NS_ERROR_INVALID_ARG);
|
||||
ps.getChildList(null);
|
||||
}, Cr.NS_ERROR_INVALID_ARG);
|
||||
|
||||
//**************************************************************************//
|
||||
//* *************************************************************************//
|
||||
// Nonexisting user preferences
|
||||
|
||||
Assert.equal(pb.prefHasUserValue("UserPref.nonexistent.hasUserValue"), false);
|
||||
pb.clearUserPref("UserPref.nonexistent.clearUserPref"); // shouldn't throw
|
||||
Assert.equal(pb.getPrefType("UserPref.nonexistent.getPrefType"), PREF_INVALID);
|
||||
Assert.equal(pb.root, "");
|
||||
Assert.equal(ps.prefHasUserValue("UserPref.nonexistent.hasUserValue"), false);
|
||||
ps.clearUserPref("UserPref.nonexistent.clearUserPref"); // shouldn't throw
|
||||
Assert.equal(ps.getPrefType("UserPref.nonexistent.getPrefType"), PREF_INVALID);
|
||||
Assert.equal(ps.root, "");
|
||||
|
||||
// bool...
|
||||
do_check_throws(function() {
|
||||
pb.getBoolPref("UserPref.nonexistent.getBoolPref");}, Cr.NS_ERROR_UNEXPECTED);
|
||||
pb.setBoolPref("UserPref.nonexistent.setBoolPref", false);
|
||||
Assert.equal(pb.getBoolPref("UserPref.nonexistent.setBoolPref"), false);
|
||||
ps.getBoolPref("UserPref.nonexistent.getBoolPref");
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
ps.setBoolPref("UserPref.nonexistent.setBoolPref", false);
|
||||
Assert.equal(ps.getBoolPref("UserPref.nonexistent.setBoolPref"), false);
|
||||
|
||||
// int...
|
||||
do_check_throws(function() {
|
||||
pb.getIntPref("UserPref.nonexistent.getIntPref");}, Cr.NS_ERROR_UNEXPECTED);
|
||||
pb.setIntPref("UserPref.nonexistent.setIntPref", 5);
|
||||
Assert.equal(pb.getIntPref("UserPref.nonexistent.setIntPref"), 5);
|
||||
ps.getIntPref("UserPref.nonexistent.getIntPref");
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
ps.setIntPref("UserPref.nonexistent.setIntPref", 5);
|
||||
Assert.equal(ps.getIntPref("UserPref.nonexistent.setIntPref"), 5);
|
||||
|
||||
// char
|
||||
do_check_throws(function() {
|
||||
pb.getCharPref("UserPref.nonexistent.getCharPref");}, Cr.NS_ERROR_UNEXPECTED);
|
||||
pb.setCharPref("UserPref.nonexistent.setCharPref", "_test");
|
||||
Assert.equal(pb.getCharPref("UserPref.nonexistent.setCharPref"), "_test");
|
||||
ps.getCharPref("UserPref.nonexistent.getCharPref");
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
ps.setCharPref("UserPref.nonexistent.setCharPref", "_test");
|
||||
Assert.equal(ps.getCharPref("UserPref.nonexistent.setCharPref"), "_test");
|
||||
|
||||
//**************************************************************************//
|
||||
//* *************************************************************************//
|
||||
// Existing user Prefs and data integrity test (round-trip match)
|
||||
|
||||
pb.setBoolPref("UserPref.existing.bool", true);
|
||||
pb.setIntPref("UserPref.existing.int", 23);
|
||||
pb.setCharPref("UserPref.existing.char", "hey");
|
||||
ps.setBoolPref("UserPref.existing.bool", true);
|
||||
ps.setIntPref("UserPref.existing.int", 23);
|
||||
ps.setCharPref("UserPref.existing.char", "hey");
|
||||
|
||||
// getPref should return the pref value
|
||||
Assert.equal(pb.getBoolPref("UserPref.existing.bool"), true);
|
||||
Assert.equal(pb.getIntPref("UserPref.existing.int"), 23);
|
||||
Assert.equal(pb.getCharPref("UserPref.existing.char"), "hey");
|
||||
Assert.equal(ps.getBoolPref("UserPref.existing.bool"), true);
|
||||
Assert.equal(ps.getIntPref("UserPref.existing.int"), 23);
|
||||
Assert.equal(ps.getCharPref("UserPref.existing.char"), "hey");
|
||||
|
||||
// setPref should not complain and should change the value of the pref
|
||||
pb.setBoolPref("UserPref.existing.bool", false);
|
||||
Assert.equal(pb.getBoolPref("UserPref.existing.bool"), false);
|
||||
pb.setIntPref("UserPref.existing.int", 24);
|
||||
Assert.equal(pb.getIntPref("UserPref.existing.int"), 24);
|
||||
pb.setCharPref("UserPref.existing.char", "hej då!");
|
||||
Assert.equal(pb.getCharPref("UserPref.existing.char"), "hej då!");
|
||||
ps.setBoolPref("UserPref.existing.bool", false);
|
||||
Assert.equal(ps.getBoolPref("UserPref.existing.bool"), false);
|
||||
ps.setIntPref("UserPref.existing.int", 24);
|
||||
Assert.equal(ps.getIntPref("UserPref.existing.int"), 24);
|
||||
ps.setCharPref("UserPref.existing.char", "hej då!");
|
||||
Assert.equal(ps.getCharPref("UserPref.existing.char"), "hej då!");
|
||||
|
||||
// prefHasUserValue should return true now
|
||||
Assert.ok(pb.prefHasUserValue("UserPref.existing.bool"));
|
||||
Assert.ok(pb.prefHasUserValue("UserPref.existing.int"));
|
||||
Assert.ok(pb.prefHasUserValue("UserPref.existing.char"));
|
||||
Assert.ok(ps.prefHasUserValue("UserPref.existing.bool"));
|
||||
Assert.ok(ps.prefHasUserValue("UserPref.existing.int"));
|
||||
Assert.ok(ps.prefHasUserValue("UserPref.existing.char"));
|
||||
|
||||
// clearUserPref should remove the pref
|
||||
pb.clearUserPref("UserPref.existing.bool");
|
||||
Assert.ok(!pb.prefHasUserValue("UserPref.existing.bool"));
|
||||
pb.clearUserPref("UserPref.existing.int");
|
||||
Assert.ok(!pb.prefHasUserValue("UserPref.existing.int"));
|
||||
pb.clearUserPref("UserPref.existing.char");
|
||||
Assert.ok(!pb.prefHasUserValue("UserPref.existing.char"));
|
||||
ps.clearUserPref("UserPref.existing.bool");
|
||||
Assert.ok(!ps.prefHasUserValue("UserPref.existing.bool"));
|
||||
ps.clearUserPref("UserPref.existing.int");
|
||||
Assert.ok(!ps.prefHasUserValue("UserPref.existing.int"));
|
||||
ps.clearUserPref("UserPref.existing.char");
|
||||
Assert.ok(!ps.prefHasUserValue("UserPref.existing.char"));
|
||||
|
||||
//**************************************************************************//
|
||||
//* *************************************************************************//
|
||||
// Large value test
|
||||
|
||||
let largeStr = new Array(MAX_PREF_LENGTH + 1).join('x');
|
||||
pb.setCharPref("UserPref.large.char", largeStr);
|
||||
largeStr += 'x';
|
||||
let largeStr = new Array(MAX_PREF_LENGTH + 1).join("x");
|
||||
ps.setCharPref("UserPref.large.char", largeStr);
|
||||
largeStr += "x";
|
||||
do_check_throws(function() {
|
||||
pb.setCharPref("UserPref.large.char", largeStr); }, Cr.NS_ERROR_ILLEGAL_VALUE);
|
||||
ps.setCharPref("UserPref.large.char", largeStr);
|
||||
}, Cr.NS_ERROR_ILLEGAL_VALUE);
|
||||
|
||||
//**************************************************************************//
|
||||
//* *************************************************************************//
|
||||
// getPrefType test
|
||||
|
||||
// bool...
|
||||
pb.setBoolPref("UserPref.getPrefType.bool", true);
|
||||
Assert.equal(pb.getPrefType("UserPref.getPrefType.bool"), PREF_BOOL);
|
||||
ps.setBoolPref("UserPref.getPrefType.bool", true);
|
||||
Assert.equal(ps.getPrefType("UserPref.getPrefType.bool"), PREF_BOOL);
|
||||
|
||||
// int...
|
||||
pb.setIntPref("UserPref.getPrefType.int", -234);
|
||||
Assert.equal(pb.getPrefType("UserPref.getPrefType.int"), PREF_INT);
|
||||
ps.setIntPref("UserPref.getPrefType.int", -234);
|
||||
Assert.equal(ps.getPrefType("UserPref.getPrefType.int"), PREF_INT);
|
||||
|
||||
// char...
|
||||
pb.setCharPref("UserPref.getPrefType.char", "testing1..2");
|
||||
Assert.equal(pb.getPrefType("UserPref.getPrefType.char"), PREF_STRING);
|
||||
ps.setCharPref("UserPref.getPrefType.char", "testing1..2");
|
||||
Assert.equal(ps.getPrefType("UserPref.getPrefType.char"), PREF_STRING);
|
||||
|
||||
//**************************************************************************//
|
||||
//* *************************************************************************//
|
||||
// getBranch tests
|
||||
|
||||
Assert.equal(ps.root, "");
|
||||
|
||||
// bool ...
|
||||
pb.setBoolPref("UserPref.root.boolPref", true);
|
||||
ps.setBoolPref("UserPref.root.boolPref", true);
|
||||
let pb_1 = ps.getBranch("UserPref.root.");
|
||||
Assert.equal(pb_1.getBoolPref("boolPref"), true);
|
||||
let pb_2 = ps.getBranch("UserPref.root.boolPref");
|
||||
|
|
@ -165,7 +175,7 @@ function run_test() {
|
|||
Assert.equal(pb_3.getBoolPref("f.anotherPref"), false);
|
||||
|
||||
// int ...
|
||||
pb.setIntPref("UserPref.root.intPref", 23);
|
||||
ps.setIntPref("UserPref.root.intPref", 23);
|
||||
pb_1 = ps.getBranch("UserPref.root.");
|
||||
Assert.equal(pb_1.getIntPref("intPref"), 23);
|
||||
pb_2 = ps.getBranch("UserPref.root.intPref");
|
||||
|
|
@ -175,7 +185,7 @@ function run_test() {
|
|||
Assert.equal(pb_3.getIntPref("f.anotherPref"), 69);
|
||||
|
||||
// char...
|
||||
pb.setCharPref("UserPref.root.charPref", "_char");
|
||||
ps.setCharPref("UserPref.root.charPref", "_char");
|
||||
pb_1 = ps.getBranch("UserPref.root.");
|
||||
Assert.equal(pb_1.getCharPref("charPref"), "_char");
|
||||
pb_2 = ps.getBranch("UserPref.root.charPref");
|
||||
|
|
@ -184,11 +194,11 @@ function run_test() {
|
|||
pb_3 = ps.getBranch("UserPref.root.charPre");
|
||||
Assert.equal(pb_3.getCharPref("f.anotherPref"), "_another");
|
||||
|
||||
//**************************************************************************//
|
||||
//* *************************************************************************//
|
||||
// getChildlist tests
|
||||
|
||||
// get an already set prefBranch
|
||||
pb1 = ps.getBranch("UserPref.root.");
|
||||
let pb1 = ps.getBranch("UserPref.root.");
|
||||
let prefList = pb1.getChildList("");
|
||||
Assert.equal(prefList.length, 6);
|
||||
|
||||
|
|
@ -200,7 +210,7 @@ function run_test() {
|
|||
Assert.ok("intPref.anotherPref" in makeList(prefList));
|
||||
Assert.ok("charPref.anotherPref" in makeList(prefList));
|
||||
|
||||
//**************************************************************************//
|
||||
//* *************************************************************************//
|
||||
// Default branch tests
|
||||
|
||||
// bool...
|
||||
|
|
@ -230,14 +240,16 @@ function run_test() {
|
|||
Assert.ok(pb1.prefHasUserValue("DefaultPref.char"));
|
||||
Assert.equal(ps.getCharPref("DefaultPref.char"), "_user");
|
||||
|
||||
//**************************************************************************//
|
||||
//* *************************************************************************//
|
||||
// pref Locking/Unlocking tests
|
||||
|
||||
// locking and unlocking a nonexistent pref should throw
|
||||
do_check_throws(function() {
|
||||
ps.lockPref("DefaultPref.nonexistent");}, Cr.NS_ERROR_ILLEGAL_VALUE);
|
||||
ps.lockPref("DefaultPref.nonexistent");
|
||||
}, Cr.NS_ERROR_ILLEGAL_VALUE);
|
||||
do_check_throws(function() {
|
||||
ps.unlockPref("DefaultPref.nonexistent");}, Cr.NS_ERROR_ILLEGAL_VALUE);
|
||||
ps.unlockPref("DefaultPref.nonexistent");
|
||||
}, Cr.NS_ERROR_ILLEGAL_VALUE);
|
||||
|
||||
// getting a locked pref branch should return the "default" value
|
||||
Assert.ok(!ps.prefIsLocked("DefaultPref.char"));
|
||||
|
|
@ -260,17 +272,17 @@ function run_test() {
|
|||
ps.lockPref("DefaultPref.char");
|
||||
ps.lockPref("DefaultPref.char");
|
||||
|
||||
//**************************************************************************//
|
||||
//* *************************************************************************//
|
||||
// resetBranch test
|
||||
|
||||
// NOT IMPLEMENTED YET in module/libpref. So we're not testing !
|
||||
// uncomment the following if resetBranch ever gets implemented.
|
||||
/*ps.resetBranch("DefaultPref");
|
||||
/* ps.resetBranch("DefaultPref");
|
||||
do_check_eq(ps.getBoolPref("DefaultPref.bool"), true);
|
||||
do_check_eq(ps.getIntPref("DefaultPref.int"), 100);
|
||||
do_check_eq(ps.getCharPref("DefaultPref.char"), "_default");*/
|
||||
|
||||
//**************************************************************************//
|
||||
//* *************************************************************************//
|
||||
// deleteBranch tests
|
||||
|
||||
// TODO : Really, this should throw!, by documentation.
|
||||
|
|
@ -278,26 +290,32 @@ function run_test() {
|
|||
// ps.deleteBranch("UserPref.nonexistent.deleteBranch");}, Cr.NS_ERROR_UNEXPECTED);
|
||||
|
||||
ps.deleteBranch("DefaultPref");
|
||||
pb = ps.getBranch("DefaultPref");
|
||||
let pb = ps.getBranch("DefaultPref");
|
||||
pb1 = ps.getDefaultBranch("DefaultPref");
|
||||
|
||||
// getting prefs on deleted user branches should throw
|
||||
do_check_throws(function() {
|
||||
pb.getBoolPref("DefaultPref.bool");}, Cr.NS_ERROR_UNEXPECTED);
|
||||
pb.getBoolPref("DefaultPref.bool");
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
pb.getIntPref("DefaultPref.int");}, Cr.NS_ERROR_UNEXPECTED);
|
||||
pb.getIntPref("DefaultPref.int");
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
pb.getCharPref("DefaultPref.char");}, Cr.NS_ERROR_UNEXPECTED);
|
||||
pb.getCharPref("DefaultPref.char");
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
|
||||
// getting prefs on deleted default branches should throw
|
||||
do_check_throws(function() {
|
||||
pb1.getBoolPref("DefaultPref.bool");}, Cr.NS_ERROR_UNEXPECTED);
|
||||
pb1.getBoolPref("DefaultPref.bool");
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
pb1.getIntPref("DefaultPref.int");}, Cr.NS_ERROR_UNEXPECTED);
|
||||
pb1.getIntPref("DefaultPref.int");
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
pb1.getCharPref("DefaultPref.char");}, Cr.NS_ERROR_UNEXPECTED);
|
||||
pb1.getCharPref("DefaultPref.char");
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
|
||||
//**************************************************************************//
|
||||
//* *************************************************************************//
|
||||
// savePrefFile & readPrefFile tests
|
||||
|
||||
// set some prefs
|
||||
|
|
@ -322,11 +340,14 @@ function run_test() {
|
|||
|
||||
// former prefs should have been replaced/lost
|
||||
do_check_throws(function() {
|
||||
pb.getBoolPref("ReadPref.bool");}, Cr.NS_ERROR_UNEXPECTED);
|
||||
pb.getBoolPref("ReadPref.bool");
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
pb.getIntPref("ReadPref.int");}, Cr.NS_ERROR_UNEXPECTED);
|
||||
pb.getIntPref("ReadPref.int");
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
do_check_throws(function() {
|
||||
pb.getCharPref("ReadPref.char");}, Cr.NS_ERROR_UNEXPECTED);
|
||||
pb.getCharPref("ReadPref.char");
|
||||
}, Cr.NS_ERROR_UNEXPECTED);
|
||||
|
||||
// loaded prefs should read ok.
|
||||
pb = ps.getBranch("testPref.");
|
||||
|
|
@ -355,7 +376,7 @@ function run_test() {
|
|||
Assert.equal(pb.getBoolPref("bool2"), false);
|
||||
Assert.equal(pb.getIntPref("int1"), 23);
|
||||
|
||||
//**************************************************************************//
|
||||
//* *************************************************************************//
|
||||
// preference Observers
|
||||
|
||||
class PrefObserver {
|
||||
|
|
@ -390,7 +411,7 @@ function run_test() {
|
|||
// notification received, we may go on...
|
||||
do_test_finished();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Indicate that we'll have 3 more async tests pending so that they all
|
||||
// actually get a chance to run.
|
||||
|
|
@ -398,15 +419,15 @@ function run_test() {
|
|||
do_test_pending();
|
||||
do_test_pending();
|
||||
|
||||
let observer = new PrefObserver(pb2, "ReadPref.int", 76);
|
||||
let observer = new PrefObserver(ps, "ReadPref.int", 76);
|
||||
ps.setIntPref("ReadPref.int", 76);
|
||||
|
||||
// removed observer should not fire
|
||||
pb2.removeObserver("ReadPref.int", observer);
|
||||
ps.removeObserver("ReadPref.int", observer);
|
||||
ps.setIntPref("ReadPref.int", 32);
|
||||
|
||||
// let's test observers once more with a non-root prefbranch
|
||||
pb = pb2.getBranch("ReadPref.");
|
||||
pb = ps.getBranch("ReadPref.");
|
||||
observer = new PrefObserver(pb, "int", 76);
|
||||
ps.setIntPref("ReadPref.int", 76);
|
||||
|
||||
|
|
|
|||
|
|
@ -3,9 +3,6 @@
|
|||
|
||||
// This file tests the `locked` attribute in default pref files.
|
||||
|
||||
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Components.utils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
const ps = Services.prefs;
|
||||
|
||||
add_test(function notChangedFromAPI() {
|
||||
|
|
|
|||
|
|
@ -2,15 +2,10 @@
|
|||
* http://creativecommons.org/licenses/publicdomain/ */
|
||||
|
||||
function run_test() {
|
||||
const PREF_NAME = "testPref";
|
||||
|
||||
var ps = Cc["@mozilla.org/preferences-service;1"]
|
||||
.getService(Ci.nsIPrefService);
|
||||
var defaultPrefs = ps.getDefaultBranch(null);
|
||||
var prefs = ps.getBranch(null);
|
||||
const ps = Services.prefs;
|
||||
|
||||
ps.resetPrefs();
|
||||
ps.readDefaultPrefsFromFile(do_get_file('data/testParser.js'));
|
||||
ps.readDefaultPrefsFromFile(do_get_file("data/testParser.js"));
|
||||
|
||||
Assert.equal(ps.getBoolPref("comment1"), true);
|
||||
Assert.equal(ps.getBoolPref("comment2"), true);
|
||||
|
|
@ -35,7 +30,7 @@ function run_test() {
|
|||
Assert.equal(ps.getIntPref("int.+ 345"), 345);
|
||||
Assert.equal(ps.getIntPref("int.-0"), -0);
|
||||
Assert.equal(ps.getIntPref("int.-1"), -1);
|
||||
Assert.equal(ps.getIntPref("int.- /* hmm */ 456"), -456);
|
||||
Assert.equal(ps.getIntPref("int.- /* hmm */\t456"), -456);
|
||||
Assert.equal(ps.getIntPref("int.-\n567"), -567);
|
||||
Assert.equal(ps.getIntPref("int.INT_MAX-1"), 2147483646);
|
||||
Assert.equal(ps.getIntPref("int.INT_MAX"), 2147483647);
|
||||
|
|
@ -46,7 +41,7 @@ function run_test() {
|
|||
Assert.equal(ps.getCharPref("string.empty"), "");
|
||||
Assert.equal(ps.getCharPref("string.abc"), "abc");
|
||||
Assert.equal(ps.getCharPref("string.long"), "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
|
||||
Assert.equal(ps.getCharPref('string.single-quotes'), '"abc"');
|
||||
Assert.equal(ps.getCharPref("string.single-quotes"), '"abc"');
|
||||
Assert.equal(ps.getCharPref("string.double-quotes"), "'abc'");
|
||||
Assert.equal(ps.getCharPref("string.weird-chars"),
|
||||
"\x0d \x09 \x0b \x0c \x06 \x16");
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/licenses/publicdomain/ */
|
||||
|
||||
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
const ps = Services.prefs;
|
||||
|
||||
// A little helper to reset the service and load one pref file.
|
||||
|
|
@ -37,10 +35,6 @@ function saveAndReload() {
|
|||
ps.readUserPrefsFromFile(file);
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
run_next_test();
|
||||
}
|
||||
|
||||
// A sticky pref should not be written if the value is unchanged.
|
||||
add_test(function notWrittenWhenUnchanged() {
|
||||
resetAndLoadDefaults();
|
||||
|
|
|
|||
|
|
@ -2,14 +2,8 @@
|
|||
* 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/. */
|
||||
|
||||
|
||||
var cs = Cc["@mozilla.org/consoleservice;1"].
|
||||
getService(Ci.nsIConsoleService);
|
||||
var ps = Cc["@mozilla.org/preferences-service;1"].
|
||||
getService(Ci.nsIPrefService);
|
||||
|
||||
function makeBuffer(length) {
|
||||
return new Array(length + 1).join('x');
|
||||
return new Array(length + 1).join("x");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -20,7 +14,7 @@ function checkWarning(pref, buffer) {
|
|||
return new Promise(resolve => {
|
||||
let complete = false;
|
||||
let listener = {
|
||||
observe: function(event) {
|
||||
observe(event) {
|
||||
let message = event.message;
|
||||
if (!(message.startsWith("Warning: attempting to write")
|
||||
&& message.includes(pref))) {
|
||||
|
|
@ -31,9 +25,9 @@ function checkWarning(pref, buffer) {
|
|||
}
|
||||
complete = true;
|
||||
info("Warning while setting " + pref);
|
||||
cs.unregisterListener(listener);
|
||||
Services.console.unregisterListener(listener);
|
||||
resolve(true);
|
||||
}
|
||||
},
|
||||
};
|
||||
do_timeout(1000, function() {
|
||||
if (complete) {
|
||||
|
|
@ -41,18 +35,14 @@ function checkWarning(pref, buffer) {
|
|||
}
|
||||
complete = true;
|
||||
info("No warning while setting " + pref);
|
||||
cs.unregisterListener(listener);
|
||||
Services.console.unregisterListener(listener);
|
||||
resolve(false);
|
||||
});
|
||||
cs.registerListener(listener);
|
||||
ps.setCharPref(pref, buffer);
|
||||
Services.console.registerListener(listener);
|
||||
Services.prefs.setCharPref(pref, buffer);
|
||||
});
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
run_next_test();
|
||||
}
|
||||
|
||||
add_task(async function() {
|
||||
// Simple change, shouldn't cause a warning
|
||||
info("Checking that a simple change doesn't cause a warning");
|
||||
|
|
|
|||
|
|
@ -1,14 +1,15 @@
|
|||
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
function isParentProcess() {
|
||||
let appInfo = Cc["@mozilla.org/xre/app-info;1"];
|
||||
return (!appInfo || appInfo.getService(Ci.nsIXULRuntime).processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT);
|
||||
return (!appInfo || Services.appinfo.processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT);
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
if (isParentProcess() == false) {
|
||||
|
||||
if (!isParentProcess()) {
|
||||
do_load_child_test_harness();
|
||||
|
||||
var pb = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
|
||||
var pb = Services.prefs;
|
||||
pb.setBoolPref("Test.IPC.bool.new", true);
|
||||
pb.setIntPref("Test.IPC.int.new", 23);
|
||||
pb.setCharPref("Test.IPC.char.new", "hey");
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
function isParentProcess() {
|
||||
let appInfo = Cc["@mozilla.org/xre/app-info;1"];
|
||||
return (!appInfo || appInfo.getService(Ci.nsIXULRuntime).processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT);
|
||||
return (Services.appinfo.processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT);
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
if (isParentProcess() == false) {
|
||||
var pb = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
|
||||
if (!isParentProcess()) {
|
||||
const pb = Services.prefs;
|
||||
pb.setBoolPref("Test.IPC.bool", true);
|
||||
pb.setIntPref("Test.IPC.int", 23);
|
||||
pb.setCharPref("Test.IPC.char", "hey");
|
||||
|
|
|
|||
|
|
@ -5,10 +5,11 @@
|
|||
// Large preferences should not be set in the child process.
|
||||
// Non-string preferences are not tested here, because their behavior
|
||||
// should not be affected by this filtering.
|
||||
//
|
||||
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
function isParentProcess() {
|
||||
let appInfo = Cc["@mozilla.org/xre/app-info;1"];
|
||||
return (!appInfo || appInfo.getService(Ci.nsIXULRuntime).processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT);
|
||||
return (Services.appinfo.processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT);
|
||||
}
|
||||
|
||||
function makeBuffer(length) {
|
||||
|
|
@ -46,9 +47,8 @@ function expectedPrefValue(def, user) {
|
|||
}
|
||||
|
||||
function run_test() {
|
||||
let pb = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
|
||||
let ps = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefService);
|
||||
let defaultBranch = ps.getDefaultBranch("");
|
||||
const pb = Services.prefs;
|
||||
let defaultBranch = pb.getDefaultBranch("");
|
||||
|
||||
let isParent = isParentProcess();
|
||||
if (isParent) {
|
||||
|
|
@ -92,7 +92,7 @@ function run_test() {
|
|||
try {
|
||||
let val = pb.getCharPref(pref_name);
|
||||
prefExists = val.length > 128;
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
prefExists = false;
|
||||
}
|
||||
ok(!prefExists,
|
||||
|
|
|
|||
|
|
@ -4,13 +4,14 @@
|
|||
|
||||
// Locked status should be communicated to children.
|
||||
|
||||
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
function isParentProcess() {
|
||||
let appInfo = Cc["@mozilla.org/xre/app-info;1"];
|
||||
return (!appInfo || appInfo.getService(Ci.nsIXULRuntime).processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT);
|
||||
return (Services.appinfo.processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT);
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
let pb = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
|
||||
const pb = Services.prefs;
|
||||
|
||||
let bprefname = "Test.IPC.locked.bool";
|
||||
let iprefname = "Test.IPC.locked.int";
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
function isParentProcess() {
|
||||
let appInfo = Cc["@mozilla.org/xre/app-info;1"];
|
||||
return (!appInfo || appInfo.getService(Ci.nsIXULRuntime).processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT);
|
||||
return (Services.appinfo.processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT);
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
if (isParentProcess() == false) {
|
||||
var pb = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
|
||||
if (!isParentProcess()) {
|
||||
const pb = Services.prefs;
|
||||
Assert.equal(pb.getBoolPref("Test.IPC.bool.new"), true);
|
||||
Assert.equal(pb.getIntPref("Test.IPC.int.new"), 23);
|
||||
Assert.equal(pb.getCharPref("Test.IPC.char.new"), "hey");
|
||||
|
|
|
|||
|
|
@ -152,7 +152,6 @@ const PREFS = [
|
|||
|
||||
for (let {type, values} of PREFS) {
|
||||
let set = `set${type}Pref`;
|
||||
let get = `get${type}Pref`;
|
||||
|
||||
function prefTest(opts) {
|
||||
function check(pref, proc, val, {expectedVal, defaultVal = undefined, expectedDefault = defaultVal, expectedFlags = {}}) {
|
||||
|
|
@ -179,14 +178,14 @@ for (let {type, values} of PREFS) {
|
|||
|
||||
return {
|
||||
beforeContent(PREF) {
|
||||
updatePref(PREF, opts.initial)
|
||||
updatePref(PREF, opts.initial);
|
||||
check(PREF, "parent", getPref(PREF), opts.initial);
|
||||
},
|
||||
contentStartup(PREF, contentVal) {
|
||||
check(PREF, "content", contentVal, opts.initial);
|
||||
check(PREF, "parent", getPref(PREF), opts.initial);
|
||||
|
||||
updatePref(PREF, opts.change1)
|
||||
updatePref(PREF, opts.change1);
|
||||
check(PREF, "parent", getPref(PREF), opts.change1);
|
||||
},
|
||||
contentUpdate1(PREF, contentVal) {
|
||||
|
|
@ -194,7 +193,7 @@ for (let {type, values} of PREFS) {
|
|||
check(PREF, "parent", getPref(PREF), opts.change1);
|
||||
|
||||
if (opts.change2) {
|
||||
updatePref(PREF, opts.change2)
|
||||
updatePref(PREF, opts.change2);
|
||||
check(PREF, "parent", getPref(PREF), opts.change2);
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@
|
|||
const PREF1_NAME = "dom.webcomponents.shadowdom.report_usage";
|
||||
const PREF1_VALUE = false;
|
||||
|
||||
const PREF2_NAME = "dom.mutation-events.cssom.disabled"
|
||||
const PREF2_NAME = "dom.mutation-events.cssom.disabled";
|
||||
const PREF2_VALUE = true;
|
||||
|
||||
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
|
@ -30,8 +30,6 @@ const {ExtensionTestUtils} = ChromeUtils.import("resource://testing-common/Exten
|
|||
|
||||
ExtensionTestUtils.init(this);
|
||||
|
||||
let contentPage;
|
||||
|
||||
const {prefs} = Services;
|
||||
const defaultPrefs = prefs.getDefaultBranch("");
|
||||
|
||||
|
|
@ -52,14 +50,15 @@ add_task(async function test_sharedMap_var_caches() {
|
|||
let contentPage = await ExtensionTestUtils.loadContentPage("about:blank", {remote: true});
|
||||
registerCleanupFunction(() => contentPage.close());
|
||||
|
||||
/* eslint-disable no-shadow */
|
||||
let values = await contentPage.spawn([PREF1_NAME, PREF2_NAME], (prefs) => {
|
||||
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
return prefs.map(pref => Services.prefs.getBoolPref(pref));
|
||||
})
|
||||
});
|
||||
/* eslint-enable no-shadow */
|
||||
|
||||
equal(values[0], !PREF1_VALUE,
|
||||
`Expected content value for ${PREF1_NAME}`);
|
||||
equal(values[1], !PREF2_VALUE,
|
||||
`Expected content value for ${PREF2_NAME}`);
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
function isParentProcess() {
|
||||
let appInfo = Cc["@mozilla.org/xre/app-info;1"];
|
||||
return (!appInfo || appInfo.getService(Ci.nsIXULRuntime).processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT);
|
||||
return Services.appinfo.processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
if (isParentProcess()) {
|
||||
|
||||
do_load_child_test_harness();
|
||||
|
||||
var pb = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
|
||||
var pb = Services.prefs;
|
||||
|
||||
// these prefs are set after the child has been created.
|
||||
pb.setBoolPref("Test.IPC.bool.new", true);
|
||||
|
|
@ -20,11 +20,11 @@ function run_test() {
|
|||
}
|
||||
|
||||
function testPrefClear() {
|
||||
var pb = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
|
||||
var pb = Services.prefs;
|
||||
pb.clearUserPref("Test.IPC.bool.new");
|
||||
|
||||
sendCommand(
|
||||
'var pb = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);\n'+
|
||||
'var pb = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);\n' +
|
||||
'pb.prefHasUserValue("Test.IPC.bool.new");\n',
|
||||
checkWasCleared);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,19 +1,20 @@
|
|||
var pb = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
|
||||
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
const pb = Services.prefs;
|
||||
|
||||
// This pref is chosen somewhat arbitrarily --- we just need one
|
||||
// that's guaranteed to have a default value.
|
||||
const kPrefName = 'intl.accept_languages'; // of type char, which we
|
||||
const kPrefName = "intl.accept_languages"; // of type char, which we
|
||||
// assume below
|
||||
var initialValue = null;
|
||||
|
||||
function check_child_pref_info_eq(continuation) {
|
||||
sendCommand(
|
||||
'var pb = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);\n'+
|
||||
'var pb = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);\n' +
|
||||
// Returns concatenation "[value],[isUser]"
|
||||
'pb.getCharPref("'+ kPrefName +'")+ "," +'+
|
||||
'pb.prefHasUserValue("'+ kPrefName +'");',
|
||||
function (info) {
|
||||
let [ value, isUser ] = info.split(',');
|
||||
'pb.getCharPref("' + kPrefName + '")+ "," +' +
|
||||
'pb.prefHasUserValue("' + kPrefName + '");',
|
||||
function(info) {
|
||||
let [ value, isUser ] = info.split(",");
|
||||
Assert.equal(pb.getCharPref(kPrefName), value);
|
||||
Assert.equal(pb.prefHasUserValue(kPrefName), isUser == "true");
|
||||
continuation();
|
||||
|
|
@ -33,11 +34,11 @@ function test_user_setting() {
|
|||
// We rely on setting this before the content process starts up.
|
||||
// When it starts up, it should recognize this as a user pref, not
|
||||
// a default pref.
|
||||
pb.setCharPref(kPrefName, 'i-imaginarylanguage');
|
||||
pb.setCharPref(kPrefName, "i-imaginarylanguage");
|
||||
// NB: processing of the value-change notification in the child
|
||||
// process triggered by the above set happens-before the remaining
|
||||
// code here
|
||||
check_child_pref_info_eq(function () {
|
||||
check_child_pref_info_eq(function() {
|
||||
Assert.equal(pb.prefHasUserValue(kPrefName), true);
|
||||
|
||||
test_cleared_is_default();
|
||||
|
|
@ -49,7 +50,7 @@ function test_cleared_is_default() {
|
|||
// NB: processing of the value-change notification in the child
|
||||
// process triggered by the above set happens-before the remaining
|
||||
// code here
|
||||
check_child_pref_info_eq(function () {
|
||||
check_child_pref_info_eq(function() {
|
||||
Assert.equal(pb.prefHasUserValue(kPrefName), false);
|
||||
|
||||
clean_up();
|
||||
|
|
@ -61,7 +62,7 @@ function clean_up() {
|
|||
// NB: processing of the value-change notification in the child
|
||||
// process triggered by the above set happens-before the remaining
|
||||
// code here
|
||||
check_child_pref_info_eq(function () {
|
||||
check_child_pref_info_eq(function() {
|
||||
do_test_finished();
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,8 +40,6 @@ static const char kPrefThirdPartySession[] =
|
|||
"network.cookie.thirdparty.sessionOnly";
|
||||
static const char kPrefThirdPartyNonsecureSession[] =
|
||||
"network.cookie.thirdparty.nonsecureSessionOnly";
|
||||
static const char kCookieLeaveSecurityAlone[] =
|
||||
"network.cookie.leave-secure-alone";
|
||||
static const char kCookieMoveIntervalSecs[] =
|
||||
"network.cookie.move.interval_sec";
|
||||
|
||||
|
|
@ -64,7 +62,6 @@ CookieServiceChild::CookieServiceChild()
|
|||
: mCookieBehavior(nsICookieService::BEHAVIOR_ACCEPT),
|
||||
mThirdPartySession(false),
|
||||
mThirdPartyNonsecureSession(false),
|
||||
mLeaveSecureAlone(true),
|
||||
mIPCOpen(false) {
|
||||
NS_ASSERTION(IsNeckoChild(), "not a child process");
|
||||
|
||||
|
|
@ -94,7 +91,6 @@ CookieServiceChild::CookieServiceChild()
|
|||
prefBranch->AddObserver(kPrefCookieBehavior, this, true);
|
||||
prefBranch->AddObserver(kPrefThirdPartySession, this, true);
|
||||
prefBranch->AddObserver(kPrefThirdPartyNonsecureSession, this, true);
|
||||
prefBranch->AddObserver(kCookieLeaveSecurityAlone, this, true);
|
||||
prefBranch->AddObserver(kCookieMoveIntervalSecs, this, true);
|
||||
PrefChanged(prefBranch);
|
||||
}
|
||||
|
|
@ -271,10 +267,6 @@ void CookieServiceChild::PrefChanged(nsIPrefBranch *aPrefBranch) {
|
|||
aPrefBranch->GetBoolPref(kPrefThirdPartyNonsecureSession, &boolval)))
|
||||
mThirdPartyNonsecureSession = boolval;
|
||||
|
||||
if (NS_SUCCEEDED(
|
||||
aPrefBranch->GetBoolPref(kCookieLeaveSecurityAlone, &boolval)))
|
||||
mLeaveSecureAlone = !!boolval;
|
||||
|
||||
if (!mThirdPartyUtil && RequireThirdPartyCheck()) {
|
||||
mThirdPartyUtil = do_GetService(THIRDPARTYUTIL_CONTRACTID);
|
||||
NS_ASSERTION(mThirdPartyUtil, "require ThirdPartyUtil service");
|
||||
|
|
@ -607,8 +599,8 @@ nsresult CookieServiceChild::SetCookieStringInternal(nsIURI *aHostURI,
|
|||
bool canSetCookie = false;
|
||||
moreCookies = nsCookieService::CanSetCookie(
|
||||
aHostURI, key, cookieAttributes, requireHostMatch, cookieStatus,
|
||||
cookieString, serverTime, aFromHttp, aChannel, mLeaveSecureAlone,
|
||||
canSetCookie, mThirdPartyUtil);
|
||||
cookieString, serverTime, aFromHttp, aChannel, canSetCookie,
|
||||
mThirdPartyUtil);
|
||||
|
||||
// We need to see if the cookie we're setting would overwrite an httponly
|
||||
// one. This would not affect anything we send over the net (those come from
|
||||
|
|
|
|||
|
|
@ -110,7 +110,6 @@ class CookieServiceChild : public PCookieServiceChild,
|
|||
uint8_t mCookieBehavior;
|
||||
bool mThirdPartySession;
|
||||
bool mThirdPartyNonsecureSession;
|
||||
bool mLeaveSecureAlone;
|
||||
bool mIPCOpen;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -134,19 +134,6 @@ static const char kPrefThirdPartySession[] =
|
|||
"network.cookie.thirdparty.sessionOnly";
|
||||
static const char kPrefThirdPartyNonsecureSession[] =
|
||||
"network.cookie.thirdparty.nonsecureSessionOnly";
|
||||
static const char kCookieLeaveSecurityAlone[] =
|
||||
"network.cookie.leave-secure-alone";
|
||||
|
||||
// For telemetry COOKIE_LEAVE_SECURE_ALONE
|
||||
#define BLOCKED_SECURE_SET_FROM_HTTP 0
|
||||
#define BLOCKED_DOWNGRADE_SECURE_INEXACT 1
|
||||
#define DOWNGRADE_SECURE_FROM_SECURE_INEXACT 2
|
||||
#define EVICTED_NEWER_INSECURE 3
|
||||
#define EVICTED_OLDEST_COOKIE 4
|
||||
#define EVICTED_PREFERRED_COOKIE 5
|
||||
#define EVICTING_SECURE_BLOCKED 6
|
||||
#define BLOCKED_DOWNGRADE_SECURE_EXACT 7
|
||||
#define DOWNGRADE_SECURE_FROM_SECURE_EXACT 8
|
||||
|
||||
static void bindCookieParameters(mozIStorageBindingParamsArray *aParamsArray,
|
||||
const nsCookieKey &aKey,
|
||||
|
|
@ -601,7 +588,6 @@ nsCookieService::nsCookieService()
|
|||
mCookieBehavior(nsICookieService::BEHAVIOR_ACCEPT),
|
||||
mThirdPartySession(false),
|
||||
mThirdPartyNonsecureSession(false),
|
||||
mLeaveSecureAlone(true),
|
||||
mMaxNumberOfCookies(kMaxNumberOfCookies),
|
||||
mMaxCookiesPerHost(kMaxCookiesPerHost),
|
||||
mCookieQuotaPerHost(kCookieQuotaPerHost),
|
||||
|
|
@ -631,7 +617,6 @@ nsresult nsCookieService::Init() {
|
|||
prefBranch->AddObserver(kPrefCookiePurgeAge, this, true);
|
||||
prefBranch->AddObserver(kPrefThirdPartySession, this, true);
|
||||
prefBranch->AddObserver(kPrefThirdPartyNonsecureSession, this, true);
|
||||
prefBranch->AddObserver(kCookieLeaveSecurityAlone, this, true);
|
||||
PrefChanged(prefBranch);
|
||||
}
|
||||
|
||||
|
|
@ -2403,10 +2388,6 @@ void nsCookieService::PrefChanged(nsIPrefBranch *aPrefBranch) {
|
|||
if (NS_SUCCEEDED(
|
||||
aPrefBranch->GetBoolPref(kPrefThirdPartyNonsecureSession, &boolval)))
|
||||
mThirdPartyNonsecureSession = boolval;
|
||||
|
||||
if (NS_SUCCEEDED(
|
||||
aPrefBranch->GetBoolPref(kCookieLeaveSecurityAlone, &boolval)))
|
||||
mLeaveSecureAlone = boolval;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
|
|
@ -3239,8 +3220,7 @@ bool nsCookieService::CanSetCookie(nsIURI *aHostURI, const nsCookieKey &aKey,
|
|||
bool aRequireHostMatch, CookieStatus aStatus,
|
||||
nsDependentCString &aCookieHeader,
|
||||
int64_t aServerTime, bool aFromHttp,
|
||||
nsIChannel *aChannel, bool aLeaveSecureAlone,
|
||||
bool &aSetCookie,
|
||||
nsIChannel *aChannel, bool &aSetCookie,
|
||||
mozIThirdPartyUtil *aThirdPartyUtil) {
|
||||
NS_ASSERTION(aHostURI, "null host!");
|
||||
|
||||
|
|
@ -3373,11 +3353,9 @@ bool nsCookieService::CanSetCookie(nsIURI *aHostURI, const nsCookieKey &aKey,
|
|||
// If the new cookie is non-https and wants to set secure flag,
|
||||
// browser have to ignore this new cookie.
|
||||
// (draft-ietf-httpbis-cookie-alone section 3.1)
|
||||
if (aLeaveSecureAlone && aCookieAttributes.isSecure && !isSecure) {
|
||||
if (aCookieAttributes.isSecure && !isSecure) {
|
||||
COOKIE_LOGFAILURE(SET_COOKIE, aHostURI, aCookieHeader,
|
||||
"non-https cookie can't set secure flag");
|
||||
Telemetry::Accumulate(Telemetry::COOKIE_LEAVE_SECURE_ALONE,
|
||||
BLOCKED_SECURE_SET_FROM_HTTP);
|
||||
return newCookie;
|
||||
}
|
||||
|
||||
|
|
@ -3427,7 +3405,7 @@ bool nsCookieService::SetCookieInternal(nsIURI *aHostURI,
|
|||
bool newCookie =
|
||||
CanSetCookie(aHostURI, aKey, cookieAttributes, aRequireHostMatch, aStatus,
|
||||
aCookieHeader, aServerTime, aFromHttp, aChannel,
|
||||
mLeaveSecureAlone, canSetCookie, mThirdPartyUtil);
|
||||
canSetCookie, mThirdPartyUtil);
|
||||
|
||||
if (!canSetCookie) {
|
||||
return newCookie;
|
||||
|
|
@ -3498,7 +3476,6 @@ void nsCookieService::AddInternal(const nsCookieKey &aKey, nsCookie *aCookie,
|
|||
isSecure = false;
|
||||
}
|
||||
bool oldCookieIsSession = false;
|
||||
if (mLeaveSecureAlone) {
|
||||
// Step1, call FindSecureCookie(). FindSecureCookie() would
|
||||
// find the existing cookie with the security flag and has
|
||||
// the same name, host and path of the new cookie, if there is any.
|
||||
|
|
@ -3510,31 +3487,12 @@ void nsCookieService::AddInternal(const nsCookieKey &aKey, nsCookie *aCookie,
|
|||
// then ignore the new cookie.
|
||||
// (draft-ietf-httpbis-cookie-alone section 3.2)
|
||||
if (!aCookie->IsSecure() &&
|
||||
(foundSecureExact || FindSecureCookie(aKey, aCookie))) {
|
||||
if (!isSecure) {
|
||||
(foundSecureExact || FindSecureCookie(aKey, aCookie)) && !isSecure) {
|
||||
COOKIE_LOGFAILURE(SET_COOKIE, aHostURI, aCookieHeader,
|
||||
"cookie can't save because older cookie is secure "
|
||||
"cookie but newer cookie is non-secure cookie");
|
||||
if (foundSecureExact) {
|
||||
Telemetry::Accumulate(Telemetry::COOKIE_LEAVE_SECURE_ALONE,
|
||||
BLOCKED_DOWNGRADE_SECURE_EXACT);
|
||||
} else {
|
||||
Telemetry::Accumulate(Telemetry::COOKIE_LEAVE_SECURE_ALONE,
|
||||
BLOCKED_DOWNGRADE_SECURE_INEXACT);
|
||||
}
|
||||
return;
|
||||
}
|
||||
// A secure site is allowed to downgrade a secure cookie
|
||||
// but we want to measure anyway.
|
||||
if (foundSecureExact) {
|
||||
Telemetry::Accumulate(Telemetry::COOKIE_LEAVE_SECURE_ALONE,
|
||||
DOWNGRADE_SECURE_FROM_SECURE_EXACT);
|
||||
} else {
|
||||
Telemetry::Accumulate(Telemetry::COOKIE_LEAVE_SECURE_ALONE,
|
||||
DOWNGRADE_SECURE_FROM_SECURE_INEXACT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RefPtr<nsCookie> oldCookie;
|
||||
nsCOMPtr<nsIArray> purgedList;
|
||||
|
|
@ -3624,19 +3582,13 @@ void nsCookieService::AddInternal(const nsCookieKey &aKey, nsCookie *aCookie,
|
|||
nsTArray<nsListIter> removedIterList;
|
||||
// Prioritize evicting insecure cookies.
|
||||
// (draft-ietf-httpbis-cookie-alone section 3.3)
|
||||
mozilla::Maybe<bool> optionalSecurity =
|
||||
mLeaveSecureAlone ? Some(false) : Nothing();
|
||||
uint32_t limit = mMaxCookiesPerHost - mCookieQuotaPerHost;
|
||||
FindStaleCookies(entry, currentTime, optionalSecurity, removedIterList,
|
||||
limit);
|
||||
FindStaleCookies(entry, currentTime, false, removedIterList, limit);
|
||||
if (removedIterList.Length() == 0) {
|
||||
if (aCookie->IsSecure()) {
|
||||
// It's valid to evict a secure cookie for another secure cookie.
|
||||
FindStaleCookies(entry, currentTime, Some(true), removedIterList,
|
||||
limit);
|
||||
FindStaleCookies(entry, currentTime, true, removedIterList, limit);
|
||||
} else {
|
||||
Telemetry::Accumulate(Telemetry::COOKIE_LEAVE_SECURE_ALONE,
|
||||
EVICTING_SECURE_BLOCKED);
|
||||
COOKIE_LOGEVICTED(aCookie,
|
||||
"Too many cookies for this domain and the new "
|
||||
"cookie is not a secure cookie");
|
||||
|
|
@ -3651,10 +3603,6 @@ void nsCookieService::AddInternal(const nsCookieKey &aKey, nsCookie *aCookie,
|
|||
for (auto it = removedIterList.rbegin(); it != removedIterList.rend();
|
||||
it++) {
|
||||
RefPtr<nsCookie> evictedCookie = (*it).Cookie();
|
||||
if (mLeaveSecureAlone && evictedCookie->Expiry() <= currentTime) {
|
||||
TelemetryForEvictingStaleCookie(evictedCookie,
|
||||
evictedCookie->LastAccessed());
|
||||
}
|
||||
COOKIE_LOGEVICTED(evictedCookie, "Too many cookies for this domain");
|
||||
RemoveCookieFromList(*it);
|
||||
CreateOrUpdatePurgeList(getter_AddRefs(purgedList), evictedCookie);
|
||||
|
|
@ -4571,8 +4519,7 @@ class CookieIterComparator {
|
|||
// Given the output iter array and the count limit, find cookies
|
||||
// sort by expiry and lastAccessed time.
|
||||
void nsCookieService::FindStaleCookies(nsCookieEntry *aEntry,
|
||||
int64_t aCurrentTime,
|
||||
const mozilla::Maybe<bool> &aIsSecure,
|
||||
int64_t aCurrentTime, bool aIsSecure,
|
||||
nsTArray<nsListIter> &aOutput,
|
||||
uint32_t aLimit) {
|
||||
MOZ_ASSERT(aLimit);
|
||||
|
|
@ -4591,7 +4538,7 @@ void nsCookieService::FindStaleCookies(nsCookieEntry *aEntry,
|
|||
continue;
|
||||
}
|
||||
|
||||
if (aIsSecure.isSome() && !aIsSecure.value()) {
|
||||
if (!aIsSecure) {
|
||||
// We want to look for the non-secure cookie first time through,
|
||||
// then find the secure cookie the second time this function is called.
|
||||
if (cookie->IsSecure()) {
|
||||
|
|
@ -4609,23 +4556,6 @@ void nsCookieService::FindStaleCookies(nsCookieEntry *aEntry,
|
|||
}
|
||||
}
|
||||
|
||||
void nsCookieService::TelemetryForEvictingStaleCookie(
|
||||
nsCookie *aEvicted, int64_t oldestCookieTime) {
|
||||
// We need to record the evicting cookie to telemetry.
|
||||
if (!aEvicted->IsSecure()) {
|
||||
if (aEvicted->LastAccessed() > oldestCookieTime) {
|
||||
Telemetry::Accumulate(Telemetry::COOKIE_LEAVE_SECURE_ALONE,
|
||||
EVICTED_NEWER_INSECURE);
|
||||
} else {
|
||||
Telemetry::Accumulate(Telemetry::COOKIE_LEAVE_SECURE_ALONE,
|
||||
EVICTED_OLDEST_COOKIE);
|
||||
}
|
||||
} else {
|
||||
Telemetry::Accumulate(Telemetry::COOKIE_LEAVE_SECURE_ALONE,
|
||||
EVICTED_PREFERRED_COOKIE);
|
||||
}
|
||||
}
|
||||
|
||||
// count the number of cookies stored by a particular host. this is provided by
|
||||
// the nsICookieManager interface.
|
||||
NS_IMETHODIMP
|
||||
|
|
|
|||
|
|
@ -255,8 +255,7 @@ class nsCookieService final : public nsICookieService,
|
|||
bool aRequireHostMatch, CookieStatus aStatus,
|
||||
nsDependentCString &aCookieHeader,
|
||||
int64_t aServerTime, bool aFromHttp,
|
||||
nsIChannel *aChannel, bool aLeaveSercureAlone,
|
||||
bool &aSetCookie,
|
||||
nsIChannel *aChannel, bool &aSetCookie,
|
||||
mozIThirdPartyUtil *aThirdPartyUtil);
|
||||
static CookieStatus CheckPrefs(
|
||||
nsICookiePermission *aPermissionServices, uint8_t aCookieBehavior,
|
||||
|
|
@ -353,10 +352,8 @@ class nsCookieService final : public nsICookieService,
|
|||
nsListIter &aIter);
|
||||
bool FindSecureCookie(const nsCookieKey &aKey, nsCookie *aCookie);
|
||||
void FindStaleCookies(nsCookieEntry *aEntry, int64_t aCurrentTime,
|
||||
const mozilla::Maybe<bool> &aIsSecure,
|
||||
nsTArray<nsListIter> &aOutput, uint32_t aLimit);
|
||||
void TelemetryForEvictingStaleCookie(nsCookie *aEvicted,
|
||||
int64_t oldestCookieTime);
|
||||
bool aIsSecure, nsTArray<nsListIter> &aOutput,
|
||||
uint32_t aLimit);
|
||||
void NotifyAccepted(nsIChannel *aChannel);
|
||||
void NotifyRejected(nsIURI *aHostURI, nsIChannel *aChannel,
|
||||
uint32_t aRejectedReason, CookieOperation aOperation);
|
||||
|
|
@ -406,7 +403,6 @@ class nsCookieService final : public nsICookieService,
|
|||
// LIMITFOREIGN}
|
||||
bool mThirdPartySession;
|
||||
bool mThirdPartyNonsecureSession;
|
||||
bool mLeaveSecureAlone;
|
||||
uint16_t mMaxNumberOfCookies;
|
||||
uint16_t mMaxCookiesPerHost;
|
||||
uint16_t mCookieQuotaPerHost;
|
||||
|
|
|
|||
|
|
@ -32,8 +32,6 @@ static NS_DEFINE_CID(kPrefServiceCID, NS_PREFSERVICE_CID);
|
|||
static const char kCookiesPermissions[] = "network.cookie.cookieBehavior";
|
||||
static const char kPrefCookieQuotaPerHost[] = "network.cookie.quotaPerHost";
|
||||
static const char kCookiesMaxPerHost[] = "network.cookie.maxPerHost";
|
||||
static const char kCookieLeaveSecurityAlone[] =
|
||||
"network.cookie.leave-secure-alone";
|
||||
|
||||
#define OFFSET_ONE_WEEK int64_t(604800) * PR_USEC_PER_SEC
|
||||
#define OFFSET_ONE_DAY int64_t(86400) * PR_USEC_PER_SEC
|
||||
|
|
@ -176,7 +174,6 @@ void InitPrefs(nsIPrefBranch *aPrefBranch) {
|
|||
// we use the most restrictive set of prefs we can;
|
||||
// however, we don't test third party blocking here.
|
||||
aPrefBranch->SetIntPref(kCookiesPermissions, 0); // accept all
|
||||
aPrefBranch->SetBoolPref(kCookieLeaveSecurityAlone, true);
|
||||
// Set quotaPerHost to maxPerHost - 1, so there is only one cookie
|
||||
// will be evicted everytime.
|
||||
aPrefBranch->SetIntPref(kPrefCookieQuotaPerHost, 49);
|
||||
|
|
@ -980,8 +977,6 @@ TEST(TestCookie, TestCookieMain) {
|
|||
GetACookie(cookieService, "http://creation.ordering.tests/", nullptr, cookie);
|
||||
EXPECT_TRUE(CheckResult(cookie.get(), MUST_EQUAL, expected.get()));
|
||||
|
||||
// *** eviction and creation ordering tests after enable
|
||||
// network.cookie.leave-secure-alone reset cookie
|
||||
cookieMgr->RemoveAll();
|
||||
|
||||
for (int32_t i = 0; i < 60; ++i) {
|
||||
|
|
|
|||
|
|
@ -45,6 +45,15 @@ __all__ = [
|
|||
]
|
||||
|
||||
|
||||
def path_starts_with(path, prefix):
|
||||
if os.altsep:
|
||||
prefix = prefix.replace(os.altsep, os.sep)
|
||||
path = path.replace(os.altsep, os.sep)
|
||||
prefix = [os.path.normcase(p) for p in prefix.split(os.sep)]
|
||||
path = [os.path.normcase(p) for p in path.split(os.sep)]
|
||||
return path[:len(prefix)] == prefix
|
||||
|
||||
|
||||
class Expression:
|
||||
def __init__(self, expression_string):
|
||||
"""
|
||||
|
|
@ -280,6 +289,15 @@ class Preprocessor:
|
|||
'LINE': 0,
|
||||
'DIRECTORY': os.path.abspath('.')}.iteritems():
|
||||
self.context[k] = v
|
||||
try:
|
||||
# Can import globally because of bootstrapping issues.
|
||||
from buildconfig import topsrcdir, topobjdir
|
||||
except ImportError:
|
||||
# Allow this script to still work independently of a configured objdir.
|
||||
topsrcdir = topobjdir = None
|
||||
self.topsrcdir = topsrcdir
|
||||
self.topobjdir = topobjdir
|
||||
self.curdir = '.'
|
||||
self.actionLevel = 0
|
||||
self.disableLevel = 0
|
||||
# ifStates can be
|
||||
|
|
@ -747,7 +765,7 @@ class Preprocessor:
|
|||
if filters:
|
||||
args = self.applyFilters(args)
|
||||
if not os.path.isabs(args):
|
||||
args = os.path.join(self.context['DIRECTORY'], args)
|
||||
args = os.path.join(self.curdir, args)
|
||||
args = open(args, 'rU')
|
||||
except Preprocessor.Error:
|
||||
raise
|
||||
|
|
@ -757,15 +775,22 @@ class Preprocessor:
|
|||
oldFile = self.context['FILE']
|
||||
oldLine = self.context['LINE']
|
||||
oldDir = self.context['DIRECTORY']
|
||||
oldCurdir = self.curdir
|
||||
self.noteLineInfo()
|
||||
|
||||
if args.isatty():
|
||||
# we're stdin, use '-' and '' for file and dir
|
||||
self.context['FILE'] = '-'
|
||||
self.context['DIRECTORY'] = ''
|
||||
self.curdir = '.'
|
||||
else:
|
||||
abspath = os.path.abspath(args.name)
|
||||
self.curdir = os.path.dirname(abspath)
|
||||
self.includes.add(abspath)
|
||||
if self.topobjdir and path_starts_with(abspath, self.topobjdir):
|
||||
abspath = '$OBJDIR' + abspath[len(self.topobjdir):]
|
||||
elif self.topsrcdir and path_starts_with(abspath, self.topsrcdir):
|
||||
abspath = '$SRCDIR' + abspath[len(self.topsrcdir):]
|
||||
self.context['FILE'] = abspath
|
||||
self.context['DIRECTORY'] = os.path.dirname(abspath)
|
||||
self.context['LINE'] = 0
|
||||
|
|
@ -780,6 +805,7 @@ class Preprocessor:
|
|||
self.checkLineNumbers = oldCheckLineNumbers
|
||||
self.context['LINE'] = oldLine
|
||||
self.context['DIRECTORY'] = oldDir
|
||||
self.curdir = oldCurdir
|
||||
def do_includesubst(self, args):
|
||||
args = self.filter_substitution(args)
|
||||
self.do_include(args)
|
||||
|
|
|
|||
|
|
@ -148,8 +148,8 @@ class TestBuild(unittest.TestCase):
|
|||
|
||||
def validate(self, config):
|
||||
self.maxDiff = None
|
||||
test_path = os.path.join(os.path.dirname(os.path.abspath(__file__)),
|
||||
'data', 'build') + os.sep
|
||||
test_path = os.sep.join(('$SRCDIR', 'python', 'mozbuild', 'mozbuild',
|
||||
'test', 'backend', 'data', 'build')) + os.sep
|
||||
|
||||
# We want unicode instances out of the files, because having plain str
|
||||
# makes assertEqual diff output in case of error extra verbose because
|
||||
|
|
|
|||
|
|
@ -567,53 +567,67 @@ class TestPreprocessor(unittest.TestCase):
|
|||
|
||||
def test_include_line(self):
|
||||
files = {
|
||||
'test.js': '\n'.join([
|
||||
'srcdir/test.js': '\n'.join([
|
||||
'#define foo foobarbaz',
|
||||
'#include @inc@',
|
||||
'@bar@',
|
||||
'',
|
||||
]),
|
||||
'bar.js': '\n'.join([
|
||||
'srcdir/bar.js': '\n'.join([
|
||||
'#define bar barfoobaz',
|
||||
'@foo@',
|
||||
'',
|
||||
]),
|
||||
'foo.js': '\n'.join([
|
||||
'srcdir/foo.js': '\n'.join([
|
||||
'bazfoobar',
|
||||
'#include bar.js',
|
||||
'bazbarfoo',
|
||||
'',
|
||||
]),
|
||||
'baz.js': 'baz\n',
|
||||
'f.js': '\n'.join([
|
||||
'objdir/baz.js': 'baz\n',
|
||||
'srcdir/f.js': '\n'.join([
|
||||
'#include foo.js',
|
||||
'#filter substitution',
|
||||
'#define inc bar.js',
|
||||
'#include test.js',
|
||||
'#include baz.js',
|
||||
'#include ../objdir/baz.js',
|
||||
'fin',
|
||||
'',
|
||||
]),
|
||||
}
|
||||
|
||||
with MockedOpen(files):
|
||||
self.pp.do_include('f.js')
|
||||
self.assertEqual(self.pp.out.getvalue(),
|
||||
('//@line 1 "CWD/foo.js"\n'
|
||||
preprocessed = ('//@line 1 "$SRCDIR/foo.js"\n'
|
||||
'bazfoobar\n'
|
||||
'//@line 2 "CWD/bar.js"\n'
|
||||
'//@line 2 "$SRCDIR/bar.js"\n'
|
||||
'@foo@\n'
|
||||
'//@line 3 "CWD/foo.js"\n'
|
||||
'//@line 3 "$SRCDIR/foo.js"\n'
|
||||
'bazbarfoo\n'
|
||||
'//@line 2 "CWD/bar.js"\n'
|
||||
'//@line 2 "$SRCDIR/bar.js"\n'
|
||||
'foobarbaz\n'
|
||||
'//@line 3 "CWD/test.js"\n'
|
||||
'//@line 3 "$SRCDIR/test.js"\n'
|
||||
'barfoobaz\n'
|
||||
'//@line 1 "CWD/baz.js"\n'
|
||||
'//@line 1 "$OBJDIR/baz.js"\n'
|
||||
'baz\n'
|
||||
'//@line 6 "CWD/f.js"\n'
|
||||
'fin\n').replace('CWD/',
|
||||
os.getcwd() + os.path.sep))
|
||||
'//@line 6 "$SRCDIR/f.js"\n'
|
||||
'fin\n').replace('DIR/', 'DIR' + os.sep)
|
||||
|
||||
# Try with separate srcdir/objdir
|
||||
with MockedOpen(files):
|
||||
self.pp.topsrcdir = os.path.abspath('srcdir')
|
||||
self.pp.topobjdir = os.path.abspath('objdir')
|
||||
self.pp.do_include('srcdir/f.js')
|
||||
self.assertEqual(self.pp.out.getvalue(), preprocessed)
|
||||
|
||||
# Try again with relative objdir
|
||||
self.setUp()
|
||||
files['srcdir/objdir/baz.js'] = files['objdir/baz.js']
|
||||
del files['objdir/baz.js']
|
||||
files['srcdir/f.js'] = files['srcdir/f.js'].replace('../', '')
|
||||
with MockedOpen(files):
|
||||
self.pp.topsrcdir = os.path.abspath('srcdir')
|
||||
self.pp.topobjdir = os.path.abspath('srcdir/objdir')
|
||||
self.pp.do_include('srcdir/f.js')
|
||||
self.assertEqual(self.pp.out.getvalue(), preprocessed)
|
||||
|
||||
def test_include_missing_file(self):
|
||||
with MockedOpen({'f': '#include foo\n'}):
|
||||
|
|
|
|||
|
|
@ -188,8 +188,7 @@ class PreprocessorOutputWrapper(object):
|
|||
self._pp = preprocessor
|
||||
|
||||
def write(self, str):
|
||||
file = os.path.normpath(os.path.abspath(self._pp.context['FILE']))
|
||||
with errors.context(file, self._pp.context['LINE']):
|
||||
with errors.context(self._pp.context['FILE'], self._pp.context['LINE']):
|
||||
self._parser.handle_line(str)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
import unittest
|
||||
import mozunit
|
||||
import os
|
||||
from buildconfig import topobjdir
|
||||
from mozpack.packager import (
|
||||
preprocess_manifest,
|
||||
CallDeque,
|
||||
|
|
@ -43,7 +44,7 @@ baz@SUFFIX@
|
|||
|
||||
|
||||
class TestPreprocessManifest(unittest.TestCase):
|
||||
MANIFEST_PATH = os.path.join(os.path.abspath(os.curdir), 'manifest')
|
||||
MANIFEST_PATH = os.path.join('$OBJDIR', 'manifest')
|
||||
|
||||
EXPECTED_LOG = [
|
||||
((MANIFEST_PATH, 2), 'add', '', 'bar/*'),
|
||||
|
|
@ -68,6 +69,11 @@ class TestPreprocessManifest(unittest.TestCase):
|
|||
self.log.append(args)
|
||||
|
||||
self.sink = MockSink()
|
||||
self.cwd = os.getcwd()
|
||||
os.chdir(topobjdir)
|
||||
|
||||
def tearDown(self):
|
||||
os.chdir(self.cwd)
|
||||
|
||||
def test_preprocess_manifest(self):
|
||||
with MockedOpen({'manifest': MANIFEST}):
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue