browser/devtools/commandline/test/browser_gcli_date.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/commandline/test/browser_gcli_date.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,373 @@
     1.4 +/*
     1.5 + * Copyright 2012, Mozilla Foundation and contributors
     1.6 + *
     1.7 + * Licensed under the Apache License, Version 2.0 (the "License");
     1.8 + * you may not use this file except in compliance with the License.
     1.9 + * You may obtain a copy of the License at
    1.10 + *
    1.11 + * http://www.apache.org/licenses/LICENSE-2.0
    1.12 + *
    1.13 + * Unless required by applicable law or agreed to in writing, software
    1.14 + * distributed under the License is distributed on an "AS IS" BASIS,
    1.15 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    1.16 + * See the License for the specific language governing permissions and
    1.17 + * limitations under the License.
    1.18 + */
    1.19 +
    1.20 +'use strict';
    1.21 +// <INJECTED SOURCE:START>
    1.22 +
    1.23 +// THIS FILE IS GENERATED FROM SOURCE IN THE GCLI PROJECT
    1.24 +// DO NOT EDIT IT DIRECTLY
    1.25 +
    1.26 +var exports = {};
    1.27 +
    1.28 +var TEST_URI = "data:text/html;charset=utf-8,<p id='gcli-input'>gcli-testDate.js</p>";
    1.29 +
    1.30 +function test() {
    1.31 +  return Task.spawn(function() {
    1.32 +    let options = yield helpers.openTab(TEST_URI);
    1.33 +    yield helpers.openToolbar(options);
    1.34 +    gcli.addItems(mockCommands.items);
    1.35 +
    1.36 +    yield helpers.runTests(options, exports);
    1.37 +
    1.38 +    gcli.removeItems(mockCommands.items);
    1.39 +    yield helpers.closeToolbar(options);
    1.40 +    yield helpers.closeTab(options);
    1.41 +  }).then(finish, helpers.handleError);
    1.42 +}
    1.43 +
    1.44 +// <INJECTED SOURCE:END>
    1.45 +
    1.46 +// var assert = require('../testharness/assert');
    1.47 +// var helpers = require('./helpers');
    1.48 +
    1.49 +var Status = require('gcli/types/types').Status;
    1.50 +
    1.51 +exports.testParse = function(options) {
    1.52 +  var date = options.requisition.types.createType('date');
    1.53 +  return date.parseString('now').then(function(conversion) {
    1.54 +    // Date comparison - these 2 dates may not be the same, but how close is
    1.55 +    // close enough? If this test takes more than 30secs to run the it will
    1.56 +    // probably time out, so we'll assume that these 2 values must be within
    1.57 +    // 1 min of each other
    1.58 +    var gap = new Date().getTime() - conversion.value.getTime();
    1.59 +    assert.ok(gap < 60000, 'now is less than a minute away');
    1.60 +
    1.61 +    assert.is(conversion.getStatus(), Status.VALID, 'now parse');
    1.62 +  });
    1.63 +};
    1.64 +
    1.65 +exports.testMaxMin = function(options) {
    1.66 +  var max = new Date();
    1.67 +  var min = new Date();
    1.68 +  var types = options.requisition.types;
    1.69 +  var date = types.createType({ name: 'date', max: max, min: min });
    1.70 +  assert.is(date.getMax(), max, 'max setup');
    1.71 +
    1.72 +  var incremented = date.increment(min);
    1.73 +  assert.is(incremented, max, 'incremented');
    1.74 +};
    1.75 +
    1.76 +exports.testIncrement = function(options) {
    1.77 +  var date = options.requisition.types.createType('date');
    1.78 +  return date.parseString('now').then(function(conversion) {
    1.79 +    var plusOne = date.increment(conversion.value);
    1.80 +    var minusOne = date.decrement(plusOne);
    1.81 +
    1.82 +    // See comments in testParse
    1.83 +    var gap = new Date().getTime() - minusOne.getTime();
    1.84 +    assert.ok(gap < 60000, 'now is less than a minute away');
    1.85 +  });
    1.86 +};
    1.87 +
    1.88 +exports.testInput = function(options) {
    1.89 +  return helpers.audit(options, [
    1.90 +    {
    1.91 +      setup:    'tsdate 2001-01-01 1980-01-03',
    1.92 +      check: {
    1.93 +        input:  'tsdate 2001-01-01 1980-01-03',
    1.94 +        hints:                              '',
    1.95 +        markup: 'VVVVVVVVVVVVVVVVVVVVVVVVVVVV',
    1.96 +        status: 'VALID',
    1.97 +        message: '',
    1.98 +        args: {
    1.99 +          command: { name: 'tsdate' },
   1.100 +          d1: {
   1.101 +            value: function(d1) {
   1.102 +              assert.is(d1.getFullYear(), 2001, 'd1 year');
   1.103 +              assert.is(d1.getMonth(), 0, 'd1 month');
   1.104 +              assert.is(d1.getDate(), 1, 'd1 date');
   1.105 +              assert.is(d1.getHours(), 0, 'd1 hours');
   1.106 +              assert.is(d1.getMinutes(), 0, 'd1 minutes');
   1.107 +              assert.is(d1.getSeconds(), 0, 'd1 seconds');
   1.108 +              assert.is(d1.getMilliseconds(), 0, 'd1 millis');
   1.109 +            },
   1.110 +            arg: ' 2001-01-01',
   1.111 +            status: 'VALID',
   1.112 +            message: ''
   1.113 +          },
   1.114 +          d2: {
   1.115 +            value: function(d2) {
   1.116 +              assert.is(d2.getFullYear(), 1980, 'd2 year');
   1.117 +              assert.is(d2.getMonth(), 0, 'd2 month');
   1.118 +              assert.is(d2.getDate(), 3, 'd2 date');
   1.119 +              assert.is(d2.getHours(), 0, 'd2 hours');
   1.120 +              assert.is(d2.getMinutes(), 0, 'd2 minutes');
   1.121 +              assert.is(d2.getSeconds(), 0, 'd2 seconds');
   1.122 +              assert.is(d2.getMilliseconds(), 0, 'd2 millis');
   1.123 +            },
   1.124 +            arg: ' 1980-01-03',
   1.125 +            status: 'VALID',
   1.126 +            message: ''
   1.127 +          },
   1.128 +        }
   1.129 +      },
   1.130 +      exec: {
   1.131 +        output: [ /^Exec: tsdate/, /2001/, /1980/ ],
   1.132 +        type: 'string',
   1.133 +        error: false
   1.134 +      }
   1.135 +    },
   1.136 +    {
   1.137 +      setup:    'tsdate 2001/01/01 1980/01/03',
   1.138 +      check: {
   1.139 +        input:  'tsdate 2001/01/01 1980/01/03',
   1.140 +        hints:                              '',
   1.141 +        markup: 'VVVVVVVVVVVVVVVVVVVVVVVVVVVV',
   1.142 +        status: 'VALID',
   1.143 +        message: '',
   1.144 +        args: {
   1.145 +          command: { name: 'tsdate' },
   1.146 +          d1: {
   1.147 +            value: function(d1) {
   1.148 +              assert.is(d1.getFullYear(), 2001, 'd1 year');
   1.149 +              assert.is(d1.getMonth(), 0, 'd1 month');
   1.150 +              assert.is(d1.getDate(), 1, 'd1 date');
   1.151 +              assert.is(d1.getHours(), 0, 'd1 hours');
   1.152 +              assert.is(d1.getMinutes(), 0, 'd1 minutes');
   1.153 +              assert.is(d1.getSeconds(), 0, 'd1 seconds');
   1.154 +              assert.is(d1.getMilliseconds(), 0, 'd1 millis');
   1.155 +            },
   1.156 +            arg: ' 2001/01/01',
   1.157 +            status: 'VALID',
   1.158 +            message: ''
   1.159 +          },
   1.160 +          d2: {
   1.161 +            value: function(d2) {
   1.162 +              assert.is(d2.getFullYear(), 1980, 'd2 year');
   1.163 +              assert.is(d2.getMonth(), 0, 'd2 month');
   1.164 +              assert.is(d2.getDate(), 3, 'd2 date');
   1.165 +              assert.is(d2.getHours(), 0, 'd2 hours');
   1.166 +              assert.is(d2.getMinutes(), 0, 'd2 minutes');
   1.167 +              assert.is(d2.getSeconds(), 0, 'd2 seconds');
   1.168 +              assert.is(d2.getMilliseconds(), 0, 'd2 millis');
   1.169 +            },
   1.170 +            arg: ' 1980/01/03',
   1.171 +            status: 'VALID',
   1.172 +            message: ''
   1.173 +          },
   1.174 +        }
   1.175 +      },
   1.176 +      exec: {
   1.177 +        output: [ /^Exec: tsdate/, /2001/, /1980/ ],
   1.178 +        type: 'string',
   1.179 +        error: false
   1.180 +      }
   1.181 +    },
   1.182 +    {
   1.183 +      setup:    'tsdate now today',
   1.184 +      check: {
   1.185 +        input:  'tsdate now today',
   1.186 +        hints:                  '',
   1.187 +        markup: 'VVVVVVVVVVVVVVVV',
   1.188 +        status: 'VALID',
   1.189 +        message: '',
   1.190 +        args: {
   1.191 +          command: { name: 'tsdate' },
   1.192 +          d1: {
   1.193 +            value: function(d1) {
   1.194 +              // How long should we allow between d1 and now? Mochitest will
   1.195 +              // time out after 30 secs, so that seems like a decent upper
   1.196 +              // limit, although 30 ms should probably do it. I don't think
   1.197 +              // reducing the limit from 30 secs will find any extra bugs
   1.198 +              assert.ok(d1.getTime() - new Date().getTime() < 30 * 1000,
   1.199 +                        'd1 time');
   1.200 +            },
   1.201 +            arg: ' now',
   1.202 +            status: 'VALID',
   1.203 +            message: ''
   1.204 +          },
   1.205 +          d2: {
   1.206 +            value: function(d2) {
   1.207 +              // See comment for d1 above
   1.208 +              assert.ok(d2.getTime() - new Date().getTime() < 30 * 1000,
   1.209 +                        'd2 time');
   1.210 +            },
   1.211 +            arg: ' today',
   1.212 +            status: 'VALID',
   1.213 +            message: ''
   1.214 +          },
   1.215 +        }
   1.216 +      },
   1.217 +      exec: {
   1.218 +        output: [ /^Exec: tsdate/, new Date().getFullYear() ],
   1.219 +        type: 'string',
   1.220 +        error: false
   1.221 +      }
   1.222 +    },
   1.223 +    {
   1.224 +      setup:    'tsdate yesterday tomorrow',
   1.225 +      check: {
   1.226 +        input:  'tsdate yesterday tomorrow',
   1.227 +        hints:                           '',
   1.228 +        markup: 'VVVVVVVVVVVVVVVVVVVVVVVVV',
   1.229 +        status: 'VALID',
   1.230 +        message: '',
   1.231 +        args: {
   1.232 +          command: { name: 'tsdate' },
   1.233 +          d1: {
   1.234 +            value: function(d1) {
   1.235 +              var compare = new Date().getTime() - (24 * 60 * 60 * 1000);
   1.236 +              // See comment for d1 in the test for 'tsdate now today'
   1.237 +              assert.ok(d1.getTime() - compare < 30 * 1000,
   1.238 +                        'd1 time');
   1.239 +            },
   1.240 +            arg: ' yesterday',
   1.241 +            status: 'VALID',
   1.242 +            message: ''
   1.243 +          },
   1.244 +          d2: {
   1.245 +            value: function(d2) {
   1.246 +              var compare = new Date().getTime() + (24 * 60 * 60 * 1000);
   1.247 +              // See comment for d1 in the test for 'tsdate now today'
   1.248 +              assert.ok(d2.getTime() - compare < 30 * 1000,
   1.249 +                        'd2 time');
   1.250 +            },
   1.251 +            arg: ' tomorrow',
   1.252 +            status: 'VALID',
   1.253 +            message: ''
   1.254 +          },
   1.255 +        }
   1.256 +      },
   1.257 +      exec: {
   1.258 +        output: [ /^Exec: tsdate/, new Date().getFullYear() ],
   1.259 +        type: 'string',
   1.260 +        error: false
   1.261 +      }
   1.262 +    }
   1.263 +  ]);
   1.264 +};
   1.265 +
   1.266 +exports.testIncrDecr = function(options) {
   1.267 +  return helpers.audit(options, [
   1.268 +    {
   1.269 +      // createRequisitionAutomator doesn't fake UP/DOWN well enough
   1.270 +      skipRemainingIf: options.isNoDom,
   1.271 +      setup:    'tsdate 2001-01-01<UP>',
   1.272 +      check: {
   1.273 +        input:  'tsdate 2001-01-02',
   1.274 +        hints:                    ' <d2>',
   1.275 +        markup: 'VVVVVVVVVVVVVVVVV',
   1.276 +        status: 'ERROR',
   1.277 +        message: '',
   1.278 +        args: {
   1.279 +          command: { name: 'tsdate' },
   1.280 +          d1: {
   1.281 +            value: function(d1) {
   1.282 +              assert.is(d1.getFullYear(), 2001, 'd1 year');
   1.283 +              assert.is(d1.getMonth(), 0, 'd1 month');
   1.284 +              assert.is(d1.getDate(), 2, 'd1 date');
   1.285 +              assert.is(d1.getHours(), 0, 'd1 hours');
   1.286 +              assert.is(d1.getMinutes(), 0, 'd1 minutes');
   1.287 +              assert.is(d1.getSeconds(), 0, 'd1 seconds');
   1.288 +              assert.is(d1.getMilliseconds(), 0, 'd1 millis');
   1.289 +            },
   1.290 +            arg: ' 2001-01-02',
   1.291 +            status: 'VALID',
   1.292 +            message: ''
   1.293 +          },
   1.294 +          d2: {
   1.295 +            value: undefined,
   1.296 +            status: 'INCOMPLETE'
   1.297 +          },
   1.298 +        }
   1.299 +      }
   1.300 +    },
   1.301 +    {
   1.302 +      // Check wrapping on decrement
   1.303 +      setup:    'tsdate 2001-02-01<DOWN>',
   1.304 +      check: {
   1.305 +        input:  'tsdate 2001-01-31',
   1.306 +        hints:                    ' <d2>',
   1.307 +        markup: 'VVVVVVVVVVVVVVVVV',
   1.308 +        status: 'ERROR',
   1.309 +        message: '',
   1.310 +        args: {
   1.311 +          command: { name: 'tsdate' },
   1.312 +          d1: {
   1.313 +            value: function(d1) {
   1.314 +              assert.is(d1.getFullYear(), 2001, 'd1 year');
   1.315 +              assert.is(d1.getMonth(), 0, 'd1 month');
   1.316 +              assert.is(d1.getDate(), 31, 'd1 date');
   1.317 +              assert.is(d1.getHours(), 0, 'd1 hours');
   1.318 +              assert.is(d1.getMinutes(), 0, 'd1 minutes');
   1.319 +              assert.is(d1.getSeconds(), 0, 'd1 seconds');
   1.320 +              assert.is(d1.getMilliseconds(), 0, 'd1 millis');
   1.321 +            },
   1.322 +            arg: ' 2001-01-31',
   1.323 +            status: 'VALID',
   1.324 +            message: ''
   1.325 +          },
   1.326 +          d2: {
   1.327 +            value: undefined,
   1.328 +            status: 'INCOMPLETE'
   1.329 +          },
   1.330 +        }
   1.331 +      }
   1.332 +    },
   1.333 +    {
   1.334 +      // Check 'max' value capping on increment
   1.335 +      setup:    'tsdate 2001-02-01 "27 feb 2000"<UP>',
   1.336 +      check: {
   1.337 +        input:  'tsdate 2001-02-01 "2000-02-28"',
   1.338 +        hints:                                '',
   1.339 +        markup: 'VVVVVVVVVVVVVVVVVVVVVVVVVVVVVV',
   1.340 +        status: 'VALID',
   1.341 +        message: '',
   1.342 +        args: {
   1.343 +          command: { name: 'tsdate' },
   1.344 +          d1: {
   1.345 +            value: function(d1) {
   1.346 +              assert.is(d1.getFullYear(), 2001, 'd1 year');
   1.347 +              assert.is(d1.getMonth(), 1, 'd1 month');
   1.348 +              assert.is(d1.getDate(), 1, 'd1 date');
   1.349 +              assert.is(d1.getHours(), 0, 'd1 hours');
   1.350 +              assert.is(d1.getMinutes(), 0, 'd1 minutes');
   1.351 +              assert.is(d1.getSeconds(), 0, 'd1 seconds');
   1.352 +              assert.is(d1.getMilliseconds(), 0, 'd1 millis');
   1.353 +            },
   1.354 +            arg: ' 2001-02-01',
   1.355 +            status: 'VALID',
   1.356 +            message: ''
   1.357 +          },
   1.358 +          d2: {
   1.359 +            value: function(d2) {
   1.360 +              assert.is(d2.getFullYear(), 2000, 'd2 year');
   1.361 +              assert.is(d2.getMonth(), 1, 'd2 month');
   1.362 +              assert.is(d2.getDate(), 28, 'd2 date');
   1.363 +              assert.is(d2.getHours(), 0, 'd2 hours');
   1.364 +              assert.is(d2.getMinutes(), 0, 'd2 minutes');
   1.365 +              assert.is(d2.getSeconds(), 0, 'd2 seconds');
   1.366 +              assert.is(d2.getMilliseconds(), 0, 'd2 millis');
   1.367 +            },
   1.368 +            arg: ' "2000-02-28"',
   1.369 +            status: 'VALID',
   1.370 +            message: ''
   1.371 +          },
   1.372 +        }
   1.373 +      }
   1.374 +    }
   1.375 +  ]);
   1.376 +};

mercurial