coreSpec.js 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298
  1. /**
  2. * ownCloud
  3. *
  4. * @author Vincent Petry
  5. * @copyright 2014 Vincent Petry <pvince81@owncloud.com>
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  9. * License as published by the Free Software Foundation; either
  10. * version 3 of the License, or any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public
  18. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  19. *
  20. */
  21. describe('Core base tests', function() {
  22. var debounceStub
  23. beforeEach(function() {
  24. debounceStub = sinon.stub(_, 'debounce').callsFake(function(callback) {
  25. return function() {
  26. // defer instead of debounce, to make it work with clock
  27. _.defer(callback);
  28. };
  29. });
  30. });
  31. afterEach(function() {
  32. // many tests call window.initCore so need to unregister global events
  33. // ideally in the future we'll need a window.unloadCore() function
  34. $(document).off('ajaxError.main');
  35. $(document).off('unload.main');
  36. $(document).off('beforeunload.main');
  37. OC._userIsNavigatingAway = false;
  38. OC._reloadCalled = false;
  39. debounceStub.restore();
  40. });
  41. describe('Base values', function() {
  42. it('Sets webroots', function() {
  43. expect(OC.getRootPath()).toBeDefined();
  44. expect(window._oc_appswebroots).toBeDefined();
  45. });
  46. });
  47. describe('filePath', function() {
  48. beforeEach(function() {
  49. window._oc_webroot = 'http://localhost';
  50. window._oc_appswebroots.files = OC.getRootPath() + '/apps3/files';
  51. });
  52. afterEach(function() {
  53. delete window._oc_appswebroots.files;
  54. });
  55. it('Uses a direct link for css and images,' , function() {
  56. expect(OC.filePath('core', 'css', 'style.css')).toEqual('http://localhost/core/css/style.css');
  57. expect(OC.filePath('files', 'css', 'style.css')).toEqual('http://localhost/apps3/files/css/style.css');
  58. expect(OC.filePath('core', 'img', 'image.png')).toEqual('http://localhost/core/img/image.png');
  59. expect(OC.filePath('files', 'img', 'image.png')).toEqual('http://localhost/apps3/files/img/image.png');
  60. });
  61. it('Routes PHP files via index.php,' , function() {
  62. expect(OC.filePath('core', 'ajax', 'test.php')).toEqual('http://localhost/index.php/core/ajax/test.php');
  63. expect(OC.filePath('files', 'ajax', 'test.php')).toEqual('http://localhost/index.php/apps/files/ajax/test.php');
  64. });
  65. });
  66. describe('Link functions', function() {
  67. var TESTAPP = 'testapp';
  68. var TESTAPP_ROOT = OC.getRootPath() + '/appsx/testapp';
  69. beforeEach(function() {
  70. window._oc_appswebroots[TESTAPP] = TESTAPP_ROOT;
  71. });
  72. afterEach(function() {
  73. // restore original array
  74. delete window._oc_appswebroots[TESTAPP];
  75. });
  76. it('Generates correct links for core apps', function() {
  77. expect(OC.linkTo('core', 'somefile.php')).toEqual(OC.getRootPath() + '/core/somefile.php');
  78. expect(OC.linkTo('admin', 'somefile.php')).toEqual(OC.getRootPath() + '/admin/somefile.php');
  79. });
  80. it('Generates correct links for regular apps', function() {
  81. expect(OC.linkTo(TESTAPP, 'somefile.php')).toEqual(OC.getRootPath() + '/index.php/apps/' + TESTAPP + '/somefile.php');
  82. });
  83. it('Generates correct remote links', function() {
  84. expect(OC.linkToRemote('webdav')).toEqual(window.location.protocol + '//' + window.location.host + OC.getRootPath() + '/remote.php/webdav');
  85. });
  86. describe('Images', function() {
  87. it('Generates image path with given extension', function() {
  88. expect(OC.imagePath('core', 'somefile.jpg')).toEqual(OC.getRootPath() + '/core/img/somefile.jpg');
  89. expect(OC.imagePath(TESTAPP, 'somefile.jpg')).toEqual(TESTAPP_ROOT + '/img/somefile.jpg');
  90. });
  91. it('Generates image path with svg extension', function() {
  92. expect(OC.imagePath('core', 'somefile')).toEqual(OC.getRootPath() + '/core/img/somefile.svg');
  93. expect(OC.imagePath(TESTAPP, 'somefile')).toEqual(TESTAPP_ROOT + '/img/somefile.svg');
  94. });
  95. });
  96. });
  97. describe('Query string building', function() {
  98. it('Returns empty string when empty params', function() {
  99. expect(OC.buildQueryString()).toEqual('');
  100. expect(OC.buildQueryString({})).toEqual('');
  101. });
  102. it('Encodes regular query strings', function() {
  103. expect(OC.buildQueryString({
  104. a: 'abc',
  105. b: 'def'
  106. })).toEqual('a=abc&b=def');
  107. });
  108. it('Encodes special characters', function() {
  109. expect(OC.buildQueryString({
  110. unicode: '汉字'
  111. })).toEqual('unicode=%E6%B1%89%E5%AD%97');
  112. expect(OC.buildQueryString({
  113. b: 'spaace value',
  114. 'space key': 'normalvalue',
  115. 'slash/this': 'amp&ersand'
  116. })).toEqual('b=spaace%20value&space%20key=normalvalue&slash%2Fthis=amp%26ersand');
  117. });
  118. it('Encodes data types and empty values', function() {
  119. expect(OC.buildQueryString({
  120. 'keywithemptystring': '',
  121. 'keywithnull': null,
  122. 'keywithundefined': null,
  123. something: 'else'
  124. })).toEqual('keywithemptystring=&keywithnull&keywithundefined&something=else');
  125. expect(OC.buildQueryString({
  126. 'booleanfalse': false,
  127. 'booleantrue': true
  128. })).toEqual('booleanfalse=false&booleantrue=true');
  129. expect(OC.buildQueryString({
  130. 'number': 123
  131. })).toEqual('number=123');
  132. });
  133. });
  134. describe('Session heartbeat', function() {
  135. var clock,
  136. oldConfig,
  137. counter;
  138. beforeEach(function() {
  139. clock = sinon.useFakeTimers();
  140. oldConfig = OC.config;
  141. counter = 0;
  142. fakeServer.autoRespond = true;
  143. fakeServer.autoRespondAfter = 0;
  144. fakeServer.respondWith(/\/csrftoken/, function(xhr) {
  145. counter++;
  146. xhr.respond(200, {'Content-Type': 'application/json'}, '{"token": "pgBEsb3MzTb1ZPd2mfDZbQ6/0j3OrXHMEZrghHcOkg8=:3khw5PSa+wKQVo4f26exFD3nplud9ECjJ8/Y5zk5/k4="}');
  147. });
  148. $(document).off('ajaxComplete'); // ignore previously registered heartbeats
  149. });
  150. afterEach(function() {
  151. clock.restore();
  152. /* jshint camelcase: false */
  153. OC.config = oldConfig;
  154. $(document).off('ajaxError');
  155. $(document).off('ajaxComplete');
  156. });
  157. it('sends heartbeat half the session lifetime when heartbeat enabled', function() {
  158. /* jshint camelcase: false */
  159. OC.config = {
  160. session_keepalive: true,
  161. session_lifetime: 300
  162. };
  163. window.initCore();
  164. expect(counter).toEqual(0);
  165. // less than half, still nothing
  166. clock.tick(100 * 1000);
  167. expect(counter).toEqual(0);
  168. // reach past half (160), one call
  169. clock.tick(55 * 1000);
  170. expect(counter).toEqual(1);
  171. // almost there to the next, still one
  172. clock.tick(140 * 1000);
  173. expect(counter).toEqual(1);
  174. // past it, second call
  175. clock.tick(20 * 1000);
  176. expect(counter).toEqual(2);
  177. });
  178. it('does not send heartbeat when heartbeat disabled', function() {
  179. /* jshint camelcase: false */
  180. OC.config = {
  181. session_keepalive: false,
  182. session_lifetime: 300
  183. };
  184. window.initCore();
  185. expect(counter).toEqual(0);
  186. clock.tick(1000000);
  187. // still nothing
  188. expect(counter).toEqual(0);
  189. });
  190. it('limits the heartbeat between one minute and one day', function() {
  191. /* jshint camelcase: false */
  192. var setIntervalStub = sinon.stub(window, 'setInterval');
  193. OC.config = {
  194. session_keepalive: true,
  195. session_lifetime: 5
  196. };
  197. window.initCore();
  198. expect(setIntervalStub.getCall(0).args[1]).toEqual(60 * 1000);
  199. setIntervalStub.reset();
  200. OC.config = {
  201. session_keepalive: true,
  202. session_lifetime: 48 * 3600
  203. };
  204. window.initCore();
  205. expect(setIntervalStub.getCall(0).args[1]).toEqual(24 * 3600 * 1000);
  206. setIntervalStub.restore();
  207. });
  208. });
  209. describe('Parse query string', function() {
  210. it('Parses query string from full URL', function() {
  211. var query = OC.parseQueryString('http://localhost/stuff.php?q=a&b=x');
  212. expect(query).toEqual({q: 'a', b: 'x'});
  213. });
  214. it('Parses query string from query part alone', function() {
  215. var query = OC.parseQueryString('q=a&b=x');
  216. expect(query).toEqual({q: 'a', b: 'x'});
  217. });
  218. it('Returns null hash when empty query', function() {
  219. var query = OC.parseQueryString('');
  220. expect(query).toEqual(null);
  221. });
  222. it('Returns empty hash when empty query with question mark', function() {
  223. var query = OC.parseQueryString('?');
  224. expect(query).toEqual({});
  225. });
  226. it('Decodes regular query strings', function() {
  227. var query = OC.parseQueryString('a=abc&b=def');
  228. expect(query).toEqual({
  229. a: 'abc',
  230. b: 'def'
  231. });
  232. });
  233. it('Ignores empty parts', function() {
  234. var query = OC.parseQueryString('&q=a&&b=x&');
  235. expect(query).toEqual({q: 'a', b: 'x'});
  236. });
  237. it('Ignores lone equal signs', function() {
  238. var query = OC.parseQueryString('&q=a&=&b=x&');
  239. expect(query).toEqual({q: 'a', b: 'x'});
  240. });
  241. it('Includes extra equal signs in value', function() {
  242. var query = OC.parseQueryString('u=a=x&q=a=b');
  243. expect(query).toEqual({u: 'a=x', q: 'a=b'});
  244. });
  245. it('Decodes plus as space', function() {
  246. var query = OC.parseQueryString('space+key=space+value');
  247. expect(query).toEqual({'space key': 'space value'});
  248. });
  249. it('Decodes special characters', function() {
  250. var query = OC.parseQueryString('unicode=%E6%B1%89%E5%AD%97');
  251. expect(query).toEqual({unicode: '汉字'});
  252. query = OC.parseQueryString('b=spaace%20value&space%20key=normalvalue&slash%2Fthis=amp%26ersand');
  253. expect(query).toEqual({
  254. b: 'spaace value',
  255. 'space key': 'normalvalue',
  256. 'slash/this': 'amp&ersand'
  257. });
  258. });
  259. it('Decodes empty values', function() {
  260. var query = OC.parseQueryString('keywithemptystring=&keywithnostring');
  261. expect(query).toEqual({
  262. 'keywithemptystring': '',
  263. 'keywithnostring': null
  264. });
  265. });
  266. it('Does not interpret data types', function() {
  267. var query = OC.parseQueryString('booleanfalse=false&booleantrue=true&number=123');
  268. expect(query).toEqual({
  269. 'booleanfalse': 'false',
  270. 'booleantrue': 'true',
  271. 'number': '123'
  272. });
  273. });
  274. });
  275. describe('Generate Url', function() {
  276. it('returns absolute urls', function() {
  277. expect(OC.generateUrl('csrftoken')).toEqual(OC.getRootPath() + '/index.php/csrftoken');
  278. expect(OC.generateUrl('/csrftoken')).toEqual(OC.getRootPath() + '/index.php/csrftoken');
  279. });
  280. it('substitutes parameters which are escaped by default', function() {
  281. expect(OC.generateUrl('apps/files/download/{file}', {file: '<">ImAnUnescapedString/!'})).toEqual(OC.getRootPath() + '/index.php/apps/files/download/%3C%22%3EImAnUnescapedString%2F!');
  282. });
  283. it('substitutes parameters which can also be unescaped via option flag', function() {
  284. expect(OC.generateUrl('apps/files/download/{file}', {file: 'subfolder/Welcome.txt'}, {escape: false})).toEqual(OC.getRootPath() + '/index.php/apps/files/download/subfolder/Welcome.txt');
  285. });
  286. it('substitutes multiple parameters which are escaped by default', function() {
  287. expect(OC.generateUrl('apps/files/download/{file}/{id}', {file: '<">ImAnUnescapedString/!', id: 5})).toEqual(OC.getRootPath() + '/index.php/apps/files/download/%3C%22%3EImAnUnescapedString%2F!/5');
  288. });
  289. it('substitutes multiple parameters which can also be unescaped via option flag', function() {
  290. expect(OC.generateUrl('apps/files/download/{file}/{id}', {file: 'subfolder/Welcome.txt', id: 5}, {escape: false})).toEqual(OC.getRootPath() + '/index.php/apps/files/download/subfolder/Welcome.txt/5');
  291. });
  292. it('doesnt error out with no params provided', function () {
  293. expect(OC.generateUrl('apps/files/download{file}')).toEqual(OC.getRootPath() + '/index.php/apps/files/download%7Bfile%7D');
  294. });
  295. });
  296. describe('Util', function() {
  297. describe('computerFileSize', function() {
  298. it('correctly parses file sizes from a human readable formated string', function() {
  299. var data = [
  300. ['125', 125],
  301. ['125.25', 125],
  302. ['125.25B', 125],
  303. ['125.25 B', 125],
  304. ['0 B', 0],
  305. ['99999999999999999999999999999999999999999999 B', 99999999999999999999999999999999999999999999],
  306. ['0 MB', 0],
  307. ['0 kB', 0],
  308. ['0kB', 0],
  309. ['125 B', 125],
  310. ['125b', 125],
  311. ['125 KB', 128000],
  312. ['125kb', 128000],
  313. ['122.1 MB', 128031130],
  314. ['122.1mb', 128031130],
  315. ['119.2 GB', 127990025421],
  316. ['119.2gb', 127990025421],
  317. ['116.4 TB', 127983153473126],
  318. ['116.4tb', 127983153473126],
  319. ['8776656778888777655.4tb', 9.650036181387265e+30],
  320. [1234, null],
  321. [-1234, null],
  322. ['-1234 B', null],
  323. ['B', null],
  324. ['40/0', null],
  325. ['40,30 kb', null],
  326. [' 122.1 MB ', 128031130],
  327. ['122.1 MB ', 128031130],
  328. [' 122.1 MB ', 128031130],
  329. [' 122.1 MB ', 128031130],
  330. ['122.1 MB ', 128031130],
  331. [' 125', 125],
  332. [' 125 ', 125],
  333. ];
  334. for (var i = 0; i < data.length; i++) {
  335. expect(OC.Util.computerFileSize(data[i][0])).toEqual(data[i][1]);
  336. }
  337. });
  338. it('returns null if the parameter is not a string', function() {
  339. expect(OC.Util.computerFileSize(NaN)).toEqual(null);
  340. expect(OC.Util.computerFileSize(125)).toEqual(null);
  341. });
  342. it('returns null if the string is unparsable', function() {
  343. expect(OC.Util.computerFileSize('')).toEqual(null);
  344. expect(OC.Util.computerFileSize('foobar')).toEqual(null);
  345. });
  346. });
  347. describe('stripTime', function() {
  348. it('strips time from dates', function() {
  349. expect(OC.Util.stripTime(new Date(2014, 2, 24, 15, 4, 45, 24)))
  350. .toEqual(new Date(2014, 2, 24, 0, 0, 0, 0));
  351. });
  352. });
  353. });
  354. describe('naturalSortCompare', function() {
  355. // cit() will skip tests if running on PhantomJS because it has issues with
  356. // localeCompare(). See https://github.com/ariya/phantomjs/issues/11063
  357. //
  358. // Please make sure to run these tests in Chrome/Firefox manually
  359. // to make sure they run.
  360. var cit = window.isPhantom?xit:it;
  361. // must provide the same results as \OC_Util::naturalSortCompare
  362. it('sorts alphabetically', function() {
  363. var a = [
  364. 'def',
  365. 'xyz',
  366. 'abc'
  367. ];
  368. a.sort(OC.Util.naturalSortCompare);
  369. expect(a).toEqual([
  370. 'abc',
  371. 'def',
  372. 'xyz'
  373. ]);
  374. });
  375. cit('sorts with different casing', function() {
  376. var a = [
  377. 'aaa',
  378. 'bbb',
  379. 'BBB',
  380. 'AAA'
  381. ];
  382. a.sort(OC.Util.naturalSortCompare);
  383. expect(a).toEqual([
  384. 'aaa',
  385. 'AAA',
  386. 'bbb',
  387. 'BBB'
  388. ]);
  389. });
  390. it('sorts with numbers', function() {
  391. var a = [
  392. '124.txt',
  393. 'abc1',
  394. '123.txt',
  395. 'abc',
  396. 'abc2',
  397. 'def (2).txt',
  398. 'ghi 10.txt',
  399. 'abc12',
  400. 'def.txt',
  401. 'def (1).txt',
  402. 'ghi 2.txt',
  403. 'def (10).txt',
  404. 'abc10',
  405. 'def (12).txt',
  406. 'z',
  407. 'ghi.txt',
  408. 'za',
  409. 'ghi 1.txt',
  410. 'ghi 12.txt',
  411. 'zz',
  412. '15.txt',
  413. '15b.txt'
  414. ];
  415. a.sort(OC.Util.naturalSortCompare);
  416. expect(a).toEqual([
  417. '15.txt',
  418. '15b.txt',
  419. '123.txt',
  420. '124.txt',
  421. 'abc',
  422. 'abc1',
  423. 'abc2',
  424. 'abc10',
  425. 'abc12',
  426. 'def.txt',
  427. 'def (1).txt',
  428. 'def (2).txt',
  429. 'def (10).txt',
  430. 'def (12).txt',
  431. 'ghi.txt',
  432. 'ghi 1.txt',
  433. 'ghi 2.txt',
  434. 'ghi 10.txt',
  435. 'ghi 12.txt',
  436. 'z',
  437. 'za',
  438. 'zz'
  439. ]);
  440. });
  441. it('sorts with chinese characters', function() {
  442. var a = [
  443. '十.txt',
  444. '一.txt',
  445. '二.txt',
  446. '十 2.txt',
  447. '三.txt',
  448. '四.txt',
  449. 'abc.txt',
  450. '五.txt',
  451. '七.txt',
  452. '八.txt',
  453. '九.txt',
  454. '六.txt',
  455. '十一.txt',
  456. '波.txt',
  457. '破.txt',
  458. '莫.txt',
  459. '啊.txt',
  460. '123.txt'
  461. ];
  462. a.sort(OC.Util.naturalSortCompare);
  463. expect(a).toEqual([
  464. '123.txt',
  465. 'abc.txt',
  466. '一.txt',
  467. '七.txt',
  468. '三.txt',
  469. '九.txt',
  470. '二.txt',
  471. '五.txt',
  472. '八.txt',
  473. '六.txt',
  474. '十.txt',
  475. '十 2.txt',
  476. '十一.txt',
  477. '啊.txt',
  478. '四.txt',
  479. '波.txt',
  480. '破.txt',
  481. '莫.txt'
  482. ]);
  483. });
  484. cit('sorts with umlauts', function() {
  485. var a = [
  486. 'öh.txt',
  487. 'Äh.txt',
  488. 'oh.txt',
  489. 'Üh 2.txt',
  490. 'Üh.txt',
  491. 'ah.txt',
  492. 'Öh.txt',
  493. 'uh.txt',
  494. 'üh.txt',
  495. 'äh.txt'
  496. ];
  497. a.sort(OC.Util.naturalSortCompare);
  498. expect(a).toEqual([
  499. 'ah.txt',
  500. 'äh.txt',
  501. 'Äh.txt',
  502. 'oh.txt',
  503. 'öh.txt',
  504. 'Öh.txt',
  505. 'uh.txt',
  506. 'üh.txt',
  507. 'Üh.txt',
  508. 'Üh 2.txt'
  509. ]);
  510. });
  511. });
  512. describe('Plugins', function() {
  513. var plugin;
  514. beforeEach(function() {
  515. plugin = {
  516. name: 'Some name',
  517. attach: function(obj) {
  518. obj.attached = true;
  519. },
  520. detach: function(obj) {
  521. obj.attached = false;
  522. }
  523. };
  524. OC.Plugins.register('OC.Test.SomeName', plugin);
  525. });
  526. it('attach plugin to object', function() {
  527. var obj = {something: true};
  528. OC.Plugins.attach('OC.Test.SomeName', obj);
  529. expect(obj.attached).toEqual(true);
  530. OC.Plugins.detach('OC.Test.SomeName', obj);
  531. expect(obj.attached).toEqual(false);
  532. });
  533. it('only call handler for target name', function() {
  534. var obj = {something: true};
  535. OC.Plugins.attach('OC.Test.SomeOtherName', obj);
  536. expect(obj.attached).not.toBeDefined();
  537. OC.Plugins.detach('OC.Test.SomeOtherName', obj);
  538. expect(obj.attached).not.toBeDefined();
  539. });
  540. });
  541. describe('Notifications', function() {
  542. var showHtmlSpy;
  543. var clock;
  544. /**
  545. * Returns the HTML or plain text of the given notification row.
  546. *
  547. * This is needed to ignore the close button that is added to the
  548. * notification row after the text.
  549. */
  550. var getNotificationText = function($node) {
  551. return $node.contents()[0].outerHTML ||
  552. $node.contents()[0].nodeValue;
  553. }
  554. beforeEach(function() {
  555. clock = sinon.useFakeTimers();
  556. });
  557. afterEach(function() {
  558. // jump past animations
  559. clock.tick(10000);
  560. clock.restore();
  561. $('body .toastify').remove();
  562. });
  563. describe('showTemporary', function() {
  564. it('shows a plain text notification with default timeout', function() {
  565. OC.Notification.showTemporary('My notification test');
  566. var $row = $('body .toastify');
  567. expect($row.length).toEqual(1);
  568. expect(getNotificationText($row)).toEqual('My notification test');
  569. });
  570. it('shows a HTML notification with default timeout', function() {
  571. OC.Notification.showTemporary('<a>My notification test</a>', { isHTML: true });
  572. var $row = $('body .toastify');
  573. expect($row.length).toEqual(1);
  574. expect(getNotificationText($row)).toEqual('<a>My notification test</a>');
  575. });
  576. it('hides itself after 7 seconds', function() {
  577. OC.Notification.showTemporary('');
  578. var $row = $('body .toastify');
  579. expect($row.length).toEqual(1);
  580. // travel in time +7000 milliseconds
  581. clock.tick(7500);
  582. $row = $('body .toastify');
  583. expect($row.length).toEqual(0);
  584. });
  585. it('hides itself after a given time', function() {
  586. OC.Notification.showTemporary('', {timeout: 10000});
  587. var $row = $('body .toastify');
  588. expect($row.length).toEqual(1);
  589. // travel in time +7000 milliseconds
  590. clock.tick(7500);
  591. $row = $('body .toastify');
  592. expect($row.length).toEqual(1);
  593. // travel in time another 4000 milliseconds
  594. clock.tick(4000);
  595. $row = $('body .toastify');
  596. expect($row.length).toEqual(0);
  597. });
  598. });
  599. describe('show', function() {
  600. it('hides itself after a given time', function() {
  601. OC.Notification.show('', {timeout: 10000});
  602. var $row = $('body .toastify');
  603. expect($row.length).toEqual(1);
  604. clock.tick(11500);
  605. $row = $('body .toastify');
  606. expect($row.length).toEqual(0);
  607. });
  608. it('does not hide itself if no timeout given to show', function() {
  609. OC.Notification.show('');
  610. var $row = $('body .toastify');
  611. expect($row.length).toEqual(1);
  612. // travel in time +1000 seconds
  613. clock.tick(1000000);
  614. $row = $('body .toastify');
  615. expect($row.length).toEqual(1);
  616. });
  617. });
  618. describe('showHtml', function() {
  619. it('hides itself after a given time', function() {
  620. OC.Notification.showHtml('<p></p>', {timeout: 10000});
  621. var $row = $('body .toastify');
  622. expect($row.length).toEqual(1);
  623. clock.tick(11500);
  624. $row = $('body .toastify');
  625. expect($row.length).toEqual(0);
  626. });
  627. it('does not hide itself if no timeout given to show', function() {
  628. OC.Notification.showHtml('<p></p>');
  629. var $row = $('body .toastify');
  630. expect($row.length).toEqual(1);
  631. // travel in time +1000 seconds
  632. clock.tick(1000000);
  633. $row = $('body .toastify');
  634. expect($row.length).toEqual(1);
  635. });
  636. });
  637. describe('hide', function() {
  638. it('hides a temporary notification before its timeout expires', function() {
  639. var hideCallback = sinon.spy();
  640. var notification = OC.Notification.showTemporary('');
  641. var $row = $('body .toastify');
  642. expect($row.length).toEqual(1);
  643. OC.Notification.hide(notification, hideCallback);
  644. // Give time to the hide animation to finish
  645. clock.tick(1000);
  646. $row = $('body .toastify');
  647. expect($row.length).toEqual(0);
  648. expect(hideCallback.calledOnce).toEqual(true);
  649. });
  650. it('hides a notification before its timeout expires', function() {
  651. var hideCallback = sinon.spy();
  652. var notification = OC.Notification.show('', {timeout: 10000});
  653. var $row = $('body .toastify');
  654. expect($row.length).toEqual(1);
  655. OC.Notification.hide(notification, hideCallback);
  656. // Give time to the hide animation to finish
  657. clock.tick(1000);
  658. $row = $('body .toastify');
  659. expect($row.length).toEqual(0);
  660. expect(hideCallback.calledOnce).toEqual(true);
  661. });
  662. it('hides a notification without timeout', function() {
  663. var hideCallback = sinon.spy();
  664. var notification = OC.Notification.show('');
  665. var $row = $('body .toastify');
  666. expect($row.length).toEqual(1);
  667. OC.Notification.hide(notification, hideCallback);
  668. // Give time to the hide animation to finish
  669. clock.tick(1000);
  670. $row = $('body .toastify');
  671. expect($row.length).toEqual(0);
  672. expect(hideCallback.calledOnce).toEqual(true);
  673. });
  674. });
  675. it('cumulates several notifications', function() {
  676. var $row1 = OC.Notification.showTemporary('One');
  677. var $row2 = OC.Notification.showTemporary('Two', {timeout: 2000});
  678. var $row3 = OC.Notification.showTemporary('Three');
  679. var $el = $('body');
  680. var $rows = $el.find('.toastify');
  681. expect($rows.length).toEqual(3);
  682. expect($rows.eq(0).is($row3)).toEqual(true);
  683. expect($rows.eq(1).is($row2)).toEqual(true);
  684. expect($rows.eq(2).is($row1)).toEqual(true);
  685. clock.tick(3000);
  686. $rows = $el.find('.toastify');
  687. expect($rows.length).toEqual(2);
  688. expect($rows.eq(0).is($row3)).toEqual(true);
  689. expect($rows.eq(1).is($row1)).toEqual(true);
  690. });
  691. it('hides the given notification when calling hide with argument', function() {
  692. var $row1 = OC.Notification.show('One');
  693. var $row2 = OC.Notification.show('Two');
  694. var $el = $('body');
  695. var $rows = $el.find('.toastify');
  696. expect($rows.length).toEqual(2);
  697. OC.Notification.hide($row2);
  698. clock.tick(3000);
  699. $rows = $el.find('.toastify');
  700. expect($rows.length).toEqual(1);
  701. expect($rows.eq(0).is($row1)).toEqual(true);
  702. });
  703. });
  704. describe('global ajax errors', function() {
  705. var reloadStub, ajaxErrorStub, clock;
  706. var notificationStub;
  707. var waitTimeMs = 6500;
  708. var oldCurrentUser;
  709. beforeEach(function() {
  710. oldCurrentUser = OC.currentUser;
  711. OC.currentUser = 'dummy';
  712. clock = sinon.useFakeTimers();
  713. reloadStub = sinon.stub(OC, 'reload');
  714. notificationStub = sinon.stub(OC.Notification, 'show');
  715. // unstub the error processing method
  716. ajaxErrorStub = OC._processAjaxError;
  717. ajaxErrorStub.restore();
  718. window.initCore();
  719. });
  720. afterEach(function() {
  721. OC.currentUser = oldCurrentUser;
  722. reloadStub.restore();
  723. notificationStub.restore();
  724. clock.restore();
  725. });
  726. it('reloads current page in case of auth error', function() {
  727. var dataProvider = [
  728. [200, false],
  729. [400, false],
  730. [0, false],
  731. [401, true],
  732. [302, true],
  733. [303, true],
  734. [307, true]
  735. ];
  736. for (var i = 0; i < dataProvider.length; i++) {
  737. var xhr = { status: dataProvider[i][0] };
  738. var expectedCall = dataProvider[i][1];
  739. reloadStub.reset();
  740. OC._reloadCalled = false;
  741. $(document).trigger(new $.Event('ajaxError'), xhr);
  742. // trigger timers
  743. clock.tick(waitTimeMs);
  744. if (expectedCall) {
  745. expect(reloadStub.calledOnce).toEqual(true);
  746. } else {
  747. expect(reloadStub.notCalled).toEqual(true);
  748. }
  749. }
  750. });
  751. it('reload only called once in case of auth error', function() {
  752. var xhr = { status: 401 };
  753. $(document).trigger(new $.Event('ajaxError'), xhr);
  754. $(document).trigger(new $.Event('ajaxError'), xhr);
  755. // trigger timers
  756. clock.tick(waitTimeMs);
  757. expect(reloadStub.calledOnce).toEqual(true);
  758. });
  759. it('does not reload the page if the user was navigating away', function() {
  760. var xhr = { status: 0 };
  761. OC._userIsNavigatingAway = true;
  762. clock.tick(100);
  763. $(document).trigger(new $.Event('ajaxError'), xhr);
  764. clock.tick(waitTimeMs);
  765. expect(reloadStub.notCalled).toEqual(true);
  766. });
  767. it('displays notification', function() {
  768. var xhr = { status: 401 };
  769. notificationUpdateStub = sinon.stub(OC.Notification, 'showUpdate');
  770. $(document).trigger(new $.Event('ajaxError'), xhr);
  771. clock.tick(waitTimeMs);
  772. expect(notificationUpdateStub.notCalled).toEqual(false);
  773. });
  774. it('shows a temporary notification if the connection is lost', function() {
  775. var xhr = { status: 0 };
  776. spyOn(OC, '_ajaxConnectionLostHandler');
  777. $(document).trigger(new $.Event('ajaxError'), xhr);
  778. clock.tick(101);
  779. expect(OC._ajaxConnectionLostHandler.calls.count()).toBe(1);
  780. });
  781. });
  782. describe('Snapper', function() {
  783. var snapConstructorStub;
  784. var snapperStub;
  785. var clock;
  786. beforeEach(function() {
  787. snapConstructorStub = sinon.stub(window, 'Snap');
  788. snapperStub = {};
  789. snapperStub.enable = sinon.stub();
  790. snapperStub.disable = sinon.stub();
  791. snapperStub.close = sinon.stub();
  792. snapperStub.on = sinon.stub();
  793. snapperStub.state = sinon.stub().returns({
  794. state: sinon.stub()
  795. });
  796. snapConstructorStub.returns(snapperStub);
  797. clock = sinon.useFakeTimers();
  798. // _.now could have been set to Date.now before Sinon replaced it
  799. // with a fake version, so _.now must be stubbed to ensure that the
  800. // fake Date.now will be called instead of the original one.
  801. _.now = sinon.stub(_, 'now').callsFake(function() {
  802. return new Date().getTime();
  803. });
  804. $('#testArea').append('<div id="app-navigation">The navigation bar</div><div id="app-content">Content</div>');
  805. });
  806. afterEach(function() {
  807. snapConstructorStub.restore();
  808. clock.restore();
  809. _.now.restore();
  810. // Remove the event handler for the resize event added to the window
  811. // due to calling window.initCore() when there is an #app-navigation
  812. // element.
  813. $(window).off('resize');
  814. viewport.reset();
  815. });
  816. it('is enabled on a narrow screen', function() {
  817. viewport.set(480);
  818. window.initCore();
  819. expect(snapConstructorStub.calledOnce).toBe(true);
  820. expect(snapperStub.enable.calledOnce).toBe(true);
  821. expect(snapperStub.disable.called).toBe(false);
  822. });
  823. it('is disabled when disallowing the gesture on a narrow screen', function() {
  824. viewport.set(480);
  825. window.initCore();
  826. expect(snapperStub.enable.calledOnce).toBe(true);
  827. expect(snapperStub.disable.called).toBe(false);
  828. expect(snapperStub.close.called).toBe(false);
  829. OC.disallowNavigationBarSlideGesture();
  830. expect(snapperStub.enable.calledOnce).toBe(true);
  831. expect(snapperStub.disable.calledOnce).toBe(true);
  832. expect(snapperStub.disable.alwaysCalledWithExactly(true)).toBe(true);
  833. expect(snapperStub.close.called).toBe(false);
  834. });
  835. it('is not disabled again when disallowing the gesture twice on a narrow screen', function() {
  836. viewport.set(480);
  837. window.initCore();
  838. expect(snapperStub.enable.calledOnce).toBe(true);
  839. expect(snapperStub.disable.called).toBe(false);
  840. expect(snapperStub.close.called).toBe(false);
  841. OC.disallowNavigationBarSlideGesture();
  842. expect(snapperStub.enable.calledOnce).toBe(true);
  843. expect(snapperStub.disable.calledOnce).toBe(true);
  844. expect(snapperStub.disable.alwaysCalledWithExactly(true)).toBe(true);
  845. expect(snapperStub.close.called).toBe(false);
  846. OC.disallowNavigationBarSlideGesture();
  847. expect(snapperStub.enable.calledOnce).toBe(true);
  848. expect(snapperStub.disable.calledOnce).toBe(true);
  849. expect(snapperStub.close.called).toBe(false);
  850. });
  851. it('is enabled when allowing the gesture after disallowing it on a narrow screen', function() {
  852. viewport.set(480);
  853. window.initCore();
  854. expect(snapperStub.enable.calledOnce).toBe(true);
  855. expect(snapperStub.disable.called).toBe(false);
  856. expect(snapperStub.close.called).toBe(false);
  857. OC.disallowNavigationBarSlideGesture();
  858. expect(snapperStub.enable.calledOnce).toBe(true);
  859. expect(snapperStub.disable.calledOnce).toBe(true);
  860. expect(snapperStub.disable.alwaysCalledWithExactly(true)).toBe(true);
  861. expect(snapperStub.close.called).toBe(false);
  862. OC.allowNavigationBarSlideGesture();
  863. expect(snapperStub.enable.calledTwice).toBe(true);
  864. expect(snapperStub.disable.calledOnce).toBe(true);
  865. expect(snapperStub.close.called).toBe(false);
  866. });
  867. it('is not enabled again when allowing the gesture twice after disallowing it on a narrow screen', function() {
  868. viewport.set(480);
  869. window.initCore();
  870. expect(snapperStub.enable.calledOnce).toBe(true);
  871. expect(snapperStub.disable.called).toBe(false);
  872. expect(snapperStub.close.called).toBe(false);
  873. OC.disallowNavigationBarSlideGesture();
  874. expect(snapperStub.enable.calledOnce).toBe(true);
  875. expect(snapperStub.disable.calledOnce).toBe(true);
  876. expect(snapperStub.disable.alwaysCalledWithExactly(true)).toBe(true);
  877. expect(snapperStub.close.called).toBe(false);
  878. OC.allowNavigationBarSlideGesture();
  879. expect(snapperStub.enable.calledTwice).toBe(true);
  880. expect(snapperStub.disable.calledOnce).toBe(true);
  881. expect(snapperStub.close.called).toBe(false);
  882. OC.allowNavigationBarSlideGesture();
  883. expect(snapperStub.enable.calledTwice).toBe(true);
  884. expect(snapperStub.disable.calledOnce).toBe(true);
  885. expect(snapperStub.close.called).toBe(false);
  886. });
  887. it('is disabled on a wide screen', function() {
  888. viewport.set(1280);
  889. window.initCore();
  890. expect(snapConstructorStub.calledOnce).toBe(true);
  891. expect(snapperStub.enable.called).toBe(false);
  892. expect(snapperStub.disable.calledOnce).toBe(true);
  893. });
  894. it('is not disabled again when disallowing the gesture on a wide screen', function() {
  895. viewport.set(1280);
  896. window.initCore();
  897. expect(snapperStub.enable.called).toBe(false);
  898. expect(snapperStub.disable.calledOnce).toBe(true);
  899. expect(snapperStub.close.calledOnce).toBe(true);
  900. OC.disallowNavigationBarSlideGesture();
  901. expect(snapperStub.enable.called).toBe(false);
  902. expect(snapperStub.disable.calledOnce).toBe(true);
  903. expect(snapperStub.close.calledOnce).toBe(true);
  904. });
  905. it('is not enabled when allowing the gesture after disallowing it on a wide screen', function() {
  906. viewport.set(1280);
  907. window.initCore();
  908. expect(snapperStub.enable.called).toBe(false);
  909. expect(snapperStub.disable.calledOnce).toBe(true);
  910. expect(snapperStub.close.calledOnce).toBe(true);
  911. OC.disallowNavigationBarSlideGesture();
  912. expect(snapperStub.enable.called).toBe(false);
  913. expect(snapperStub.disable.calledOnce).toBe(true);
  914. expect(snapperStub.close.calledOnce).toBe(true);
  915. OC.allowNavigationBarSlideGesture();
  916. expect(snapperStub.enable.called).toBe(false);
  917. expect(snapperStub.disable.calledOnce).toBe(true);
  918. expect(snapperStub.close.calledOnce).toBe(true);
  919. });
  920. it('is enabled when resizing to a narrow screen', function() {
  921. viewport.set(1280);
  922. window.initCore();
  923. expect(snapperStub.enable.called).toBe(false);
  924. expect(snapperStub.disable.calledOnce).toBe(true);
  925. viewport.set(480);
  926. // Setting the viewport width does not automatically trigger a
  927. // resize.
  928. $(window).resize();
  929. // The resize handler is debounced to be executed a few milliseconds
  930. // after the resize event.
  931. clock.tick(1000);
  932. expect(snapperStub.enable.calledOnce).toBe(true);
  933. expect(snapperStub.disable.calledOnce).toBe(true);
  934. });
  935. it('is not enabled when resizing to a narrow screen after disallowing the gesture', function() {
  936. viewport.set(1280);
  937. window.initCore();
  938. expect(snapperStub.enable.called).toBe(false);
  939. expect(snapperStub.disable.calledOnce).toBe(true);
  940. OC.disallowNavigationBarSlideGesture();
  941. expect(snapperStub.enable.called).toBe(false);
  942. expect(snapperStub.disable.calledOnce).toBe(true);
  943. viewport.set(480);
  944. // Setting the viewport width does not automatically trigger a
  945. // resize.
  946. $(window).resize();
  947. // The resize handler is debounced to be executed a few milliseconds
  948. // after the resize event.
  949. clock.tick(1000);
  950. expect(snapperStub.enable.called).toBe(false);
  951. expect(snapperStub.disable.calledOnce).toBe(true);
  952. });
  953. it('is enabled when resizing to a narrow screen after disallowing the gesture and allowing it', function() {
  954. viewport.set(1280);
  955. window.initCore();
  956. expect(snapperStub.enable.called).toBe(false);
  957. expect(snapperStub.disable.calledOnce).toBe(true);
  958. OC.disallowNavigationBarSlideGesture();
  959. expect(snapperStub.enable.called).toBe(false);
  960. expect(snapperStub.disable.calledOnce).toBe(true);
  961. OC.allowNavigationBarSlideGesture();
  962. expect(snapperStub.enable.called).toBe(false);
  963. expect(snapperStub.disable.calledOnce).toBe(true);
  964. viewport.set(480);
  965. // Setting the viewport width does not automatically trigger a
  966. // resize.
  967. $(window).resize();
  968. // The resize handler is debounced to be executed a few milliseconds
  969. // after the resize event.
  970. clock.tick(1000);
  971. expect(snapperStub.enable.calledOnce).toBe(true);
  972. expect(snapperStub.disable.calledOnce).toBe(true);
  973. });
  974. it('is enabled when allowing the gesture after disallowing it and resizing to a narrow screen', function() {
  975. viewport.set(1280);
  976. window.initCore();
  977. expect(snapperStub.enable.called).toBe(false);
  978. expect(snapperStub.disable.calledOnce).toBe(true);
  979. OC.disallowNavigationBarSlideGesture();
  980. expect(snapperStub.enable.called).toBe(false);
  981. expect(snapperStub.disable.calledOnce).toBe(true);
  982. viewport.set(480);
  983. // Setting the viewport width does not automatically trigger a
  984. // resize.
  985. $(window).resize();
  986. // The resize handler is debounced to be executed a few milliseconds
  987. // after the resize event.
  988. clock.tick(1000);
  989. expect(snapperStub.enable.called).toBe(false);
  990. expect(snapperStub.disable.calledOnce).toBe(true);
  991. OC.allowNavigationBarSlideGesture();
  992. expect(snapperStub.enable.calledOnce).toBe(true);
  993. expect(snapperStub.disable.calledOnce).toBe(true);
  994. });
  995. it('is disabled when disallowing the gesture after disallowing it, resizing to a narrow screen and allowing it', function() {
  996. viewport.set(1280);
  997. window.initCore();
  998. expect(snapperStub.enable.called).toBe(false);
  999. expect(snapperStub.disable.calledOnce).toBe(true);
  1000. OC.disallowNavigationBarSlideGesture();
  1001. expect(snapperStub.enable.called).toBe(false);
  1002. expect(snapperStub.disable.calledOnce).toBe(true);
  1003. viewport.set(480);
  1004. // Setting the viewport width does not automatically trigger a
  1005. // resize.
  1006. $(window).resize();
  1007. // The resize handler is debounced to be executed a few milliseconds
  1008. // after the resize event.
  1009. clock.tick(1000);
  1010. expect(snapperStub.enable.called).toBe(false);
  1011. expect(snapperStub.disable.calledOnce).toBe(true);
  1012. OC.allowNavigationBarSlideGesture();
  1013. expect(snapperStub.enable.calledOnce).toBe(true);
  1014. expect(snapperStub.disable.calledOnce).toBe(true);
  1015. OC.disallowNavigationBarSlideGesture();
  1016. expect(snapperStub.enable.calledOnce).toBe(true);
  1017. expect(snapperStub.disable.calledTwice).toBe(true);
  1018. expect(snapperStub.disable.getCall(1).calledWithExactly(true)).toBe(true);
  1019. });
  1020. it('is disabled when resizing to a wide screen', function() {
  1021. viewport.set(480);
  1022. window.initCore();
  1023. expect(snapperStub.enable.calledOnce).toBe(true);
  1024. expect(snapperStub.disable.called).toBe(false);
  1025. expect(snapperStub.close.called).toBe(false);
  1026. viewport.set(1280);
  1027. // Setting the viewport width does not automatically trigger a
  1028. // resize.
  1029. $(window).resize();
  1030. // The resize handler is debounced to be executed a few milliseconds
  1031. // after the resize event.
  1032. clock.tick(1000);
  1033. expect(snapperStub.enable.calledOnce).toBe(true);
  1034. expect(snapperStub.disable.calledOnce).toBe(true);
  1035. expect(snapperStub.close.calledOnce).toBe(true);
  1036. });
  1037. it('is not disabled again when disallowing the gesture after resizing to a wide screen', function() {
  1038. viewport.set(480);
  1039. window.initCore();
  1040. expect(snapperStub.enable.calledOnce).toBe(true);
  1041. expect(snapperStub.disable.called).toBe(false);
  1042. expect(snapperStub.close.called).toBe(false);
  1043. viewport.set(1280);
  1044. // Setting the viewport width does not automatically trigger a
  1045. // resize.
  1046. $(window).resize();
  1047. // The resize handler is debounced to be executed a few milliseconds
  1048. // after the resize event.
  1049. clock.tick(1000);
  1050. expect(snapperStub.enable.calledOnce).toBe(true);
  1051. expect(snapperStub.disable.calledOnce).toBe(true);
  1052. expect(snapperStub.close.calledOnce).toBe(true);
  1053. OC.disallowNavigationBarSlideGesture();
  1054. expect(snapperStub.enable.calledOnce).toBe(true);
  1055. expect(snapperStub.disable.calledOnce).toBe(true);
  1056. expect(snapperStub.close.calledOnce).toBe(true);
  1057. });
  1058. it('is not enabled when allowing the gesture after disallowing it, resizing to a narrow screen and resizing to a wide screen', function() {
  1059. viewport.set(1280);
  1060. window.initCore();
  1061. expect(snapperStub.enable.called).toBe(false);
  1062. expect(snapperStub.disable.calledOnce).toBe(true);
  1063. expect(snapperStub.close.calledOnce).toBe(true);
  1064. OC.disallowNavigationBarSlideGesture();
  1065. expect(snapperStub.enable.called).toBe(false);
  1066. expect(snapperStub.disable.calledOnce).toBe(true);
  1067. expect(snapperStub.close.calledOnce).toBe(true);
  1068. viewport.set(480);
  1069. // Setting the viewport width does not automatically trigger a
  1070. // resize.
  1071. $(window).resize();
  1072. // The resize handler is debounced to be executed a few milliseconds
  1073. // after the resize event.
  1074. clock.tick(1000);
  1075. expect(snapperStub.enable.called).toBe(false);
  1076. expect(snapperStub.disable.calledOnce).toBe(true);
  1077. expect(snapperStub.close.calledOnce).toBe(true);
  1078. viewport.set(1280);
  1079. $(window).resize();
  1080. clock.tick(1000);
  1081. expect(snapperStub.enable.called).toBe(false);
  1082. expect(snapperStub.disable.calledTwice).toBe(true);
  1083. expect(snapperStub.close.calledTwice).toBe(true);
  1084. OC.allowNavigationBarSlideGesture();
  1085. expect(snapperStub.enable.called).toBe(false);
  1086. expect(snapperStub.disable.calledTwice).toBe(true);
  1087. expect(snapperStub.close.calledTwice).toBe(true);
  1088. });
  1089. });
  1090. });