Skip to content

Commit

Permalink
Adds additional JsExport tests and some test cleanup
Browse files Browse the repository at this point in the history
Change-Id: Ib6820d2ecaf03a325b31a0dc0f6da098e91bf9ba
  • Loading branch information
gkdn committed Feb 26, 2015
1 parent c79ece3 commit 4435e46
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 70 deletions.
71 changes: 44 additions & 27 deletions user/test/com/google/gwt/core/client/interop/JsExportTest.java
Expand Up @@ -18,7 +18,6 @@
import static com.google.gwt.core.client.ScriptInjector.TOP_WINDOW; import static com.google.gwt.core.client.ScriptInjector.TOP_WINDOW;


import com.google.gwt.core.client.ScriptInjector; import com.google.gwt.core.client.ScriptInjector;
import com.google.gwt.core.client.interop.subpackage.MyNestedExportedClassSansPackageNamespace;
import com.google.gwt.junit.client.GWTTestCase; import com.google.gwt.junit.client.GWTTestCase;


/** /**
Expand Down Expand Up @@ -231,36 +230,54 @@ private native Object getNotExportedMethods() /*-{
}-*/; }-*/;


public static void testInheritClassNamespace() { public static void testInheritClassNamespace() {
assertEquals(MyExportedClassWithNamespace.BAR, getFooBAR()); assertEquals(42, getBAR());
} }


private static native int getFooBAR() /*-{ private static native int getBAR() /*-{
return $wnd.foo.MyExportedClassWithNamespace.BAR || 0; return $wnd.foo.MyExportedClassWithNamespace.BAR;
}-*/;

public static void testInheritClassNamespace_noExport() {
assertEquals(99, getBAZ());
}

private static native int getBAZ() /*-{
return $wnd.foobaz.MyClassWithNamespace.BAZ;
}-*/; }-*/;


public void testInheritPackageNamespace() { public void testInheritPackageNamespace() {
assertEquals(MyExportedClassWithPackageNamespace.WOO, getWOO()); assertEquals(1001, getWOO());
} }


private static native int getWOO() /*-{ private static native int getWOO() /*-{
return $wnd.woo.MyExportedClassWithPackageNamespace.WOO || 0; return $wnd.woo.MyExportedClassWithPackageNamespace.WOO;
}-*/; }-*/;


public void testNotInheritNestedPackageNamespace() { public void testInheritPackageNamespace_nestedClass() {
assertFalse(MyNestedExportedClassSansPackageNamespace.WOO == getNestedWOO()); assertEquals(99, getNestedWOO());
assertNotNull(createNestedExportedClass());
} }


private static native int getNestedWOO() /*-{ private static native int getNestedWOO() /*-{
return $wnd['woo.subpackage.MyNestedExportedClassSansPackageNamespace.WOO'] || 0; return $wnd.woo.MyClassWithNestedExportedClass.Inner.WOO;
}-*/; }-*/;


public void testNestedEnum() { private static native Object createNestedExportedClass() /*-{
assertEquals(MyClassWithNestedEnum.NestedEnum.FOO.name(), return new $wnd.woo.MyClassWithNestedExportedClass.Inner();
getEnumNameViaJs(MyClassWithNestedEnum.NestedEnum.FOO)); }-*/;

public void testInheritPackageNamespace_subpackage() {
assertNull(getNestedSubpackage());
assertNotNull(getNestedSubpackageCorrect());
} }


private static native String getEnumNameViaJs(MyClassWithNestedEnum.NestedEnum ref) /*-{ private static native Object getNestedSubpackage() /*-{
return ref.name2(); return $wnd.woo.subpackage;
}-*/;

private static native Object getNestedSubpackageCorrect() /*-{
return $wnd.com.google.gwt.core.client.interop.subpackage.
MyNestedExportedClassSansPackageNamespace;
}-*/; }-*/;


