diff --git a/IPython/html/tests/util.js b/IPython/html/tests/util.js
index 1636474c3..a572190bc 100644
--- a/IPython/html/tests/util.js
+++ b/IPython/html/tests/util.js
@@ -2,15 +2,15 @@
// Utility functions for the HTML notebook's CasperJS tests.
//
-// Get the URL of a notebook server on which to run tests.
casper.get_notebook_server = function () {
+ // Get the URL of a notebook server on which to run tests.
port = casper.cli.get("port");
port = (typeof port === 'undefined') ? '8888' : port;
return 'http://127.0.0.1:' + port;
};
-// Create and open a new notebook.
casper.open_new_notebook = function () {
+ // Create and open a new notebook.
var baseUrl = this.get_notebook_server();
this.start(baseUrl);
this.thenClick('button#new_notebook');
@@ -34,15 +34,15 @@ casper.open_new_notebook = function () {
});
};
-// Return whether or not the kernel is running.
casper.kernel_running = function kernel_running() {
+ // Return whether or not the kernel is running.
return this.evaluate(function kernel_running() {
return IPython.notebook.kernel.running;
});
};
-// Shut down the current notebook's kernel.
casper.shutdown_current_kernel = function () {
+ // Shut down the current notebook's kernel.
this.thenEvaluate(function() {
IPython.notebook.kernel.kill();
});
@@ -50,8 +50,9 @@ casper.shutdown_current_kernel = function () {
this.wait(1000);
};
-// Delete created notebook.
casper.delete_current_notebook = function () {
+ // Delete created notebook.
+
// For some unknown reason, this doesn't work?!?
this.thenEvaluate(function() {
IPython.notebook.delete();
@@ -59,6 +60,7 @@ casper.delete_current_notebook = function () {
};
casper.wait_for_busy = function () {
+ // Waits for the notebook to enter a busy state.
this.waitFor(function () {
return this.evaluate(function () {
return IPython._status == 'busy';
@@ -67,6 +69,7 @@ casper.wait_for_busy = function () {
};
casper.wait_for_idle = function () {
+ // Waits for the notebook to idle.
this.waitFor(function () {
return this.evaluate(function () {
return IPython._status == 'idle';
@@ -74,8 +77,8 @@ casper.wait_for_idle = function () {
});
};
-// wait for the nth output in a given cell
casper.wait_for_output = function (cell_num, out_num) {
+ // wait for the nth output in a given cell
this.wait_for_idle();
out_num = out_num || 0;
this.then(function() {
@@ -94,14 +97,14 @@ casper.wait_for_output = function (cell_num, out_num) {
});
};
-// wait for a widget msg que to reach 0
-//
-// Parameters
-// ----------
-// widget_info : object
-// Object which contains info related to the widget. The model_id property
-// is used to identify the widget.
casper.wait_for_widget = function (widget_info) {
+ // wait for a widget msg que to reach 0
+ //
+ // Parameters
+ // ----------
+ // widget_info : object
+ // Object which contains info related to the widget. The model_id property
+ // is used to identify the widget.
this.waitFor(function () {
var pending = this.evaluate(function (m) {
return IPython.notebook.kernel.widget_manager.get_model(m).pending_msgs;
@@ -115,8 +118,8 @@ casper.wait_for_widget = function (widget_info) {
});
};
-// return an output of a given cell
casper.get_output_cell = function (cell_num, out_num) {
+ // return an output of a given cell
out_num = out_num || 0;
var result = casper.evaluate(function (c, o) {
var cell = IPython.notebook.get_cell(c);
@@ -137,33 +140,33 @@ casper.get_output_cell = function (cell_num, out_num) {
}
};
-// return the number of cells in the notebook
casper.get_cells_length = function () {
+ // return the number of cells in the notebook
var result = casper.evaluate(function () {
return IPython.notebook.get_cells().length;
});
return result;
};
-// Set the text content of a cell.
casper.set_cell_text = function(index, text){
+ // Set the text content of a cell.
this.evaluate(function (index, text) {
var cell = IPython.notebook.get_cell(index);
cell.set_text(text);
}, index, text);
};
-// Get the text content of a cell.
casper.get_cell_text = function(index){
+ // Get the text content of a cell.
return this.evaluate(function (index) {
var cell = IPython.notebook.get_cell(index);
return cell.get_text();
}, index);
};
-// Inserts a cell at the bottom of the notebook
-// Returns the new cell's index.
casper.insert_cell_at_bottom = function(cell_type){
+ // Inserts a cell at the bottom of the notebook
+ // Returns the new cell's index.
cell_type = cell_type || 'code';
return this.evaluate(function (cell_type) {
@@ -172,9 +175,9 @@ casper.insert_cell_at_bottom = function(cell_type){
}, cell_type);
};
-// Insert a cell at the bottom of the notebook and set the cells text.
-// Returns the new cell's index.
casper.append_cell = function(text, cell_type) {
+ // Insert a cell at the bottom of the notebook and set the cells text.
+ // Returns the new cell's index.
var index = this.insert_cell_at_bottom(cell_type);
if (text !== undefined) {
this.set_cell_text(index, text);
@@ -182,9 +185,9 @@ casper.append_cell = function(text, cell_type) {
return index;
};
-// Asynchronously executes a cell by index.
-// Returns the cell's index.
casper.execute_cell = function(index){
+ // Asynchronously executes a cell by index.
+ // Returns the cell's index.
var that = this;
this.then(function(){
that.evaluate(function (index) {
@@ -195,11 +198,11 @@ casper.execute_cell = function(index){
return index;
};
-// Synchronously executes a cell by index.
-// Optionally accepts a then_callback parameter. then_callback will get called
-// when the cell has finished executing.
-// Returns the cell's index.
casper.execute_cell_then = function(index, then_callback) {
+ // Synchronously executes a cell by index.
+ // Optionally accepts a then_callback parameter. then_callback will get called
+ // when the cell has finished executing.
+ // Returns the cell's index.
var return_val = this.execute_cell(index);
this.wait_for_idle();
@@ -214,18 +217,18 @@ casper.execute_cell_then = function(index, then_callback) {
return return_val;
};
-// Utility function that allows us to easily check if an element exists
-// within a cell. Uses JQuery selector to look for the element.
casper.cell_element_exists = function(index, selector){
+ // Utility function that allows us to easily check if an element exists
+ // within a cell. Uses JQuery selector to look for the element.
return casper.evaluate(function (index, selector) {
var $cell = IPython.notebook.get_cell(index).element;
return $cell.find(selector).length > 0;
}, index, selector);
};
-// Utility function that allows us to execute a jQuery function on an
-// element within a cell.
casper.cell_element_function = function(index, selector, function_name, function_args){
+ // Utility function that allows us to execute a jQuery function on an
+ // element within a cell.
return casper.evaluate(function (index, selector, function_name, function_args) {
var $cell = IPython.notebook.get_cell(index).element;
var $el = $cell.find(selector);
@@ -233,9 +236,10 @@ casper.cell_element_function = function(index, selector, function_name, function
}, index, selector, function_name, function_args);
};
-// Validate the entire dual mode state of the notebook. Make sure no more than
-// one cell is selected, focused, in edit mode, etc...
casper.validate_notebook_state = function(message, mode, cell_index) {
+ // Validate the entire dual mode state of the notebook. Make sure no more than
+ // one cell is selected, focused, in edit mode, etc...
+
// General tests.
this.test.assertEquals(this.get_keyboard_mode(), this.get_notebook_mode(),
message + '; keyboard and notebook modes match');
@@ -274,15 +278,16 @@ casper.validate_notebook_state = function(message, mode, cell_index) {
}
};
-// Select a cell in the notebook.
casper.select_cell = function(index) {
+ // Select a cell in the notebook.
this.evaluate(function (i) {
IPython.notebook.select(i);
}, {i: index});
};
-// Emulate a click on a cell's editor.
casper.click_cell_editor = function(index) {
+ // Emulate a click on a cell's editor.
+
// Code Mirror does not play nicely with emulated brower events.
// Instead of trying to emulate a click, here we run code similar to
// the code used in Code Mirror that handles the mousedown event on a
@@ -294,22 +299,22 @@ casper.click_cell_editor = function(index) {
}, {i: index});
};
-// Set the Code Mirror instance cursor's location.
casper.set_cell_editor_cursor = function(index, line_index, char_index) {
+ // Set the Code Mirror instance cursor's location.
this.evaluate(function (i, l, c) {
IPython.notebook.get_cell(i).code_mirror.setCursor(l, c);
}, {i: index, l: line_index, c: char_index});
};
-// Focus the notebook div.
casper.focus_notebook = function() {
+ // Focus the notebook div.
this.evaluate(function (){
$('#notebook').focus();
}, {});
};
-// Emulate a keydown in the notebook.
casper.trigger_keydown = function() {
+ // Emulate a keydown in the notebook.
for (var i = 0; i < arguments.length; i++) {
this.evaluate(function (k) {
var element = $(document);
@@ -319,25 +324,25 @@ casper.trigger_keydown = function() {
}
};
-// Get the mode of the keyboard manager.
casper.get_keyboard_mode = function() {
+ // Get the mode of the keyboard manager.
return this.evaluate(function() {
return IPython.keyboard_manager.mode;
}, {});
};
-// Get the mode of the notebook.
casper.get_notebook_mode = function() {
+ // Get the mode of the notebook.
return this.evaluate(function() {
return IPython.notebook.mode;
}, {});
};
-// Get a single cell.
-//
-// Note: Handles to DOM elements stored in the cell will be useless once in
-// CasperJS context.
casper.get_cell = function(index) {
+ // Get a single cell.
+ //
+ // Note: Handles to DOM elements stored in the cell will be useless once in
+ // CasperJS context.
return this.evaluate(function(i) {
var cell = IPython.notebook.get_cell(i);
if (cell) {
@@ -347,8 +352,8 @@ casper.get_cell = function(index) {
}, {i : index});
};
-// Make sure a cell's editor is the only editor focused on the page.
casper.is_cell_editor_focused = function(index) {
+ // Make sure a cell's editor is the only editor focused on the page.
return this.evaluate(function(i) {
var focused_textarea = $('#notebook .CodeMirror-focused textarea');
if (focused_textarea.length > 1) { throw 'More than one Code Mirror editor is focused at once!'; }
@@ -364,22 +369,22 @@ casper.is_cell_editor_focused = function(index) {
}, {i : index});
};
-// Check if a cell is the only cell selected.
-// Pass null as the index to check if no cells are selected.
casper.is_only_cell_selected = function(index) {
+ // Check if a cell is the only cell selected.
+ // Pass null as the index to check if no cells are selected.
return this.is_only_cell_on(index, 'selected', 'unselected');
};
-// Check if a cell is the only cell in edit mode.
-// Pass null as the index to check if all of the cells are in command mode.
casper.is_only_cell_edit = function(index) {
+ // Check if a cell is the only cell in edit mode.
+ // Pass null as the index to check if all of the cells are in command mode.
return this.is_only_cell_on(index, 'edit_mode', 'command_mode');
};
-// Check if a cell is the only cell with the `on_class` DOM class applied to it.
-// All of the other cells are checked for the `off_class` DOM class.
-// Pass null as the index to check if all of the cells have the `off_class`.
casper.is_only_cell_on = function(i, on_class, off_class) {
+ // Check if a cell is the only cell with the `on_class` DOM class applied to it.
+ // All of the other cells are checked for the `off_class` DOM class.
+ // Pass null as the index to check if all of the cells have the `off_class`.
var cells_length = this.get_cells_length();
for (var j = 0; j < cells_length; j++) {
if (j === i) {
@@ -395,8 +400,8 @@ casper.is_only_cell_on = function(i, on_class, off_class) {
return true;
};
-// Check if a cell has a class.
casper.cell_has_class = function(index, classes) {
+ // Check if a cell has a class.
return this.evaluate(function(i, c) {
var cell = IPython.notebook.get_cell(i);
if (cell) {
@@ -406,8 +411,8 @@ casper.cell_has_class = function(index, classes) {
}, {i : index, c: classes});
};
-// Wrap a notebook test to reduce boilerplate.
casper.notebook_test = function(test) {
+ // Wrap a notebook test to reduce boilerplate.
this.open_new_notebook();
this.then(test);
@@ -465,8 +470,8 @@ casper.on('waitFor.timeout', function onWaitForTimeout(timeout) {
this.echo("Is the notebook server running?");
});
-// Pass `console.log` calls from page JS to casper.
casper.print_log = function () {
+ // Pass `console.log` calls from page JS to casper.
this.on('remote.message', function(msg) {
this.echo('Remote message caught: ' + msg);
});