2012-10-02 03:35:43 +04:00
|
|
|
var testHelper = {};
|
|
|
|
|
|
|
|
(function(){
|
2012-10-03 20:37:48 +04:00
|
|
|
var $iframeContainer, $iframe;
|
|
|
|
|
|
|
|
testHelper.init = function(){
|
|
|
|
$iframeContainer = $("#iframe-container");
|
|
|
|
}
|
|
|
|
|
|
|
|
testHelper.randomString = function randomString(len)
|
|
|
|
{
|
|
|
|
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
|
|
var randomstring = '';
|
|
|
|
for (var i = 0; i < len; i++)
|
|
|
|
{
|
|
|
|
var rnum = Math.floor(Math.random() * chars.length);
|
|
|
|
randomstring += chars.substring(rnum, rnum + 1);
|
|
|
|
}
|
|
|
|
return randomstring;
|
|
|
|
}
|
|
|
|
|
|
|
|
testHelper.newPad = function(cb){
|
|
|
|
var padName = "FRONTEND_TEST_" + testHelper.randomString(20);
|
|
|
|
$iframe = $("<iframe src='/p/" + padName + "'></iframe>");
|
|
|
|
|
|
|
|
$iframeContainer.empty().append($iframe);
|
2012-10-02 03:35:43 +04:00
|
|
|
|
|
|
|
var checkInterval;
|
|
|
|
$iframe.load(function(){
|
2012-10-03 20:37:48 +04:00
|
|
|
checkInterval = setInterval(function(){
|
|
|
|
var loaded = false;
|
2012-10-02 03:35:43 +04:00
|
|
|
|
2012-10-03 20:37:48 +04:00
|
|
|
try {
|
|
|
|
//check if loading div is hidden
|
|
|
|
loaded = !testHelper.$getPadChrome().find("#editorloadingbox").is(":visible");
|
|
|
|
} catch(e){}
|
2012-10-02 03:35:43 +04:00
|
|
|
|
2012-10-03 20:37:48 +04:00
|
|
|
if(loaded){
|
|
|
|
clearTimeout(timeout);
|
|
|
|
clearInterval(checkInterval);
|
2012-10-02 03:35:43 +04:00
|
|
|
|
2012-10-03 20:37:48 +04:00
|
|
|
cb(null, {name: padName});
|
|
|
|
}
|
|
|
|
}, 100);
|
|
|
|
});
|
2012-10-02 03:35:43 +04:00
|
|
|
|
|
|
|
var timeout = setTimeout(function(){
|
2012-10-03 20:37:48 +04:00
|
|
|
if(checkInterval) clearInterval(checkInterval);
|
2012-10-02 03:35:43 +04:00
|
|
|
cb(new Error("Pad didn't load in 10 seconds"));
|
|
|
|
}, 10000);
|
|
|
|
|
2012-10-03 20:37:48 +04:00
|
|
|
return padName;
|
|
|
|
}
|
|
|
|
|
|
|
|
testHelper.$getPadChrome = function(){
|
|
|
|
var win = $iframe[0].contentWindow;
|
|
|
|
var $content = $iframe.contents();
|
|
|
|
$content.window = win;
|
|
|
|
|
|
|
|
return $content;
|
|
|
|
}
|
|
|
|
|
|
|
|
testHelper.$getPadOuter = function(){
|
|
|
|
var $iframe = testHelper.$getPadChrome().find('iframe.[name="ace_outer"]');
|
|
|
|
var win = $iframe[0].contentWindow;
|
|
|
|
var $content = $iframe.contents();
|
|
|
|
$content.window = win;
|
2012-10-02 03:35:43 +04:00
|
|
|
|
2012-10-03 20:37:48 +04:00
|
|
|
return $content;
|
|
|
|
}
|
2012-10-02 03:35:43 +04:00
|
|
|
|
2012-10-03 20:37:48 +04:00
|
|
|
testHelper.$getPadInner = function(){
|
|
|
|
var $iframe = testHelper.$getPadOuter().find('iframe.[name="ace_inner"]');
|
|
|
|
var win = $iframe[0].contentWindow;
|
|
|
|
var $content = $iframe.contents();
|
|
|
|
$content.window = win;
|
2012-10-02 03:35:43 +04:00
|
|
|
|
2012-10-03 20:37:48 +04:00
|
|
|
return $content;
|
|
|
|
}
|
2012-10-02 03:35:43 +04:00
|
|
|
|
|
|
|
// copied from http://stackoverflow.com/questions/985272/jquery-selecting-text-in-an-element-akin-to-highlighting-with-your-mouse
|
2012-10-03 20:37:48 +04:00
|
|
|
// selects the whole dom element you give it
|
|
|
|
testHelper.selectText = function(element, $iframe){
|
|
|
|
var doc = $iframe[0], win = $iframe.window, range, selection;
|
2012-10-02 03:35:43 +04:00
|
|
|
|
|
|
|
if (doc.body.createTextRange) { //ms
|
|
|
|
range = doc.body.createTextRange();
|
|
|
|
range.moveToElementText(element);
|
|
|
|
range.select();
|
2012-10-03 20:37:48 +04:00
|
|
|
} else if (win.getSelection) { //all others
|
|
|
|
selection = win.getSelection();
|
2012-10-02 03:35:43 +04:00
|
|
|
range = doc.createRange();
|
|
|
|
range.selectNodeContents(element);
|
|
|
|
selection.removeAllRanges();
|
|
|
|
selection.addRange(range);
|
|
|
|
}
|
2012-10-03 20:37:48 +04:00
|
|
|
}
|
2012-10-02 03:35:43 +04:00
|
|
|
})()
|
|
|
|
|