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, 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, entity_select_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);
76 this._tests[9].instance.item = 0;
78 this._add(flow_give_CID, flow_give_contractID, flow_give_name,
79 flow_give_test, resource_select_check);
81 this._add(give_discard_CID, give_discard_contractID, give_discard_name,
82 resource_discard_test, give_discard_check);
86 this._add(give_submit_CID, give_submit_contractID, give_submit_name,
87 resource_submit_test, give_submit_check);
89 this._add(flow_take_CID, flow_take_contractID, flow_take_name,
90 flow_take_test, resource_select_check);
92 this._add(take_discard_CID, take_discard_contractID, take_discard_name,
93 resource_discard_test, take_discard_check);
97 this._add(take_submit_CID, take_submit_contractID, take_submit_name,
98 resource_submit_test, take_submit_check);
99 this._tests[17].instance.item = 1;
101 this._add(flow_save_CID, flow_save_contractID, flow_save_name,
102 flow_save_test, null);
105 /* Module-specific Defines and Utilities */
106 var contentId = "content";
107 var treeId = "page1.tree";
110 /* Top Window Test */
111 const top_contractID = "@aasii.org/abstract/test/vc-top;1";
112 const top_name = "aaVCTopTest";
113 const top_CID = Components.ID("{5274ac84-fc9c-4bf9-9689-0a89f5638e1c}");
115 function top_test(runner)
117 runner.watchWindow = runner.testWindow;
120 function top_check(runner)
122 var doc = runner.testWindow.document;
123 if ( doc.documentElement.tagName != "window" )
124 runner.addJSFailure("main window not created");
126 var web = doc.getElementById("content").docShell
127 .QueryInterface(nsCI.nsIWebNavigation);
129 if (web.currentURI.spec != "about:blank")
130 runner.addJSFailure("content is not expected at startup: " + web.currentURI.spec);
131 var session = web.sessionHistory.QueryInterface(nsCI.aaISession);
133 runner.addJSFailure("session not started");
136 /* 'cmd_show1' Test */
137 const show_entity_contractID = "@aasii.org/abstract/test/show-entity;1";
138 const show_entity_name = "aaVCShow1Test";
139 const show_entity_CID = Components.ID("{8a57485e-fed0-4eed-ab93-5f9c01aacbe8}");
141 function show_entity_test(runner)
143 runner.doCommand("cmd_view_entity");
144 runner.watchWindow = getFrame(runner).contentWindow;
148 const entity_contractID = "@aasii.org/abstract/test/entity;1";
149 const entity_name = "aaVCPage1OnSelectTest";
150 const entity_CID = Components.ID("{213e5e73-f6d7-42c4-9d04-746fd6d7f01a}");
152 function entity_test(runner)
154 var tree = getElement(runner,treeId);
155 var box = getElement(runner, entityTagId);
158 runner.doCommand("cmd_page1_new");
159 if (! entity_details_check(tree, box))
160 runner.addJSFailure("page1.tag not synched");
163 runner.doCommand("cmd_page1_save");
164 if (! entity_details_check(tree, box))
165 runner.addJSFailure("page1.tag not synched");
167 /* Test that 'cancel' clears selection */
168 runner.doCommand("cmd_page1_cancel");
169 if (tree.view.selection.currentIndex != -1)
170 runner.addJSFailure("page1.tree selection not cleared");
172 /* Test synchronization after selection */
173 tree.view.selection.select(0);
174 if (! entity_details_check(tree, box))
175 runner.addJSFailure("page1.tag not synched");
177 runner.doCommand("cmd_page1_new");
178 if (box.getAttribute("focused") != "true")
179 runner.addJSFailure("entity.tag not focused");
180 if (tree.view.selection.currentIndex != -1)
181 runner.addJSFailure("entity.tree selection not cleared");
182 if (! entity_details_check(tree, box))
183 runner.addJSFailure("entity.tag not synched");
185 runner.doCommand("cmd_page1_cancel");
186 if (tree.view.selection.currentIndex != 0)
187 runner.addJSFailure("page1.tree selection not restored");
188 if (! entity_details_check(tree, box))
189 runner.addJSFailure("page1.tag not synched");
191 tree.view.selection.select(-1);
192 runner.doCommand("cmd_page1_new");
193 if (tree.view.getCellText(0,tree.columns[0]) != "K")
194 runner.addJSFailure("entity.tree.line1 failed");
196 runner.doCommand("cmd_page1_cancel");
197 if (! entity_details_check(tree, box))
198 runner.addJSFailure("page1.tag not synched");
200 tree.view.selection.select(0);
201 runner.doCommand("cmd_page1_new");
203 runner.doCommand("cmd_page1_reset");
204 if (! entity_details_check(tree, box))
205 runner.addJSFailure("page1.tag not synched");
208 runner.doCommand("cmd_page1_save");
209 runner.addJSFailure("page1.save not disabled");
213 var entity = getFrame(runner).contentWindow.wrappedJSObject
216 runner.addJSFailure("blank entity marked edited");
219 runner.addJSFailure("edited entity marked blank");
222 /* Test that insertion goes to the last row */
223 var count = tree.view.rowCount;
224 runner.doCommand("cmd_page1_save");
225 if (tree.view.selection.currentIndex != count)
226 runner.addJSFailure("page1.tree insert not focused");
228 runner.doCommand("cmd_page1_cancel");
229 if (tree.view.selection.currentIndex != -1)
230 runner.addJSFailure("page1.tree selection not cleared");
233 runner.doCommand("cmd_page1_change");
234 runner.addJSFailure("page1.change not disabled");
237 tree.view.selection.select(count);
238 runner.doCommand("cmd_page1_change");
241 runner.doCommand("cmd_page1_save");
242 if (box.value != "temp")
243 runner.addJSFailure("page1.tag not unique");
246 runner.doCommand("cmd_page1_save");
247 if (! entity_details_check(tree, box))
248 runner.addJSFailure("page1.tag not synched");
249 if (tree.view.selection.currentIndex != count)
250 runner.addJSFailure("page1.change on wrong index");
251 if (box.value != "L")
252 runner.addJSFailure("entity.change not saved");
254 runner.doCommand("cmd_page1_new");
255 if (! entity_details_check(tree, box))
256 runner.addJSFailure("page1.tag not synched");
259 runner.doCommand("cmd_page1_save");
260 if (! entity_details_check(tree, box))
261 runner.addJSFailure("page1.tag not synched");
263 runner.doCommand("cmd_page1_new");
264 if (! entity_details_check(tree, box))
265 runner.addJSFailure("page1.tag not synched");
268 runner.doCommand("cmd_page1_save");
269 if (! entity_details_check(tree, box))
270 runner.addJSFailure("page1.tag not synched");
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}");
291 function show_resource_test(runner)
293 runner.doCommand("cmd_view_resource");
294 runner.watchWindow = getFrame(runner).contentWindow;
297 function show_resource_check(runner)
299 var tree = getElement(runner,treeId);
300 resource_check(runner);
301 // XXX 403202 'Unflexing' the tree speeds up reflow significantly
302 if (tree && tree.hasAttribute("flex"))
303 tree.removeAttribute("flex");
307 const resource_contractID = "@aasii.org/abstract/test/resource;1";
308 const resource_name = "aaVCPage2OnSelectTest";
309 const resource_CID = Components.ID("{540d4ac5-d104-473c-846a-052d50ca62be}");
311 function resource_test(runner)
313 var tree = getElement(runner,treeId);
314 var box = getElement(runner, resourceTagId);
317 runner.doCommand("cmd_page1_new");
318 if (! resource_details_check(tree, box))
319 runner.addJSFailure("page1.tag not synched");
322 runner.doCommand("cmd_page1_save");
323 if (! resource_details_check(tree, box))
324 runner.addJSFailure("page1.tag not synched");
326 /* Test that 'cancel' clears selection */
327 runner.doCommand("cmd_page1_cancel");
328 if (tree.view.selection.currentIndex != -1)
329 runner.addJSFailure("page1.tree selection not cleared");
331 /* Test synchronization after selection */
332 tree.view.selection.select(0);
333 if (! resource_details_check(tree, box))
334 runner.addJSFailure("resource page1.tag not synched");
336 runner.doCommand("cmd_page1_new");
337 if (box.getAttribute("focused") != "true")
338 runner.addJSFailure("resource page1.tag not focused");
339 if (tree.view.selection.currentIndex != -1)
340 runner.addJSFailure("resource page1.tree selection not cleared");
341 if (! resource_details_check(tree, box))
342 runner.addJSFailure("resource page1.tag not synched");
344 runner.doCommand("cmd_page1_cancel");
345 if (tree.view.selection.currentIndex != 0)
346 runner.addJSFailure("resource page1.tree selection not restored");
347 if (! resource_details_check(tree, box))
348 runner.addJSFailure("resource page1.tag not synched");
350 tree.view.selection.select(-1);
351 runner.doCommand("cmd_page1_new");
353 runner.doCommand("cmd_page1_cancel");
354 if (! resource_details_check(tree, box))
355 runner.addJSFailure("resource page1.tag not synched");
357 tree.view.selection.select(0);
358 runner.doCommand("cmd_page1_new");
360 runner.doCommand("cmd_page1_reset");
361 if (! resource_details_check(tree, box))
362 runner.addJSFailure("resource page1.tag not synched");
365 runner.doCommand("cmd_page1_save");
366 runner.addJSFailure("resource page1.save not disabled");
372 var count = tree.view.rowCount;
373 runner.doCommand("cmd_page1_save");
374 if (tree.view.selection.currentIndex != count)
375 runner.addJSFailure("resource page1.tree insert not focused");
376 if (! resource_details_check(tree, box))
377 runner.addJSFailure("resource page1.tag not synched");
379 tree.view.selection.select(-1);
381 runner.doCommand("cmd_page1_change");
382 runner.addJSFailure("resource page1.change not disabled");
385 tree.view.selection.select(count);
386 runner.doCommand("cmd_page1_change");
389 runner.doCommand("cmd_page1_save");
390 if (box.value != "temp")
391 runner.addJSFailure("resource page1.tag not unique");
394 runner.doCommand("cmd_page1_save");
395 if (! resource_details_check(tree, box))
396 runner.addJSFailure("resource page1.tag not synched");
397 if (tree.view.selection.currentIndex != count)
398 runner.addJSFailure("resource page1.change on wrong index");
399 if (box.value != "y")
400 runner.addJSFailure("resource page1.change not saved");
403 runner.doCommand("cmd_page1_new");
404 if (! resource_details_check(tree, box))
405 runner.addJSFailure("page1.tag not synched");
408 runner.doCommand("cmd_page1_save");
409 if (! resource_details_check(tree, box))
410 runner.addJSFailure("page1.tag not synched");
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 runner.doCommand("cmd_page1_new");
447 if (! flow_details_check(runner))
448 runner.addJSFailure("[flow] page not synched");
451 /* ask for entity from flow page */
452 const flow_entity_contractID = "@aasii.org/abstract/test/flow-entity;1";
453 const flow_entity_name = "aaVCFlowEntityTest";
454 const flow_entity_CID = Components.ID("{1b16209f-d818-4bf1-862d-64953ff8c414}");
456 const entity_discard_contractID = "@aasii.org/abstract/test/entity-discard;1";
457 const entity_discard_name = "aaVCEntityDiscardTest";
458 const entity_discard_CID = Components.ID("{21737fb5-a114-4a9a-bc45-907ecbffeb23}");
460 function entity_discard_check(runner)
463 if (getElement(runner, entityTagId).value != "")
464 runner.addJSFailure("entity discard failed");
467 const entity_submit_contractID = "@aasii.org/abstract/test/entity-submit;1";
468 const entity_submit_name = "aaVCEntitySubmitTest";
469 const entity_submit_CID = Components.ID("{755a6691-7d04-4b02-95e8-894b3dd17034}");
471 function entity_submit_check(runner)
474 if (getElement(runner, entityTagId).value != "K")
475 runner.addJSFailure("entity submit failed");
478 /* ask for give resource from flow page */
479 const flow_give_contractID = "@aasii.org/abstract/test/flow-give;1";
480 const flow_give_name = "aaVCFlowGiveResourceTest";
481 const flow_give_CID = Components.ID("{fc969e46-99d8-4612-b502-2494e2d372cd}");
483 function flow_give_test(runner)
486 runner.doCommand("cmd_flow_give");
487 runner.watchWindow = getFrame(runner).contentWindow;
490 const give_discard_contractID = "@aasii.org/abstract/test/give-discard;1";
491 const give_discard_name = "aaGiveResourceDiscardTest";
492 const give_discard_CID = Components.ID("{6b3c8a33-e4eb-41f3-8367-0926ef033197}");
494 function give_discard_check(runner)
497 if (getElement(runner, "give.tag").value != "")
498 runner.addJSFailure("resource dsicard failed");
501 const give_submit_contractID = "@aasii.org/abstract/test/give-submit;1";
502 const give_submit_name = "aaGiveResourceSubmitTest";
503 const give_submit_CID = Components.ID("{a7a676e9-45c2-49cd-be2b-c40da915fb20}");
505 function give_submit_check(runner)
508 if (getElement(runner, "give.tag").value != "x")
509 runner.addJSFailure("resource submit failed");
512 /* ask for take resource from flow page */
513 const flow_take_contractID = "@aasii.org/abstract/test/flow-take;1";
514 const flow_take_name = "aaVCFlowTakeResourceTest";
515 const flow_take_CID = Components.ID("{573b04f4-2d4c-4a70-a880-939f960ea883}");
517 const take_discard_contractID = "@aasii.org/abstract/test/take-discard;1";
518 const take_discard_name = "aaTakeResourceDiscardTest";
519 const take_discard_CID = Components.ID("{8a096221-c744-4cc9-9689-ed53b3b28858}");
521 function take_discard_check(runner)
524 if (getElement(runner, "take.tag").value != "")
525 runner.addJSFailure("resource discard failed");
528 const take_submit_contractID = "@aasii.org/abstract/test/take-submit;1";
529 const take_submit_name = "aaTakeResourceSubmitTest";
530 const take_submit_CID = Components.ID("{fed26559-2aee-458c-8778-0f5d363cab86}");
532 function take_submit_check(runner)
535 if (getElement(runner, "take.tag").value != "y")
536 runner.addJSFailure("resource submit failed: "
537 + getElement(runner, "take.tag").value);
540 const flow_save_contractID = "@aasii.org/abstract/test/flow-save;1";
541 const flow_save_name = "aaVCFlowSaveTest";
542 const flow_save_CID = Components.ID("{a8704d86-db0e-4256-bdc4-4774d11cf2fb}");
544 function flow_save_test(runner)
546 var tree = getElement(runner,treeId);
547 var tagBox = getElement(runner, "flow.tag")
548 var rateBox = getElement(runner, "flow.rate")
549 var count = tree.view.rowCount;
553 if (! flow_details_check(runner))
554 runner.addJSFailure("[flow save] page not synched");
555 getElement(runner, "rate.direction").selectedIndex = 1;
556 rateBox.value = "100";
557 sendOnInput(rateBox);
558 if (! flow_details_check(runner))
559 runner.addJSFailure("[flow save] page not synched");
560 runner.doCommand("cmd_page1_save");
561 if (tree.view.selection.currentIndex != count)
562 runner.addJSFailure("[flow save] insert not focused in the tree");
563 if (! flow_details_check(runner))
564 runner.addJSFailure("[flow save] page not synched");
566 runner.doCommand("cmd_page1_change");
567 runner.addJSFailure("[flow save] 'change' not disabled");