Add tests for font descriptors that are equivalent to test_value_storage and test_property_syntax_errors.

This commit is contained in:
L. David Baron 2009-03-09 16:14:34 -07:00
Родитель 75cee288ca
Коммит 81be042f5b
4 изменённых файлов: 279 добавлений и 0 удалений

Просмотреть файл

@ -103,6 +103,8 @@ _TEST_FILES = test_acid3_test46.html \
test_cascade.html \
test_compute_data_with_start_struct.html \
test_css_eof_handling.html \
test_descriptor_storage.html \
test_descriptor_syntax_errors.html \
test_dont_use_document_colors.html \
test_font_face_parser.html \
test_hover.html \
@ -130,6 +132,7 @@ _TEST_FILES = test_acid3_test46.html \
test_visited_pref.html \
css_properties.js \
property_database.js \
descriptor_database.js \
unstyled.xml \
unstyled.css \
unstyled-frame.xml \

Просмотреть файл

@ -0,0 +1,95 @@
/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* vim: set shiftwidth=4 tabstop=4 autoindent cindent noexpandtab: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is property_database.js.
*
* The Initial Developer of the Original Code is the Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2007
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* L. David Baron <dbaron@dbaron.org>, Mozilla Corporation (original author)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
// Each property has the following fields:
// domProp: The name of the relevant member of nsIDOM[NS]CSS2Properties
// values: Strings that are values for the descriptor and should be accepted.
// invalid_values: Things that are not values for the descriptor and
// should be rejected.
var gCSSFontFaceDescriptors = {
"font-family": {
domProp: "fontFamily",
values: [ "\"serif\"", "\"cursive\"", "seriff", "Times New Roman", "TimesRoman", "\"Times New Roman\"" ],
/* not clear that the generics are really invalid */
invalid_values: [ "sans-serif", "Times New Roman, serif", "'Times New Roman', serif", "cursive", "fantasy" ]
},
"font-stretch": {
domProp: "fontStretch",
values: [ "normal", "ultra-condensed", "extra-condensed", "condensed", "semi-condensed", "semi-expanded", "expanded", "extra-expanded", "ultra-expanded" ],
invalid_values: [ "wider", "narrower" ]
},
"font-style": {
domProp: "fontStyle",
values: [ "normal", "italic", "oblique" ],
invalid_values: []
},
"font-weight": {
domProp: "fontWeight",
values: [ "normal", "400", "bold", "100", "200", "300", "500", "600", "700", "800", "900" ],
invalid_values: [ "107", "399", "401", "699", "710", "bolder", "lighter" ]
},
"src": {
domProp: null,
values: [
"url(404.ttf)",
"url(\"404.eot\")",
"url(\'404.otf\')",
"url(404.ttf) format(\"truetype\")",
"url(404.ttf) format(\"truetype\", \"opentype\")",
"url(404.ttf) format(\"truetype\", \"opentype\"), url(\'404.eot\')",
"local(Times New Roman)",
"local(\'Times New Roman\')",
"local(\"Times New Roman\")",
"local(serif)", /* is this valid? */
"local(\"serif\")",
"url(404.ttf) format(\"truetype\", \"unknown\"), local(Times New Roman), url(\'404.eot\')",
],
invalid_values: [
"url(404.ttf) format(truetype)",
"url(404.ttf) format(\"truetype\" \"opentype\")",
"url(404.ttf) format(\"truetype\",)",
"local(\"Times New\" Roman)",
]
},
"unicode-range": {
domProp: null,
values: [ "U+0-10FFFF", "U+3-7B3", "U+3??", "U+6A", "U+3????", "U+???", "U+302-302", "U+0-7,A-C", "U+100-17F,200-17F", "U+3??, U+500-513 ,U+612 , U+4????", "U+1FFF,U+200-27F" ],
invalid_values: [ "U+1????-2????" ]
}
}

Просмотреть файл

