Skip to main content
Post Made Community Wiki by animusonStaffMod
Source Link
pomeh
  • 4.9k
  • 13
  • 5

I've noticed some points during testing:

  • the language order is not the same in the displayed post and in edit mode, this is a bit confusing
  • you can't edit the code using the code snippet tool: if you have already the Begin snippet: js tag in your content and click on the button, the content is not prefilled
  • make edit pane resizable because they are too small, and depending on what you do you want more space for JavaScript or for CSS only
  • there is no error reporting when the code fails, neither syntax errors or runtime errors
  • debugger keyword is not working for me using Firefox 30: the Firebug debugger is activated but the file shown is blank making impossible to use step into/over buttons
  • since the JS code is all inlined on one single line, it doesn't handle simple comments in your code (test at the end of my snippet below)

Also, here are my two cents tests, almost accessing all kind of objects and properties (with no success so far):

function debug() {
  var args = [].slice.call(arguments);

  console.log.apply(console, args);
  /*window.alert.apply(window, [args.join(' ')]);*/
}

function showType(a, b) {
  debug(a, typeof b);
}

var TESTS = [

  /* PASSING TESTS */
  function() {
    debug('#################');
    debug('# PASSING TESTS #');
    debug('#################');
  },

  function() {
    showType('parent ', parent);
  },
  function() {
    showType('parent.window', parent.window);
  },
  function() {
    showType('console', console);
  },
  function() {
    showType('top', top);
  },
  function() {
    showType('eval', eval);
  },
  function() {
    showType('parent.postMessage', parent.postMessage);
  },
  function() {
    showType('top.postMessage', top.postMessage);
  },
  function() {
    showType('document.cookies', document.cookies);
  },


  function() {
    debug( Object.keys(window) );
    /* prints: window,location,top,document,InstallTrigger,console,showType,TESTS,external,sidebar */
  },
  function() {
    debug( Object.keys(document) );
    /* prints: location */
  },
  function() {
    debug( Object.keys(top) );
    debug( Object.keys(top).length );
    /* prints: 0 */
  },
  function() {
    debug( Object.keys(parent) );
    debug( Object.keys(parent).length );
    /* prints: 0 */
  },

  function() {
    console.log('some log output');
  },

  function(){
    showType('top.top', top.top);
  },
  function(){
    showType('parent.top', parent.top);
  },
  function(){
    showType('top.location', top.location);
  },
  function(){
    showType('parent.location', parent.location);
  },
  function(){
    showType('top.window', top.window);
  },
  function(){
    showType('parent.window', parent.window);
  },
  function(){
    showType('parent', parent);
  },
  function(){
    showType('parent.window', parent.window);
  },
  function(){
    showType('parent.window.parent', parent.window.parent);
  },
  function(){
    showType('parent.window.parent.window', parent.window.parent.window);
  },
  function(){
    showType('window.addEventListener', window.addEventListener);
  },
  function(){
    showType('parent.window.top', parent.window.top);
  },

  function() {
    debug(top === parent);
    debug(top.postMessage=== parent.postMessage);
  },

  function(){
    showType('parent.window.onbeforeunload', parent.window.onbeforeunload);
  },
  function(){
    showType('parent.window.document', parent.window.document);
  },
  function(){
    showType('parent.location.replace', parent.location.replace);
  },

  function(){
    eval("showType('parent', parent);");
  },


  /* MIXED TESTS */
  /* with success and failures */
  function() {
    debug('###############');
    debug('# MIXED TESTS #');
    debug('###############');
  },

  function() {
    var keys = Object.keys(window), i = keys.length, name;

    while (name = keys[--i])
    {
      try {
        showType('top.'+name, top[name]);
      } catch (e) {
        debug('KO top.'+name, e);
      }

      try {
        showType('parent.'+name, parent[name]);
      } catch (e) {
        debug('KO parent.'+name, e);
      }

    }

  },



  /* FAILING TESTS */
  function() {
    debug('#################');
    debug('# FAILING TESTS #');
    debug('#################');
  },

  function KO() {
    showType('parent.document', parent.document);
  },
  function KO() {
    showType('parent.document.cookies', parent.document.cookies);
  },
  function KO() {
    showType('parent.document.postMessage', parent.document.postMessage);
  },
  function KO() {
    showType('parent.window.alert', parent.window.alert);
  },
  function KO() {
    showType('parent.window.StackExchange', parent.window.StackExchange);
  },
  function KO() {
    showType('parent.window.console', parent.window.console);
  },
  function KO() {
    showType('parent.cookies', parent.cookies);
  },
  function KO() {
    showType('top.cookies', top.cookies);
  },
  function KO() {
    showType('parent.StackExchange', parent.StackExchange);
  },
  function KO() {
    showType('top.StackExchange', top.StackExchange);
  },
  function KO() {
    showType('parent.alert', parent.alert);
  },
  function KO() {
    showType('top.alert', top.alert);
  },
  function KO() {
    showType('parent.console', parent.console);
  },
  function KO() {
    showType('top.console', top.console);
  },
  function KO() {
    showType('parent.addEventListener', parent.addEventListener);
  },
  function KO() {
    showType('top.addEventListener', top.addEventListener);
  },
  function KO() {
    showType('top.snippetRenderer', top.snippetRenderer);
  },
  function KO() {
    showType('parent.snippetRenderer', parent.snippetRenderer);
  },
  function KO() {
    showType('top.jQuery', top.jQuery);
  },
  function KO() {
    showType('parent.jQuery', parent.jQuery);
  },
  function KO(){
    showType('parent.addEventListener', parent.addEventListener);
  },
  function KO(){
    showType('parent.window.parent.addEventListener', parent.window.parent.addEventListener);
  },
  function KO(){
    showType('parent.window.top.addEventListener', parent.window.top.addEventListener);
  },
  function KO(){
    parent.location.replace('https://stackoverflow.com');
  },
  function KO(){
    showType('parent.location.href', parent.location.href);
  },
  function KO(){
    parent.location.href = 'https://stackoverflow.com'
  },
  function KO(){
    eval("showType('parent.addEventListener', parent.addEventListener);");
  },

  function KO(){
    showType('parent.window.open', parent.window.open);
  },
  function KO(){
    top.window.top.open('https://stackoverflow.com', '_blank');
  },
  function KO(){
    window.open('https://stackoverflow.com', '_blank');
  },

];

TESTS.forEach(function(test) {
  debug('Running:', test.toString());

  try {
    test();

  } catch (e) {
    debug('KO ', e);
  }
});

alert('Almost end of the script');
// following code will never be executed
alert('End of the script');