1 | // Copyright 2014 The Flutter Authors. All rights reserved. |
---|---|
2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. |
4 | |
5 | import 'dart:js_interop'; |
6 | |
7 | import 'package:web/web.dart'as web; |
8 | |
9 | Future<void> main() async { |
10 | if (await testFetchResources()) { |
11 | print('--- TEST SUCCEEDED ---'); |
12 | } else { |
13 | print('--- TEST FAILED ---'); |
14 | } |
15 | } |
16 | |
17 | // Attempt to load CanvasKit resources hosted on gstatic. |
18 | Future<bool> testFetchResources() async { |
19 | const String engineVersion = String.fromEnvironment('TEST_FLUTTER_ENGINE_VERSION'); |
20 | if (engineVersion.isEmpty) { |
21 | return false; |
22 | } |
23 | try { |
24 | final web.Response response = await web.window.fetch( |
25 | 'https://www.gstatic.com/flutter-canvaskit/$engineVersion/canvaskit.js'.toJS, |
26 | web.RequestInit( |
27 | method: 'GET', |
28 | ), |
29 | ).toDart; |
30 | if (!response.ok) { |
31 | return false; |
32 | } |
33 | } catch (err) { |
34 | print(err); |
35 | return false; |
36 | } |
37 | try { |
38 | final web.Response response = await web.window.fetch( |
39 | 'https://www.gstatic.com/flutter-canvaskit/$engineVersion/canvaskit.wasm'.toJS, |
40 | web.RequestInit( |
41 | method: 'GET', |
42 | ) |
43 | ).toDart; |
44 | if (!response.ok) { |
45 | return false; |
46 | } |
47 | } catch (err) { |
48 | print(err); |
49 | return false; |
50 | } |
51 | return true; |
52 | } |
53 |