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_earl_grey_ui.h" | 5 #import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h" |
| 6 | 6 |
| 7 #import "ios/chrome/browser/ui/settings/clear_browsing_data_collection_view_cont roller.h" | |
| 8 #import "ios/chrome/browser/ui/settings/privacy_collection_view_controller.h" | |
| 9 #import "ios/chrome/browser/ui/settings/settings_collection_view_controller.h" | |
| 7 #import "ios/chrome/browser/ui/tools_menu/tools_menu_constants.h" | 10 #import "ios/chrome/browser/ui/tools_menu/tools_menu_constants.h" |
| 8 #import "ios/chrome/browser/ui/tools_menu/tools_popup_controller.h" | 11 #import "ios/chrome/browser/ui/tools_menu/tools_popup_controller.h" |
| 9 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 12 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
| 10 #import "ios/chrome/test/app/chrome_test_util.h" | 13 #import "ios/chrome/test/app/chrome_test_util.h" |
| 11 #include "ios/chrome/test/app/navigation_test_util.h" | 14 #include "ios/chrome/test/app/navigation_test_util.h" |
| 12 #import "ios/chrome/test/earl_grey/chrome_matchers.h" | 15 #import "ios/chrome/test/earl_grey/chrome_matchers.h" |
| 13 #import "ios/testing/wait_util.h" | 16 #import "ios/testing/wait_util.h" |
| 14 #import "ios/web/public/test/earl_grey/js_test_util.h" | 17 #import "ios/web/public/test/earl_grey/js_test_util.h" |
| 15 #import "ios/web/public/test/earl_grey/web_view_matchers.h" | 18 #import "ios/web/public/test/earl_grey/web_view_matchers.h" |
| 16 | 19 |
| 17 #if !defined(__has_feature) || !__has_feature(objc_arc) | 20 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 18 #error "This file requires ARC support." | 21 #error "This file requires ARC support." |
| 19 #endif | 22 #endif |
| 20 | 23 |
| 24 using chrome_test_util::ButtonWithAccessibilityLabel; | |
| 21 using testing::WaitUntilConditionOrTimeout; | 25 using testing::WaitUntilConditionOrTimeout; |
| 22 using testing::kWaitForPageLoadTimeout; | 26 using testing::kWaitForPageLoadTimeout; |
| 23 | 27 |
| 28 namespace { | |
| 29 | |
| 30 // Returns a GREYAction to scroll down (swipe up) for a reasonably small amount. | |
| 31 id<GREYAction> ScrollDown() { | |
| 32 // 150 is a reasonable value to ensure all menu items are seen, without too | |
| 33 // much delay. With a larger value, some menu items could be skipped while | |
| 34 // searching. A smaller value increses the area that is searched, but slows | |
| 35 // down the scroll. | |
| 36 CGFloat const kMenuScrollDisplacement = 150; | |
| 37 return grey_scrollInDirection(kGREYDirectionDown, kMenuScrollDisplacement); | |
| 38 } | |
| 39 } // namespace | |
| 40 | |
| 24 @implementation ChromeEarlGreyUI | 41 @implementation ChromeEarlGreyUI |
| 25 | 42 |
| 26 + (void)openToolsMenu { | 43 + (void)openToolsMenu { |
| 27 // TODO(crbug.com/685570): Fix the tap instead of adding a delay. | 44 // TODO(crbug.com/685570): Fix the tap instead of adding a delay. |
| 28 GREYCondition* myCondition = [GREYCondition | 45 GREYCondition* myCondition = [GREYCondition |
| 29 conditionWithName:@"Delay to ensure the toolbar menu can be opened" | 46 conditionWithName:@"Delay to ensure the toolbar menu can be opened" |
| 30 block:^BOOL { | 47 block:^BOOL { |
| 31 return NO; | 48 return NO; |
| 32 }]; | 49 }]; |
| 33 [myCondition waitWithTimeout:0.5]; | 50 [myCondition waitWithTimeout:0.5]; |
| 34 | 51 |
| 35 // TODO(crbug.com/639524): Add logic to ensure the app is in the correct | 52 // TODO(crbug.com/639524): Add logic to ensure the app is in the correct |
| 36 // state, for example DCHECK if no tabs are displayed. | 53 // state, for example DCHECK if no tabs are displayed. |
| 37 [[[EarlGrey | 54 [[[EarlGrey |
| 38 selectElementWithMatcher:grey_allOf(chrome_test_util::ToolsMenuButton(), | 55 selectElementWithMatcher:grey_allOf(chrome_test_util::ToolsMenuButton(), |
| 39 grey_sufficientlyVisible(), nil)] | 56 grey_sufficientlyVisible(), nil)] |
| 40 usingSearchAction:grey_swipeSlowInDirection(kGREYDirectionDown) | 57 usingSearchAction:grey_swipeSlowInDirection(kGREYDirectionDown) |
| 41 onElementWithMatcher:web::WebViewScrollView( | 58 onElementWithMatcher:web::WebViewScrollView( |
| 42 chrome_test_util::GetCurrentWebState())] | 59 chrome_test_util::GetCurrentWebState())] |
| 43 performAction:grey_tap()]; | 60 performAction:grey_tap()]; |
| 44 // TODO(crbug.com/639517): Add webViewScrollView matcher so we don't have | 61 // TODO(crbug.com/639517): Add webViewScrollView matcher so we don't have |
| 45 // to always find it. | 62 // to always find it. |
| 46 } | 63 } |
| 47 | 64 |
| 48 + (void)openSettingsMenu { | 65 + (void)openSettingsMenu { |
| 49 [ChromeEarlGreyUI openToolsMenu]; | 66 [ChromeEarlGreyUI openToolsMenu]; |
| 50 id<GREYMatcher> toolsMenuTableViewMatcher = | 67 id<GREYMatcher> interactableSettingsButton = grey_allOf( |
|
Eugene But (OOO till 7-30)
2017/05/09 00:15:04
nit: Do you want to make a function for this match
baxley
2017/05/09 18:39:19
I created a function for SettingsButton, but not t
| |
| 51 grey_accessibilityID(kToolsMenuTableViewId); | 68 grey_accessibilityID(kToolsMenuSettingsId), grey_interactable(), nil); |
| 52 [[[EarlGrey | 69 [[[EarlGrey selectElementWithMatcher:interactableSettingsButton] |
| 53 selectElementWithMatcher:grey_accessibilityID(kToolsMenuSettingsId)] | 70 usingSearchAction:ScrollDown() |
| 54 usingSearchAction:grey_scrollToContentEdge(kGREYContentEdgeBottom) | 71 onElementWithMatcher:grey_accessibilityID(kToolsMenuTableViewId)] |
| 55 onElementWithMatcher:toolsMenuTableViewMatcher] performAction:grey_tap()]; | 72 performAction:grey_tap()]; |
| 73 } | |
| 74 | |
| 75 + (void)tapButtonInSettingsMenu:(id<GREYMatcher>)buttonMatcher { | |
| 76 id<GREYMatcher> interactableButtonMatcher = | |
| 77 grey_allOf(buttonMatcher, grey_interactable(), nil); | |
| 78 [[[EarlGrey selectElementWithMatcher:interactableButtonMatcher] | |
| 79 usingSearchAction:ScrollDown() | |
| 80 onElementWithMatcher:grey_accessibilityID(kSettingsCollectionViewId)] | |
| 81 performAction:grey_tap()]; | |
| 82 } | |
| 83 | |
| 84 + (void)tapButtonInClearBrowsingDataMenu:(id<GREYMatcher>)buttonMatcher { | |
| 85 id<GREYMatcher> clearBrowsingDataViewMatcher = | |
|
Eugene But (OOO till 7-30)
2017/05/09 00:15:03
ditto
baxley
2017/05/09 18:39:19
Done.
| |
| 86 grey_accessibilityID(kClearBrowsingDataCollectionViewId); | |
| 87 id<GREYMatcher> interactableButtonMatcher = | |
| 88 grey_allOf(buttonMatcher, grey_interactable(), nil); | |
| 89 [[[EarlGrey selectElementWithMatcher:interactableButtonMatcher] | |
| 90 usingSearchAction:ScrollDown() | |
| 91 onElementWithMatcher:clearBrowsingDataViewMatcher] | |
| 92 performAction:grey_tap()]; | |
| 93 } | |
| 94 | |
| 95 + (void)tapButtonInPrivacyMenu:(id<GREYMatcher>)buttonMatcher { | |
| 96 id<GREYMatcher> interactableButtonMatcher = | |
| 97 grey_allOf(buttonMatcher, grey_interactable(), nil); | |
| 98 [[[EarlGrey selectElementWithMatcher:interactableButtonMatcher] | |
| 99 usingSearchAction:ScrollDown() | |
| 100 onElementWithMatcher:grey_accessibilityID(kPrivacyCollectionViewId)] | |
| 101 performAction:grey_tap()]; | |
| 56 } | 102 } |
| 57 | 103 |
| 58 + (void)openNewTab { | 104 + (void)openNewTab { |
| 59 [ChromeEarlGreyUI openToolsMenu]; | 105 [ChromeEarlGreyUI openToolsMenu]; |
| 60 id<GREYMatcher> newTabButtonMatcher = | 106 id<GREYMatcher> newTabButtonMatcher = |
| 61 grey_accessibilityID(kToolsMenuNewTabId); | 107 grey_accessibilityID(kToolsMenuNewTabId); |
| 62 [[EarlGrey selectElementWithMatcher:newTabButtonMatcher] | 108 [[EarlGrey selectElementWithMatcher:newTabButtonMatcher] |
| 63 performAction:grey_tap()]; | 109 performAction:grey_tap()]; |
| 64 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; | 110 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; |
| 65 } | 111 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 101 return error == nil; | 147 return error == nil; |
| 102 }; | 148 }; |
| 103 NSString* errorMessage = | 149 NSString* errorMessage = |
| 104 isVisible ? @"Toolbar was not visible" : @"Toolbar was visible"; | 150 isVisible ? @"Toolbar was not visible" : @"Toolbar was visible"; |
| 105 GREYAssert(testing::WaitUntilConditionOrTimeout( | 151 GREYAssert(testing::WaitUntilConditionOrTimeout( |
| 106 kWaitForToolbarAnimationTimeout, condition), | 152 kWaitForToolbarAnimationTimeout, condition), |
| 107 errorMessage); | 153 errorMessage); |
| 108 } | 154 } |
| 109 | 155 |
| 110 @end | 156 @end |
| OLD | NEW |