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