| 1 |
// Copyright 2009 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 |
/** |
| 16 |
* @fileoverview Common test functions for tweak unit tests. |
| 17 |
* |
| 18 |
* @author [email protected] (Andrew Grieve) |
| 19 |
* @package |
| 20 |
*/ |
| 21 |
|
| 22 |
goog.provide('goog.tweak.testhelpers'); |
| 23 |
|
| 24 |
goog.setTestOnly(); |
| 25 |
|
| 26 |
goog.require('goog.tweak'); |
| 27 |
goog.require('goog.tweak.BooleanGroup'); |
| 28 |
goog.require('goog.tweak.BooleanInGroupSetting'); |
| 29 |
goog.require('goog.tweak.BooleanSetting'); |
| 30 |
goog.require('goog.tweak.ButtonAction'); |
| 31 |
goog.require('goog.tweak.NumericSetting'); |
| 32 |
goog.require('goog.tweak.Registry'); |
| 33 |
goog.require('goog.tweak.StringSetting'); |
| 34 |
|
| 35 |
|
| 36 |
var boolEntry; |
| 37 |
var boolEntry2; |
| 38 |
var strEntry; |
| 39 |
var strEntry2; |
| 40 |
var strEnumEntry; |
| 41 |
var numEntry; |
| 42 |
var numEnumEntry; |
| 43 |
var boolGroup; |
| 44 |
var boolOneEntry; |
| 45 |
var boolTwoEntry; |
| 46 |
var buttonEntry; |
| 47 |
|
| 48 |
|
| 49 |
/** |
| 50 |
* Creates a registry with some entries in it. |
| 51 |
* @param {string} queryParams The query parameter string to use for the |
| 52 |
* registry. |
| 53 |
* @param {!Object<string|number|boolean>=} opt_compilerOverrides Compiler |
| 54 |
* overrides. |
| 55 |
* @suppress {accessControls} Private state is accessed for test purposes. |
| 56 |
*/ |
| 57 |
function createRegistryEntries(queryParams, opt_compilerOverrides) { |
| 58 |
// Initialize the registry with the given query string. |
| 59 |
var registry = |
| 60 |
new goog.tweak.Registry(queryParams, opt_compilerOverrides || {}); |
| 61 |
goog.tweak.registry_ = registry; |
| 62 |
|
| 63 |
boolEntry = new goog.tweak.BooleanSetting('Bool', 'The bool1'); |
| 64 |
registry.register(boolEntry); |
| 65 |
|
| 66 |
boolEntry2 = new goog.tweak.BooleanSetting('Bool2', 'The bool2'); |
| 67 |
boolEntry2.setDefaultValue(true); |
| 68 |
registry.register(boolEntry2); |
| 69 |
|
| 70 |
strEntry = new goog.tweak.StringSetting('Str', 'The str1'); |
| 71 |
strEntry.setParamName('s'); |
| 72 |
registry.register(strEntry); |
| 73 |
|
| 74 |
strEntry2 = new goog.tweak.StringSetting('Str2', 'The str2'); |
| 75 |
strEntry2.setDefaultValue('foo'); |
| 76 |
registry.register(strEntry2); |
| 77 |
|
| 78 |
strEnumEntry = new goog.tweak.StringSetting('Enum', 'The enum'); |
| 79 |
strEnumEntry.setValidValues(['A', 'B', 'C']); |
| 80 |
strEnumEntry.setRestartRequired(false); |
| 81 |
registry.register(strEnumEntry); |
| 82 |
|
| 83 |
numEntry = new goog.tweak.NumericSetting('Num', 'The num'); |
| 84 |
numEntry.setDefaultValue(99); |
| 85 |
registry.register(numEntry); |
| 86 |
|
| 87 |
numEnumEntry = new goog.tweak.NumericSetting('Enum2', 'The 2nd enum'); |
| 88 |
numEnumEntry.setValidValues([1, 2, 3]); |
| 89 |
numEnumEntry.setRestartRequired(false); |
| 90 |
numEnumEntry.label = 'Enum the second&'; |
| 91 |
registry.register(numEnumEntry); |
| 92 |
|
| 93 |
boolGroup = new goog.tweak.BooleanGroup('BoolGroup', 'The bool group'); |
| 94 |
registry.register(boolGroup); |
| 95 |
|
| 96 |
boolOneEntry = |
| 97 |
new goog.tweak.BooleanInGroupSetting('BoolOne', 'Desc for 1', boolGroup); |
| 98 |
boolOneEntry.setToken('B1'); |
| 99 |
boolOneEntry.setRestartRequired(false); |
| 100 |
boolGroup.addChild(boolOneEntry); |
| 101 |
registry.register(boolOneEntry); |
| 102 |
|
| 103 |
boolTwoEntry = |
| 104 |
new goog.tweak.BooleanInGroupSetting('BoolTwo', 'Desc for 2', boolGroup); |
| 105 |
boolTwoEntry.setDefaultValue(true); |
| 106 |
boolGroup.addChild(boolTwoEntry); |
| 107 |
registry.register(boolTwoEntry); |
| 108 |
|
| 109 |
buttonEntry = |
| 110 |
new goog.tweak.ButtonAction('Button', 'The Btn', goog.nullFunction); |
| 111 |
buttonEntry.label = '<btn>'; |
| 112 |
registry.register(buttonEntry); |
| 113 |
|
| 114 |
var nsBoolGroup = |
| 115 |
new goog.tweak.BooleanGroup('foo.bar.BoolGroup', 'Namespaced Bool Group'); |
| 116 |
registry.register(nsBoolGroup); |
| 117 |
var nsBool = new goog.tweak.BooleanInGroupSetting( |
| 118 |
'foo.bar.BoolOne', 'Desc for Namespaced 1', nsBoolGroup); |
| 119 |
nsBoolGroup.addChild(nsBool); |
| 120 |
registry.register(nsBool); |
| 121 |
} |