Skip to content

Commit

Permalink
cross_domain-wasn't consistently passing
Browse files Browse the repository at this point in the history
  • Loading branch information
David Clarke committed Apr 11, 2012
1 parent 3d97355 commit 2f0bcc9
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 26 deletions.
2 changes: 2 additions & 0 deletions apphelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ const PERMS_FILE = 0644;

var popupNotifications = getPopupNotifications(window.top);

var event_listener_loaded = {};

netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
Components.classes["@mozilla.org/permissionmanager;1"]
.getService(Components.interfaces.nsIPermissionManager)
Expand Down
4 changes: 3 additions & 1 deletion apps/include.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
<script src="../jshelper.js"></script>
<!-- finally, define our handlers that'll be invoked over jschannel by the parent -->
<script>

window.addEventListener('message', doSomething);
var installed = false;

function doSomething(event) {
if(event.data == "getSelf") {
var origin = URLParse(appURL).normalize().originOnly().toString();
Expand Down Expand Up @@ -101,7 +103,7 @@
next
);
}
}
}
}
</script>
</html>
19 changes: 0 additions & 19 deletions jshelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,6 @@ var SERVERS = {"_primary":"http://127.0.0.1:8088",
"no_delegated_install":"http://sub2.test2.example.org:80/chrome/dom/tests/mochitest/webapps/apps/no_delegated_install.webapp"
};

function createIframe(name) {

var appURL = SERVERS[name];
appURL = appURL.substring(0,appURL.indexOf(name + ".webapp"));
var iframe = document.createElement("iframe");
iframe.setAttribute('type', 'content');
iframe.setAttribute('src', appURL + "include.html");
iframe.setAttribute('style', "width: 350px; height: 350px; display: block;");
iframe.setAttribute('id', name);
iframe.height = window.innerHeight + 'px';
iframe.width = window.innerWidth + 'px';
info(appURL + "include.html");
document.documentElement.appendChild(iframe);

}

function onIframeLoad(name, check, next) {
document.getElementById(name).contentWindow.wrappedJSObject.next = next;
Expand Down Expand Up @@ -172,7 +157,6 @@ function mozAppscb(pending, comparatorObj, check, next) {
info("success cb, called");
if(pending.result) {
if(pending.result.length) {
info("length = " + pending.result.length);
for(i=0;i < pending.result.length;i++) {
pending.result[i].status= 'success';
js_traverse(comparatorObj[i], check, pending.result[i]);
Expand All @@ -183,10 +167,8 @@ function mozAppscb(pending, comparatorObj, check, next) {
js_traverse(comparatorObj[0], check, pending.result);
}
} else {
info('here');
js_traverse(comparatorObj[0], check, null);
}
info("typeof next = " + typeof next);
if(typeof next == 'function') {
info("calling next");
next();
Expand Down Expand Up @@ -250,7 +232,6 @@ function install(appURL, check, receipts, next) {

function getInstalled(appURLs, check, receipts, next) {
var checkInstalled = [];
info("HERE");
for (var i = 0; i < appURLs.length ; i++) {
var appURL = appURLs[i];
var origin = URLParse(appURL).normalize().originOnly().toString();
Expand Down
22 changes: 16 additions & 6 deletions test_cross_domain.xul
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=
<script type="application/javascript" src="apphelper.js"/>
<script type="application/javascript" src="jshelper.js"/>
<script type="application/javascript" src="urlmatch.js"/>

<!-- test results are displayed in the html:body -->
<head></head>
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id="
target="_blank">Mozilla Bug </a>
<iframe id="super_crazy" onload="go();" src="http://www.example.com:80/chrome/dom/tests/mochitest/webapps/apps/include.html"/>
<iframe id="no_delegated_install" onload="go();" src="http://sub2.test2.example.org:80/chrome/dom/tests/mochitest/webapps/apps/include.html"/>

</body>

Expand All @@ -25,11 +28,19 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=
steps = [setUp, verify_no_apps, get_installed_returns_nothing, install_super_crazy, check_event_listener_fired, get_self_returns_nothing,
get_self_on_domain, install_on_domain, check_event_listener_fired, get_all_installed,
get_installed_on_domain, uninstall_on_domain, get_all_on_domain, tearDown];
var iframes_loaded = 0 ;

function go() {
++iframes_loaded;
if (iframes_loaded >= 2) {
runAll(steps);
}
}

runAll(steps);

function setUp(next) {
info("in " + arguments.callee.name);

uninstallAll(next);
}

Expand Down Expand Up @@ -68,8 +79,11 @@ function get_self_returns_nothing(next) {

function get_self_on_domain(next) {
info("in " + arguments.callee.name);
if (!event_listener_loaded["super_crazy"]) {
if(document.getElementById(name))
document.getElementById(name).contentWindow.postMessage("areweReadyYet", '*');
}
onIframeLoad("super_crazy", ok, next);

document.getElementById("super_crazy").contentWindow.postMessage("getSelf", '*');
}

Expand All @@ -85,7 +99,6 @@ function get_all_installed(next) {
getInstalled(appURLs, ok, null, next);
}


function uninstall_on_domain(next) {
info("in " + arguments.callee.name);
onIframeLoad("super_crazy", ok, next);
Expand All @@ -109,9 +122,6 @@ function tearDown() {
uninstallAll();
}

createIframe("super_crazy");
createIframe("no_delegated_install");

</script>

</window>
Expand Down

0 comments on commit 2f0bcc9

Please sign in to comment.