| 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 <EarlGrey/EarlGrey.h> | 5 #import <EarlGrey/EarlGrey.h> |
| 6 #import <UIKit/UIKit.h> | 6 #import <UIKit/UIKit.h> |
| 7 #import <XCTest/XCTest.h> | 7 #import <XCTest/XCTest.h> |
| 8 | 8 |
| 9 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
| 10 #include "ios/chrome/browser/ui/ui_util.h" | 10 #include "ios/chrome/browser/ui/ui_util.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 } | 52 } |
| 53 | 53 |
| 54 // Matcher for the open image in new tab button in the context menu. | 54 // Matcher for the open image in new tab button in the context menu. |
| 55 id<GREYMatcher> OpenImageInNewTabButton() { | 55 id<GREYMatcher> OpenImageInNewTabButton() { |
| 56 return ButtonWithAccessibilityLabelId( | 56 return ButtonWithAccessibilityLabelId( |
| 57 IDS_IOS_CONTENT_CONTEXT_OPENIMAGENEWTAB); | 57 IDS_IOS_CONTENT_CONTEXT_OPENIMAGENEWTAB); |
| 58 } | 58 } |
| 59 | 59 |
| 60 // Waits for the context menu item to disappear. TODO(crbug.com/682871): Remove | 60 // Waits for the context menu item to disappear. TODO(crbug.com/682871): Remove |
| 61 // this once EarlGrey is synchronized with context menu. | 61 // this once EarlGrey is synchronized with context menu. |
| 62 void WaitForContextMenuItemDisappeared(id<GREYMatcher> contextMenuItemButton) { | 62 void WaitForContextMenuItemDisappeared( |
| 63 id<GREYMatcher> context_menu_item_button) { |
| 63 ConditionBlock condition = ^{ | 64 ConditionBlock condition = ^{ |
| 64 NSError* error = nil; | 65 NSError* error = nil; |
| 65 [[EarlGrey selectElementWithMatcher:contextMenuItemButton] | 66 [[EarlGrey selectElementWithMatcher:context_menu_item_button] |
| 66 assertWithMatcher:grey_nil() | 67 assertWithMatcher:grey_nil() |
| 67 error:&error]; | 68 error:&error]; |
| 68 return error == nil; | 69 return error == nil; |
| 69 }; | 70 }; |
| 70 GREYAssert(testing::WaitUntilConditionOrTimeout( | 71 GREYAssert(testing::WaitUntilConditionOrTimeout( |
| 71 testing::kWaitForUIElementTimeout, condition), | 72 testing::kWaitForUIElementTimeout, condition), |
| 72 @"Waiting for matcher %@ failed.", contextMenuItemButton); | 73 @"Waiting for matcher %@ failed.", context_menu_item_button); |
| 73 } | 74 } |
| 74 | 75 |
| 75 // Long press on |elementId| to trigger context menu and then tap on | 76 // Long press on |element_id| to trigger context menu and then tap on |
| 76 // |contextMenuItemButton| item. | 77 // |contextMenuItemButton| item. |
| 77 void LongPressElementAndTapOnButton(const char* elementId, | 78 void LongPressElementAndTapOnButton(const char* element_id, |
| 78 id<GREYMatcher> contextMenuItemButton) { | 79 id<GREYMatcher> context_menu_item_button) { |
| 79 id<GREYMatcher> webViewMatcher = | 80 id<GREYMatcher> web_view_matcher = |
| 80 web::WebViewInWebState(chrome_test_util::GetCurrentWebState()); | 81 web::WebViewInWebState(chrome_test_util::GetCurrentWebState()); |
| 81 [[EarlGrey selectElementWithMatcher:webViewMatcher] | 82 [[EarlGrey selectElementWithMatcher:web_view_matcher] |
| 82 performAction:chrome_test_util::longPressElementForContextMenu(elementId, | 83 performAction:chrome_test_util::LongPressElementForContextMenu( |
| 83 true)]; | 84 element_id, true /* menu should appear */)]; |
| 84 | 85 |
| 85 [[EarlGrey selectElementWithMatcher:contextMenuItemButton] | 86 [[EarlGrey selectElementWithMatcher:context_menu_item_button] |
| 86 assertWithMatcher:grey_notNil()]; | 87 assertWithMatcher:grey_notNil()]; |
| 87 [[EarlGrey selectElementWithMatcher:contextMenuItemButton] | 88 [[EarlGrey selectElementWithMatcher:context_menu_item_button] |
| 88 performAction:grey_tap()]; | 89 performAction:grey_tap()]; |
| 89 WaitForContextMenuItemDisappeared(contextMenuItemButton); | 90 WaitForContextMenuItemDisappeared(context_menu_item_button); |
| 90 } | 91 } |
| 91 | 92 |
| 92 // A simple wrapper that sleeps for 1s to wait for the animation, triggered from | 93 // A simple wrapper that sleeps for 1s to wait for the animation, triggered from |
| 93 // opening a new tab through context menu, to finish before selecting tab. | 94 // opening a new tab through context menu, to finish before selecting tab. |
| 94 // TODO(crbug.com/643792): Remove this function when the bug is fixed. | 95 // TODO(crbug.com/643792): Remove this function when the bug is fixed. |
| 95 void SelectTabAtIndexInCurrentMode(NSUInteger index) { | 96 void SelectTabAtIndexInCurrentMode(NSUInteger index) { |
| 96 // Delay for 1 second. | 97 // Delay for 1 second. |
| 97 GREYCondition* myCondition = [GREYCondition conditionWithName:@"delay" | 98 GREYCondition* myCondition = [GREYCondition conditionWithName:@"delay" |
| 98 block:^BOOL { | 99 block:^BOOL { |
| 99 return NO; | 100 return NO; |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 SelectTabAtIndexInCurrentMode(1U); | 257 SelectTabAtIndexInCurrentMode(1U); |
| 257 | 258 |
| 258 // Verify url and tab count. | 259 // Verify url and tab count. |
| 259 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( | 260 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( |
| 260 destinationURL.GetContent())] | 261 destinationURL.GetContent())] |
| 261 assertWithMatcher:grey_notNil()]; | 262 assertWithMatcher:grey_notNil()]; |
| 262 chrome_test_util::AssertMainTabCount(2U); | 263 chrome_test_util::AssertMainTabCount(2U); |
| 263 } | 264 } |
| 264 | 265 |
| 265 @end | 266 @end |
| OLD | NEW |