public void testEnum_enumerations() { public void testEnum_enumerations() {
Expand All @@ -269,19 +286,19 @@ public void testEnum_enumerations() {
} }


private static native Object getEnumerationTEST1() /*-{ private static native Object getEnumerationTEST1() /*-{
return $wnd.woo.MyEnumWithJsExport.TEST1; return $wnd.woo.MyExportedEnum.TEST1;
}-*/; }-*/;


private static native Object getEnumerationTEST2() /*-{ private static native Object getEnumerationTEST2() /*-{
return $wnd.woo.MyEnumWithJsExport.TEST2; return $wnd.woo.MyExportedEnum.TEST2;
}-*/; }-*/;


public void testEnum_exportedMethods() { public void testEnum_exportedMethods() {
assertNotNull(getPublicStaticMethodInEnum()); assertNotNull(getPublicStaticMethodInEnum());
} }


private static native Object getPublicStaticMethodInEnum() /*-{ private static native Object getPublicStaticMethodInEnum() /*-{
return $wnd.woo.MyEnumWithJsExport.publicStaticMethod(); return $wnd.woo.MyExportedEnum.publicStaticMethod();
}-*/; }-*/;


public void testEnum_exportedFields() { public void testEnum_exportedFields() {
Expand All @@ -293,11 +310,11 @@ public void testEnum_exportedFields() {
} }


private static native int getPublicStaticFinalFieldInEnum() /*-{ private static native int getPublicStaticFinalFieldInEnum() /*-{
return $wnd.woo.MyEnumWithJsExport.publicStaticFinalField; return $wnd.woo.MyExportedEnum.publicStaticFinalField;
}-*/; }-*/;


private static native int getPublicStaticFieldInEnum() /*-{ private static native int getPublicStaticFieldInEnum() /*-{
return $wnd.woo.MyEnumWithJsExport.publicStaticField; return $wnd.woo.MyExportedEnum.publicStaticField;
}-*/; }-*/;


public void testEnum_notExported() { public void testEnum_notExported() {
Expand All @@ -306,17 +323,17 @@ public void testEnum_notExported() {
} }


private native Object getNotExportedFieldsInEnum() /*-{ private native Object getNotExportedFieldsInEnum() /*-{
return $wnd.woo.MyEnumWithJsExport.publicFinalField return $wnd.woo.MyExportedEnum.publicFinalField
|| $wnd.woo.MyEnumWithJsExport.privateStaticFinalField || $wnd.woo.MyExportedEnum.privateStaticFinalField
|| $wnd.woo.MyEnumWithJsExport.protectedStaticFinalField || $wnd.woo.MyExportedEnum.protectedStaticFinalField
|| $wnd.woo.MyEnumWithJsExport.defaultStaticFinalField; || $wnd.woo.MyExportedEnum.defaultStaticFinalField;
}-*/; }-*/;


private native Object getNotExportedMethodsInEnum() /*-{ private native Object getNotExportedMethodsInEnum() /*-{
return $wnd.woo.MyEnumWithJsExport.publicMethod return $wnd.woo.MyExportedEnum.publicMethod
|| $wnd.woo.MyEnumWithJsExport.protectedStaticMethod || $wnd.woo.MyExportedEnum.protectedStaticMethod
|| $wnd.woo.MyEnumWithJsExport.privateStaticMethod || $wnd.woo.MyExportedEnum.privateStaticMethod
|| $wnd.woo.MyEnumWithJsExport.defaultStaticMethod; || $wnd.woo.MyExportedEnum.defaultStaticMethod;
}-*/; }-*/;


