| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package com.google.javascript.jscomp; | 5 package com.google.javascript.jscomp; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Tests {@link ChromePass}. | 8 * Tests {@link ChromePass}. |
| 9 */ | 9 */ |
| 10 public class ChromePassTest extends CompilerTestCase { | 10 public class ChromePassTest extends CompilerTestCase { |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 "cr.ui = cr.ui || {};\n" + | 356 "cr.ui = cr.ui || {};\n" + |
| 357 "cr.define('cr.ui', function() {\n" + | 357 "cr.define('cr.ui', function() {\n" + |
| 358 " return {};\n" + | 358 " return {};\n" + |
| 359 "});"); | 359 "});"); |
| 360 } | 360 } |
| 361 | 361 |
| 362 public void testCrExportPathInvalidNumberOfArguments() throws Exception { | 362 public void testCrExportPathInvalidNumberOfArguments() throws Exception { |
| 363 test("cr.exportPath();", null, ChromePass.CR_EXPORT_PATH_WRONG_NUMBER_OF
_ARGUMENTS); | 363 test("cr.exportPath();", null, ChromePass.CR_EXPORT_PATH_WRONG_NUMBER_OF
_ARGUMENTS); |
| 364 } | 364 } |
| 365 | 365 |
| 366 public void testCrMakePublicWorksOnOneMethodDefinedInPrototypeObject() throw
s Exception { |
| 367 test( |
| 368 "/** @constructor */\n" + |
| 369 "Class = function() {};\n" + |
| 370 "\n" + |
| 371 "Class.prototype = {\n" + |
| 372 " /** @return {number} */\n" + |
| 373 " method_: function() { return 42; }\n" + |
| 374 "};\n" + |
| 375 "\n" + |
| 376 "cr.makePublic(Class, ['method']);", |
| 377 "/** @constructor */\n" + |
| 378 "Class = function() {};\n" + |
| 379 "\n" + |
| 380 "Class.prototype = {\n" + |
| 381 " /** @return {number} */\n" + |
| 382 " method_: function() { return 42; }\n" + |
| 383 "};\n" + |
| 384 "\n" + |
| 385 "/** @return {number} */\n" + |
| 386 "Class.method;\n" + |
| 387 "\n" + |
| 388 "cr.makePublic(Class, ['method']);"); |
| 389 } |
| 390 |
| 391 public void testCrMakePublicWorksOnTwoMethods() throws Exception { |
| 392 test( |
| 393 "/** @constructor */\n" + |
| 394 "Class = function() {}\n" + |
| 395 "\n" + |
| 396 "Class.prototype = {\n" + |
| 397 " /** @return {number} */\n" + |
| 398 " m1_: function() { return 42; },\n" + |
| 399 "\n" + |
| 400 " /** @return {string} */\n" + |
| 401 " m2_: function() { return ''; }\n" + |
| 402 "};\n" + |
| 403 "\n" + |
| 404 "cr.makePublic(Class, ['m1', 'm2']);", |
| 405 "/** @constructor */\n" + |
| 406 "Class = function() {}\n" + |
| 407 "\n" + |
| 408 "Class.prototype = {\n" + |
| 409 " /** @return {number} */\n" + |
| 410 " m1_: function() { return 42; },\n" + |
| 411 "\n" + |
| 412 " /** @return {string} */\n" + |
| 413 " m2_: function() { return ''; }\n" + |
| 414 "}\n" + |
| 415 "\n" + |
| 416 "/** @return {number} */\n" + |
| 417 "Class.m1;\n" + |
| 418 "\n" + |
| 419 "/** @return {string} */\n" + |
| 420 "Class.m2;\n" + |
| 421 "\n" + |
| 422 "cr.makePublic(Class, ['m1', 'm2']);"); |
| 423 } |
| 424 |
| 425 public void testCrMakePublicRequiresMethodsToHaveJSDoc() throws Exception { |
| 426 test("/** @constructor */\n" + |
| 427 "Class = function() {}\n" + |
| 428 "\n" + |
| 429 "Class.prototype = {\n" + |
| 430 " method_: function() {}\n" + |
| 431 "}\n" + |
| 432 "\n" + |
| 433 "cr.makePublic(Class, ['method']);", null, ChromePass.CR_MAKE_PU
BLIC_HAS_NO_JSDOC); |
| 434 } |
| 435 |
| 436 public void testCrMakePublicDoesNothingWithMethodsNotInAPI() throws Exceptio
n { |
| 437 test( |
| 438 "/** @constructor */\n" + |
| 439 "Class = function() {}\n" + |
| 440 "\n" + |
| 441 "Class.prototype = {\n" + |
| 442 " method_: function() {}\n" + |
| 443 "}\n" + |
| 444 "\n" + |
| 445 "cr.makePublic(Class, []);", |
| 446 "/** @constructor */\n" + |
| 447 "Class = function() {}\n" + |
| 448 "\n" + |
| 449 "Class.prototype = {\n" + |
| 450 " method_: function() {}\n" + |
| 451 "}\n" + |
| 452 "\n" + |
| 453 "cr.makePublic(Class, []);"); |
| 454 } |
| 455 |
| 456 public void testCrMakePublicRequiresExportedMethodToBeDeclared() throws Exce
ption { |
| 457 test( |
| 458 "/** @constructor */\n" + |
| 459 "Class = function() {}\n" + |
| 460 "\n" + |
| 461 "Class.prototype = {\n" + |
| 462 "}\n" + |
| 463 "\n" + |
| 464 "cr.makePublic(Class, ['method']);", null, |
| 465 ChromePass.CR_MAKE_PUBLIC_MISSED_DECLARATION); |
| 466 } |
| 467 |
| 468 public void testCrMakePublicWorksOnOneMethodDefinedDirectlyOnPrototype() thr
ows Exception { |
| 469 test( |
| 470 "/** @constructor */\n" + |
| 471 "Class = function() {}\n" + |
| 472 "\n" + |
| 473 "/** @return {number} */\n" + |
| 474 "Class.prototype.method_ = function() {};\n" + |
| 475 "\n" + |
| 476 "cr.makePublic(Class, ['method']);", |
| 477 "/** @constructor */\n" + |
| 478 "Class = function() {}\n" + |
| 479 "\n" + |
| 480 "/** @return {number} */\n" + |
| 481 "Class.prototype.method_ = function() {};\n" + |
| 482 "\n" + |
| 483 "/** @return {number} */\n" + |
| 484 "Class.method;\n" + |
| 485 "\n" + |
| 486 "cr.makePublic(Class, ['method']);"); |
| 487 } |
| 488 |
| 366 } | 489 } |
| OLD | NEW |