-
Notifications
You must be signed in to change notification settings - Fork 26.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds the hasStrings method for Mac, and improves the state of unit testing on Mac.
- Loading branch information
Showing
5 changed files
with
104 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
shell/platform/darwin/macos/framework/Source/FlutterViewControllerTest.mm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterViewController_Internal.h" | ||
|
||
#include "flutter/shell/platform/darwin/macos/framework/Headers/FlutterEngine.h" | ||
#include "flutter/shell/platform/darwin/macos/framework/Source/FlutterDartProject_Internal.h" | ||
#include "flutter/shell/platform/darwin/macos/framework/Source/FlutterEngine_Internal.h" | ||
#include "flutter/testing/testing.h" | ||
#import "third_party/ocmock/Source/OCMock/OCMock.h" | ||
|
||
namespace flutter::testing { | ||
|
||
// Returns a mock FlutterViewController that is able to work in environments | ||
// without a real pasteboard. | ||
id mockViewController(NSString* pasteboardString) { | ||
NSString* fixtures = @(testing::GetFixturesPath()); | ||
FlutterDartProject* project = [[FlutterDartProject alloc] | ||
initWithAssetsPath:fixtures | ||
ICUDataPath:[fixtures stringByAppendingString:@"/icudtl.dat"]]; | ||
FlutterViewController* viewController = [[FlutterViewController alloc] initWithProject:project]; | ||
|
||
// Mock pasteboard so that this test will work in environments without a | ||
// real pasteboard. | ||
id pasteboardMock = OCMClassMock([NSPasteboard class]); | ||
OCMExpect([pasteboardMock stringForType:[OCMArg any]]).andDo(^(NSInvocation* invocation) { | ||
NSString* returnValue = pasteboardString.length > 0 ? pasteboardString : nil; | ||
[invocation setReturnValue:&returnValue]; | ||
}); | ||
id viewControllerMock = OCMPartialMock(viewController); | ||
OCMStub([viewControllerMock pasteboard]).andReturn(pasteboardMock); | ||
return viewControllerMock; | ||
} | ||
|
||
TEST(FlutterViewControllerTest, HasStringsWhenPasteboardEmpty) { | ||
// Mock FlutterViewController so that it behaves like the pasteboard is empty. | ||
id viewControllerMock = mockViewController(nil); | ||
|
||
// Call hasStrings and expect it to be false. | ||
__block bool calledAfterClear = false; | ||
__block bool valueAfterClear; | ||
FlutterResult resultAfterClear = ^(id result) { | ||
calledAfterClear = true; | ||
NSNumber* valueNumber = [result valueForKey:@"value"]; | ||
valueAfterClear = [valueNumber boolValue]; | ||
}; | ||
FlutterMethodCall* methodCallAfterClear = | ||
[FlutterMethodCall methodCallWithMethodName:@"Clipboard.hasStrings" arguments:nil]; | ||
[viewControllerMock handleMethodCall:methodCallAfterClear result:resultAfterClear]; | ||
ASSERT_TRUE(calledAfterClear); | ||
ASSERT_FALSE(valueAfterClear); | ||
} | ||
|
||
TEST(FlutterViewControllerTest, HasStringsWhenPasteboardFull) { | ||
// Mock FlutterViewController so that it behaves like the pasteboard has a | ||
// valid string. | ||
id viewControllerMock = mockViewController(@"some string"); | ||
|
||
// Call hasStrings and expect it to be true. | ||
__block bool called = false; | ||
__block bool value; | ||
FlutterResult result = ^(id result) { | ||
called = true; | ||
NSNumber* valueNumber = [result valueForKey:@"value"]; | ||
value = [valueNumber boolValue]; | ||
}; | ||
FlutterMethodCall* methodCall = | ||
[FlutterMethodCall methodCallWithMethodName:@"Clipboard.hasStrings" arguments:nil]; | ||
[viewControllerMock handleMethodCall:methodCall result:result]; | ||
ASSERT_TRUE(called); | ||
ASSERT_TRUE(value); | ||
} | ||
|
||
} // flutter::testing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters