"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "vendor/backbone/test/router.js" between
lodash-3.0.0.tar.gz and lodash-4.0.0.tar.gz

About: lodash is a modern JavaScript utility library delivering modularity, performance, & extras.

router.js  (lodash-3.0.0):router.js  (lodash-4.0.0)
skipping to change at line 43 skipping to change at line 43
// window.location.pathname does. // window.location.pathname does.
if (!/^\//.test(this.pathname)) this.pathname = '/' + this.pathname; if (!/^\//.test(this.pathname)) this.pathname = '/' + this.pathname;
}, },
toString: function() { toString: function() {
return this.href; return this.href;
} }
}); });
module("Backbone.Router", { QUnit.module('Backbone.Router', {
setup: function() { setup: function() {
location = new Location('http://example.com'); location = new Location('http://example.com');
Backbone.history = _.extend(new Backbone.History, {location: location}); Backbone.history = _.extend(new Backbone.History, {location: location});
router = new Router({testing: 101}); router = new Router({testing: 101});
Backbone.history.interval = 9; Backbone.history.interval = 9;
Backbone.history.start({pushState: false}); Backbone.history.start({pushState: false});
lastRoute = null; lastRoute = null;
lastArgs = []; lastArgs = [];
Backbone.history.on('route', onRoute); Backbone.history.on('route', onRoute);
skipping to change at line 70 skipping to change at line 70
}); });
var ExternalObject = { var ExternalObject = {
value: 'unset', value: 'unset',
routingFunction: function(value) { routingFunction: function(value) {
this.value = value; this.value = value;
} }
}; };
_.bindAll(ExternalObject, 'routingFunction'); ExternalObject.routingFunction = _.bind(ExternalObject.routingFunction, Extern alObject);
var Router = Backbone.Router.extend({ var Router = Backbone.Router.extend({
count: 0, count: 0,
routes: { routes: {
"noCallback": "noCallback", 'noCallback': 'noCallback',
"counter": "counter", 'counter': 'counter',
"search/:query": "search", 'search/:query': 'search',
"search/:query/p:page": "search", 'search/:query/p:page': 'search',
"charñ": "charUTF", 'charñ': 'charUTF',
"char%C3%B1": "charEscaped", 'char%C3%B1': 'charEscaped',
"contacts": "contacts", 'contacts': 'contacts',
"contacts/new": "newContact", 'contacts/new': 'newContact',
"contacts/:id": "loadContact", 'contacts/:id': 'loadContact',
"route-event/:arg": "routeEvent", 'route-event/:arg': 'routeEvent',
"optional(/:item)": "optionalItem", 'optional(/:item)': 'optionalItem',
"named/optional/(y:z)": "namedOptional", 'named/optional/(y:z)': 'namedOptional',
"splat/*args/end": "splat", 'splat/*args/end': 'splat',
":repo/compare/*from...*to": "github", ':repo/compare/*from...*to': 'github',
"decode/:named/*splat": "decode", 'decode/:named/*splat': 'decode',
"*first/complex-*part/*rest": "complex", '*first/complex-*part/*rest': 'complex',
"query/:entity": "query", 'query/:entity': 'query',
"function/:value": ExternalObject.routingFunction, 'function/:value': ExternalObject.routingFunction,
"*anything": "anything" '*anything': 'anything'
}, },
initialize : function(options) { initialize: function(options) {
this.testing = options.testing; this.testing = options.testing;
this.route('implicit', 'implicit'); this.route('implicit', 'implicit');
}, },
counter: function() { counter: function() {
this.count++; this.count++;
}, },
implicit: function() { implicit: function() {
this.count++; this.count++;
skipping to change at line 179 skipping to change at line 179
decode: function(named, path) { decode: function(named, path) {
this.named = named; this.named = named;
this.path = path; this.path = path;
}, },
routeEvent: function(arg) { routeEvent: function(arg) {
} }
}); });
test("initialize", 1, function() { QUnit.test('initialize', function(assert) {
equal(router.testing, 101); assert.expect(1);
assert.equal(router.testing, 101);
}); });
test("routes (simple)", 4, function() { QUnit.test('routes (simple)', function(assert) {
assert.expect(4);
location.replace('http://example.com#search/news'); location.replace('http://example.com#search/news');
Backbone.history.checkUrl(); Backbone.history.checkUrl();
equal(router.query, 'news'); assert.equal(router.query, 'news');
equal(router.page, void 0); assert.equal(router.page, void 0);
equal(lastRoute, 'search'); assert.equal(lastRoute, 'search');
equal(lastArgs[0], 'news'); assert.equal(lastArgs[0], 'news');
}); });
test("routes (simple, but unicode)", 4, function() { QUnit.test('routes (simple, but unicode)', function(assert) {
assert.expect(4);
location.replace('http://example.com#search/тест'); location.replace('http://example.com#search/тест');
Backbone.history.checkUrl(); Backbone.history.checkUrl();
equal(router.query, "тест"); assert.equal(router.query, 'тест');
equal(router.page, void 0); assert.equal(router.page, void 0);
equal(lastRoute, 'search'); assert.equal(lastRoute, 'search');
equal(lastArgs[0], "тест"); assert.equal(lastArgs[0], 'тест');
}); });
test("routes (two part)", 2, function() { QUnit.test('routes (two part)', function(assert) {
assert.expect(2);
location.replace('http://example.com#search/nyc/p10'); location.replace('http://example.com#search/nyc/p10');
Backbone.history.checkUrl(); Backbone.history.checkUrl();
equal(router.query, 'nyc'); assert.equal(router.query, 'nyc');
equal(router.page, '10'); assert.equal(router.page, '10');
}); });
test("routes via navigate", 2, function() { QUnit.test('routes via navigate', function(assert) {
assert.expect(2);
Backbone.history.navigate('search/manhattan/p20', {trigger: true}); Backbone.history.navigate('search/manhattan/p20', {trigger: true});
equal(router.query, 'manhattan'); assert.equal(router.query, 'manhattan');
equal(router.page, '20'); assert.equal(router.page, '20');
}); });
test("routes via navigate with params", 1, function() { QUnit.test('routes via navigate with params', function(assert) {
assert.expect(1);
Backbone.history.navigate('query/test?a=b', {trigger: true}); Backbone.history.navigate('query/test?a=b', {trigger: true});
equal(router.queryArgs, 'a=b'); assert.equal(router.queryArgs, 'a=b');
}); });
test("routes via navigate for backwards-compatibility", 2, function() { QUnit.test('routes via navigate for backwards-compatibility', function(assert)
{
assert.expect(2);
Backbone.history.navigate('search/manhattan/p20', true); Backbone.history.navigate('search/manhattan/p20', true);
equal(router.query, 'manhattan'); assert.equal(router.query, 'manhattan');
equal(router.page, '20'); assert.equal(router.page, '20');
}); });
test("reports matched route via nagivate", 1, function() { QUnit.test('reports matched route via nagivate', function(assert) {
ok(Backbone.history.navigate('search/manhattan/p20', true)); assert.expect(1);
assert.ok(Backbone.history.navigate('search/manhattan/p20', true));
}); });
test("route precedence via navigate", 6, function(){ QUnit.test('route precedence via navigate', function(assert){
assert.expect(6);
// check both 0.9.x and backwards-compatibility options // check both 0.9.x and backwards-compatibility options
_.each([ { trigger: true }, true ], function( options ){ _.each([{trigger: true}, true], function( options ){
Backbone.history.navigate('contacts', options); Backbone.history.navigate('contacts', options);
equal(router.contact, 'index'); assert.equal(router.contact, 'index');
Backbone.history.navigate('contacts/new', options); Backbone.history.navigate('contacts/new', options);
equal(router.contact, 'new'); assert.equal(router.contact, 'new');
Backbone.history.navigate('contacts/foo', options); Backbone.history.navigate('contacts/foo', options);
equal(router.contact, 'load'); assert.equal(router.contact, 'load');
}); });
}); });
test("loadUrl is not called for identical routes.", 0, function() { QUnit.test('loadUrl is not called for identical routes.', function(assert) {
Backbone.history.loadUrl = function(){ ok(false); }; assert.expect(0);
Backbone.history.loadUrl = function(){ assert.ok(false); };
location.replace('http://example.com#route'); location.replace('http://example.com#route');
Backbone.history.navigate('route'); Backbone.history.navigate('route');
Backbone.history.navigate('/route'); Backbone.history.navigate('/route');
Backbone.history.navigate('/route'); Backbone.history.navigate('/route');
}); });
test("use implicit callback if none provided", 1, function() { QUnit.test('use implicit callback if none provided', function(assert) {
assert.expect(1);
router.count = 0; router.count = 0;
router.navigate('implicit', {trigger: true}); router.navigate('implicit', {trigger: true});
equal(router.count, 1); assert.equal(router.count, 1);
}); });
test("routes via navigate with {replace: true}", 1, function() { QUnit.test('routes via navigate with {replace: true}', function(assert) {
assert.expect(1);
location.replace('http://example.com#start_here'); location.replace('http://example.com#start_here');
Backbone.history.checkUrl(); Backbone.history.checkUrl();
location.replace = function(href) { location.replace = function(href) {
strictEqual(href, new Location('http://example.com#end_here').href); assert.strictEqual(href, new Location('http://example.com#end_here').href) ;
}; };
Backbone.history.navigate('end_here', {replace: true}); Backbone.history.navigate('end_here', {replace: true});
}); });
test("routes (splats)", 1, function() { QUnit.test('routes (splats)', function(assert) {
assert.expect(1);
location.replace('http://example.com#splat/long-list/of/splatted_99args/end' ); location.replace('http://example.com#splat/long-list/of/splatted_99args/end' );
Backbone.history.checkUrl(); Backbone.history.checkUrl();
equal(router.args, 'long-list/of/splatted_99args'); assert.equal(router.args, 'long-list/of/splatted_99args');
}); });
test("routes (github)", 3, function() { QUnit.test('routes (github)', function(assert) {
assert.expect(3);
location.replace('http://example.com#backbone/compare/1.0...braddunbar:with/ slash'); location.replace('http://example.com#backbone/compare/1.0...braddunbar:with/ slash');
Backbone.history.checkUrl(); Backbone.history.checkUrl();
equal(router.repo, 'backbone'); assert.equal(router.repo, 'backbone');
equal(router.from, '1.0'); assert.equal(router.from, '1.0');
equal(router.to, 'braddunbar:with/slash'); assert.equal(router.to, 'braddunbar:with/slash');
}); });
test("routes (optional)", 2, function() { QUnit.test('routes (optional)', function(assert) {
assert.expect(2);
location.replace('http://example.com#optional'); location.replace('http://example.com#optional');
Backbone.history.checkUrl(); Backbone.history.checkUrl();
ok(!router.arg); assert.ok(!router.arg);
location.replace('http://example.com#optional/thing'); location.replace('http://example.com#optional/thing');
Backbone.history.checkUrl(); Backbone.history.checkUrl();
equal(router.arg, 'thing'); assert.equal(router.arg, 'thing');
}); });
test("routes (complex)", 3, function() { QUnit.test('routes (complex)', function(assert) {
assert.expect(3);
location.replace('http://example.com#one/two/three/complex-part/four/five/si x/seven'); location.replace('http://example.com#one/two/three/complex-part/four/five/si x/seven');
Backbone.history.checkUrl(); Backbone.history.checkUrl();
equal(router.first, 'one/two/three'); assert.equal(router.first, 'one/two/three');
equal(router.part, 'part'); assert.equal(router.part, 'part');
equal(router.rest, 'four/five/six/seven'); assert.equal(router.rest, 'four/five/six/seven');
}); });
test("routes (query)", 5, function() { QUnit.test('routes (query)', function(assert) {
assert.expect(5);
location.replace('http://example.com#query/mandel?a=b&c=d'); location.replace('http://example.com#query/mandel?a=b&c=d');
Backbone.history.checkUrl(); Backbone.history.checkUrl();
equal(router.entity, 'mandel'); assert.equal(router.entity, 'mandel');
equal(router.queryArgs, 'a=b&c=d'); assert.equal(router.queryArgs, 'a=b&c=d');
equal(lastRoute, 'query'); assert.equal(lastRoute, 'query');
equal(lastArgs[0], 'mandel'); assert.equal(lastArgs[0], 'mandel');
equal(lastArgs[1], 'a=b&c=d'); assert.equal(lastArgs[1], 'a=b&c=d');
}); });
test("routes (anything)", 1, function() { QUnit.test('routes (anything)', function(assert) {
assert.expect(1);
location.replace('http://example.com#doesnt-match-a-route'); location.replace('http://example.com#doesnt-match-a-route');
Backbone.history.checkUrl(); Backbone.history.checkUrl();
equal(router.anything, 'doesnt-match-a-route'); assert.equal(router.anything, 'doesnt-match-a-route');
}); });
test("routes (function)", 3, function() { QUnit.test('routes (function)', function(assert) {
assert.expect(3);
router.on('route', function(name) { router.on('route', function(name) {
ok(name === ''); assert.ok(name === '');
}); });
equal(ExternalObject.value, 'unset'); assert.equal(ExternalObject.value, 'unset');
location.replace('http://example.com#function/set'); location.replace('http://example.com#function/set');
Backbone.history.checkUrl(); Backbone.history.checkUrl();
equal(ExternalObject.value, 'set'); assert.equal(ExternalObject.value, 'set');
}); });
test("Decode named parameters, not splats.", 2, function() { QUnit.test('Decode named parameters, not splats.', function(assert) {
assert.expect(2);
location.replace('http://example.com#decode/a%2Fb/c%2Fd/e'); location.replace('http://example.com#decode/a%2Fb/c%2Fd/e');
Backbone.history.checkUrl(); Backbone.history.checkUrl();
strictEqual(router.named, 'a/b'); assert.strictEqual(router.named, 'a/b');
strictEqual(router.path, 'c/d/e'); assert.strictEqual(router.path, 'c/d/e');
}); });
test("fires event when router doesn't have callback on it", 1, function() { QUnit.test("fires event when router doesn't have callback on it", function(ass
router.on("route:noCallback", function(){ ok(true); }); ert) {
assert.expect(1);
router.on('route:noCallback', function(){ assert.ok(true); });
location.replace('http://example.com#noCallback'); location.replace('http://example.com#noCallback');
Backbone.history.checkUrl(); Backbone.history.checkUrl();
}); });
test("#933, #908 - leading slash", 2, function() { QUnit.test('No events are triggered if #execute returns false.', function(asse
rt) {
assert.expect(1);
var Router = Backbone.Router.extend({
routes: {
foo: function() {
assert.ok(true);
}
},
execute: function(callback, args) {
callback.apply(this, args);
return false;
}
});
var router = new Router;
router.on('route route:foo', function() {
assert.ok(false);
});
Backbone.history.on('route', function() {
assert.ok(false);
});
location.replace('http://example.com#foo');
Backbone.history.checkUrl();
});
QUnit.test('#933, #908 - leading slash', function(assert) {
assert.expect(2);
location.replace('http://example.com/root/foo'); location.replace('http://example.com/root/foo');
Backbone.history.stop(); Backbone.history.stop();
Backbone.history = _.extend(new Backbone.History, {location: location}); Backbone.history = _.extend(new Backbone.History, {location: location});
Backbone.history.start({root: '/root', hashChange: false, silent: true}); Backbone.history.start({root: '/root', hashChange: false, silent: true});
strictEqual(Backbone.history.getFragment(), 'foo'); assert.strictEqual(Backbone.history.getFragment(), 'foo');
Backbone.history.stop(); Backbone.history.stop();
Backbone.history = _.extend(new Backbone.History, {location: location}); Backbone.history = _.extend(new Backbone.History, {location: location});
Backbone.history.start({root: '/root/', hashChange: false, silent: true}); Backbone.history.start({root: '/root/', hashChange: false, silent: true});
strictEqual(Backbone.history.getFragment(), 'foo'); assert.strictEqual(Backbone.history.getFragment(), 'foo');
});
test("#1003 - History is started before navigate is called", 1, function() {
Backbone.history.stop();
Backbone.history.navigate = function(){ ok(Backbone.History.started); };
Backbone.history.start();
// If this is not an old IE navigate will not be called.
if (!Backbone.history.iframe) ok(true);
}); });
test("#967 - Route callback gets passed encoded values.", 3, function() { QUnit.test('#967 - Route callback gets passed encoded values.', function(asser
t) {
assert.expect(3);
var route = 'has%2Fslash/complex-has%23hash/has%20space'; var route = 'has%2Fslash/complex-has%23hash/has%20space';
Backbone.history.navigate(route, {trigger: true}); Backbone.history.navigate(route, {trigger: true});
strictEqual(router.first, 'has/slash'); assert.strictEqual(router.first, 'has/slash');
strictEqual(router.part, 'has#hash'); assert.strictEqual(router.part, 'has#hash');
strictEqual(router.rest, 'has space'); assert.strictEqual(router.rest, 'has space');
}); });
test("correctly handles URLs with % (#868)", 3, function() { QUnit.test('correctly handles URLs with % (#868)', function(assert) {
assert.expect(3);
location.replace('http://example.com#search/fat%3A1.5%25'); location.replace('http://example.com#search/fat%3A1.5%25');
Backbone.history.checkUrl(); Backbone.history.checkUrl();
location.replace('http://example.com#search/fat'); location.replace('http://example.com#search/fat');
Backbone.history.checkUrl(); Backbone.history.checkUrl();
equal(router.query, 'fat'); assert.equal(router.query, 'fat');
equal(router.page, void 0); assert.equal(router.page, void 0);
equal(lastRoute, 'search'); assert.equal(lastRoute, 'search');
}); });
test("#2666 - Hashes with UTF8 in them.", 2, function() { QUnit.test('#2666 - Hashes with UTF8 in them.', function(assert) {
assert.expect(2);
Backbone.history.navigate('charñ', {trigger: true}); Backbone.history.navigate('charñ', {trigger: true});
equal(router.charType, 'UTF'); assert.equal(router.charType, 'UTF');
Backbone.history.navigate('char%C3%B1', {trigger: true}); Backbone.history.navigate('char%C3%B1', {trigger: true});
equal(router.charType, 'escaped'); assert.equal(router.charType, 'UTF');
}); });
test("#1185 - Use pathname when hashChange is not wanted.", 1, function() { QUnit.test('#1185 - Use pathname when hashChange is not wanted.', function(ass
ert) {
assert.expect(1);
Backbone.history.stop(); Backbone.history.stop();
location.replace('http://example.com/path/name#hash'); location.replace('http://example.com/path/name#hash');
Backbone.history = _.extend(new Backbone.History, {location: location}); Backbone.history = _.extend(new Backbone.History, {location: location});
Backbone.history.start({hashChange: false}); Backbone.history.start({hashChange: false});
var fragment = Backbone.history.getFragment(); var fragment = Backbone.history.getFragment();
strictEqual(fragment, location.pathname.replace(/^\//, '')); assert.strictEqual(fragment, location.pathname.replace(/^\//, ''));
}); });
test("#1206 - Strip leading slash before location.assign.", 1, function() { QUnit.test('#1206 - Strip leading slash before location.assign.', function(ass
ert) {
assert.expect(1);
Backbone.history.stop(); Backbone.history.stop();
location.replace('http://example.com/root/'); location.replace('http://example.com/root/');
Backbone.history = _.extend(new Backbone.History, {location: location}); Backbone.history = _.extend(new Backbone.History, {location: location});
Backbone.history.start({hashChange: false, root: '/root/'}); Backbone.history.start({hashChange: false, root: '/root/'});
location.assign = function(pathname) { location.assign = function(pathname) {
strictEqual(pathname, '/root/fragment'); assert.strictEqual(pathname, '/root/fragment');
}; };
Backbone.history.navigate('/fragment'); Backbone.history.navigate('/fragment');
}); });
test("#1387 - Root fragment without trailing slash.", 1, function() { QUnit.test('#1387 - Root fragment without trailing slash.', function(assert) {
assert.expect(1);
Backbone.history.stop(); Backbone.history.stop();
location.replace('http://example.com/root'); location.replace('http://example.com/root');
Backbone.history = _.extend(new Backbone.History, {location: location}); Backbone.history = _.extend(new Backbone.History, {location: location});
Backbone.history.start({hashChange: false, root: '/root/', silent: true}); Backbone.history.start({hashChange: false, root: '/root/', silent: true});
strictEqual(Backbone.history.getFragment(), ''); assert.strictEqual(Backbone.history.getFragment(), '');
}); });
test("#1366 - History does not prepend root to fragment.", 2, function() { QUnit.test('#1366 - History does not prepend root to fragment.', function(asse
rt) {
assert.expect(2);
Backbone.history.stop(); Backbone.history.stop();
location.replace('http://example.com/root/'); location.replace('http://example.com/root/');
Backbone.history = _.extend(new Backbone.History, { Backbone.history = _.extend(new Backbone.History, {
location: location, location: location,
history: { history: {
pushState: function(state, title, url) { pushState: function(state, title, url) {
strictEqual(url, '/root/x'); assert.strictEqual(url, '/root/x');
} }
} }
}); });
Backbone.history.start({ Backbone.history.start({
root: '/root/', root: '/root/',
pushState: true, pushState: true,
hashChange: false hashChange: false
}); });
Backbone.history.navigate('x'); Backbone.history.navigate('x');
strictEqual(Backbone.history.fragment, 'x'); assert.strictEqual(Backbone.history.fragment, 'x');
}); });
test("Normalize root.", 1, function() { QUnit.test('Normalize root.', function(assert) {
assert.expect(1);
Backbone.history.stop(); Backbone.history.stop();
location.replace('http://example.com/root'); location.replace('http://example.com/root');
Backbone.history = _.extend(new Backbone.History, { Backbone.history = _.extend(new Backbone.History, {
location: location, location: location,
history: { history: {
pushState: function(state, title, url) { pushState: function(state, title, url) {
strictEqual(url, '/root/fragment'); assert.strictEqual(url, '/root/fragment');
} }
} }
}); });
Backbone.history.start({ Backbone.history.start({
pushState: true, pushState: true,
root: '/root', root: '/root',
hashChange: false hashChange: false
}); });
Backbone.history.navigate('fragment'); Backbone.history.navigate('fragment');
}); });
test("Normalize root.", 1, function() { QUnit.test('Normalize root.', function(assert) {
assert.expect(1);
Backbone.history.stop(); Backbone.history.stop();
location.replace('http://example.com/root#fragment'); location.replace('http://example.com/root#fragment');
Backbone.history = _.extend(new Backbone.History, { Backbone.history = _.extend(new Backbone.History, {
location: location, location: location,
history: { history: {
pushState: function(state, title, url) {}, pushState: function(state, title, url) {},
replaceState: function(state, title, url) { replaceState: function(state, title, url) {
strictEqual(url, '/root/fragment'); assert.strictEqual(url, '/root/fragment');
} }
} }
}); });
Backbone.history.start({ Backbone.history.start({
pushState: true, pushState: true,
root: '/root' root: '/root'
}); });
}); });
test("Normalize root.", 1, function() { QUnit.test('Normalize root.', function(assert) {
assert.expect(1);
Backbone.history.stop(); Backbone.history.stop();
location.replace('http://example.com/root'); location.replace('http://example.com/root');
Backbone.history = _.extend(new Backbone.History, {location: location}); Backbone.history = _.extend(new Backbone.History, {location: location});
Backbone.history.loadUrl = function() { ok(true); }; Backbone.history.loadUrl = function() { assert.ok(true); };
Backbone.history.start({ Backbone.history.start({
pushState: true, pushState: true,
root: '/root' root: '/root'
}); });
}); });
test("Normalize root - leading slash.", 1, function() { QUnit.test('Normalize root - leading slash.', function(assert) {
assert.expect(1);
Backbone.history.stop(); Backbone.history.stop();
location.replace('http://example.com/root'); location.replace('http://example.com/root');
Backbone.history = _.extend(new Backbone.History, { Backbone.history = _.extend(new Backbone.History, {
location: location, location: location,
history: { history: {
pushState: function(){}, pushState: function(){},
replaceState: function(){} replaceState: function(){}
} }
}); });
Backbone.history.start({root: 'root'}); Backbone.history.start({root: 'root'});
strictEqual(Backbone.history.root, '/root/'); assert.strictEqual(Backbone.history.root, '/root/');
}); });
test("Transition from hashChange to pushState.", 1, function() { QUnit.test('Transition from hashChange to pushState.', function(assert) {
assert.expect(1);
Backbone.history.stop(); Backbone.history.stop();
location.replace('http://example.com/root#x/y'); location.replace('http://example.com/root#x/y');
Backbone.history = _.extend(new Backbone.History, { Backbone.history = _.extend(new Backbone.History, {
location: location, location: location,
history: { history: {
pushState: function(){}, pushState: function(){},
replaceState: function(state, title, url){ replaceState: function(state, title, url){
strictEqual(url, '/root/x/y'); assert.strictEqual(url, '/root/x/y');
} }
} }
}); });
Backbone.history.start({ Backbone.history.start({
root: 'root', root: 'root',
pushState: true pushState: true
}); });
}); });
test("#1619: Router: Normalize empty root", 1, function() { QUnit.test('#1619: Router: Normalize empty root', function(assert) {
assert.expect(1);
Backbone.history.stop(); Backbone.history.stop();
location.replace('http://example.com/'); location.replace('http://example.com/');
Backbone.history = _.extend(new Backbone.History, { Backbone.history = _.extend(new Backbone.History, {
location: location, location: location,
history: { history: {
pushState: function(){}, pushState: function(){},
replaceState: function(){} replaceState: function(){}
} }
}); });
Backbone.history.start({root: ''}); Backbone.history.start({root: ''});
strictEqual(Backbone.history.root, '/'); assert.strictEqual(Backbone.history.root, '/');
}); });
test("#1619: Router: nagivate with empty root", 1, function() { QUnit.test('#1619: Router: nagivate with empty root', function(assert) {
assert.expect(1);
Backbone.history.stop(); Backbone.history.stop();
location.replace('http://example.com/'); location.replace('http://example.com/');
Backbone.history = _.extend(new Backbone.History, { Backbone.history = _.extend(new Backbone.History, {
location: location, location: location,
history: { history: {
pushState: function(state, title, url) { pushState: function(state, title, url) {
strictEqual(url, '/fragment'); assert.strictEqual(url, '/fragment');
} }
} }
}); });
Backbone.history.start({ Backbone.history.start({
pushState: true, pushState: true,
root: '', root: '',
hashChange: false hashChange: false
}); });
Backbone.history.navigate('fragment'); Backbone.history.navigate('fragment');
}); });
test("Transition from pushState to hashChange.", 1, function() { QUnit.test('Transition from pushState to hashChange.', function(assert) {
assert.expect(1);
Backbone.history.stop(); Backbone.history.stop();
location.replace('http://example.com/root/x/y?a=b'); location.replace('http://example.com/root/x/y?a=b');
location.replace = function(url) { location.replace = function(url) {
strictEqual(url, '/root/#x/y?a=b'); assert.strictEqual(url, '/root#x/y?a=b');
}; };
Backbone.history = _.extend(new Backbone.History, { Backbone.history = _.extend(new Backbone.History, {
location: location, location: location,
history: { history: {
pushState: null, pushState: null,
replaceState: null replaceState: null
} }
}); });
Backbone.history.start({ Backbone.history.start({
root: 'root', root: 'root',
pushState: true pushState: true
}); });
}); });
test("#1695 - hashChange to pushState with search.", 1, function() { QUnit.test('#1695 - hashChange to pushState with search.', function(assert) {
assert.expect(1);
Backbone.history.stop(); Backbone.history.stop();
location.replace('http://example.com/root#x/y?a=b'); location.replace('http://example.com/root#x/y?a=b');
Backbone.history = _.extend(new Backbone.History, { Backbone.history = _.extend(new Backbone.History, {
location: location, location: location,
history: { history: {
pushState: function(){}, pushState: function(){},
replaceState: function(state, title, url){ replaceState: function(state, title, url){
strictEqual(url, '/root/x/y?a=b'); assert.strictEqual(url, '/root/x/y?a=b');
} }
} }
}); });
Backbone.history.start({ Backbone.history.start({
root: 'root', root: 'root',
pushState: true pushState: true
}); });
}); });
test("#1746 - Router allows empty route.", 1, function() { QUnit.test('#1746 - Router allows empty route.', function(assert) {
assert.expect(1);
var Router = Backbone.Router.extend({ var Router = Backbone.Router.extend({
routes: {'': 'empty'}, routes: {'': 'empty'},
empty: function(){}, empty: function(){},
route: function(route){ route: function(route){
strictEqual(route, ''); assert.strictEqual(route, '');
} }
}); });
new Router; new Router;
}); });
test("#1794 - Trailing space in fragments.", 1, function() { QUnit.test('#1794 - Trailing space in fragments.', function(assert) {
assert.expect(1);
var history = new Backbone.History; var history = new Backbone.History;
strictEqual(history.getFragment('fragment '), 'fragment'); assert.strictEqual(history.getFragment('fragment '), 'fragment');
}); });
test("#1820 - Leading slash and trailing space.", 1, function() { QUnit.test('#1820 - Leading slash and trailing space.', 1, function(assert) {
var history = new Backbone.History; var history = new Backbone.History;
strictEqual(history.getFragment('/fragment '), 'fragment'); assert.strictEqual(history.getFragment('/fragment '), 'fragment');
}); });
test("#1980 - Optional parameters.", 2, function() { QUnit.test('#1980 - Optional parameters.', function(assert) {
assert.expect(2);
location.replace('http://example.com#named/optional/y'); location.replace('http://example.com#named/optional/y');
Backbone.history.checkUrl(); Backbone.history.checkUrl();
strictEqual(router.z, undefined); assert.strictEqual(router.z, undefined);
location.replace('http://example.com#named/optional/y123'); location.replace('http://example.com#named/optional/y123');
Backbone.history.checkUrl(); Backbone.history.checkUrl();
strictEqual(router.z, '123'); assert.strictEqual(router.z, '123');
}); });
test("#2062 - Trigger 'route' event on router instance.", 2, function() { QUnit.test("#2062 - Trigger 'route' event on router instance.", function(asser
t) {
assert.expect(2);
router.on('route', function(name, args) { router.on('route', function(name, args) {
strictEqual(name, 'routeEvent'); assert.strictEqual(name, 'routeEvent');
deepEqual(args, ['x', null]); assert.deepEqual(args, ['x', null]);
}); });
location.replace('http://example.com#route-event/x'); location.replace('http://example.com#route-event/x');
Backbone.history.checkUrl(); Backbone.history.checkUrl();
}); });
test("#2255 - Extend routes by making routes a function.", 1, function() { QUnit.test('#2255 - Extend routes by making routes a function.', function(asse
rt) {
assert.expect(1);
var RouterBase = Backbone.Router.extend({ var RouterBase = Backbone.Router.extend({
routes: function() { routes: function() {
return { return {
home: "root", home: 'root',
index: "index.html" index: 'index.html'
}; };
} }
}); });
var RouterExtended = RouterBase.extend({ var RouterExtended = RouterBase.extend({
routes: function() { routes: function() {
var _super = RouterExtended.__super__.routes; var _super = RouterExtended.__super__.routes;
return _.extend(_super(), return _.extend(_super(), {show: 'show', search: 'search'});
{ show: "show",
search: "search" });
} }
}); });
var router = new RouterExtended(); var router = new RouterExtended();
deepEqual({home: "root", index: "index.html", show: "show", search: "search" }, router.routes); assert.deepEqual({home: 'root', index: 'index.html', show: 'show', search: ' search'}, router.routes);
}); });
test("#2538 - hashChange to pushState only if both requested.", 0, function() QUnit.test('#2538 - hashChange to pushState only if both requested.', function
{ (assert) {
assert.expect(0);
Backbone.history.stop(); Backbone.history.stop();
location.replace('http://example.com/root?a=b#x/y'); location.replace('http://example.com/root?a=b#x/y');
Backbone.history = _.extend(new Backbone.History, { Backbone.history = _.extend(new Backbone.History, {
location: location, location: location,
history: { history: {
pushState: function(){}, pushState: function(){},
replaceState: function(){ ok(false); } replaceState: function(){ assert.ok(false); }
} }
}); });
Backbone.history.start({ Backbone.history.start({
root: 'root', root: 'root',
pushState: true, pushState: true,
hashChange: false hashChange: false
}); });
}); });
test('No hash fallback.', 0, function() { QUnit.test('No hash fallback.', function(assert) {
assert.expect(0);
Backbone.history.stop(); Backbone.history.stop();
Backbone.history = _.extend(new Backbone.History, { Backbone.history = _.extend(new Backbone.History, {
location: location, location: location,
history: { history: {
pushState: function(){}, pushState: function(){},
replaceState: function(){} replaceState: function(){}
} }
}); });
var Router = Backbone.Router.extend({ var Router = Backbone.Router.extend({
routes: { routes: {
hash: function() { ok(false); } hash: function() { assert.ok(false); }
} }
}); });
var router = new Router; var router = new Router;
location.replace('http://example.com/'); location.replace('http://example.com/');
Backbone.history.start({ Backbone.history.start({
pushState: true, pushState: true,
hashChange: false hashChange: false
}); });
location.replace('http://example.com/nomatch#hash'); location.replace('http://example.com/nomatch#hash');
Backbone.history.checkUrl(); Backbone.history.checkUrl();
}); });
test('#2656 - No trailing slash on root.', 1, function() { QUnit.test('#2656 - No trailing slash on root.', function(assert) {
assert.expect(1);
Backbone.history.stop(); Backbone.history.stop();
Backbone.history = _.extend(new Backbone.History, { Backbone.history = _.extend(new Backbone.History, {
location: location, location: location,
history: { history: {
pushState: function(state, title, url){ pushState: function(state, title, url){
strictEqual(url, '/root'); assert.strictEqual(url, '/root');
} }
} }
}); });
location.replace('http://example.com/root/path'); location.replace('http://example.com/root/path');
Backbone.history.start({pushState: true, hashChange: false, root: 'root'}); Backbone.history.start({pushState: true, hashChange: false, root: 'root'});
Backbone.history.navigate(''); Backbone.history.navigate('');
}); });
test('#2656 - No trailing slash on root.', 1, function() { QUnit.test('#2656 - No trailing slash on root.', function(assert) {
assert.expect(1);
Backbone.history.stop(); Backbone.history.stop();
Backbone.history = _.extend(new Backbone.History, { Backbone.history = _.extend(new Backbone.History, {
location: location, location: location,
history: { history: {
pushState: function(state, title, url) { pushState: function(state, title, url) {
strictEqual(url, '/'); assert.strictEqual(url, '/');
} }
} }
}); });
location.replace('http://example.com/path'); location.replace('http://example.com/path');
Backbone.history.start({pushState: true, hashChange: false}); Backbone.history.start({pushState: true, hashChange: false});
Backbone.history.navigate(''); Backbone.history.navigate('');
}); });
test('#2765 - Fragment matching sans query/hash.', 2, function() { QUnit.test('#2656 - No trailing slash on root.', function(assert) {
assert.expect(1);
Backbone.history.stop();
Backbone.history = _.extend(new Backbone.History, {
location: location,
history: {
pushState: function(state, title, url){
assert.strictEqual(url, '/root?x=1');
}
}
});
location.replace('http://example.com/root/path');
Backbone.history.start({pushState: true, hashChange: false, root: 'root'});
Backbone.history.navigate('?x=1');
});
QUnit.test('#2765 - Fragment matching sans query/hash.', function(assert) {
assert.expect(2);
Backbone.history.stop(); Backbone.history.stop();
Backbone.history = _.extend(new Backbone.History, { Backbone.history = _.extend(new Backbone.History, {
location: location, location: location,
history: { history: {
pushState: function(state, title, url) { pushState: function(state, title, url) {
strictEqual(url, '/path?query#hash'); assert.strictEqual(url, '/path?query#hash');
} }
} }
}); });
var Router = Backbone.Router.extend({ var Router = Backbone.Router.extend({
routes: { routes: {
path: function() { ok(true); } path: function() { assert.ok(true); }
} }
}); });
var router = new Router; var router = new Router;
location.replace('http://example.com/'); location.replace('http://example.com/');
Backbone.history.start({pushState: true, hashChange: false}); Backbone.history.start({pushState: true, hashChange: false});
Backbone.history.navigate('path?query#hash', true); Backbone.history.navigate('path?query#hash', true);
}); });
test('Do not decode the search params.', function() { QUnit.test('Do not decode the search params.', function(assert) {
assert.expect(1);
var Router = Backbone.Router.extend({ var Router = Backbone.Router.extend({
routes: { routes: {
path: function(params){ path: function(params){
strictEqual(params, 'x=y%20z'); assert.strictEqual(params, 'x=y%3Fz');
} }
} }
}); });
var router = new Router; var router = new Router;
Backbone.history.navigate('path?x=y%20z', true); Backbone.history.navigate('path?x=y%3Fz', true);
}); });
test('Navigate to a hash url.', function() { QUnit.test('Navigate to a hash url.', function(assert) {
assert.expect(1);
Backbone.history.stop(); Backbone.history.stop();
Backbone.history = _.extend(new Backbone.History, {location: location}); Backbone.history = _.extend(new Backbone.History, {location: location});
Backbone.history.start({pushState: true}); Backbone.history.start({pushState: true});
var Router = Backbone.Router.extend({ var Router = Backbone.Router.extend({
routes: { routes: {
path: function(params) { path: function(params) {
strictEqual(params, 'x=y'); assert.strictEqual(params, 'x=y');
} }
} }
}); });
var router = new Router; var router = new Router;
location.replace('http://example.com/path?x=y#hash'); location.replace('http://example.com/path?x=y#hash');
Backbone.history.checkUrl(); Backbone.history.checkUrl();
}); });
test('#navigate to a hash url.', function() { QUnit.test('#navigate to a hash url.', function(assert) {
assert.expect(1);
Backbone.history.stop(); Backbone.history.stop();
Backbone.history = _.extend(new Backbone.History, {location: location}); Backbone.history = _.extend(new Backbone.History, {location: location});
Backbone.history.start({pushState: true}); Backbone.history.start({pushState: true});
var Router = Backbone.Router.extend({ var Router = Backbone.Router.extend({
routes: { routes: {
path: function(params) { path: function(params) {
strictEqual(params, 'x=y'); assert.strictEqual(params, 'x=y');
} }
} }
}); });
var router = new Router; var router = new Router;
Backbone.history.navigate('path?x=y#hash', true); Backbone.history.navigate('path?x=y#hash', true);
}); });
test('unicode pathname', 1, function() { QUnit.test('unicode pathname', function(assert) {
assert.expect(1);
location.replace('http://example.com/myyjä'); location.replace('http://example.com/myyjä');
Backbone.history.stop(); Backbone.history.stop();
Backbone.history = _.extend(new Backbone.History, {location: location}); Backbone.history = _.extend(new Backbone.History, {location: location});
var Router = Backbone.Router.extend({ var Router = Backbone.Router.extend({
routes: { routes: {
myyjä: function() { myyjä: function() {
ok(true); assert.ok(true);
}
}
});
new Router;
Backbone.history.start({pushState: true});
});
QUnit.test('unicode pathname with % in a parameter', function(assert) {
assert.expect(1);
location.replace('http://example.com/myyjä/foo%20%25%3F%2f%40%25%20bar');
location.pathname = '/myyj%C3%A4/foo%20%25%3F%2f%40%25%20bar';
Backbone.history.stop();
Backbone.history = _.extend(new Backbone.History, {location: location});
var Router = Backbone.Router.extend({
routes: {
'myyjä/:query': function(query) {
assert.strictEqual(query, 'foo %?/@% bar');
} }
} }
}); });
new Router; new Router;
Backbone.history.start({pushState: true}); Backbone.history.start({pushState: true});
}); });
test('newline in route', 1, function() { QUnit.test('newline in route', function(assert) {
assert.expect(1);
location.replace('http://example.com/stuff%0Anonsense?param=foo%0Abar'); location.replace('http://example.com/stuff%0Anonsense?param=foo%0Abar');
Backbone.history.stop(); Backbone.history.stop();
Backbone.history = _.extend(new Backbone.History, {location: location}); Backbone.history = _.extend(new Backbone.History, {location: location});
var Router = Backbone.Router.extend({ var Router = Backbone.Router.extend({
routes: { routes: {
'stuff\nnonsense': function() { 'stuff\nnonsense': function() {
ok(true); assert.ok(true);
} }
} }
}); });
new Router; new Router;
Backbone.history.start({pushState: true}); Backbone.history.start({pushState: true});
}); });
QUnit.test('Router#execute receives callback, args, name.', function(assert) {
assert.expect(3);
location.replace('http://example.com#foo/123/bar?x=y');
Backbone.history.stop();
Backbone.history = _.extend(new Backbone.History, {location: location});
var Router = Backbone.Router.extend({
routes: {'foo/:id/bar': 'foo'},
foo: function(){},
execute: function(callback, args, name) {
assert.strictEqual(callback, this.foo);
assert.deepEqual(args, ['123', 'x=y']);
assert.strictEqual(name, 'foo');
}
});
var router = new Router;
Backbone.history.start();
});
QUnit.test('pushState to hashChange with only search params.', function(assert
) {
assert.expect(1);
Backbone.history.stop();
location.replace('http://example.com?a=b');
location.replace = function(url) {
assert.strictEqual(url, '/#?a=b');
};
Backbone.history = _.extend(new Backbone.History, {
location: location,
history: null
});
Backbone.history.start({pushState: true});
});
QUnit.test('#3123 - History#navigate decodes before comparison.', function(ass
ert) {
assert.expect(1);
Backbone.history.stop();
location.replace('http://example.com/shop/search?keyword=short%20dress');
Backbone.history = _.extend(new Backbone.History, {
location: location,
history: {
pushState: function(){ assert.ok(false); },
replaceState: function(){ assert.ok(false); }
}
});
Backbone.history.start({pushState: true});
Backbone.history.navigate('shop/search?keyword=short%20dress', true);
assert.strictEqual(Backbone.history.fragment, 'shop/search?keyword=short dre
ss');
});
QUnit.test('#3175 - Urls in the params', function(assert) {
assert.expect(1);
Backbone.history.stop();
location.replace('http://example.com#login?a=value&backUrl=https%3A%2F%2Fwww
.msn.com%2Fidp%2Fidpdemo%3Fspid%3Dspdemo%26target%3Db');
Backbone.history = _.extend(new Backbone.History, {location: location});
var router = new Backbone.Router;
router.route('login', function(params) {
assert.strictEqual(params, 'a=value&backUrl=https%3A%2F%2Fwww.msn.com%2Fid
p%2Fidpdemo%3Fspid%3Dspdemo%26target%3Db');
});
Backbone.history.start();
});
QUnit.test('#3358 - pushState to hashChange transition with search params', fu
nction(assert) {
assert.expect(1);
Backbone.history.stop();
location.replace('http://example.com/root?foo=bar');
location.replace = function(url) {
assert.strictEqual(url, '/root#?foo=bar');
};
Backbone.history = _.extend(new Backbone.History, {
location: location,
history: {
pushState: undefined,
replaceState: undefined
}
});
Backbone.history.start({root: '/root', pushState: true});
});
QUnit.test("Paths that don't match the root should not match no root", functio
n(assert) {
assert.expect(0);
location.replace('http://example.com/foo');
Backbone.history.stop();
Backbone.history = _.extend(new Backbone.History, {location: location});
var Router = Backbone.Router.extend({
routes: {
foo: function(){
assert.ok(false, 'should not match unless root matches');
}
}
});
var router = new Router;
Backbone.history.start({root: 'root', pushState: true});
});
QUnit.test("Paths that don't match the root should not match roots of the same
length", function(assert) {
assert.expect(0);
location.replace('http://example.com/xxxx/foo');
Backbone.history.stop();
Backbone.history = _.extend(new Backbone.History, {location: location});
var Router = Backbone.Router.extend({
routes: {
foo: function(){
assert.ok(false, 'should not match unless root matches');
}
}
});
var router = new Router;
Backbone.history.start({root: 'root', pushState: true});
});
QUnit.test('roots with regex characters', function(assert) {
assert.expect(1);
location.replace('http://example.com/x+y.z/foo');
Backbone.history.stop();
Backbone.history = _.extend(new Backbone.History, {location: location});
var Router = Backbone.Router.extend({
routes: {foo: function(){ assert.ok(true); }}
});
var router = new Router;
Backbone.history.start({root: 'x+y.z', pushState: true});
});
QUnit.test('roots with unicode characters', function(assert) {
assert.expect(1);
location.replace('http://example.com/®ooτ/foo');
Backbone.history.stop();
Backbone.history = _.extend(new Backbone.History, {location: location});
var Router = Backbone.Router.extend({
routes: {foo: function(){ assert.ok(true); }}
});
var router = new Router;
Backbone.history.start({root: '®ooτ', pushState: true});
});
QUnit.test('roots without slash', function(assert) {
assert.expect(1);
location.replace('http://example.com/®ooτ');
Backbone.history.stop();
Backbone.history = _.extend(new Backbone.History, {location: location});
var Router = Backbone.Router.extend({
routes: {'': function(){ assert.ok(true); }}
});
var router = new Router;
Backbone.history.start({root: '®ooτ', pushState: true});
});
})(); })();
 End of changes. 123 change blocks. 
179 lines changed or deleted 448 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)