forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upstream two UI-related test utilities for iOS
This upstreams two test utility files: - KeyboardAppearanceListener, which watches for the software keyboard showing and hiding - ui_view_test_utils, which can Dismiss any visible alerts, and can force the display of a view (to ensure state changes that the OS might defer until drawing take effect). These are located in ui/ as they will be used in both ios/web/ and ios/chrome/. BUG=464810 Review URL: https://codereview.chromium.org/1122543002 Cr-Commit-Position: refs/heads/master@{#328775}
- Loading branch information
stuartmorgan
authored and
Commit bot
committed
May 7, 2015
1 parent
d0abaa3
commit 0f91f7a
Showing
5 changed files
with
142 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright 2012 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef UI_BASE_TEST_IOS_KEYBOARD_APPEARANCE_LISTENER_H_ | ||
#define UI_BASE_TEST_IOS_KEYBOARD_APPEARANCE_LISTENER_H_ | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
// Listener to observe the keyboard coming up or down. | ||
@interface KeyboardAppearanceListener : NSObject | ||
|
||
// Returns YES if the keyboard is currently visible. | ||
@property(nonatomic, readonly, getter=isKeyboardVisible) bool keyboardVisible; | ||
|
||
@end | ||
|
||
#endif // UI_BASE_TEST_IOS_KEYBOARD_APPEARANCE_LISTENER_H_ |
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,46 @@ | ||
// Copyright 2012 The Chromium 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 "ui/base/test/ios/keyboard_appearance_listener.h" | ||
|
||
#include <vector> | ||
|
||
@implementation KeyboardAppearanceListener { | ||
@private | ||
std::vector<id> _notificationObservers; | ||
} | ||
|
||
@synthesize keyboardVisible = _keyboardVisible; | ||
|
||
- (id)init { | ||
self = [super init]; | ||
if (self) { | ||
NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; | ||
_notificationObservers.push_back( | ||
[center addObserverForName:UIKeyboardDidShowNotification | ||
object:nil | ||
queue:nil | ||
usingBlock:^(NSNotification* arg) { | ||
_keyboardVisible = true; | ||
}]); | ||
_notificationObservers.push_back( | ||
[center addObserverForName:UIKeyboardWillHideNotification | ||
object:nil | ||
queue:nil | ||
usingBlock:^(NSNotification* arg) { | ||
_keyboardVisible = false; | ||
}]); | ||
} | ||
return self; | ||
} | ||
|
||
- (void)dealloc { | ||
NSNotificationCenter* nc = [NSNotificationCenter defaultCenter]; | ||
for (const auto& observer : _notificationObservers) { | ||
[nc removeObserver:observer]; | ||
} | ||
_notificationObservers.clear(); | ||
[super dealloc]; | ||
} | ||
@end |
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,26 @@ | ||
// Copyright 2014 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef UI_BASE_TEST_IOS_UI_VIEW_TEST_UTILS_H_ | ||
#define UI_BASE_TEST_IOS_UI_VIEW_TEST_UTILS_H_ | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
namespace ui { | ||
namespace test { | ||
namespace uiview_utils { | ||
|
||
// Cancels any visible UIAlertViews. | ||
void CancelAlerts(); | ||
|
||
// Forces rendering of a UIView. This is used in tests to make sure that UIKit | ||
// optimizations don't have the views return the previous values (such as | ||
// zoomScale). | ||
void ForceViewRendering(UIView* view); | ||
|
||
} // namespace uiview_utils | ||
} // test | ||
} // namespace ui | ||
|
||
#endif // UI_BASE_TEST_IOS_UI_VIEW_TEST_UTILS_H_ |
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,38 @@ | ||
// Copyright 2014 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "ui/base/test/ios/ui_view_test_utils.h" | ||
|
||
#include "base/logging.h" | ||
|
||
namespace ui { | ||
namespace test { | ||
namespace uiview_utils { | ||
|
||
void CancelAlerts() { | ||
for (UIWindow* window in [UIApplication sharedApplication].windows) { | ||
for (UIView* view in [window subviews]) { | ||
if ([view isKindOfClass:[UIAlertView class]]) { | ||
UIAlertView* alertView = (UIAlertView*)view; | ||
[alertView dismissWithClickedButtonIndex:0 animated:NO]; | ||
} | ||
} | ||
} | ||
} | ||
|
||
void ForceViewRendering(UIView* view) { | ||
DCHECK(view); | ||
CALayer* layer = view.layer; | ||
DCHECK(layer); | ||
// 19 is an arbitrary non-zero value. | ||
UIGraphicsBeginImageContext(CGSizeMake(19, 19)); | ||
CGContext* context = UIGraphicsGetCurrentContext(); | ||
DCHECK(context); | ||
[layer renderInContext:context]; | ||
UIGraphicsEndImageContext(); | ||
} | ||
|
||
} // namespace uiview_utils | ||
} // namespace test | ||
} // namespace ui |
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