1 /* vim:set ts=2 sw=2 sts=2 et cindent tw=79 ft=javascript: */
3 * Copyright (C) 2007 Sergey Yanovich <ynvich@gmail.com>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public
16 * License along with this program; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
21 const nsCI = Components.interfaces
22 const moduleName = "aaVCTest";
23 const moduleCID = "{c23f7275-3b2f-432a-b2fe-c560b7b0a069}";
24 const moduleContractID = "@aasii.org/abstract/test/vc-base;1";
26 Components.utils.import("resource:///modules/aaTestVC.jsm");
30 * The NSGetModule function is the magic entry point that XPCOM uses to find
31 * what XPCOM components this module provides
33 function NSGetModule(comMgr, fileSpec)
35 var loader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
36 .getService(Components.interfaces.mozIJSSubScriptLoader);
37 loader.loadSubScript("resource:///modules/nsTestFrame.jsm");
39 var aaVCTestModule = new JSTestModule();
40 aaVCTestModule.init = ModuleInit;
41 aaVCTestModule.init();
42 return aaVCTestModule;
47 this._name = moduleName;
48 this._CID = Components.ID(moduleCID);
49 this._contractID = moduleContractID;
52 this._add(top_CID, top_contractID, top_name, top_test, top_check);
54 this._add(show_entity_CID, show_entity_contractID, show_entity_name,
55 show_entity_test, show_entity_check);
57 this._add(entity_CID, entity_contractID, entity_name, entity_test, null);
59 this._add(show_resource_CID, show_resource_contractID, show_resource_name,
60 show_resource_test, show_resource_check);
62 this._add(resource_CID, resource_contractID, resource_name, resource_test, null);
64 this._add(flow_CID, flow_contractID, flow_name, flow_test, flow_page_check);
66 this._add(flow_entity_CID, flow_entity_contractID, flow_entity_name,
67 flow_entity_test, flow_entity_check);
69 this._add(entity_discard_CID, entity_discard_contractID, entity_discard_name,
70 entity_discard_test, entity_discard_check);
74 this._add(entity_submit_CID, entity_submit_contractID, entity_submit_name,
75 entity_submit_test, entity_submit_check);
77 this._add(flow_give_CID, flow_give_contractID, flow_give_name,
78 flow_give_test, flow_resource_check);
80 this._add(give_discard_CID, give_discard_contractID, give_discard_name,
81 resource_discard_test, give_discard_check);
85 this._add(give_submit_CID, give_submit_contractID, give_submit_name,
86 resource_submit_test, give_submit_check);
88 this._add(flow_take_CID, flow_take_contractID, flow_take_name,
89 flow_take_test, flow_resource_check);
91 this._add(take_discard_CID, take_discard_contractID, take_discard_name,
92 resource_discard_test, take_discard_check);
96 this._add(take_submit_CID, take_submit_contractID, take_submit_name,
97 resource_submit_test, take_submit_check);
99 this._add(flow_save_CID, flow_save_contractID, flow_save_name,
100 flow_save_test, null);
103 /* Module-specific Defines and Utilities */
104 var contentId = "content";
105 var treeId = "page1.tree";
108 /* Top Window Test */
109 const top_contractID = "@aasii.org/abstract/test/vc-top;1";
110 const top_name = "aaVCTopTest";
111 const top_CID = Components.ID("{5274ac84-fc9c-4bf9-9689-0a89f5638e1c}");
113 function top_test(runner)
115 runner.watchWindow = runner.testWindow;
118 function top_check(runner)
120 var doc = runner.testWindow.document;
121 if ( doc.documentElement.tagName != "window" )
122 runner.addJSFailure("main window not created");
124 var web = doc.getElementById("content").docShell
125 .QueryInterface(nsCI.nsIWebNavigation);
127 if (web.currentURI.spec != "about:blank")
128 runner.addJSFailure("content is not expected at startup: " + web.currentURI.spec);
129 var session = web.sessionHistory.QueryInterface(nsCI.aaISession);
131 runner.addJSFailure("session not started");
134 /* 'cmd_show1' Test */
135 const show_entity_contractID = "@aasii.org/abstract/test/show-entity;1";
136 const show_entity_name = "aaVCShow1Test";
137 const show_entity_CID = Components.ID("{8a57485e-fed0-4eed-ab93-5f9c01aacbe8}");
138 const entityTagId = "entity.tag";
140 function show_entity_test(runner)
142 runner.doCommand("cmd_view_entity");
143 runner.watchWindow = getFrame(runner).contentWindow;
146 function show_entity_check(runner)
148 var tree = getElement(runner,treeId);
149 var box = getElement(runner, entityTagId);
152 runner.addJSFailure("entity page failed");
153 if (tree.view.getCellText(0,tree.columns[0]) != "abstract")
154 runner.addJSFailure("entity.tree.line1 failed");
155 if (tree.view.getCellText(1,tree.columns[0]) != "Sergey")
156 runner.addJSFailure("entity.tree.line2 failed");
157 if (! entity_details_check(tree, box))
158 runner.addJSFailure("entity.tag failed");
159 // XXX 403202 'Unflexing' the tree speeds up reflow significantly
160 if (tree && tree.hasAttribute("flex"))
161 tree.removeAttribute("flex");
165 const entity_contractID = "@aasii.org/abstract/test/entity;1";
166 const entity_name = "aaVCPage1OnSelectTest";
167 const entity_CID = Components.ID("{213e5e73-f6d7-42c4-9d04-746fd6d7f01a}");
169 function entity_details_check(tree, box)
173 var row = tree.view.selection.currentIndex;
174 var text = box.value;
175 if (row == -1 || ! tree.view.selection.isSelected(row)) {
181 if (tree.view.getCellText(row,tree.columns[0]) == text)
188 function entity_test(runner)
190 var tree = getElement(runner,treeId);
191 var box = getElement(runner, entityTagId);
193 tree.view.selection.select(0);
194 if (! entity_details_check(tree, box))
195 runner.addJSFailure("page1.tag not synched");
196 runner.doCommand("cmd_page1_new");
197 if (box.getAttribute("focused") != "true")
198 runner.addJSFailure("entity.tag not focused");
199 if (tree.view.selection.currentIndex != -1)
200 runner.addJSFailure("entity.tree selection not cleared");
201 if (! entity_details_check(tree, box))
202 runner.addJSFailure("entity.tag not synched");
204 runner.doCommand("cmd_page1_cancel");
205 if (tree.view.selection.currentIndex != 0)
206 runner.addJSFailure("page1.tree selection not restored");
207 if (! entity_details_check(tree, box))
208 runner.addJSFailure("page1.tag not synched");
210 tree.view.selection.select(-1);
211 runner.doCommand("cmd_page1_new");
212 if (tree.view.getCellText(0,tree.columns[0]) != "abstract")
213 runner.addJSFailure("entity.tree.line1 failed");
215 runner.doCommand("cmd_page1_cancel");
216 if (! entity_details_check(tree, box))
217 runner.addJSFailure("page1.tag not synched");
219 tree.view.selection.select(0);
220 runner.doCommand("cmd_page1_new");
222 runner.doCommand("cmd_page1_reset");
223 if (! entity_details_check(tree, box))
224 runner.addJSFailure("page1.tag not synched");
227 runner.doCommand("cmd_page1_save");
228 runner.addJSFailure("page1.save not disabled");
232 var entity = getFrame(runner).contentWindow.wrappedJSObject
235 runner.addJSFailure("blank entity marked edited");
238 runner.addJSFailure("edited entity marked blank");
241 var count = tree.view.rowCount;
242 runner.doCommand("cmd_page1_save");
243 if (tree.view.selection.currentIndex != count)
244 runner.addJSFailure("page1.tree insert not focused");
246 runner.doCommand("cmd_page1_cancel");
247 if (tree.view.selection.currentIndex != -1)
248 runner.addJSFailure("page1.tree selection not cleared");
251 runner.doCommand("cmd_page1_change");
252 runner.addJSFailure("page1.change not disabled");
255 tree.view.selection.select(count);
256 runner.doCommand("cmd_page1_change");
257 box.value="abstract";
259 runner.doCommand("cmd_page1_save");
260 if (box.value != "insert")
261 runner.addJSFailure("page1.tag not unique");
262 box.value="A.N. Onymous";
264 runner.doCommand("cmd_page1_save");
265 if (! entity_details_check(tree, box))
266 runner.addJSFailure("page1.tag not synched");
267 if (tree.view.selection.currentIndex != count)
268 runner.addJSFailure("page1.change on wrong index");
269 if (box.value != "A.N. Onymous")
270 runner.addJSFailure("entity.change not saved");
272 if (getAnnoElement(runner, "header", "header.discard")
273 .getAttribute("collapsed") != "true")
274 runner.addJSFailure("entity.discard button should not be visible");
275 if (getAnnoElement(runner, "header", "header.submit")
276 .getAttribute("collapsed") != "true")
277 runner.addJSFailure("entity.submit button should not be visible");
278 if (getElement(runner, "cmd_page1_discard")
279 .getAttribute("disabled") != "true")
280 runner.addJSFailure("entity_discard command should be disabled");
281 if (getElement(runner, "cmd_page1_submit")
282 .getAttribute("disabled") != "true")
283 runner.addJSFailure("entity_submit command should be disabled");
286 /* 'cmd_show2' Test */
287 const show_resource_contractID = "@aasii.org/abstract/test/show-resource;1";
288 const show_resource_name = "aaVCShow2Test";
289 const show_resource_CID = Components.ID("{2aa28aa0-d25c-4fdc-a32b-27fe83afab1d}");
290 const resourceTagId = "resource.tag";
292 function show_resource_test(runner)
294 runner.doCommand("cmd_view_resource");
295 runner.watchWindow = getFrame(runner).contentWindow;
298 function resource_details_check(tree, box)
302 var row = tree.view.selection.currentIndex;
303 var text = box.value;
304 if (row == -1 || ! tree.view.selection.isSelected(row)) {
310 if (tree.view.getCellText(row,tree.columns[0]) == text)
317 function show_resource_check(runner)
319 var tree = getElement(runner,treeId);
320 var box = getElement(runner, resourceTagId);
323 runner.addJSFailure("Browse->Resources failed");
324 if (tree.view.getCellText(0,tree.columns[0]) != "RUB")
325 runner.addJSFailure("resources page1.tree.line1 failed");
326 if (! resource_details_check(tree, box))
327 runner.addJSFailure("resource.tag failed");
328 // XXX 403202 'Unflexing' the tree speeds up reflow significantly
329 if (tree && tree.hasAttribute("flex"))
330 tree.removeAttribute("flex");
334 const resource_contractID = "@aasii.org/abstract/test/resource;1";
335 const resource_name = "aaVCPage2OnSelectTest";
336 const resource_CID = Components.ID("{540d4ac5-d104-473c-846a-052d50ca62be}");
338 function resource_test(runner)
340 var tree = getElement(runner,treeId);
341 var box = getElement(runner, resourceTagId);
343 tree.view.selection.select(0);
344 if (! resource_details_check(tree, box))
345 runner.addJSFailure("resource page1.tag not synched");
346 runner.doCommand("cmd_page1_new");
347 if (box.getAttribute("focused") != "true")
348 runner.addJSFailure("resource page1.tag not focused");
349 if (tree.view.selection.currentIndex != -1)
350 runner.addJSFailure("resource page1.tree selection not cleared");
351 if (! resource_details_check(tree, box))
352 runner.addJSFailure("resource page1.tag not synched");
354 runner.doCommand("cmd_page1_cancel");
355 if (tree.view.selection.currentIndex != 0)
356 runner.addJSFailure("resource page1.tree selection not restored");
357 if (! resource_details_check(tree, box))
358 runner.addJSFailure("resource page1.tag not synched");
360 tree.view.selection.select(-1);
361 runner.doCommand("cmd_page1_new");
363 runner.doCommand("cmd_page1_cancel");
364 if (! resource_details_check(tree, box))
365 runner.addJSFailure("resource page1.tag not synched");
367 tree.view.selection.select(0);
368 runner.doCommand("cmd_page1_new");
370 runner.doCommand("cmd_page1_reset");
371 if (! resource_details_check(tree, box))
372 runner.addJSFailure("resource page1.tag not synched");
375 runner.doCommand("cmd_page1_save");
376 runner.addJSFailure("resource page1.save not disabled");
382 var count = tree.view.rowCount;
383 runner.doCommand("cmd_page1_save");
384 if (tree.view.selection.currentIndex != count)
385 runner.addJSFailure("resource page1.tree insert not focused");
386 if (! resource_details_check(tree, box))
387 runner.addJSFailure("resource page1.tag not synched");
389 tree.view.selection.select(-1);
391 runner.doCommand("cmd_page1_change");
392 runner.addJSFailure("resource page1.change not disabled");
395 tree.view.selection.select(count);
396 runner.doCommand("cmd_page1_change");
397 box.value="AASI share";
399 runner.doCommand("cmd_page1_save");
400 if (box.value != "EU")
401 runner.addJSFailure("resource page1.tag not unique");
404 runner.doCommand("cmd_page1_save");
405 if (! resource_details_check(tree, box))
406 runner.addJSFailure("resource page1.tag not synched");
407 if (tree.view.selection.currentIndex != count)
408 runner.addJSFailure("resource page1.change on wrong index");
409 if (box.value != "USD")
410 runner.addJSFailure("resource page1.change not saved");
414 const flow_contractID = "@aasii.org/abstract/test/flow;1";
415 const flow_name = "aaVCFlowPageTest";
416 const flow_CID = Components.ID("{b2c6addf-862e-4457-99b7-1909ef6208e0}");
417 const flowTagId = "flow.tag";
419 function flow_test(runner)
421 runner.doCommand("cmd_process_flow");
422 runner.watchWindow = getFrame(runner).contentWindow;
425 function flow_page_check(runner)
427 var tree = getElement(runner,treeId);
428 // XXX 403202 'Unflexing' the tree speeds up reflow significantly
429 if (tree && tree.hasAttribute("flex"))
430 tree.removeAttribute("flex");
433 if (getAnnoElement(runner, "header", "header.discard")
434 .getAttribute("collapsed") != "true")
435 runner.addJSFailure("flow.discard button should be invisible");
436 if (getAnnoElement(runner, "header", "header.submit")
437 .getAttribute("collapsed") != "true")
438 runner.addJSFailure("flow.submit button should be invisible");
439 if (getElement(runner, "cmd_page1_discard")
440 .getAttribute("disabled") != "true")
441 runner.addJSFailure("flow_discard command should be disabled");
442 if (getElement(runner, "cmd_page1_submit")
443 .getAttribute("disabled") != "true")
444 runner.addJSFailure("flow_submit command should be disabled");
446 tree.view.selection.select(3);
447 if (! flow_details_check(runner))
448 runner.addJSFailure("[flow] page not synched");
449 getElement(runner, "rate.direction").selectedIndex = 1;
450 if (! flow_details_check(runner))
451 runner.addJSFailure("[flow] page not synched");
452 //var details = getFrame(runner).contentWindow.wrappedJSObject.gDetails;
453 //jsdump("flow_page: " +tree.view.selection.currentIndex + " - " + details.index);
454 runner.doCommand("cmd_page1_new");
455 //var details = getFrame(runner).contentWindow.wrappedJSObject.gDetails;
456 //jsdump("flow_page: " +tree.view.selection.currentIndex + " - " + details.index);
457 if (! flow_details_check(runner))
458 runner.addJSFailure("[flow] page not synched");
461 /* ask for entity from flow page */
462 const flow_entity_contractID = "@aasii.org/abstract/test/flow-entity;1";
463 const flow_entity_name = "aaVCFlowEntityTest";
464 const flow_entity_CID = Components.ID("{1b16209f-d818-4bf1-862d-64953ff8c414}");
466 function flow_entity_test(runner)
468 runner.doCommand("cmd_flow_entity");
469 runner.watchWindow = getFrame(runner).contentWindow;
472 const entity_discard_contractID = "@aasii.org/abstract/test/entity-discard;1";
473 const entity_discard_name = "aaVCEntityDiscardTest";
474 const entity_discard_CID = Components.ID("{21737fb5-a114-4a9a-bc45-907ecbffeb23}");
476 function entity_discard_check(runner)
479 if (getElement(runner, entityTagId).value != "")
480 runner.addJSFailure("entity discard failed");
481 if (! session_buffer_check(runner))
482 runner.addJSFailure("session buffer not cleared");
485 const entity_submit_contractID = "@aasii.org/abstract/test/entity-submit;1";
486 const entity_submit_name = "aaVCEntitySubmitTest";
487 const entity_submit_CID = Components.ID("{755a6691-7d04-4b02-95e8-894b3dd17034}");
489 function entity_submit_check(runner)
492 if (getElement(runner, entityTagId).value != "Sergey")
493 runner.addJSFailure("entity submit failed");
494 if (! session_buffer_check(runner))
495 runner.addJSFailure("session buffer not cleared");
498 /* submit/discard from entity page */
499 function flow_entity_check(runner)
501 show_entity_check(runner);
503 if (getAnnoElement(runner, "header", "header.discard")
504 .getAttribute("collapsed") == "true")
505 runner.addJSFailure("entity.discard button should be visible");
506 if (getAnnoElement(runner, "header", "header.submit")
507 .getAttribute("collapsed") == "true")
508 runner.addJSFailure("entity.submit button should be visible");
509 if (getElement(runner, "cmd_page1_discard")
510 .getAttribute("disabled") == "true")
511 runner.addJSFailure("entity_discard command should be enabled");
512 if (getElement(runner, "cmd_page1_submit")
513 .getAttribute("disabled") == "true")
514 runner.addJSFailure("entity_submit command should be enabled");
517 function entity_discard_test(runner)
519 getElement(runner,treeId).view.selection.select(1);
520 runner.doCommand("cmd_page1_discard");
521 runner.watchWindow = getFrame(runner).contentWindow;
524 function entity_submit_test(runner)
526 getElement(runner,treeId).view.selection.select(1);
527 runner.doCommand("cmd_page1_submit");
528 runner.watchWindow = getFrame(runner).contentWindow;
531 /* submit/discard from resource page */
532 function flow_resource_check(runner)
534 show_resource_check(runner);
536 if (getAnnoElement(runner, "header", "header.discard")
537 .getAttribute("collapsed") == "true")
538 runner.addJSFailure("resource.discard button should be visible");
539 if (getAnnoElement(runner, "header", "header.submit")
540 .getAttribute("collapsed") == "true")
541 runner.addJSFailure("resource.submit button should be visible");
542 if (getElement(runner, "cmd_page1_discard")
543 .getAttribute("disabled") == "true")
544 runner.addJSFailure("resource_discard command should be enabled");
545 if (getElement(runner, "cmd_page1_submit")
546 .getAttribute("disabled") == "true")
547 runner.addJSFailure("resource_submit command should be enabled");
550 function resource_discard_test(runner)
552 getElement(runner,treeId).view.selection.select(1);
553 runner.doCommand("cmd_page1_discard");
554 runner.watchWindow = getFrame(runner).contentWindow;
557 function resource_submit_test(runner)
559 getElement(runner,treeId).view.selection.select(gItem);
560 runner.doCommand("cmd_page1_submit");
561 runner.watchWindow = getFrame(runner).contentWindow;
564 /* ask for give resource from flow page */
565 const flow_give_contractID = "@aasii.org/abstract/test/flow-give;1";
566 const flow_give_name = "aaVCFlowGiveResourceTest";
567 const flow_give_CID = Components.ID("{fc969e46-99d8-4612-b502-2494e2d372cd}");
569 function flow_give_test(runner)
572 runner.doCommand("cmd_flow_give");
573 runner.watchWindow = getFrame(runner).contentWindow;
576 const give_discard_contractID = "@aasii.org/abstract/test/give-discard;1";
577 const give_discard_name = "aaGiveResourceDiscardTest";
578 const give_discard_CID = Components.ID("{6b3c8a33-e4eb-41f3-8367-0926ef033197}");
580 function give_discard_check(runner)
583 if (getElement(runner, "give.tag").value != "")
584 runner.addJSFailure("resource dsicard failed");
585 if (! session_buffer_check(runner))
586 runner.addJSFailure("session buffer not cleared");
589 const give_submit_contractID = "@aasii.org/abstract/test/give-submit;1";
590 const give_submit_name = "aaGiveResourceSubmitTest";
591 const give_submit_CID = Components.ID("{a7a676e9-45c2-49cd-be2b-c40da915fb20}");
593 function give_submit_check(runner)
596 if (getElement(runner, "give.tag").value != "RUB")
597 runner.addJSFailure("resource submit failed");
598 if (! session_buffer_check(runner))
599 runner.addJSFailure("session buffer not cleared");
602 /* ask for take resource from flow page */
603 const flow_take_contractID = "@aasii.org/abstract/test/flow-take;1";
604 const flow_take_name = "aaVCFlowTakeResourceTest";
605 const flow_take_CID = Components.ID("{573b04f4-2d4c-4a70-a880-939f960ea883}");
607 function flow_take_test(runner)
610 runner.doCommand("cmd_flow_take");
611 runner.watchWindow = getFrame(runner).contentWindow;
614 const take_discard_contractID = "@aasii.org/abstract/test/take-discard;1";
615 const take_discard_name = "aaTakeResourceDiscardTest";
616 const take_discard_CID = Components.ID("{8a096221-c744-4cc9-9689-ed53b3b28858}");
618 function take_discard_check(runner)
621 if (getElement(runner, "take.tag").value != "")
622 runner.addJSFailure("resource dsicard failed");
623 if (! session_buffer_check(runner))
624 runner.addJSFailure("session buffer not cleared");
627 const take_submit_contractID = "@aasii.org/abstract/test/take-submit;1";
628 const take_submit_name = "aaTakeResourceSubmitTest";
629 const take_submit_CID = Components.ID("{fed26559-2aee-458c-8778-0f5d363cab86}");
631 function take_submit_check(runner)
634 if (getElement(runner, "take.tag").value != "EUR")
635 runner.addJSFailure("resource submit failed");
636 if (! session_buffer_check(runner))
637 runner.addJSFailure("session buffer not cleared");
640 const flow_save_contractID = "@aasii.org/abstract/test/flow-save;1";
641 const flow_save_name = "aaVCFlowSaveTest";
642 const flow_save_CID = Components.ID("{a8704d86-db0e-4256-bdc4-4774d11cf2fb}");
644 function flow_save_test(runner)
646 var tree = getElement(runner,treeId);
647 var tagBox = getElement(runner, "flow.tag")
648 var rateBox = getElement(runner, "flow.rate")
649 var count = tree.view.rowCount;
651 tagBox.value = "equipment storage 1";
653 if (! flow_details_check(runner))
654 runner.addJSFailure("[flow save] page not synched");
656 sendOnInput(rateBox);
657 if (! flow_details_check(runner))
658 runner.addJSFailure("[flow save] page not synched");
659 runner.doCommand("cmd_page1_save");
660 if (tree.view.selection.currentIndex != count)
661 runner.addJSFailure("[flow save] insert not focused in the tree");
662 if (! flow_details_check(runner))
663 runner.addJSFailure("[flow save] page not synched");
665 runner.doCommand("cmd_page1_change");
666 runner.addJSFailure("[flow save] 'change' not disabled");