browser/devtools/commandline/test/browser_gcli_resource.js

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

     1 /*
     2  * Copyright 2012, Mozilla Foundation and contributors
     3  *
     4  * Licensed under the Apache License, Version 2.0 (the "License");
     5  * you may not use this file except in compliance with the License.
     6  * You may obtain a copy of the License at
     7  *
     8  * http://www.apache.org/licenses/LICENSE-2.0
     9  *
    10  * Unless required by applicable law or agreed to in writing, software
    11  * distributed under the License is distributed on an "AS IS" BASIS,
    12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  * See the License for the specific language governing permissions and
    14  * limitations under the License.
    15  */
    17 'use strict';
    18 // <INJECTED SOURCE:START>
    20 // THIS FILE IS GENERATED FROM SOURCE IN THE GCLI PROJECT
    21 // DO NOT EDIT IT DIRECTLY
    23 var exports = {};
    25 var TEST_URI = "data:text/html;charset=utf-8,<p id='gcli-input'>gcli-testResource.js</p>";
    27 function test() {
    28   return Task.spawn(function() {
    29     let options = yield helpers.openTab(TEST_URI);
    30     yield helpers.openToolbar(options);
    31     gcli.addItems(mockCommands.items);
    33     yield helpers.runTests(options, exports);
    35     gcli.removeItems(mockCommands.items);
    36     yield helpers.closeToolbar(options);
    37     yield helpers.closeTab(options);
    38   }).then(finish, helpers.handleError);
    39 }
    41 // <INJECTED SOURCE:END>
    43 // var assert = require('../testharness/assert');
    45 var promise = require('gcli/util/promise');
    46 var util = require('gcli/util/util');
    47 var resource = require('gcli/types/resource');
    48 var Status = require('gcli/types/types').Status;
    51 var tempDocument;
    53 exports.setup = function(options) {
    54   tempDocument = resource.getDocument();
    55   if (options.window) {
    56     resource.setDocument(options.window.document);
    57   }
    58 };
    60 exports.shutdown = function(options) {
    61   resource.setDocument(tempDocument);
    62   tempDocument = undefined;
    63 };
    65 exports.testAllPredictions1 = function(options) {
    66   if (options.isFirefox || options.isNoDom) {
    67     assert.log('Skipping checks due to firefox document.stylsheets support.');
    68     return;
    69   }
    71   var resource = options.requisition.types.createType('resource');
    72   return resource.getLookup().then(function(opts) {
    73     assert.ok(opts.length > 1, 'have all resources');
    75     return util.promiseEach(opts, function(prediction) {
    76       return checkPrediction(resource, prediction);
    77     });
    78   });
    79 };
    81 exports.testScriptPredictions = function(options) {
    82   if (options.isFirefox || options.isNoDom) {
    83     assert.log('Skipping checks due to firefox document.stylsheets support.');
    84     return;
    85   }
    87   var types = options.requisition.types;
    88   var resource = types.createType({ name: 'resource', include: 'text/javascript' });
    89   return resource.getLookup().then(function(opts) {
    90     assert.ok(opts.length > 1, 'have js resources');
    92     return util.promiseEach(opts, function(prediction) {
    93       return checkPrediction(resource, prediction);
    94     });
    95   });
    96 };
    98 exports.testStylePredictions = function(options) {
    99   if (options.isFirefox || options.isNoDom) {
   100     assert.log('Skipping checks due to firefox document.stylsheets support.');
   101     return;
   102   }
   104   var types = options.requisition.types;
   105   var resource = types.createType({ name: 'resource', include: 'text/css' });
   106   return resource.getLookup().then(function(opts) {
   107     assert.ok(opts.length >= 1, 'have css resources');
   109     return util.promiseEach(opts, function(prediction) {
   110       return checkPrediction(resource, prediction);
   111     });
   112   });
   113 };
   115 exports.testAllPredictions2 = function(options) {
   116   if (options.isNoDom) {
   117     assert.log('Skipping checks due to nodom document.stylsheets support.');
   118     return;
   119   }
   120   var types = options.requisition.types;
   122   var scriptRes = types.createType({ name: 'resource', include: 'text/javascript' });
   123   return scriptRes.getLookup().then(function(scriptOptions) {
   124     var styleRes = types.createType({ name: 'resource', include: 'text/css' });
   125     return styleRes.getLookup().then(function(styleOptions) {
   126       var allRes = types.createType({ name: 'resource' });
   127       return allRes.getLookup().then(function(allOptions) {
   128         assert.is(scriptOptions.length + styleOptions.length,
   129                   allOptions.length,
   130                   'split');
   131       });
   132     });
   133   });
   134 };
   136 exports.testAllPredictions3 = function(options) {
   137   if (options.isNoDom) {
   138     assert.log('Skipping checks due to nodom document.stylsheets support.');
   139     return;
   140   }
   142   var types = options.requisition.types;
   143   var res1 = types.createType({ name: 'resource' });
   144   return res1.getLookup().then(function(options1) {
   145     var res2 = types.createType('resource');
   146     return res2.getLookup().then(function(options2) {
   147       assert.is(options1.length, options2.length, 'type spec');
   148     });
   149   });
   150 };
   152 function checkPrediction(res, prediction) {
   153   var name = prediction.name;
   154   var value = prediction.value;
   156   // resources don't need context so cheat and pass in null
   157   var context = null;
   158   return res.parseString(name, context).then(function(conversion) {
   159     assert.is(conversion.getStatus(), Status.VALID, 'status VALID for ' + name);
   160     assert.is(conversion.value, value, 'value for ' + name);
   162     assert.is(typeof value.loadContents, 'function', 'resource for ' + name);
   163     assert.is(typeof value.element, 'object', 'resource for ' + name);
   165     return promise.resolve(res.stringify(value, context)).then(function(strung) {
   166       assert.is(strung, name, 'stringify for ' + name);
   167     });
   168   });
   169 }

mercurial