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 EXPORTED_SYMBOLS = [ "jsdump", "objdump", "getFrame", "getElement",
23 "session_buffer_check",
24 "flow_details_check", "flow_check" ];
26 const nsCI = Components.interfaces
30 Components.classes['@mozilla.org/consoleservice;1']
31 .getService(Components.interfaces.nsIConsoleService)
32 .logStringMessage(str);
38 for (var prop in obj) {
40 jsdump(prop + ": " + obj[prop]);
42 jsdump(prop + ": error: " + e.message);
47 function getFrame(runner)
51 return runner.testWindow.document.getElementById("content");
54 function getElement(runner, id)
58 var el = getFrame(runner).contentDocument.getElementById(id);
61 if (el.wrappedJSObject)
62 return el.wrappedJSObject;
66 function getAnnoElement(runner, id, annoid)
68 if (! annoid || ! id || ! runner)
70 var doc = getFrame(runner).contentDocument;
71 var el = doc.getAnonymousElementByAttribute(doc.getElementById(id),
73 if (el && el.wrappedJSObject)
74 return el.wrappedJSObject;
78 function flow_details_check(runner)
80 var details = getFrame(runner).contentWindow.wrappedJSObject.gDetails;
82 runner.addJSFailure("[flow page] detailView is null");
85 var index = details.index;
91 flow = details._item.QueryInterface(nsCI.aaIFlow);
93 runner.addJSFailure("[flow page] detailView._item is null");
96 var tree = getFrame(runner).contentWindow.wrappedJSObject.gTree;
98 runner.addJSFailure("[flow page] tree is null");
101 if (tree.view.getCellText(index,tree.columns[0]) != flow.tag) {
102 runner.addJSFailure("[flow page] tree.tag not synched for line " + index);
106 runner.addJSFailure("[flow page] flow.entity is null for line " + index);
108 } else if (tree.view.getCellText(index,tree.columns[1]) != flow.entity.tag) {
109 runner.addJSFailure("[flow page] tree.entity.tag not synched for line "
114 var treeIndex = tree.view.selection.currentIndex;
115 if (details.buffer ) {
116 flow = details.buffer.QueryInterface(nsCI.aaIFlow);
118 runner.addJSFailure("[flow] detailView.buffer is not a flow");
121 } else if (treeIndex == -1) {
124 if (getElement(runner, "flow.tag").value != flow.tag) {
125 runner.addJSFailure("[flow page] flow.tag not synched");
128 if ((flow.entity && getElement(runner,"entity.tag").value != flow.entity.tag)
129 || (! flow.entity && getElement(runner,"entity.tag").value != "")) {
130 runner.addJSFailure("[flow page] flow.entity.tag not synched");
133 if ((flow.giveResource && getElement(runner,"give.tag").value !=
134 flow.giveResource.tag) || (! flow.giveResource &&
135 getElement(runner,"give.tag").value != "")) {
136 runner.addJSFailure("[flow page] flow.giveResource.tag not synched");
139 if ((flow.takeResource && getElement(runner,"take.tag").value !=
140 flow.takeResource.tag) || (! flow.takeResource &&
141 getElement(runner,"take.tag").value != "")) {
142 runner.addJSFailure("[flow page] flow.takeResource.tag not synched");
145 var indirect = getFrame(runner).contentWindow.wrappedJSObject.gIndirectRate;
146 if ((indirect ? (1 / flow.rate) : flow.rate)
147 != getElement(runner,"flow.rate").value) {
148 runner.addJSFailure("[flow page] flow.rate not synched");
154 const treeId = "page1.tree";
155 const flowTagId = "flow.tag";
157 function flow_check(runner)
159 var tree = getElement(runner,treeId);
161 if (tree.view.getCellText(0,tree.columns[0]) != "equity share 1")
162 runner.addJSFailure("flow.tree.line1 failed");
163 if (! flow_details_check(runner))
164 runner.addJSFailure("[flow] page not synched");