michael@0: /* michael@0: * Copyright 2012, Mozilla Foundation and contributors michael@0: * michael@0: * Licensed under the Apache License, Version 2.0 (the "License"); michael@0: * you may not use this file except in compliance with the License. michael@0: * You may obtain a copy of the License at michael@0: * michael@0: * http://www.apache.org/licenses/LICENSE-2.0 michael@0: * michael@0: * Unless required by applicable law or agreed to in writing, software michael@0: * distributed under the License is distributed on an "AS IS" BASIS, michael@0: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. michael@0: * See the License for the specific language governing permissions and michael@0: * limitations under the License. michael@0: */ michael@0: michael@0: 'use strict'; michael@0: // michael@0: michael@0: // THIS FILE IS GENERATED FROM SOURCE IN THE GCLI PROJECT michael@0: // DO NOT EDIT IT DIRECTLY michael@0: michael@0: var exports = {}; michael@0: michael@0: var TEST_URI = "data:text/html;charset=utf-8,

gcli-testResource.js

"; michael@0: michael@0: function test() { michael@0: return Task.spawn(function() { michael@0: let options = yield helpers.openTab(TEST_URI); michael@0: yield helpers.openToolbar(options); michael@0: gcli.addItems(mockCommands.items); michael@0: michael@0: yield helpers.runTests(options, exports); michael@0: michael@0: gcli.removeItems(mockCommands.items); michael@0: yield helpers.closeToolbar(options); michael@0: yield helpers.closeTab(options); michael@0: }).then(finish, helpers.handleError); michael@0: } michael@0: michael@0: // michael@0: michael@0: // var assert = require('../testharness/assert'); michael@0: michael@0: var promise = require('gcli/util/promise'); michael@0: var util = require('gcli/util/util'); michael@0: var resource = require('gcli/types/resource'); michael@0: var Status = require('gcli/types/types').Status; michael@0: michael@0: michael@0: var tempDocument; michael@0: michael@0: exports.setup = function(options) { michael@0: tempDocument = resource.getDocument(); michael@0: if (options.window) { michael@0: resource.setDocument(options.window.document); michael@0: } michael@0: }; michael@0: michael@0: exports.shutdown = function(options) { michael@0: resource.setDocument(tempDocument); michael@0: tempDocument = undefined; michael@0: }; michael@0: michael@0: exports.testAllPredictions1 = function(options) { michael@0: if (options.isFirefox || options.isNoDom) { michael@0: assert.log('Skipping checks due to firefox document.stylsheets support.'); michael@0: return; michael@0: } michael@0: michael@0: var resource = options.requisition.types.createType('resource'); michael@0: return resource.getLookup().then(function(opts) { michael@0: assert.ok(opts.length > 1, 'have all resources'); michael@0: michael@0: return util.promiseEach(opts, function(prediction) { michael@0: return checkPrediction(resource, prediction); michael@0: }); michael@0: }); michael@0: }; michael@0: michael@0: exports.testScriptPredictions = function(options) { michael@0: if (options.isFirefox || options.isNoDom) { michael@0: assert.log('Skipping checks due to firefox document.stylsheets support.'); michael@0: return; michael@0: } michael@0: michael@0: var types = options.requisition.types; michael@0: var resource = types.createType({ name: 'resource', include: 'text/javascript' }); michael@0: return resource.getLookup().then(function(opts) { michael@0: assert.ok(opts.length > 1, 'have js resources'); michael@0: michael@0: return util.promiseEach(opts, function(prediction) { michael@0: return checkPrediction(resource, prediction); michael@0: }); michael@0: }); michael@0: }; michael@0: michael@0: exports.testStylePredictions = function(options) { michael@0: if (options.isFirefox || options.isNoDom) { michael@0: assert.log('Skipping checks due to firefox document.stylsheets support.'); michael@0: return; michael@0: } michael@0: michael@0: var types = options.requisition.types; michael@0: var resource = types.createType({ name: 'resource', include: 'text/css' }); michael@0: return resource.getLookup().then(function(opts) { michael@0: assert.ok(opts.length >= 1, 'have css resources'); michael@0: michael@0: return util.promiseEach(opts, function(prediction) { michael@0: return checkPrediction(resource, prediction); michael@0: }); michael@0: }); michael@0: }; michael@0: michael@0: exports.testAllPredictions2 = function(options) { michael@0: if (options.isNoDom) { michael@0: assert.log('Skipping checks due to nodom document.stylsheets support.'); michael@0: return; michael@0: } michael@0: var types = options.requisition.types; michael@0: michael@0: var scriptRes = types.createType({ name: 'resource', include: 'text/javascript' }); michael@0: return scriptRes.getLookup().then(function(scriptOptions) { michael@0: var styleRes = types.createType({ name: 'resource', include: 'text/css' }); michael@0: return styleRes.getLookup().then(function(styleOptions) { michael@0: var allRes = types.createType({ name: 'resource' }); michael@0: return allRes.getLookup().then(function(allOptions) { michael@0: assert.is(scriptOptions.length + styleOptions.length, michael@0: allOptions.length, michael@0: 'split'); michael@0: }); michael@0: }); michael@0: }); michael@0: }; michael@0: michael@0: exports.testAllPredictions3 = function(options) { michael@0: if (options.isNoDom) { michael@0: assert.log('Skipping checks due to nodom document.stylsheets support.'); michael@0: return; michael@0: } michael@0: michael@0: var types = options.requisition.types; michael@0: var res1 = types.createType({ name: 'resource' }); michael@0: return res1.getLookup().then(function(options1) { michael@0: var res2 = types.createType('resource'); michael@0: return res2.getLookup().then(function(options2) { michael@0: assert.is(options1.length, options2.length, 'type spec'); michael@0: }); michael@0: }); michael@0: }; michael@0: michael@0: function checkPrediction(res, prediction) { michael@0: var name = prediction.name; michael@0: var value = prediction.value; michael@0: michael@0: // resources don't need context so cheat and pass in null michael@0: var context = null; michael@0: return res.parseString(name, context).then(function(conversion) { michael@0: assert.is(conversion.getStatus(), Status.VALID, 'status VALID for ' + name); michael@0: assert.is(conversion.value, value, 'value for ' + name); michael@0: michael@0: assert.is(typeof value.loadContents, 'function', 'resource for ' + name); michael@0: assert.is(typeof value.element, 'object', 'resource for ' + name); michael@0: michael@0: return promise.resolve(res.stringify(value, context)).then(function(strung) { michael@0: assert.is(strung, name, 'stringify for ' + name); michael@0: }); michael@0: }); michael@0: }