123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 |
- (function(){
- var
- History = window.History,
- document = window.document,
- test = window.test,
- same = window.same;
- if ( !History.enabled ) {
- throw new Error('History.js is disabled');
- }
- History.options.debug = false;
- var
- States = {
-
- 0: {
- 'url': document.location.href.replace(/#.*$/,''),
- 'title': ''
- },
-
- 1: {
- 'data': {
- 'state': 1,
- 'rand': Math.random()
- },
- 'title': 'State 1',
- 'url': '?state=1'
- },
-
- 2: {
- 'data': {
- 'state': 2,
- 'rand': Math.random()
- },
- 'title': 'State 2',
- 'url': '?state=2&asd=%20asd%2520asd'
- },
-
- 3: {
- 'url': '?state=3'
- },
-
- 4: {
- 'data': {
- 'state': 4,
- 'trick': true,
- 'rand': Math.random()
- },
- 'title': 'State 4',
- 'url': '?state=3'
- },
-
- 5: {
- 'url': '?state=1#log'
- },
-
- 6: {
- 'data': {
- 'state': 6,
- 'rand': Math.random()
- },
- 'url': 'six.html'
- },
-
- 7: {
- 'url': 'seven'
- },
-
- 8: {
- 'url': '/eight'
- }
- },
- stateOrder = [0,1,2,3,4,3,1,0,1,3,4,3,1,0,6,7,8,1,8,7,6,0],
- currentTest = 0;
- var title = document.title;
- var banner;
- var checkStatus = function(){
- banner = banner || document.getElementById('qunit-banner');
- var status = banner.className !== 'qunit-fail';
- return status;
- };
- var checkState = function(){
- if ( !checkStatus() ) {
- throw new Error('A test has failed');
- }
- var
- stateIndex = stateOrder[currentTest],
- expectedState = History.normalizeState(States[stateIndex]),
- actualState = History.getState(false);
- ++currentTest;
- document.title = title+': '+actualState.url;
- var
- testName = 'Test '+currentTest,
- stateName = 'State '+stateIndex;
- test(testName,function(){
- History.log('Completed: '+testName +' / '+ stateName);
- same(actualState,expectedState,stateName);
- });
-
- (new Image()).src = "image.php";
- };
- checkState();
- History.Adapter.bind(window,'statechange',checkState);
- var addLog = function(){
- var args = arguments;
- History.queue(function(){
- History.log.apply(History,args);
- });
- };
- History.Adapter.onDomLoad(function(){
- setTimeout(function(){
-
-
-
-
- addLog('Test 2',History.queues.length,History.busy.flag);
- History.setHash(History.getHashByState(States[1]));
-
- addLog('Test 3',History.queues.length,History.busy.flag);
- History.pushState(States[2].data, States[2].title, States[2].url);
-
- addLog('Test 3-2',History.queues.length,History.busy.flag);
- History.pushState(States[2].data, States[2].title, States[2].url);
-
- addLog('Test 3-3',History.queues.length,History.busy.flag);
- History.replaceState(States[2].data, States[2].title, States[2].url);
-
- addLog('Test 4',History.queues.length,History.busy.flag);
- History.replaceState(States[3].data, States[3].title, States[3].url);
-
- addLog('Test 5',History.queues.length,History.busy.flag);
- History.pushState(States[4].data, States[4].title, States[4].url);
-
-
-
-
- addLog('Test 6,7',History.queues.length,History.busy.flag);
- History.go(-2);
-
-
- addLog('Test 8',History.queues.length,History.busy.flag);
- History.back();
-
-
- addLog('Test 9,10',History.queues.length,History.busy.flag);
- History.go(2);
-
- addLog('Test 11',History.queues.length,History.busy.flag);
- History.forward();
-
- addLog('Test 12',History.queues.length,History.busy.flag);
- History.back();
-
- addLog('Test 13',History.queues.length,History.busy.flag);
- History.back();
-
-
-
- addLog('Test 13-2',History.queues.length,History.busy.flag);
- History.setHash('log');
-
- addLog('Test 13-3',History.queues.length,History.busy.flag);
- History.back();
-
- addLog('Test 14',History.queues.length,History.busy.flag);
- History.back();
-
-
-
-
- addLog('Test 15',History.queues.length,History.busy.flag);
- History.pushState(States[6].data, States[6].title, States[6].url);
-
- addLog('Test 16',History.queues.length,History.busy.flag);
- History.pushState(States[7].data, States[7].title, States[7].url);
-
- addLog('Test 17',History.queues.length,History.busy.flag);
- History.pushState(States[8].data, States[8].title, States[8].url);
-
-
- addLog('Test 18',History.queues.length,History.busy.flag);
- History.pushState(States[1].data, States[1].title, States[1].url);
-
-
-
- addLog('Test 19',History.queues.length,History.busy.flag);
- History.back();
-
- addLog('Test 20',History.queues.length,History.busy.flag);
- History.back();
-
- addLog('Test 21',History.queues.length,History.busy.flag);
- History.back();
-
- addLog('Test 22',History.queues.length,History.busy.flag);
- History.back();
- },1000);
- });
- })();
|