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