function test_extension() {
  var workspace = new Blockly.Workspace();
  var block;
  try {
    assertUndefined(Blockly.Extensions.ALL_['extensions_test']);

    var numCallsToBefore = 0;
    var numCallsToAfter = 0;

    // Extension defined before the block type is defined.
    Blockly.Extensions.register('extensions_test_before', function () {
      numCallsToBefore++;
      this.extendedWithBefore = true;
    });

    Blockly.defineBlocksWithJsonArray([{
      "type": "extension_test_block",
      "message0": "extension_test_block",
      "extensions": ["extensions_test_before", "extensions_test_after"]
    }]);

    // Extension defined after the block type (but before instantiation).
    Blockly.Extensions.register('extensions_test_after', function () {
      numCallsToAfter++;
      this.extendedWithAfter = true;
    });

    assert(goog.isFunction(Blockly.Extensions.ALL_['extensions_test_before']));
    assert(goog.isFunction(Blockly.Extensions.ALL_['extensions_test_after']));
    assertEquals(0, numCallsToBefore);
    assertEquals(0, numCallsToAfter);

    block = new Blockly.Block(workspace, 'extension_test_block');

    assertEquals(1, numCallsToBefore);
    assertEquals(1, numCallsToAfter);
    assert(block.extendedWithBefore);
    assert(block.extendedWithAfter);
  } finally {
    block && block.dispose();
    workspace.dispose();

    delete Blockly.Extensions.ALL_['extensions_test_before'];
    delete Blockly.Extensions.ALL_['extensions_test_after'];
    delete Blockly.Blocks['extension_test_block'];
  }
}
@fileoverview Tests for Blockly.Extensions
@author Anm@anm.me (Andrew n marshall)