function loadWithConfig (conf, check) { var config = []; for (var k in conf) { config.push(k + "=" + encodeURI($.isArray(conf[k]) ? JSON.stringify(conf[k]) : conf[k]).replace(/=/g, "%3D")); } var $ifr = $("") , loaded = false , MAXOUT = 5000 , incr = function (ev) { if (ev.data && ev.data.topic == "end-all") loaded = true; } ; $ifr.attr("src", "spec/core/simple.html?" + config.join(";")); runs(function () { window.addEventListener("message", incr, false); $ifr.appendTo($("body")); }); waitsFor(function () { return loaded; }, MAXOUT); runs(function () { check($ifr); $ifr.remove(); loaded = false; window.removeEventListener("message", incr, false); }); } describe("W3C — Permalinks", function () { var MAXOUT = 5000 , basicConfig = { editors: [{ name: "Shane McCarron", url: "http://URI", company: "COMPANY", companyURI: "http://COMPANY", mailto: "EMAIL", note: "NOTE"}] , shortName: "some-spec" , publicationDate: "2013-06-25" , previousPublishDate: "2012-06-07" , previousMaturity: "REC" , specStatus: "PER" , wgPatentURI: "http://www.w3.org/fake-patent-uri" , includePermalinks: true , doRDFa: 1.1 } , noConfig = { editors: [{ name: "Shane McCarron", url: "http://URI", company: "COMPANY", companyURI: "http://COMPANY", mailto: "EMAIL", note: "NOTE"}] , shortName: "some-spec" , publicationDate: "2013-06-25" , previousPublishDate: "2012-06-07" , previousMaturity: "REC" , specStatus: "PER" , includePermalinks: false , doRDFa: false }; it("permalinks data should be added when section or h* have an id", function () { var doc; runs(function () { makeRSDoc({ config: basicConfig, body: $("
Some unique SOTD content

a heading

some content

") }, function (rsdoc) { doc = rsdoc; }); }); waitsFor(function () { return doc; }, MAXOUT); runs(function () { var $c = $("#sotd", doc) ; var list = $(".permalink", $c); expect(list.length).toEqual(0); $c = $("#testing", doc); list = $(".permalink", $c) ; expect(list.length).toEqual(1); flushIframes(); }); }); it("permalinks data should be added when div or h* have an id", function () { var doc; runs(function () { makeRSDoc({ config: basicConfig, body: $("
Some unique SOTD content

a heading

some content

") }, function (rsdoc) { doc = rsdoc; }); }); waitsFor(function () { return doc; }, MAXOUT); runs(function () { var $c = $("#sotd", doc) ; var list = $(".permalink", $c); expect(list.length).toEqual(0); $c = $("#testing", doc); list = $(".permalink", $c) ; expect(list.length).toEqual(1); flushIframes(); }); }); it("permalinks data should not be added when section or h* have no id", function () { var doc; runs(function () { makeRSDoc({ config: basicConfig, body: $("
Some unique SOTD content

a heading

some content

another heading

Other Content

") }, function (rsdoc) { doc = rsdoc; }); }); waitsFor(function () { return doc; }, MAXOUT); runs(function () { var $c = $("#testing", doc); $c = $c.nextElementSibling; var list = $(".permalink", $c) ; expect(list.length).toEqual(0); flushIframes(); }); }); it("permalinks data should not be added when section has a class of nolink", function () { var doc; runs(function () { makeRSDoc({ config: basicConfig, body: $("
Some unique SOTD content
") }, function (rsdoc) { doc = rsdoc; }); }); waitsFor(function () { return doc; }, MAXOUT); runs(function () { var $c = $("#testing", doc); var list = $(".permalink", $c) ; expect(list.length).toEqual(0); flushIframes(); }); }); it("should do nothing when disabled", function () { var doc; runs(function () { makeRSDoc({ config: noConfig, body: $("
Some unique SOTD content

a heading

some content

") }, function (rsdoc) { doc = rsdoc; }); }); waitsFor(function () { return doc; }, MAXOUT); runs(function () { var $c = $("#sotd", doc) ; var list = $c.children(".permalink"); expect(list.length).toEqual(0); $n = $("#testing", doc); list = $n.children(".permalink") ; expect(list.length).toEqual(0); flushIframes(); }); }); it("permalinks content attribute should have special characters escaped", function () { var doc; runs(function () { makeRSDoc({ config: basicConfig, body: $("
Some unique SOTD content

a heading with "+'"'+" and '

some content

") }, function (rsdoc) { doc = rsdoc; }); }); waitsFor(function () { return doc; }, MAXOUT); runs(function () { var $c = $("#testing", doc); var list = $("span.permalink a span", $c) ; expect(list.length).toEqual(1); expect($(list[0]).attr("content")).toMatch(/'/); expect($(list[0]).attr("content")).toMatch(/"/); flushIframes(); }); }); it("permalinks not on edge will have non-breaking space after heading", function () { var doc; runs(function () { makeRSDoc({ config: basicConfig, body: $("
Some unique SOTD content

a heading with "+'"'+" and '

some content

") }, function (rsdoc) { doc = rsdoc; }); }); waitsFor(function () { return doc; }, MAXOUT); runs(function () { var $c = $("#testing", doc); var list = $("h2", $c) ; expect(list.length).toEqual(1); expect(list[0].innerHTML).toMatch(/ /); flushIframes(); }); }); });