Skip to content

Commit

Permalink
Discovered the power of explicit_done:true, removed unneccessary code
Browse files Browse the repository at this point in the history
  • Loading branch information
Hallvord R. M. Steen committed May 24, 2014
1 parent af9aaca commit cd5ef37
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 40 deletions.
Expand Up @@ -27,20 +27,18 @@
"null with var - after navigation": {stringified_opener:'null'},
"null without var - after navigation": {stringified_opener:'null'}
}

var test = async_test("overwriting window.opener", {timeout:240000});
var sub_props = {timeout: 10000};
setup({timeout: 480000, explicit_done: true});
var idx = 0, win;
var testURL = location.pathname.replace('overwriting-window-opener.html', 'support/window-opener-popup.html');
testURL = location.protocol + '//' + 'www1.' + location.host + testURL + '?';

window.addEventListener('message', test.step_func(function (e) {
window.addEventListener('message', function (e) {
if(e.data === 'DONE'){
// this test is just an empty wrapper for the sub-tests, it doesn't assert anything
test.done();
done();
return;
}
var data = e.data, t2;
var data = e.data;
var reading_throws = false, opener_is_this_window = false, stringified_opener = '';
try{
var the_opener = win.opener;
Expand All @@ -50,62 +48,46 @@
reading_throws = true;
}
if(data.step === 'pre-nav'){ // First part of test, before navigation
t2 = async_test(data.name +' - setting should not throw', sub_props);
t2.step( function(){
test(function(){
assert_equals(data.setting_throws, expectations.setting_throws);
});
t2.done();
t2 = async_test(data.name +' setting succeeds', sub_props);
t2.step( function(){
}, data.name +' - setting should not throw');
test(function(){
assert_equals(data.setting_succeeds, expectations.setting_succeeds);
});
t2.done();
t2 = async_test(data.name +' getting redefined property (from opener, different origin) throws', sub_props);
t2.step( function(){
}, data.name +' setting succeeds');
test(function(){
assert_equals(reading_throws, expectations.reading_throws, 'opener set to '+ data.name+' - reading should throw ' + (reading_throws ? '' : ' (opener stringifies as ' + stringified_opener + ')') );
assert_false(opener_is_this_window, 'Opener no longer refers to this window when it\'s been set');
});
t2.done();
}, data.name +' getting redefined property (from opener, different origin) throws');
}else if(data.step === 'post-nav'){
if(expectations[data.name]){ // this is a special case..
t2 = async_test(data.name + ', stringifying throws?', sub_props);
t2.step(function(){
test(function(){
assert_false(data.stringifying_throws);
assert_equals(data.stringified_opener, expectations[data.name].stringified_opener);
});
t2.done();
t2 = async_test(data.name + ', win.opener read from opener is null', sub_props);
t2.step(function(){
}, data.name + ', stringifying throws?');
test(function(){
assert_equals(win.opener, null);
assert_false(opener_is_this_window, 'is win.opener self?');
});
t2.done();
}, data.name + ', win.opener read from opener is null');
}else{
t2 = async_test(data.name + ', stringifying throws', sub_props);
t2.step(function(){
test(function(){
assert_true(data.stringifying_throws);
assert_equals(data.stringified_opener, 'not tested');
});
t2.done();
t2 = async_test(data.name + ', win.opener read from opener is self', sub_props);
t2.step(function(){
}, data.name + ', stringifying throws');
test(function(){
assert_true(opener_is_this_window);
});
t2.done();
}, data.name + ', win.opener read from opener is self');
}
if(data.name.indexOf('window')>-1){
// special case: opener was set to 'window' (i.e. the popup's window object) before navigating
// maybe this is persistent in some UAs?
t2 = async_test(data.name + ', window.opener read from popup is not self');
t2.step(function(){
test(function(){
assert_false(data.is_self);
});
t2.done();
}, data.name + ', window.opener read from popup is not self');
}

win = window.open(testURL + 'idx=' + (parseInt(data.idx)+1));
}
}), false);
}, false);

win = window.open(testURL + 'idx=' + '0');

Expand Down
Expand Up @@ -5,7 +5,7 @@
<body>
<p>window.opener test helper window - post navigation</p>
<script>
window.addEventListener('message', function (e) { console.log(e.source);
window.addEventListener('message', function (e) {
if(e.data === 'poll for results'){
var testidx = location.search.match(/idx=(\d+)/)[1];
var name = decodeURIComponent(location.search.match(/name=([^&]+)/)[1]);
Expand Down

0 comments on commit cd5ef37

Please sign in to comment.