Commit c62a9956 authored by Javier Ernesto Flores Robles's avatar Javier Ernesto Flores Robles Committed by Commit Bot

[iOS][MF] Add support for device rotation

Adds a flag wich resets after a delay when the device rotates. This
allows to know if certain notification are caused due a recent rotation.

Bug: 845472
Cq-Include-Trybots: luci.chromium.try:ios-simulator-cronet;luci.chromium.try:ios-simulator-full-configs
Change-Id: I7b36544a451c677ff0ff842876f80841847a2833
Reviewed-on: https://chromium-review.googlesource.com/c/1273145
Commit-Queue: Javier Ernesto Flores Robles <javierrobles@chromium.org>
Reviewed-by: default avataredchin <edchin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#601072}
parent 7297c666
...@@ -10,8 +10,15 @@ ...@@ -10,8 +10,15 @@
@interface KeyboardObserverHelper () @interface KeyboardObserverHelper ()
// Boolean to check if the keyboard was actually dismissed. // Flag that indicates if the keyboard is on screen.
@property(nonatomic) BOOL keyboardOnScreen; @property(nonatomic, getter=isKeyboardOnScreen) BOOL keyboardOnScreen;
// Flag that indicates if the next keyboard did hide notification should be
// ignored. This happens when the keyboard is on screen and the device rotates.
// Causing keyboard notifications to be sent, but the keyboard never leaves the
// screen.
@property(nonatomic, getter=shouldIgnoreNextKeyboardDidHide)
BOOL ignoreNextKeyboardDidHide;
@end @end
...@@ -35,6 +42,11 @@ ...@@ -35,6 +42,11 @@
selector:@selector(keyboardDidHide:) selector:@selector(keyboardDidHide:)
name:UIKeyboardDidHideNotification name:UIKeyboardDidHideNotification
object:nil]; object:nil];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(orientationDidChange:)
name:UIApplicationDidChangeStatusBarOrientationNotification
object:nil];
} }
return self; return self;
} }
...@@ -53,6 +65,12 @@ ...@@ -53,6 +65,12 @@
} }
- (void)keyboardDidHide:(NSNotification*)notification { - (void)keyboardDidHide:(NSNotification*)notification {
// If UIKeyboardDidHideNotification was sent because of a orientation
// change, reset the flag and ignore.
if (self.shouldIgnoreNextKeyboardDidHide) {
self.ignoreNextKeyboardDidHide = NO;
return;
}
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
if (!self.keyboardOnScreen) { if (!self.keyboardOnScreen) {
[self.delegate keyboardDidHide]; [self.delegate keyboardDidHide];
...@@ -60,4 +78,12 @@ ...@@ -60,4 +78,12 @@
}); });
} }
- (void)orientationDidChange:(NSNotification*)notification {
// If the keyboard is on screen, set the flag to ignore next keyboard did
// hide.
if (self.keyboardOnScreen) {
self.ignoreNextKeyboardDidHide = YES;
}
}
@end @end
...@@ -224,6 +224,8 @@ void ClearPasswordStore() { ...@@ -224,6 +224,8 @@ void ClearPasswordStore() {
- (void)tearDown { - (void)tearDown {
ClearPasswordStore(); ClearPasswordStore();
[EarlGrey rotateDeviceToOrientation:UIDeviceOrientationPortrait
errorOrNil:nil];
[super tearDown]; [super tearDown];
} }
...@@ -501,4 +503,26 @@ void ClearPasswordStore() { ...@@ -501,4 +503,26 @@ void ClearPasswordStore() {
assertWithMatcher:grey_sufficientlyVisible()]; assertWithMatcher:grey_sufficientlyVisible()];
} }
// Test that the Password View Controller stays on rotation.
- (void)testPasswordControllerSupportsRotation {
// Bring up the keyboard.
[[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewMatcher()]
performAction:chrome_test_util::TapWebElement(kFormElementUsername)];
// Tap on the passwords icon.
[[EarlGrey selectElementWithMatcher:PasswordIconMatcher()]
performAction:grey_tap()];
// Verify the password controller table view is visible.
[[EarlGrey selectElementWithMatcher:PasswordTableViewMatcher()]
assertWithMatcher:grey_sufficientlyVisible()];
[EarlGrey rotateDeviceToOrientation:UIDeviceOrientationLandscapeLeft
errorOrNil:nil];
// Verify the password controller table view is still visible.
[[EarlGrey selectElementWithMatcher:PasswordTableViewMatcher()]
assertWithMatcher:grey_sufficientlyVisible()];
}
@end @end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment