Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "ios/chrome/test/earl_grey/chrome_matchers.h" | 5 #import "ios/chrome/test/earl_grey/chrome_matchers.h" |
| 6 | 6 |
| 7 #import <OCHamcrest/OCHamcrest.h> | 7 #import <OCHamcrest/OCHamcrest.h> |
| 8 | 8 |
| 9 #import <WebKit/WebKit.h> | 9 #import <WebKit/WebKit.h> |
| 10 | 10 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 46 GREYAssert( | 46 GREYAssert( |
| 47 testing::WaitUntilConditionOrTimeout(testing::kWaitForJSCompletionTimeout, | 47 testing::WaitUntilConditionOrTimeout(testing::kWaitForJSCompletionTimeout, |
| 48 ^{ | 48 ^{ |
| 49 return did_finish; | 49 return did_finish; |
| 50 }), | 50 }), |
| 51 @"JavaScript did not complete"); | 51 @"JavaScript did not complete"); |
| 52 | 52 |
| 53 return [result autorelease]; | 53 return [result autorelease]; |
| 54 } | 54 } |
| 55 | 55 |
| 56 id<GREYMatcher> webViewWithNavDelegateOfClass(Class cls) { | 56 id<GREYMatcher> WebViewWithNavDelegateOfClass(Class cls) { |
|
Eugene But (OOO till 7-30)
2017/01/23 19:39:04
Could you please file a bug to remove this method.
baxley
2017/01/24 22:18:50
Done.
| |
| 57 MatchesBlock matches = ^BOOL(UIView* view) { | 57 MatchesBlock matches = ^BOOL(UIView* view) { |
| 58 return [view isKindOfClass:[WKWebView class]] && | 58 return [view isKindOfClass:[WKWebView class]] && |
| 59 [base::mac::ObjCCast<WKWebView>(view).navigationDelegate | 59 [base::mac::ObjCCast<WKWebView>(view).navigationDelegate |
| 60 isKindOfClass:cls]; | 60 isKindOfClass:cls]; |
| 61 }; | 61 }; |
| 62 | 62 |
| 63 DescribeToBlock describe = ^(id<GREYDescription> description) { | 63 DescribeToBlock describe = ^(id<GREYDescription> description) { |
| 64 [description appendText:@"web view with "]; | 64 [description appendText:@"web view with "]; |
| 65 [description appendText:NSStringFromClass(cls)]; | 65 [description appendText:NSStringFromClass(cls)]; |
| 66 [description appendText:@"navigation delegate"]; | 66 [description appendText:@"navigation delegate"]; |
| 67 }; | 67 }; |
| 68 | 68 |
| 69 return [[[GREYElementMatcherBlock alloc] initWithMatchesBlock:matches | 69 return [[[GREYElementMatcherBlock alloc] initWithMatchesBlock:matches |
| 70 descriptionBlock:describe] | 70 descriptionBlock:describe] |
| 71 autorelease]; | 71 autorelease]; |
| 72 } | 72 } |
| 73 | 73 |
| 74 id<GREYMatcher> collectionViewSwitchIsOn(BOOL isOn) { | 74 id<GREYMatcher> CollectionViewSwitchIsOn(BOOL isOn) { |
| 75 MatchesBlock matches = ^BOOL(id element) { | 75 MatchesBlock matches = ^BOOL(id element) { |
| 76 CollectionViewSwitchCell* switchCell = | 76 CollectionViewSwitchCell* switchCell = |
| 77 base::mac::ObjCCastStrict<CollectionViewSwitchCell>(element); | 77 base::mac::ObjCCastStrict<CollectionViewSwitchCell>(element); |
| 78 UISwitch* switchView = switchCell.switchView; | 78 UISwitch* switchView = switchCell.switchView; |
| 79 return (switchView.on && isOn) || (!switchView.on && !isOn); | 79 return (switchView.on && isOn) || (!switchView.on && !isOn); |
| 80 }; | 80 }; |
| 81 DescribeToBlock describe = ^void(id<GREYDescription> description) { | 81 DescribeToBlock describe = ^void(id<GREYDescription> description) { |
| 82 NSString* name = | 82 NSString* name = |
| 83 [NSString stringWithFormat:@"collectionViewSwitchInState(%@)", | 83 [NSString stringWithFormat:@"collectionViewSwitchInState(%@)", |
| 84 isOn ? @"ON" : @"OFF"]; | 84 isOn ? @"ON" : @"OFF"]; |
| 85 [description appendText:name]; | 85 [description appendText:name]; |
| 86 }; | 86 }; |
| 87 return [[[GREYElementMatcherBlock alloc] initWithMatchesBlock:matches | 87 return [[[GREYElementMatcherBlock alloc] initWithMatchesBlock:matches |
| 88 descriptionBlock:describe] | 88 descriptionBlock:describe] |
| 89 autorelease]; | 89 autorelease]; |
| 90 } | 90 } |
| 91 | 91 |
| 92 } // namespace | 92 } // namespace |
| 93 | 93 |
| 94 namespace chrome_test_util { | 94 namespace chrome_test_util { |
| 95 | 95 |
| 96 id<GREYMatcher> buttonWithAccessibilityLabel(NSString* label) { | 96 id<GREYMatcher> ButtonWithAccessibilityLabel(NSString* label) { |
| 97 return grey_allOf(grey_accessibilityLabel(label), | 97 return grey_allOf(grey_accessibilityLabel(label), |
| 98 grey_accessibilityTrait(UIAccessibilityTraitButton), nil); | 98 grey_accessibilityTrait(UIAccessibilityTraitButton), nil); |
| 99 } | 99 } |
| 100 | 100 |
| 101 id<GREYMatcher> buttonWithAccessibilityLabelId(int message_id) { | 101 id<GREYMatcher> ButtonWithAccessibilityLabelId(int message_id) { |
| 102 return buttonWithAccessibilityLabel( | 102 return ButtonWithAccessibilityLabel( |
| 103 l10n_util::GetNSStringWithFixup(message_id)); | 103 l10n_util::GetNSStringWithFixup(message_id)); |
| 104 } | 104 } |
| 105 | 105 |
| 106 id<GREYMatcher> staticTextWithAccessibilityLabel(NSString* label) { | 106 id<GREYMatcher> StaticTextWithAccessibilityLabel(NSString* label) { |
| 107 return grey_allOf(grey_accessibilityLabel(label), | 107 return grey_allOf(grey_accessibilityLabel(label), |
| 108 grey_accessibilityTrait(UIAccessibilityTraitStaticText), | 108 grey_accessibilityTrait(UIAccessibilityTraitStaticText), |
| 109 nil); | 109 nil); |
| 110 } | 110 } |
| 111 | 111 |
| 112 id<GREYMatcher> staticTextWithAccessibilityLabelId(int message_id) { | 112 id<GREYMatcher> StaticTextWithAccessibilityLabelId(int message_id) { |
| 113 return staticTextWithAccessibilityLabel( | 113 return StaticTextWithAccessibilityLabel( |
| 114 l10n_util::GetNSStringWithFixup(message_id)); | 114 l10n_util::GetNSStringWithFixup(message_id)); |
| 115 } | 115 } |
| 116 | 116 |
| 117 id<GREYMatcher> webViewBelongingToWebController() { | 117 id<GREYMatcher> WebViewBelongingToWebController() { |
| 118 return webViewWithNavDelegateOfClass(NSClassFromString(@"CRWWebController")); | 118 return WebViewWithNavDelegateOfClass(NSClassFromString(@"CRWWebController")); |
| 119 } | 119 } |
| 120 | 120 |
| 121 id<GREYMatcher> webViewContainingText(std::string text) { | 121 id<GREYMatcher> WebViewContainingText(std::string text) { |
| 122 return web::webViewContainingText(std::move(text), GetCurrentWebState()); | 122 return web::WebViewContainingText(std::move(text), GetCurrentWebState()); |
| 123 } | 123 } |
| 124 | 124 |
| 125 id<GREYMatcher> webViewNotContainingText(std::string text) { | 125 id<GREYMatcher> WebViewNotContainingText(std::string text) { |
| 126 return web::webViewNotContainingText(std::move(text), GetCurrentWebState()); | 126 return web::WebViewNotContainingText(std::move(text), GetCurrentWebState()); |
| 127 } | 127 } |
| 128 | 128 |
| 129 id<GREYMatcher> staticHtmlViewContainingText(NSString* text) { | 129 id<GREYMatcher> StaticHtmlViewContainingText(NSString* text) { |
| 130 // The WKWebView in a static HTML view isn't part of a webState, but it | 130 // The WKWebView in a static HTML view isn't part of a webState, but it |
| 131 // does have the StaticHtmlViewController as its navigation delegate. | 131 // does have the StaticHtmlViewController as its navigation delegate. |
| 132 MatchesBlock matches = ^BOOL(WKWebView* webView) { | 132 MatchesBlock matches = ^BOOL(WKWebView* webView) { |
| 133 StaticHtmlViewController* html_view_controller = | 133 StaticHtmlViewController* html_view_controller = |
| 134 base::mac::ObjCCast<StaticHtmlViewController>( | 134 base::mac::ObjCCast<StaticHtmlViewController>( |
| 135 webView.navigationDelegate); | 135 webView.navigationDelegate); |
| 136 | 136 |
| 137 __block BOOL did_succeed = NO; | 137 __block BOOL did_succeed = NO; |
| 138 NSDate* deadline = | 138 NSDate* deadline = |
| 139 [NSDate dateWithTimeIntervalSinceNow:testing::kWaitForUIElementTimeout]; | 139 [NSDate dateWithTimeIntervalSinceNow:testing::kWaitForUIElementTimeout]; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 150 } | 150 } |
| 151 return did_succeed; | 151 return did_succeed; |
| 152 }; | 152 }; |
| 153 | 153 |
| 154 DescribeToBlock describe = ^(id<GREYDescription> description) { | 154 DescribeToBlock describe = ^(id<GREYDescription> description) { |
| 155 [description appendText:@"static HTML web view containing "]; | 155 [description appendText:@"static HTML web view containing "]; |
| 156 [description appendText:text]; | 156 [description appendText:text]; |
| 157 }; | 157 }; |
| 158 | 158 |
| 159 return grey_allOf( | 159 return grey_allOf( |
| 160 webViewWithNavDelegateOfClass([StaticHtmlViewController class]), | 160 WebViewWithNavDelegateOfClass([StaticHtmlViewController class]), |
| 161 [[[GREYElementMatcherBlock alloc] initWithMatchesBlock:matches | 161 [[[GREYElementMatcherBlock alloc] initWithMatchesBlock:matches |
| 162 descriptionBlock:describe] | 162 descriptionBlock:describe] |
| 163 autorelease], | 163 autorelease], |
| 164 nil); | 164 nil); |
| 165 } | 165 } |
| 166 | 166 |
| 167 id<GREYMatcher> cancelButton() { | 167 id<GREYMatcher> CancelButton() { |
| 168 return buttonWithAccessibilityLabelId(IDS_CANCEL); | 168 return ButtonWithAccessibilityLabelId(IDS_CANCEL); |
| 169 } | 169 } |
| 170 | 170 |
| 171 id<GREYMatcher> forwardButton() { | 171 id<GREYMatcher> ForwardButton() { |
| 172 return buttonWithAccessibilityLabelId(IDS_ACCNAME_FORWARD); | 172 return ButtonWithAccessibilityLabelId(IDS_ACCNAME_FORWARD); |
| 173 } | 173 } |
| 174 | 174 |
| 175 id<GREYMatcher> backButton() { | 175 id<GREYMatcher> BackButton() { |
| 176 return buttonWithAccessibilityLabelId(IDS_ACCNAME_BACK); | 176 return ButtonWithAccessibilityLabelId(IDS_ACCNAME_BACK); |
| 177 } | 177 } |
| 178 | 178 |
| 179 id<GREYMatcher> reloadButton() { | 179 id<GREYMatcher> ReloadButton() { |
| 180 return buttonWithAccessibilityLabelId(IDS_IOS_ACCNAME_RELOAD); | 180 return ButtonWithAccessibilityLabelId(IDS_IOS_ACCNAME_RELOAD); |
| 181 } | 181 } |
| 182 | 182 |
| 183 id<GREYMatcher> stopButton() { | 183 id<GREYMatcher> StopButton() { |
| 184 return buttonWithAccessibilityLabelId(IDS_IOS_ACCNAME_STOP); | 184 return ButtonWithAccessibilityLabelId(IDS_IOS_ACCNAME_STOP); |
| 185 } | 185 } |
| 186 | 186 |
| 187 id<GREYMatcher> omnibox() { | 187 id<GREYMatcher> Omnibox() { |
| 188 return grey_kindOfClass([OmniboxTextFieldIOS class]); | 188 return grey_kindOfClass([OmniboxTextFieldIOS class]); |
| 189 } | 189 } |
| 190 | 190 |
| 191 id<GREYMatcher> pageSecurityInfoButton() { | 191 id<GREYMatcher> PageSecurityInfoButton() { |
| 192 return grey_accessibilityLabel(@"Page Security Info"); | 192 return grey_accessibilityLabel(@"Page Security Info"); |
| 193 } | 193 } |
| 194 | 194 |
| 195 id<GREYMatcher> omniboxText(std::string text) { | 195 id<GREYMatcher> OmniboxText(std::string text) { |
| 196 return grey_allOf(omnibox(), | 196 return grey_allOf(Omnibox(), |
| 197 hasProperty(@"text", base::SysUTF8ToNSString(text)), nil); | 197 hasProperty(@"text", base::SysUTF8ToNSString(text)), nil); |
| 198 } | 198 } |
| 199 | 199 |
| 200 id<GREYMatcher> toolsMenuButton() { | 200 id<GREYMatcher> ToolsMenuButton() { |
| 201 return grey_allOf(grey_accessibilityID(kToolbarToolsMenuButtonIdentifier), | 201 return grey_allOf(grey_accessibilityID(kToolbarToolsMenuButtonIdentifier), |
| 202 grey_sufficientlyVisible(), nil); | 202 grey_sufficientlyVisible(), nil); |
| 203 } | 203 } |
| 204 | 204 |
| 205 id<GREYMatcher> shareButton() { | 205 id<GREYMatcher> ShareButton() { |
| 206 return buttonWithAccessibilityLabelId(IDS_IOS_TOOLS_MENU_SHARE); | 206 return ButtonWithAccessibilityLabelId(IDS_IOS_TOOLS_MENU_SHARE); |
| 207 } | 207 } |
| 208 | 208 |
| 209 id<GREYMatcher> showTabsButton() { | 209 id<GREYMatcher> ShowTabsButton() { |
| 210 return grey_allOf(grey_accessibilityID(kToolbarStackButtonIdentifier), | 210 return grey_allOf(grey_accessibilityID(kToolbarStackButtonIdentifier), |
| 211 grey_sufficientlyVisible(), nil); | 211 grey_sufficientlyVisible(), nil); |
| 212 } | 212 } |
| 213 | 213 |
| 214 id<GREYMatcher> collectionViewSwitchCell(NSString* accessibilityIdentifier, | 214 id<GREYMatcher> CollectionViewSwitchCell(NSString* accessibilityIdentifier, |
| 215 BOOL isOn) { | 215 BOOL isOn) { |
| 216 return grey_allOf(grey_accessibilityID(accessibilityIdentifier), | 216 return grey_allOf(grey_accessibilityID(accessibilityIdentifier), |
| 217 collectionViewSwitchIsOn(isOn), grey_sufficientlyVisible(), | 217 CollectionViewSwitchIsOn(isOn), grey_sufficientlyVisible(), |
| 218 nil); | 218 nil); |
| 219 } | 219 } |
| 220 | 220 |
| 221 } // namespace chrome_test_util | 221 } // namespace chrome_test_util |
| OLD | NEW |