browser/devtools/commandline/test/browser_gcli_resource.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_resource.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,169 @@
     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-testResource.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 +
    1.48 +var promise = require('gcli/util/promise');
    1.49 +var util = require('gcli/util/util');
    1.50 +var resource = require('gcli/types/resource');
    1.51 +var Status = require('gcli/types/types').Status;
    1.52 +
    1.53 +
    1.54 +var tempDocument;
    1.55 +
    1.56 +exports.setup = function(options) {
    1.57 +  tempDocument = resource.getDocument();
    1.58 +  if (options.window) {
    1.59 +    resource.setDocument(options.window.document);
    1.60 +  }
    1.61 +};
    1.62 +
    1.63 +exports.shutdown = function(options) {
    1.64 +  resource.setDocument(tempDocument);
    1.65 +  tempDocument = undefined;
    1.66 +};
    1.67 +
    1.68 +exports.testAllPredictions1 = function(options) {
    1.69 +  if (options.isFirefox || options.isNoDom) {
    1.70 +    assert.log('Skipping checks due to firefox document.stylsheets support.');
    1.71 +    return;
    1.72 +  }
    1.73 +
    1.74 +  var resource = options.requisition.types.createType('resource');
    1.75 +  return resource.getLookup().then(function(opts) {
    1.76 +    assert.ok(opts.length > 1, 'have all resources');
    1.77 +
    1.78 +    return util.promiseEach(opts, function(prediction) {
    1.79 +      return checkPrediction(resource, prediction);
    1.80 +    });
    1.81 +  });
    1.82 +};
    1.83 +
    1.84 +exports.testScriptPredictions = function(options) {
    1.85 +  if (options.isFirefox || options.isNoDom) {
    1.86 +    assert.log('Skipping checks due to firefox document.stylsheets support.');
    1.87 +    return;
    1.88 +  }
    1.89 +
    1.90 +  var types = options.requisition.types;
    1.91 +  var resource = types.createType({ name: 'resource', include: 'text/javascript' });
    1.92 +  return resource.getLookup().then(function(opts) {
    1.93 +    assert.ok(opts.length > 1, 'have js resources');
    1.94 +
    1.95 +    return util.promiseEach(opts, function(prediction) {
    1.96 +      return checkPrediction(resource, prediction);
    1.97 +    });
    1.98 +  });
    1.99 +};
   1.100 +
   1.101 +exports.testStylePredictions = function(options) {
   1.102 +  if (options.isFirefox || options.isNoDom) {
   1.103 +    assert.log('Skipping checks due to firefox document.stylsheets support.');
   1.104 +    return;
   1.105 +  }
   1.106 +
   1.107 +  var types = options.requisition.types;
   1.108 +  var resource = types.createType({ name: 'resource', include: 'text/css' });
   1.109 +  return resource.getLookup().then(function(opts) {
   1.110 +    assert.ok(opts.length >= 1, 'have css resources');
   1.111 +
   1.112 +    return util.promiseEach(opts, function(prediction) {
   1.113 +      return checkPrediction(resource, prediction);
   1.114 +    });
   1.115 +  });
   1.116 +};
   1.117 +
   1.118 +exports.testAllPredictions2 = function(options) {
   1.119 +  if (options.isNoDom) {
   1.120 +    assert.log('Skipping checks due to nodom document.stylsheets support.');
   1.121 +    return;
   1.122 +  }
   1.123 +  var types = options.requisition.types;
   1.124 +
   1.125 +  var scriptRes = types.createType({ name: 'resource', include: 'text/javascript' });
   1.126 +  return scriptRes.getLookup().then(function(scriptOptions) {
   1.127 +    var styleRes = types.createType({ name: 'resource', include: 'text/css' });
   1.128 +    return styleRes.getLookup().then(function(styleOptions) {
   1.129 +      var allRes = types.createType({ name: 'resource' });
   1.130 +      return allRes.getLookup().then(function(allOptions) {
   1.131 +        assert.is(scriptOptions.length + styleOptions.length,
   1.132 +                  allOptions.length,
   1.133 +                  'split');
   1.134 +      });
   1.135 +    });
   1.136 +  });
   1.137 +};
   1.138 +
   1.139 +exports.testAllPredictions3 = function(options) {
   1.140 +  if (options.isNoDom) {
   1.141 +    assert.log('Skipping checks due to nodom document.stylsheets support.');
   1.142 +    return;
   1.143 +  }
   1.144 +
   1.145 +  var types = options.requisition.types;
   1.146 +  var res1 = types.createType({ name: 'resource' });
   1.147 +  return res1.getLookup().then(function(options1) {
   1.148 +    var res2 = types.createType('resource');
   1.149 +    return res2.getLookup().then(function(options2) {
   1.150 +      assert.is(options1.length, options2.length, 'type spec');
   1.151 +    });
   1.152 +  });
   1.153 +};
   1.154 +
   1.155 +function checkPrediction(res, prediction) {
   1.156 +  var name = prediction.name;
   1.157 +  var value = prediction.value;
   1.158 +
   1.159 +  // resources don't need context so cheat and pass in null
   1.160 +  var context = null;
   1.161 +  return res.parseString(name, context).then(function(conversion) {
   1.162 +    assert.is(conversion.getStatus(), Status.VALID, 'status VALID for ' + name);
   1.163 +    assert.is(conversion.value, value, 'value for ' + name);
   1.164 +
   1.165 +    assert.is(typeof value.loadContents, 'function', 'resource for ' + name);
   1.166 +    assert.is(typeof value.element, 'object', 'resource for ' + name);
   1.167 +
   1.168 +    return promise.resolve(res.stringify(value, context)).then(function(strung) {
   1.169 +      assert.is(strung, name, 'stringify for ' + name);
   1.170 +    });
   1.171 +  });
   1.172 +}

mercurial