Bug 1240735 - Add tests for theme_color and background_color members. r=baku
--- a/dom/manifest/test/mochitest.ini
+++ b/dom/manifest/test/mochitest.ini
@@ -3,18 +3,20 @@ support-files =
common.js
resource.sjs
manifestLoader.html
[test_ImageObjectProcessor_background_color.html]
[test_ImageObjectProcessor_density.html]
[test_ImageObjectProcessor_sizes.html]
[test_ImageObjectProcessor_src.html]
[test_ImageObjectProcessor_type.html]
+[test_ManifestProcessor_background_color.html]
[test_ManifestProcessor_display.html]
[test_ManifestProcessor_icons.html]
[test_ManifestProcessor_JSON.html]
[test_ManifestProcessor_lang.html]
[test_ManifestProcessor_name_and_short_name.html]
[test_ManifestProcessor_orientation.html]
[test_ManifestProcessor_scope.html]
[test_ManifestProcessor_splash_screens.html]
[test_ManifestProcessor_start_url.html]
+[test_ManifestProcessor_theme_color.html]
[test_ManifestProcessor_warnings.html]
new file mode 100644
--- /dev/null
+++ b/dom/manifest/test/test_ManifestProcessor_background_color.html
@@ -0,0 +1,94 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1195018
+-->
+<head>
+ <meta charset="utf-8">
+ <title>Test for Bug 1195018</title>
+ <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+ <script src="common.js"></script>
+ <script>
+/**
+ * background_color member
+ * https://w3c.github.io/manifest/#background_color-member
+ **/
+'use strict';
+
+typeTests.forEach(type => {
+ data.jsonText = JSON.stringify({
+ background_color: type
+ });
+ var result = processor.process(data);
+
+ is(result.background_color, undefined, `Expect non-string background_color to be undefined: ${typeof type}.`);
+});
+
+var validThemeColors = [
+ 'maroon',
+ '#f00',
+ '#ff0000',
+ 'rgb(255,0,0)',
+ 'rgb(100%, 0%, 0%)',
+ 'rgb(255,0,0)',
+ 'rgb(300,0,0)',
+ 'rgb(255,-10,0)',
+ 'rgb(110%, 0%, 0%)',
+ 'rgb(255,0,0)',
+ 'rgba(255,0,0,1)',
+ 'rgb(100%,0%,0%)',
+ 'rgba(100%,0%,0%,1)',
+ 'rgba(0,0,255,0.5)',
+ 'rgba(100%, 50%, 0%, 0.1)',
+ 'hsl(120, 100%, 50%)',
+ 'hsla(120, 100%, 50%, 1)',
+];
+
+validThemeColors.forEach(background_color => {
+ data.jsonText = JSON.stringify({
+ background_color: background_color
+ });
+ var result = processor.process(data);
+
+ is(result.background_color, background_color, `Expect background_color to be returned: ${background_color}.`);
+});
+
+var invalidThemeColors = [
+ 'marooon',
+ 'f000000',
+ '#ff00000',
+ 'rgb(255 0 0)',
+ 'rgb(100, 0%, 0%)',
+ 'rgb(255,0)',
+ 'rgb(300 0 0)',
+ 'rbg(255,-10,0)',
+ 'rgb(110, 0%, 0%)',
+ '(255,0,0) }',
+ 'rgba(255)',
+ ' rgb(100%,0%,0%) }',
+ 'hsl 120, 100%, 50%',
+ 'hsla{120, 100%, 50%, 1}',
+]
+
+invalidThemeColors.forEach(background_color => {
+ data.jsonText = JSON.stringify({
+ background_color: background_color
+ });
+ var result = processor.process(data);
+
+ is(result.background_color, undefined, `Expect background_color to be undefined: ${background_color}.`);
+});
+
+// Trim tests
+validThemeColors.forEach(background_color => {
+ var expandedThemeColor = `${seperators}${lineTerminators}${background_color}${lineTerminators}${seperators}`;
+ data.jsonText = JSON.stringify({
+ background_color: expandedThemeColor
+ });
+ var result = processor.process(data);
+
+ is(result.background_color, background_color, `Expect trimmed background_color to be returned.`);
+});
+ </script>
+</head>
new file mode 100644
--- /dev/null
+++ b/dom/manifest/test/test_ManifestProcessor_theme_color.html
@@ -0,0 +1,94 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1195018
+-->
+<head>
+ <meta charset="utf-8">
+ <title>Test for Bug 1195018</title>
+ <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+ <script src="common.js"></script>
+ <script>
+/**
+ * theme_color member
+ * https://w3c.github.io/manifest/#theme_color-member
+ **/
+'use strict';
+
+typeTests.forEach(type => {
+ data.jsonText = JSON.stringify({
+ theme_color: type
+ });
+ var result = processor.process(data);
+
+ is(result.theme_color, undefined, `Expect non-string theme_color to be undefined: ${typeof type}.`);
+});
+
+var validThemeColors = [
+ 'maroon',
+ '#f00',
+ '#ff0000',
+ 'rgb(255,0,0)',
+ 'rgb(100%, 0%, 0%)',
+ 'rgb(255,0,0)',
+ 'rgb(300,0,0)',
+ 'rgb(255,-10,0)',
+ 'rgb(110%, 0%, 0%)',
+ 'rgb(255,0,0)',
+ 'rgba(255,0,0,1)',
+ 'rgb(100%,0%,0%)',
+ 'rgba(100%,0%,0%,1)',
+ 'rgba(0,0,255,0.5)',
+ 'rgba(100%, 50%, 0%, 0.1)',
+ 'hsl(120, 100%, 50%)',
+ 'hsla(120, 100%, 50%, 1)',
+];
+
+validThemeColors.forEach(theme_color => {
+ data.jsonText = JSON.stringify({
+ theme_color: theme_color
+ });
+ var result = processor.process(data);
+
+ is(result.theme_color, theme_color, `Expect theme_color to be returned: ${theme_color}.`);
+});
+
+var invalidThemeColors = [
+ 'marooon',
+ 'f000000',
+ '#ff00000',
+ 'rgb(255 0 0)',
+ 'rgb(100, 0%, 0%)',
+ 'rgb(255,0)',
+ 'rgb(300 0 0)',
+ 'rbg(255,-10,0)',
+ 'rgb(110, 0%, 0%)',
+ '(255,0,0) }',
+ 'rgba(255)',
+ ' rgb(100%,0%,0%) }',
+ 'hsl 120, 100%, 50%',
+ 'hsla{120, 100%, 50%, 1}',
+]
+
+invalidThemeColors.forEach(theme_color => {
+ data.jsonText = JSON.stringify({
+ theme_color: theme_color
+ });
+ var result = processor.process(data);
+
+ is(result.theme_color, undefined, `Expect theme_color to be undefined: ${theme_color}.`);
+});
+
+// Trim tests
+validThemeColors.forEach(theme_color => {
+ var expandedThemeColor = `${seperators}${lineTerminators}${theme_color}${lineTerminators}${seperators}`;
+ data.jsonText = JSON.stringify({
+ theme_color: expandedThemeColor
+ });
+ var result = processor.process(data);
+
+ is(result.theme_color, theme_color, `Expect trimmed theme_color to be returned.`);
+});
+ </script>
+</head>