Merge the last green changeset on mozilla-inbound to mozilla-central

This commit is contained in:
Ehsan Akhgari 2011-07-12 14:30:24 -04:00
Родитель bbef6d1373 eb8a060ff4
Коммит 16c06707b7
16 изменённых файлов: 775 добавлений и 162 удалений

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

@ -1068,6 +1068,8 @@ nsCanvasRenderingContext2D::SetDimensions(PRInt32 width, PRInt32 height)
mZero = PR_TRUE;
height = 1;
width = 1;
} else {
mZero = PR_FALSE;
}
gfxASurface::gfxImageFormat format = GetImageFormat();

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

@ -1226,6 +1226,8 @@ nsCanvasRenderingContext2DAzure::SetDimensions(PRInt32 width, PRInt32 height)
mZero = PR_TRUE;
height = 1;
width = 1;
} else {
mZero = PR_FALSE;
}
// Check that the dimensions are sane

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

@ -21392,6 +21392,27 @@ function test_zero_dimensions_imagedata() {
}
</script>
<p>Canvas test: getImageData_after_zero_canvas</p>
<canvas id="c686" width="100" height="100"></canvas>
<script type="text/javascript">
function test_getImageData_after_zero_canvas() {
var c = document.getElementById("c686");
var ctx = c.getContext("2d");
ctx.fillStyle = "rgba(0, 0, 0, 1.0)";
ctx.fillRect(0, 0, c.width, c.height);
var oldimgdata = ctx.getImageData(0, 0, c.width, c.height);
c.width = c.height = 0;
c.width = c.height = 100;
ctx.fillRect(0, 0, c.width, c.height);
var imgdata = ctx.getImageData(0, 0, c.width, c.height);
var same = false;
ok(imgdata.data.length === oldimgdata.data.length, "not the same length");
for (var i = 0; i < imgdata.data.length; ++i)
same = imgdata.data[i] === oldimgdata.data[i];
ok(same, "changing dimensions broke canvas");
}
</script>
<script>
function asyncTestsDone() {
@ -24661,6 +24682,12 @@ function runTests() {
} catch(e) {
ok(false, "unexpected exception thrown in: test_zero_dimensions_imagedata");
}
try {
test_getImageData_after_zero_canvas();
} catch(e) {
throw e;
ok(false, "unexpected exception thrown in: test_getImageData_after_zero_canvas");
}
try {
// run this test last since it replaces the getContext method
test_type_replace();

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

@ -55,11 +55,11 @@
using namespace mozilla;
#ifdef PR_LOGGING
static PRLogModuleInfo *gUserFontsLog = PR_NewLogModule("userfonts");
PRLogModuleInfo *gfxUserFontSet::sUserFontsLog = PR_NewLogModule("userfonts");
#endif /* PR_LOGGING */
#define LOG(args) PR_LOG(gUserFontsLog, PR_LOG_DEBUG, args)
#define LOG_ENABLED() PR_LOG_TEST(gUserFontsLog, PR_LOG_DEBUG)
#define LOG(args) PR_LOG(sUserFontsLog, PR_LOG_DEBUG, args)
#define LOG_ENABLED() PR_LOG_TEST(sUserFontsLog, PR_LOG_DEBUG)
static PRUint64 sFontSetGeneration = LL_INIT(0, 0);
@ -445,7 +445,7 @@ CopyWOFFMetadata(const PRUint8* aFontData, PRUint32 aLength,
// ensure that it is eventually deleted via NS_Free().
PRBool
gfxUserFontSet::OnLoadComplete(gfxProxyFontEntry *aProxy,
const PRUint8 *aFontData, PRUint32 aLength,
const PRUint8 *aFontData, PRUint32 aLength,
nsresult aDownloadStatus)
{
// download successful, make platform font using font data
@ -482,14 +482,9 @@ gfxUserFontSet::OnLoadComplete(gfxProxyFontEntry *aProxy,
const PRUint8* saneData =
SanitizeOpenTypeData(aFontData, aLength, saneLen,
fontType == GFX_USERFONT_WOFF);
#ifdef DEBUG
if (!saneData) {
char buf[1000];
sprintf(buf, "downloaded font rejected for \"%s\"",
NS_ConvertUTF16toUTF8(aProxy->FamilyName()).get());
NS_WARNING(buf);
LogMessage(aProxy, "rejected by sanitizer");
}
#endif
if (saneData) {
// The sanitizer ensures that we have a valid sfnt and a usable
// name table, so this should never fail unless we're out of
@ -503,7 +498,7 @@ gfxUserFontSet::OnLoadComplete(gfxProxyFontEntry *aProxy,
saneData,
saneLen);
if (!fe) {
NS_WARNING("failed to make platform font from download");
LogMessage(aProxy, "not usable by platform");
}
}
} else {
@ -523,11 +518,14 @@ gfxUserFontSet::OnLoadComplete(gfxProxyFontEntry *aProxy,
fe = gfxPlatform::GetPlatform()->MakePlatformFont(aProxy,
aFontData,
aLength);
if (!fe) {
LogMessage(aProxy, "not usable by platform");
}
aFontData = nsnull; // we must NOT free this below!
} else {
// the data was unusable, so just discard it
// (error will be reported below, if logging is enabled)
NS_WARNING("failed to make platform font from download");
LogMessage(aProxy, "SFNT header or tables invalid");
}
}
}
@ -572,16 +570,8 @@ gfxUserFontSet::OnLoadComplete(gfxProxyFontEntry *aProxy,
}
} else {
// download failed
#ifdef PR_LOGGING
if (LOG_ENABLED()) {
nsCAutoString fontURI;
aProxy->mSrcList[aProxy->mSrcIndex].mURI->GetSpec(fontURI);
LOG(("userfonts (%p) [src %d] failed uri: (%s) for (%s) error %8.8x downloading font data\n",
this, aProxy->mSrcIndex, fontURI.get(),
NS_ConvertUTF16toUTF8(aProxy->mFamily->Name()).get(),
aDownloadStatus));
}
#endif
LogMessage(aProxy, "download failed", nsIScriptError::errorFlag,
aDownloadStatus);
}
if (aFontData) {
@ -606,7 +596,8 @@ gfxUserFontSet::LoadNext(gfxProxyFontEntry *aProxyEntry)
{
PRUint32 numSrc = aProxyEntry->mSrcList.Length();
NS_ASSERTION(aProxyEntry->mSrcIndex < numSrc, "already at the end of the src list for user font");
NS_ASSERTION(aProxyEntry->mSrcIndex < numSrc,
"already at the end of the src list for user font");
if (aProxyEntry->mLoadingState == gfxProxyFontEntry::NOT_LOADING) {
aProxyEntry->mLoadingState = gfxProxyFontEntry::LOADING_STARTED;
@ -617,21 +608,22 @@ gfxUserFontSet::LoadNext(gfxProxyFontEntry *aProxyEntry)
aProxyEntry->mSrcIndex++;
}
// load each src entry in turn, until a local face is found or a download begins successfully
// load each src entry in turn, until a local face is found
// or a download begins successfully
while (aProxyEntry->mSrcIndex < numSrc) {
const gfxFontFaceSrc& currSrc = aProxyEntry->mSrcList[aProxyEntry->mSrcIndex];
// src local ==> lookup and load
// src local ==> lookup and load
if (currSrc.mIsLocal) {
gfxFontEntry *fe =
gfxPlatform::GetPlatform()->LookupLocalFont(aProxyEntry,
currSrc.mLocalName);
if (fe) {
LOG(("userfonts (%p) [src %d] loaded local: (%s) for (%s) gen: %8.8x\n",
this, aProxyEntry->mSrcIndex,
NS_ConvertUTF16toUTF8(currSrc.mLocalName).get(),
NS_ConvertUTF16toUTF8(aProxyEntry->mFamily->Name()).get(),
LOG(("userfonts (%p) [src %d] loaded local: (%s) for (%s) gen: %8.8x\n",
this, aProxyEntry->mSrcIndex,
NS_ConvertUTF16toUTF8(currSrc.mLocalName).get(),
NS_ConvertUTF16toUTF8(aProxyEntry->mFamily->Name()).get(),
PRUint32(mGeneration)));
fe->mFeatureSettings.AppendElements(aProxyEntry->mFeatureSettings);
fe->mLanguageOverride = aProxyEntry->mLanguageOverride;
@ -639,52 +631,37 @@ gfxUserFontSet::LoadNext(gfxProxyFontEntry *aProxyEntry)
ReplaceFontEntry(aProxyEntry, fe);
return STATUS_LOADED;
} else {
LOG(("userfonts (%p) [src %d] failed local: (%s) for (%s)\n",
this, aProxyEntry->mSrcIndex,
NS_ConvertUTF16toUTF8(currSrc.mLocalName).get(),
NS_ConvertUTF16toUTF8(aProxyEntry->mFamily->Name()).get()));
LOG(("userfonts (%p) [src %d] failed local: (%s) for (%s)\n",
this, aProxyEntry->mSrcIndex,
NS_ConvertUTF16toUTF8(currSrc.mLocalName).get(),
NS_ConvertUTF16toUTF8(aProxyEntry->mFamily->Name()).get()));
}
}
}
// src url ==> start the load process
else {
if (gfxPlatform::GetPlatform()->IsFontFormatSupported(currSrc.mURI,
if (gfxPlatform::GetPlatform()->IsFontFormatSupported(currSrc.mURI,
currSrc.mFormatFlags)) {
nsresult rv = StartLoad(aProxyEntry, &currSrc);
PRBool loadOK = NS_SUCCEEDED(rv);
if (loadOK) {
#ifdef PR_LOGGING
if (LOG_ENABLED()) {
nsCAutoString fontURI;
currSrc.mURI->GetSpec(fontURI);
LOG(("userfonts (%p) [src %d] loading uri: (%s) for (%s)\n",
this, aProxyEntry->mSrcIndex, fontURI.get(),
LOG(("userfonts (%p) [src %d] loading uri: (%s) for (%s)\n",
this, aProxyEntry->mSrcIndex, fontURI.get(),
NS_ConvertUTF16toUTF8(aProxyEntry->mFamily->Name()).get()));
}
#endif
return STATUS_LOADING;
return STATUS_LOADING;
} else {
#ifdef PR_LOGGING
if (LOG_ENABLED()) {
nsCAutoString fontURI;
currSrc.mURI->GetSpec(fontURI);
LOG(("userfonts (%p) [src %d] failed uri: (%s) for (%s) download failed\n",
this, aProxyEntry->mSrcIndex, fontURI.get(),
NS_ConvertUTF16toUTF8(aProxyEntry->mFamily->Name()).get()));
}
#endif
LogMessage(aProxyEntry, "download failed",
nsIScriptError::errorFlag, rv);
}
} else {
#ifdef PR_LOGGING
if (LOG_ENABLED()) {
nsCAutoString fontURI;
currSrc.mURI->GetSpec(fontURI);
LOG(("userfonts (%p) [src %d] failed uri: (%s) for (%s) format not supported\n",
this, aProxyEntry->mSrcIndex, fontURI.get(),
NS_ConvertUTF16toUTF8(aProxyEntry->mFamily->Name()).get()));
}
#endif
LogMessage(aProxyEntry, "format not supported",
nsIScriptError::warningFlag);
}
}
@ -692,8 +669,8 @@ gfxUserFontSet::LoadNext(gfxProxyFontEntry *aProxyEntry)
}
// all src's failed; mark this entry as unusable (so fallback will occur)
LOG(("userfonts (%p) failed all src for (%s)\n",
this, NS_ConvertUTF16toUTF8(aProxyEntry->mFamily->Name()).get()));
LOG(("userfonts (%p) failed all src for (%s)\n",
this, NS_ConvertUTF16toUTF8(aProxyEntry->mFamily->Name()).get()));
aProxyEntry->mLoadingState = gfxProxyFontEntry::LOADING_FAILED;
return STATUS_END_OF_LIST;

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

@ -47,6 +47,7 @@
#include "nsIURI.h"
#include "nsIFile.h"
#include "nsISupportsImpl.h"
#include "nsIScriptError.h"
class nsIURI;
class gfxMixedFontFamily;
@ -252,10 +253,18 @@ protected:
gfxMixedFontFamily *GetFamily(const nsAString& aName) const;
// report a problem of some kind (implemented in nsUserFontSet)
virtual nsresult LogMessage(gfxProxyFontEntry *aProxy,
const char *aMessage,
PRUint32 aFlags = nsIScriptError::errorFlag,
nsresult aStatus = 0) = 0;
// font families defined by @font-face rules
nsRefPtrHashtable<nsStringHashKey, gfxMixedFontFamily> mFontFamilies;
PRUint64 mGeneration;
static PRLogModuleInfo *sUserFontsLog;
};
// acts a placeholder until the real font is downloaded

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

@ -0,0 +1,40 @@
<!DOCTYPE html>
<html>
<body>
<div>
<canvas id="c1" width="400" height="400"></canvas>
<canvas id="c2" width="400" height="400"></canvas>
</div>
<script type="text/javascript">
var canv1 = document.getElementById('c1');
var canv2 = document.getElementById('c2');
var ctx1 = canv1.getContext('2d');
var ctx2 = canv2.getContext('2d');
ctx1.strokeStyle = '#FF0000';
ctx1.moveTo(10, 10);
ctx1.lineTo(390, 390);
ctx1.stroke();
function doTest()
{
// Save img data
var imgData = ctx1.getImageData(0, 0, canv1.width, canv1.height);
// Resize canvas - seems to cause the bug
canv1.width = 0;
canv1.height = 0;
canv1.width = 400;
canv1.height = 400;
// Put image data from ctx1 to ctx2
ctx2.putImageData(imgData, 0, 0);
// Draw canvas2 on canvas1
ctx1.drawImage(canv2, 0, 0);
};
doTest();
</script>
</body>
</html>

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

@ -0,0 +1,41 @@
<!DOCTYPE html>
<html>
<body>
<div>
<canvas id="c1" width="400" height="400"></canvas>
<canvas id="c2" width="400" height="400"></canvas>
</div>
<script type="text/javascript">
var canv1 = document.getElementById('c1');
var canv2 = document.getElementById('c2');
var ctx1 = canv1.getContext('2d');
var ctx2 = canv2.getContext('2d');
ctx1.strokeStyle = '#FF0000';
ctx1.moveTo(10, 10);
ctx1.lineTo(390, 390);
ctx1.stroke();
function doTest()
{
// Save img data
var imgData = ctx1.getImageData(0, 0, canv1.width, canv1.height);
// Resize canvas - seems to cause the bug
canv1.width = 0;
canv1.height = 0;
canv1.width = 400;
canv1.height = 400;
// Put image data from ctx1 to ctx2
ctx2.putImageData(imgData, 0, 0);
// Draw canvas2 on canvas1
ctx1.drawImage(canv2, 0, 0);
};
doTest();
doTest();
</script>
</body>
</html>

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

@ -1651,3 +1651,4 @@ fails-if(layersGPUAccelerated&&cocoaWidget) == 654950-1.html 654950-1-ref.html #
== 660682-1.html 660682-1-ref.html
!= 669015-1.xul 669015-1-notref.xul
== 668319-1.xul about:blank
== 670442-1.html 670442-1-ref.html

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

@ -73,6 +73,8 @@
#include "nsIChannelPolicy.h"
#include "nsChannelPolicy.h"
#include "nsIConsoleService.h"
#include "nsStyleSet.h"
using namespace mozilla;
@ -342,17 +344,7 @@ nsUserFontSet::StartLoad(gfxProxyFontEntry *aProxy,
rv = nsFontFaceLoader::CheckLoadAllowed(principal, aFontFaceSrc->mURI,
ps->GetDocument());
if (NS_FAILED(rv)) {
#ifdef PR_LOGGING
if (LOG_ENABLED()) {
nsCAutoString fontURI, referrerURI;
aFontFaceSrc->mURI->GetSpec(fontURI);
if (aFontFaceSrc->mReferrer)
aFontFaceSrc->mReferrer->GetSpec(referrerURI);
LOG(("fontdownloader download blocked - font uri: (%s) "
"referrer uri: (%s) err: %8.8x\n",
fontURI.get(), referrerURI.get(), rv));
}
#endif
LogMessage(aProxy, "download not allowed", nsIScriptError::errorFlag, rv);
return rv;
}
@ -697,3 +689,105 @@ nsUserFontSet::FindRuleForEntry(gfxFontEntry *aFontEntry)
}
return nsnull;
}
nsresult
nsUserFontSet::LogMessage(gfxProxyFontEntry *aProxy,
const char *aMessage,
PRUint32 aFlags,
nsresult aStatus)
{
nsCOMPtr<nsIConsoleService>
console(do_GetService(NS_CONSOLESERVICE_CONTRACTID));
if (!console) {
return NS_ERROR_NOT_AVAILABLE;
}
NS_ConvertUTF16toUTF8 familyName(aProxy->FamilyName());
nsCAutoString fontURI;
aProxy->mSrcList[aProxy->mSrcIndex].mURI->GetSpec(fontURI);
char weightKeywordBuf[8]; // plenty to sprintf() a PRUint16
const char *weightKeyword;
const nsAFlatCString& weightKeywordString =
nsCSSProps::ValueToKeyword(aProxy->Weight(),
nsCSSProps::kFontWeightKTable);
if (weightKeywordString.Length() > 0) {
weightKeyword = weightKeywordString.get();
} else {
sprintf(weightKeywordBuf, "%u", aProxy->Weight());
weightKeyword = weightKeywordBuf;
}
nsPrintfCString
msg(1024,
"downloadable font: %s "
"(font-family: \"%s\" style:%s weight:%s stretch:%s src index:%d)",
aMessage,
familyName.get(),
aProxy->IsItalic() ? "italic" : "normal",
weightKeyword,
nsCSSProps::ValueToKeyword(aProxy->Stretch(),
nsCSSProps::kFontStretchKTable).get(),
aProxy->mSrcIndex);
if (aStatus != 0) {
msg.Append(": ");
switch (aStatus) {
case NS_ERROR_DOM_BAD_URI:
msg.Append("bad URI or cross-site access not allowed");
break;
case NS_ERROR_CONTENT_BLOCKED:
msg.Append("content blocked");
break;
default:
msg.Append("status=");
msg.AppendInt(aStatus);
break;
}
}
msg.Append("\nsource: ");
msg.Append(fontURI);
#ifdef PR_LOGGING
if (PR_LOG_TEST(sUserFontsLog, PR_LOG_DEBUG)) {
PR_LOG(sUserFontsLog, PR_LOG_DEBUG,
("userfonts (%p) %s", this, msg.get()));
}
#endif
// try to give the user an indication of where the rule came from
nsCSSFontFaceRule* rule = FindRuleForEntry(aProxy);
nsString href;
nsString text;
nsresult rv;
if (rule) {
rv = rule->GetCssText(text);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDOMCSSStyleSheet> sheet;
rv = rule->GetParentStyleSheet(getter_AddRefs(sheet));
NS_ENSURE_SUCCESS(rv, rv);
rv = sheet->GetHref(href);
NS_ENSURE_SUCCESS(rv, rv);
}
nsCOMPtr<nsIScriptError2> scriptError =
do_CreateInstance(NS_SCRIPTERROR_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
PRUint64 windowID = GetPresContext()->Document()->OuterWindowID();
rv = scriptError->InitWithWindowID(NS_ConvertUTF8toUTF16(msg).get(),
href.get(), // file
text.get(), // src line
0, 0, // line & column number
aFlags, // flags
"CSS Loader", // category (make separate?)
windowID);
if (NS_SUCCEEDED(rv)){
nsCOMPtr<nsIScriptError> logError = do_QueryInterface(scriptError);
if (logError) {
console->LogMessage(logError);
}
}
return NS_OK;
}

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

@ -102,6 +102,11 @@ protected:
nsTArray<FontFaceRuleRecord>& oldRules,
PRBool& aFontSetModified);
virtual nsresult LogMessage(gfxProxyFontEntry *aProxy,
const char *aMessage,
PRUint32 aFlags = nsIScriptError::errorFlag,
nsresult aStatus = 0);
nsPresContext *mPresContext; // weak reference
// Set of all loaders pointing to us. These are not strong pointers,

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

@ -484,6 +484,8 @@ nsStandardURL::AppendSegmentToBuf(char *buf, PRUint32 i, const char *str, URLSeg
memcpy(buf + i, str + seg.mPos, seg.mLen);
seg.mPos = i;
i += seg.mLen;
} else {
seg.mPos = i;
}
return i;
}
@ -832,6 +834,8 @@ nsStandardURL::ParseURL(const char *spec, PRInt32 specLen)
nsresult
nsStandardURL::ParsePath(const char *spec, PRUint32 pathPos, PRInt32 pathLen)
{
LOG(("ParsePath: %s pathpos %d len %d\n",spec,pathPos,pathLen));
nsresult rv = mParser->ParsePath(spec + pathPos, pathLen,
&mFilepath.mPos, &mFilepath.mLen,
&mParam.mPos, &mParam.mLen,

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

@ -426,6 +426,8 @@ nsNoAuthURLParser::ParseAfterScheme(const char *spec, PRInt32 specLen,
#if defined(XP_WIN) || defined(XP_OS2)
// if the authority looks like a drive number then we
// really want to treat it as part of the path
// [a-zA-Z][:|]{/\}
// i.e one of: c: c:\foo c:/foo c| c|\foo c|/foo
if ((specLen > 3) && (spec[3] == ':' || spec[3] == '|') &&
nsCRT::IsAsciiAlpha(spec[2]) &&
((specLen == 4) || (spec[4] == '/') || (spec[4] == '\\'))) {
@ -433,16 +435,17 @@ nsNoAuthURLParser::ParseAfterScheme(const char *spec, PRInt32 specLen,
break;
}
#endif
p = (const char *) memchr(spec + 2, '/', specLen - 2);
// Ignore apparent authority; path is everything after it
for (p = spec + 2; p < spec + specLen; ++p) {
if (*p == '/' || *p == '?' || *p == '#' || *p == ';')
break;
}
}
if (p) {
SET_RESULT(auth, 0, -1);
SET_RESULT(auth, 0, -1);
if (p && p != spec+specLen)
SET_RESULT(path, p - spec, specLen - (p - spec));
}
else {
SET_RESULT(auth, 0, -1);
else
SET_RESULT(path, 0, -1);
}
return;
}
default:

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

@ -1,6 +1,15 @@
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
Components.utils.import("resource://gre/modules/NetUtil.jsm");
const Ci = Components.interfaces;
const Cr = Components.results;
var gIoService = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
// Relevant RFCs: 1738, 1808, 2396, 3986 (newer than the code)
// http://greenbytes.de/tech/webdav/rfc3986.html#rfc.section.5.4
// http://greenbytes.de/tech/tc/uris/
// TEST DATA
// ---------
@ -29,12 +38,25 @@ var gTests = [
path: "text/html;charset=utf-8,<html></html>",
ref: "",
nsIURL: false, nsINestedURI: false },
{ spec: "data:text/html;charset=utf-8,<html>\r\n\t</html>",
scheme: "data",
prePath: "data:",
path: "text/html;charset=utf-8,<html></html>",
ref: "",
nsIURL: false, nsINestedURI: false },
{ spec: "data:text/plain,hello world",
scheme: "data",
prePath: "data:",
path: "text/plain,hello%20world",
ref: "",
nsIURL: false, nsINestedURI: false },
{ spec: "file:///dir/afile",
scheme: "data",
prePath: "data:",
path: "text/plain,2",
ref: "",
relativeURI: "data:te\nxt/plain,2",
nsIURL: false, nsINestedURI: false },
{ spec: "file://",
scheme: "file",
prePath: "file://",
@ -53,6 +75,20 @@ var gTests = [
path: "/myFile.html",
ref: "",
nsIURL: true, nsINestedURI: false },
{ spec: "file:///dir/afile",
scheme: "file",
prePath: "file://",
path: "/dir/data/text/plain,2",
ref: "",
relativeURI: "data/text/plain,2",
nsIURL: true, nsINestedURI: false },
{ spec: "file:///dir/dir2/",
scheme: "file",
prePath: "file://",
path: "/dir/dir2/data/text/plain,2",
ref: "",
relativeURI: "data/text/plain,2",
nsIURL: true, nsINestedURI: false },
{ spec: "ftp://",
scheme: "ftp",
prePath: "ftp://",
@ -74,6 +110,9 @@ var gTests = [
{ spec: "ftp://foo:bar@ftp.mozilla.org:100/pub/mozilla.org/README",
scheme: "ftp",
prePath: "ftp://foo:bar@ftp.mozilla.org:100",
port: 100,
username: "foo",
password: "bar",
path: "/pub/mozilla.org/README",
ref: "",
nsIURL: true, nsINestedURI: false },
@ -101,6 +140,44 @@ var gTests = [
path: "/",
ref: "",
nsIURL: true, nsINestedURI: false },
{ spec: "http://www.exa\nmple.com/",
scheme: "http",
prePath: "http://www.example.com",
path: "/",
ref: "",
nsIURL: true, nsINestedURI: false },
{ spec: "http://10.32.4.239/",
scheme: "http",
prePath: "http://10.32.4.239",
host: "10.32.4.239",
path: "/",
ref: "",
nsIURL: true, nsINestedURI: false },
{ spec: "http://[::192.9.5.5]/ipng",
scheme: "http",
prePath: "http://[::192.9.5.5]",
host: "::192.9.5.5",
path: "/ipng",
ref: "",
nsIURL: true, nsINestedURI: false },
{ spec: "http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:8888/index.html",
scheme: "http",
prePath: "http://[fedc:ba98:7654:3210:fedc:ba98:7654:3210]:8888",
host: "fedc:ba98:7654:3210:fedc:ba98:7654:3210",
port: 8888,
path: "/index.html",
ref: "",
nsIURL: true, nsINestedURI: false },
{ spec: "http://bar:foo@www.mozilla.org:8080/pub/mozilla.org/README.html",
scheme: "http",
prePath: "http://bar:foo@www.mozilla.org:8080",
port: 8080,
username: "bar",
password: "foo",
host: "www.mozilla.org",
path: "/pub/mozilla.org/README.html",
ref: "",
nsIURL: true, nsINestedURI: false },
{ spec: "jar:resource://!/",
scheme: "jar",
prePath: "jar:",
@ -173,6 +250,284 @@ var gTests = [
path: "abc",
ref: "",
nsIURL: false, nsINestedURI: false },
{ spec: "http://www2.example.com/",
relativeURI: "a/b/c/d",
scheme: "http",
prePath: "http://www2.example.com",
path: "/a/b/c/d",
ref: "",
nsIURL: true, nsINestedURI: false },
// relative URL testcases from http://greenbytes.de/tech/webdav/rfc3986.html#rfc.section.5.4
{ spec: "http://a/b/c/d;p?q",
relativeURI: "g:h",
scheme: "g",
prePath: "g:",
path: "h",
ref: "",
nsIURL: false, nsINestedURI: false },
{ spec: "http://a/b/c/d;p?q",
relativeURI: "g",
scheme: "http",
prePath: "http://a",
path: "/b/c/g",
ref: "",
nsIURL: true, nsINestedURI: false },
{ spec: "http://a/b/c/d;p?q",
relativeURI: "./g",
scheme: "http",
prePath: "http://a",
path: "/b/c/g",
ref: "",
nsIURL: true, nsINestedURI: false },
{ spec: "http://a/b/c/d;p?q",
relativeURI: "g/",
scheme: "http",
prePath: "http://a",
path: "/b/c/g/",
ref: "",
nsIURL: true, nsINestedURI: false },
{ spec: "http://a/b/c/d;p?q",
relativeURI: "/g",
scheme: "http",
prePath: "http://a",
path: "/g",
ref: "",
nsIURL: true, nsINestedURI: false },
{ spec: "http://a/b/c/d;p?q",
relativeURI: "?y",
scheme: "http",
prePath: "http://a",
path: "/b/c/d;p?y",
ref: "",// fix
nsIURL: true, nsINestedURI: false },
{ spec: "http://a/b/c/d;p?q",
relativeURI: "g?y",
scheme: "http",
prePath: "http://a",
path: "/b/c/g?y",
ref: "",// fix
nsIURL: true, nsINestedURI: false },
{ spec: "http://a/b/c/d;p?q",
relativeURI: "#s",
scheme: "http",
prePath: "http://a",
path: "/b/c/d;p?q#s",
ref: "s",// fix
nsIURL: true, nsINestedURI: false },
{ spec: "http://a/b/c/d;p?q",
relativeURI: "g#s",
scheme: "http",
prePath: "http://a",
path: "/b/c/g#s",
ref: "s",
nsIURL: true, nsINestedURI: false },
{ spec: "http://a/b/c/d;p?q",
relativeURI: "g?y#s",
scheme: "http",
prePath: "http://a",
path: "/b/c/g?y#s",
ref: "s",
nsIURL: true, nsINestedURI: false },
/*
Bug xxxxxx - we return a path of b/c/;x
{ spec: "http://a/b/c/d;p?q",
relativeURI: ";x",
scheme: "http",
prePath: "http://a",
path: "/b/c/d;x",
ref: "",
nsIURL: true, nsINestedURI: false },
*/
{ spec: "http://a/b/c/d;p?q",
relativeURI: "g;x",
scheme: "http",
prePath: "http://a",
path: "/b/c/g;x",
ref: "",
nsIURL: true, nsINestedURI: false },
{ spec: "http://a/b/c/d;p?q",
relativeURI: "g;x?y#s",
scheme: "http",
prePath: "http://a",
path: "/b/c/g;x?y#s",
ref: "s",
nsIURL: true, nsINestedURI: false },
/*
Can't easily specify a relative URI of "" to the test code
{ spec: "http://a/b/c/d;p?q",
relativeURI: "",
scheme: "http",
prePath: "http://a",
path: "/b/c/d",
ref: "",
nsIURL: true, nsINestedURI: false },
*/
{ spec: "http://a/b/c/d;p?q",
relativeURI: ".",
scheme: "http",
prePath: "http://a",
path: "/b/c/",
ref: "",
nsIURL: true, nsINestedURI: false },
{ spec: "http://a/b/c/d;p?q",
relativeURI: "./",
scheme: "http",
prePath: "http://a",
path: "/b/c/",
ref: "",
nsIURL: true, nsINestedURI: false },
{ spec: "http://a/b/c/d;p?q",
relativeURI: "..",
scheme: "http",
prePath: "http://a",
path: "/b/",
ref: "",
nsIURL: true, nsINestedURI: false },
{ spec: "http://a/b/c/d;p?q",
relativeURI: "../",
scheme: "http",
prePath: "http://a",
path: "/b/",
ref: "",
nsIURL: true, nsINestedURI: false },
{ spec: "http://a/b/c/d;p?q",
relativeURI: "../g",
scheme: "http",
prePath: "http://a",
path: "/b/g",
ref: "",
nsIURL: true, nsINestedURI: false },
{ spec: "http://a/b/c/d;p?q",
relativeURI: "../..",
scheme: "http",
prePath: "http://a",
path: "/",
ref: "",
nsIURL: true, nsINestedURI: false },
{ spec: "http://a/b/c/d;p?q",
relativeURI: "../../",
scheme: "http",
prePath: "http://a",
path: "/",
ref: "",
nsIURL: true, nsINestedURI: false },
{ spec: "http://a/b/c/d;p?q",
relativeURI: "../../g",
scheme: "http",
prePath: "http://a",
path: "/g",
ref: "",
nsIURL: true, nsINestedURI: false },
// abnormal examples
{ spec: "http://a/b/c/d;p?q",
relativeURI: "../../../g",
scheme: "http",
prePath: "http://a",
path: "/g",
ref: "",
nsIURL: true, nsINestedURI: false },
{ spec: "http://a/b/c/d;p?q",
relativeURI: "../../../../g",
scheme: "http",
prePath: "http://a",
path: "/g",
ref: "",
nsIURL: true, nsINestedURI: false },
// coalesce
{ spec: "http://a/b/c/d;p?q",
relativeURI: "/./g",
scheme: "http",
prePath: "http://a",
path: "/g",
ref: "",
nsIURL: true, nsINestedURI: false },
{ spec: "http://a/b/c/d;p?q",
relativeURI: "/../g",
scheme: "http",
prePath: "http://a",
path: "/g",
ref: "",
nsIURL: true, nsINestedURI: false },
{ spec: "http://a/b/c/d;p?q",
relativeURI: "g.",
scheme: "http",
prePath: "http://a",
path: "/b/c/g.",
ref: "",
nsIURL: true, nsINestedURI: false },
{ spec: "http://a/b/c/d;p?q",
relativeURI: ".g",
scheme: "http",
prePath: "http://a",
path: "/b/c/.g",
ref: "",
nsIURL: true, nsINestedURI: false },
{ spec: "http://a/b/c/d;p?q",
relativeURI: "g..",
scheme: "http",
prePath: "http://a",
path: "/b/c/g..",
ref: "",
nsIURL: true, nsINestedURI: false },
{ spec: "http://a/b/c/d;p?q",
relativeURI: "..g",
scheme: "http",
prePath: "http://a",
path: "/b/c/..g",
ref: "",
nsIURL: true, nsINestedURI: false },
{ spec: "http://a/b/c/d;p?q",
relativeURI: ".",
scheme: "http",
prePath: "http://a",
path: "/b/c/",
ref: "",
nsIURL: true, nsINestedURI: false },
{ spec: "http://a/b/c/d;p?q",
relativeURI: "./../g",
scheme: "http",
prePath: "http://a",
path: "/b/g",
ref: "",
nsIURL: true, nsINestedURI: false },
{ spec: "http://a/b/c/d;p?q",
relativeURI: "./g/.",
scheme: "http",
prePath: "http://a",
path: "/b/c/g/",
ref: "",
nsIURL: true, nsINestedURI: false },
{ spec: "http://a/b/c/d;p?q",
relativeURI: "g/./h",
scheme: "http",
prePath: "http://a",
path: "/b/c/g/h",
ref: "",
nsIURL: true, nsINestedURI: false },
{ spec: "http://a/b/c/d;p?q",
relativeURI: "g/../h",
scheme: "http",
prePath: "http://a",
path: "/b/c/h",
ref: "",// fix
nsIURL: true, nsINestedURI: false },
{ spec: "http://a/b/c/d;p?q",
relativeURI: "g;x=1/./y",
scheme: "http",
prePath: "http://a",
path: "/b/c/g;x=1/y",
ref: "",
nsIURL: true, nsINestedURI: false },
{ spec: "http://a/b/c/d;p?q",
relativeURI: "g;x=1/../y",
scheme: "http",
prePath: "http://a",
path: "/b/c/y",
ref: "",
nsIURL: true, nsINestedURI: false },
];
var gHashSuffixes = [
@ -239,24 +594,57 @@ function do_check_uri_eqExceptRef(aURI1, aURI2, aCheckTrueFunc) {
// in the test bundle (or matches some function of that corresponding property,
// if aTestFunctor is passed in).
function do_check_property(aTest, aURI, aPropertyName, aTestFunctor) {
var expectedVal = aTestFunctor ?
aTestFunctor(aTest[aPropertyName]) :
aTest[aPropertyName];
if (aTest[aPropertyName]) {
var expectedVal = aTestFunctor ?
aTestFunctor(aTest[aPropertyName]) :
aTest[aPropertyName];
do_info("testing " + aPropertyName + " of " +
(aTestFunctor ? "modified '" : "'" ) + aTest.spec +
"' is '" + expectedVal + "'");
do_check_eq(aURI[aPropertyName], expectedVal);
do_info("testing " + aPropertyName + " of " +
(aTestFunctor ? "modified '" : "'" ) + aTest.spec +
"' is '" + expectedVal + "'");
do_check_eq(aURI[aPropertyName], expectedVal);
}
}
// Test that a given URI parses correctly into its various components.
function do_test_uri_basic(aTest) {
var URI = NetUtil.newURI(aTest.spec);
var URI;
do_info("Basic tests for " + aTest.spec + " relative URI: " + aTest.relativeURI);
try {
URI = NetUtil.newURI(aTest.spec);
} catch(e) {
do_info("Caught error on parse of" + aTest.spec + " Error: " + e.result);
if (aTest.fail) {
do_check_eq(e.result, aTest.result);
return;
}
do_throw(e.result);
}
if (aTest.relativeURI) {
var relURI;
try {
relURI = gIoService.newURI(aTest.relativeURI, null, URI);
} catch (e) {
do_info("Caught error on Relative parse of " + aTest.spec + " + " + aTest.relativeURI +" Error: " + e.result);
if (aTest.relativeFail) {
do_check_eq(e.result, aTest.relativeFail);
return;
}
do_throw(e.result);
}
do_info("relURI.path = " + relURI.path + ", was " + URI.path);
URI = relURI;
do_info("URI.path now = " + URI.path);
}
// Sanity-check
do_info("testing " + aTest.spec + " equals a clone of itself");
do_check_uri_eq(URI, URI.clone());
do_check_uri_eq(URI, URI.cloneIgnoringRef());
do_check_uri_eqExceptRef(URI, URI.cloneIgnoringRef());
do_info("testing " + aTest.spec + " instanceof nsIURL");
do_check_eq(URI instanceof Ci.nsIURL, aTest.nsIURL);
do_info("testing " + aTest.spec + " instanceof nsINestedURI");
@ -282,6 +670,10 @@ function do_test_uri_basic(aTest) {
do_check_property(aTest, URI, "prePath");
do_check_property(aTest, URI, "path");
do_check_property(aTest, URI, "ref");
do_check_property(aTest, URI, "port");
do_check_property(aTest, URI, "username");
do_check_property(aTest, URI, "password");
do_check_property(aTest, URI, "host");
}
// Test that a given URI parses correctly when we add a given ref to the end
@ -289,8 +681,25 @@ function do_test_uri_with_hash_suffix(aTest, aSuffix) {
do_info("making sure caller is using suffix that starts with '#'");
do_check_eq(aSuffix[0], "#");
var testURI = NetUtil.newURI(aTest.spec + aSuffix);
var origURI = NetUtil.newURI(aTest.spec);
var testURI;
if (aTest.relativeURI) {
try {
origURI = gIoService.newURI(aTest.relativeURI, null, origURI);
} catch (e) {
do_info("Caught error on Relative parse of " + aTest.spec + " + " + aTest.relativeURI +" Error: " + e.result);
return;
}
try {
testURI = gIoService.newURI(aSuffix, null, origURI);
} catch (e) {
do_info("Caught error adding suffix to " + aTest.spec + " + " + aTest.relativeURI + ", suffix " + aSuffix + " Error: " + e.result);
return;
}
} else {
testURI = NetUtil.newURI(aTest.spec + aSuffix);
}
do_info("testing " + aTest.spec + " with '" + aSuffix + "' appended " +
"equals a clone of itself");
@ -298,11 +707,6 @@ function do_test_uri_with_hash_suffix(aTest, aSuffix) {
do_info("testing " + aTest.spec +
" doesn't equal self with '" + aSuffix + "' appended");
if (aTest.spec == "file://") {
do_info("TODO: bug 656853");
todo_check_false(origURI.equals(testURI));
return; // bail out early since file:// doesn't handle hash refs at all
}
do_check_false(origURI.equals(testURI));
@ -310,23 +714,24 @@ function do_test_uri_with_hash_suffix(aTest, aSuffix) {
" is equalExceptRef to self with '" + aSuffix + "' appended");
do_check_uri_eqExceptRef(origURI, testURI);
do_info("testing cloneIgnoringRef on " + testURI.spec +
" is equal to no-ref version but not equal to ref version");
var cloneNoRef = testURI.cloneIgnoringRef();
if ((aTest.spec == "http://" || aTest.spec == "ftp://") && aSuffix == "#") {
do_info("TODO: bug 657033");
do_check_uri_eq(cloneNoRef, origURI, todo_check_true);
} else {
if (!origURI.ref) {
// These tests fail if origURI has a ref
do_info("testing cloneIgnoringRef on " + testURI.spec +
" is equal to no-ref version but not equal to ref version");
var cloneNoRef = testURI.cloneIgnoringRef();
do_check_uri_eq(cloneNoRef, origURI);
do_check_false(cloneNoRef.equals(testURI));
}
do_check_false(cloneNoRef.equals(testURI));
do_check_property(aTest, testURI, "scheme");
do_check_property(aTest, testURI, "prePath");
do_check_property(aTest, testURI, "path",
function(aStr) { return aStr + aSuffix; });
do_check_property(aTest, testURI, "ref",
function(aStr) { return aSuffix.substr(1); });
if (!origURI.ref) {
// These don't work if it's a ref already because '+' doesn't give the right result
do_check_property(aTest, testURI, "path",
function(aStr) { return aStr + aSuffix; });
do_check_property(aTest, testURI, "ref",
function(aStr) { return aSuffix.substr(1); });
}
}
// Tests various ways of setting & clearing a ref on a URI.
@ -339,13 +744,6 @@ function do_test_mutate_ref(aTest, aSuffix) {
var testURI = NetUtil.newURI(aTest.spec);
if (aTest.spec == "file://") {
do_info("TODO: bug 656853");
testURI.ref = aSuffix;
do_check_uri_eq(testURI, refURIWithSuffix, todo_check_true);
return; // bail out early since file:// doesn't handle hash refs at all
}
// First: Try setting .ref to our suffix
do_info("testing that setting .ref on " + aTest.spec +
" to '" + aSuffix + "' does what we expect");
@ -370,41 +768,39 @@ function do_test_mutate_ref(aTest, aSuffix) {
do_check_uri_eq(testURI, refURIWithoutSuffix);
do_check_uri_eqExceptRef(testURI, refURIWithSuffix);
// Now try setting .spec directly (including suffix) and then clearing .ref
var specWithSuffix = aTest.spec + aSuffix;
do_info("testing that setting spec to " +
specWithSuffix + " and then clearing ref does what we expect");
testURI.spec = specWithSuffix
testURI.ref = "";
if ((aTest.spec == "http://" || aTest.spec == "ftp://") && aSuffix == "#") {
do_info("TODO: bug 657033");
do_check_uri_eq(testURI, refURIWithoutSuffix, todo_check_true);
do_check_uri_eqExceptRef(testURI, refURIWithSuffix, todo_check_true);
} else {
do_check_uri_eq(testURI, refURIWithoutSuffix);
do_check_uri_eqExceptRef(testURI, refURIWithSuffix);
}
if (!aTest.relativeURI) {
// TODO: These tests don't work as-is for relative URIs.
// XXX nsIJARURI throws an exception in SetPath(), so skip it for next part.
if (!(testURI instanceof Ci.nsIJARURI)) {
// Now try setting .path directly (including suffix) and then clearing .ref
// (same as above, but with now with .path instead of .spec)
testURI = NetUtil.newURI(aTest.spec);
var pathWithSuffix = aTest.path + aSuffix;
do_info("testing that setting path to " +
pathWithSuffix + " and then clearing ref does what we expect");
testURI.path = pathWithSuffix;
// Now try setting .spec directly (including suffix) and then clearing .ref
var specWithSuffix = aTest.spec + aSuffix;
do_info("testing that setting spec to " +
specWithSuffix + " and then clearing ref does what we expect");
testURI.spec = specWithSuffix;
testURI.ref = "";
do_check_uri_eq(testURI, refURIWithoutSuffix);
do_check_uri_eqExceptRef(testURI, refURIWithSuffix);
// Also: make sure that clearing .path also clears .ref
testURI.path = pathWithSuffix;
do_info("testing that clearing path from " +
pathWithSuffix + " also clears .ref");
testURI.path = "";
do_check_eq(testURI.ref, "");
// XXX nsIJARURI throws an exception in SetPath(), so skip it for next part.
if (!(testURI instanceof Ci.nsIJARURI)) {
// Now try setting .path directly (including suffix) and then clearing .ref
// (same as above, but with now with .path instead of .spec)
testURI = NetUtil.newURI(aTest.spec);
var pathWithSuffix = aTest.path + aSuffix;
do_info("testing that setting path to " +
pathWithSuffix + " and then clearing ref does what we expect");
testURI.path = pathWithSuffix;
testURI.ref = "";
do_check_uri_eq(testURI, refURIWithoutSuffix);
do_check_uri_eqExceptRef(testURI, refURIWithSuffix);
// Also: make sure that clearing .path also clears .ref
testURI.path = pathWithSuffix;
do_info("testing that clearing path from " +
pathWithSuffix + " also clears .ref");
testURI.path = "";
do_check_eq(testURI.ref, "");
}
}
}
@ -437,22 +833,42 @@ function do_test_immutable(aTest) {
// ------------------
function run_test()
{
// UTF-8 check - From bug 622981
// ASCII
let base = gIoService.newURI("http://example.org/xenia?", null, null);
let resolved = gIoService.newURI("?x", null, base);
let expected = gIoService.newURI("http://example.org/xenia?x",
null, null);
do_info("Bug 662981: ACSII - comparing " + resolved.spec + " and " + expected.spec);
do_check_true(resolved.equals(expected));
// UTF-8 character "è"
// Bug 622981 was triggered by an empty query string
base = gIoService.newURI("http://example.org/xènia?", null, null);
resolved = gIoService.newURI("?x", null, base);
expected = gIoService.newURI("http://example.org/xènia?x",
null, null);
do_info("Bug 662981: UTF8 - comparing " + resolved.spec + " and " + expected.spec);
do_check_true(resolved.equals(expected));
gTests.forEach(function(aTest) {
// Check basic URI functionality
do_test_uri_basic(aTest);
// Try adding various #-prefixed strings to the ends of the URIs
gHashSuffixes.forEach(function(aSuffix) {
do_test_uri_with_hash_suffix(aTest, aSuffix);
if (!aTest.immutable) {
do_test_mutate_ref(aTest, aSuffix);
}
});
if (!aTest.fail) {
// Try adding various #-prefixed strings to the ends of the URIs
gHashSuffixes.forEach(function(aSuffix) {
do_test_uri_with_hash_suffix(aTest, aSuffix);
if (!aTest.immutable) {
do_test_mutate_ref(aTest, aSuffix);
}
});
// For URIs that we couldn't mutate above due to them being immutable:
// Now we check that they're actually immutable.
if (aTest.immutable) {
do_test_immutable(aTest);
// For URIs that we couldn't mutate above due to them being immutable:
// Now we check that they're actually immutable.
if (aTest.immutable) {
do_test_immutable(aTest);
}
}
});
}

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

@ -127,14 +127,6 @@ function onAlertLoad()
var alertBox = document.getElementById("alertBox");
alertBox.orient = (gOrigin & NS_ALERT_HORIZONTAL) ? "vertical" : "horizontal";
// The above doesn't cause the labels in alertTextBox to reflow,
// see bug 311557. As the theme's -moz-box-align css rule gets ignored,
// we work around the bug by setting the align property.
if (gOrigin & NS_ALERT_HORIZONTAL)
{
document.getElementById("alertTextBox").align = "center";
}
sizeToContent();
// Work around a bug where sizeToContent() leaves a border outside of the content

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

@ -90,5 +90,5 @@ label {
-moz-padding-start: 5px;
-moz-padding-end: 5px;
margin-bottom: 8px;
-moz-box-align: center; /* also hard-coded in alert.js, see bug 311557 */
-moz-box-align: center;
}

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

@ -95,5 +95,5 @@ label {
-moz-padding-start: 5px;
-moz-padding-end: 5px;
margin-bottom: 8px;
-moz-box-align: center; /* also hard-coded in alert.js, see bug 311557 */
-moz-box-align: center;
}