Browse files

Merge remote-tracking branch 'origin/develop' into work

  • Loading branch information...
2 parents 3034854 + 966a2cb commit d3f75c8a0fa68ec49c97ca67fdc54a725e5d4d8a @modeswitch modeswitch committed Jan 19, 2012
Showing with 64 additions and 90 deletions.
  1. +1 −1 external/CubicVR.js
  2. +5 −5 src/base/resource.js
  3. +8 −9 src/core/load.js
  4. +9 −1 test/base/resource.js
  5. +38 −72 test/core/load.js
  6. +3 −2 test/core/resource/script.js
2 external/CubicVR.js
@@ -1 +1 @@
-Subproject commit 4e747b71f6298a701c6c8e5f1f339dba3ab88092
+Subproject commit 45035e42a670fe1836303844377805c32f4eb4af
View
10 src/base/resource.js
@@ -36,7 +36,7 @@ define( function ( require ) {
options = options || {};
- var _source = options.source || null,
+ var _url = options.url || null,
_script = options.script || null,
_parameters = options.parameters || null;
@@ -46,15 +46,15 @@ define( function ( require ) {
var _cache = options.cache || this.cache;
var _instance;
- if( _source ) {
- if( _cache && _cache.contains( _source ) ) {
+ if( _url ) {
+ if( _cache && _cache.contains( _url ) ) {
// Find the _instance in the cache and return it
- _instance = _cache.find( _source );
+ _instance = _cache.find( _url );
_onsuccess( _instance );
} else {
// Fetch the _instance from its source
var xhr = new XMLHttpRequest();
- xhr.open( 'GET', _source, true );
+ xhr.open( 'GET', _url, true );
xhr.onreadystatechange = function() {
if( 4 != xhr.readyState ) {
return;
View
17 src/core/load.js
@@ -9,10 +9,10 @@ define( function ( require ) {
var load = function resourceLoad( itemsToLoad, options ) {
var result = {};
- var failedLoads = [];
+ var errors = {};
function areLoadsPending () {
- if (Object.keys( result ).length + failedLoads.length <
+ if (Object.keys( result ).length + Object.keys( errors ).length <
itemsToLoad.length) {
return true;
}
@@ -22,21 +22,20 @@ define( function ( require ) {
function makeItemOptions( itemToLoad ) {
var itemOptions = {
- source: itemToLoad.source,
+ url: itemToLoad.url,
onsuccess: function itemOnSuccess( item ) {
- result[itemToLoad.source] = item;
+ result[itemToLoad.url] = item;
itemToLoad.onsuccess( item );
if (!areLoadsPending()) {
- options.oncomplete( result );
+ options.oncomplete( result, errors );
}
},
onfailure: function itemOnFailure( error ) {
- console.log("onfailure called");
- failedLoads.push(itemToLoad.source);
+ errors[itemToLoad.url] = error;
itemToLoad.onfailure( error );
if (!areLoadsPending()) {
- options.oncomplete( result );
+ options.oncomplete( result, errors );
}
}
};
@@ -46,7 +45,7 @@ define( function ( require ) {
if (!itemsToLoad.length) {
if ("oncomplete" in options) {
- options.oncomplete( result );
+ options.oncomplete( result, errors );
}
return result;
View
10 test/base/resource.js
@@ -32,7 +32,7 @@
expect(1);
var options = {
- source : "no-such-url-exists",
+ url : "no-such-url-exists",
onsuccess : function itemOnSuccess(item) {
ok( false, "non-existent file load shouldn't call onsuccess" );
@@ -55,6 +55,14 @@
var resource = new engine.base.Resource()(options);
});
+ // TD: test data URLs, and commutativity/normalization of params:
+ //
+ // "data:gladius/script;core.script.test?x=1&y=2"
+ // "data:gladius/script;core.script.test?y=2&x=1"
+
+ // TD: test that result not populated before oncomplete is called and
+ // result returned on async completion
+
// TD test loading of a resource when passing a constructor for the
// for processing the returned JSON:
//
View
110 test/core/load.js
@@ -25,57 +25,47 @@
});
asyncTest( 'invoke load with an empty list', function() {
- expect(3);
-
- function onprogress ( ) {
- // TD: no start here means tests will hang, so it's probably impossible
- // for the ok() below to ever fire, but just in case...
- ok( false, "progress should not be called for 100% completion");
- }
+ expect(4);
- function oncomplete ( result ) {
+ function oncomplete ( result, errors ) {
start();
ok( true, "empty load completed");
deepEqual(result, {}, "result set is empty after empty load done");
-
+ deepEqual(errors, {}, "error set is empty after empty load done");
// TD: test that cache has not been modified
}
var result = engine.core.resource.load([], {
oncomplete: oncomplete,
- onprogress: onprogress,
cache: "myEmptyCache"});
deepEqual(result, {}, "result set is empty after empty load initiated");
});
asyncTest( 'invoke load with a single uncached resource', function() {
- expect(6);
+ expect(7);
var resourcePath = "assets/test-loadfile1.json";
- function onprogress ( ) {
- ok( false, "progress should not be called for only 1 file");
- }
-
- function oncomplete ( result ) {
+ function oncomplete ( result, errors ) {
ok( true, "single uncached load completed");
ok( result.hasOwnProperty(resourcePath),
"result set has correct URL property");
deepEqual(result[resourcePath], {},
"result set contains correct data");
- equal( Object.keys(result).length, 1, "result set is right size");
+ equal( Object.keys(result).length, 1, "result set is right size" );
+ deepEqual( errors, {}, "error set is empty after successful load" );
start();
// TD: test that cache has not been modified
}
var resourceToLoad = {
type: "engine.core.resource.json",
- source: resourcePath,
+ url: resourcePath,
onsuccess: function( result ) {
deepEqual(result, {}, "empty JSON object should have been loaded");
},
@@ -86,35 +76,34 @@
var result = engine.core.resource.load([resourceToLoad], {
oncomplete: oncomplete,
- onprogress: onprogress,
cache: "myEmptyCache"});
deepEqual(result, {}, "result set is empty after single uncached load started");
});
asyncTest( 'invoke load with a single non-existent resource', function() {
- expect(4);
+ expect(6);
var resourcePath = "no-such-url-exists";
- function onprogress ( ) {
- ok( false, "progress should not be called for only 1 file");
- }
+ function oncomplete ( result, errors ) {
- function oncomplete ( result ) {
- // XXX should we have another callback or arg to signal that
- // something went wrong?
ok( true, "single non-existent load completed");
equal( Object.keys(result).length, 0, "result set is empty");
+ equal( Object.keys(errors).length, 1, "non-existent load failed" );
+
+ ok( errors.hasOwnProperty(resourcePath),
+ "result set has correct URL property");
+
start();
// TD: test that cache has been appropriately modified
}
var resourceToLoad = {
type: "engine.core.resource.json",
- source: resourcePath,
+ url: resourcePath,
onsuccess: function( result ) {
ok(false, "non-existent file should not have loaded successfully");
},
@@ -125,34 +114,36 @@
var result = engine.core.resource.load([resourceToLoad], {
oncomplete: oncomplete,
- onprogress: onprogress,
cache: "myEmptyCache"});
deepEqual(result, {}, "result set is empty after non-existent load started");
});
+ function makeResourceInfo(path) {
+ var r = {
+ type: "engine.core.resource.json",
+ url: path,
+ onsuccess: function(result) {
+ deepEqual(result, {}, "empty JSON object should have been loaded");
+ },
+ onfailure: function(error) {
+ ok(false, "failed to load minimal JSON file: " + error);
+ }
+ };
+
+ return r;
+ }
+
+
asyncTest( 'load three uncached resource', function() {
- expect(12);
+ expect(13);
var resourcePath = "assets/test-loadfile1.json";
var resourcePath2 = "assets/test-loadfile2.json";
var resourcePath3 = "assets/test-loadfile3.json";
- function onprogress ( ) {
- // TD (dmose): I'm not convinced that this API is very useful. The
- // only simple granularity we can offer is calling back after each
- // file loads, and that progress updating could just be done on the
- // onsuccess/onfailure handler for each file. I'd like to talk to
- // bzbarsky, biesi, or someone else with experience with the gecko
- // webprogress stuff. Or, even more ideally, a UX person. Would
- // also be interesting to chat with experienced game devs here.
-
- // we need to either make a passing a test or kill this API
- // before landing on the develop branch
- }
-
- function oncomplete ( result ) {
+ function oncomplete ( result, errors ) {
ok( true, "three uncached loads completed");
equal( Object.keys(result).length, 3, "result set is right size" );
@@ -164,25 +155,12 @@
"result set contains correct data for " + resources[i] );
}
+ deepEqual(errors, {}, "no errors were returned");
+
start();
// TD: test that cache has been appropriately modified
}
- function makeResourceInfo(path) {
- var r = {
- type: "engine.core.resource.json",
- source: path,
- onsuccess: function( result ) {
- deepEqual(result, {}, "empty JSON object should have been loaded");
- },
- onfailure: function( error ) {
- ok(false, "failed to load minimal JSON file: " + error);
- }
- };
-
- return r;
- }
-
var resourcesToLoad = [
makeResourceInfo(resourcePath),
makeResourceInfo(resourcePath2),
@@ -191,31 +169,19 @@
var result = engine.core.resource.load(resourcesToLoad, {
oncomplete: oncomplete,
- onprogress: onprogress,
cache: "myEmptyCache"});
deepEqual(result, {}, "result set is empty after single uncached load started");
});
- // TD: test group load with some failing & some succeeding loads
-
- // TD: test constructor type handling
-
// TD: test what happens when itemsToLoad contains dups &
// non-canonicalized dups
// TD: test that passing in various edge cases and null for options
// behaves appropriately
- // TD: test what happens when itemsToLoad is not an array. duck-type as
- // single object to load?
+ // TD: test that when itemsToLoad is not an array an exception is raised
// TD: ensure that we test that result is not populated before one of
- // onprogress or oncomplete is called; refactor regular resources to
- // behave this way?
-
- // TD: progress should not be called at 100% complete; get rid of onprogress
- // ok()
-
-
+ // oncomplete is called
}());
View
5 test/core/resource/script.js
@@ -1,7 +1,8 @@
/*jshint white: false, strict: false, plusplus: false, onevar: false,
nomen: false */
/*global gladius: false, document: false, window: false, module: false, start,
- test: false, expect: false, ok: false, notEqual: false, stop, QUnit: false */
+ test: false, expect: false, ok: false, notEqual: false, stop, QUnit: false,
+ asyncTest: false, same: false */
(function() {
@@ -26,7 +27,7 @@
expect( 1 );
engine.core.resource.Script({
- source: 'assets/test-script.json',
+ url: 'assets/test-script.json',
onsuccess: function( instance ) {
same(
3,

0 comments on commit d3f75c8

Please sign in to comment.