diff --git a/tests/frontend/helper.js b/tests/frontend/helper.js
index 1e2f201b7..0d29a31f2 100644
--- a/tests/frontend/helper.js
+++ b/tests/frontend/helper.js
@@ -1,80 +1,99 @@
var testHelper = {};
(function(){
- var $iframeContainer = $("#iframe-container"), $iframe;
+ var $iframeContainer, $iframe;
- 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.init = function(){
+ $iframeContainer = $("#iframe-container");
+ }
- testHelper.newPad = function(cb){
- var padName = "FRONTEND_TEST_" + testHelper.randomString(20);
- $iframe = $("")
+ 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;
+ }
- $iframeContainer.empty().append($iframe);
+ testHelper.newPad = function(cb){
+ var padName = "FRONTEND_TEST_" + testHelper.randomString(20);
+ $iframe = $("");
+
+ $iframeContainer.empty().append($iframe);
var checkInterval;
$iframe.load(function(){
- checkInterval = setInterval(function(){
- var loaded = false;
+ checkInterval = setInterval(function(){
+ var loaded = false;
- try {
- //check if loading div is hidden
- loaded = !testHelper.$getPadChrome().find("#editorloadingbox").is(":visible");
- } catch(e){}
+ try {
+ //check if loading div is hidden
+ loaded = !testHelper.$getPadChrome().find("#editorloadingbox").is(":visible");
+ } catch(e){}
- if(loaded){
- clearTimeout(timeout);
- clearInterval(checkInterval);
+ if(loaded){
+ clearTimeout(timeout);
+ clearInterval(checkInterval);
- cb(null, {name: padName});
- }
- }, 100);
- });
+ cb(null, {name: padName});
+ }
+ }, 100);
+ });
var timeout = setTimeout(function(){
- if(checkInterval) clearInterval(checkInterval);
+ if(checkInterval) clearInterval(checkInterval);
cb(new Error("Pad didn't load in 10 seconds"));
}, 10000);
- return padName;
- }
+ return padName;
+ }
- testHelper.$getPadChrome = function(){
- return $iframe.contents()
- }
+ testHelper.$getPadChrome = function(){
+ var win = $iframe[0].contentWindow;
+ var $content = $iframe.contents();
+ $content.window = win;
- testHelper.$getPadOuter = function(){
- return testHelper.$getPadChrome().find('iframe.[name="ace_outer"]').contents();
- }
+ return $content;
+ }
- testHelper.$getPadInner = function(){
- return testHelper.$getPadOuter().find('iframe.[name="ace_inner"]').contents();
- }
+ testHelper.$getPadOuter = function(){
+ 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(){
+ 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
- testHelper.selectText = function(element){
- var doc = document, range, selection;
+ // selects the whole dom element you give it
+ testHelper.selectText = function(element, $iframe){
+ var doc = $iframe[0], win = $iframe.window, range, selection;
if (doc.body.createTextRange) { //ms
range = doc.body.createTextRange();
range.moveToElementText(element);
range.select();
- } else if (window.getSelection) { //all others
- selection = window.getSelection();
+ } else if (win.getSelection) { //all others
+ selection = win.getSelection();
range = doc.createRange();
range.selectNodeContents(element);
selection.removeAllRanges();
selection.addRange(range);
}
- }
+ }
})()
diff --git a/tests/frontend/lib/mocha.js b/tests/frontend/lib/mocha.js
index f67fd0263..5f2da0139 100644
--- a/tests/frontend/lib/mocha.js
+++ b/tests/frontend/lib/mocha.js
@@ -4856,8 +4856,8 @@ process.on = function(e, fn){
var options = mocha.options;
mocha.globals('location');
- var query = Mocha.utils.parseQuery(window.location.search || '');
- if (query.grep) mocha.grep(query.grep);
+ //var query = Mocha.utils.parseQuery(window.location.search || '');
+ //if (query.grep) mocha.grep(query.grep);
return Mocha.prototype.run.call(mocha, function(){
Mocha.utils.highlightTags('code');
diff --git a/tests/frontend/runner.js b/tests/frontend/runner.js
index 042f6c914..d2b2822f8 100644
--- a/tests/frontend/runner.js
+++ b/tests/frontend/runner.js
@@ -1,7 +1,11 @@
-(function(){
- //allow iframe access
- document.domain = document.domain;
+$(function(){
+ //allow cross iframe access
+ document.domain = document.domain;
- //start test framework
- mocha.run();
-})()
\ No newline at end of file
+ //initalize the test helper
+ testHelper.init();
+
+ //configure and start the test framework
+ mocha.ignoreLeaks();
+ mocha.run();
+});
\ No newline at end of file
diff --git a/tests/frontend/specs/button_bold.js b/tests/frontend/specs/button_bold.js
index 0898ea085..148fd3638 100644
--- a/tests/frontend/specs/button_bold.js
+++ b/tests/frontend/specs/button_bold.js
@@ -5,14 +5,14 @@ describe("bold button", function(){
});
it("makes text bold", function() {
- //get the inner iframe
+ //get the inner iframe
var $inner = testHelper.$getPadInner();
//get the first text element out of the inner iframe
var firstTextElement = $inner.find("div").first();
//select this text element
- testHelper.selectText(firstTextElement[0]);
+ testHelper.selectText(firstTextElement[0], $inner);
//get the bold button and click it
var $boldButton = testHelper.$getPadChrome().find(".buttonicon-bold");