Bug 1173214, r=seth,bz

--HG--
extra : commitid : 4vG71pjrBIY
This commit is contained in:
Gijs Kruitbosch 2015-08-26 10:24:04 +01:00
parent 5cececa4ba
commit 1aa68e8c0f
12 changed files with 168 additions and 59 deletions

View File

@ -67,13 +67,22 @@ nsIconProtocolHandler::NewURI(const nsACString& aSpec,
nsIURI* aBaseURI,
nsIURI** result)
{
nsCOMPtr<nsIURI> uri = new nsMozIconURI();
nsCOMPtr<nsIMozIconURI> uri = new nsMozIconURI();
if (!uri) return NS_ERROR_OUT_OF_MEMORY;
nsresult rv = uri->SetSpec(aSpec);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIURL> iconURL;
uri->GetIconURL(getter_AddRefs(iconURL));
if (iconURL) {
uri = new nsNestedMozIconURI();
rv = uri->SetSpec(aSpec);
if (NS_FAILED(rv)) {
return rv;
}
}
NS_ADDREF(*result = uri);
return NS_OK;
}

View File

@ -12,6 +12,7 @@
#include "nsIconURI.h"
#include "nsIIOService.h"
#include "nsIURL.h"
#include "nsNetUtil.h"
#include "prprf.h"
#include "plstr.h"
#include <stdlib.h>
@ -647,3 +648,33 @@ nsMozIconURI::Deserialize(const URIParams& aParams)
return true;
}
////////////////////////////////////////////////////////////
// Nested version of nsIconURI
nsNestedMozIconURI::nsNestedMozIconURI()
{ }
nsNestedMozIconURI::~nsNestedMozIconURI()
{ }
NS_IMPL_ISUPPORTS_INHERITED(nsNestedMozIconURI, nsMozIconURI, nsINestedURI)
NS_IMETHODIMP
nsNestedMozIconURI::GetInnerURI(nsIURI** aURI)
{
nsCOMPtr<nsIURI> iconURL = do_QueryInterface(mIconURL);
if (iconURL) {
iconURL.forget(aURI);
} else {
*aURI = nullptr;
}
return NS_OK;
}
NS_IMETHODIMP
nsNestedMozIconURI::GetInnermostURI(nsIURI** aURI)
{
return NS_ImplGetInnermostURI(this, aURI);
}

View File

@ -11,9 +11,10 @@
#include "nsCOMPtr.h"
#include "nsString.h"
#include "nsIIPCSerializableURI.h"
#include "nsINestedURI.h"
class nsMozIconURI final : public nsIMozIconURI
, public nsIIPCSerializableURI
class nsMozIconURI : public nsIMozIconURI
, public nsIIPCSerializableURI
{
public:
NS_DECL_THREADSAFE_ISUPPORTS
@ -40,4 +41,23 @@ protected:
// kStateStrings
};
// For moz-icon URIs that point to an actual file on disk and are
// therefore nested URIs
class nsNestedMozIconURI final : public nsMozIconURI
, public nsINestedURI
{
NS_DECL_ISUPPORTS_INHERITED
NS_FORWARD_NSIURI(nsMozIconURI::)
NS_FORWARD_NSIMOZICONURI(nsMozIconURI::)
NS_FORWARD_NSIIPCSERIALIZABLEURI(nsMozIconURI::)
NS_DECL_NSINESTEDURI
nsNestedMozIconURI();
protected:
virtual ~nsNestedMozIconURI();
};
#endif // mozilla_image_decoders_icon_nsIconURI_h

View File

Before

Width:  |  Height:  |  Size: 766 B

After

Width:  |  Height:  |  Size: 766 B

View File

@ -40,6 +40,10 @@ disabled = bug 1100497
disabled = bug 1101415
[test_background_image_anim.html]
[test_bullet_animation.html]
[test_bug415761.html]
skip-if = os != "win" || os_version == "6.2"
support-files =
bug415761.ico
[test_changeOfSource.html]
[test_changeOfSource2.html]
[test_has_transparency.html]

View File

