Skip to content

Commit 1ce114d

Browse files
committed
Merge pull request dart-gde#243 from bholtz/downloadIdlsPR
Adds new idl download tool
2 parents cb56ee2 + 4b49b51 commit 1ce114d

12 files changed

+603
-13
lines changed

idl_readme.txt

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
1-
This directory contains copies of Chromium IDL files.
1+
The idl directory contains copies of Chromium IDL and JSON files.
22

33
The original files are from:
44

5-
https://src.chromium.org/chrome/trunk/src/chrome/common/extensions/api
6-
https://src.chromium.org/chrome/trunk/src/extensions/common/api
5+
https://chromium.googlesource.com/chromium/src/+/<chrome_version>/chrome/common/extensions/api
6+
https://chromium.googlesource.com/chromium/src/+/<chrome_version>/extensions/common/api
77

8-
SVN revisions available at http://omahaproxy.appspot.com/.
9-
Current revision: 283104
8+
GIT revisions available at http://omahaproxy.appspot.com/.
109

1110
To update:
1211

13-
rm -rf idl
14-
svn co https://src.chromium.org/chrome/trunk/src/chrome/common/extensions/api idl/chrome -r <rev_number>
15-
svn co https://src.chromium.org/chrome/trunk/src/extensions/common/api idl/extensions -r <rev_number>
16-
17-
Please see the corresponding LICENSE file at: http://src.chromium.org/svn/trunk/src/LICENSE
12+
dart tool/download_idls.dart

pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ dev_dependencies:
1414
args: any
1515
browser: any
1616
logging: any
17+
mockito: any
1718
parsers: '>=0.14.0 <0.15.0'
1819
path: any
1920
test: ^0.12.0

test/all.dart

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11

22
library all_test;
33

4+
import 'chrome_idl_files_test.dart' as test_chrome_idl_files;
5+
import 'chrome_idl_test.dart' as test_chrome_idl;
6+
import 'googlesource_test.dart' as googlesource_test;
47
import 'model_json_test.dart' as model_json_test;
8+
import 'omaha_test.dart' as omaha_test;
9+
import 'simple_http_client_test.dart' as simple_http_client_test;
510
import 'src_gen_test.dart' as src_gen_test;
6-
import 'utils_test.dart' as utils_test;
7-
import 'chrome_idl_test.dart' as test_chrome_idl;
8-
import 'chrome_idl_files_test.dart' as test_chrome_idl_files;
11+
import 'tag_matcher_test.dart' as tag_matcher_test;
912
import 'transformer_test.dart' as transformer_test;
13+
import 'utils_test.dart' as utils_test;
1014

