8 var onRoute = function(routerParam, route, args) {
13 var Location = function(href) {
17 _.extend(Location.prototype, {
19 parser: document.createElement('a'),
21 replace: function(href) {
22 this.parser.href = href;
23 _.extend(this, _.pick(this.parser,
32 // In IE, anchor.pathname does not contain a leading slash though
33 // window.location.pathname does.
34 if (!/^\//.test(this.pathname)) this.pathname = '/' + this.pathname;
37 toString: function() {
43 QUnit.module('Backbone.Router', {
46 location = new Location('http://example.com');
47 Backbone.history = _.extend(new Backbone.History, {location: location});
48 router = new Router({testing: 101});
49 Backbone.history.interval = 9;
50 Backbone.history.start({pushState: false});
53 Backbone.history.on('route', onRoute);
56 teardown: function() {
57 Backbone.history.stop();
58 Backbone.history.off('route', onRoute);
63 var ExternalObject = {
66 routingFunction: function(value) {
70 ExternalObject.routingFunction = _.bind(ExternalObject.routingFunction, ExternalObject);
72 var Router = Backbone.Router.extend({
77 'noCallback': 'noCallback',
79 'search/:query': 'search',
80 'search/:query/p:page': 'search',
82 'char%C3%B1': 'charEscaped',
83 'contacts': 'contacts',
84 'contacts/new': 'newContact',
85 'contacts/:id': 'loadContact',
86 'route-event/:arg': 'routeEvent',
87 'optional(/:item)': 'optionalItem',
88 'named/optional/(y:z)': 'namedOptional',
89 'splat/*args/end': 'splat',
90 ':repo/compare/*from...*to': 'github',
91 'decode/:named/*splat': 'decode',
92 '*first/complex-*part/*rest': 'complex',
93 'query/:entity': 'query',
94 'function/:value': ExternalObject.routingFunction,
95 '*anything': 'anything'
98 initialize: function(options) {
99 this.testing = options.testing;
100 this.route('implicit', 'implicit');
103 counter: function() {
107 implicit: function() {
111 search: function(query, page) {
116 charUTF: function() {
117 this.charType = 'UTF';
120 charEscaped: function() {
121 this.charType = 'escaped';
124 contacts: function(){
125 this.contact = 'index';
128 newContact: function(){
129 this.contact = 'new';
132 loadContact: function(){
133 this.contact = 'load';
136 optionalItem: function(arg){
137 this.arg = arg !== void 0 ? arg : null;
140 splat: function(args) {
144 github: function(repo, from, to) {
150 complex: function(first, part, rest) {
156 query: function(entity, args) {
157 this.entity = entity;
158 this.queryArgs = args;
161 anything: function(whatever) {
162 this.anything = whatever;
165 namedOptional: function(z) {
169 decode: function(named, path) {
174 routeEvent: function(arg) {
179 QUnit.test('initialize', function(assert) {
181 assert.equal(router.testing, 101);
184 QUnit.test('routes (simple)', function(assert) {
186 location.replace('http://example.com#search/news');
187 Backbone.history.checkUrl();
188 assert.equal(router.query, 'news');
189 assert.equal(router.page, void 0);
190 assert.equal(lastRoute, 'search');
191 assert.equal(lastArgs[0], 'news');
194 QUnit.test('routes (simple, but unicode)', function(assert) {
196 location.replace('http://example.com#search/тест');
197 Backbone.history.checkUrl();
198 assert.equal(router.query, 'тест');
199 assert.equal(router.page, void 0);
200 assert.equal(lastRoute, 'search');
201 assert.equal(lastArgs[0], 'тест');
204 QUnit.test('routes (two part)', function(assert) {
206 location.replace('http://example.com#search/nyc/p10');
207 Backbone.history.checkUrl();
208 assert.equal(router.query, 'nyc');
209 assert.equal(router.page, '10');
212 QUnit.test('routes via navigate', function(assert) {
214 Backbone.history.navigate('search/manhattan/p20', {trigger: true});
215 assert.equal(router.query, 'manhattan');
216 assert.equal(router.page, '20');
219 QUnit.test('routes via navigate with params', function(assert) {
221 Backbone.history.navigate('query/test?a=b', {trigger: true});
222 assert.equal(router.queryArgs, 'a=b');
225 QUnit.test('routes via navigate for backwards-compatibility', function(assert) {
227 Backbone.history.navigate('search/manhattan/p20', true);
228 assert.equal(router.query, 'manhattan');
229 assert.equal(router.page, '20');
232 QUnit.test('reports matched route via nagivate', function(assert) {
234 assert.ok(Backbone.history.navigate('search/manhattan/p20', true));
237 QUnit.test('route precedence via navigate', function(assert){
239 // check both 0.9.x and backwards-compatibility options
240 _.each([{trigger: true}, true], function( options ){
241 Backbone.history.navigate('contacts', options);
242 assert.equal(router.contact, 'index');
243 Backbone.history.navigate('contacts/new', options);
244 assert.equal(router.contact, 'new');
245 Backbone.history.navigate('contacts/foo', options);
246 assert.equal(router.contact, 'load');
250 QUnit.test('loadUrl is not called for identical routes.', function(assert) {
252 Backbone.history.loadUrl = function(){ assert.ok(false); };
253 location.replace('http://example.com#route');
254 Backbone.history.navigate('route');
255 Backbone.history.navigate('/route');
256 Backbone.history.navigate('/route');
259 QUnit.test('use implicit callback if none provided', function(assert) {
262 router.navigate('implicit', {trigger: true});
263 assert.equal(router.count, 1);
266 QUnit.test('routes via navigate with {replace: true}', function(assert) {
268 location.replace('http://example.com#start_here');
269 Backbone.history.checkUrl();
270 location.replace = function(href) {
271 assert.strictEqual(href, new Location('http://example.com#end_here').href);
273 Backbone.history.navigate('end_here', {replace: true});
276 QUnit.test('routes (splats)', function(assert) {
278 location.replace('http://example.com#splat/long-list/of/splatted_99args/end');
279 Backbone.history.checkUrl();
280 assert.equal(router.args, 'long-list/of/splatted_99args');
283 QUnit.test('routes (github)', function(assert) {
285 location.replace('http://example.com#backbone/compare/1.0...braddunbar:with/slash');
286 Backbone.history.checkUrl();
287 assert.equal(router.repo, 'backbone');
288 assert.equal(router.from, '1.0');
289 assert.equal(router.to, 'braddunbar:with/slash');
292 QUnit.test('routes (optional)', function(assert) {
294 location.replace('http://example.com#optional');
295 Backbone.history.checkUrl();
296 assert.ok(!router.arg);
297 location.replace('http://example.com#optional/thing');
298 Backbone.history.checkUrl();
299 assert.equal(router.arg, 'thing');
302 QUnit.test('routes (complex)', function(assert) {
304 location.replace('http://example.com#one/two/three/complex-part/four/five/six/seven');
305 Backbone.history.checkUrl();
306 assert.equal(router.first, 'one/two/three');
307 assert.equal(router.part, 'part');
308 assert.equal(router.rest, 'four/five/six/seven');
311 QUnit.test('routes (query)', function(assert) {
313 location.replace('http://example.com#query/mandel?a=b&c=d');
314 Backbone.history.checkUrl();
315 assert.equal(router.entity, 'mandel');
316 assert.equal(router.queryArgs, 'a=b&c=d');
317 assert.equal(lastRoute, 'query');
318 assert.equal(lastArgs[0], 'mandel');
319 assert.equal(lastArgs[1], 'a=b&c=d');
322 QUnit.test('routes (anything)', function(assert) {
324 location.replace('http://example.com#doesnt-match-a-route');
325 Backbone.history.checkUrl();
326 assert.equal(router.anything, 'doesnt-match-a-route');
329 QUnit.test('routes (function)', function(assert) {
331 router.on('route', function(name) {
332 assert.ok(name === '');
334 assert.equal(ExternalObject.value, 'unset');
335 location.replace('http://example.com#function/set');
336 Backbone.history.checkUrl();
337 assert.equal(ExternalObject.value, 'set');
340 QUnit.test('Decode named parameters, not splats.', function(assert) {
342 location.replace('http://example.com#decode/a%2Fb/c%2Fd/e');
343 Backbone.history.checkUrl();
344 assert.strictEqual(router.named, 'a/b');
345 assert.strictEqual(router.path, 'c/d/e');
348 QUnit.test("fires event when router doesn't have callback on it", function(assert) {
350 router.on('route:noCallback', function(){ assert.ok(true); });
351 location.replace('http://example.com#noCallback');
352 Backbone.history.checkUrl();
355 QUnit.test('No events are triggered if #execute returns false.', function(assert) {
357 var MyRouter = Backbone.Router.extend({
365 execute: function(callback, args) {
366 callback.apply(this, args);
372 var myRouter = new MyRouter;
374 myRouter.on('route route:foo', function() {
378 Backbone.history.on('route', function() {
382 location.replace('http://example.com#foo');
383 Backbone.history.checkUrl();
386 QUnit.test('#933, #908 - leading slash', function(assert) {
388 location.replace('http://example.com/root/foo');
390 Backbone.history.stop();
391 Backbone.history = _.extend(new Backbone.History, {location: location});
392 Backbone.history.start({root: '/root', hashChange: false, silent: true});
393 assert.strictEqual(Backbone.history.getFragment(), 'foo');
395 Backbone.history.stop();
396 Backbone.history = _.extend(new Backbone.History, {location: location});
397 Backbone.history.start({root: '/root/', hashChange: false, silent: true});
398 assert.strictEqual(Backbone.history.getFragment(), 'foo');
401 QUnit.test('#967 - Route callback gets passed encoded values.', function(assert) {
403 var route = 'has%2Fslash/complex-has%23hash/has%20space';
404 Backbone.history.navigate(route, {trigger: true});
405 assert.strictEqual(router.first, 'has/slash');
406 assert.strictEqual(router.part, 'has#hash');
407 assert.strictEqual(router.rest, 'has space');
410 QUnit.test('correctly handles URLs with % (#868)', function(assert) {
412 location.replace('http://example.com#search/fat%3A1.5%25');
413 Backbone.history.checkUrl();
414 location.replace('http://example.com#search/fat');
415 Backbone.history.checkUrl();
416 assert.equal(router.query, 'fat');
417 assert.equal(router.page, void 0);
418 assert.equal(lastRoute, 'search');
421 QUnit.test('#2666 - Hashes with UTF8 in them.', function(assert) {
423 Backbone.history.navigate('charñ', {trigger: true});
424 assert.equal(router.charType, 'UTF');
425 Backbone.history.navigate('char%C3%B1', {trigger: true});
426 assert.equal(router.charType, 'UTF');
429 QUnit.test('#1185 - Use pathname when hashChange is not wanted.', function(assert) {
431 Backbone.history.stop();
432 location.replace('http://example.com/path/name#hash');
433 Backbone.history = _.extend(new Backbone.History, {location: location});
434 Backbone.history.start({hashChange: false});
435 var fragment = Backbone.history.getFragment();
436 assert.strictEqual(fragment, location.pathname.replace(/^\//, ''));
439 QUnit.test('#1206 - Strip leading slash before location.assign.', function(assert) {
441 Backbone.history.stop();
442 location.replace('http://example.com/root/');
443 Backbone.history = _.extend(new Backbone.History, {location: location});
444 Backbone.history.start({hashChange: false, root: '/root/'});
445 location.assign = function(pathname) {
446 assert.strictEqual(pathname, '/root/fragment');
448 Backbone.history.navigate('/fragment');
451 QUnit.test('#1387 - Root fragment without trailing slash.', function(assert) {
453 Backbone.history.stop();
454 location.replace('http://example.com/root');
455 Backbone.history = _.extend(new Backbone.History, {location: location});
456 Backbone.history.start({hashChange: false, root: '/root/', silent: true});
457 assert.strictEqual(Backbone.history.getFragment(), '');
460 QUnit.test('#1366 - History does not prepend root to fragment.', function(assert) {
462 Backbone.history.stop();
463 location.replace('http://example.com/root/');
464 Backbone.history = _.extend(new Backbone.History, {
467 pushState: function(state, title, url) {
468 assert.strictEqual(url, '/root/x');
472 Backbone.history.start({
477 Backbone.history.navigate('x');
478 assert.strictEqual(Backbone.history.fragment, 'x');
481 QUnit.test('Normalize root.', function(assert) {
483 Backbone.history.stop();
484 location.replace('http://example.com/root');
485 Backbone.history = _.extend(new Backbone.History, {
488 pushState: function(state, title, url) {
489 assert.strictEqual(url, '/root/fragment');
493 Backbone.history.start({
498 Backbone.history.navigate('fragment');
501 QUnit.test('Normalize root.', function(assert) {
503 Backbone.history.stop();
504 location.replace('http://example.com/root#fragment');
505 Backbone.history = _.extend(new Backbone.History, {
508 pushState: function(state, title, url) {},
509 replaceState: function(state, title, url) {
510 assert.strictEqual(url, '/root/fragment');
514 Backbone.history.start({
520 QUnit.test('Normalize root.', function(assert) {
522 Backbone.history.stop();
523 location.replace('http://example.com/root');
524 Backbone.history = _.extend(new Backbone.History, {location: location});
525 Backbone.history.loadUrl = function() { assert.ok(true); };
526 Backbone.history.start({
532 QUnit.test('Normalize root - leading slash.', function(assert) {
534 Backbone.history.stop();
535 location.replace('http://example.com/root');
536 Backbone.history = _.extend(new Backbone.History, {
539 pushState: function(){},
540 replaceState: function(){}
543 Backbone.history.start({root: 'root'});
544 assert.strictEqual(Backbone.history.root, '/root/');
547 QUnit.test('Transition from hashChange to pushState.', function(assert) {
549 Backbone.history.stop();
550 location.replace('http://example.com/root#x/y');
551 Backbone.history = _.extend(new Backbone.History, {
554 pushState: function(){},
555 replaceState: function(state, title, url){
556 assert.strictEqual(url, '/root/x/y');
560 Backbone.history.start({
566 QUnit.test('#1619: Router: Normalize empty root', function(assert) {
568 Backbone.history.stop();
569 location.replace('http://example.com/');
570 Backbone.history = _.extend(new Backbone.History, {
573 pushState: function(){},
574 replaceState: function(){}
577 Backbone.history.start({root: ''});
578 assert.strictEqual(Backbone.history.root, '/');
581 QUnit.test('#1619: Router: nagivate with empty root', function(assert) {
583 Backbone.history.stop();
584 location.replace('http://example.com/');
585 Backbone.history = _.extend(new Backbone.History, {
588 pushState: function(state, title, url) {
589 assert.strictEqual(url, '/fragment');
593 Backbone.history.start({
598 Backbone.history.navigate('fragment');
601 QUnit.test('Transition from pushState to hashChange.', function(assert) {
603 Backbone.history.stop();
604 location.replace('http://example.com/root/x/y?a=b');
605 location.replace = function(url) {
606 assert.strictEqual(url, '/root#x/y?a=b');
608 Backbone.history = _.extend(new Backbone.History, {
615 Backbone.history.start({
621 QUnit.test('#1695 - hashChange to pushState with search.', function(assert) {
623 Backbone.history.stop();
624 location.replace('http://example.com/root#x/y?a=b');
625 Backbone.history = _.extend(new Backbone.History, {
628 pushState: function(){},
629 replaceState: function(state, title, url){
630 assert.strictEqual(url, '/root/x/y?a=b');
634 Backbone.history.start({
640 QUnit.test('#1746 - Router allows empty route.', function(assert) {
642 var MyRouter = Backbone.Router.extend({
643 routes: {'': 'empty'},
645 route: function(route){
646 assert.strictEqual(route, '');
652 QUnit.test('#1794 - Trailing space in fragments.', function(assert) {
654 var history = new Backbone.History;
655 assert.strictEqual(history.getFragment('fragment '), 'fragment');
658 QUnit.test('#1820 - Leading slash and trailing space.', 1, function(assert) {
659 var history = new Backbone.History;
660 assert.strictEqual(history.getFragment('/fragment '), 'fragment');
663 QUnit.test('#1980 - Optional parameters.', function(assert) {
665 location.replace('http://example.com#named/optional/y');
666 Backbone.history.checkUrl();
667 assert.strictEqual(router.z, undefined);
668 location.replace('http://example.com#named/optional/y123');
669 Backbone.history.checkUrl();
670 assert.strictEqual(router.z, '123');
673 QUnit.test("#2062 - Trigger 'route' event on router instance.", function(assert) {
675 router.on('route', function(name, args) {
676 assert.strictEqual(name, 'routeEvent');
677 assert.deepEqual(args, ['x', null]);
679 location.replace('http://example.com#route-event/x');
680 Backbone.history.checkUrl();
683 QUnit.test('#2255 - Extend routes by making routes a function.', function(assert) {
685 var RouterBase = Backbone.Router.extend({
694 var RouterExtended = RouterBase.extend({
696 var _super = RouterExtended.__super__.routes;
697 return _.extend(_super(), {show: 'show', search: 'search'});
701 var myRouter = new RouterExtended();
702 assert.deepEqual({home: 'root', index: 'index.html', show: 'show', search: 'search'}, myRouter.routes);
705 QUnit.test('#2538 - hashChange to pushState only if both requested.', function(assert) {
707 Backbone.history.stop();
708 location.replace('http://example.com/root?a=b#x/y');
709 Backbone.history = _.extend(new Backbone.History, {
712 pushState: function(){},
713 replaceState: function(){ assert.ok(false); }
716 Backbone.history.start({
723 QUnit.test('No hash fallback.', function(assert) {
725 Backbone.history.stop();
726 Backbone.history = _.extend(new Backbone.History, {
729 pushState: function(){},
730 replaceState: function(){}
734 var MyRouter = Backbone.Router.extend({
736 hash: function() { assert.ok(false); }
739 var myRouter = new MyRouter;
741 location.replace('http://example.com/');
742 Backbone.history.start({
746 location.replace('http://example.com/nomatch#hash');
747 Backbone.history.checkUrl();
750 QUnit.test('#2656 - No trailing slash on root.', function(assert) {
752 Backbone.history.stop();
753 Backbone.history = _.extend(new Backbone.History, {
756 pushState: function(state, title, url){
757 assert.strictEqual(url, '/root');
761 location.replace('http://example.com/root/path');
762 Backbone.history.start({pushState: true, hashChange: false, root: 'root'});
763 Backbone.history.navigate('');
766 QUnit.test('#2656 - No trailing slash on root.', function(assert) {
768 Backbone.history.stop();
769 Backbone.history = _.extend(new Backbone.History, {
772 pushState: function(state, title, url) {
773 assert.strictEqual(url, '/');
777 location.replace('http://example.com/path');
778 Backbone.history.start({pushState: true, hashChange: false});
779 Backbone.history.navigate('');
782 QUnit.test('#2656 - No trailing slash on root.', function(assert) {
784 Backbone.history.stop();
785 Backbone.history = _.extend(new Backbone.History, {
788 pushState: function(state, title, url){
789 assert.strictEqual(url, '/root?x=1');
793 location.replace('http://example.com/root/path');
794 Backbone.history.start({pushState: true, hashChange: false, root: 'root'});
795 Backbone.history.navigate('?x=1');
798 QUnit.test('#2765 - Fragment matching sans query/hash.', function(assert) {
800 Backbone.history.stop();
801 Backbone.history = _.extend(new Backbone.History, {
804 pushState: function(state, title, url) {
805 assert.strictEqual(url, '/path?query#hash');
810 var MyRouter = Backbone.Router.extend({
812 path: function() { assert.ok(true); }
815 var myRouter = new MyRouter;
817 location.replace('http://example.com/');
818 Backbone.history.start({pushState: true, hashChange: false});
819 Backbone.history.navigate('path?query#hash', true);
822 QUnit.test('Do not decode the search params.', function(assert) {
824 var MyRouter = Backbone.Router.extend({
826 path: function(params){
827 assert.strictEqual(params, 'x=y%3Fz');
831 var myRouter = new MyRouter;
832 Backbone.history.navigate('path?x=y%3Fz', true);
835 QUnit.test('Navigate to a hash url.', function(assert) {
837 Backbone.history.stop();
838 Backbone.history = _.extend(new Backbone.History, {location: location});
839 Backbone.history.start({pushState: true});
840 var MyRouter = Backbone.Router.extend({
842 path: function(params) {
843 assert.strictEqual(params, 'x=y');
847 var myRouter = new MyRouter;
848 location.replace('http://example.com/path?x=y#hash');
849 Backbone.history.checkUrl();
852 QUnit.test('#navigate to a hash url.', function(assert) {
854 Backbone.history.stop();
855 Backbone.history = _.extend(new Backbone.History, {location: location});
856 Backbone.history.start({pushState: true});
857 var MyRouter = Backbone.Router.extend({
859 path: function(params) {
860 assert.strictEqual(params, 'x=y');
864 var myRouter = new MyRouter;
865 Backbone.history.navigate('path?x=y#hash', true);
868 QUnit.test('unicode pathname', function(assert) {
870 location.replace('http://example.com/myyjä');
871 Backbone.history.stop();
872 Backbone.history = _.extend(new Backbone.History, {location: location});
873 var MyRouter = Backbone.Router.extend({
881 Backbone.history.start({pushState: true});
884 QUnit.test('unicode pathname with % in a parameter', function(assert) {
886 location.replace('http://example.com/myyjä/foo%20%25%3F%2f%40%25%20bar');
887 location.pathname = '/myyj%C3%A4/foo%20%25%3F%2f%40%25%20bar';
888 Backbone.history.stop();
889 Backbone.history = _.extend(new Backbone.History, {location: location});
890 var MyRouter = Backbone.Router.extend({
892 'myyjä/:query': function(query) {
893 assert.strictEqual(query, 'foo %?/@% bar');
898 Backbone.history.start({pushState: true});
901 QUnit.test('newline in route', function(assert) {
903 location.replace('http://example.com/stuff%0Anonsense?param=foo%0Abar');
904 Backbone.history.stop();
905 Backbone.history = _.extend(new Backbone.History, {location: location});
906 var MyRouter = Backbone.Router.extend({
908 'stuff\nnonsense': function() {
914 Backbone.history.start({pushState: true});
917 QUnit.test('Router#execute receives callback, args, name.', function(assert) {
919 location.replace('http://example.com#foo/123/bar?x=y');
920 Backbone.history.stop();
921 Backbone.history = _.extend(new Backbone.History, {location: location});
922 var MyRouter = Backbone.Router.extend({
923 routes: {'foo/:id/bar': 'foo'},
925 execute: function(callback, args, name) {
926 assert.strictEqual(callback, this.foo);
927 assert.deepEqual(args, ['123', 'x=y']);
928 assert.strictEqual(name, 'foo');
931 var myRouter = new MyRouter;
932 Backbone.history.start();
935 QUnit.test('pushState to hashChange with only search params.', function(assert) {
937 Backbone.history.stop();
938 location.replace('http://example.com?a=b');
939 location.replace = function(url) {
940 assert.strictEqual(url, '/#?a=b');
942 Backbone.history = _.extend(new Backbone.History, {
946 Backbone.history.start({pushState: true});
949 QUnit.test('#3123 - History#navigate decodes before comparison.', function(assert) {
951 Backbone.history.stop();
952 location.replace('http://example.com/shop/search?keyword=short%20dress');
953 Backbone.history = _.extend(new Backbone.History, {
956 pushState: function(){ assert.ok(false); },
957 replaceState: function(){ assert.ok(false); }
960 Backbone.history.start({pushState: true});
961 Backbone.history.navigate('shop/search?keyword=short%20dress', true);
962 assert.strictEqual(Backbone.history.fragment, 'shop/search?keyword=short dress');
965 QUnit.test('#3175 - Urls in the params', function(assert) {
967 Backbone.history.stop();
968 location.replace('http://example.com#login?a=value&backUrl=https%3A%2F%2Fwww.msn.com%2Fidp%2Fidpdemo%3Fspid%3Dspdemo%26target%3Db');
969 Backbone.history = _.extend(new Backbone.History, {location: location});
970 var myRouter = new Backbone.Router;
971 myRouter.route('login', function(params) {
972 assert.strictEqual(params, 'a=value&backUrl=https%3A%2F%2Fwww.msn.com%2Fidp%2Fidpdemo%3Fspid%3Dspdemo%26target%3Db');
974 Backbone.history.start();
977 QUnit.test('#3358 - pushState to hashChange transition with search params', function(assert) {
979 Backbone.history.stop();
980 location.replace('http://example.com/root?foo=bar');
981 location.replace = function(url) {
982 assert.strictEqual(url, '/root#?foo=bar');
984 Backbone.history = _.extend(new Backbone.History, {
987 pushState: undefined,
988 replaceState: undefined
991 Backbone.history.start({root: '/root', pushState: true});
994 QUnit.test("Paths that don't match the root should not match no root", function(assert) {
996 location.replace('http://example.com/foo');
997 Backbone.history.stop();
998 Backbone.history = _.extend(new Backbone.History, {location: location});
999 var MyRouter = Backbone.Router.extend({
1002 assert.ok(false, 'should not match unless root matches');
1006 var myRouter = new MyRouter;
1007 Backbone.history.start({root: 'root', pushState: true});
1010 QUnit.test("Paths that don't match the root should not match roots of the same length", function(assert) {
1012 location.replace('http://example.com/xxxx/foo');
1013 Backbone.history.stop();
1014 Backbone.history = _.extend(new Backbone.History, {location: location});
1015 var MyRouter = Backbone.Router.extend({
1018 assert.ok(false, 'should not match unless root matches');
1022 var myRouter = new MyRouter;
1023 Backbone.history.start({root: 'root', pushState: true});
1026 QUnit.test('roots with regex characters', function(assert) {
1028 location.replace('http://example.com/x+y.z/foo');
1029 Backbone.history.stop();
1030 Backbone.history = _.extend(new Backbone.History, {location: location});
1031 var MyRouter = Backbone.Router.extend({
1032 routes: {foo: function(){ assert.ok(true); }}
1034 var myRouter = new MyRouter;
1035 Backbone.history.start({root: 'x+y.z', pushState: true});
1038 QUnit.test('roots with unicode characters', function(assert) {
1040 location.replace('http://example.com/®ooτ/foo');
1041 Backbone.history.stop();
1042 Backbone.history = _.extend(new Backbone.History, {location: location});
1043 var MyRouter = Backbone.Router.extend({
1044 routes: {foo: function(){ assert.ok(true); }}
1046 var myRouter = new MyRouter;
1047 Backbone.history.start({root: '®ooτ', pushState: true});
1050 QUnit.test('roots without slash', function(assert) {
1052 location.replace('http://example.com/®ooτ');
1053 Backbone.history.stop();
1054 Backbone.history = _.extend(new Backbone.History, {location: location});
1055 var MyRouter = Backbone.Router.extend({
1056 routes: {'': function(){ assert.ok(true); }}
1058 var myRouter = new MyRouter;
1059 Backbone.history.start({root: '®ooτ', pushState: true});