@ -0,0 +1,98 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test for icon filenames</title>
<script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/WindowSnapshot.js"></script>
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
</head>
<body>
<pre id="test">
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
// We want to make sure that moz-icon URIs with non-ascii characters work. To that
// end, we compare the rendering of an icon without non-ascii characters to that
// of one that does include such characters.
// First, obtain the file URI to the ourselves:
var chromeURI = location.href;
var io = Components.classes['@mozilla.org/network/io-service;1']
.getService(Components.interfaces.nsIIOService);
chromeURI = io.newURI(chromeURI, null, null);
var chromeReg = Components.classes["@mozilla.org/chrome/chrome-registry;1"]
.getService(Components.interfaces.nsIChromeRegistry);
fileURI = chromeReg.convertChromeURL(chromeURI);
fileURI.QueryInterface(Components.interfaces.nsIFileURL);
var self = fileURI.file;
// Check if the non-ascii-named icon is still hanging around from a previous test
var dest = self.parent;
dest.append("\u263a.ico");
if (dest.exists()) {
dest.remove(false);
}
// Copy the source icon so that we have an identical icon with non-ascii characters
// in its name
var src = self.parent;
src.append("bug415761.ico");
src.copyTo(null, dest.leafName);
// Now load both icons in an Image() with a moz-icon URI
var testImage = new Image();
var refImage = new Image();
var loadedImages = 0;
testImage.onload = refImage.onload = function() {
loadedImages++;
if (loadedImages == 2) {
finishTest();
}
};
testImage.onerror = refImage.onerror = function() {
testImage.onload = refImage.onload = function() {};
ok(false, "Icon did not load successfully");
SimpleTest.finish();
};
function finishTest() {
ok(true, "Both icons loaded successfully");
// Render the reference to a canvas
var refCanvas = document.createElement("canvas");
refCanvas.setAttribute("height", 32);
refCanvas.setAttribute("width", 32);
refCanvas.getContext('2d').drawImage(refImage, 0, 0, 32, 32);
// Render the icon with a non-ascii character in its name to a canvas
var testCanvas = document.createElement("canvas");
testCanvas.setAttribute("height", 32);
testCanvas.setAttribute("width", 32);
testCanvas.getContext('2d').drawImage(testImage, 0, 0, 32, 32);
// Assert that they should be the same.
assertSnapshots(refCanvas, testCanvas, true, 0, "icon", "reference icon");
SimpleTest.finish();
};
var testURI = io.newFileURI(dest).spec;
var refURI = io.newFileURI(src).spec;
testImage.src = "moz-icon:" + testURI;
refImage.src = "moz-icon:" + refURI;
SimpleTest.registerCleanupFunction(function() {
// Remove the copied file if it exists.
if (dest.exists()) {
dest.remove(false);
}
});
</script>
</pre>
</body>
</html>

View File

@ -1,16 +0,0 @@
body {
background: #222 url("chrome://global/skin/media/imagedoc-darknoise.png");
margin: 0;
}
body > :first-child {
display: block;
position: absolute;
margin: auto;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: hsl(0,0%,90%) url("chrome://global/skin/media/imagedoc-lightnoise.png");
color: #222;
}

View File

@ -1,21 +0,0 @@
function handleRequest(request, response)
{
var self = Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
self.initWithPath(getState("__LOCATION__"));
var dest = self.parent;
dest.append("\u263a.ico");
if (dest.exists())
dest.remove(false);
var src = self.parent;
src.append("bug415761.ico");
src.copyTo(null, dest.leafName);
var uri = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService)
.newFileURI(dest).spec;
response.setStatusLine(request.httpVersion, 200, "OK");
response.setHeader("Content-Type", "text/html");
response.setHeader("Cache-Control", "no-cache");
response.write("<link rel=\"stylesheet\" href=\"ImageDocument.css\">");
response.write("<img src=\"moz-icon:" + uri + "\" width=\"32\" height=\"32\">");
}

View File

@ -1,12 +0,0 @@
function handleRequest(request, response)
{
var self = Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
self.initWithPath(getState("__LOCATION__"));
var dest = self.parent;
dest.append("\u263a.ico");
if (dest.exists())
dest.remove(false);
response.setStatusLine(request.httpVersion, 200, "OK");
response.setHeader("Content-Type", "text/html");
}

View File

@ -1,2 +0,0 @@
skip-if(!winWidget) skip-if(/^Windows\x20NT\x2010\.0/.test(http.oscpu)||/^Windows\x20NT\x206\.2/.test(http.oscpu)) HTTP == bug415761.sjs bug415761.ico # See Bug 850194
skip-if(!winWidget) skip-if(/^Windows\x20NT\x2010\.0/.test(http.oscpu)||/^Windows\x20NT\x206\.2/.test(http.oscpu)) HTTP == bug415761cleanup.sjs about:blank

View File

@ -34,9 +34,6 @@ include gif/reftest.list
# APNG tests
include apng/reftest.list
# Icon tests
include icon/win/reftest.list
# Generic image tests
include generic/reftest.list

View File

@ -209,7 +209,8 @@ function run_test()
testURI("data:text/html,Hello World", "data resource", "data resource");
testURI("jar:http://www.mozilla.com/file!/magic", "mozilla.com", "www.mozilla.com");
testURI("file:///C:/Cool/Stuff/", "local file", "local file");
testURI("moz-icon:file:///test.extension", "moz-icon resource", "moz-icon resource");
testURI("moz-icon:file:///test.extension", "local file", "local file");
testURI("moz-icon://.extension", "moz-icon resource", "moz-icon resource");
testURI("about:config", "about resource", "about resource");
testAllGetReadableDates();