1115
void main() {
1216
model_json_test.main();
@@ -15,4 +19,8 @@ void main() {
1519
test_chrome_idl.main();
1620
test_chrome_idl_files.main();
1721
transformer_test.defineTests();
22+
simple_http_client_test.defineTests();
23+
omaha_test.defineTests();
24+
tag_matcher_test.defineTests();
25+
googlesource_test.defineTests();
1826
}

test/googlesource_test.dart

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
library googlesource_test;
2+
3+
import 'dart:async';
4+
import 'dart:convert';
5+
6+
import 'package:test/test.dart';
7+
8+
import '../tool/src/googlesource.dart';
9+
import '../tool/src/simple_http_client.dart';
10+
11+
void main() => defineTests();
12+
13+
void defineTests() {
14+
group('GoogleSourceFile', () {
15+
GoogleSourceFile file;
16+
17+
void testHtmlConversion(List<String> lines) {
18+
file = new GoogleSourceFile(asHtml(lines), 'example.com');
19+
20+
expect(file.fileContents, lines.join('\n'));
21+
}
22+
23+
test('correctly parses simple raw html', () {
24+
testHtmlConversion(['just one line']);
25+
});
26+
27+
test('correctly parses multiline raw html', () {
28+
testHtmlConversion(['multiple', 'small', 'lines']);
29+
});
30+
31+
test('correctly parses multiline raw html with whitespace', () {
32+
testHtmlConversion(['if (true)', ' goto label;', '', '', 'label']);
33+
});
34+
35+
test('unescapes files', () {
36+
var testEscapeString = 'this & that is <\"\'>';
37+
var escapedHtmlFile = '<table><tr><td></td><td><a name="1"></a><span>'
38+
'${HTML_ESCAPE.convert(testEscapeString)}</span></td></tr></table>';
39+
file = new GoogleSourceFile(escapedHtmlFile, 'www.example.com');
40+
41+
expect(file.fileContents, testEscapeString);
42+
});
43+
});
44+
45+
group('GoogleSourceCrawler', () {
46+
var baseUri = 'http://www.example.com/';
47+
FakeSimpleHttpClient client;
48+
GoogleSourceCrawler crawler;
49+
50+
setUp(() {
51+
client = new FakeSimpleHttpClient();
52+
crawler = new GoogleSourceCrawler(baseUri, client: client);
53+
});
54+
55+
test('returns correct files in single directory', () async {
56+
prepopulateHttpResponses(client, test1);
57+
58+
var files = await crawler.findAllMatchingFiles('test').toList();
59+
60+
expect(files.length, 3);
61+
expect(
62+
files.map((file) => file.url),
63+
allOf(contains('/test/a.idl'), contains('/test/b.idl'),
64+
contains('/test/c.idl')));
65+
});
66+
67+
test('correctly follows the file tree', () async {
68+
prepopulateHttpResponses(client, test2);
69+
70+
var files = await crawler.findAllMatchingFiles('test').toList();
71+
72+
expect(files.single.url, '/test/foo/bar/baz/qux.idl');
73+
});
74+
75+
test('rejects files with non-matching extensions', () async {
76+
prepopulateHttpResponses(client, test3);
77+
78+
var files = await crawler.findAllMatchingFiles('test').toList();
79+
80+
expect(files.length, 2);
81+
expect(
82+
files.map((file) => file.url),
83+
allOf(contains('/test/a.idl'), contains('/test/c.json')));
84+
});
85+
});
86+
}
87+
88+
void prepopulateHttpResponses(
89+
FakeSimpleHttpClient fakeClient, List<String> responses) {
90+
fakeClient.reset();
91+
for (var response in responses) {
92+
fakeClient.addHtml(response);
93+
}
94+
}
95+
96+
class FakeSimpleHttpClient implements SimpleHttpClient {
97+
List<String> _htmlOutputList;
98+
int _callCount;
99+
100+
FakeSimpleHttpClient() {
101+
reset();
102+
}
103+
104+
Future<String> getHtmlAtUri(_) {
105+
var html = '';
106+
if (_htmlOutputList.isNotEmpty) {
107+
html = _htmlOutputList[_callCount];
108+
}
109+
if (_callCount != _htmlOutputList.length - 1) {
110+
_callCount++;
111+
}
112+
return new Future.value(html);
113+
}
114+
115+
void reset() {
116+
_htmlOutputList = [];
117+
_callCount = 0;
118+
}
119+
120+
void addHtml(String html) {
121+
_htmlOutputList.add(html);
122+
}
123+
}
124+
125+
var test1 = [
126+
'<ol>'
127+
'<li><a href="/test/a.idl">a.idl</a></li>'
128+
'<li><a href="/test/b.idl">b.idl</a></li>'
129+
'<li><a href="/test/c.idl">c.idl</a></li>'
130+
'</ol>',
131+
'a contents',
132+
'b contents',
133+
'c contents'
134+
];
135+
136+
var test2 = [
137+
'<ol><li><a href="/test/foo/">foo</a></li></ol>',
138+
'<ol><li><a href="/test/foo/bar/">bar</a></li></ol>',
139+
'<ol><li><a href="/test/foo/bar/baz/">baz</a></li></ol>',
140+
'<ol><li><a href="/test/foo/bar/baz/qux.idl">qux.idl</a></li></ol>',
141+
'qux contents'
142+
];
143+
144+
var test3 = [
145+
'<ol><li><a href="/test/a.idl">a.idl</a></li>'
146+
'<li><a href="/test/b.txt">b.txt</a></li>'
147+
'<li><a href="/test/c.json">c.json</a></li></ol>',
148+
'a contents',
149+
'b contents',
150+
'c contents'
151+
];
152+
153+
String asHtml(List<String> lines) {
154+
var liHtml = lines
155+
.map((line) => '<tr><td></td><td><a></a><span>$line</span></td></tr>')
156+
.join();
157+
return '<table>$liHtml</table>';
158+
}
159+
160+
var multilineFileHtml = '''<table>
161+
<tr>
162+
<td></td>
163+
<td><li><a name="1"></a><span>first line</span></li></td>
164+
</tr>
165+
<tr>
166+
<td></td>
167+
<td><li><a name="2"></a><span> second line</span></li></td>
168+
</tr>
169+
<tr>
170+
<td></td>
171+
<td><li><a name="3"></a><span>just one line</span></li></td>
172+
</tr>
173+
<tr>
174+
<td></td>
175+
<td><li><a name="4"></a><span>just one line</span></li></td>
176+
</tr>
177+
<tr>
178+
<td></td>
179+
<td><li><a name="5"></a><span>just one line</span></li></td>
180+
</tr>
181+
<tr>
182+
<td></td>
183+
<td><li><a name="6"></a><span>just one line</span></li></td>
184+
</tr>
185+
</table>''';

test/omaha_test.dart

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
library omaha_test;
2+
3+
import 'dart:async';
4+
5+
import 'package:mockito/mockito.dart';
6+
import 'package:test/test.dart';
7+
8+
import '../tool/src/omaha.dart';
9+
import '../tool/src/simple_http_client.dart';
10+
11+
void main() => defineTests();
12+
13+
void defineTests() {
14+
group('OmahaVersionExtractor', () {
15+
OmahaVersionExtractor extractor;
16+
MockSimpleHttpClient client;
17+
String html;
18+
19+
setUp(() {
20+
client = new MockSimpleHttpClient();
21+
when(client.getHtmlAtUri(any)).thenAnswer((_) => new Future.value(html));
22+
extractor = new OmahaVersionExtractor(client: client);
23+
});
24+
25+
test('correctly parses good, simple input', () async {
26+
var version = 'alpha';
27+
html = 'mac,stable,$version';
28+
29+
expect(await extractor.stableVersion, version);
30+
});
31+
});
32+
}
33+
34+
class MockSimpleHttpClient extends Mock implements SimpleHttpClient {
35+
noSuchMethod(Invocation msg) => super.noSuchMethod(msg);
36+
}

test/simple_http_client_test.dart

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
library simple_http_client_test;
2+
3+
import 'dart:async';
4+
import 'dart:io';
5+
6+
import 'package:mockito/mockito.dart';
7+
import 'package:test/test.dart';
8+
9+
import '../tool/src/simple_http_client.dart';
10+
11+
void main() => defineTests();
12+
13+
void defineTests() {
14+
group('SimpleHttpClient', () {
15+
SimpleHttpClient simpleClient;
16+
MockHttpClient mockClient;
17+
MockHttpClientRequest mockRequest;
18+
MockHttpClientResponse mockResponse;
19+
List<String> html;
20+
21+
setUp(() {
22+
mockClient = new MockHttpClient();
23+
mockRequest = new MockHttpClientRequest();
24+
mockResponse = new MockHttpClientResponse();
25+
26+
when(mockClient.getUrl(any)).thenReturn(mockRequest);
27+
when(mockRequest.done).thenReturn(new Future(() => mockResponse));
28+
when(mockResponse.transform(any)).thenAnswer((_) => html);
29+
30+
simpleClient = new SimpleHttpClient(client: mockClient);
31+
});
32+
33+
test('returns string', () async {
34+
var testString = 'this is some great testHtml';
35+
html = [testString];
36+
37+
expect(await simpleClient.getHtmlAtUri(Uri.parse('example.com')),
38+
testString);
39+
});
40+
});
41+
}
42+
43+
class MockHttpClient extends Mock implements HttpClient {
44+
noSuchMethod(Invocation msg) => super.noSuchMethod(msg);
45+
}
46+
47+
class MockHttpClientRequest extends Mock implements HttpClientRequest {
48+
noSuchMethod(Invocation msg) => super.noSuchMethod(msg);
49+
}
50+
51+
class MockHttpClientResponse extends Mock implements HttpClientResponse {
52+
noSuchMethod(Invocation msg) => super.noSuchMethod(msg);
53+
}

0 commit comments

Comments
 (0)