mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-01-31 19:02:59 +01:00
made test helpers more cross browser compatible
This commit is contained in:
parent
ba4ebbba3b
commit
7aee98bce8
4 changed files with 79 additions and 56 deletions
|
@ -1,7 +1,11 @@
|
||||||
var testHelper = {};
|
var testHelper = {};
|
||||||
|
|
||||||
(function(){
|
(function(){
|
||||||
var $iframeContainer = $("#iframe-container"), $iframe;
|
var $iframeContainer, $iframe;
|
||||||
|
|
||||||
|
testHelper.init = function(){
|
||||||
|
$iframeContainer = $("#iframe-container");
|
||||||
|
}
|
||||||
|
|
||||||
testHelper.randomString = function randomString(len)
|
testHelper.randomString = function randomString(len)
|
||||||
{
|
{
|
||||||
|
@ -17,7 +21,7 @@ var testHelper = {};
|
||||||
|
|
||||||
testHelper.newPad = function(cb){
|
testHelper.newPad = function(cb){
|
||||||
var padName = "FRONTEND_TEST_" + testHelper.randomString(20);
|
var padName = "FRONTEND_TEST_" + testHelper.randomString(20);
|
||||||
$iframe = $("<iframe src='/p/" + padName + "'></iframe>")
|
$iframe = $("<iframe src='/p/" + padName + "'></iframe>");
|
||||||
|
|
||||||
$iframeContainer.empty().append($iframe);
|
$iframeContainer.empty().append($iframe);
|
||||||
|
|
||||||
|
@ -49,27 +53,42 @@ var testHelper = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
testHelper.$getPadChrome = function(){
|
testHelper.$getPadChrome = function(){
|
||||||
return $iframe.contents()
|
var win = $iframe[0].contentWindow;
|
||||||
|
var $content = $iframe.contents();
|
||||||
|
$content.window = win;
|
||||||
|
|
||||||
|
return $content;
|
||||||
}
|
}
|
||||||
|
|
||||||
testHelper.$getPadOuter = function(){
|
testHelper.$getPadOuter = function(){
|
||||||
return testHelper.$getPadChrome().find('iframe.[name="ace_outer"]').contents();
|
var $iframe = testHelper.$getPadChrome().find('iframe.[name="ace_outer"]');
|
||||||
|
var win = $iframe[0].contentWindow;
|
||||||
|
var $content = $iframe.contents();
|
||||||
|
$content.window = win;
|
||||||
|
|
||||||
|
return $content;
|
||||||
}
|
}
|
||||||
|
|
||||||
testHelper.$getPadInner = function(){
|
testHelper.$getPadInner = function(){
|
||||||
return testHelper.$getPadOuter().find('iframe.[name="ace_inner"]').contents();
|
var $iframe = testHelper.$getPadOuter().find('iframe.[name="ace_inner"]');
|
||||||
|
var win = $iframe[0].contentWindow;
|
||||||
|
var $content = $iframe.contents();
|
||||||
|
$content.window = win;
|
||||||
|
|
||||||
|
return $content;
|
||||||
}
|
}
|
||||||
|
|
||||||
// copied from http://stackoverflow.com/questions/985272/jquery-selecting-text-in-an-element-akin-to-highlighting-with-your-mouse
|
// copied from http://stackoverflow.com/questions/985272/jquery-selecting-text-in-an-element-akin-to-highlighting-with-your-mouse
|
||||||
testHelper.selectText = function(element){
|
// selects the whole dom element you give it
|
||||||
var doc = document, range, selection;
|
testHelper.selectText = function(element, $iframe){
|
||||||
|
var doc = $iframe[0], win = $iframe.window, range, selection;
|
||||||
|
|
||||||
if (doc.body.createTextRange) { //ms
|
if (doc.body.createTextRange) { //ms
|
||||||
range = doc.body.createTextRange();
|
range = doc.body.createTextRange();
|
||||||
range.moveToElementText(element);
|
range.moveToElementText(element);
|
||||||
range.select();
|
range.select();
|
||||||
} else if (window.getSelection) { //all others
|
} else if (win.getSelection) { //all others
|
||||||
selection = window.getSelection();
|
selection = win.getSelection();
|
||||||
range = doc.createRange();
|
range = doc.createRange();
|
||||||
range.selectNodeContents(element);
|
range.selectNodeContents(element);
|
||||||
selection.removeAllRanges();
|
selection.removeAllRanges();
|
||||||
|
|
|
@ -4856,8 +4856,8 @@ process.on = function(e, fn){
|
||||||
var options = mocha.options;
|
var options = mocha.options;
|
||||||
mocha.globals('location');
|
mocha.globals('location');
|
||||||
|
|
||||||
var query = Mocha.utils.parseQuery(window.location.search || '');
|
//var query = Mocha.utils.parseQuery(window.location.search || '');
|
||||||
if (query.grep) mocha.grep(query.grep);
|
//if (query.grep) mocha.grep(query.grep);
|
||||||
|
|
||||||
return Mocha.prototype.run.call(mocha, function(){
|
return Mocha.prototype.run.call(mocha, function(){
|
||||||
Mocha.utils.highlightTags('code');
|
Mocha.utils.highlightTags('code');
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
(function(){
|
$(function(){
|
||||||
//allow iframe access
|
//allow cross iframe access
|
||||||
document.domain = document.domain;
|
document.domain = document.domain;
|
||||||
|
|
||||||
//start test framework
|
//initalize the test helper
|
||||||
|
testHelper.init();
|
||||||
|
|
||||||
|
//configure and start the test framework
|
||||||
|
mocha.ignoreLeaks();
|
||||||
mocha.run();
|
mocha.run();
|
||||||
})()
|
});
|
|
@ -12,7 +12,7 @@ describe("bold button", function(){
|
||||||
var firstTextElement = $inner.find("div").first();
|
var firstTextElement = $inner.find("div").first();
|
||||||
|
|
||||||
//select this text element
|
//select this text element
|
||||||
testHelper.selectText(firstTextElement[0]);
|
testHelper.selectText(firstTextElement[0], $inner);
|
||||||
|
|
||||||
//get the bold button and click it
|
//get the bold button and click it
|
||||||
var $boldButton = testHelper.$getPadChrome().find(".buttonicon-bold");
|
var $boldButton = testHelper.$getPadChrome().find(".buttonicon-bold");
|
||||||
|
|
Loading…
Reference in a new issue