forked from tiagogribeiro/unittest-cache-addon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
136 lines (117 loc) · 3.65 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
"use strict";
var self = require("sdk/self");
var resultTest = require("./lib/result.js");
var tabs = require("sdk/tabs");
var { setTimeout } = require("sdk/timers");
/**
* Carregando do painel principal do Addon.
* @type type
*/
var panel = require("sdk/panel").Panel({
contentURL: self.data.url("unittest-default.html"),
onHide: function() {
buttonIcon.state('window', {checked: false});
},
onShow: panelShow,
height: 370,
width: 430
});
function panelShow(){
var prefs = require("sdk/simple-prefs").prefs;
var namespace = prefs["namespace"];
var urlServidor = prefs["urlTest"];
if ((namespace!==undefined)&&(urlServidor!==undefined)){
hiddenFrame.element.contentWindow.location = getUrlServer();
panel.port.emit('urlSubmit',getUrlServer());
panel.port.emit('configure',false);
} else {
panel.port.emit('configure',true);
}
}
/**
* Iframe oculto.
* @type Module hidden-frame|Module hidden-frame
*/
var hiddenFrames = require("sdk/frame/hidden-frame");
var hiddenFrame = hiddenFrames.add(hiddenFrames.HiddenFrame({
onReady: function () {
var frame = this;
this.element.addEventListener("DOMContentLoaded", function () {
var isLoged = (frame.element.contentDocument.title.indexOf("UnitTest") > -1);
if (isLoged) {
if (resultPageLoaded() == false) {
panel.contentURL = self.data.url("unittest-panel.html");
}
var results = resultTest.testsPerformed( frame.element.contentDocument.body );
setTimeout(function(){
panel.port.emit("render-results", results);
},500);
} else {
panel.contentURL = self.data.url("unittest-default.html");
panel.port.emit("login-failure");
}
}, true, true);
}
}));
function resultPageLoaded() {
return (panel.contentURL == self.data.url("unittest-panel.html"))
}
var { ToggleButton } = require("sdk/ui/button/toggle");
var buttonIcon = ToggleButton({
id: "unittest-button-icon",
label: "UnitTest",
icon: {
"16": "./icon_16.png",
"32": "./icon_32.png",
"64": "./icon_64.png"
},
onChange: function(state) {
if (state.checked) {
panel.show({
position: buttonIcon
});
}
}
});
panel.port.on("load-suite", function (link) {
tabs.open(link);
});
/**
* Monta a url para consulta de resultados no servidor de testes.
* @returns {String}
*/
function getUrlServer(){
var prefs = require("sdk/simple-prefs").prefs;
var url = prefs["urlTest"];
var namespace = prefs["namespace"];
var http = url+ '/csp/' + namespace + '/%25UnitTest.Portal.Home.zen';
return http;
}
/**
* Notificação que o login foi submetido.
*/
panel.port.on("login-submit", function (text) {
console.log('Submetendo....');
hiddenFrame.element.contentWindow.location = getUrlServer();
});
/**
* Registrando as configurações do usuário.
* @author Tiago G. Ribeiro
*/
panel.port.on("save-preference", function (data) {
var port = (data.port!=="") ? ":"+data.port : "";
var prefs = require("sdk/simple-prefs").prefs;
prefs["urlTest"] = data.protocol + data.url + port;
prefs["namespace"]= data.namespace;this
panel.port.emit("configure",false);
panel.port.emit('urlSubmit',getUrlServer());
});
/**
* Obtendo as configurações do usuário.
* @author Tiago G. Ribeiro
*/
panel.port.on("get-preference", function (data) {
var prefs = require("sdk/simple-prefs").prefs;
var result = { url : prefs.urlTest, namespace : prefs.namespace};
return result;
});