xdomain.html 10.6 KB
<html>
<head>
	<script type="text/javascript">
	  var dohArgs= (window.parent.doh && window.parent.doh.dohArgs) || {async:0, variation:2};

	  // for test debuggin...
	  //dohArgs = {async:0, variation:1}
	  //dohArgs = {async:"legacyAsync", variation:1}
	  //dohArgs = {async:0, variation:2}
	  //dohArgs = {async:"legacyAsync", variation:2}

	  var dojoConfig = {
		async:dohArgs.async
	  };
	  var expectedSequence;
	  
	  var built = 1;
	  //>>excludeStart("srcVersion", kwArgs.copyTests=="build");
	  built = 0;
	  //>>excludeEnd("srcVersion");
	  if((dohArgs.async=="legacyAsync" || built) && dohArgs.variation==2){
		expectedSequence = [
			"local1-5",
			"local1-17",
			"local2-1",
			"local2-2",
			"local2-3",
			"local3-1",
			"local3-2",
			"local1-1",
			"local1-2",
			"local1-3",
			"local1-dep-1",
			"local1-dep-2",
			"local1-4",
			"local1-6",
			"dojo.tests._base.loader.xdomain.local1-runtimeDependent1-1",
			"dojo.tests._base.loader.xdomain.local1-runtimeDependent1-2",
			"local1-7",
			"local1-8",
			"dojo.tests._base.loader.xdomain.local1-browser-1",
			"dojo.tests._base.loader.xdomain.local1-browser-2",
			"dojo.tests._base.loader.xdomain.local1-browser-skip-1",
			"local1-9",
			"local1-10",
			"local1-11",
			"local1-12",
			"local1-13",
			"local1-14",
			"local1-15",
			"local1-16",
			"local1-18",
			"local3-3",
			"local2-4"].join(";");
	  }else if(dohArgs.async==0 && dohArgs.variation==2){
		expectedSequence = [
			"local2-1",
			"local2-2",
			"local2-3",
			"local2-4",
			"local1-5",
			"local1-17",
			"local3-1",
			"local3-2",
			"local1-1",
			"local1-2",
			"local1-3",
			"local1-dep-1",
			"local1-dep-2",
			"local1-4",
			"local1-6",
			"dojo.tests._base.loader.xdomain.local1-runtimeDependent1-1",
			"dojo.tests._base.loader.xdomain.local1-runtimeDependent1-2",
			"local1-7",
			"local1-8",
			"dojo.tests._base.loader.xdomain.local1-browser-1",
			"dojo.tests._base.loader.xdomain.local1-browser-2",
			"dojo.tests._base.loader.xdomain.local1-browser-skip-1",
			"local1-9",
			"local1-10",
			"local1-11",
			"local1-12",
			"local1-13",
			"local1-14",
			"local1-15",
			"local1-16",
			"local1-18",
			"local3-3"].join(";");
	  }else if((dohArgs.async=="legacyAsync" || built) && dohArgs.variation==1){
		expectedSequence = [
			"local1-5",
			"local1-17",
			"local1-1",
			"local1-2",
			"local1-3",
			"local1-dep-1",
			"local1-dep-2",
			"local1-4",
			"local1-6",
			"dojo.tests._base.loader.xdomain.local1-runtimeDependent1-1",
			"dojo.tests._base.loader.xdomain.local1-runtimeDependent1-2",
			"local1-7",
			"local1-8",
			"dojo.tests._base.loader.xdomain.local1-browser-1",
			"dojo.tests._base.loader.xdomain.local1-browser-2",
			"dojo.tests._base.loader.xdomain.local1-browser-skip-1",
			"local1-9",
			"local1-10",
			"local1-11",
			"local1-12",
			"local1-13",
			"local1-14",
			"local1-15",
			"local1-16",
			"local1-18"].join(";");
	  }else if(dohArgs.async==0 && dohArgs.variation==1){
		expectedSequence = [
			"local1-1",
			"local1-2",
			"local1-3",
			"local1-4",
			"local1-5",
			"local1-6",
			"local1-7",
			"local1-8",
			"local1-9",
			"local1-10",
			"local1-11",
			"local1-12",
			"local1-13",
			"local1-14",
			"local1-15",
			"local1-16",
			"local1-17",
			"local1-18",
			"local1-dep-1",
			"local1-dep-2",
			"dojo.tests._base.loader.xdomain.local1-runtimeDependent1-1",
			"dojo.tests._base.loader.xdomain.local1-runtimeDependent1-2",
			"dojo.tests._base.loader.xdomain.local1-browser-1",
			"dojo.tests._base.loader.xdomain.local1-browser-2",
			"dojo.tests._base.loader.xdomain.local1-browser-skip-1"].join(";");
	  }
	</script>
	<script type="text/javascript" src="../../../../dojo.js"></script>
	<script type="text/javascript">
	    define("dijit", ["dojo"], function(dojo){ return dojo.dijit; });
	    define("dojox", ["dojo"], function(dojo){ return dojo.dojox; });



		var xdomainLog= [], xdomainExecSequence= [];

		require(["dojo", "doh", "dojo/has"], function(dojo, doh, has){ 
			if(!("legacyMode" in require)){
				doh.register("xdomain", function(t){
					t.is("dojotoolkit.org", define.vendor);
					t.is(true, "legacyMode" in require);
				});
				doh.runOnLoad();
				return;
		    }

			// pretend that everything except the stuff in dojo/tests/_base/loader/xdomain is xdomain
			require.isXdUrl = function(url){
				return !/loader\/xdomain/.test(url) && !/syncBundle/.test(url);
			};

			// each of these dojo.requires a xdomain module which puts the loader in xdomain loading mode,
		    // then dojo.requires a local tree of modules with various loading challenges. Many of the loading
			// challenges are in local1; therefore we test when that module causes the xdomain shift and when
			// the loader is already in xdomain when that module is demanded
			if(dohArgs.variation==1){
				dojo.require("dojo.tests._base.loader.xdomain.local1");
				//>>excludeStart("srcVersion", kwArgs.copyTests=="build");
				if(dohArgs.async==0){
					// can't stop the local module from completely executing...
					xdomainLog.push(11, dojo.tests._base.loader.xdomain.local1==="stepOnLocal1");
					xdomainLog.push(12, dojo.require("dojo.tests._base.loader.xdomain.local1")==="stepOnLocal1");
					xdomainLog.push(13, require("dojo/tests/_base/loader/xdomain/local1")==="stepOnLocal1");
				}else{
					xdomainLog.push(11, dojo.getObject("dojo.tests._base.loader.xdomain.local1")===undefined);
				}
				//>>excludeEnd("srcVersion");
			}else{
				dojo.require("dojo.tests._base.loader.xdomain.local2");
				//>>excludeStart("srcVersion", kwArgs.copyTests=="build");
				if(dohArgs.async==0){
					// can't stop the local module from completely executing...
					xdomainLog.push(11, dojo.tests._base.loader.xdomain.local2.status==="local2-loaded");
					xdomainLog.push(12, dojo.require("dojo.tests._base.loader.xdomain.local2").status==="local2-loaded");
					xdomainLog.push(13, require("dojo/tests/_base/loader/xdomain/local2").status==="local2-loaded");
				}else{
					xdomainLog.push(11, dojo.getObject("dojo.tests._base.loader.xdomain.local2")===undefined);
				}
				xdomainLog.push(16,	dojo.getObject("dojo.tests._base.loader.xdomain.local1")===undefined);
				if(dojo.isIE!=6){
					try{
						require("dojo/tests/_base/loader/xdomain/local1");
						xdomainLog.push(19, false);
					}catch(e){
						xdomainLog.push(19, true);
					}
				}
				//>>excludeEnd("srcVersion");
			}


			// but none of the modules after going into xdomain loading should be executed
			// (WARNING: ie might look different because of its strange caching behavior)
			xdomainLog.push(14, (dojo.hash===undefined));
			xdomainLog.push(15, (dojo.cookie===undefined));
			xdomainLog.push(17, dojo.getObject("dojo.tests._base.loader.xdomain.local3")===undefined);
			if(dojo.isIE!=6){
				try{
					require("dojo/tests/_base/loader/xdomain/local3");
					xdomainLog.push(18, false);
				}catch(e){
					xdomainLog.push(18, true);
				}
			}

			doh.register("xdomain", function(t){
				//console.log(xdomainExecSequence.join(";"));
				for(var i= 0; i<xdomainLog.length; i+= 2){
					t.is(true, xdomainLog[i+1], "failed at id="+xdomainLog[i]);
				}

				t.is(expectedSequence, xdomainExecSequence.join(";"));

				t.is("stepOnLocal1", dojo.tests._base.loader.xdomain.local1);
				t.is("stepOnLocal1", dojo.getObject("dojo.tests._base.loader.xdomain.local1"));
				t.is("stepOnLocal1", dojo.require("dojo.tests._base.loader.xdomain.local1"));
				t.is("stepOnLocal1", require("dojo/tests/_base/loader/xdomain/local1"));

				t.is("stepOn1SteppedOn", dojo.tests._base.loader.xdomain.local1SteppedOn);
				t.is("stepOn1SteppedOn", dojo.getObject("dojo.tests._base.loader.xdomain.local1SteppedOn"));
				t.is("stepOn1SteppedOn", dojo.require("dojo.tests._base.loader.xdomain.local1SteppedOn"));
				t.is("stepOn1SteppedOn", require("dojo/tests/_base/loader/xdomain/local1SteppedOn"));

				t.is("local1NotSteppedOn", dojo.tests._base.loader.xdomain.local1NotSteppedOn.status);
				t.is("local1NotSteppedOn", dojo.getObject("dojo.tests._base.loader.xdomain.local1NotSteppedOn.status"));
				t.is("local1NotSteppedOn", dojo.require("dojo.tests._base.loader.xdomain.local1NotSteppedOn").status);
				t.is("local1NotSteppedOn", require("dojo/tests/_base/loader/xdomain/local1NotSteppedOn").status);

				t.is("dojo.tests._base.loader.xdomain.local1-dep-ok", dojo.tests._base.loader.xdomain["local1-dep"].status);
				t.is("dojo.tests._base.loader.xdomain.local1-dep-ok", dojo.getObject("dojo.tests._base.loader.xdomain.local1-dep.status"));
				t.is("dojo.tests._base.loader.xdomain.local1-dep-ok", dojo.require("dojo.tests._base.loader.xdomain.local1-dep").status);
				t.is("dojo.tests._base.loader.xdomain.local1-dep-ok", require("dojo/tests/_base/loader/xdomain/local1-dep").status);

				t.is("dojo.tests._base.loader.xdomain.local1-runtimeDependent1-ok", dojo.tests._base.loader.xdomain["local1-runtimeDependent1"].status);
				t.is("dojo.tests._base.loader.xdomain.local1-runtimeDependent1-ok", dojo.getObject("dojo.tests._base.loader.xdomain.local1-runtimeDependent1.status"));
				t.is("dojo.tests._base.loader.xdomain.local1-runtimeDependent1-ok", dojo.require("dojo.tests._base.loader.xdomain.local1-runtimeDependent1").status);
				t.is("dojo.tests._base.loader.xdomain.local1-runtimeDependent1-ok", require("dojo/tests/_base/loader/xdomain/local1-runtimeDependent1").status);

				t.is("ok", dojo.getObject("dojo.tests._base.loader.xdomain.local1-runtimeDependent").status);

				t.is(undefined, dojo.tests._base.loader.xdomain["local1-runtimeDependent2"]);
				t.is(undefined, dojo.getObject("dojo.tests._base.loader.xdomain.local1-runtimeDependent2"));
			    try{
    				require("dojo/tests/_base/loader/xdomain/local1/runtimeDependent2");
		            t.is(1, 0);
    			}catch(e){
		            t.is(1, 1);
    			}

				t.is("dojo.tests._base.loader.xdomain.local1-browser-ok", dojo.tests._base.loader.xdomain["local1-browser"].status);
				t.is("dojo.tests._base.loader.xdomain.local1-browser-ok", dojo.getObject("dojo.tests._base.loader.xdomain.local1-browser.status"));
				t.is("dojo.tests._base.loader.xdomain.local1-browser-ok", dojo.require("dojo.tests._base.loader.xdomain.local1-browser").status);
				t.is("dojo.tests._base.loader.xdomain.local1-browser-ok", require("dojo/tests/_base/loader/xdomain/local1-browser").status);

				t.isNot(undefined, dojo.cookie);
				t.is(dojo.cookie, dojo.getObject("dojo.cookie"));
				t.is(dojo.cookie, require("dojo/cookie"));
												   
				if(dohArgs.variation!=1){
					t.isNot(undefined, dojo.hash);
					t.is(dojo.hash, dojo.getObject("dojo.hash"));
					t.is(dojo.hash, require("dojo/hash"));
				}
			});
			doh.runOnLoad();
		});
	</script>
</head>
<body>
  <h1>check console</h1>
  <p>This test loads a not-xdomain module that contains a xdomain and a not-xdomain module</p>
</body>
</html>