mirror of
https://github.com/webodf/WebODF.git
synced 2026-11-30 16:47:58 +01:00
Fix loading of webodf.css in qtjsruntimetest.
If the <link/> element does not load the css, load the webodf.css in a <script/> element. Also avoid loading webodf.css more than once.
This commit is contained in:
+43
-11
@@ -891,29 +891,61 @@
|
||||
|
||||
/**
|
||||
* @param {!Document} document
|
||||
* @return {!HTMLStyleElement}
|
||||
* @return {!Element}
|
||||
*/
|
||||
function addWebODFStyleSheet(document) {
|
||||
/**
|
||||
* @param {!string} css
|
||||
* @param {!HTMLHeadElement} head
|
||||
* @return {!Element}
|
||||
*/
|
||||
function addCSS(css, head) {
|
||||
var e = document.createElementNS(head.namespaceURI, 'style');
|
||||
e.setAttribute('media', 'screen, print, handheld, projection');
|
||||
e.setAttribute('type', 'text/css');
|
||||
e.appendChild(document.createTextNode(css));
|
||||
head.appendChild(e);
|
||||
return e;
|
||||
}
|
||||
var head = /**@type{!HTMLHeadElement}*/(document.getElementsByTagName('head')[0]),
|
||||
/**@type{?Element}*/
|
||||
style,
|
||||
href;
|
||||
href,
|
||||
count = document.styleSheets.length;
|
||||
// make sure this is only added once per HTML document, e.g. in case of
|
||||
// multiple odfCanvases
|
||||
style = head.firstElementChild;
|
||||
while (style) {
|
||||
if (style.getAttribute("webodfcss")) {
|
||||
return style;
|
||||
}
|
||||
style = style.nextElementSibling;
|
||||
}
|
||||
if (String(typeof webodf_css) !== "undefined") {
|
||||
style = document.createElementNS(head.namespaceURI, 'style');
|
||||
style.setAttribute('media', 'screen, print, handheld, projection');
|
||||
style.appendChild(document.createTextNode(webodf_css));
|
||||
style = addCSS(webodf_css, head);
|
||||
} else {
|
||||
style = document.createElementNS(head.namespaceURI, 'link');
|
||||
href = "webodf.css";
|
||||
if (runtime.currentDirectory) {
|
||||
href = runtime.currentDirectory() + "/../" + href;
|
||||
href = runtime.currentDirectory();
|
||||
if (href.length > 0 && href.substr(-1) !== "/") {
|
||||
href += "/";
|
||||
}
|
||||
href += "../webodf.css";
|
||||
}
|
||||
style.setAttribute('href', href);
|
||||
style.setAttribute('rel', 'stylesheet');
|
||||
style.setAttribute('type', 'text/css');
|
||||
head.appendChild(style);
|
||||
// if the css was not loaded, with <link/>, read and add the css
|
||||
// this is a workaround for behaviour of qtjsruntime
|
||||
if (count === document.styleSheets.length) {
|
||||
head.removeChild(style);
|
||||
style = addCSS(/**@type{!string}*/(runtime.readFileSync(href, "utf-8")), head);
|
||||
}
|
||||
}
|
||||
style.setAttribute('type', 'text/css');
|
||||
// TODO: make sure this is only added once per HTML document, e.g. in case of multiple odfCanvases
|
||||
head.appendChild(style);
|
||||
return /**@type {!HTMLStyleElement}*/(style);
|
||||
style.setAttribute('webodfcss', 'true');
|
||||
return style;
|
||||
}
|
||||
/**
|
||||
* @param {!Document} document Put and ODF Canvas inside this element.
|
||||
@@ -966,7 +998,7 @@
|
||||
showAnnotationRemoveButton = false,
|
||||
/**@type{gui.AnnotationViewManager}*/
|
||||
annotationViewManager = null,
|
||||
/**@type{!HTMLStyleElement}*/
|
||||
/**@type{!Element}*/
|
||||
webodfcss,
|
||||
/**@type{!HTMLStyleElement}*/
|
||||
fontcss,
|
||||
|
||||
@@ -22,10 +22,12 @@ add_custom_target(nodetest ALL
|
||||
if (QT4_FOUND)
|
||||
COPY_FILES(tests_qtjsruntimetest ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_BINARY_DIR}/_qtjsruntimetest ${TESTS_TESTFILES} )
|
||||
COPY_FILES(tests_qtjsruntimetest2 ${CMAKE_CURRENT_SOURCE_DIR}/..
|
||||
${CMAKE_CURRENT_BINARY_DIR} webodf.css)
|
||||
add_custom_target(qtjsruntimetest ALL
|
||||
COMMAND qtjsruntime ${RUNTIME} tests.js
|
||||
WORKING_DIRECTORY _qtjsruntimetest
|
||||
DEPENDS NodeJS ${tests_qtjsruntimetest} qtjsruntime manifest.json-target
|
||||
DEPENDS NodeJS ${tests_qtjsruntimetest} ${tests_qtjsruntimetest2} qtjsruntime manifest.json-target
|
||||
)
|
||||
endif (QT4_FOUND)
|
||||
|
||||
|
||||
@@ -209,8 +209,8 @@ ops.OdtDocumentTests = function OdtDocumentTests(runner) {
|
||||
r.shouldBe(t, "t.steps", "6");
|
||||
}
|
||||
function testCountLinesStepsDown_OverWrap() {
|
||||
createOdtDocument("<text:p text:style-name='width30px'>ABCD FGHIJ</text:p>");
|
||||
appendCssRule("text|p[text|style-name=width30px] { width: 30px; }\n"); // Width calculated to wrap at first space
|
||||
createOdtDocument("<text:p text:style-name='width4em'>ABCD FGHIJ</text:p>");
|
||||
appendCssRule("text|p[text|style-name=width4em] { width: 4em; }\n"); // Width calculated to wrap at first space
|
||||
setCursorPosition(4);
|
||||
t.steps = t.counter.countLinesSteps(1, t.filter);
|
||||
r.shouldBe(t, "t.steps", "6");
|
||||
@@ -252,8 +252,8 @@ ops.OdtDocumentTests = function OdtDocumentTests(runner) {
|
||||
r.shouldBe(t, "t.steps", "3");
|
||||
}
|
||||
function testCountStepsToLineBoundary_Forward_OverWrapping() {
|
||||
createOdtDocument("<text:p text:style-name='width30px'>ABC DEF</text:p>");
|
||||
appendCssRule("text|p[text|style-name=width30px] { width: 30px; }\n"); // Width calculated to wrap at first space
|
||||
createOdtDocument("<text:p text:style-name='width3em'>ABC DEF</text:p>");
|
||||
appendCssRule("text|p[text|style-name=width3em] { width: 3em; }\n"); // Width calculated to wrap at first space
|
||||
setCursorPosition(0);
|
||||
t.steps = t.counter.countStepsToLineBoundary(1, t.filter);
|
||||
r.shouldBe(t, "t.steps", "3");
|
||||
@@ -302,8 +302,8 @@ ops.OdtDocumentTests = function OdtDocumentTests(runner) {
|
||||
r.shouldBe(t, "t.steps", "-3");
|
||||
}
|
||||
function testCountStepsToLineBoundary_Backward_OverWrapping() {
|
||||
createOdtDocument("<text:p text:style-name='width30px'>ABC DEF</text:p>");
|
||||
appendCssRule("text|p[text|style-name=width30px] { width: 30px; }\n"); // Width calculated to wrap at first space
|
||||
createOdtDocument("<text:p text:style-name='width3em'>ABC DEF</text:p>");
|
||||
appendCssRule("text|p[text|style-name=width3em] { width: 3em; }\n"); // Width calculated to wrap at first space
|
||||
setCursorPosition(6);
|
||||
t.steps = t.counter.countStepsToLineBoundary(-1, t.filter);
|
||||
r.shouldBe(t, "t.steps", "-2");
|
||||
|
||||
@@ -62,13 +62,6 @@ runtime.loadClass("odf.TextStyleApplicatorTests");
|
||||
runtime.loadClass("xmldom.LSSerializerTests");
|
||||
runtime.loadClass("xmldom.XPathTests");
|
||||
|
||||
// qtjsruntimetest tests break if OdfCanvas is allowed to insert a dynamic <link/> element.
|
||||
// If a dynamic link is inserted, subsequent dynamic style sheets (document.createElement(...)) fail to result in
|
||||
// new entries being added to document.styleSheets.
|
||||
// This can easily be seen by commenting out the following and running ops.OdtCursorTests followed by ops.OdtDocumentTests.
|
||||
// As ops.OdtDocumentTests is the only test suite to rely on style behaviour functioning correctly and will report failures.
|
||||
webodf_css = "/* Need to prevent OdfCanvas from inserting it's own <link/> element. See tests.js for more information */";
|
||||
|
||||
/**
|
||||
* Holds the unit tests to run.
|
||||
* @type {!Array.<Function>}
|
||||
|
||||
Reference in New Issue
Block a user