2
2
// for details. All rights reserved. Use of this source code is governed by a
3
3
// BSD-style license that can be found in the LICENSE file.
4
4
5
- import 'dart:collection' ;
6
-
7
5
// TODO(nweiz): support pluggable platforms.
8
6
/// An enum of all platforms on which tests can run.
9
7
class TestPlatform {
10
8
// When adding new platforms, be sure to update the baseline and derived
11
9
// variable tests in test/backend/platform_selector/evaluate_test.
12
10
13
11
/// The command-line Dart VM.
14
- static const TestPlatform vm =
15
- const TestPlatform ._("VM" , "vm" , isDartVM: true );
12
+ static const TestPlatform vm = const TestPlatform ("VM" , "vm" , isDartVM: true );
16
13
17
14
/// Dartium.
18
- static const TestPlatform dartium = const TestPlatform ._ ("Dartium" , "dartium" ,
15
+ static const TestPlatform dartium = const TestPlatform ("Dartium" , "dartium" ,
19
16
isBrowser: true , isBlink: true , isDartVM: true );
20
17
21
18
/// Dartium content shell.
22
- static const TestPlatform contentShell = const TestPlatform ._ (
19
+ static const TestPlatform contentShell = const TestPlatform (
23
20
"Dartium Content Shell" , "content-shell" ,
24
21
isBrowser: true , isBlink: true , isDartVM: true , isHeadless: true );
25
22
26
23
/// Google Chrome.
27
- static const TestPlatform chrome = const TestPlatform ._ ("Chrome" , "chrome" ,
24
+ static const TestPlatform chrome = const TestPlatform ("Chrome" , "chrome" ,
28
25
isBrowser: true , isJS: true , isBlink: true );
29
26
30
27
/// PhantomJS.
31
- static const TestPlatform phantomJS = const TestPlatform ._ (
28
+ static const TestPlatform phantomJS = const TestPlatform (
32
29
"PhantomJS" , "phantomjs" ,
33
30
isBrowser: true , isJS: true , isBlink: true , isHeadless: true );
34
31
35
32
/// Mozilla Firefox.
36
33
static const TestPlatform firefox =
37
- const TestPlatform ._ ("Firefox" , "firefox" , isBrowser: true , isJS: true );
34
+ const TestPlatform ("Firefox" , "firefox" , isBrowser: true , isJS: true );
38
35
39
36
/// Apple Safari.
40
37
static const TestPlatform safari =
41
- const TestPlatform ._ ("Safari" , "safari" , isBrowser: true , isJS: true );
38
+ const TestPlatform ("Safari" , "safari" , isBrowser: true , isJS: true );
42
39
43
40
/// Microsoft Internet Explorer.
44
- static const TestPlatform internetExplorer = const TestPlatform ._ (
41
+ static const TestPlatform internetExplorer = const TestPlatform (
45
42
"Internet Explorer" , "ie" ,
46
43
isBrowser: true , isJS: true );
47
44
48
45
/// The command-line Node.js VM.
49
46
static const TestPlatform nodeJS =
50
- const TestPlatform ._("Node.js" , "node" , isJS: true );
51
-
52
- /// A list of all instances of [TestPlatform] .
53
- static final UnmodifiableListView <TestPlatform > all =
54
- new UnmodifiableListView <TestPlatform >(_allPlatforms);
55
-
56
- /// Finds a platform by its identifier string.
57
- ///
58
- /// If no platform is found, returns `null` .
59
- static TestPlatform find (String identifier) =>
60
- all.firstWhere ((platform) => platform.identifier == identifier,
61
- orElse: () => null );
47
+ const TestPlatform ("Node.js" , "node" , isJS: true );
62
48
63
- static Set <TestPlatform > _builtIn = new Set .from ([
49
+ /// The platforms that are supported by the test runner by default.
50
+ static const List <TestPlatform > builtIn = const [
64
51
TestPlatform .vm,
65
52
TestPlatform .dartium,
66
53
TestPlatform .contentShell,
@@ -70,7 +57,7 @@ class TestPlatform {
70
57
TestPlatform .safari,
71
58
TestPlatform .internetExplorer,
72
59
TestPlatform .nodeJS
73
- ]) ;
60
+ ];
74
61
75
62
/// The human-friendly name of the platform.
76
63
final String name;
@@ -93,7 +80,7 @@ class TestPlatform {
93
80
/// Whether this platform has no visible window.
94
81
final bool isHeadless;
95
82
96
- const TestPlatform ._ (this .name, this .identifier,
83
+ const TestPlatform (this .name, this .identifier,
97
84
{this .isDartVM: false ,
98
85
this .isBrowser: false ,
99
86
this .isJS: false ,
@@ -103,10 +90,13 @@ class TestPlatform {
103
90
/// Converts a JSON-safe representation generated by [serialize] back into a
104
91
/// [TestPlatform] .
105
92
factory TestPlatform .deserialize (Object serialized) {
106
- if (serialized is String ) return find (serialized);
93
+ if (serialized is String ) {
94
+ return builtIn
95
+ .firstWhere ((platform) => platform.identifier == serialized);
96
+ }
107
97
108
98
var map = serialized as Map ;
109
- return new TestPlatform ._ (map["name" ], map["identifier" ],
99
+ return new TestPlatform (map["name" ], map["identifier" ],
110
100
isDartVM: map["isDartVM" ],
111
101
isBrowser: map["isBrowser" ],
112
102
isJS: map["isJS" ],
@@ -117,7 +107,7 @@ class TestPlatform {
117
107
/// Converts [this] into a JSON-safe object that can be converted back to a
118
108
/// [TestPlatform] using [new TestPlatform.deserialize] .
119
109
Object serialize () {
120
- if (_builtIn .contains (this )) return identifier;
110
+ if (builtIn .contains (this )) return identifier;
121
111
122
112
return {
123
113
"name" : name,
@@ -132,26 +122,3 @@ class TestPlatform {
132
122
133
123
String toString () => name;
134
124
}
135
-
136
- final List <TestPlatform > _allPlatforms = TestPlatform ._builtIn.toList ();
137
-
138
- /// **Do not call this function without express permission from the test package
139
- /// authors**.
140
- ///
141
- /// This constructs and globally registers a new TestPlatform with the provided
142
- /// details.
143
- TestPlatform registerTestPlatform (String name, String identifier,
144
- {bool isDartVM: false ,
145
- bool isBrowser: false ,
146
- bool isJS: false ,
147
- bool isBlink: false ,
148
- bool isHeadless: false }) {
149
- var platform = new TestPlatform ._(name, identifier,
150
- isDartVM: isDartVM,
151
- isBrowser: isBrowser,
152
- isJS: isJS,
153
- isBlink: isBlink,
154
- isHeadless: isHeadless);
155
- _allPlatforms.add (platform);
156
- return platform;
157
- }
0 commit comments