From 10f853c059b8ea9159dc173af1cbbb0713632324 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Thu, 26 Mar 2015 15:00:31 -0400 Subject: [PATCH] Bug 1147699 - Part 10: Add a test for FetchEvent.request.context when intercepting font loads; r=nsm --- .../fetch/context/context_test.js | 2 ++ .../serviceworkers/fetch/context/index.html | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/dom/workers/test/serviceworkers/fetch/context/context_test.js b/dom/workers/test/serviceworkers/fetch/context/context_test.js index 717b9439eff..1a585e97aaa 100644 --- a/dom/workers/test/serviceworkers/fetch/context/context_test.js +++ b/dom/workers/test/serviceworkers/fetch/context/context_test.js @@ -38,6 +38,8 @@ self.addEventListener("fetch", function(event) { respondToServiceWorker(event, "embed"); } else if (event.request.url.indexOf("object") >= 0) { respondToServiceWorker(event, "object"); + } else if (event.request.url.indexOf("font") >= 0) { + respondToServiceWorker(event, "font"); } // Fail any request that we don't know about. try { diff --git a/dom/workers/test/serviceworkers/fetch/context/index.html b/dom/workers/test/serviceworkers/fetch/context/index.html index 420d67bc9b4..d8ed8b6b9f5 100644 --- a/dom/workers/test/serviceworkers/fetch/context/index.html +++ b/dom/workers/test/serviceworkers/fetch/context/index.html @@ -141,6 +141,23 @@ }); } + function testFont() { + return new Promise(function(resolve, reject) { + var css = '@font-face { font-family: "sw-font"; src: url("font"); }'; + css += '* { font-family: "sw-font"; }'; + var style = document.createElement("style"); + style.appendChild(document.createTextNode(css)); + document.documentElement.appendChild(style); + navigator.serviceWorker.addEventListener("message", function onMessage(e) { + if (e.data.data == "font") { + is(e.data.context, "font", "Expected the font context on an font"); + navigator.serviceWorker.removeEventListener("message", onMessage); + resolve(); + } + }, false); + }); + } + Promise.all([ testFetch(), testImage(), @@ -152,6 +169,7 @@ testCSPReport(), testEmbed(), testObject(), + testFont(), ]) .then(function() { finish();