| var FrameworkTest = TestCase.create("FrameworkTest"); |
| |
| FrameworkTest.prototype.testEmptyGetBundles = function() { |
| var framework = new orion.Framework(); |
| assertEquals(0, framework.getBundles().length); |
| }; |
| |
| FrameworkTest.prototype.getSetProperty = function() { |
| var framework = new orion.Framework(); |
| assertUndefined(framework.getProperty("test")); |
| framework.setProperty("test", "value"); |
| assertEquals("test", framework.getProperty("test")); |
| framework.setProperty("test"); |
| assertUndefined(framework.getProperty("test")); |
| }; |
| |
| FrameworkTest.prototype.testNullLocationInstallBundle = function() { |
| var framework = new orion.Framework(); |
| try { |
| framework.installBundle(null); |
| } catch (e) { |
| return; |
| } |
| fail(); |
| }; |
| |
| FrameworkTest.prototype.testSimpleInstallBundle = function() { |
| var framework = new orion.Framework(); |
| var b = framework.installBundle("xyz", {name:"xyz"}); |
| assertEquals(1, framework.getBundles().length); |
| assertEquals(orion.Bundle.INSTALLED, b.getState()); |
| }; |
| |
| FrameworkTest.prototype.testLocationInstallBundle = function() { |
| var framework = new orion.Framework(); |
| var clazz = Packages.org.eclipse.e4.languages.javascript.framework.test.AllTests; |
| var b = framework.installBundle(clazz.getResource("/scripts/bundle1")); |
| assertEquals(1, framework.getBundles().length); |
| assertEquals(orion.Bundle.INSTALLED, b.getState()); |
| }; |
| |
| FrameworkTest.prototype.testLocationResolveBundle = function() { |
| var framework = new orion.Framework(); |
| var clazz = Packages.org.eclipse.e4.languages.javascript.framework.test.AllTests; |
| var b = framework.installBundle(clazz.getResource("/scripts/bundle2")); |
| assertEquals(1, framework.getBundles().length); |
| assertEquals(orion.Bundle.INSTALLED, b.getState()); |
| framework.resolve(); |
| assertEquals(orion.Bundle.RESOLVED, b.getState()); |
| assertEquals(7, b.load("test").x); |
| assertEquals(8, b.load("test").y); |
| assertEquals(9, b.load("test").z); |
| }; |
| |
| // test is really slow because of envjs uri handling |
| //XXXing test out for now |
| FrameworkTest.prototype.XXXtestLocationResolveDojoBundle = function() { |
| var framework = new orion.Framework(); |
| var clazz = Packages.org.eclipse.e4.languages.javascript.framework.test.AllTests; |
| var b = framework.installBundle(clazz.getResource("/scripts/bundle3")); |
| assertEquals(1, framework.getBundles().length); |
| assertEquals(orion.Bundle.INSTALLED, b.getState()); |
| framework.resolve(); |
| assertEquals(orion.Bundle.RESOLVED, b.getState()); |
| assertTrue(b.load("dojo").version.toString().indexOf("1.3.3") != -1); |
| }; |
| |
| FrameworkTest.prototype.testEmptyRefresh = function() { |
| var framework = new orion.Framework(); |
| framework.refresh(); |
| }; |
| |
| FrameworkTest.prototype.testSimpleRefresh = function() { |
| var framework = new orion.Framework(); |
| var b = framework.installBundle("xyz", {name:"xyz"}); |
| assertEquals(1, framework.getBundles().length); |
| assertEquals(orion.Bundle.INSTALLED, b.getState()); |
| b.uninstall(); |
| assertEquals(orion.Bundle.UNINSTALLED, b.getState()); |
| assertEquals(1, framework.getBundles().length); |
| framework.refresh(); |
| assertEquals(0, framework.getBundles().length); |
| }; |
| |
| |
| FrameworkTest.prototype.testEmptyResolve = function() { |
| var framework = new orion.Framework(); |
| framework.resolve(); |
| }; |
| |
| FrameworkTest.prototype.testSimpleResolve = function() { |
| var framework = new orion.Framework(); |
| var b = framework.installBundle("xyz", {name:"xyz"}); |
| assertEquals(1, framework.getBundles().length); |
| assertEquals(orion.Bundle.INSTALLED, b.getState()); |
| framework.resolve(); |
| assertEquals(orion.Bundle.RESOLVED, b.getState()); |
| }; |
| |
| FrameworkTest.prototype.testResolveNonSingleton = function() { |
| var framework = new orion.Framework(); |
| var a = framework.installBundle("cde", {name:"cde", version:"1"}); |
| var b = framework.installBundle("cde2", {name:"cde", version:"2"}); |
| assertEquals(2, framework.getBundles().length); |
| assertEquals(orion.Bundle.INSTALLED, a.getState()); |
| assertEquals(orion.Bundle.INSTALLED, b.getState()); |
| framework.resolve(); |
| assertTrue(orion.Bundle.RESOLVED == a.getState()); |
| assertTrue(orion.Bundle.RESOLVED == b.getState()); |
| }; |
| |
| FrameworkTest.prototype.testResolveSingletonFail = function() { |
| var framework = new orion.Framework(); |
| var a = framework.installBundle("cde", {name:"cde", singleton:true, version:"1"}); |
| var b = framework.installBundle("cde2", {name:"cde", singleton:true, version:"2"}); |
| assertEquals(2, framework.getBundles().length); |
| assertEquals(orion.Bundle.INSTALLED, a.getState()); |
| assertEquals(orion.Bundle.INSTALLED, b.getState()); |
| framework.resolve(); |
| assertTrue(orion.Bundle.RESOLVED == a.getState()); |
| assertFalse(orion.Bundle.RESOLVED == b.getState()); |
| }; |
| |
| |
| FrameworkTest.prototype.testResolveImportsFail = function() { |
| var framework = new orion.Framework(); |
| var b = framework.installBundle("xyz", {name:"xyz", imports:["abc"]}); |
| assertEquals(1, framework.getBundles().length); |
| assertEquals(orion.Bundle.INSTALLED, b.getState()); |
| framework.resolve(); |
| assertFalse(orion.Bundle.RESOLVED == b.getState()); |
| }; |
| |
| FrameworkTest.prototype.testResolveOptionalImports = function() { |
| var framework = new orion.Framework(); |
| var b = framework.installBundle("xyz", {name:"xyz", imports:[{name:"abc", resolution:"optional"}]}); |
| assertEquals(1, framework.getBundles().length); |
| assertEquals(orion.Bundle.INSTALLED, b.getState()); |
| framework.resolve(); |
| assertTrue(orion.Bundle.RESOLVED == b.getState()); |
| }; |
| |
| FrameworkTest.prototype.testResolveImportsSuccess = function() { |
| var framework = new orion.Framework(); |
| var a = framework.installBundle("cde", {name:"cde", exports:["abc"], script:"var abc = {hi:7};"}); |
| var b = framework.installBundle("xyz", {name:"xyz", imports:["abc"]}); |
| assertEquals(2, framework.getBundles().length); |
| assertEquals(orion.Bundle.INSTALLED, a.getState()); |
| assertEquals(orion.Bundle.INSTALLED, b.getState()); |
| framework.resolve(); |
| assertTrue(orion.Bundle.RESOLVED == a.getState()); |
| assertTrue(orion.Bundle.RESOLVED == b.getState()); |
| }; |
| |
| FrameworkTest.prototype.testResolveVersionedImportsSuccess = function() { |
| var framework = new orion.Framework(); |
| var a = framework.installBundle("cde", {name:"cde", exports:[{name:"abc",version:"1.2"}], script:"var abc = {hi:7};"}); |
| var b = framework.installBundle("xyz", {name:"xyz", imports:[{name:"abc",version:"1.2"}]}); |
| assertEquals(2, framework.getBundles().length); |
| assertEquals(orion.Bundle.INSTALLED, a.getState()); |
| assertEquals(orion.Bundle.INSTALLED, b.getState()); |
| framework.resolve(); |
| assertTrue(orion.Bundle.RESOLVED == a.getState()); |
| assertTrue(orion.Bundle.RESOLVED == b.getState()); |
| }; |
| |
| FrameworkTest.prototype.testResolveVersionedImportsFail = function() { |
| var framework = new orion.Framework(); |
| var a = framework.installBundle("cde", {name:"cde", exports:[{name:"abc",version:"1.1"}], script:"var abc = {hi:7};"}); |
| var b = framework.installBundle("xyz", {name:"xyz", imports:[{name:"abc",version:"1.2"}]}); |
| assertEquals(2, framework.getBundles().length); |
| assertEquals(orion.Bundle.INSTALLED, a.getState()); |
| assertEquals(orion.Bundle.INSTALLED, b.getState()); |
| framework.resolve(); |
| assertTrue(orion.Bundle.RESOLVED == a.getState()); |
| assertFalse(orion.Bundle.RESOLVED == b.getState()); |
| }; |
| |
| |
| FrameworkTest.prototype.testResolveResourceImportsSuccess = function() { |
| var framework = new orion.Framework(); |
| var a = framework.installBundle("cde", {name:"cde", exports:["/abc/def"]}); |
| var b = framework.installBundle("xyz", {name:"xyz", imports:["/abc/def"]}); |
| assertEquals(2, framework.getBundles().length); |
| assertEquals(orion.Bundle.INSTALLED, a.getState()); |
| assertEquals(orion.Bundle.INSTALLED, b.getState()); |
| framework.resolve(); |
| assertTrue(orion.Bundle.RESOLVED == a.getState()); |
| assertTrue(orion.Bundle.RESOLVED == b.getState()); |
| }; |
| |
| |
| FrameworkTest.prototype.testResolveImportsFailAfterUninstall = function() { |
| var framework = new orion.Framework(); |
| var a = framework.installBundle("cde", {name:"cde", exports:["abc"], script:"var abc = {hi:7};"}); |
| var b = framework.installBundle("xyz", {name:"xyz", imports:["abc"]}); |
| framework.resolve(); |
| assertTrue(orion.Bundle.RESOLVED == a.getState()); |
| assertTrue(orion.Bundle.RESOLVED == b.getState()); |
| a.uninstall(); |
| framework.refresh(); |
| assertFalse(orion.Bundle.RESOLVED == b.getState()); |
| }; |
| |
| FrameworkTest.prototype.testResolveLikeFunction = function() { |
| var load = new Function("", "var abc = {hi:7};\n\n return {abc:abc};"); |
| var x= load.apply({}, []); |
| assertEquals(7, x.abc.hi); |
| }; |
| |
| FrameworkTest.prototype.testResolveImportsLoad = function() { |
| var framework = new orion.Framework(); |
| var a = framework.installBundle("cde", {name:"cde", exports:["abc"], script:"var abc = {hi:7};"}); |
| framework.resolve(); |
| assertEquals(7, a.load("abc").hi); |
| var b = framework.installBundle("xyz", {name:"xyz", imports:["abc"], exports:["def"], script:"var def = abc;"}); |
| framework.resolve(); |
| assertTrue(orion.Bundle.RESOLVED == a.getState()); |
| assertTrue(orion.Bundle.RESOLVED == b.getState()); |
| assertEquals(7, b.load("def").hi); |
| }; |
| |
| FrameworkTest.prototype.testResolveMultipleImportsLoad = function() { |
| var framework = new orion.Framework(); |
| var a = framework.installBundle("cde", {name:"cde", exports:["abc","xyz"], script:"var abc = {hi:7};\nvar xyz = {bye:9};"}); |
| framework.resolve(); |
| assertEquals(7, a.load("abc").hi); |
| assertEquals(9, a.load("xyz").bye); |
| var b = framework.installBundle("xyz", {name:"xyz", imports:["abc","xyz"], exports:["def","ghi"], script:"var def = abc;\nvar ghi = xyz;"}); |
| framework.resolve(); |
| assertTrue(orion.Bundle.RESOLVED == a.getState()); |
| assertTrue(orion.Bundle.RESOLVED == b.getState()); |
| assertEquals(7, b.load("def").hi); |
| assertEquals(9, b.load("ghi").bye); |
| }; |
| |
| FrameworkTest.prototype.testEmptyShutdown = function() { |
| var framework = new orion.Framework(); |
| framework.shutdown(); |
| }; |
| FrameworkTest.prototype.testEmptyShutdown = function() { |
| var framework = new orion.Framework(); |
| var b = framework.installBundle("xyz", {name:"xyz"}); |
| assertEquals(1, framework.getBundles().length); |
| assertEquals(orion.Bundle.INSTALLED, b.getState()); |
| framework.shutdown(); |
| assertEquals(0, framework.getBundles().length); |
| }; |
| var foo="ha"; |
| FrameworkTest.prototype.testBoris = function() { |
| function isGlobal(candidate) { |
| return candidate == (function(){return this})(); |
| } |
| |
| assertTrue(isGlobal((function(){return this})())); |
| |
| (function(){ |
| this.fool = "ha"; |
| })(); |
| var a ={foo:"bar"}; |
| function doIt1(){ |
| return this.foo; |
| } |
| |
| function doIt2(){ |
| function doIt3(){ |
| return this.foo; |
| } |
| return doIt3(); |
| } |
| assertEquals("doIt1 failed", "bar", doIt1.apply(a)); |
| assertEquals("ha", doIt2.apply(a)); |
| }; |
| |
| |