[app] Select 'transfer.toFlow'
[abstract.git] / app / aaTestVC.jsm
bloba625f836b2891343b23432b60c69ca62f7ff192d
1 /* vim:set ts=2 sw=2 sts=2 et cindent tw=79 ft=javascript: */
2 /*
3  * Copyright (C) 2007 Sergey Yanovich <ynvich@gmail.com>
4  *
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.
9  *
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.
14  *
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.
19  */
21 EXPORTED_SYMBOLS = [ "jsdump", "objdump", "getFrame", "getElement",
22                  "getAnnoElement",
23                  "session_buffer_check",
24                  "flow_details_check", "flow_check" ];
26 const nsCI                   = Components.interfaces
28 function jsdump(str)
30     Components.classes['@mozilla.org/consoleservice;1']
31       .getService(Components.interfaces.nsIConsoleService)
32       .logStringMessage(str);
35 function objdump(obj)
37   jsdump(obj);
38   for (var prop in obj) {
39     try {
40       jsdump(prop + ": " + obj[prop]);
41     } catch (e) {
42       jsdump(prop + ": error: " + e.message);
43     }
44   }
47 function getFrame(runner)
49   if (! runner)
50     return null;
51   return runner.testWindow.document.getElementById("content");
54 function getElement(runner, id)
56   if (! id || ! runner)
57     return null;
58   var el = getFrame(runner).contentDocument.getElementById(id);
59   if (! el)
60     return null;
61   if (el.wrappedJSObject)
62     return el.wrappedJSObject;
63   return el;
66 function getAnnoElement(runner, id, annoid)
68   if (! annoid || ! id || ! runner)
69     return null;
70   var doc = getFrame(runner).contentDocument;
71   var el = doc.getAnonymousElementByAttribute(doc.getElementById(id),
72       "annoid", annoid);
73   if (el && el.wrappedJSObject)
74     return el.wrappedJSObject;
75   return el;
78 function flow_details_check(runner)
80   var details = getFrame(runner).contentWindow.wrappedJSObject.gDetails;
81   if (! details) {
82     runner.addJSFailure("[flow page] detailView is null");
83     return false;
84   }
85   var index = details.index;
86   if (index == -1)
87     return true;
88   var result = true;
89   var flow;
90   try {
91     flow = details._item.QueryInterface(nsCI.aaIFlow);
92   } catch(e) {
93     runner.addJSFailure("[flow page] detailView._item is null");
94     return false;
95   }
96   var tree = getFrame(runner).contentWindow.wrappedJSObject.gTree;
97   if (! tree) {
98     runner.addJSFailure("[flow page] tree is null");
99     return false;
100   }
101   if (tree.view.getCellText(index,tree.columns[0]) != flow.tag) {
102     runner.addJSFailure("[flow page] tree.tag not synched for line " + index);
103     result = false;
104   }
105   if (! flow.entity) {
106     runner.addJSFailure("[flow page] flow.entity is null for line " + index);
107     result = false;
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 "
110         + index);
111     result = false;
112   }
114   var treeIndex = tree.view.selection.currentIndex;
115   if (details.buffer ) {
116     flow = details.buffer.QueryInterface(nsCI.aaIFlow);
117     if (! flow) {
118       runner.addJSFailure("[flow] detailView.buffer is not a flow");
119       return false;
120     }
121   } else if (treeIndex == -1) {
122     return result;
123   }
124   if (getElement(runner, "flow.tag").value != flow.tag) {
125     runner.addJSFailure("[flow page] flow.tag not synched");
126     result = false;
127   }
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");
131     result = false;
132   }
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");
137     result = false;
138   }
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");
143     result = false;
144   }
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");
149     result = false;
150   }
151   return result;
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");
167 function session_buffer_check(runner)
169   return ! getFrame(runner).docShell.QueryInterface(nsCI.nsIWebNavigation)
170       .sessionHistory.QueryInterface(nsCI.nsIInterfaceRequestor)
171       .getInterface(nsCI.aaISession).queryBuffer;