This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
hasStrings Mac #20531
Merged
Merged
hasStrings Mac #20531
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
bb0f4be
hasStrings on mac
justinmc 97acb46
WIP test
justinmc 660092e
Clean up and remove test since unit testing on mac not set up?
justinmc ffc7af4
Test hasStrings
justinmc 98adfc9
Test hasStrings after clearing the clipboard as well
justinmc 59ad159
Run Mac unit tests in run_tests.py
justinmc 084c926
Formatting
justinmc 1a22b66
Build.gn formatting
justinmc 67f0173
Test name
justinmc 6177e74
WIP trying to get ocmock to work in Mac
justinmc 24d28c8
Use new ocmock target coming in buildroot PR
justinmc 51280f2
Mocked pasteboard working
justinmc a15798e
handleMethodCall removed from header and pasteboard moved to property…
justinmc 878aa78
Docs clarification
justinmc c2bca18
clipboardHasStrings returns a bool, caller handles dictionary
justinmc 54301f3
Split tests and some cleanup
justinmc 70286fc
Deduplicate mocking code
justinmc 6c778fe
Comment cleanup
justinmc b68a594
Analyzer fixes
justinmc 25385b5
Merge branch 'master' into has-strings-mac
justinmc 45b81b4
Reference new buildroot hash after my change to ocmock there
justinmc 2d0728d
Merge branch 'master' into has-strings-mac
justinmc 3c9ec6e
_pasteboard -> pasteboard
justinmc a52595d
Mock pasteboard value directly instead of mocking setString
justinmc d14a117
Don't run the mac tests with run_test.py, because they fail in AOT mode
justinmc 3490d8a
Merge branch 'master' into has-strings-mac
justinmc e1566ac
pasteboard in the private header
justinmc 491a585
Merge branch 'master' into has-strings-mac
justinmc 8c2d240
Merge branch 'master' into has-strings-mac
justinmc 06a6034
Use ocmock now that it has been made to work with mac and ocmock_src …
justinmc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is doing a lot of different things; please make individual tests that are more targeted. You're already using a fake pasteboard, so there's no need to do the entire cycle in a single test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call, I split it into two and it's a lot cleaner.