Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / closure_compiler / runner / test / com / google / javascript / jscomp / ChromePassTest.java
index b8db07d..d6264c1 100644 (file)
@@ -76,7 +76,7 @@ public class ChromePassTest extends CompilerTestCase {
             "});");
     }
 
-    public void testCrDefineReassignsExportedFunctionByQualifiedName() throws Exception {
+    public void testCrDefineReassignsExportedVarByQualifiedName() throws Exception {
         test(
             "cr.define('namespace', function() {\n" +
             "  var internalStaticMethod = function() {\n" +
@@ -97,6 +97,42 @@ public class ChromePassTest extends CompilerTestCase {
             "});");
     }
 
+    public void testCrDefineExportsVarsWithoutAssignment() throws Exception {
+        test(
+            "cr.define('namespace', function() {\n" +
+            "  var a;\n" +
+            "  return {\n" +
+            "    a: a\n" +
+            "  };\n" +
+            "});\n",
+            "var namespace = namespace || {};\n" +
+            "cr.define('namespace', function() {\n" +
+            "  namespace.a;\n" +
+            "  return {\n" +
+            "    a: namespace.a\n" +
+            "  };\n" +
+            "});\n");
+    }
+
+    public void testCrDefineExportsVarsWithoutAssignmentWithJSDoc() throws Exception {
+        test(
+            "cr.define('namespace', function() {\n" +
+            "  /** @type {number} */\n" +
+            "  var a;\n" +
+            "  return {\n" +
+            "    a: a\n" +
+            "  };\n" +
+            "});\n",
+            "var namespace = namespace || {};\n" +
+            "cr.define('namespace', function() {\n" +
+            "  /** @type {number} */\n" +
+            "  namespace.a;\n" +
+            "  return {\n" +
+            "    a: namespace.a\n" +
+            "  };\n" +
+            "});\n");
+    }
+
     public void testCrDefineCopiesJSDocForExportedVariable() throws Exception {
         test(
             "cr.define('namespace', function() {\n" +
@@ -137,6 +173,25 @@ public class ChromePassTest extends CompilerTestCase {
             "});");
     }
 
+    public void testCrDefineDoesNothingWithNonExportedVar() throws Exception {
+        test(
+            "cr.define('namespace', function() {\n" +
+            "  var a;\n" +
+            "  var b;\n" +
+            "  return {\n" +
+            "    a: a\n" +
+            "  };\n" +
+            "});\n",
+            "var namespace = namespace || {};\n" +
+            "cr.define('namespace', function() {\n" +
+            "  namespace.a;\n" +
+            "  var b;\n" +
+            "  return {\n" +
+            "    a: namespace.a\n" +
+            "  };\n" +
+            "});\n");
+    }
+
     public void testCrDefineChangesReferenceToExportedFunction() throws Exception {
         test(
             "cr.define('namespace', function() {\n" +
@@ -257,7 +312,7 @@ public class ChromePassTest extends CompilerTestCase {
         test(
             "cr.define('a.b.c.d', function() {\n" +
             "  return {};\n" +
-            "});" +
+            "});\n" +
             "cr.define('a.b.e.f', function() {\n" +
             "  return {};\n" +
             "});",
@@ -267,7 +322,7 @@ public class ChromePassTest extends CompilerTestCase {
             "a.b.c.d = a.b.c.d || {};\n" +
             "cr.define('a.b.c.d', function() {\n" +
             "  return {};\n" +
-            "});" +
+            "});\n" +
             "a.b.e = a.b.e || {};\n" +
             "a.b.e.f = a.b.e.f || {};\n" +
             "cr.define('a.b.e.f', function() {\n" +
@@ -308,4 +363,166 @@ public class ChromePassTest extends CompilerTestCase {
         test("cr.exportPath();", null, ChromePass.CR_EXPORT_PATH_WRONG_NUMBER_OF_ARGUMENTS);
     }
 
+    public void testCrMakePublicWorksOnOneMethodDefinedInPrototypeObject() throws Exception {
+        test(
+            "/** @constructor */\n" +
+            "function Class() {};\n" +
+            "\n" +
+            "Class.prototype = {\n" +
+            "  /** @return {number} */\n" +
+            "  method_: function() { return 42; }\n" +
+            "};\n" +
+            "\n" +
+            "cr.makePublic(Class, ['method']);",
+            "/** @constructor */\n" +
+            "function Class() {};\n" +
+            "\n" +
+            "Class.prototype = {\n" +
+            "  /** @return {number} */\n" +
+            "  method_: function() { return 42; }\n" +
+            "};\n" +
+            "\n" +
+            "/** @return {number} */\n" +
+            "Class.method;\n" +
+            "\n" +
+            "cr.makePublic(Class, ['method']);");
+    }
+
+    public void testCrMakePublicWorksOnTwoMethods() throws Exception {
+        test(
+            "/** @constructor */\n" +
+            "function Class() {}\n" +
+            "\n" +
+            "Class.prototype = {\n" +
+            "  /** @return {number} */\n" +
+            "  m1_: function() { return 42; },\n" +
+            "\n" +
+            "  /** @return {string} */\n" +
+            "  m2_: function() { return ''; }\n" +
+            "};\n" +
+            "\n" +
+            "cr.makePublic(Class, ['m1', 'm2']);",
+            "/** @constructor */\n" +
+            "function Class() {}\n" +
+            "\n" +
+            "Class.prototype = {\n" +
+            "  /** @return {number} */\n" +
+            "  m1_: function() { return 42; },\n" +
+            "\n" +
+            "  /** @return {string} */\n" +
+            "  m2_: function() { return ''; }\n" +
+            "}\n" +
+            "\n" +
+            "/** @return {number} */\n" +
+            "Class.m1;\n" +
+            "\n" +
+            "/** @return {string} */\n" +
+            "Class.m2;\n" +
+            "\n" +
+            "cr.makePublic(Class, ['m1', 'm2']);");
+    }
+
+    public void testCrMakePublicRequiresMethodsToHaveJSDoc() throws Exception {
+        test("/** @constructor */\n" +
+            "function Class() {}\n" +
+            "\n" +
+            "Class.prototype = {\n" +
+            "  method_: function() {}\n" +
+            "}\n" +
+            "\n" +
+            "cr.makePublic(Class, ['method']);", null, ChromePass.CR_MAKE_PUBLIC_HAS_NO_JSDOC);
+    }
+
+    public void testCrMakePublicDoesNothingWithMethodsNotInAPI() throws Exception {
+        test(
+            "/** @constructor */\n" +
+            "function Class() {}\n" +
+            "\n" +
+            "Class.prototype = {\n" +
+            "  method_: function() {}\n" +
+            "}\n" +
+            "\n" +
+            "cr.makePublic(Class, []);",
+            "/** @constructor */\n" +
+            "function Class() {}\n" +
+            "\n" +
+            "Class.prototype = {\n" +
+            "  method_: function() {}\n" +
+            "}\n" +
+            "\n" +
+            "cr.makePublic(Class, []);");
+    }
+
+    public void testCrMakePublicRequiresExportedMethodToBeDeclared() throws Exception {
+        test(
+            "/** @constructor */\n" +
+            "function Class() {}\n" +
+            "\n" +
+            "Class.prototype = {\n" +
+            "}\n" +
+            "\n" +
+            "cr.makePublic(Class, ['method']);", null,
+            ChromePass.CR_MAKE_PUBLIC_MISSED_DECLARATION);
+    }
+
+    public void testCrMakePublicWorksOnOneMethodDefinedDirectlyOnPrototype() throws Exception {
+        test(
+            "/** @constructor */\n" +
+            "function Class() {}\n" +
+            "\n" +
+            "/** @return {number} */\n" +
+            "Class.prototype.method_ = function() {};\n" +
+            "\n" +
+            "cr.makePublic(Class, ['method']);",
+            "/** @constructor */\n" +
+            "function Class() {}\n" +
+            "\n" +
+            "/** @return {number} */\n" +
+            "Class.prototype.method_ = function() {};\n" +
+            "\n" +
+            "/** @return {number} */\n" +
+            "Class.method;\n" +
+            "\n" +
+            "cr.makePublic(Class, ['method']);");
+    }
+
+    public void testCrMakePublicWorksOnDummyDeclaration() throws Exception {
+        test(
+            "/** @constructor */\n" +
+            "function Class() {}\n" +
+            "\n" +
+            "/** @return {number} */\n" +
+            "Class.prototype.method_;\n" +
+            "\n" +
+            "cr.makePublic(Class, ['method']);",
+            "/** @constructor */\n" +
+            "function Class() {}\n" +
+            "\n" +
+            "/** @return {number} */\n" +
+            "Class.prototype.method_;\n" +
+            "\n" +
+            "/** @return {number} */\n" +
+            "Class.method;\n" +
+            "\n" +
+            "cr.makePublic(Class, ['method']);");
+    }
+
+    public void testCrMakePublicReportsInvalidSecondArgumentMissing() throws Exception {
+        test(
+            "cr.makePublic(Class);", null,
+            ChromePass.CR_MAKE_PUBLIC_INVALID_SECOND_ARGUMENT);
+    }
+
+    public void testCrMakePublicReportsInvalidSecondArgumentNotAnArray() throws Exception {
+        test(
+            "cr.makePublic(Class, 42);", null,
+            ChromePass.CR_MAKE_PUBLIC_INVALID_SECOND_ARGUMENT);
+    }
+
+    public void testCrMakePublicReportsInvalidSecondArgumentArrayWithNotAString() throws Exception {
+        test(
+            "cr.makePublic(Class, [42]);", null,
+            ChromePass.CR_MAKE_PUBLIC_INVALID_SECOND_ARGUMENT);
+    }
+
 }