From f4bc9bada3327117ae28beb5700c3fd2f052033b Mon Sep 17 00:00:00 2001 From: Erik Vold Date: Tue, 13 Nov 2012 23:22:33 +0800 Subject: [PATCH 1/3] adding svg tests, the widget one is failing.. --- data/mofo_logo.SVG | 49 +++++++++++++++++++++++++++++++++++++++++++++ test/test-panel.js | 14 +++++++++++++ test/test-widget.js | 36 +++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 data/mofo_logo.SVG diff --git a/data/mofo_logo.SVG b/data/mofo_logo.SVG new file mode 100644 index 000000000..0c84f07f5 --- /dev/null +++ b/data/mofo_logo.SVG @@ -0,0 +1,49 @@ + + + + +]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/test-panel.js b/test/test-panel.js index bdce83d90..dee19a5f6 100644 --- a/test/test-panel.js +++ b/test/test-panel.js @@ -7,6 +7,7 @@ let panels = require('sdk/panel'); let tests = {}, panels, Panel; const { Loader } = require('sdk/test/loader'); const timer = require("sdk/timers"); +const self = require('self'); tests.testPanel = function(test) { test.waitUntilDone(); @@ -441,6 +442,19 @@ tests.testContentURLOption = function(test) { "Panel throws an exception if contentURL is not a URL."); }; +tests.testSVGDocument = function(test) { + let URL_STRING = self.data.url("mozilla_foundation_logo.svg"); + + let panel = Panel({ + contentURL: URL_STRING + }); + panel.show(); + panel.hide(); + test.pass("contentURL accepts a svg document"); + test.assertEqual(panel.contentURL, URL_STRING, + "contentURL is the string to which it was set."); +}; + exports.testContentScriptOptionsOption = function(test) { test.waitUntilDone(); diff --git a/test/test-widget.js b/test/test-widget.js index 78bc9f924..1857887e5 100644 --- a/test/test-widget.js +++ b/test/test-widget.js @@ -11,6 +11,23 @@ const url = require("sdk/url"); const windowUtils = require("sdk/deprecated/window-utils"); const tabBrowser = require("sdk/deprecated/tab-browser"); const timer = require("sdk/timers"); +const self = require("self"); + +function LoaderWithHookedConsole() { + let errors = []; + let loader = Loader(module, { + console: Object.create(console, { + error: { value: function(e) { + errors.push(e); + }} + }) + }); + + return { + loader: loader, + errors: errors + } +} exports.testConstructor = function(test) { test.waitUntilDone(30000); @@ -1027,6 +1044,25 @@ exports.testPostMessageOnLocationChange = function(test) { }); }; +exports.testSVGWidget = function(test) { + test.waitUntilDone(); + + // use of capital SVG here is intended, that was failing.. + let SVG_URL = self.data.url("mofo_logo.SVG"); + + let widget = require("widget").Widget({ + id: "mozilla-svg-logo", + label: "moz foundation logo", + contentURL: SVG_URL, + contentScript: "self.postMessage({count: window.document.images.length, src: window.document.images[0].src});", + onMessage: function(data) { + test.assertEqual(data.count, 1, 'only one image'); + test.assertEqual(data.src, SVG_URL, 'only one image'); + test.done(); + } + }); +}; + exports.testNavigationBarWidgets = function testNavigationBarWidgets(test) { test.waitUntilDone(); From 14f8bcd27dab1f259f173771f7390159b2491539 Mon Sep 17 00:00:00 2001 From: Erik Vold Date: Wed, 14 Nov 2012 10:27:14 +0800 Subject: [PATCH 2/3] using svg images for widget content no longer fails --- lib/sdk/widget.js | 25 +++++++++++++------------ test/test-panel.js | 1 + test/test-widget.js | 16 ---------------- 3 files changed, 14 insertions(+), 28 deletions(-) diff --git a/lib/sdk/widget.js b/lib/sdk/widget.js index f1236aa54..56bb22d11 100644 --- a/lib/sdk/widget.js +++ b/lib/sdk/widget.js @@ -573,32 +573,31 @@ function BrowserWindow(window) { } BrowserWindow.prototype = { - // Adds an array of items to the window. addItems: function BW_addItems(items) { items.forEach(this._addItemToWindow, this); }, - + _addItemToWindow: function BW__addItemToWindow(baseWidget) { // Create a WidgetView instance let widget = baseWidget._createView(); - + // Create a WidgetChrome instance let item = new WidgetChrome({ widget: widget, doc: this.doc, window: this.window }); - + widget._chrome = item; - + this._insertNodeInToolbar(item.node); - + // We need to insert Widget DOM Node before finishing widget view creation // (because fill creates an iframe and tries to access its docShell) item.fill(); }, - + _insertNodeInToolbar: function BW__insertNodeInToolbar(node) { // Add to the customization palette let toolbox = this.doc.getElementById("navigator-toolbox"); @@ -762,7 +761,7 @@ WidgetChrome.prototype.fill = function WC_fill() { WidgetChrome.prototype.getContentType = function WC_getContentType() { if (this._widget.content) return CONTENT_TYPE_HTML; - return (this._widget.contentURL && /\.(jpg|gif|png|ico)$/.test(this._widget.contentURL)) + return (this._widget.contentURL && /\.(jpg|gif|png|ico|svg)$/i.test(this._widget.contentURL)) ? CONTENT_TYPE_IMAGE : CONTENT_TYPE_URI; } @@ -826,7 +825,7 @@ WidgetChrome.prototype.setContent = function WC_setContent() { // Detect if document consists of a single image. WidgetChrome._isImageDoc = function WC__isImageDoc(doc) { - return doc.body.childNodes.length == 1 && + return /*doc.body &&*/ doc.body.childNodes.length == 1 && doc.body.firstElementChild && doc.body.firstElementChild.tagName == "IMG"; } @@ -875,8 +874,9 @@ WidgetChrome.prototype.addEventHandlers = function WC_addEventHandlers() { // We may have had an unload event before that cleaned up the symbiont if (!self._symbiont) self.setContent(); - + let doc = e.target; + if (contentType == CONTENT_TYPE_IMAGE || WidgetChrome._isImageDoc(doc)) { // Force image content to size. // Add-on authors must size their images correctly. @@ -893,9 +893,10 @@ WidgetChrome.prototype.addEventHandlers = function WC_addEventHandlers() { // Allow all content to fill the box by default. doc.body.style.margin = "0"; } + iframe.addEventListener("load", loadListener, true); this.eventListeners["load"] = loadListener; - + // Register a listener to unload symbiont if the toolbaritem is moved // on user toolbars customization function unloadListener(e) { @@ -910,7 +911,7 @@ WidgetChrome.prototype.addEventHandlers = function WC_addEventHandlers() { } catch(e) {} } - + iframe.addEventListener("unload", unloadListener, true); this.eventListeners["unload"] = unloadListener; } diff --git a/test/test-panel.js b/test/test-panel.js index dee19a5f6..c3fed8166 100644 --- a/test/test-panel.js +++ b/test/test-panel.js @@ -450,6 +450,7 @@ tests.testSVGDocument = function(test) { }); panel.show(); panel.hide(); + panel.destroy(); test.pass("contentURL accepts a svg document"); test.assertEqual(panel.contentURL, URL_STRING, "contentURL is the string to which it was set."); diff --git a/test/test-widget.js b/test/test-widget.js index 1857887e5..b0b14315d 100644 --- a/test/test-widget.js +++ b/test/test-widget.js @@ -13,22 +13,6 @@ const tabBrowser = require("sdk/deprecated/tab-browser"); const timer = require("sdk/timers"); const self = require("self"); -function LoaderWithHookedConsole() { - let errors = []; - let loader = Loader(module, { - console: Object.create(console, { - error: { value: function(e) { - errors.push(e); - }} - }) - }); - - return { - loader: loader, - errors: errors - } -} - exports.testConstructor = function(test) { test.waitUntilDone(30000); From b322e5889aaea3bad812e05826c6b1257b6a47f6 Mon Sep 17 00:00:00 2001 From: Erik Vold Date: Mon, 10 Dec 2012 17:12:05 -0800 Subject: [PATCH 3/3] bug fixes, using proper svg filename and destroying the test widget --- test/test-panel.js | 7 +++---- test/test-widget.js | 1 + 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/test-panel.js b/test/test-panel.js index d1175f16a..2b9d3b7e3 100644 --- a/test/test-panel.js +++ b/test/test-panel.js @@ -6,7 +6,6 @@ let { Cc, Ci } = require("chrome"); const { Loader } = require('sdk/test/loader'); const timer = require("sdk/timers"); const self = require('self'); -const { Panel } = require('sdk/panel'); exports["test Panel"] = function(assert, done) { const { Panel } = require('sdk/panel'); @@ -456,16 +455,16 @@ exports["test Content URL Option"] = function(assert) { }; exports.testSVGDocument = function(assert) { - let URL_STRING = self.data.url("mozilla_foundation_logo.svg"); + let SVG_URL = self.data.url("mofo_logo.SVG"); - let panel = Panel({ contentURL: URL_STRING }); + let panel = require("sdk/panel").Panel({ contentURL: SVG_URL }); panel.show(); panel.hide(); panel.destroy(); assert.pass("contentURL accepts a svg document"); - assert.equal(panel.contentURL, URL_STRING, + assert.equal(panel.contentURL, SVG_URL, "contentURL is the string to which it was set."); }; diff --git a/test/test-widget.js b/test/test-widget.js index b34104a19..5dce2a723 100644 --- a/test/test-widget.js +++ b/test/test-widget.js @@ -1042,6 +1042,7 @@ exports.testSVGWidget = function(test) { contentURL: SVG_URL, contentScript: "self.postMessage({count: window.document.images.length, src: window.document.images[0].src});", onMessage: function(data) { + widget.destroy(); test.assertEqual(data.count, 1, 'only one image'); test.assertEqual(data.src, SVG_URL, 'only one image'); test.done();