| 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 |
|
| 15 |
goog.provide('goog.tweak.BaseEntryTest'); |
| 16 |
goog.setTestOnly('goog.tweak.BaseEntryTest'); |
| 17 |
|
| 18 |
goog.require('goog.testing.MockControl'); |
| 19 |
goog.require('goog.testing.jsunit'); |
| 20 |
/** @suppress {extraRequire} needed for createRegistryEntries. */ |
| 21 |
goog.require('goog.tweak.testhelpers'); |
| 22 |
|
| 23 |
var mockControl; |
| 24 |
|
| 25 |
function setUp() { |
| 26 |
mockControl = new goog.testing.MockControl(); |
| 27 |
} |
| 28 |
|
| 29 |
function tearDown() { |
| 30 |
goog.tweak.registry_ = null; |
| 31 |
mockControl.$verifyAll(); |
| 32 |
} |
| 33 |
|
| 34 |
function testGetValue_defaultValues() { |
| 35 |
createRegistryEntries(''); |
| 36 |
assertFalse('wrong initial value for bool', boolEntry.getValue()); |
| 37 |
assertEquals('wrong initial value for enum', 'A', strEnumEntry.getValue()); |
| 38 |
assertEquals('wrong initial value for str', '', strEntry.getValue()); |
| 39 |
|
| 40 |
assertEquals('wrong initial value for bool2', true, boolEntry2.getValue()); |
| 41 |
assertEquals('wrong initial value for enum2', 1, numEnumEntry.getValue()); |
| 42 |
assertEquals('wrong initial value for str2', 'foo', strEntry2.getValue()); |
| 43 |
|
| 44 |
assertFalse('wrong initial value for BoolOne', boolOneEntry.getValue()); |
| 45 |
assertTrue('wrong initial value for BoolTwo', boolTwoEntry.getValue()); |
| 46 |
} |
| 47 |
|
| 48 |
function testGetValue_nonDefaultValues() { |
| 49 |
createRegistryEntries('?bool=1&enum=C'); |
| 50 |
// These have the restartRequired option set. |
| 51 |
boolEntry.setValue(false); |
| 52 |
strEntry.setValue('foo'); |
| 53 |
numEntry.setValue(5); |
| 54 |
assertTrue('wrong value for boolean', boolEntry.getValue()); |
| 55 |
assertEquals( |
| 56 |
'wrong value for string', strEntry.getDefaultValue(), |
| 57 |
strEntry.getValue()); |
| 58 |
assertEquals( |
| 59 |
'wrong value for num', numEntry.getDefaultValue(), numEntry.getValue()); |
| 60 |
|
| 61 |
// These do not have the restartRequired option set. |
| 62 |
strEnumEntry.setValue('B'); |
| 63 |
boolOneEntry.setValue(true); |
| 64 |
assertEquals('wrong value for strEnum', 'B', strEnumEntry.getValue()); |
| 65 |
assertEquals('wrong value for boolOne', true, boolOneEntry.getValue()); |
| 66 |
} |
| 67 |
|
| 68 |
function testCallbacks() { |
| 69 |
createRegistryEntries(''); |
| 70 |
var mockCallback = mockControl.createFunctionMock(); |
| 71 |
boolEntry.addCallback(mockCallback); |
| 72 |
boolOneEntry.addCallback(mockCallback); |
| 73 |
strEnumEntry.addCallback(mockCallback); |
| 74 |
numEnumEntry.addCallback(mockCallback); |
| 75 |
|
| 76 |
mockCallback(boolEntry); |
| 77 |
mockCallback(boolOneEntry); |
| 78 |
mockCallback(strEnumEntry); |
| 79 |
mockCallback(numEnumEntry); |
| 80 |
mockControl.$replayAll(); |
| 81 |
|
| 82 |
boolEntry.setValue(true); |
| 83 |
boolOneEntry.setValue(true); |
| 84 |
strEnumEntry.setValue('C'); |
| 85 |
numEnumEntry.setValue(3); |
| 86 |
} |