@ -0,0 +1,127 @@
<!DOCTYPE HTML>
<html>
<!--
-->
<head>
<title>Test for parsing, storage, and serialization of CSS @font-face descriptor values</title>
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="descriptor_database.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
/** Test for parsing, storage, and serialization of CSS @font-face descriptor values **/
/*
* For explanation of some of the more interesting tests here, see the comment
* in test_value_storage.html .
*/
var gStyleElement = document.createElement("style");
gStyleElement.setAttribute("type", "text/css");
document.getElementsByTagName("head")[0].appendChild(gStyleElement);
var gSheet = gStyleElement.sheet;
gSheet.insertRule("@font-face { }", 0);
var gRule = gSheet.cssRules[0];
var gDeclaration = gRule.style;
function fake_set_property(descriptor, value) {
gSheet.deleteRule(0);
gSheet.insertRule("@font-face { " + descriptor + ": " + value + "}", 0);
gRule = gSheet.cssRules[0];
gDeclaration = gRule.style;
}
function xfail_parse(descriptor, value) {
switch (descriptor) {
case "unicode-range":
// not yet implemented
return true;
case "src":
// not clear whether this is an error or not, so mark todo for now
return value == "local(serif)";
}
return false;
}
function test_descriptor(descriptor)
{
var info = gCSSFontFaceDescriptors[descriptor];
function test_value(value) {
// // We don't implement SetProperty yet (bug 443978).
// gDeclaration.setProperty(descriptor, value, "");
fake_set_property(descriptor, value);
var idx;
var step1val = gDeclaration.getPropertyValue(descriptor);
var step1ser = gDeclaration.cssText;
var func = xfail_parse(descriptor, value) ? todo_isnot : isnot;
func(step1val, "", "setting '" + value + "' on '" + descriptor + "'");
// We don't care particularly about the whitespace or the placement of
// semicolons, but for simplicity we'll test the current behavior.
var expected_serialization = "";
if (step1val != "")
expected_serialization = " " + descriptor + ": " + step1val + ";\n";
is(step1ser, expected_serialization,
"serialization should match descriptor value");
gDeclaration.removeProperty(descriptor);
// // We don't implement SetProperty yet (bug 443978).
// gDeclaration.setProperty(descriptor, step1val, "");
fake_set_property(descriptor, step1val);
is(gDeclaration.getPropertyValue(descriptor), step1val,
"parse+serialize should be idempotent for '" +
descriptor + ": " + value + "'");
gDeclaration.removeProperty(descriptor);
}
var idx;
for (idx in info.values)
test_value(info.values[idx]);
}
// To avoid triggering the slow script dialog, we have to test one
// descriptor at a time.
SimpleTest.waitForExplicitFinish();
var descs = [];
for (var desc in gCSSFontFaceDescriptors)
descs.push(desc);
descs = descs.reverse();
function do_one(l) {
if (l.length == 0) {
// SimpleTest.finish() is really slow, so we have to disable the
// slow script dialog for this part
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var prefService = Components.classes["@mozilla.org/preferences-service;1"].
getService(Components.interfaces.nsIPrefService);
var domBranch = prefService.getBranch("dom.");
var oldVal = domBranch.getIntPref("max_script_run_time");
domBranch.setIntPref("max_script_run_time", 0);
SimpleTest.finish();
domBranch.setIntPref("max_script_run_time", oldVal);
return;
}
test_descriptor(l.pop());
setTimeout(do_one, 0, l);
}
setTimeout(do_one, 0, descs);
</script>
</pre>
</body>
</html>

Просмотреть файл

@ -0,0 +1,54 @@
<!DOCTYPE HTML>
<html>
<!--
-->
<head>
<title>Test that we reject syntax errors listed in descriptor_database.js</title>
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="descriptor_database.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
var gStyleElement = document.createElement("style");
gStyleElement.setAttribute("type", "text/css");
document.getElementsByTagName("head")[0].appendChild(gStyleElement);
var gSheet = gStyleElement.sheet;
gSheet.insertRule("@font-face { }", 0);
var gRule = gSheet.cssRules[0];
var gDeclaration = gRule.style;
function fake_set_property(descriptor, value) {
gSheet.deleteRule(0);
gSheet.insertRule("@font-face { " + descriptor + ": " + value + "}", 0);
gRule = gSheet.cssRules[0];
gDeclaration = gRule.style;
}
for (var descriptor in gCSSFontFaceDescriptors) {
var info = gCSSFontFaceDescriptors[descriptor];
for (var idx in info.invalid_values) {
var badval = info.invalid_values[idx];
// // We don't implement SetProperty yet (bug 443978).
// gDeclaration.setProperty(descriptor, badval, "");
fake_set_property(descriptor, badval);
is(gDeclaration.getPropertyValue(descriptor), "",
"invalid value '" + badval + "' not accepted for '" + descriptor +
"' descriptor");
gDeclaration.removeProperty(descriptor);
}
}
</script>
</pre>
</body>
</html>