Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The LUCI Authors. All rights reserved. | 1 // Copyright 2016 The LUCI Authors. All rights reserved. |
|
jcgregorio
2016/09/02 18:44:01
Add TODO to add unit tests for this code via Karma
| |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 this.swarming = this.swarming || {}; | 5 this.swarming = this.swarming || {}; |
| 6 this.swarming.alias = this.swarming.alias || (function(){ | 6 this.swarming.alias = this.swarming.alias || (function(){ |
| 7 var ANDROID_ALIASES = { | 7 var ANDROID_ALIASES = { |
| 8 "bullhead": "Nexus 5X", | 8 "bullhead": "Nexus 5X", |
| 9 "flo": "Nexus 7 (2013)", | 9 "flo": "Nexus 7 (2013)", |
| 10 "flounder": "Nexus 9", | 10 "flounder": "Nexus 9", |
| 11 "foster": "NVIDIA Shield", | 11 "foster": "NVIDIA Shield", |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 53 var ALIAS_REGEXP = /.+ \((.*)\)/; | 53 var ALIAS_REGEXP = /.+ \((.*)\)/; |
| 54 | 54 |
| 55 var alias = {}; | 55 var alias = {}; |
| 56 | 56 |
| 57 alias.DIMENSIONS_WITH_ALIASES = ["device_type", "gpu"]; | 57 alias.DIMENSIONS_WITH_ALIASES = ["device_type", "gpu"]; |
| 58 | 58 |
| 59 alias.android = function(dt) { | 59 alias.android = function(dt) { |
| 60 return ANDROID_ALIASES[dt] || UNKNOWN; | 60 return ANDROID_ALIASES[dt] || UNKNOWN; |
| 61 }; | 61 }; |
| 62 | 62 |
| 63 // alias.apply is the consistent way to modify a string to show its alias. | 63 // alias.apply tries to alias the string "orig" based on what "type" it is. |
| 64 alias.apply = function(orig, alias) { | 64 // If type is in DIMENSIONS_WITH_ALIASES, the appropriate alias (e.g. gpu) |
| 65 return alias +" ("+orig+")"; | 65 // is automatically applied. Otherwise, "type" is treated as the alias. |
| 66 // If type is known, but there is no matching alias (e.g. for gpu: FOOBAR) | |
| 67 // the original will be returned. | |
| 68 alias.apply = function(orig, type) { | |
| 69 var aliaser = aliasMap[type]; | |
| 70 if (!aliaser) { | |
| 71 // treat type as the actual alias | |
| 72 return type + " ("+orig+")"; | |
| 73 } | |
| 74 var alias = aliaser(orig); | |
| 75 if (alias !== "unknown") { | |
| 76 return alias + " ("+orig+")"; | |
| 77 } | |
| 78 return orig; | |
| 66 }; | 79 }; |
| 67 | 80 |
| 68 alias.gpu = function(gpu) { | 81 alias.gpu = function(gpu) { |
| 69 return GPU_ALIASES[gpu] || UNKNOWN; | 82 return GPU_ALIASES[gpu] || UNKNOWN; |
| 70 }; | 83 }; |
| 71 | 84 |
| 72 // alias.unapply will return the base dimension/state with its alias removed | 85 // alias.unapply will return the base dimension/state with its alias removed |
| 73 // if it had one. This is handy for sorting and filtering. | 86 // if it had one. This is handy for sorting and filtering. |
| 74 alias.unapply = function(str) { | 87 alias.unapply = function(str) { |
| 75 var match = ALIAS_REGEXP.exec(str); | 88 var match = ALIAS_REGEXP.exec(str); |
| 76 if (match) { | 89 if (match) { |
| 77 return match[1]; | 90 return match[1]; |
| 78 } | 91 } |
| 79 return str; | 92 return str; |
| 80 }; | 93 }; |
| 81 | 94 |
| 95 var aliasMap = { | |
| 96 "device_type": alias.android, | |
| 97 "gpu": alias.gpu, | |
| 98 } | |
| 99 | |
| 82 return alias; | 100 return alias; |
| 83 })(); | 101 })(); |
| OLD | NEW |