entries_test.js 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // Copyright 2013 The Closure Library Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS-IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. goog.provide('goog.tweak.BaseEntryTest');
  15. goog.setTestOnly('goog.tweak.BaseEntryTest');
  16. goog.require('goog.testing.MockControl');
  17. goog.require('goog.testing.jsunit');
  18. /** @suppress {extraRequire} needed for createRegistryEntries. */
  19. goog.require('goog.tweak.testhelpers');
  20. var mockControl;
  21. function setUp() {
  22. mockControl = new goog.testing.MockControl();
  23. }
  24. function tearDown() {
  25. goog.tweak.registry_ = null;
  26. mockControl.$verifyAll();
  27. }
  28. function testGetValue_defaultValues() {
  29. createRegistryEntries('');
  30. assertFalse('wrong initial value for bool', boolEntry.getValue());
  31. assertEquals('wrong initial value for enum', 'A', strEnumEntry.getValue());
  32. assertEquals('wrong initial value for str', '', strEntry.getValue());
  33. assertEquals('wrong initial value for bool2', true, boolEntry2.getValue());
  34. assertEquals('wrong initial value for enum2', 1, numEnumEntry.getValue());
  35. assertEquals('wrong initial value for str2', 'foo', strEntry2.getValue());
  36. assertFalse('wrong initial value for BoolOne', boolOneEntry.getValue());
  37. assertTrue('wrong initial value for BoolTwo', boolTwoEntry.getValue());
  38. }
  39. function testGetValue_nonDefaultValues() {
  40. createRegistryEntries('?bool=1&enum=C');
  41. // These have the restartRequired option set.
  42. boolEntry.setValue(false);
  43. strEntry.setValue('foo');
  44. numEntry.setValue(5);
  45. assertTrue('wrong value for boolean', boolEntry.getValue());
  46. assertEquals(
  47. 'wrong value for string', strEntry.getDefaultValue(),
  48. strEntry.getValue());
  49. assertEquals(
  50. 'wrong value for num', numEntry.getDefaultValue(), numEntry.getValue());
  51. // These do not have the restartRequired option set.
  52. strEnumEntry.setValue('B');
  53. boolOneEntry.setValue(true);
  54. assertEquals('wrong value for strEnum', 'B', strEnumEntry.getValue());
  55. assertEquals('wrong value for boolOne', true, boolOneEntry.getValue());
  56. }
  57. function testCallbacks() {
  58. createRegistryEntries('');
  59. var mockCallback = mockControl.createFunctionMock();
  60. boolEntry.addCallback(mockCallback);
  61. boolOneEntry.addCallback(mockCallback);
  62. strEnumEntry.addCallback(mockCallback);
  63. numEnumEntry.addCallback(mockCallback);
  64. mockCallback(boolEntry);
  65. mockCallback(boolOneEntry);
  66. mockCallback(strEnumEntry);
  67. mockCallback(numEnumEntry);
  68. mockControl.$replayAll();
  69. boolEntry.setValue(true);
  70. boolOneEntry.setValue(true);
  71. strEnumEntry.setValue('C');
  72. numEnumEntry.setValue(3);
  73. }