| Flutter macOS Embedder |

FlutterViewEngineProviderTest.mm
Go to the documentation of this file.
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 <Carbon/Carbon.h>
6 #import <Foundation/Foundation.h>
7 #import <OCMock/OCMock.h>
8
9 #import "flutter/shell/platform/darwin/macos/framework/Source/FlutterEngineTestUtils.h"
10 #import "flutter/shell/platform/darwin/macos/framework/Source/FlutterEngine_Internal.h"
11 #import "flutter/shell/platform/darwin/macos/framework/Source/FlutterViewController_Internal.h"
12 #import "flutter/shell/platform/darwin/macos/framework/Source/FlutterViewEngineProvider.h"
13 #import "flutter/testing/testing.h"
14 #include "third_party/googletest/googletest/include/gtest/gtest.h"
15
16 #import "flutter/testing/testing.h"
17 #include "third_party/googletest/googletest/include/gtest/gtest.h"
18
19 namespace flutter::testing {
20
21 TEST(FlutterViewEngineProviderUnittests, GetViewReturnsTheCorrectView) {
22 FlutterViewEngineProvider* viewProvider;
23 id mockEngine = CreateMockFlutterEngine(@"");
24 __block id mockFlutterViewController;
25 OCMStub([mockEngine viewControllerForId:0])
26 .ignoringNonObjectArgs()
27 .andDo(^(NSInvocation* invocation) {
28 FlutterViewId viewId;
29 [invocation getArgument:&viewId atIndex:2];
30 if (viewId == kFlutterImplicitViewId) {
31 if (mockFlutterViewController != nil) {
32 [invocation setReturnValue:&mockFlutterViewController];
33 }
34 }
35 });
36 viewProvider = [[FlutterViewEngineProvider alloc] initWithEngine:mockEngine];
37
38 // When the view controller is not set, the returned view is nil.
39 EXPECT_EQ([viewProvider viewForId:0], nil);
40
41 // When the view controller is set, the returned view is the controller's view.
42 mockFlutterViewController = OCMStrictClassMock([FlutterViewController class]);
43 id mockView = OCMStrictClassMock([FlutterView class]);
44 OCMStub([mockFlutterViewController flutterView]).andReturn(mockView);
45 EXPECT_EQ([viewProvider viewForId:0], mockView);
46 }
47
48 } // namespace flutter::testing
FlutterViewController
Definition: FlutterViewController.h:65
flutter::testing::CreateMockFlutterEngine
id CreateMockFlutterEngine(NSString *pasteboardString)
Definition: FlutterEngineTestUtils.mm:76
FlutterEngine_Internal.h
FlutterViewEngineProvider.h
flutter::testing
Definition: AccessibilityBridgeMacTest.mm:13
flutter::testing::TEST
TEST(FlutterAppDelegateTest, DoesNotCallDelegatesWithoutHandler)
Definition: FlutterAppDelegateTest.mm:32
FlutterEngineTestUtils.h
FlutterViewEngineProvider
Definition: FlutterViewEngineProvider.h:18
kFlutterImplicitViewId
constexpr FlutterViewId kFlutterImplicitViewId
Definition: FlutterView.h:26
FlutterViewController_Internal.h
FlutterView
Definition: FlutterView.h:48
FlutterViewId
int64_t FlutterViewId
Definition: FlutterView.h:15