1 | // Copyright 2013 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 | #include "flutter/testing/fixture_test.h" |
6 | |
7 | namespace flutter { |
8 | namespace testing { |
9 | |
10 | FixtureTest::FixtureTest() |
11 | : native_resolver_(std::make_shared<TestDartNativeResolver>()), |
12 | assets_dir_(fml::OpenDirectory(GetFixturesPath(), |
13 | false, |
14 | fml::FilePermission::kRead)), |
15 | aot_symbols_(LoadELFSymbolFromFixturesIfNeccessary()) {} |
16 | |
17 | Settings FixtureTest::CreateSettingsForFixture() { |
18 | Settings settings; |
19 | settings.leak_vm = false; |
20 | settings.task_observer_add = [](intptr_t, fml::closure) {}; |
21 | settings.task_observer_remove = [](intptr_t) {}; |
22 | settings.isolate_create_callback = [this]() { |
23 | native_resolver_->SetNativeResolverForIsolate(); |
24 | }; |
25 | settings.enable_observatory = false; |
26 | SetSnapshotsAndAssets(settings); |
27 | return settings; |
28 | } |
29 | |
30 | void FixtureTest::SetSnapshotsAndAssets(Settings& settings) { |
31 | if (!assets_dir_.is_valid()) { |
32 | return; |
33 | } |
34 | |
35 | settings.assets_dir = assets_dir_.get(); |
36 | |
37 | // In JIT execution, all snapshots are present within the binary itself and |
38 | // don't need to be explicitly supplied by the embedder. In AOT, these |
39 | // snapshots will be present in the application AOT dylib. |
40 | if (DartVM::IsRunningPrecompiledCode()) { |
41 | FML_CHECK(PrepareSettingsForAOTWithSymbols(settings, aot_symbols_)); |
42 | } else { |
43 | settings.application_kernels = [this]() { |
44 | std::vector<std::unique_ptr<const fml::Mapping>> kernel_mappings; |
45 | kernel_mappings.emplace_back( |
46 | fml::FileMapping::CreateReadOnly(assets_dir_, "kernel_blob.bin" )); |
47 | return kernel_mappings; |
48 | }; |
49 | } |
50 | } |
51 | |
52 | void FixtureTest::AddNativeCallback(std::string name, |
53 | Dart_NativeFunction callback) { |
54 | native_resolver_->AddNativeCallback(std::move(name), callback); |
55 | } |
56 | |
57 | } // namespace testing |
58 | } // namespace flutter |
59 | |