aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Benjamin Jones <bjones@galois.com>2012-10-04 11:44:01 -0700
committerGravatar Benjamin Jones <bjones@galois.com>2012-10-04 11:44:01 -0700
commit0c9948b4d26a7341e1ea62290293fa28454d0185 (patch)
treebcd97e3666a8c5392085b5a04ae61b3d599c44ec
parent39e5b2b67f3e041c6d86f434480441965f00a04e (diff)
Added color, font, and image rulesets. Other minor cleanups.
-rw-r--r--exampleData/basic/testColorRules.html61
-rw-r--r--exampleData/basic/testFontRules.html19
-rw-r--r--exampleData/ruleSets/alwaysErrThreeTimes.json4
-rw-r--r--exampleData/ruleSets/colorRules.json74
-rw-r--r--exampleData/ruleSets/fontRules.json38
-rw-r--r--exampleData/ruleSets/imageRules.json10
-rw-r--r--exampleData/ruleSets/template.json41
-rw-r--r--exampleData/ruleSets/trivialReport.json2
8 files changed, 187 insertions, 62 deletions
diff --git a/exampleData/basic/testColorRules.html b/exampleData/basic/testColorRules.html
index 9faeae0..58aa7ce 100644
--- a/exampleData/basic/testColorRules.html
+++ b/exampleData/basic/testColorRules.html
@@ -1,23 +1,50 @@
<!DOCTYPE html>
<html>
- <head></head>
+
+ <title>Test Color Rules</title>
+ <head>
+
+ <!-- Simple embedded style sheet -->
+ <style type="text/css">
+ #nav-left { color: #C3C2C5; }
+ #nav-left a:hover { color: #B4B4B4; }
+ #nav-left a:active { color: #4E4E4E; }
+ </style>
+ </head>
+
<body>
-<h1>Color tests</h1>
-<p style="color: #FFFFF1">This (almost) is an FF paragraph.</p>
-<p style="color: #CCCCCC">This is an CC paragraph.</p>
-<p style="color: #3D3D3D">This is an 3D paragraph.</p>
-<p style="color: #000000">This is an 00 paragraph.</p>
-<hr>
-<p style="color: #3D3D3D; background-color: #C2C2C2">This is a paragraph with OK bg color</p>
-<p style="color: #3D3D3D; background-color: #CCCC00">This is a paragraph with BAD bg color</p>
-<hr>
-<div id="content" style="color: #F7F7F7">
- This is a DIV ID=content
-</div>
-random text here
-<div id="content" style="color: #C7C7C7">
- This is a DIV ID=content with bad colors!
-</div>
+
+ <div id='nav-left'>
+ Left Navigation
+ <ul>
+ <li><a href="#link1">A link</a></li>
+ <li><a href="#link2">Another link</a></li>
+ <li><a href="#link3">Yet a third link</a></li>
+ </ul>
+ </div>
+
+ <div id='main'>
+ <h1>Color tests</h1>
+ <p style="color: #FFFFF1">This (almost) is an FF paragraph.</p>
+ <p style="color: #CCCCCC">This is an CC paragraph.</p>
+ <p style="color: #3D3D3D">This is an 3D paragraph.</p>
+ <p style="color: #000000">This is an 00 paragraph.</p>
+ <hr>
+ <p style="color: #3D3D3D; background-color: #C2C2C2">This is a paragraph with OK bg color</p>
+ <p style="color: #3D3D3D; background-color: #CCCC00">This is a paragraph with BAD bg color</p>
+ <hr>
+ <div id="content" style="color: #F7F7F7">
+ This is a DIV ID=content
+ </div>
+ random text here
+ <div id="content" style="color: #C7C7C7">
+ This is a DIV ID=content with bad colors!
+ </div>
+ </div>
+
+ <a name="link1">link 1 ref</a>
+ <a name="link2">link 2 ref</a>
+ <a name="link3">link 3 ref</a>
</body>
</html>
diff --git a/exampleData/basic/testFontRules.html b/exampleData/basic/testFontRules.html
new file mode 100644
index 0000000..0de8fd5
--- /dev/null
+++ b/exampleData/basic/testFontRules.html
@@ -0,0 +1,19 @@
+<html>
+ <head>
+ <title>Test Font Rules</title>
+ </head>
+
+ <body>
+ <h1>Test Font Rules</h1>
+
+ <p style="font-family: Verdana; font-size: 12px; font-weight: bold">
+ This is Verdana / Bold / 12px
+ </p>
+
+ <p style="font-size: 150%">
+ This is inherited font at 150%
+ </p>
+
+ </body>
+</html>
+
diff --git a/exampleData/ruleSets/alwaysErrThreeTimes.json b/exampleData/ruleSets/alwaysErrThreeTimes.json
index f0301ab..9060f5d 100644
--- a/exampleData/ruleSets/alwaysErrThreeTimes.json
+++ b/exampleData/ruleSets/alwaysErrThreeTimes.json
@@ -1,5 +1,5 @@
{ "name": "always errors"
-, "description": "A trivila rule set for experimentation."
+, "description": "A trivial rule set for experimentation."
, "rules": [ { "id":13
, "name": "Reports three times"
, "description": "Test guideline that reports three errors"
@@ -20,4 +20,4 @@
}
}
]
-} \ No newline at end of file
+}
diff --git a/exampleData/ruleSets/colorRules.json b/exampleData/ruleSets/colorRules.json
index 5dfb7ca..c2862e4 100644
--- a/exampleData/ruleSets/colorRules.json
+++ b/exampleData/ruleSets/colorRules.json
@@ -1,8 +1,16 @@
+/* colorRules.json
+ * Author: Benjamin Jones <bjones@galois.com>
+ *
+ * Simple rules for checking that the colors of specific elements are in a specific set.
+ * Test using exampleData/basic/testColorRules.html
+ */
+
{ 'name': "Colors are in a specified set"
, 'description': "All background and foreground colors used on a page should be in a specificed set"
, 'rules': [
- { 'image-appears': "Foregrounds"
- , 'description': "Foreground colors are in a specified set"
+ { 'name': "Foregrounds"
+ , 'description': "Foreground colors should be in the set:"+
+ "'#0, #FFFFFF, #3D3D3D, #B4B4B4, #4E4E4E, #C2C2C2, #F7F7F7"
, 'rule':
function() { //----------------------------------------------
var allowableColors = { '#0': 1, '#FFFFFF': 1, '#3D3D3D': 1,
@@ -11,15 +19,17 @@
fiveui.query(':visible').each(
function(i, elt) {
var color = $(elt).css('color');
- // console.log('color: ' + color + ' --> ' + fiveui.colorToHex(color));
- if (!(fiveui.colorToHex(color) in allowableColors)) {
- report('Disallowed FOREground color appears');
+ if (!(fiveui.color.color.colorToHex(color) in allowableColors)) {
+ report('Disallowed FOREground color ' +
+ fiveui.color.colorToHex(color) +
+ ' appears', $(elt));
}
});
} //---------------------------------------------------------
},//==============================================================
- { 'image-appears': "Backgrounds"
- , 'description': "Backgrounds colors are in a specified set"
+ { 'name': "Backgrounds"
+ , 'description': "Backgrounds colors are in the set:" +
+ "#000000, #FFFFFF, #3D3D3D, #B4B4B4, #4E4E4E, #C2C2C2"
, 'rule':
function() { //----------------------------------------------
var allowableColors = { '#0': 1, '#FFFFFF': 1,
@@ -28,23 +38,59 @@
fiveui.query(':visible').each(
function(i, elt) {
var color = $(elt).css('background-color');
- if (!(fiveui.colorToHex(color) in allowableColors)) {
- report('Disallowed BACKground color appears');
+ if (!(fiveui.color.colorToHex(color) in allowableColors)) {
+ report('Disallowed BACKground color ' +
+ fiveui.color.colorToHex(color) +
+ ' appears', $(elt));
}
});
} //---------------------------------------------------------
},//==============================================================
- { 'image-appears': "Content Area Color"
- , 'description': "Content Area Color is #F7"
+ { 'name': "Content Area Color"
+ , 'description': "Content Area Color should be #F7"
, 'rule':
//----------
function() {
var allowableColors = { '#F7F7F7': 1 };
- fiveui.query("div[id='content'").each(
+ fiveui.query("#content").each(
function(i, elt) {
var color = $(elt).css('color');
- if (!(fiveui.colorToHex(color) in allowableColors)) {
- report('Invalid color in content area');
+ if (!(fiveui.color.colorToHex(color) in allowableColors)) {
+ report('Invalid color '+fiveui.color.colorToHex(color) +
+ ' in content area', $(elt));
+ }
+ });
+ } //---------------------------------------------------------
+ },//==============================================================
+ { 'name': "Left Nav Color"
+ , 'description': "Left Nav Color should be #C2 (#4E if active)"
+ , 'rule':
+ //----------
+ function() {
+ var allowableColors = { '#C2C2C2': 1 };
+ fiveui.query("#nav-left").each(
+ function(i, elt) {
+ var color = $(elt).css('color');
+ // if active then .. 4E
+ if (!(fiveui.color.colorToHex(color) in allowableColors)) {
+ report('Invalid color '+fiveui.color.colorToHex(color) +
+ ' in left nav area', $(elt));
+ }
+ });
+ } //---------------------------------------------------------
+ },//==============================================================
+ { 'name': "Header Color"
+ , 'description': "Header Color should be #3D"
+ , 'rule':
+ //----------
+ function() {
+ var allowableColors = { '#3D3D3D': 1 };
+ fiveui.query(":header").each(
+ function(i, elt) {
+ var color = $(elt).css('color');
+ if (!(fiveui.color.colorToHex(color) in allowableColors)) {
+ report('Invalid color '+fiveui.color.colorToHex(color) +
+ ' in header', $(elt));
}
});
} //---------------------------------------------------------
diff --git a/exampleData/ruleSets/fontRules.json b/exampleData/ruleSets/fontRules.json
new file mode 100644
index 0000000..a07fab4
--- /dev/null
+++ b/exampleData/ruleSets/fontRules.json
@@ -0,0 +1,38 @@
+/*
+ * fontRules.json
+ * Author: Benjamin Jones <bjones@galois.com>
+ *
+ * Simple rules for checking that fonts (family/weight/size) of specific elements are
+ * in a specific set.
+ *
+ * Test using exampleData/basic/testFontRules.html
+ */
+
+{ 'name': "Fonts (family/size/style) are in a specified set"
+, 'description': "All fonts used on a page should be in a specificed set"
+, 'rules': [
+ { 'name': "Font set"
+ , 'description': "Font (family/weight/size) should be in the set ..."
+ , 'rule':
+ function() { //----------------------------------------------
+ var allowableFonts = {
+ "Verdana": { "bold": ["25", "22", "12", "10"]
+ , "normal": ["12", "11", "10"] } }
+ fiveui.query('body *').each(
+ function(i, elt) {
+ var family = $(elt).css('font-family');
+ var sizeTxt = $(elt).css('font-size');
+ var size = /([1-9][0-9])/.exec(sizeTxt)[0];
+ var weight = $(elt).css('font-weight');
+ console.log('Found font: ' + family + size + weight);
+ if (!(family in allowableFonts) ||
+ !(weight in allowableFonts[family]) ||
+ !(size in allowableFonts[family][weight])) {
+ report('Disallowed font: ' +
+ family + size + weight, $(elt));
+ }
+ });
+ } //---------------------------------------------------------
+ }//==============================================================
+ ]
+}
diff --git a/exampleData/ruleSets/imageRules.json b/exampleData/ruleSets/imageRules.json
index 0ba8f77..924d750 100644
--- a/exampleData/ruleSets/imageRules.json
+++ b/exampleData/ruleSets/imageRules.json
@@ -1,3 +1,13 @@
+/*
+ * imageRules.json
+ * Author: Benjamin Jones <bjones@galois.com>
+ *
+ * Simple rules for checking that specific images appear on a page and that specific images
+ * link back to specific URLs.
+ *
+ * Test using exampleData/basic/testImageRules.html
+ */
+
{ 'name': "Image exists and links back to URL"
, 'description': "A specific image file should be included in the page and link back to a specific URL"
, 'rules': [
diff --git a/exampleData/ruleSets/template.json b/exampleData/ruleSets/template.json
index 6a5a886..3d098c7 100644
--- a/exampleData/ruleSets/template.json
+++ b/exampleData/ruleSets/template.json
@@ -1,32 +1,17 @@
-{ 'name': "Colors are in a specified set"
-, 'description': "All background and foreground colors used on a page should be in a specificed set"
+/*
+ * template.json
+ * Author: Benjamin Jones <bjones@galois.com>
+ *
+ * Template ruleset containing one empty rule.
+ */
+
+{ 'name': "NAME"
+, 'description': "DESCRIPTION"
, 'rules': [
- { 'image-appears': "Foregrounds"
- , 'description': "Foreground colors are in a specified set"
+ { 'name': "RULE NAME"
+ , 'description': "RULE DESC"
, 'rule':
- function() {
- var allowableColors = [ '#000000', '#FFFFFF', '#3D3D3D', '#B4B4B4', '#4E4E4E', '#C2C2C2' ];
- fiveui.query('').each(
- function(i, elt) {
- if ($(elt).css('color') in allowableColors) {
- $(elt).addClass('reportColor');
- }
- });
- }
+ function() {} // Function that checks the rule
},
- { 'image-appears': "Backgrounds"
- , 'description': "Backgrounds colors are in a specified set"
- , 'rule':
- function() {
- var allowableColors = [ 'transparent', '#000000', '#FFFFFF', '#3D3D3D', '#B4B4B4', '#4E4E4E', '#C2C2C2' ];
- fiveui.query('').each(
- function(i, elt) {
- if ($(elt).css('color') in allowableColors) {
- $(elt).addClass('reportBackColor');
- }
- });
- }
- }
-
- ]
+ ]
}
diff --git a/exampleData/ruleSets/trivialReport.json b/exampleData/ruleSets/trivialReport.json
index bd264d1..f14d3f6 100644
--- a/exampleData/ruleSets/trivialReport.json
+++ b/exampleData/ruleSets/trivialReport.json
@@ -4,4 +4,4 @@
'description': 'An empty test rule',
'rule': function() { report('test error'); }
} ]
-} \ No newline at end of file
+}