public void testEnum_subclassEnumerations() { public void testEnum_subclassEnumerations() {
Expand Down
40 changes: 14 additions & 26 deletions user/test/com/google/gwt/core/client/interop/JsTypeTest.java
Expand Up @@ -68,11 +68,6 @@ public void testVirtualUpRefs() {
listNoExport.add("Tight"); listNoExport.add("Tight");
assertEquals("TightCollectionBaseFooImpl", listNoExport.x); assertEquals("TightCollectionBaseFooImpl", listNoExport.x);


// TODO: fix me
if (isIE8()) {
return;
}

// Calls through a bridge method. // Calls through a bridge method.
listWithExport.add("Tight"); listWithExport.add("Tight");
assertEquals("TightListImpl", listWithExport.x); assertEquals("TightListImpl", listWithExport.x);
Expand All @@ -81,24 +76,25 @@ public void testVirtualUpRefs() {
public void testConcreteJsTypeAccess() { public void testConcreteJsTypeAccess() {
ConcreteJsType concreteJsType = new ConcreteJsType(); ConcreteJsType concreteJsType = new ConcreteJsType();


testJsTypeHasFields(concreteJsType, "publicMethod", "publicField"); assertJsTypeHasFields(concreteJsType, "publicMethod", "publicField");
testJsTypeHasNoFields(concreteJsType, "publicStaticMethod", "privateMethod", "protectedMethod", assertJsTypeDoesntHaveFields(concreteJsType, "publicStaticMethod", "privateMethod",
"packageMethod", "publicStaticField", "privateField", "protectedField", "packageField"); "protectedMethod", "packageMethod", "publicStaticField", "privateField", "protectedField",
"packageField");
} }


public void testConcreteJsTypeSubclassAccess() { public void testConcreteJsTypeSubclassAccess() {
ConcreteJsType concreteJsType = new ConcreteJsType(); ConcreteJsType concreteJsType = new ConcreteJsType();
ConcreteJsTypeSubclass concreteJsTypeSubclass = new ConcreteJsTypeSubclass(); ConcreteJsTypeSubclass concreteJsTypeSubclass = new ConcreteJsTypeSubclass();


// A subclass of a JsType is not itself a JsType. // A subclass of a JsType is not itself a JsType.
testJsTypeHasNoFields(concreteJsTypeSubclass, "publicSubclassMethod", "publicSubclassField", assertJsTypeDoesntHaveFields(concreteJsTypeSubclass, "publicSubclassMethod",
"publicStaticSubclassMethod", "privateSubclassMethod", "protectedSubclassMethod", "publicSubclassField", "publicStaticSubclassMethod", "privateSubclassMethod",
"packageSubclassMethod", "publicStaticSubclassField", "privateSubclassField", "protectedSubclassMethod", "packageSubclassMethod", "publicStaticSubclassField",
"protectedSubclassField", "packageSubclassField"); "privateSubclassField", "protectedSubclassField", "packageSubclassField");


// But if it overrides an exported method then the overriding method will be exported. // But if it overrides an exported method then the overriding method will be exported.
testJsTypeHasFields(concreteJsType, "publicMethod"); assertJsTypeHasFields(concreteJsType, "publicMethod");
testJsTypeHasFields(concreteJsTypeSubclass, "publicMethod"); assertJsTypeHasFields(concreteJsTypeSubclass, "publicMethod");
assertFalse( assertFalse(
areSameFunction(concreteJsType, "publicMethod", concreteJsTypeSubclass, "publicMethod")); areSameFunction(concreteJsType, "publicMethod", concreteJsTypeSubclass, "publicMethod"));
assertFalse(callIntFunction(concreteJsType, "publicMethod") assertFalse(callIntFunction(concreteJsType, "publicMethod")
Expand Down Expand Up @@ -264,8 +260,8 @@ public void testEnumeration() {
} }


public void testEnumJsTypeAccess() { public void testEnumJsTypeAccess() {
testJsTypeHasFields(MyEnumWithJsType.TEST2, "publicMethod", "publicField"); assertJsTypeHasFields(MyEnumWithJsType.TEST2, "publicMethod", "publicField");
testJsTypeHasNoFields(MyEnumWithJsType.TEST2, "publicStaticMethod", "privateMethod", assertJsTypeDoesntHaveFields(MyEnumWithJsType.TEST2, "publicStaticMethod", "privateMethod",
"protectedMethod", "packageMethod", "publicStaticField", "privateField", "protectedField", "protectedMethod", "packageMethod", "publicStaticField", "privateField", "protectedField",
"packageField"); "packageField");
} }
Expand Down Expand Up @@ -317,14 +313,6 @@ private static native boolean hasField(Object object, String fieldName) /*-{
return object[fieldName] != undefined; return object[fieldName] != undefined;
}-*/; }-*/;


private static native boolean isIE8() /*-{
return $wnd.navigator.userAgent.toLowerCase().indexOf('msie') != -1 && $doc.documentMode == 8;
}-*/;

private static native boolean isFirefox40OrEarlier() /*-{
return @com.google.gwt.dom.client.DOMImplMozilla::isGecko2OrBefore()();
}-*/;

private static native int callPublicMethodFromEnumeration(MyEnumWithJsType enumeration) /*-{ private static native int callPublicMethodFromEnumeration(MyEnumWithJsType enumeration) /*-{
return enumeration.idxAddOne(); return enumeration.idxAddOne();
}-*/; }-*/;
Expand All @@ -334,13 +322,13 @@ private static native int callPublicMethodFromEnumerationSubclass(
return enumeration.foo(); return enumeration.foo();
}-*/; }-*/;


private static void testJsTypeHasFields(Object obj, String... fields) { private static void assertJsTypeHasFields(Object obj, String... fields) {
for (String field : fields) { for (String field : fields) {
assertTrue("Field '" + field + "' should be exported", hasField(obj, field)); assertTrue("Field '" + field + "' should be exported", hasField(obj, field));
} }
} }


private static void testJsTypeHasNoFields(Object obj, String... fields) { private static void assertJsTypeDoesntHaveFields(Object obj, String... fields) {
for (String field : fields) { for (String field : fields) {
assertFalse("Field '" + field + "' should not be exported", hasField(obj, field)); assertFalse("Field '" + field + "' should not be exported", hasField(obj, field));
} }
Expand Down
Expand Up @@ -16,16 +16,13 @@
package com.google.gwt.core.client.interop; package com.google.gwt.core.client.interop;


import com.google.gwt.core.client.js.JsExport; import com.google.gwt.core.client.js.JsExport;
import com.google.gwt.core.client.js.JsType; import com.google.gwt.core.client.js.JsNamespace;


class MyClassWithNestedEnum { /**
@JsType * Class with a namespace.
*/
@JsNamespace("foobaz")
public class MyClassWithNamespace {
@JsExport @JsExport
public enum NestedEnum { public static final int BAZ = 99;
FOO, BAR;

public String name2() {
return name();
}
}
} }
Expand Up @@ -16,18 +16,16 @@
package com.google.gwt.core.client.interop; package com.google.gwt.core.client.interop;


import com.google.gwt.core.client.js.JsExport; import com.google.gwt.core.client.js.JsExport;
import com.google.gwt.core.client.js.JsNamespace;


/** /**
* Test namespace inherited from outer class. * Class with a nested exported class.
*/ */
@JsNamespace("foo") public class MyClassWithNestedExportedClass {
public class MyClassWithNamespaceNested {
/** /**
* Exported field. * Exported nested class.
*/ */
@JsExport @JsExport
public static class Inner { public static class Inner {
public static final int BAZ = 99; public static final int WOO = 99;
} }
} }
Expand Up @@ -21,7 +21,7 @@
* This enum is annotated as @JsExport. * This enum is annotated as @JsExport.
*/ */
@JsExport @JsExport
public enum MyEnumWithJsExport { public enum MyExportedEnum {
TEST1, TEST2; TEST1, TEST2;


public static int publicStaticMethod() { public static int publicStaticMethod() {
Expand Down

0 comments on commit 4435e46

Please sign in to comment.