Mercurial > bugzilla-dashboard
annotate js/black-box.js @ 100:c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
author | Atul Varma <avarma@mozilla.com> |
---|---|
date | Tue, 27 Apr 2010 23:06:29 -0700 |
parents | 544d339d2b4c |
children | 106a0018e601 |
rev | line source |
---|---|
100
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
1 function getXPathForElement(el, xml) { |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
2 var xpath = ""; |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
3 var pos, tempitem2; |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
4 |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
5 while (el !== xml.documentElement) { |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
6 pos = 0; |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
7 tempitem2 = el; |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
8 while (tempitem2) { |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
9 if (tempitem2.nodeType === 1 && tempitem2.nodeName === el.nodeName) { |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
10 // If it is ELEMENT_NODE of the same name |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
11 pos += 1; |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
12 } |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
13 tempitem2 = tempitem2.previousSibling; |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
14 } |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
15 |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
16 xpath = el.nodeName + "[" + pos + "]" + "/" + xpath; |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
17 |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
18 el = el.parentNode; |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
19 } |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
20 xpath = "/" + xml.documentElement.nodeName + "/" + xpath; |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
21 xpath = xpath.replace(/\/$/, ''); |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
22 return xpath; |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
23 } |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
24 |
99
544d339d2b4c
Added the beginnings of a black-box app that can be used to generate/run functional tests.
Atul Varma <avarma@mozilla.com>
parents:
diff
changeset
|
25 function onDashboardLoaded(dashboard, options) { |
100
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
26 var require = Require.build(Require.modules, {window: window}); |
99
544d339d2b4c
Added the beginnings of a black-box app that can be used to generate/run functional tests.
Atul Varma <avarma@mozilla.com>
parents:
diff
changeset
|
27 |
544d339d2b4c
Added the beginnings of a black-box app that can be used to generate/run functional tests.
Atul Varma <avarma@mozilla.com>
parents:
diff
changeset
|
28 // Needed for Firebug, which won't log iframe errors to the console. |
544d339d2b4c
Added the beginnings of a black-box app that can be used to generate/run functional tests.
Atul Varma <avarma@mozilla.com>
parents:
diff
changeset
|
29 $(dashboard).error( |
544d339d2b4c
Added the beginnings of a black-box app that can be used to generate/run functional tests.
Atul Varma <avarma@mozilla.com>
parents:
diff
changeset
|
30 function(event) { |
544d339d2b4c
Added the beginnings of a black-box app that can be used to generate/run functional tests.
Atul Varma <avarma@mozilla.com>
parents:
diff
changeset
|
31 console.warn("An error occurred in the dashboard iframe."); |
544d339d2b4c
Added the beginnings of a black-box app that can be used to generate/run functional tests.
Atul Varma <avarma@mozilla.com>
parents:
diff
changeset
|
32 }); |
544d339d2b4c
Added the beginnings of a black-box app that can be used to generate/run functional tests.
Atul Varma <avarma@mozilla.com>
parents:
diff
changeset
|
33 |
100
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
34 function DOMElementToCSSSelector(element) { |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
35 if (element.id) |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
36 return "#" + element.id; |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
37 |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
38 var document = element.ownerDocument; |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
39 |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
40 function isUnique(selector) { |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
41 return (document.querySelectorAll(selector).length == 1); |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
42 } |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
43 |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
44 var parent = element.parentNode; |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
45 while (parent) { |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
46 if (parent.id) |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
47 break; |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
48 parent = parent.parentNode; |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
49 } |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
50 |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
51 if (parent && parent.id) { |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
52 var selector = "#" + parent.id; |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
53 |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
54 var list = element.classList; |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
55 for (var i = 0; i < list.length; i++) { |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
56 selector += " ." + list[i]; |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
57 if (isUnique(selector)) |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
58 return selector; |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
59 } |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
60 } |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
61 return null; |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
62 } |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
63 |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
64 dashboard.addEventListener( |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
65 "mousedown", |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
66 function(event) { |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
67 var document = event.target.ownerDocument; |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
68 var xpath = getXPathForElement(event.target, document); |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
69 var result = document.evaluate(xpath, document, null, |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
70 XPathResult.ANY_TYPE, null); |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
71 console.log("mousedown", event.target, |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
72 DOMElementToCSSSelector(event.target), |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
73 xpath, |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
74 result.iterateNext()); |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
75 }, |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
76 true |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
77 ); |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
78 |
99
544d339d2b4c
Added the beginnings of a black-box app that can be used to generate/run functional tests.
Atul Varma <avarma@mozilla.com>
parents:
diff
changeset
|
79 var moduleExports = {}; |
544d339d2b4c
Added the beginnings of a black-box app that can be used to generate/run functional tests.
Atul Varma <avarma@mozilla.com>
parents:
diff
changeset
|
80 var dbrequire = dashboard.Require.build(dashboard.Require.modules, |
544d339d2b4c
Added the beginnings of a black-box app that can be used to generate/run functional tests.
Atul Varma <avarma@mozilla.com>
parents:
diff
changeset
|
81 moduleExports); |
100
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
82 |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
83 function delegate(method, args) { |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
84 //console.log(method, args); |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
85 } |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
86 |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
87 var ajaxImpl = require("mocks/bugzilla/trivial").makeAjaxImpl(); |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
88 options.cache = require("mocks/cache").create(delegate); |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
89 options.Bugzilla = require("mocks/bugzilla").create(options.Bugzilla, |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
90 ajaxImpl, |
c486d35fad27
added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
Atul Varma <avarma@mozilla.com>
parents:
99
diff
changeset
|
91 delegate); |
99
544d339d2b4c
Added the beginnings of a black-box app that can be used to generate/run functional tests.
Atul Varma <avarma@mozilla.com>
parents:
diff
changeset
|
92 dbrequire("date-utils").now = function() { |
544d339d2b4c
Added the beginnings of a black-box app that can be used to generate/run functional tests.
Atul Varma <avarma@mozilla.com>
parents:
diff
changeset
|
93 return new Date("Tue Apr 27 2010 09:00:00 GMT"); |
544d339d2b4c
Added the beginnings of a black-box app that can be used to generate/run functional tests.
Atul Varma <avarma@mozilla.com>
parents:
diff
changeset
|
94 }; |
544d339d2b4c
Added the beginnings of a black-box app that can be used to generate/run functional tests.
Atul Varma <avarma@mozilla.com>
parents:
diff
changeset
|
95 dbrequire("app/loader").init(moduleExports, options); |
544d339d2b4c
Added the beginnings of a black-box app that can be used to generate/run functional tests.
Atul Varma <avarma@mozilla.com>
parents:
diff
changeset
|
96 } |
544d339d2b4c
Added the beginnings of a black-box app that can be used to generate/run functional tests.
Atul Varma <avarma@mozilla.com>
parents:
diff
changeset
|
97 |
544d339d2b4c
Added the beginnings of a black-box app that can be used to generate/run functional tests.
Atul Varma <avarma@mozilla.com>
parents:
diff
changeset
|
98 $(window).ready( |
544d339d2b4c
Added the beginnings of a black-box app that can be used to generate/run functional tests.
Atul Varma <avarma@mozilla.com>
parents:
diff
changeset
|
99 function() { |
544d339d2b4c
Added the beginnings of a black-box app that can be used to generate/run functional tests.
Atul Varma <avarma@mozilla.com>
parents:
diff
changeset
|
100 var iframe = $("#dashboard").get(0); |
544d339d2b4c
Added the beginnings of a black-box app that can be used to generate/run functional tests.
Atul Varma <avarma@mozilla.com>
parents:
diff
changeset
|
101 iframe.src = "index.html?testing=1"; |
544d339d2b4c
Added the beginnings of a black-box app that can be used to generate/run functional tests.
Atul Varma <avarma@mozilla.com>
parents:
diff
changeset
|
102 }); |