Bug 1266627 - Web Manifest: Normalize enumerable values to lowercase. r=mconley
authorMarcos Caceres <marcos@marcosc.com>
Wed, 25 May 2016 18:44:00 -0400
changeset 299085 151e42dd75fb1103782c982af98e472dde418b35
parent 299084 76dd48ec6e04b64621b5d301f90ce0445ee7e6e2
child 299086 796f83f7888a091c5596c25f9a86b77504b25075
push id77426
push userryanvm@gmail.com
push dateThu, 26 May 2016 03:59:28 +0000
treeherdermozilla-inbound@5f821afd7299 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmconley
bugs1266627
milestone49.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1266627 - Web Manifest: Normalize enumerable values to lowercase. r=mconley
dom/manifest/ManifestProcessor.jsm
dom/manifest/test/test_ManifestProcessor_display.html
dom/manifest/test/test_ManifestProcessor_orientation.html
--- a/dom/manifest/ManifestProcessor.jsm
+++ b/dom/manifest/ManifestProcessor.jsm
@@ -141,34 +141,34 @@ this.ManifestProcessor = { // jshint ign
       const spec = {
         objectName: 'manifest',
         object: rawManifest,
         property: 'orientation',
         expectedType: 'string',
         trim: true
       };
       const value = extractor.extractValue(spec);
-      if (this.orientationTypes.has(value)) {
-        return value;
+      if (value && typeof value === "string" && this.orientationTypes.has(value.toLowerCase())) {
+        return value.toLowerCase();
       }
       // The spec special-cases orientation to return the empty string.
       return '';
     }
 
     function processDisplayMember() {
       const spec = {
         objectName: 'manifest',
         object: rawManifest,
         property: 'display',
         expectedType: 'string',
         trim: true
       };
       const value = extractor.extractValue(spec);
-      if (displayModes.has(value)) {
-        return value;
+      if (value && typeof value === "string" && displayModes.has(value.toLowerCase())) {
+        return value.toLowerCase();
       }
       return this.defaultDisplayMode;
     }
 
     function processScopeMember() {
       const spec = {
         objectName: 'manifest',
         object: rawManifest,
--- a/dom/manifest/test/test_ManifestProcessor_display.html
+++ b/dom/manifest/test/test_ManifestProcessor_display.html
@@ -20,40 +20,57 @@ typeTests.forEach((type) => {
   var expected = `Expect non - string display to default to "browser".`;
   data.jsonText = JSON.stringify({
     display: type
   });
   var result = processor.process(data);
   is(result.display, 'browser', expected);
 });
 
-/*Test valid modes*/
-var validModes = ['fullscreen', 'standalone', 'minimal-ui', 'browser']
+/*Test valid modes - case insensitive*/
+var validModes = [
+  'fullscreen',
+  'standalone',
+  'minimal-ui',
+  'browser',
+  'FullScreen',
+  'standAlone',
+  'minimal-UI',
+  'BROWSER',
+]
 validModes.forEach((mode) => {
-  var expected = `Expect display mode to be ${mode}.`;
+  var expected = `Expect display mode to be ${mode.toLowerCase()}.`;
   data.jsonText = JSON.stringify({
     display: mode
   });
   var result = processor.process(data);
-  is(result.display, mode, expected);
+  is(result.display, mode.toLowerCase(), expected);
 });
 
 //trim tests
 validModes.forEach((display) => {
   var expected = `Expect trimmed display mode to be returned.`;
   var expandedDisplay =  seperators + lineTerminators + display + lineTerminators + seperators;
   data.jsonText = JSON.stringify({
     display: expandedDisplay
   });
   var result = processor.process(data);
-  is(result.display, display, expected);
+  is(result.display, display.toLowerCase(), expected);
 });
 
 //Unknown modes
-var invalidModes = ['foo', `fooo${whiteSpace}`, '', 'fullscreen,standalone', 'standalone fullscreen', 'FULLSCreEN'];
+var invalidModes = [
+  'foo',
+  `fooo${whiteSpace}`,
+  '',
+  'fullscreen,standalone',
+  'standalone fullscreen',
+  'FULLSCreENS',
+];
+
 invalidModes.forEach((invalidMode) => {
   var expected = `Expect default display mode "browser" to be returned: '${invalidMode}'`;
   data.jsonText = JSON.stringify({
     display: invalidMode
   });
   var result = processor.process(data);
   is(result.display, 'browser', expected);
 });
--- a/dom/manifest/test/test_ManifestProcessor_orientation.html
+++ b/dom/manifest/test/test_ManifestProcessor_orientation.html
@@ -20,64 +20,67 @@ typeTests.forEach((type) => {
   var expected = `Expect non-string orientation to be empty string : ${typeof type}.`;
   data.jsonText = JSON.stringify({
     orientation: type
   });
   var result = processor.process(data);
   is(result.orientation, '', expected);
 });
 
-
 var validOrientations = [
   'any',
   'natural',
   'landscape',
   'portrait',
   'portrait-primary',
   'portrait-secondary',
   'landscape-primary',
-  'landscape-secondary'
+  'landscape-secondary',
+  'aNy',
+  'NaTuRal',
+  'LANDsCAPE',
+  'PORTRAIT',
+  'portrait-PRIMARY',
+  'portrait-SECONDARY',
+  'LANDSCAPE-primary',
+  'LANDSCAPE-secondary',
 ];
 
 validOrientations.forEach((orientation) => {
   var expected = `Expect orientation to be returned: ${orientation}.`;
-  data.jsonText = JSON.stringify({
-    orientation: orientation
-  });
+  data.jsonText = JSON.stringify({ orientation });
   var result = processor.process(data);
-  is(result.orientation, orientation, expected);
+  is(result.orientation, orientation.toLowerCase(), expected);
 });
 
 var invalidOrientations = [
   'all',
-  'ANY',
-  'NaTuRal',
+  'ANYMany',
+  'NaTuRalle',
   'portrait-primary portrait-secondary',
   'portrait-primary,portrait-secondary',
   'any-natural',
   'portrait-landscape',
   'primary-portrait',
   'secondary-portrait',
   'landscape-landscape',
   'secondary-primary'
-]
+];
 
 invalidOrientations.forEach((orientation) => {
   var expected = `Expect orientation to be empty string: ${orientation}.`;
-  data.jsonText = JSON.stringify({
-    orientation: orientation
-  });
+  data.jsonText = JSON.stringify({ orientation });
   var result = processor.process(data);
   is(result.orientation, "", expected);
 });
 
 //Trim tests
 validOrientations.forEach((orientation) => {
   var expected = `Expect trimmed orientation to be returned.`;
   var expandedOrientation = `${seperators}${lineTerminators}${orientation}${lineTerminators}${seperators}`;
   data.jsonText = JSON.stringify({
     orientation: expandedOrientation
   });
   var result = processor.process(data);
-  is(result.orientation, orientation, expected);
+  is(result.orientation, orientation.toLowerCase(), expected);
 });
   </script>
 </head>