coreSpec.js 36 KB

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