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 com.google.gwt.core.client.ScriptInjector;
import com.google.gwt.core.client.interop.subpackage.MyNestedExportedClassSansPackageNamespace;
import com.google.gwt.junit.client.GWTTestCase;

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

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

private static native int getFooBAR() /*-{
return $wnd.foo.MyExportedClassWithNamespace.BAR || 0;
private static native int getBAR() /*-{
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() {
assertEquals(MyExportedClassWithPackageNamespace.WOO, getWOO());
assertEquals(1001, getWOO());
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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");
assertEquals("TightCollectionBaseFooImpl", listNoExport.x);

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

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

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

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

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

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

public void testEnumJsTypeAccess() {
testJsTypeHasFields(MyEnumWithJsType.TEST2, "publicMethod", "publicField");
testJsTypeHasNoFields(MyEnumWithJsType.TEST2, "publicStaticMethod", "privateMethod",
assertJsTypeHasFields(MyEnumWithJsType.TEST2, "publicMethod", "publicField");
assertJsTypeDoesntHaveFields(MyEnumWithJsType.TEST2, "publicStaticMethod", "privateMethod",
"protectedMethod", "packageMethod", "publicStaticField", "privateField", "protectedField",
"packageField");
}
Expand Down Expand Up @@ -317,14 +313,6 @@ private static native boolean hasField(Object object, String fieldName) /*-{
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) /*-{
return enumeration.idxAddOne();
}-*/;
Expand All @@ -334,13 +322,13 @@ private static native int callPublicMethodFromEnumerationSubclass(
return enumeration.foo();
}-*/;

private static void testJsTypeHasFields(Object obj, String... fields) {
private static void assertJsTypeHasFields(Object obj, String... fields) {
for (String field : fields) {
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) {
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;

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
public enum NestedEnum {
FOO, BAR;

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

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 MyClassWithNamespaceNested {
public class MyClassWithNestedExportedClass {
/**
* Exported field.
* Exported nested class.
*/
@JsExport
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.
*/
@JsExport
public enum MyEnumWithJsExport {
public enum MyExportedEnum {
TEST1, TEST2;

public static int publicStaticMethod() {
Expand Down

0 comments on commit 4435e46

Please sign in to comment.