copy-prop-stack-slot-test-framework.js 117 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. (function (window) {
  6. ///////////////////////////////////////////////////////////////////////////////
  7. // Utils object for helper functions
  8. ///////////////////////////////////////////////////////////////////////////////
  9. var Utils = {};
  10. //Doc Mode
  11. Utils.IE7STANDARDSMODE = 7;
  12. Utils.IE8STANDARDSMODE = 8;
  13. Utils.IE9STANDARDSMODE = 9;
  14. Utils.IE10STANDARDSMODE = 10;
  15. Utils.IE11STANDARDSMODE = 11;
  16. Utils.IE12STANDARDSMODE = 12;
  17. //IE Architectures
  18. Utils.X86MODE = "x86";
  19. Utils.X64MODE = "x64";
  20. Utils.ARMMODE = "arm";
  21. Utils.getHOSTMode = function () {
  22. var documentMode = this.IE11STANDARDSMODE; // Making default to be IE11 standards mode
  23. //See if document.documentMode is defined
  24. try {
  25. if ((document) && (document.documentMode)) {
  26. documentMode = document.documentMode;
  27. }
  28. } catch (ex) {
  29. //We are not running in IE, need to put logic of versioning for other hosts later
  30. }
  31. if (documentMode < 8)
  32. return this.IE7STANDARDSMODE;
  33. else if (documentMode == 8)
  34. return this.IE8STANDARDSMODE;
  35. else if (documentMode == 9)
  36. return this.IE9STANDARDSMODE;
  37. else if (documentMode == 10)
  38. return this.IE10STANDARDSMODE;
  39. else if (documentMode == 11 && typeof Math.hypot === "undefined") //hack for now as we run version:6 switch to emulate Doc mode 12
  40. return this.IE11STANDARDSMODE;
  41. else
  42. return this.IE12STANDARDSMODE;
  43. }
  44. var activeXInfo = {
  45. "WScript.Shell": {
  46. "clsid": "72C24DD5-D70A-438b-8A42-98424B88AFB8",
  47. "type": "application/x-shellscript"
  48. },
  49. "Loader42.Logger": {
  50. "clsid": "7CDFA963-4058-45AE-9061-D34614D83472",
  51. "type": "application/vns.ms-loader42loggerax"
  52. },
  53. "Scripting.FileSystemObject": {
  54. "clsid": "0D43FE01-F093-11cf-8940-00A0C9054228",
  55. "type": "application/x-filesystemobject"
  56. },
  57. "MutatorsHost.MutatorsActiveX": {
  58. "clsid": "ffafec7c-214c-4aab-b929-caa646777649",
  59. "type": "application/x-mutatorsactivex"
  60. },
  61. "apgloballib.apglobal": {
  62. "clsid": "CBFCDDC2-CDB1-3270-B9C5-FBE31729B041",
  63. "type": "application/x-apgloballib"
  64. },
  65. "Logger.Status": {
  66. "clsid": "712B2344-7A71-4242-B21C-AA728108EDD8",
  67. "type": "application/x-loggerstatus"
  68. },
  69. "WTTLogger.Logger": {
  70. "clsid": "FFC4E997-D97B-45DF-AD22-44C4B2DEDD2B",
  71. "type": "application/x-wttlogger"
  72. }
  73. };
  74. function createActiveXObject(progId) {
  75. var activeX;
  76. try {
  77. activeX = new ActiveXObject(progId);
  78. }
  79. catch (ex) {
  80. // Can't create ActiveXObject element in Edge mode, append Object element instead
  81. activeX = document.createElement("object");
  82. activeX.setAttribute('id', progId);
  83. activeX.setAttribute('type', activeXInfo[progId]["type"]);
  84. document.body.appendChild(activeX);
  85. }
  86. return activeX;
  87. }
  88. Utils.IEMatchesArch = function () {
  89. if (this.getProcessorArchitecture() != this.X64MODE) {
  90. return true;
  91. }
  92. if (this.runWow64()) {
  93. return this.getIEArchitecture() == this.X86MODE;
  94. }
  95. else {
  96. return this.getIEArchitecture() == this.X64MODE;
  97. }
  98. }
  99. Utils.getProcessorArchitecture = function () {
  100. try {
  101. var GetEnvVariable = function (variable) {
  102. var wscriptShell = createActiveXObject("WScript.Shell");
  103. var wshEnvironment = wscriptShell.Environment("System");
  104. return wshEnvironment(variable);
  105. }
  106. var result = GetEnvVariable("PROCESSOR_ARCHITECTURE");
  107. if (result != null) {
  108. result = result.toUpperCase();
  109. }
  110. if (result === "AMD64") {
  111. return this.X64MODE;
  112. }
  113. else if (result === "X86") {
  114. return this.X86MODE;
  115. }
  116. else if (result === "ARM") {
  117. return this.ARMMODE;
  118. }
  119. }
  120. catch (e) {
  121. throw new Error("[getProcessorArchitecture] Failed to retrieve environment variable. " + e.Message);
  122. }
  123. }
  124. Utils.getIEArchitecture = function () {
  125. if (typeof navigator === 'undefined') {
  126. return this.X64MODE;
  127. }
  128. //get the user agent and split the strings and identify t he IE mode that we are running
  129. var mode = navigator.userAgent;
  130. var arr_mode = mode.toLowerCase().split(";");
  131. for (var i = 0; i < arr_mode.length; i++) {
  132. if (arr_mode[i] === " wow64") {
  133. return this.X86MODE;
  134. }
  135. else if (arr_mode[i] === " x64") {
  136. return this.X64MODE;
  137. }
  138. else if (arr_mode[i] === " arm") {
  139. for (var j = i + 1; j < arr_mode.length; j++) {
  140. if (arr_mode[j] === " virtual)")
  141. return X86MODE;
  142. }
  143. return this.ARMMODE;
  144. }
  145. }
  146. //default to x86
  147. return this.X86MODE;
  148. }
  149. Utils.runWow64 = function () {
  150. try {
  151. var GetEnvVariable = function (variable) {
  152. var wscriptShell = createActiveXObject("WScript.Shell");
  153. var wshEnvironment = wscriptShell.Environment("Process");
  154. return wshEnvironment(variable);
  155. }
  156. var result = GetEnvVariable("NightlyWow64");
  157. if (result === "1") {
  158. return true;
  159. }
  160. else {
  161. return false;
  162. }
  163. }
  164. catch (e) {
  165. throw new Error("[runWow64] Failed to retrieve environment variable. " + e.Message);
  166. }
  167. }
  168. //Get the host of script engine
  169. Utils.WWAHOST = "WWA";
  170. Utils.IEHOST = "Internet Explorer";
  171. Utils.getHOSTType = function () {
  172. //navigator.appName will return the host name, e.g. "WWAHost/1.0" or "Microsoft Internet Explorer"
  173. if (typeof navigator != 'undefined' && navigator.appName.indexOf(this.WWAHOST) >= 0) {
  174. return this.WWAHOST;
  175. }
  176. return this.IEHOST;
  177. }
  178. //Get localized error message
  179. Utils.getLocalizedError = function (ID, _default, substitution) {
  180. if (_default) {
  181. return _default;
  182. }
  183. if (substitution == undefined) {
  184. var localizedString = apGlobalObj.apGetLocalizedString(ID);
  185. } else {
  186. var localizedString = apGlobalObj.apGetLocalizedStringWithSubstitution(ID, substitution);
  187. }
  188. return localizedString;
  189. }
  190. // read "MaxInterpretCount" environment variable to know how many time to run test suite
  191. Utils.getMaxInterpretCount = function () {
  192. try {
  193. var GetEnvVariable = function (variable) {
  194. var wscriptShell = createActiveXObject("WScript.Shell");
  195. var wshEnvironment = wscriptShell.Environment("Process");
  196. return wshEnvironment(variable);
  197. }
  198. var result = GetEnvVariable("MaxInterpretCount");
  199. if (result === "")
  200. return 0;
  201. else
  202. return Math.floor(result);
  203. }
  204. catch (e) {
  205. return 0;
  206. }
  207. }
  208. ///////////////////////////////////////////////////////////////////////////////
  209. // WTTLogger:
  210. // Logs directly to WTT.
  211. ///////////////////////////////////////////////////////////////////////////////
  212. var loggers = [];
  213. function WTTLogger() {
  214. var WTT_TRACE_LVL_MSG = 0x10000000;
  215. var WTT_TRACE_LVL_USER = 0x20000000;
  216. var WTT_TRACE_LVL_ERR = 0x01000000;
  217. var WTT_TRACE_LVL_ASSERT = 0x02000000;
  218. var WTT_TRACE_LVL_INVALID_PARAM = 0x04000000;
  219. var WTT_TRACE_LVL_BUG = 0x08000000;
  220. var WTT_TRACE_LVL_BREAK = 0x00100000;
  221. var WTT_TRACE_LVL_WARN = 0x00200000;
  222. var WTT_TRACE_LVL_FUNCTION_ENTRY = 0x00010000;
  223. var WTT_TRACE_LVL_FUNCTION_EXIT = 0x00020000;
  224. var WTT_TRACE_LVL_CONTEXT_ENTRY = 0x00040000;
  225. var WTT_TRACE_LVL_CONTEXT_EXIT = 0x00080000;
  226. var WTT_TRACE_LVL_START_TEST = 0x0100;
  227. var WTT_TRACE_LVL_END_TEST = 0x0200;
  228. var WTT_TRACE_LVL_TCMINFO = 0x0400;
  229. var WTT_TRACE_LVL_MACHINEINFO = 0x0800;
  230. var WTT_TRACE_LVL_ROLLUP = 0x0010;
  231. var WTT_ERROR_TYPE_HRESULT = 0x1;
  232. var WTT_ERROR_TYPE_NTSTATUS = 0x2;
  233. var WTT_ERROR_TYPE_WIN32 = 0x4;
  234. var WTT_ERROR_TYPE_BOOL = 0x8;
  235. var WTT_ERROR_LIST_EXPECTED = 0x1;
  236. var WTT_ERROR_LIST_BREAKON = 0x2;
  237. var WTT_TC_RESULT_PASS = 0x1;
  238. var WTT_TC_RESULT_FAIL = 0x2;
  239. var WTT_TC_RESULT_BLOCKED = 0x3;
  240. var WTT_TC_RESULT_WARN = 0x4;
  241. var WTT_TC_RESULT_SKIPPED = 0x5;
  242. var WTT_BUG_TYPE_BLOCKING = 0x1;
  243. var WTT_BUG_TYPE_NONBLOCKING = 0x2;
  244. var loggerObj = createActiveXObject("WTTLogger.Logger");
  245. var logHandle;
  246. var wwahostTimeout = 1000;
  247. var maxMsgSize = 3000; //actually 3901, but do we really even need 3000 in wtt
  248. this.start = function (filename, priority) {
  249. logHandle = loggerObj.CreateLogDevice(null);
  250. loggerObj.Trace(WTT_TRACE_LVL_MSG, logHandle, "Running " + filename);
  251. }
  252. this.testStart = function (test) {
  253. loggerObj.StartTest(test.desc, logHandle);
  254. }
  255. this.verify = function (test, passed, act, exp, msg) {
  256. if (!passed)
  257. loggerObj.Trace(WTT_TRACE_LVL_MSG, logHandle, "Failed - Act: " + act + ", Exp: " + exp + ":" + msg);
  258. }
  259. this.pass = function (test) {
  260. loggerObj.EndTest(test.desc, WTT_TC_RESULT_PASS, "", logHandle);
  261. }
  262. this.fail = function (test) {
  263. loggerObj.EndTest(test.desc, WTT_TC_RESULT_FAIL, "", logHandle);
  264. }
  265. this.error = function (test, error) {
  266. loggerObj.Trace(WTT_TRACE_LVL_MSG, logHandle, "Error: " + error.name + " - " + error.description);
  267. loggerObj.EndTest(test.desc, WTT_TC_RESULT_FAIL, "", logHandle);
  268. }
  269. this.end = function () {
  270. loggerObj.CloseLogDevice("", logHandle);
  271. //If we're running WTTLogger in a IE environment, we are probably running tests in wwahost,
  272. //so we should close the window after we finish in order to write logs and rollup. The timeout
  273. //is to ensure the rest of glue shutdown happens
  274. //if(typeof document !== "undefined" && Utils.getHOSTType() == Utils.WWAHOST)
  275. // setTimeout(function() { window.close(); }, wwahostTimeout);
  276. }
  277. this.comment = function (str) {
  278. var msg = str.toString().substring(0, maxMsgSize);
  279. loggerObj.Trace(WTT_TRACE_LVL_MSG, logHandle, msg);
  280. }
  281. this.bug = function (number, msg, db) {
  282. db = db || "Windows 8 Bugs";
  283. loggerObj.Trace(WTT_TRACE_LVL_BUG, logHandle, db, number, WTT_BUG_TYPE_BLOCKING);
  284. this.comment(msg);
  285. }
  286. }
  287. WTTLogger.shouldEnable = function () {
  288. try {
  289. var test = createActiveXObject("WTTLogger.Logger");
  290. return true;
  291. } catch (e) {
  292. return false;
  293. }
  294. }
  295. loggers.push(WTTLogger);
  296. ///////////////////////////////////////////////////////////////////////////////
  297. // HTMLLogger:
  298. // Provides HTML output. Must be run in a browser to function.
  299. ///////////////////////////////////////////////////////////////////////////////
  300. function HTMLLogger() {
  301. var resultsContainer;
  302. var testProgress = [];
  303. var results = [];
  304. var domReady = false;
  305. var summaryTable;
  306. var passes = 0;
  307. var failures = 0;
  308. var failureList = [];
  309. var executingTest = false;
  310. var done = false;
  311. var loggerInstance = this;
  312. var filename;
  313. var priority;
  314. var verifies = 0;
  315. if (document.addEventListener) {
  316. document.addEventListener("DOMContentLoaded", whenDomReady, false);
  317. } else {
  318. setTimeout(waitForDomReady, 1);
  319. }
  320. function waitForDomReady() {
  321. // Otherwise use the oft-used doScroll hack which, according to MSDN, will always thrown an
  322. // error unless the document is ready.
  323. try {
  324. document.documentElement.doScroll("left");
  325. }
  326. catch (e) {
  327. // We're not ready yet. Check again in a bit.
  328. setTimeout(waitForDomReady, 1);
  329. return;
  330. }
  331. whenDomReady();
  332. }
  333. function whenDomReady() {
  334. domReady = true;
  335. insertStyles();
  336. setupMutators();
  337. createSummaryTable();
  338. createCheckBox();
  339. setupTable();
  340. printResults();
  341. }
  342. // Inserts a stylesheet to the DOM and fills it with our styles.
  343. function insertStyles() {
  344. var css = [
  345. "body{font-family:'Segoe UI';font-size:1em}",
  346. "table{border-collapse:collapse;padding:0;margin:0}",
  347. "table td,table th{padding:3px}",
  348. "table tr.test_result td.result{border:1px solid #000;border-right:none}",
  349. "table tr.test_result td.details{border:1px solid #000;border-left:none}",
  350. "table td.result{font-size:2em;font-family:'Segoe UI Semibold';text-align:center;padding:3px 20px}",
  351. "table tr.pass td.result{background-color:#c3d69b}",
  352. "table tr.fail td.result{background-color:#d99694}",
  353. "table tr.error td.result{background-color:#d99694}",
  354. "table tr.bug td.result{background-color:#ffefbb}",
  355. "table tr.comment td.result, table tr.comment td.details {font-size:1em;text-align:left;}",
  356. "table td.details{padding:0px}",
  357. "table td.details table{width:100%;height:100%;}",
  358. "table tr.pass td.details th{background-color:#c3d69b}",
  359. "table tr.fail td.details th{background-color:#d99694}",
  360. "table tr.error td.details th{background-color:#d99694}",
  361. "table tr.hidden {display:none;}",
  362. "table td.details tr.detail_pass{background-color:#ebf1dd}",
  363. "table td.details tr.detail_fail{background-color:#f2dcdb}",
  364. "table td.details tr.detail_comment{background-color:#f2ffe9;}",
  365. "table td.details tr.detail_comment td{padding: 10px 20px;}",
  366. "table td.details tr.detail_comment td.detail_result{font-family:'Segoe UI Semibold';}",
  367. "table td.details tr.detail_bug{background-color:#ffefbb;}",
  368. "table td.details tr.detail_bug td{padding: 10px 20px;}",
  369. "table td.details tr.detail_bug td.detail_result{font-family:'Segoe UI Semibold';}",
  370. "table td.details th{font-size:1.1em;font-weight:normal;font-family:'Segoe UI Semibold';text-align:left}",
  371. "table td.details table td{padding:3px 20px}",
  372. "table td.details table td.error_message{background-color:#d99694;padding:3px}",
  373. "table td.details td.detail_message{width:95%}",
  374. "table td.details td.detail_result{width:5%}",
  375. "#results_summary{margin-bottom:1em;font-size:1.5em;}",
  376. "div.mutators { float: right }",
  377. "#results_summary td{padding:0 20px;}"];
  378. // Create a style dom element
  379. var style = document.createElement('style');
  380. style.type = 'text/css';
  381. style.rel = 'stylesheet';
  382. style.media = 'screen';
  383. // Append the element to the page's header
  384. document.getElementsByTagName("head")[0].appendChild(style);
  385. // Get a stylesheet object for the element we just inserted
  386. var stylesheet = document.styleSheets[document.styleSheets.length - 1];
  387. // Add the styles to the sheet. If there is a cssText property, we can just join together
  388. // all of the rules and add them at once. Otherwise, add them one at a time.
  389. if (typeof stylesheet.cssText == "string")
  390. document.styleSheets[document.styleSheets.length - 1].cssText = css.join('');
  391. else
  392. for (var i = 0; i < css.length; i++)
  393. stylesheet.insertRule(css[i], i);
  394. }
  395. //Replace angle brackets for the text
  396. function replaceAngleBrackets(text) {
  397. if (text == undefined)
  398. return "";
  399. if (text.replace == undefined)
  400. return text;
  401. return text.replace(/&/g, '&amp;')
  402. .replace(/</g, '&lt;')
  403. .replace(/>/g, '&gt;')
  404. .replace(/\n/g, '<br/>')
  405. .replace(/\s/g, '&nbsp;');
  406. }
  407. // Sets up the master table that will hold the results.
  408. function setupTable() {
  409. var masterTable = document.createElement("table");
  410. var body = document.createElement("tbody");
  411. masterTable.appendChild(body);
  412. document.body.appendChild(masterTable);
  413. resultsContainer = body;
  414. }
  415. // Add a dropdown box to select mutators to apply if we have the mutators ActiveX.
  416. function setupMutators() {
  417. function applyMutator(e) {
  418. // Undefined in IE < 8.
  419. if (typeof e === "undefined")
  420. e = window.event;
  421. var target = (typeof e.target === "undefined") ? e.srcElement : e.target;
  422. if (target.value === "")
  423. runner.mutators = [];
  424. else
  425. runner.mutators = [target.value];
  426. // Clear logger and reset.
  427. loggerInstance.clear();
  428. Run();
  429. }
  430. try {
  431. if (typeof mutator === "undefined") {
  432. // assigns to global mutator
  433. mutator = createActiveXObject("MutatorsHost.MutatorsActiveX");
  434. }
  435. } catch (e) {
  436. return
  437. }
  438. var mutators = mutator.GetMutatorsList().split(",");
  439. // Create a select box and fill it with options for each mutator.
  440. var select = document.createElement("select");
  441. select.appendChild(document.createElement("option"));
  442. for (var i = 0; i < mutators.length; i++) {
  443. option = document.createElement("option");
  444. option.innerHTML = mutators[i];
  445. option.value = mutators[i];
  446. select.appendChild(option);
  447. }
  448. select.onchange = applyMutator;
  449. // Put the box in a label, put the label in a div, and put the div in the document body.
  450. var container = document.createElement("div");
  451. var label = document.createElement("label");
  452. label.innerHTML = "Mutate With: ";
  453. label.appendChild(select);
  454. container.appendChild(label);
  455. container.setAttribute("class", "mutators");
  456. document.body.appendChild(container);
  457. }
  458. // Adds a result to the results array..
  459. function addResult(type, result, test, testProgress, error) {
  460. results.push({
  461. type: type,
  462. result: result,
  463. test: test,
  464. testProgress: testProgress,
  465. error: error
  466. });
  467. if (domReady)
  468. printResults();
  469. }
  470. // Goes through all the results and prints them to the table. This results array
  471. // fills up when the DOM is not ready yet.
  472. //
  473. function printResults() {
  474. while (results.length > 0) {
  475. var result = results.shift();
  476. if (result.type === "comment" || result.type === "bug")
  477. addRow(result);
  478. else
  479. addResultRow(result.result, result.test, result.testProgress, result.error);
  480. }
  481. }
  482. //Add a comment or bug to the status table
  483. function addRow(result) {
  484. var comment = result.result;
  485. var row = resultsContainer.insertRow(-1);
  486. var res = row.insertCell(-1);
  487. var details = row.insertCell(-1);
  488. res.innerHTML = replaceAngleBrackets(result.type);
  489. details.innerHTML = replaceAngleBrackets(comment);
  490. row.className = result.type.toLowerCase();
  491. res.className = "result";
  492. }
  493. // Adds a result to the status table.
  494. function addResultRow(result, test, testProgress, error) {
  495. var row = resultsContainer.insertRow(-1);
  496. var res = row.insertCell(-1);
  497. var details = row.insertCell(-1);
  498. res.innerHTML = result.toUpperCase();
  499. row.className = "test_result " + result;
  500. res.className = "result";
  501. details.className = "details";
  502. var detailsTable = constructDetailsTable(test, testProgress, error);
  503. details.appendChild(detailsTable);
  504. }
  505. // Constructs and returns the table that holds all the test progress that were
  506. // run.
  507. function constructDetailsTable(test, testProgress, error) {
  508. var table = document.createElement('table');
  509. var body, row, cell, text, msgCell;
  510. // Create the row with the test description
  511. body = document.createElement("tbody");
  512. row = document.createElement("tr");
  513. cell = document.createElement("th");
  514. cell.innerHTML = replaceAngleBrackets(test.id + ": " + test.desc);
  515. cell.setAttribute("colSpan", "2");
  516. row.appendChild(cell);
  517. body.appendChild(row);
  518. // Create an error row if there's an error.
  519. if (typeof error != "undefined") {
  520. row = document.createElement("tr");
  521. cell = document.createElement("td");
  522. cell.innerHTML = error.name + ": " + error.message;
  523. cell.setAttribute("colSpan", "2");
  524. cell.className = "error_message";
  525. row.appendChild(cell);
  526. body.appendChild(row);
  527. }
  528. // Loop through all the test progress adding rows for each.
  529. var assertionResult;
  530. for (var i = 0; i < testProgress.length; i++) {
  531. if (testProgress[i].type === 'comment')
  532. assertionResult = "comment";
  533. else if (testProgress[i].type === 'bug')
  534. assertionResult = "bug";
  535. else if (testProgress[i].passed)
  536. assertionResult = "pass";
  537. else
  538. assertionResult = "fail";
  539. row = document.createElement("tr");
  540. row.className = "detail_" + assertionResult;
  541. if (testProgress[i].passed)
  542. row.className += " hidden";
  543. cell = document.createElement("td");
  544. cell.className = "detail_result";
  545. msgCell = document.createElement("td");
  546. msgCell.className = "detail_message";
  547. cell.innerHTML = replaceAngleBrackets(assertionResult);
  548. msgCell.innerHTML = replaceAngleBrackets(testProgress[i].message);
  549. if (testProgress[i].type !== 'comment' && testProgress[i].type !== 'bug') {
  550. if (!testProgress[i].passed) {
  551. msgCell.innerHTML += "<br>Expected: " + testProgress[i].expected;
  552. msgCell.innerHTML += "<br>Actual: " + testProgress[i].actual;
  553. }
  554. }
  555. row.appendChild(cell);
  556. row.appendChild(msgCell);
  557. body.appendChild(row);
  558. }
  559. table.appendChild(body);
  560. return table;
  561. }
  562. function createSummaryTable() {
  563. var table = document.createElement("table");
  564. table.id = "results_summary";
  565. var row = table.insertRow(-1);
  566. var cell = row.insertCell(-1);
  567. cell.id = "testName";
  568. cell = row.insertCell(-1);
  569. cell.id = "priority";
  570. cell = row.insertCell(-1);
  571. cell.id = "passes";
  572. cell = row.insertCell(-1);
  573. cell.id = "failures";
  574. cell = row.insertCell(-1);
  575. cell.id = "total";
  576. var rowForFailure = table.insertRow(-1);
  577. var cellForFailure = rowForFailure.insertCell(-1);
  578. cellForFailure.id = "FailedCases";
  579. document.body.appendChild(table);
  580. if (done)
  581. populateSummaryTable();
  582. }
  583. function populateSummaryTable() {
  584. if (!domReady)
  585. return; // we'll come back later if we need at the end of createSummaryTable.
  586. document.getElementById("testName").innerHTML = "TEST: " + filename;
  587. document.getElementById("priority").innerHTML = "PRIORITY: " + priority;
  588. document.getElementById("passes").innerHTML = "PASS: " + passes;
  589. document.getElementById("failures").innerHTML = "FAIL: " + failures;
  590. document.getElementById("total").innerHTML = "TOTAL: " + (passes + failures);
  591. if (failures > 0)
  592. document.getElementById("FailedCases").innerHTML = "Failed Cases: " + failureList.toString();
  593. if ((passes + failures) === 0) {
  594. document.write("<h1>No tests were run! There's probably a SyntaxError in the test file.</h1>")
  595. }
  596. // Added for XBox team to parse out pass/fail from page title
  597. document.title =
  598. 'PASS:' + passes +
  599. ';FAIL:' + failures +
  600. ';TOTAL:' + (passes + failures);
  601. }
  602. function createCheckBox() {
  603. var box = document.createElement("input");
  604. box.type = "checkbox";
  605. box.checked = false;
  606. box.id = "displayCheckbox";
  607. var label = document.createElement('label');
  608. label.innerHTML = "Display passed test result"
  609. box.onclick = function () {
  610. var trList = document.getElementsByTagName("tr");
  611. for (var x = 0; x < trList.length; x++) {
  612. if (this.checked) {
  613. //Remove hidden in class name
  614. trList[x].className = trList[x].className.replace("hidden", "");
  615. }
  616. else {
  617. //Add hidden to detail_pass
  618. trList[x].className = trList[x].className.replace("detail_pass", "detail_pass hidden");
  619. }
  620. }
  621. }
  622. document.body.appendChild(box);
  623. document.body.appendChild(label);
  624. }
  625. function internalComment(type, str) {
  626. if (executingTest)
  627. testProgress.push({ type: type, message: str });
  628. else
  629. addResult(type, str);
  630. }
  631. this.start = function (file, pri) {
  632. filename = file;
  633. priority = pri;
  634. }
  635. this.testStart = function (test) {
  636. testProgress = []; // track assertions and comments from tests.
  637. executingTest = true;
  638. }
  639. this.verify = function (test, passed, act, exp, msg) {
  640. verifies++;
  641. if (verifies < 1000 || !passed) {
  642. testProgress.push({ type: 'assertion', passed: passed, actual: act, expected: exp, message: msg });
  643. }
  644. }
  645. this.pass = function (test) {
  646. passes++;
  647. addResult('result', 'pass', test, testProgress);
  648. executingTest = false;
  649. }
  650. this.fail = function (test) {
  651. failures++;
  652. failureList.push(test.id);
  653. addResult('result', 'fail', test, testProgress);
  654. executingTest = false;
  655. }
  656. this.error = function (test, error) {
  657. failures++;
  658. // Throw the error so we can debug in browser.
  659. setTimeout(function () { throw error }, 0);
  660. addResult('result', 'error', test, testProgress, error);
  661. executingTest = false;
  662. }
  663. this.end = function () {
  664. done = true;
  665. populateSummaryTable();
  666. }
  667. this.comment = function (str) {
  668. internalComment('comment', str);
  669. };
  670. this.bug = function (number, msg) {
  671. msg = msg || "";
  672. internalComment('bug', "Bug: " + number + ": " + msg);
  673. };
  674. this.clear = function () {
  675. if (typeof resultsContainer == "undefined")
  676. return;
  677. passes = 0;
  678. failures = 0;
  679. failureList = [];
  680. var children = resultsContainer.childNodes;
  681. for (var i = children.length - 1; i >= 0; i--) {
  682. resultsContainer.removeChild(children[i]);
  683. }
  684. }
  685. }
  686. HTMLLogger.shouldEnable = function () {
  687. return typeof document !== "undefined"
  688. }
  689. loggers.push(HTMLLogger);
  690. ///////////////////////////////////////////////////////////////////////////////
  691. // WScriptLogger:
  692. // Log to the console using WScript.
  693. ////////////////////////////////////////////////////////////////////////////////
  694. function WScriptLogger() {
  695. var passCount = 0;
  696. var failCount = 0;
  697. var verifications = [];
  698. var verbose = false;
  699. // Initialize the projection related stuff in JsHost
  700. if (Utils.getHOSTType() == Utils.WWAHOST) {
  701. WScript.InitializeProjection();
  702. }
  703. this.start = function (filename, priority) {
  704. if (!verbose) {
  705. return;
  706. }
  707. if (priority === "all") {
  708. WScript.Echo(filename);
  709. } else {
  710. WScript.Echo(filename + " Priority " + priority);
  711. }
  712. }
  713. this.testStart = function (test) {
  714. verifications = [];
  715. }
  716. this.verify = function (test, passed, act, exp, msg) {
  717. //print(`test:${test} passed:${passed} act:${act} exp:${exp} msg:${msg}`)
  718. if (passed) {
  719. if (verbose) {
  720. verifications.push("\tPass: " + msg + "\n\t\t Actual: " + act + "\n");
  721. }
  722. } else {
  723. verifications.push("\n\tFail: " + msg + "\n\t\tExpected: " + exp + "\n\t\t Actual: " + act + "\n");
  724. }
  725. }
  726. this.pass = function (test) {
  727. passCount++;
  728. if (verbose) {
  729. WScript.Echo("PASS\t" + test.id + ": " + test.desc);
  730. //Needed for baselines
  731. WScript.Echo(verifications.join("\n"));
  732. }
  733. }
  734. this.fail = function (test) {
  735. failCount++;
  736. WScript.Echo("");
  737. WScript.Echo("");
  738. WScript.Echo("FAIL\t" + test.id + ": " + test.desc);
  739. WScript.Echo("");
  740. WScript.Echo(verifications.join("\n"));
  741. WScript.Echo("");
  742. WScript.Echo("");
  743. }
  744. this.error = function (test, error) {
  745. failCount++;
  746. WScript.Echo("");
  747. WScript.Echo("");
  748. WScript.Echo("FAIL\t" + test.id + ": " + test.desc);
  749. WScript.Echo("\n\tError: " + error.name + " - " + error.description);
  750. if (verifications.length > 0) {
  751. WScript.Echo("");
  752. WScript.Echo(verifications.join("\n"));
  753. WScript.Echo("");
  754. }
  755. WScript.Echo("");
  756. WScript.Echo("");
  757. }
  758. this.end = function () {
  759. if (verbose) {
  760. WScript.Echo("");
  761. WScript.Echo("Passed: " + passCount);
  762. WScript.Echo("Failed: " + failCount);
  763. if ((passCount + failCount) === 0) {
  764. WScript.Echo("");
  765. WScript.Echo("No tests were run! There's probably a SyntaxError in the test file.")
  766. }
  767. } else {
  768. if (failCount === 0) {
  769. WScript.Echo('pass');
  770. } else {
  771. WScript.Echo('fail');
  772. }
  773. }
  774. }
  775. this.comment = function (str) {
  776. if (verbose) {
  777. verifications.push("\tComment: " + str);
  778. }
  779. };
  780. }
  781. WScriptLogger.shouldEnable = function () {
  782. return typeof WScript !== "undefined" && typeof WScript.Echo !== "undefined" && typeof window.location === "undefined";
  783. }
  784. loggers.push(WScriptLogger);
  785. // A simple logger object exposed on the window, giving the user access to the comment method.
  786. // Simply publishes a comment event.
  787. var windowLogger = {};
  788. windowLogger.comment = function (str) {
  789. runner.publish('comment', str);
  790. }
  791. ///////////////////////////////////////////////////////////////////////////////
  792. // NightlyLogger:
  793. // Provides Logging for automated nightly runs using apgloblib. Must be run in a browser to
  794. // function.
  795. ///////////////////////////////////////////////////////////////////////////////
  796. function NightlyLogger() {
  797. var apPlatform;
  798. var runCount;
  799. function VBS_apglobal_init() {
  800. apPlatform = apGlobalObj.apGetPlatform();
  801. runCount = 0;
  802. }
  803. function apInitTest(stTestName) {
  804. if (window.runsExecuted == 0) { // In MaxInterprentCount case do it only on first iteration
  805. apGlobalObj.apInitTest(stTestName);
  806. }
  807. }
  808. function apInitScenario(stScenarioName) {
  809. runCount++;
  810. apGlobalObj.apInitScenario(stScenarioName);
  811. }
  812. function apLogFailInfo(stMessage, stExpected, stActual, stBugNum) {
  813. if (stBugNum == null) stBugNum = ""; // and may Fajen suffer for it
  814. apGlobalObj.apLogFailInfo("" + stMessage, "" + stExpected, "" + stActual, "" + stBugNum);
  815. }
  816. function apEndTest() {
  817. if (window.runsExecuted >= window.runsToExecute - 1) { // In MaxInterprentCount case do it only on last iteration
  818. if (runCount === 0) {
  819. apLogFailInfo("Zero tests were run! Must be a SyntaxError in the test file...", true, false, '');
  820. }
  821. apGlobalObj.apEndTest();
  822. }
  823. }
  824. function apErrorTrap() {
  825. apGlobalObj.apLogFailInfo("call to apErrorTrap found!", "", "", "");
  826. }
  827. this.start = function (filename) {
  828. VBS_apglobal_init()
  829. apInitTest(filename)
  830. }
  831. this.testStart = function (test) {
  832. apInitScenario(test.id + " : " + test.desc)
  833. }
  834. this.verify = function (test, passed, act, exp, msg) {
  835. if (!passed)
  836. apLogFailInfo(msg, exp, act, '');
  837. }
  838. this.pass = function (test) { }
  839. this.fail = function (test) { }
  840. this.error = function (test, error) {
  841. apLogFailInfo("Exception thrown : " + error.name + "Message: " + error.message, true, false, '');
  842. }
  843. this.end = function () {
  844. apEndTest();
  845. }
  846. this.comment = function (msg) { }
  847. }
  848. NightlyLogger.shouldEnable = function () {
  849. try {
  850. var GetEnvVariable = function (variable) {
  851. var wscriptShell = createActiveXObject("WScript.Shell");
  852. var wshEnvironment = wscriptShell.Environment("Process");
  853. return wshEnvironment(variable);
  854. }
  855. var result = GetEnvVariable("JScript_NightlyRun");
  856. if (result === "")
  857. return false;
  858. else
  859. return true;
  860. }
  861. catch (e) {
  862. return false;
  863. }
  864. }
  865. loggers.push(NightlyLogger);
  866. ///////////////////////////////////////////////////////////////////////////////
  867. // Loader42Logger:
  868. // Provides Logging for automations runs with Loader42. Must be run in a browser to function.
  869. ///////////////////////////////////////////////////////////////////////////////
  870. function Loader42Logger() {
  871. // Provides logging back to Loader42 (and therefore WTT and Blackbeard)
  872. var filename = "File Name Not Specified";
  873. var Loader42Log = {
  874. // define some constants for reporting success/failure of a test
  875. FAIL: 0,
  876. PASS: 1,
  877. BLOCKED: 2,
  878. Logger: null,
  879. TestsComplete: false,
  880. Debug: false,
  881. // Initialize the ActiveX logger object
  882. InitLogger: function () {
  883. if (Loader42Log.Logger === null) {
  884. try {
  885. Loader42Log.Logger = createActiveXObject("Loader42.Logger");
  886. }
  887. catch (ex) {
  888. // Can't create ActiveXObject element in Edge mode, append Object element instead
  889. Loader42Log.Logger = document.createElement("object");
  890. Loader42Log.Logger.setAttribute('id', 'logger');
  891. Loader42Log.Logger.setAttribute('type', 'application/vns.ms-loader42loggerax');
  892. document.body.appendChild(Loader42Log.Logger);
  893. }
  894. try {
  895. // Cleanup logger in case where HTMLLoader is not in use
  896. // but Loader42 is present.
  897. if (Loader42Log.Logger.loaderName !== "HTMLLoader") {
  898. Loader42Log.Logger = null;
  899. }
  900. }
  901. catch (ex) {
  902. Loader42Log.Logger = null;
  903. }
  904. }
  905. },
  906. // Called at the start of every test case. Argument is the name of the test
  907. // case.
  908. TestStart: function (name) {
  909. Loader42Log.InitLogger();
  910. if (Loader42Log.Logger) {
  911. Loader42Log.Logger.LogTestStart(name);
  912. }
  913. else if (Loader42Log.Debug) {
  914. alert("TestStart(): " + name);
  915. }
  916. },
  917. // Called at the end of every test case. Name should match what is used in
  918. // TestStart(). Result should be one of the constants
  919. // Logger42Log.FAIL,
  920. // Logger42Log.PASS,
  921. // Logger42Log.BLOCKED
  922. // Message is a simple descriptive error, mostly useful in explaining why
  923. // a test failed or was blocked.
  924. TestFinish: function (name, result, message) {
  925. Loader42Log.InitLogger();
  926. if (Loader42Log.Logger) {
  927. Loader42Log.Logger.LogTestEnd(name, result, message);
  928. }
  929. else if (Loader42Log.Debug) {
  930. var status;
  931. if (result === Loader42Log.PASS) {
  932. status = "PASS";
  933. }
  934. else if (result === Loader42Log.FAIL) {
  935. status = "FAIL";
  936. }
  937. else if (result === Loader42Log.BLOCKED) {
  938. status = "BLOCKED";
  939. }
  940. else {
  941. status = "UNKNOWN";
  942. }
  943. alert("TestFinish(): " + name + "\n\n" + status + ": " + message);
  944. }
  945. },
  946. // Logs a message on behalf of the function. Used for tracing/debugging.
  947. TestComment: function (comment) {
  948. Loader42Log.InitLogger();
  949. if (Loader42Log.Logger) {
  950. Loader42Log.Logger.LogComment(comment);
  951. }
  952. },
  953. // Signaled at the end of the test, when the page wishes to close the
  954. // browser. Should only be called once.
  955. AllTestsComplete: function () {
  956. Loader42Log.InitLogger();
  957. if (Loader42Log.TestsComplete) {
  958. Loader42Log.TestStart("LogException");
  959. Loader42Log.TestComment("AllTestsComplete() called twice.");
  960. Loader42Log.TestFinish("LogException", Loader42Log.PASS, "AllTestsComplete() called twice.");
  961. }
  962. else {
  963. Loader42Log.TestsComplete = true;
  964. if (Loader42Log.Logger) {
  965. // Since success/failure is really determined by if there are
  966. // any failures in TestFinish, we don't have to really worry
  967. // about logging success or failure here.
  968. Loader42Log.Logger.LogResult(true, "AllTestsComplete");
  969. }
  970. else if (Loader42Log.Debug) {
  971. alert("AllTestsComplete");
  972. }
  973. }
  974. }
  975. };
  976. //Added for Loader42- True for the first Scenario
  977. var firsttest = true;
  978. var prevScenario = "";
  979. var loggermessage = "";
  980. var loggerresult = 1;
  981. function apInitTest(stTestName) {
  982. if (window.runsExecuted == 0) { // In MaxInterprentCount case do it only on first iteration
  983. filename = stTestName;
  984. //Added for Loader42 - InitLogger will initialize the logger
  985. Loader42Log.InitLogger();
  986. }
  987. }
  988. function apInitScenario(stScenarioName) {
  989. //Added for Loader42-If this is the first scenario do not call Test Fininsh
  990. if (firsttest === true) {
  991. Loader42Log.TestStart(stScenarioName);
  992. firsttest = false; //Done with the first test
  993. }
  994. else {
  995. //Added for Loader42- if the Scenario Succeeded log the result as passed
  996. if (loggerresult === 1) {
  997. Loader42Log.TestComment("");
  998. Loader42Log.TestComment("File Name " + filename);
  999. Loader42Log.TestComment("Result PASSED");
  1000. Loader42Log.TestComment("Scenario " + prevScenario);
  1001. Loader42Log.TestComment("");
  1002. }
  1003. //TestFinish the previous scenario
  1004. Loader42Log.TestFinish(prevScenario, loggerresult, loggermessage);
  1005. //Test start a New Scenario
  1006. Loader42Log.TestStart(stScenarioName);
  1007. //Added for Loader42-Reset the Variable back to the initial value for the New Scenario
  1008. loggermessage = ""; //Clear tge loggermessage
  1009. loggerresult = 1; //Set Default to Success
  1010. }
  1011. prevScenario = stScenarioName;
  1012. }
  1013. function apLogFailInfo(stMessage, stExpected, stActual, stBugNum) {
  1014. if (stBugNum == null) stBugNum = ""; // and may Fajen suffer for it
  1015. //Added for Loader42 - Store the result in a global variable with all the values
  1016. Loader42Log.TestComment("");
  1017. Loader42Log.TestComment("File Name " + filename);
  1018. Loader42Log.TestComment("Result FAILED");
  1019. Loader42Log.TestComment("Scenario " + stMessage);
  1020. Loader42Log.TestComment("EXPECTED Result " + stExpected);
  1021. Loader42Log.TestComment("ACTUAL Result " + stActual);
  1022. Loader42Log.TestComment("");
  1023. loggerresult = 0; //this indicates failiure
  1024. }
  1025. function apEndTest() {
  1026. if (window.runsExecuted >= window.runsToExecute - 1) { // In MaxInterprentCount case do it only on last iteration
  1027. //Added for Loader42- Finish the last test that was started
  1028. if (loggerresult === 1) {
  1029. Loader42Log.TestComment("");
  1030. Loader42Log.TestComment("File Name " + filename);
  1031. Loader42Log.TestComment("Result PASSED");
  1032. Loader42Log.TestComment("Scenario " + prevScenario);
  1033. Loader42Log.TestComment("");
  1034. }
  1035. //Finishing the last Scenario
  1036. Loader42Log.TestFinish(prevScenario, loggerresult, loggermessage);
  1037. //Added for Loader42 - - called once to finish the test
  1038. Loader42Log.TestComment("Ending Test" + filename);
  1039. Loader42Log.AllTestsComplete();
  1040. }
  1041. }
  1042. this.start = function (filename) {
  1043. apInitTest(filename)
  1044. }
  1045. this.testStart = function (test) {
  1046. apInitScenario(test.desc)
  1047. }
  1048. this.verify = function (test, passed, act, exp, msg) {
  1049. if (!passed)
  1050. apLogFailInfo(msg, exp, act, '');
  1051. }
  1052. this.pass = function (test) { }
  1053. this.fail = function (test) { }
  1054. this.error = function (test, error) {
  1055. apLogFailInfo("Exception thrown : " + error.name + "Message: " + error.message, true, false, '');
  1056. }
  1057. this.end = function () {
  1058. apEndTest();
  1059. }
  1060. this.comment = function (msg) {
  1061. Loader42Log.TestComment(msg);
  1062. }
  1063. }
  1064. Loader42Logger.shouldEnable = function () {
  1065. try {
  1066. var Logger = createActiveXObject("Loader42.Logger");
  1067. return true;
  1068. }
  1069. catch (e) {
  1070. return false;
  1071. }
  1072. return false;
  1073. }
  1074. loggers.push(Loader42Logger);
  1075. ///////////////////////////////////////////////////////////////////////////////
  1076. // StressLogger:
  1077. // Provides logging support via the DrummerLogger ActiveX object to log and report to the Drummer test harness. It also uses the HTML logger to output the results in IE.
  1078. ///////////////////////////////////////////////////////////////////////////////
  1079. function StressLogger() {
  1080. var htmlLogger = new HTMLLogger();
  1081. var htmlLoggerRegistered = false;
  1082. var logger = new ActiveXObject("DrummerLogger.Logger");
  1083. var that = this;
  1084. var id;
  1085. window.onerror = function () {
  1086. this.end();
  1087. }
  1088. //logger.Config.NumberIterations -> Contains the number of iterations asked to perform
  1089. this.CurrentTestGroupIteration = 1;
  1090. function getRunId() {
  1091. id = window.location.href.substring(window.location.href.indexOf("stressrun=") + 10)
  1092. }
  1093. this.start = function (fileName) {
  1094. getRunId();
  1095. logger.Initialize(id);
  1096. that.Config = logger.Config;
  1097. logger.Comment("Test File: " + fileName);
  1098. logger.Comment("Runtime Iterations Requested: " + that.Config.RuntimeIterations);
  1099. logger.Comment("Testcase Iterations Requested: " + that.Config.TestcaseIterations);
  1100. logger.Comment("Collection Frequency Requested: " + that.Config.CollectionFrequency);
  1101. if (that.Config.OutputHTML && !htmlLoggerRegistered) {
  1102. runner.subscribe(htmlLogger);
  1103. htmlLoggerRegistered = true;
  1104. }
  1105. }
  1106. this.testStart = function (test) {
  1107. logger.InitScenario(test.id + ": " + test.desc);
  1108. }
  1109. this.verify = function (test, passed, act, exp, msg) {
  1110. logger.Comment("Passed: " + passed + "; Actual: " + act + "; Expected: " + exp + "; Message: " + msg);
  1111. }
  1112. this.pass = function (test) {
  1113. logger.EndScenario("pass", test.desc);
  1114. }
  1115. this.fail = function (test) {
  1116. logger.EndScenario("fail", test.desc);
  1117. }
  1118. this.error = function (test, error) {
  1119. logger.Error(error.message);
  1120. }
  1121. this.end = function () {
  1122. logger.Comment("TestGroupIteration Executed: " + (that.CurrentTestGroupIteration - 1));
  1123. logger.Finished();
  1124. }
  1125. this.comment = function (msg) {
  1126. logger.Comment(msg);
  1127. }
  1128. this.CollectMetrics = function () {
  1129. logger.CollectMetrics();
  1130. }
  1131. }
  1132. StressLogger.shouldEnable = function () {
  1133. try {
  1134. var logger = new ActiveXObject("DrummerLogger.Logger");
  1135. var str = window.location.href.substring(window.location.href.indexOf("?") + 1);
  1136. if (str.indexOf("stressrun") > -1)
  1137. return true;
  1138. else
  1139. return false;
  1140. }
  1141. catch (e) {
  1142. return false;
  1143. }
  1144. }
  1145. loggers.push(StressLogger);
  1146. ///////////////////////////////////////////////////////////////////////////////
  1147. // End Loggers
  1148. ///////////////////////////////////////////////////////////////////////////////
  1149. //scheduler in charge of giving us tasks
  1150. var scheduler = null;
  1151. var runner = (function () {
  1152. //holds onto objects that wish to be notified of pub/sub events
  1153. var subscribers = [];
  1154. //callbacks that get run before any tests execute
  1155. var globalSetups = [];
  1156. //callbacks that get run after all tests execute
  1157. var globalTeardowns = [];
  1158. //how many start calls we are waiting for
  1159. var waitCount = 0;
  1160. //current handle returned from setTimeout
  1161. var waitHandle = null;
  1162. //valid states
  1163. //init - initial state
  1164. // => running
  1165. // => error
  1166. //running - running test
  1167. // => waiting
  1168. // => ending
  1169. // => error
  1170. //waiting - waiting for async op
  1171. // => waiting
  1172. // => resuming
  1173. // => timeout
  1174. // => error
  1175. //resuming - resuming from async op
  1176. // => error
  1177. // => running
  1178. //timeout - timed out during async op
  1179. // => resuming
  1180. // => error
  1181. //ending - final state
  1182. //error - error in the test
  1183. // => running
  1184. // => ending
  1185. //current state of the runner
  1186. var currentState = "init";
  1187. //name of the currently executing file/suite. This is set via
  1188. //setting Loader42_FileName on the global scope
  1189. var fileName = null;
  1190. //priority to run for filtering tests. Valid values are "all" or a number
  1191. var priority = "all";
  1192. //default timeout for async tasks
  1193. var DEFAULT_TIMEOUT = 10000;
  1194. //flag for the main run loop
  1195. var ended = false;
  1196. //object holding valid states and the action to take each iteration while running in them
  1197. var states = {
  1198. init: function () {
  1199. if (window.runsExecuted == 0) { // In MaxInterprentCount case do it only on first iteration
  1200. runner.publish('start', fileName, priority);
  1201. }
  1202. scheduler.prepend(globalSetups);
  1203. scheduler.push(globalTeardowns);
  1204. transitionTo("running");
  1205. },
  1206. resuming: function () {
  1207. transitionTo("running");
  1208. },
  1209. running: function () {
  1210. var task = scheduler.next();
  1211. if (task) {
  1212. try {
  1213. task();
  1214. } catch (ex) {
  1215. runner.publish('error', currentTest, ex);
  1216. transitionTo("error");
  1217. }
  1218. } else {
  1219. transitionTo('ending');
  1220. }
  1221. },
  1222. ending: function () {
  1223. if (++window.runsExecuted < window.runsToExecute) {
  1224. transitionTo("restarting");
  1225. }
  1226. else {
  1227. runner.publish("end", fileName, priority);
  1228. ended = true;
  1229. }
  1230. },
  1231. restarting: function () {
  1232. tasks = ranTasks;
  1233. ranTasks = [];
  1234. transitionTo("init");
  1235. },
  1236. waiting: function () { },
  1237. timeout: function () {
  1238. if (waitHandle === null)
  1239. return;
  1240. waitHandle = null;
  1241. currentTest.error = new Error("Timed out before runner.start() being called");
  1242. testPassed = false;
  1243. waitCount = 0;
  1244. transitionTo("resuming");
  1245. },
  1246. error: function () {
  1247. ended = true;
  1248. }
  1249. };
  1250. // Subscribes to an event named prop for each property of obj, with the callback being the
  1251. // value.
  1252. function subscribeObject(obj) {
  1253. for (var prop in obj)
  1254. if (typeof obj[prop] === "function")
  1255. subscribeToEvent(prop, obj[prop]);
  1256. }
  1257. // Subscribes to an event of a given name with the given callback.
  1258. function subscribeToEvent(e, callback) {
  1259. if (typeof subscribers[e] === "undefined")
  1260. subscribers[e] = [];
  1261. subscribers[e].push(callback);
  1262. }
  1263. //transitions the runner to a new state and validates that the transition is allowed
  1264. //parameters:
  1265. // * newState: string representing the new state to transition to
  1266. function transitionTo(newState) {
  1267. function transitionAssert() {
  1268. var res = false;
  1269. for (var i = 0; i < arguments.length; i++)
  1270. if (arguments[i] === newState)
  1271. res = true;
  1272. runnerAssert(res, "invalid state transition: " + currentState + "->" + newState)
  1273. }
  1274. switch (currentState) {
  1275. case "init":
  1276. transitionAssert("running", "error");
  1277. break;
  1278. case "running":
  1279. transitionAssert("waiting", "ending", "error");
  1280. break;
  1281. case "waiting":
  1282. transitionAssert("resuming", "waiting", "error", "timeout");
  1283. break;
  1284. case "timeout":
  1285. transitionAssert("resuming", "error");
  1286. break;
  1287. case "resuming":
  1288. transitionAssert("running", "error");
  1289. break;
  1290. case "error":
  1291. transitionAssert("running", "ending");
  1292. break;
  1293. case "ending":
  1294. transitionAssert("restarting", "error");
  1295. break;
  1296. case "restarting":
  1297. transitionAssert("init", "error");
  1298. break;
  1299. default:
  1300. runnerAssert(false, "Invalid state");
  1301. break;
  1302. }
  1303. currentState = newState;
  1304. }
  1305. //internal check to validate assumptions at given points in the code
  1306. //along the lines of the C ASSERT macro or C# asserts
  1307. //parameters:
  1308. // * bool - boolean value that is assumed to be true
  1309. // * msg - message to publish if the bool is false
  1310. //returns:
  1311. // the bool passed in (for use in conditionals or assignment)
  1312. function runnerAssert(bool, msg) {
  1313. if (!bool) {
  1314. runner.publish('comment', "Internal failure: " + msg);
  1315. transitionTo("error");
  1316. currentTest.error = new Error("Internal failure: " + msg);
  1317. }
  1318. return bool;
  1319. }
  1320. //main runloop for the runner. Loops continuously unless state
  1321. //is waiting or the test is ended. Each iteration, it runs the action
  1322. //associated with the current state
  1323. function runTasks() {
  1324. while (!ended) {
  1325. states[currentState]();
  1326. if (currentState === "waiting")
  1327. return;
  1328. }
  1329. }
  1330. //wraps globalSetup or globalTeardown operations in a try catch block to allow logging
  1331. function wrapGlobalOperation(type, task) {
  1332. return function () {
  1333. try {
  1334. task();
  1335. } catch (e) {
  1336. runner.publish('comment', "Error during " + type + " - " + e.name + ": " + e.description);
  1337. runner.publish('end', fileName, priority);
  1338. transitionTo("error");
  1339. }
  1340. }
  1341. }
  1342. // Runner object is responsible for controlling the execution of tests. It is exposed on the global
  1343. // object to external code can call any method on runner.
  1344. return {
  1345. // Subscribe to an event by passing an eventName and a callback function. Subscribe to
  1346. // multiple events by passing an object with keys that correspond to the event names you
  1347. // want to subscribe to.
  1348. subscribe: function () {
  1349. if (arguments.length == 1)
  1350. subscribeObject(arguments[0]);
  1351. else
  1352. subscribeToEvent(arguments[0], arguments[1]);
  1353. },
  1354. // Publish an event. Calls all subscribed callbacks with the provided arguments.
  1355. publish: function (e) {
  1356. var args = Array.prototype.slice.call(arguments, 1);
  1357. if (typeof subscribers[e] !== "undefined")
  1358. for (var i = 0; i < subscribers[e].length; i++)
  1359. subscribers[e][i].apply(undefined, args);
  1360. },
  1361. mutators: [],
  1362. //Runs list of tests once.
  1363. //parameters:
  1364. // * testFileName - name of the test file/suite
  1365. run: function (testFileName) {
  1366. runnerAssert(scheduler !== null, "no scheduler set. This only happens if setScheduler is not called with a scheduler");
  1367. if (ended) { // We are running it again
  1368. window.runsExecuted = 0;
  1369. ended = false;
  1370. tasks = ranTasks;
  1371. ranTasks = [];
  1372. currentState = "init";
  1373. }
  1374. runnerAssert(currentState === "init", "run called while runner in bad state. Probably means multiple calls to run were made");
  1375. if (typeof testFileName === "undefined") {
  1376. try {
  1377. testFileName = Loader42_FileName; // Loader42_FileName may be undefined.
  1378. } catch (e) {
  1379. //noop
  1380. } finally {
  1381. testFileName = testFileName || "No filename given";
  1382. }
  1383. }
  1384. fileName = testFileName;
  1385. runTasks();
  1386. },
  1387. //Decrements the wait counter and instructs the runner to resume running after a wait call
  1388. // if the counter is 0. If the timeout has fired, this is a noop.
  1389. //parameters:
  1390. // * testWaitHandle - waithandle corresponding to the return value from start
  1391. start: function (testWaitHandle) {
  1392. if (typeof testWaitHandle !== "undefined" && testWaitHandle !== waitHandle)
  1393. return;
  1394. waitCount--;
  1395. if (waitCount === 0) {
  1396. clearTimeout && clearTimeout(testWaitHandle);
  1397. transitionTo("resuming");
  1398. waitHandle = null;
  1399. runTasks();
  1400. }
  1401. },
  1402. //Increments the wait counter and instructs the runner to wait for an async op to finish
  1403. //if the counter is > 0. If count is passed, the wait counter is incremented by that amount.
  1404. //parameters:
  1405. // * timeout - time (in milliseconds) to wait before timing out. Defaults to DEFAULT_TIMEOUT
  1406. // * count - amount to increment counter by. Defaults to 1
  1407. //returns:
  1408. // * the waitHandle produced by setTimeout
  1409. wait: function (timeout, count) {
  1410. count = count || 1;
  1411. timeout = timeout || DEFAULT_TIMEOUT;
  1412. waitCount += count;
  1413. if (waitCount > 0) {
  1414. transitionTo("waiting");
  1415. waitHandle = setTimeout && setTimeout(function () {
  1416. transitionTo("timeout");
  1417. runTasks();
  1418. }, timeout);
  1419. return waitHandle;
  1420. }
  1421. },
  1422. // Create a new test object with the properties specified in obj.
  1423. addTest: function (obj) {
  1424. var test = new TestCase();
  1425. for (var prop in obj) {
  1426. test[prop] = obj[prop]
  1427. }
  1428. test.AddTest();
  1429. },
  1430. globalSetup: function (callback) {
  1431. globalSetups.push(wrapGlobalOperation("global setup", callback));
  1432. },
  1433. globalTeardown: function (callback) {
  1434. globalTeardowns.push(wrapGlobalOperation("global teardown", callback));
  1435. },
  1436. //sets the scheduler for the runner. Note that this doesn't (currently) unregister the old scheduler.
  1437. //As part of registering the scheduler, the 'schedule' and 'prepend' events are registered for pub/sub
  1438. //parameters:
  1439. // * sched - new scheduler object
  1440. setScheduler: function (sched) {
  1441. scheduler = sched;
  1442. runner.subscribe("schedule", sched.schedule);
  1443. }
  1444. };
  1445. })();
  1446. for (var i = 0; i < loggers.length; i++)
  1447. if (loggers[i].shouldEnable())
  1448. runner.subscribe(new loggers[i]());
  1449. // holds the list of tasks that need to be scheduled. Running is currently destructive to this list
  1450. var tasks = [];
  1451. // holds the list of tasks that have been run already, so that tasks[] list can be restored after the run
  1452. var ranTasks = [];
  1453. window.runsExecuted = 0;
  1454. window.runsToExecute = Utils.getMaxInterpretCount() + 1;
  1455. // populate and return default scheduler object
  1456. var defaultScheduler = (function () {
  1457. return {
  1458. //adds an item to the tail of the list. If the item has a tasks property that is a function
  1459. //the return value of that function is used instead of this item
  1460. //parameters:
  1461. // * item - item to schedule
  1462. schedule: function (item) {
  1463. var items;
  1464. if (item.tasks && typeof item.tasks === "function")
  1465. items = item.tasks();
  1466. else
  1467. items = [item];
  1468. for (var i = 0; i < items.length; i++)
  1469. tasks.push(items[i]);
  1470. },
  1471. //prepends an item or array to the list. If the item is an array, it is concatenated onto
  1472. //the front of the list (i.e. single level flatten). Otherwise it is just put into the list
  1473. //parameters:
  1474. // * obj - item to put onto the front of the list
  1475. prepend: function (obj) {
  1476. var type = hoozit(obj);
  1477. if (type === "array") {
  1478. for (var i = obj.length - 1; i >= 0; i--) {
  1479. tasks.unshift(obj[i]);
  1480. }
  1481. } else {
  1482. tasks.unshift(obj);
  1483. }
  1484. },
  1485. //appends an item or array to the list. If the item is an array, it is concatenated onto
  1486. //the end of the list (i.e. single level flatten). Otherwise it is just put into the list
  1487. //parameters:
  1488. // * obj - item to put onto the end of the list
  1489. push: function (obj) {
  1490. var type = hoozit(obj);
  1491. if (type === "array") {
  1492. for (var i = 0; i < obj.length; i++) {
  1493. tasks.push(obj[i]);
  1494. }
  1495. } else {
  1496. tasks.push(obj);
  1497. }
  1498. },
  1499. //returns the next task to run
  1500. //returns:
  1501. //the next task to run or null if there are no more tasks
  1502. next: function () {
  1503. var task = null;
  1504. if (tasks.length > 0) {
  1505. task = tasks.shift();
  1506. ranTasks.push(task);
  1507. }
  1508. return task;
  1509. }
  1510. };
  1511. })();
  1512. runner.setScheduler(defaultScheduler);
  1513. ///////////////////////////////////////////////////////////////////////////////
  1514. // Test Runner
  1515. ///////////////////////////////////////////////////////////////////////////////
  1516. var currentTest;
  1517. var testPassed;
  1518. // A test case object
  1519. var TestCase = function () {
  1520. //close over this for the tasks method
  1521. var testCase = this;
  1522. // Flag to execute the test in global scope
  1523. this.useGlobalThis = false;
  1524. this.baselineFile = false;
  1525. this.baselineHandler = 0;
  1526. this.baselineCounter = 0;
  1527. this.pass = true;
  1528. this.AddTest = function () {
  1529. // Function to add use test case to testCases list
  1530. if ((this.id === undefined) || (this.id === "")) {
  1531. runner.publish('comment', "Test case id is not valid ");
  1532. } else if (this.desc === undefined || this.desc === "") {
  1533. runner.publish('comment', "Test case description not specified");
  1534. } else if (this.preReq && (!(typeof (this.preReq) === "function"))) {
  1535. runner.publish('comment', "Invalid preReq function");
  1536. } else if ((this.test === undefined) || (!(typeof (this.test) === "function"))) {
  1537. runner.publish('comment', "Invalid test function");
  1538. } else {
  1539. runner.publish('schedule', this);
  1540. }
  1541. };
  1542. //splits the test work into setup, test and cleanup. This allows the runner to pause
  1543. //between the test task and the cleanup task in order to wait for async operations
  1544. //returns:
  1545. // - an array of functions
  1546. this.tasks = function () {
  1547. function setup() {
  1548. testPassed = true;
  1549. currentTest = testCase;
  1550. runner.publish('testStart', currentTest);
  1551. }
  1552. function test() {
  1553. // if (!Utils.IEMatchesArch()) {
  1554. // throw new Error("IE architecture setting does not match Processor architecture and run settings: " + Utils.getIEArchitecture());
  1555. // }
  1556. if (!currentTest.preReq || currentTest.preReq()) {
  1557. try {
  1558. if (currentTest.useGlobalThis) {
  1559. testFunc = currentTest.test;
  1560. testFunc();
  1561. } else {
  1562. currentTest.test();
  1563. }
  1564. } catch (e) {
  1565. currentTest.error = e;
  1566. }
  1567. } else {
  1568. runner.publish('comment', "Test prereq returned false. Skipping");
  1569. }
  1570. }
  1571. function cleanup() {
  1572. if (currentTest.error !== undefined) {
  1573. runner.publish('error', currentTest, currentTest.error);
  1574. } else if (testPassed) {
  1575. runner.publish('pass', currentTest);
  1576. } else {
  1577. runner.publish('fail', currentTest);
  1578. }
  1579. runner.publish('testEnd', currentTest);
  1580. }
  1581. return [setup, test, cleanup];
  1582. }
  1583. }
  1584. /*
  1585. * Baseline test cases
  1586. */
  1587. function addEscapeCharacter(txt) {
  1588. txt = txt.replace(/\\/g, "\\\\");
  1589. txt = txt.replace(/\"/g, "\\\"");
  1590. txt = txt.replace(/\'/g, "\\\'");
  1591. txt = txt.replace(/\r/g, "\\r");
  1592. txt = txt.replace(/\n/g, "\\n");
  1593. return txt;
  1594. }
  1595. //Testcase that will use baseline support
  1596. function BaselineTestCase() {
  1597. //close over this for the tasks method
  1598. var testCase = this;
  1599. // Flag to execute the test in global scope
  1600. this.useGlobalThis = false;
  1601. this.baselineFile = false;
  1602. this.baselineHandler = 0;
  1603. this.baselineCounter = 0;
  1604. this.pass = true;
  1605. this.AddTest = function () {
  1606. // Function to add use test case to testCases list
  1607. if ((this.id === undefined) || (this.id === "")) {
  1608. runner.publish('comment', "Test case id is not valid ");
  1609. } else if (this.desc === undefined || this.desc === "") {
  1610. runner.publish('comment', "Test case description not specified");
  1611. } else if (this.preReq && (!(typeof (this.preReq) === "function"))) {
  1612. runner.publish('comment', "Invalid preReq function");
  1613. } else if ((this.test === undefined) || (!(typeof (this.test) === "function"))) {
  1614. runner.publish('comment', "Invalid test function");
  1615. } else {
  1616. runner.publish('schedule', this);
  1617. }
  1618. };
  1619. //splits the test work into setup, test and cleanup. This allows the runner to pause
  1620. //between the test task and the cleanup task in order to wait for async operations
  1621. //returns:
  1622. // - an array of functions
  1623. this.tasks = function () {
  1624. function setup() {
  1625. testPassed = true;
  1626. currentTest = testCase;
  1627. BaselineTestCase.startBaseline();
  1628. runner.publish('testStart', currentTest);
  1629. }
  1630. function test() {
  1631. if (!currentTest.preReq || currentTest.preReq()) {
  1632. try {
  1633. if (currentTest.useGlobalThis) {
  1634. testFunc = currentTest.test;
  1635. testFunc();
  1636. } else {
  1637. currentTest.test();
  1638. }
  1639. } catch (e) {
  1640. currentTest.error = e;
  1641. }
  1642. } else {
  1643. runner.publish('comment', "Test prereq returned false. Skipping");
  1644. }
  1645. }
  1646. function cleanup() {
  1647. if (currentTest.error !== undefined) {
  1648. runner.publish('error', currentTest, currentTest.error);
  1649. } else if (testPassed) {
  1650. runner.publish('pass', currentTest);
  1651. } else {
  1652. runner.publish('fail', currentTest);
  1653. }
  1654. BaselineTestCase.stopBaseline();
  1655. runner.publish('testEnd', currentTest);
  1656. }
  1657. return [setup, test, cleanup];
  1658. }
  1659. }
  1660. //Static variables for BaselineTestCase
  1661. BaselineTestCase.baselineFileExt = ".baseline.js";
  1662. BaselineTestCase.editMode = false;
  1663. BaselineTestCase.useGlobalBaseline = false;
  1664. BaselineTestCase.fileName = null;
  1665. BaselineTestCase.fileHandler = null;
  1666. BaselineTestCase.elementIndexInFile = 0;
  1667. BaselineTestCase.currentTestcaseID = 0;
  1668. //Static methods for BaselineTestCase
  1669. BaselineTestCase.constructBLFileName = function (testCaseID) {
  1670. var filePath = window.location.href;
  1671. var fileName = filePath.substring(filePath.lastIndexOf("/") + 1);
  1672. fileName = fileName.substring(0, fileName.lastIndexOf("."));
  1673. if (typeof (testCaseID) == "undefined") {
  1674. fileName = fileName + "." + getHOSTMode() + BaselineTestCase.baselineFileExt;
  1675. }
  1676. else {
  1677. testCaseID = String(testCaseID).replace(/[^a-zA-Z 0-9]+/g, "_");
  1678. fileName = fileName + testCaseID + "." + getHOSTMode() + BaselineTestCase.baselineFileExt;
  1679. }
  1680. var baselineFilePath = filePath.substring(0, filePath.lastIndexOf("/") + 1) + fileName;
  1681. //redirecting the baseline file path to js directory when we find EzeHtmlTestFiles directory structure
  1682. baselineFilePath = baselineFilePath.replace(/EzeHtmlTestFiles/, "EzeJSTestFiles");
  1683. // mutator local run will fail in baseline testcases if don't reset this counters
  1684. BaselineTestCase.elementIndexInFile = 0;
  1685. BaselineTestCase.currentTestcaseID = 0;
  1686. //loadjsfile(baselineFilePath);
  1687. return baselineFilePath;
  1688. }
  1689. BaselineTestCase.openBaseline = function (fileName) {
  1690. var objFSO = createActiveXObject("Scripting.FileSystemObject");
  1691. if (fileName.indexOf("file:///") > -1) fileName = fileName.substring(8);
  1692. BaselineTestCase.fileHandler = objFSO.CreateTextFile(fileName, true);
  1693. BaselineTestCase.fileHandler.WriteLine("var baselineExpArr = [");
  1694. }
  1695. BaselineTestCase.closeBaseline = function () {
  1696. if (BaselineTestCase.editMode) {
  1697. BaselineTestCase.fileHandler.WriteLine();
  1698. BaselineTestCase.fileHandler.WriteLine("];");
  1699. BaselineTestCase.fileHandler.Close();
  1700. }
  1701. else {
  1702. //If there is more elements in the baseline file has not been compared, fail the test.
  1703. if (typeof (baselineExpArr) != "undefined") {
  1704. if (BaselineTestCase.elementIndexInFile < baselineExpArr.length) {
  1705. fail("There is more elements in baseline file than expected. Total element in baselinefile=" + baselineExpArr.length + ", expected=" + BaselineTestCase.elementIndexInFile);
  1706. }
  1707. }
  1708. if (!BaselineTestCase.useGlobalBaseline) {
  1709. BaselineTestCase.elementIndexInFile = 0;
  1710. BaselineTestCase.fileHandler = 0;
  1711. }
  1712. }
  1713. }
  1714. BaselineTestCase.verify = function (act, msg) {
  1715. if (BaselineTestCase.editMode) {
  1716. if (BaselineTestCase.elementIndexInFile > 0) {
  1717. BaselineTestCase.fileHandler.WriteLine(",");
  1718. }
  1719. var escapedAct = act;
  1720. if (act instanceof String || typeof act == "string") {
  1721. escapedAct = addEscapeCharacter(act);
  1722. }
  1723. if (escapedAct != null) //don't add quotes to null values
  1724. {
  1725. BaselineTestCase.fileHandler.Write("\"" + escapedAct + "\"");
  1726. }
  1727. else {
  1728. BaselineTestCase.fileHandler.Write("null");
  1729. }
  1730. BaselineTestCase.elementIndexInFile++;
  1731. }
  1732. else {
  1733. if (BaselineTestCase.elementIndexInFile >= baselineExpArr.length) {
  1734. fail("Test is expecting more elements in baseline file.Expecting " + (BaselineTestCase.elementIndexInFile + 1) + ", actual = " + baselineExpArr.length);
  1735. }
  1736. else {
  1737. var exp = baselineExpArr[BaselineTestCase.elementIndexInFile++];
  1738. if (act != null && act.toString)
  1739. verify(act.toString(), exp, msg);
  1740. else
  1741. verify(act, exp, msg);
  1742. }
  1743. }
  1744. }
  1745. BaselineTestCase.loadBaseline = function (fileName) {
  1746. var loadSuccess = true;
  1747. var oXmlHttp = new XMLHttpRequest();
  1748. oXmlHttp.OnReadyStateChange = function () {
  1749. if (oXmlHttp.readyState == 4) {
  1750. //XmlHttpRequest will return 0 if we request a file from local disk
  1751. //Return value 200 on succees only if we request a file from web server
  1752. if (oXmlHttp.status == 200 || window.location.href.indexOf("http") == -1) {
  1753. if (fileName != null) {
  1754. if (document.getElementById("blScriptTag") == null) {
  1755. var header = document.getElementsByTagName('HEAD').item(0);
  1756. var oScript = document.createElement("script");
  1757. oScript.language = "javascript";
  1758. oScript.type = "text/javascript";
  1759. oScript.defer = true;
  1760. oScript.id = "blScriptTag";
  1761. oScript.text = oXmlHttp.responseText;
  1762. header.appendChild(oScript);
  1763. }
  1764. else {
  1765. //Get response text and strip the "var baselineExpArr =" then assign the new value to baselineExpArr
  1766. var a = oXmlHttp.responseText;
  1767. baselineExpArr = eval(a.substring(a.indexOf("=") + 1, a.length - 2));
  1768. }
  1769. }
  1770. }
  1771. else {
  1772. loadSuccess = false;
  1773. }
  1774. }
  1775. }
  1776. oXmlHttp.open('GET', fileName, false);
  1777. oXmlHttp.send(null);
  1778. if (!loadSuccess) throw new Error('XML request error for file ' + fileName + ': ' + oXmlHttp.statusText + ' (' + oXmlHttp.status + ')');
  1779. }
  1780. BaselineTestCase.startBaseline = function () {
  1781. if (BaselineTestCase.useGlobalBaseline)
  1782. return;
  1783. //Set baseline file name based on the fileName from Run method and test id
  1784. //This block will be executed we are not using global baseline
  1785. if (currentTest instanceof BaselineTestCase) {
  1786. //Create baseline file if baselineEditMode is true, otherwise load the js file
  1787. if (BaselineTestCase.editMode) {
  1788. BaselineTestCase.openBaseline(BaselineTestCase.constructBLFileName(currentTest.id));
  1789. }
  1790. else {
  1791. BaselineTestCase.loadBaseline(BaselineTestCase.constructBLFileName(currentTest.id));
  1792. }
  1793. }
  1794. }
  1795. BaselineTestCase.stopBaseline = function () {
  1796. if (BaselineTestCase.useGlobalBaseline)
  1797. return;
  1798. if (currentTest instanceof BaselineTestCase) {
  1799. //Close the baseline file
  1800. BaselineTestCase.closeBaseline();
  1801. }
  1802. BaselineTestCase.currentTestcaseID++;
  1803. }
  1804. BaselineTestCase.startGlobalBaseline = function () {
  1805. if (!BaselineTestCase.useGlobalBaseline)
  1806. return;
  1807. try {
  1808. //Open baseline file if we use global baseline (one baseline for all test)
  1809. if (BaselineTestCase.editMode) {
  1810. BaselineTestCase.openBaseline(BaselineTestCase.constructBLFileName());
  1811. }
  1812. //load the global baseline file
  1813. else {
  1814. BaselineTestCase.loadBaseline(BaselineTestCase.constructBLFileName());
  1815. }
  1816. }
  1817. catch (e) {
  1818. fail("Exception occured on opening baseline file with message: " + e.message);
  1819. }
  1820. }
  1821. BaselineTestCase.stopGlobalBaseline = function () {
  1822. if (!BaselineTestCase.useGlobalBaseline)
  1823. return;
  1824. try {
  1825. //Close the baseline file (only if we use global baseline file)
  1826. BaselineTestCase.closeBaseline();
  1827. }
  1828. catch (e) {
  1829. fail("Exception occured on closing baseline file with message: " + e.message);
  1830. }
  1831. }
  1832. // Subscribe to various events to set up baseline.
  1833. runner.subscribe('start', BaselineTestCase.startGlobalBaseline);
  1834. runner.subscribe('end', BaselineTestCase.stopGlobalBaseline);
  1835. /*
  1836. * This object facilitates testing cross-context scenarios. Create a new instance first to getcd
  1837. * started. See http://devdiv/sites/bpt/team/eze/Eze%20Wiki/Cross%20Context%20Test%20Framework.aspx
  1838. * for documentation.
  1839. */
  1840. var CrossContextTest = function () {
  1841. var cct = this;
  1842. cct.testIframe = true;
  1843. cct.testWindow = (Utils.getHOSTType() == Utils.WWAHOST) ? false : true;
  1844. var waitingForReady = false;
  1845. var readyCallbacks = [];
  1846. var childFunctions = [];
  1847. var childProperties = {};
  1848. /*
  1849. * Wait for the document to be ready for DOM updates.
  1850. * This should be updated to use DOMContentReady when that is supported.
  1851. */
  1852. function onReady(callback) {
  1853. // Check if we're already ready, and if so, just call the callback.
  1854. if (document.readyState == "complete") {
  1855. callback.call();
  1856. return;
  1857. }
  1858. // Otherwise, push to our ready list and start waiting.
  1859. readyCallbacks.push(callback);
  1860. // If we're not already waiting, wait for document ready and call callbacks.
  1861. if (!waitingForReady) {
  1862. waitingForReady = true;
  1863. waitForReady();
  1864. }
  1865. }
  1866. /*
  1867. * Wait until doScroll doesn't throw an exception, and then run all the callbacks.
  1868. */
  1869. function waitForReady() {
  1870. // Otherwise use the oft-used doScroll hack which, according to MSDN, will always thrown an
  1871. // error unless the document is ready.
  1872. try {
  1873. document.documentElement.doScroll("left");
  1874. }
  1875. catch (e) {
  1876. // We're not ready yet. Check again in a bit.
  1877. setTimeout(waitForReady, 1);
  1878. return;
  1879. }
  1880. // Assume we're ready, so call all the callbacks.
  1881. for (var i = 0; i < readyCallbacks.length; i++) {
  1882. readyCallbacks[i].call();
  1883. }
  1884. }
  1885. /*
  1886. * Sets any properties on the newly opened window.
  1887. * be careful -- this only reference obj from parent context
  1888. */
  1889. function setChildWindowProperties(win) {
  1890. for (var prop in childProperties) {
  1891. win[prop] = childProperties[prop];
  1892. }
  1893. }
  1894. /*
  1895. * Writes the HTML to the child window by appending HTML tag. Used for WWA
  1896. * * parentWindow, that refers to either window.parent or window.opener, depending on if this is a
  1897. * popup window or an iframe,
  1898. * Append html, head, body and script content to iframe/popup window
  1899. */
  1900. function AppendChildHtml(doc) {
  1901. function createChildTag(tagName, attributes) {
  1902. tag = doc.createElement(tagName);
  1903. for (var k in attributes) {
  1904. tag.setAttribute(k, attributes[k]);
  1905. }
  1906. return tag;
  1907. }
  1908. doc.open();
  1909. doc.write("<html><head></head><body></body></html>");
  1910. doc.close();
  1911. var head = doc.getElementsByTagName("head")[0];
  1912. var meta1 = createChildTag('meta', {
  1913. 'http-equiv': '"X-UA-Compatible"',
  1914. 'content': '"IE=' + document.documentMode + '"'
  1915. }
  1916. );
  1917. head.appendChild(meta1);
  1918. // add the body content
  1919. if (typeof cct.childContent !== 'undefined') {
  1920. var body = doc.getElementsByTagName("body")[0];
  1921. body.innerHTML = cct.childContent;
  1922. }
  1923. // this function will be sent to child, be called when the script load complete
  1924. function __init__(sender) {
  1925. parentWindow = window.parent == window ? window.opener : window.parent;
  1926. if (sender.readyState == "complete") {
  1927. sender.onreadystatechange = null;
  1928. parentWindow.childReady.ready(); // notify parent to start test
  1929. }
  1930. }
  1931. // init the script
  1932. var script = createChildTag('script', {
  1933. type: 'text/javascript',
  1934. onreadystatechange: "iamready(this)"
  1935. }
  1936. );
  1937. script.text += __init__.toString() + "\n" + "var iamready = __init__;\n";
  1938. // write the childFunctions
  1939. for (var i = 0; i < childFunctions.length; i++) {
  1940. script.text += childFunctions[i].toString() + "\n";
  1941. }
  1942. head.appendChild(script);
  1943. }
  1944. /*
  1945. * Writes html content to doc. Used for IE
  1946. * * parentWindow, that refers to either window.parent or window.opener, depending on if this is a
  1947. * popup window or an iframe,
  1948. */
  1949. function WriteChildHtml(doc) {
  1950. doc.open();
  1951. doc.write("<html>\n<head>\n");
  1952. doc.write("<meta http-equiv=\"X-UA-Compatible\" content=\"IE=" + document.documentMode + "\" />\n");
  1953. doc.write("<scri" + "pt type='text/javascript'>\n");
  1954. doc.write("var parentWindow = window.parent == window ? window.opener : window.parent;\n");
  1955. //// function waitForReady will sent to child, to determin if child is ready
  1956. function waitForReady() {
  1957. if (document.addEventListener) {
  1958. document.addEventListener("DOMContentLoaded", whenDomReady, false);
  1959. } else {
  1960. setTimeout(waitForDomReady, 1);
  1961. }
  1962. function waitForDomReady() {
  1963. // Otherwise use the oft-used doScroll hack which, according to MSDN, will always thrown an
  1964. // error unless the document is ready.
  1965. try {
  1966. document.documentElement.doScroll("left");
  1967. }
  1968. catch (e) {
  1969. // We're not ready yet. Check again in a bit.
  1970. setTimeout(waitForDomReady, 1);
  1971. return;
  1972. }
  1973. whenDomReady();
  1974. }
  1975. function whenDomReady() {
  1976. parentWindow.childReady.ready();
  1977. }
  1978. }
  1979. //////
  1980. doc.write(waitForReady.toString() + "\n");
  1981. doc.write("waitForReady();\n");
  1982. for (var i = 0; i < childFunctions.length; i++) {
  1983. doc.write(childFunctions[i].toString() + "\n");
  1984. }
  1985. doc.write("</scr" + "ipt>\n</head>\n<body>\n");
  1986. if (cct.childContent !== undefined) doc.write(cct.childContent)
  1987. doc.write("</body></html>");
  1988. doc.close();
  1989. }
  1990. var writeChildContent = (Utils.getHOSTType() == Utils.WWAHOST) ? AppendChildHtml : WriteChildHtml;
  1991. // Set either of these to control the content of the child windows.
  1992. this.childContent = undefined;
  1993. /*
  1994. * If we have Loader42Log, use that to log comments, otherwise use a nop. This is merely a
  1995. * default and can be overridden by users should they need custom logging.
  1996. */
  1997. if (typeof window.logger !== 'undefined') {
  1998. this.comment = logger.comment;
  1999. } else {
  2000. this.comment = new Function();
  2001. }
  2002. /*
  2003. * Add a function to the list of functions to append to the child windows.
  2004. * NOTE: While when you define these functions they look like closures, they are not used as such.
  2005. * The toString representation is appended to the new windows, destroying any scope you might have
  2006. * set up.
  2007. */
  2008. this.addChildFunction = function (func) {
  2009. childFunctions.push(func);
  2010. }
  2011. /*
  2012. * Add a property to the list of properties to give to the child windows.
  2013. */
  2014. this.addChildProperty = function (name, value) {
  2015. childProperties[name] = value;
  2016. }
  2017. function ChildReady(waitHandle) {
  2018. this.waitHandle = waitHandle;
  2019. this.ready = function () {
  2020. runner.start(this.waitHandle);
  2021. }
  2022. }
  2023. var prepareIframe = function () {
  2024. cct.comment("Starting iframe tests");
  2025. cct.frame = document.createElement('iframe');
  2026. document.body.appendChild(cct.frame);
  2027. var waitHandle = runner.wait();
  2028. window.childReady = new ChildReady(waitHandle);
  2029. writeChildContent(cct.frame.contentDocument ? cct.frame.contentDocument : cct.frame.contentWindow.document);
  2030. }
  2031. var runIframe = function () {
  2032. if (typeof BaselineTestCase !== 'undefined' && typeof mutator !== 'undefined') {
  2033. // save the check point for window.open
  2034. cct.baselineTCElementIndexInFile = BaselineTestCase.elementIndexInFile;
  2035. }
  2036. setChildWindowProperties(cct.frame.contentWindow);
  2037. try {
  2038. cct.callback.call(undefined, cct.frame.contentWindow);
  2039. }
  2040. catch (e) {
  2041. currentTest.error = e;
  2042. }
  2043. }
  2044. var cleanupIframe = function () {
  2045. window.childReady = undefined;
  2046. // Remove the iframe when we're done so it doesn't interfere with any other tests.
  2047. document.body.removeChild(cct.frame);
  2048. }
  2049. var preparePopWin = function () {
  2050. cct.comment("Starting new window tests");
  2051. cct.win = window.open();
  2052. var waitHandle = runner.wait();
  2053. window.childReady = new ChildReady(waitHandle);
  2054. writeChildContent(cct.win.document);
  2055. }
  2056. var runPopWin = function () {
  2057. if (typeof BaselineTestCase !== 'undefined' && typeof mutator !== 'undefined') {
  2058. // save the check point for window.open
  2059. BaselineTestCase.elementIndexInFile = cct.baselineTCElementIndexInFile;
  2060. }
  2061. setChildWindowProperties(cct.win);
  2062. try {
  2063. cct.callback.call(undefined, cct.win);
  2064. }
  2065. catch (e) {
  2066. currentTest.error = e;
  2067. }
  2068. }
  2069. var cleanupPopWin = function () {
  2070. window.childReady = undefined;
  2071. cct.win.close();
  2072. window.parentWaitHandle = undefined;
  2073. // make sure the popup window is closed and then move on
  2074. var waitHandle = runner.wait();
  2075. setTimeout(function () {
  2076. try {
  2077. if (!cct.win.closed) {
  2078. setTimeout(arguments.callee, 10);
  2079. return;
  2080. }
  2081. } catch (e) { }
  2082. runner.start(waitHandle);
  2083. }, 10);
  2084. }
  2085. /*
  2086. * Run a test. Do any verification in the callback. The callback will be called with the new
  2087. * window as the first parameter. If you want to wait for the document to be ready, pass true
  2088. * for the second parameter. You should note that this will currently break our test framework
  2089. * as nothing in the test function body can be asyncrhonous. When a test is asynchronous, the
  2090. * test will pass (with no verify statements executed) while the verifies wait in the
  2091. * background for the document to become ready.
  2092. */
  2093. this.test = function (callback, waitForReady) {
  2094. var run = function () {
  2095. cct.callback = callback;
  2096. if (cct.testWindow) {
  2097. // Test with window.open
  2098. scheduler.prepend([preparePopWin, runPopWin, cleanupPopWin]);
  2099. }
  2100. if (cct.testIframe) {
  2101. // Test with iframe.
  2102. scheduler.prepend([prepareIframe, runIframe, cleanupIframe]);
  2103. }
  2104. };
  2105. if (waitForReady) onReady(run);
  2106. else run();
  2107. }
  2108. }
  2109. //Mutator support
  2110. var mutator;
  2111. // env will be the empty string if the environment variable is not present.
  2112. var env = "";
  2113. try {
  2114. env = (createActiveXObject("WScript.Shell")).Environment("Process")("JScript_Mutators");
  2115. if (env.length > 0)
  2116. runner.mutators = env.split(",");
  2117. } catch (e) { }
  2118. (function () {
  2119. var originalTest;
  2120. runner.subscribe('testStart', function (test) {
  2121. if (runner.mutators.length === 0)
  2122. return;
  2123. try {
  2124. if (typeof mutator === "undefined")
  2125. mutator = createActiveXObject("MutatorsHost.MutatorsActiveX");
  2126. runner.publish('comment', "Mutating with " + runner.mutators.join(","));
  2127. originalTest = test.test;
  2128. originalTestString = originalTest.toString();
  2129. // Parse out just the function body to mutate.
  2130. testBody = originalTestString.substring(originalTestString.indexOf("{") + 1,
  2131. originalTestString.lastIndexOf("}"));
  2132. newTestString = mutator.Mutate(runner.mutators.join(","), testBody);
  2133. // Create a new function with the mutated function body. Note that this destroys the
  2134. // lexical environment of the original test function, so test code that relies on
  2135. // identifiers declared outside of the function body but not in global scope will fail.
  2136. test.test = new Function(newTestString);
  2137. runner.publish('comment', "<pre>" + test.test.toString() + "</pre>");
  2138. } catch (e) { }
  2139. })
  2140. /* Restore the original test object after the test has finished.
  2141. */
  2142. runner.subscribe('testEnd', function (test) {
  2143. if (runner.mutators.length === 0)
  2144. return;
  2145. test.test = originalTest;
  2146. })
  2147. })()
  2148. /****************************************************************************
  2149. //Function for stress testing that determines if the test group should loop again
  2150. //Currently not working as scheduler does not call this function.
  2151. //Need to change the stressLogger to StressLogger.shouldEnable()
  2152. ****************************************************************************/
  2153. function ContinueTestGroupIteration() {
  2154. if (typeof stressLogger !== "undefined") {
  2155. stressLogger.CurrentTestGroupIteration++;
  2156. if (stressLogger.Config.RuntimeIterations < stressLogger.CurrentTestGroupIteration) {
  2157. return false;
  2158. }
  2159. return true;
  2160. }
  2161. return false;
  2162. }
  2163. ///////////////////////////////////////////////////////////////////////////////
  2164. // Verification functions.
  2165. ///////////////////////////////////////////////////////////////////////////////
  2166. //the wrapping function is really just to allow folding in editors
  2167. var verify = (function () {
  2168. function verify(act, exp, msg) {
  2169. var result = equiv(act, exp);
  2170. testPassed = testPassed && result;
  2171. runner.publish('verify', currentTest, result, act, exp, msg);
  2172. }
  2173. verify.equal = verify;
  2174. verify.notEqual = function (act, exp, msg) {
  2175. var result = !equiv(act, exp);
  2176. testPassed = testPassed && result;
  2177. runner.publish('verify', currentTest, result, act, "not " + exp, msg);
  2178. };
  2179. verify.strictEqual = function (act, exp, msg) {
  2180. var result = act === exp;
  2181. testPassed = testPassed && result;
  2182. runner.publish('verify', currentTest, result, act, exp, msg);
  2183. }
  2184. verify.notStrictEqual = function (act, exp, msg) {
  2185. var result = act !== exp;
  2186. testPassed = testPassed && result;
  2187. runner.publish('verify', currentTest, result, act, "not " + exp, msg);
  2188. }
  2189. verify.noException = function (callback, msg) {
  2190. try {
  2191. var res = callback();
  2192. verify.equal(res, res, msg);
  2193. } catch (e) {
  2194. verify.equal(res, "no exception", msg);
  2195. }
  2196. };
  2197. verify.exception = function (callback, exception, msg) {
  2198. try {
  2199. var res = callback();
  2200. verify.equal(res, "exception", msg);
  2201. } catch (e) {
  2202. verify.instanceOf(e, exception)
  2203. }
  2204. };
  2205. verify.defined = function (obj, msg) {
  2206. return verify.notStrictEqual(obj, undefined, msg + " should be defined");
  2207. };
  2208. verify.notDefined = function (obj, msg) {
  2209. return verify.strictEqual(obj, undefined, msg + " should not be defined");
  2210. };
  2211. verify.typeOf = function (obj, expected) {
  2212. return verify.equal(typeof obj, expected, "typeof " + obj);
  2213. };
  2214. verify.instanceOf = function (obj, expected) {
  2215. return verify.equal(obj instanceof expected, true, "instanceof " + obj);
  2216. };
  2217. return verify;
  2218. })();
  2219. function fail(msg) {
  2220. verify(true, false, msg);
  2221. }
  2222. function assert(condition, msg) {
  2223. verify(condition, true, msg);
  2224. }
  2225. ///////////////////////////////////////////////////////////////////////////////
  2226. // Below here is code to support the old test case format. These old test
  2227. // cases call a series of ap* functions directly. The object below basically
  2228. // proxies calls to ap* functions to the appropriate logger. Because the old
  2229. // test case format doesn't instantiate a test case object, the code below
  2230. // creates a stub to pass to the loggers.
  2231. ///////////////////////////////////////////////////////////////////////////////
  2232. function OldGlueProxy() {
  2233. var test;
  2234. var testStarted = false;
  2235. var scenarioStarted = false;
  2236. var scenarioPassed = true;
  2237. function finishScenario() {
  2238. if (scenarioPassed)
  2239. runner.publish('pass', test);
  2240. else
  2241. runner.publish('fail', test);
  2242. }
  2243. this.apInitTest = function (name) {
  2244. if (window.runsExecuted == 0) { // In MaxInterprentCount case do it only on first iteration
  2245. if (testStarted)
  2246. runner.publish('end');
  2247. testStarted = true;
  2248. if (typeof Loader42_FileName == 'undefined')
  2249. runner.publish('start', name);
  2250. else
  2251. runner.publish('start', Loader42_FileName);
  2252. }
  2253. }
  2254. this.apInitScenario = function (name) {
  2255. if (scenarioStarted)
  2256. finishScenario();
  2257. var id = /^\d+/.exec(name);
  2258. if (id === null)
  2259. id = "";
  2260. test = { id: id, desc: name, test: Function() };
  2261. runner.publish('testStart', test);
  2262. scenarioStarted = true;
  2263. scenarioPassed = true;
  2264. }
  2265. this.apEndScenario = function () {
  2266. finishScenario();
  2267. scenarioStarted = false;
  2268. }
  2269. this.apLogFailInfo = function (msg, exp, act) {
  2270. runner.publish('verify', test, false, act, exp, msg);
  2271. scenarioPassed = false;
  2272. }
  2273. this.apEndTest = function () {
  2274. if (window.runsExecuted >= window.runsToExecute - 1) { // In MaxInterprentCount case do it only on last iteration
  2275. if (scenarioStarted)
  2276. finishScenario();
  2277. runner.publish('end');
  2278. testStarted = false;
  2279. }
  2280. }
  2281. this.apWriteDebug = function (msg) {
  2282. runner.publish('comment', msg);
  2283. }
  2284. this.VBS_apglobal_init = function () {
  2285. try {
  2286. window.apGlobalObj = createActiveXObject("apgloballib.apglobal");
  2287. } catch (e) {
  2288. // Can't create ActiveX, so make a stub object with the same methods.
  2289. window.apGlobalObj = {
  2290. apInitTest: apInitTest,
  2291. apInitScenario: apInitScenario,
  2292. apLogFailInfo: apLogFailInfo,
  2293. apEndScenario: apEndScenario,
  2294. apEndTest: apEndTest,
  2295. apGetLangExt: function (Lcid) {
  2296. var LangExt = "";
  2297. switch (apGlobalObj.apPrimaryLang(Lcid)) {
  2298. case 0x9:
  2299. LangExt = "EN"; // LANG_ENGLISH
  2300. break;
  2301. case 0xC:
  2302. LangExt = "FR"; // LANG_FRENCH
  2303. break;
  2304. case 0xA:
  2305. LangExt = "ES"; // LANG_SPANISH
  2306. break;
  2307. case 0x7:
  2308. LangExt = "DE"; // LANG_GERMAN
  2309. break;
  2310. case 0x10:
  2311. LangExt = "IT"; // LANG_ITALIAN
  2312. break;
  2313. case 0x16:
  2314. LangExt = "PT"; // LANG_PORTUGUESE
  2315. break;
  2316. case 0x1D:
  2317. LangExt = "SV"; // LANG_SWEDISH
  2318. break;
  2319. case 0x14:
  2320. LangExt = "NO"; // LANG_NORWEGIAN
  2321. break;
  2322. }
  2323. if (LangExt == "") { //Hack for DBCS
  2324. switch (Lcid) {
  2325. case 0x411:
  2326. LangExt = "JP"; // LANG_JAPANESE
  2327. break;
  2328. case 0x412:
  2329. LangExt = "KO"; // LANG_KOREAN
  2330. break;
  2331. case 0x404:
  2332. LangExt = "CHT"; // Chinese
  2333. break;
  2334. case 0x804:
  2335. LangExt = "CHS"; // PRC
  2336. break;
  2337. }
  2338. }
  2339. return LangExt;
  2340. },
  2341. apPrimaryLang: function (Lcid) {
  2342. return Lcid & 0x3FF;
  2343. },
  2344. apGetLocFormatDate: function (Lcid, Fmt) {
  2345. var strToken = "";
  2346. switch (Fmt) // am not sure whenstr.toUpper will be supported..
  2347. {
  2348. case "LONG DATE":
  2349. case "long date":
  2350. strToken = "datelong";
  2351. break;
  2352. case "MEDIUM DATE":
  2353. case "medium date":
  2354. strToken = "datemed";
  2355. break;
  2356. case "SHORT DATE":
  2357. case "short date":
  2358. strToken = "dateshort";
  2359. break;
  2360. case "GENERAL DATE":
  2361. case "general date":
  2362. strToken = "gendate";
  2363. break;
  2364. case "LONG TIME":
  2365. case "long time":
  2366. strToken = "timelong";
  2367. break;
  2368. case "MEDIUM TIME":
  2369. case "medium time":
  2370. strToken = "timemed";
  2371. break;
  2372. case "SHORT TIME":
  2373. case "short time":
  2374. strToken = "timeshort";
  2375. break;
  2376. }
  2377. return apGlobalObj.apGetToken(Lcid, "fmt_named_" + strToken, "OLB");
  2378. },
  2379. apGetToken: function (Lcid, strTokenName, strFileName) {
  2380. // not needed right now..
  2381. var strToken = "";
  2382. return (strToken == "") ? "[[Token Not Found]]" : strToken;
  2383. },
  2384. apGetLocInfo: function (Lcid, lctype, ProjectOverride, Flags) { },
  2385. apGetOSVer: function () {
  2386. //not needed
  2387. return "NT;";
  2388. },
  2389. apGetPathName: function () {
  2390. //not needed
  2391. apGlobalObj.apLogFailInfo("FAILURE: TC requested function apGetPathName", "", "", "");
  2392. apGlobalObj.apEndTest();
  2393. return "";
  2394. },
  2395. apGetPlatform: function () {
  2396. //not needed
  2397. return "NT;";
  2398. },
  2399. apGetVolumeName: function (OS) {
  2400. //not needed
  2401. return "NT;";
  2402. },
  2403. LangHost: function () {
  2404. // return GetUserDefaultLCID();
  2405. return 1033;
  2406. },
  2407. apGetLocalizedString: function (resID) {
  2408. return "No localized string returned";
  2409. },
  2410. apGetLocalizedStringWithSubstitution: function (resID, stringSubstitution) {
  2411. return "No localized string returned";
  2412. }
  2413. }
  2414. }
  2415. window.apPlatform = apGlobalObj.apGetPlatform();
  2416. }
  2417. this.apGetLocale = function () {
  2418. return apGlobalObj.LangHost();
  2419. }
  2420. }
  2421. ///////////////////////////////////////////////////////////////////////////////
  2422. // Object Comparison functions.
  2423. ///////////////////////////////////////////////////////////////////////////////
  2424. // Determine what is o.
  2425. function hoozit(o) {
  2426. if (typeof o === "undefined") {
  2427. return "undefined";
  2428. } else if (o === null) {
  2429. return "null";
  2430. } else if (o.constructor === String) {
  2431. return "string";
  2432. } else if (o.constructor === Boolean) {
  2433. return "boolean";
  2434. } else if (o.constructor === Number) {
  2435. if (isNaN(o)) {
  2436. return "nan";
  2437. } else {
  2438. return "number";
  2439. }
  2440. // consider: typeof [] === object
  2441. } else if (o instanceof Array) {
  2442. return "array";
  2443. // consider: typeof new Date() === object
  2444. } else if (o instanceof Date) {
  2445. return "date";
  2446. // consider: /./ instanceof Object;
  2447. // /./ instanceof RegExp;
  2448. // typeof /./ === "function"; // => false in IE and Opera,
  2449. // true in FF and Safari
  2450. } else if (o instanceof RegExp) {
  2451. return "regexp";
  2452. } else if (typeof o === "object") {
  2453. return "object";
  2454. } else if (o instanceof Function) {
  2455. return "function";
  2456. } else {
  2457. return undefined;
  2458. }
  2459. }
  2460. // Call the o related callback with the given arguments.
  2461. function bindCallbacks(o, callbacks, args) {
  2462. var prop = hoozit(o);
  2463. if (prop) {
  2464. if (hoozit(callbacks[prop]) === "function") {
  2465. return callbacks[prop].apply(callbacks, args);
  2466. } else {
  2467. return callbacks[prop]; // or undefined
  2468. }
  2469. }
  2470. }
  2471. // Test for equality any JavaScript type.
  2472. // Discussions and reference: http://philrathe.com/articles/equiv
  2473. // Test suites: http://philrathe.com/tests/equiv
  2474. // Author: Philippe Rath? <[email protected]>
  2475. var equiv = function () {
  2476. var innerEquiv; // the real equiv function
  2477. var callers = []; // stack to decide between skip/abort functions
  2478. var callbacks = function () {
  2479. // for string, boolean, number and null
  2480. function useStrictEquality(b, a) {
  2481. if (b instanceof a.constructor || a instanceof b.constructor) {
  2482. // to catch short annotaion VS 'new' annotation of a declaration
  2483. // e.g. var i = 1;
  2484. // var j = new Number(1);
  2485. return a == b;
  2486. } else {
  2487. return a === b;
  2488. }
  2489. }
  2490. return {
  2491. "string": useStrictEquality,
  2492. "boolean": useStrictEquality,
  2493. "number": useStrictEquality,
  2494. "null": useStrictEquality,
  2495. "undefined": useStrictEquality,
  2496. "nan": function (b) {
  2497. return isNaN(b);
  2498. },
  2499. "date": function (b, a) {
  2500. return hoozit(b) === "date" && a.valueOf() === b.valueOf();
  2501. },
  2502. "regexp": function (b, a) {
  2503. return hoozit(b) === "regexp" &&
  2504. a.source === b.source && // the regex itself
  2505. a.global === b.global && // and its modifers (gmi) ...
  2506. a.ignoreCase === b.ignoreCase &&
  2507. a.multiline === b.multiline;
  2508. },
  2509. // - skip when the property is a method of an instance (OOP)
  2510. // - abort otherwise,
  2511. // initial === would have catch identical references anyway
  2512. "function": function () {
  2513. var caller = callers[callers.length - 1];
  2514. return caller !== Object &&
  2515. typeof caller !== "undefined";
  2516. },
  2517. "array": function (b, a) {
  2518. var i;
  2519. var len;
  2520. // b could be an object literal here
  2521. if (!(hoozit(b) === "array")) {
  2522. return false;
  2523. }
  2524. len = a.length;
  2525. if (len !== b.length) { // safe and faster
  2526. return false;
  2527. }
  2528. for (i = 0; i < len; i++) {
  2529. if (!innerEquiv(a[i], b[i])) {
  2530. return false;
  2531. }
  2532. }
  2533. return true;
  2534. },
  2535. "object": function (b, a) {
  2536. var i;
  2537. var eq = true; // unless we can proove it
  2538. var aProperties = [], bProperties = []; // collection of strings
  2539. // comparing constructors is more strict than using instanceof
  2540. if (a.constructor !== b.constructor) {
  2541. return false;
  2542. }
  2543. // stack constructor before traversing properties
  2544. callers.push(a.constructor);
  2545. for (i in a) { // be strict: don't ensures hasOwnProperty and go deep
  2546. aProperties.push(i); // collect a's properties
  2547. if (!innerEquiv(a[i], b[i])) {
  2548. eq = false;
  2549. }
  2550. }
  2551. callers.pop(); // unstack, we are done
  2552. for (i in b) {
  2553. bProperties.push(i); // collect b's properties
  2554. }
  2555. // Ensures identical properties name
  2556. return eq && innerEquiv(aProperties, bProperties);
  2557. }
  2558. };
  2559. } ();
  2560. innerEquiv = function () { // can take multiple arguments
  2561. var args = Array.prototype.slice.apply(arguments);
  2562. if (args.length < 2) {
  2563. return true; // end transition
  2564. }
  2565. return (function (a, b) {
  2566. if (a === b) {
  2567. return true; // catch the most you can
  2568. } else if (a === null || b === null || typeof a === "undefined" || typeof b === "undefined" || hoozit(a) !== hoozit(b)) {
  2569. return false; // don't lose time with error prone cases
  2570. } else {
  2571. return bindCallbacks(a, callbacks, [b, a]);
  2572. }
  2573. // apply transition with (1..n) arguments
  2574. })(args[0], args[1]) && arguments.callee.apply(this, args.splice(1, args.length - 1));
  2575. };
  2576. return innerEquiv;
  2577. } ();
  2578. ///////////////////////////////////////////////////////////////////////////////
  2579. //
  2580. // Assign globals to the global object.
  2581. // These are underscore prefixed because they are called by functions of the same name outside the
  2582. // framework closure. This is done because window.verify will not be overwritten by a
  2583. // function verify() {} in global scope, which many old tests depend on.
  2584. //
  2585. ///////////////////////////////////////////////////////////////////////////////
  2586. window._verify = verify;
  2587. window._assert = assert;
  2588. window._fail = fail;
  2589. window.getLocalizedError = Utils.getLocalizedError;
  2590. window.Run = runner.run;
  2591. window.runner = runner;
  2592. window.TestCase = TestCase;
  2593. window.BaselineTestCase = BaselineTestCase;
  2594. window.CrossContextTest = CrossContextTest;
  2595. window.logger = windowLogger;
  2596. // globals for versioning
  2597. window.IE7STANDARDSMODE = Utils.IE7STANDARDSMODE;
  2598. window.IE8STANDARDSMODE = Utils.IE8STANDARDSMODE;
  2599. window.IE9STANDARDSMODE = Utils.IE9STANDARDSMODE;
  2600. window.IE10STANDARDSMODE = Utils.IE10STANDARDSMODE;
  2601. window.IE11STANDARDSMODE = Utils.IE11STANDARDSMODE;
  2602. window.IE12STANDARDSMODE = Utils.IE12STANDARDSMODE;
  2603. window.getHOSTMode = Utils.getHOSTMode;
  2604. window.X86MODE = Utils.X86MODE;
  2605. window.X64MODE = Utils.X64MODE;
  2606. window.ARMMODE = Utils.ARMMODE;
  2607. window.getIEArchitecture = Utils.getIEArchitecture;
  2608. window.Utils = Utils;
  2609. // Function returns true/false based on equality, same as verify, but excludes logging.
  2610. Utils.equiv = equiv;
  2611. // An object to hold various implementational details of our engine that our test cases rely upon
  2612. window.Chakra = {
  2613. // The amount of properties that have to be declared to transition object from path to
  2614. // dictionary type.
  2615. PathToDictionaryTransitionThreshold: 16
  2616. }
  2617. // if this is called, set up globals required for old test cases.
  2618. window.VBS_apglobal_init = function () {
  2619. // Old test cases require conditional compilation in a few cases, so turn it on.
  2620. //@cc_on
  2621. var proxy = new OldGlueProxy();
  2622. window.apInitTest = proxy.apInitTest;
  2623. window.apInitScenario = proxy.apInitScenario;
  2624. window.apEndScenario = proxy.apEndScenario;
  2625. window.apLogFailInfo = proxy.apLogFailInfo;
  2626. window.apEndTest = proxy.apEndTest;
  2627. window.apWriteDebug = proxy.apWriteDebug;
  2628. window.VBS_apglobal_init = proxy.VBS_apglobal_init;
  2629. window.apGetLocale = proxy.apGetLocale;
  2630. proxy.VBS_apglobal_init();
  2631. }
  2632. // It used to be defined via 'function VBS_apglobal_init()'
  2633. // 'window.apGlobalObj' has to be defined
  2634. if (typeof window.apGlobalObj == "undefined") {
  2635. try {
  2636. // Define the object
  2637. window.apGlobalObj = createActiveXObject("apgloballib.apglobal");
  2638. } catch (e) {
  2639. // Cannot instantiate ActiveXObject
  2640. window.apGlobalObj = null;
  2641. }
  2642. }
  2643. })(this);
  2644. // Default version of these verification functions simply call the framework version of them.
  2645. verify = _verify;
  2646. assert = _assert;
  2647. fail = _fail;
  2648. // Disable simple print from doing anything
  2649. VBS_apglobal_init();
  2650. function ScriptEngineMajorVersion() { return 5; }
  2651. function ScriptEngineMinorVersion() { return 8; }
  2652. apGlobalObj.osSetIntlValue = function() { return 0; }
  2653. apGlobalObj.osGetIntlValue = function() { return 0; }