Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 68da62f

Browse files
committed
add test
1 parent 94e0989 commit 68da62f

File tree

3 files changed

+130
-0
lines changed

3 files changed

+130
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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+
#import <Flutter/Flutter.h>
6+
#import <XCTest/XCTest.h>
7+
#import "AppDelegate.h"
8+
9+
@interface XCUIElement (ftr_waitForNonExistence)
10+
/// Keeps waiting until the element doesn't exist. Returns NO if the timeout is
11+
/// reached before it doesn't exist.
12+
- (BOOL)ftr_waitForNonExistenceWithTimeout:(NSTimeInterval)timeout;
13+
/// Waits the full duration to ensure something doesn't exist for that duration.
14+
/// Returns NO if at some point the element exists during the duration.
15+
- (BOOL)ftr_waitForNonExistenceForDuration:(NSTimeInterval)duration;
16+
@end
17+
18+
@implementation XCUIElement (ftr_waitForNonExistence)
19+
- (BOOL)ftr_waitForNonExistenceWithTimeout:(NSTimeInterval)timeout {
20+
NSTimeInterval delta = 0.5;
21+
while (timeout > 0.0) {
22+
if (!self.exists) {
23+
return YES;
24+
}
25+
usleep(delta * 1000000);
26+
timeout -= delta;
27+
}
28+
return NO;
29+
}
30+
31+
- (BOOL)ftr_waitForNonExistenceForDuration:(NSTimeInterval)duration {
32+
return ![self waitForExistenceWithTimeout:duration];
33+
}
34+
35+
@end
36+
37+
@interface LocalizationInitializationTest : XCTestCase
38+
@property(nonatomic, strong) XCUIApplication* application;
39+
@end
40+
41+
@implementation LocalizationInitializationTest
42+
43+
- (void)setUp {
44+
[super setUp];
45+
self.continueAfterFailure = NO;
46+
47+
self.application = [[XCUIApplication alloc] init];
48+
self.application.launchArguments = @[ @"--locale-initialization" ];
49+
[self.application launch];
50+
}
51+
52+
- (void)testNoLocalePrepend {
53+
NSTimeInterval timeout = 10.0;
54+
55+
// The locales recieved by dart:ui are exposed onBeginFrame via semantics label.
56+
// There should only be one locale, as we have removed the locale prepend on iOS.
57+
XCUIElement* textInputSemanticsObject =
58+
[[[self.application textFields] matchingIdentifier:@"[en_US]"] element];
59+
XCTAssertTrue([textInputSemanticsObject waitForExistenceWithTimeout:timeout]);
60+
}
61+
62+
@end
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Copyright 2020 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+
import 'dart:typed_data';
6+
import 'dart:ui';
7+
8+
import 'scenario.dart';
9+
10+
/// A scenario that sends back messages when touches are received.
11+
class LocaleInitialization extends Scenario {
12+
/// Constructor for `SendTextFocusScemantics`.
13+
LocaleInitialization(Window window)
14+
: assert(window != null),
15+
super(window);
16+
17+
@override
18+
void onBeginFrame(Duration duration) {
19+
// Doesn't matter what we draw. Just paint white.
20+
final SceneBuilder builder = SceneBuilder();
21+
final PictureRecorder recorder = PictureRecorder();
22+
final Canvas canvas = Canvas(recorder);
23+
24+
canvas.drawRect(
25+
Rect.fromLTWH(0, 0, window.physicalSize.width, window.physicalSize.height),
26+
Paint()..color = const Color.fromARGB(255, 255, 255, 255),
27+
);
28+
final Picture picture = recorder.endRecording();
29+
30+
builder.addPicture(
31+
Offset.zero,
32+
picture,
33+
);
34+
final Scene scene = builder.build();
35+
window.render(scene);
36+
scene.dispose();
37+
38+
// On the first frame, also pretend that it drew a text field. Send the
39+
// corresponding semantics tree comprised of 1 node for the text field.
40+
window.updateSemantics((SemanticsUpdateBuilder()
41+
..updateNode(
42+
id: 0,
43+
// SemanticsFlag.isTextField.
44+
flags: 16,
45+
// SemanticsAction.tap.
46+
actions: 1,
47+
rect: const Rect.fromLTRB(0.0, 0.0, 414.0, 48.0),
48+
label: window.locales.toString(),
49+
textDirection: TextDirection.ltr,
50+
textSelectionBase: -1,
51+
textSelectionExtent: -1,
52+
platformViewId: -1,
53+
maxValueLength: -1,
54+
currentValueLength: 0,
55+
scrollChildren: 0,
56+
scrollIndex: 0,
57+
// transform: Matrix4.identity().storage,
58+
elevation: 0.0,
59+
thickness: 0.0,
60+
childrenInTraversalOrder: Int32List(0),
61+
childrenInHitTestOrder: Int32List(0),
62+
additionalActions: Int32List(0),
63+
)).build()
64+
);
65+
}
66+
}

testing/scenario_app/lib/src/scenarios.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import 'dart:ui';
77

88
import 'animated_color_square.dart';
9+
import 'src/locale_initialization.dart';
910
import 'platform_view.dart';
1011
import 'poppable_screen.dart';
1112
import 'scenario.dart';
@@ -14,6 +15,7 @@ import 'touches_scenario.dart';
1415

1516
Map<String, Scenario> _scenarios = <String, Scenario>{
1617
'animated_color_square': AnimatedColorSquareScenario(window),
18+
'locale_initialization': LocaleInitialization(window),
1719
'platform_view': PlatformViewScenario(window, 'Hello from Scenarios (Platform View)', id: 0),
1820
'platform_view_no_overlay_intersection': PlatformViewNoOverlayIntersectionScenario(window, 'Hello from Scenarios (Platform View)', id: 0),
1921
'platform_view_partial_intersection': PlatformViewPartialIntersectionScenario(window, 'Hello from Scenarios (Platform View)', id: 0),

0 commit comments

Comments
 (0)