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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
49 id<GREYMatcher> OpenImageButton() { | 49 id<GREYMatcher> OpenImageButton() { |
50 return ButtonWithAccessibilityLabelId(IDS_IOS_CONTENT_CONTEXT_OPENIMAGE); | 50 return ButtonWithAccessibilityLabelId(IDS_IOS_CONTENT_CONTEXT_OPENIMAGE); |
51 } | 51 } |
52 | 52 |
53 // Matcher for the open image in new tab button in the context menu. | 53 // Matcher for the open image in new tab button in the context menu. |
54 id<GREYMatcher> OpenImageInNewTabButton() { | 54 id<GREYMatcher> OpenImageInNewTabButton() { |
55 return ButtonWithAccessibilityLabelId( | 55 return ButtonWithAccessibilityLabelId( |
56 IDS_IOS_CONTENT_CONTEXT_OPENIMAGENEWTAB); | 56 IDS_IOS_CONTENT_CONTEXT_OPENIMAGENEWTAB); |
57 } | 57 } |
58 | 58 |
59 // Matcher for the open link in new tab button in the context menu. | |
60 // TODO(crbug.com/638674): Clean up code duplication. | |
61 id<GREYMatcher> OpenLinkInNewTabButton() { | |
62 return ButtonWithAccessibilityLabelId(IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWTAB); | |
63 } | |
64 | |
65 // Waits for the context menu item to disappear. TODO(crbug.com/682871): Remove | 59 // Waits for the context menu item to disappear. TODO(crbug.com/682871): Remove |
66 // this once EarlGrey is synchronized with context menu. | 60 // this once EarlGrey is synchronized with context menu. |
67 void WaitForContextMenuItemDisappeared(id<GREYMatcher> contextMenuItemButton) { | 61 void WaitForContextMenuItemDisappeared(id<GREYMatcher> contextMenuItemButton) { |
68 ConditionBlock condition = ^{ | 62 ConditionBlock condition = ^{ |
69 NSError* error = nil; | 63 NSError* error = nil; |
70 [[EarlGrey selectElementWithMatcher:contextMenuItemButton] | 64 [[EarlGrey selectElementWithMatcher:contextMenuItemButton] |
71 assertWithMatcher:grey_nil() | 65 assertWithMatcher:grey_nil() |
72 error:&error]; | 66 error:&error]; |
73 return error == nil; | 67 return error == nil; |
74 }; | 68 }; |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
173 | 167 |
174 // The initial page contains a link to the destination page. | 168 // The initial page contains a link to the destination page. |
175 responses[initialURL] = "<a style='margin-left:50px' href='" + | 169 responses[initialURL] = "<a style='margin-left:50px' href='" + |
176 destinationURL.spec() + "' id='link'>link</a>"; | 170 destinationURL.spec() + "' id='link'>link</a>"; |
177 responses[destinationURL] = kDestinationHtml; | 171 responses[destinationURL] = kDestinationHtml; |
178 | 172 |
179 web::test::SetUpSimpleHttpServer(responses); | 173 web::test::SetUpSimpleHttpServer(responses); |
180 [ChromeEarlGrey loadURL:initialURL]; | 174 [ChromeEarlGrey loadURL:initialURL]; |
181 chrome_test_util::AssertMainTabCount(1U); | 175 chrome_test_util::AssertMainTabCount(1U); |
182 | 176 |
183 LongPressElementAndTapOnButton(kDestinationLinkID, OpenLinkInNewTabButton()); | 177 LongPressElementAndTapOnButton(kDestinationLinkID, |
178 chrome_test_util::OpenLinkInNewTabMenuItem()); | |
Eugene But (OOO till 7-30)
2017/03/06 20:10:04
Optional nit: do you want to add using chrome_test
baxley
2017/03/06 20:53:34
I left it as is, since the using makes it more tha
| |
184 | 179 |
185 SelectTabAtIndexInCurrentMode(1U); | 180 SelectTabAtIndexInCurrentMode(1U); |
186 | 181 |
187 // Verify url and tab count. | 182 // Verify url and tab count. |
188 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( | 183 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( |
189 destinationURL.GetContent())] | 184 destinationURL.GetContent())] |
190 assertWithMatcher:grey_notNil()]; | 185 assertWithMatcher:grey_notNil()]; |
191 chrome_test_util::AssertMainTabCount(2U); | 186 chrome_test_util::AssertMainTabCount(2U); |
192 } | 187 } |
193 | 188 |
(...skipping 21 matching lines...) Expand all Loading... | |
215 | 210 |
216 // Scroll down on the web view to make the link visible. | 211 // Scroll down on the web view to make the link visible. |
217 [[EarlGrey | 212 [[EarlGrey |
218 selectElementWithMatcher:WebViewScrollView( | 213 selectElementWithMatcher:WebViewScrollView( |
219 chrome_test_util::GetCurrentWebState())] | 214 chrome_test_util::GetCurrentWebState())] |
220 performAction:grey_swipeFastInDirection(kGREYDirectionUp)]; | 215 performAction:grey_swipeFastInDirection(kGREYDirectionUp)]; |
221 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( | 216 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( |
222 kDestinationLinkID)] | 217 kDestinationLinkID)] |
223 assertWithMatcher:grey_notNil()]; | 218 assertWithMatcher:grey_notNil()]; |
224 | 219 |
225 LongPressElementAndTapOnButton(kDestinationLinkID, OpenLinkInNewTabButton()); | 220 LongPressElementAndTapOnButton(kDestinationLinkID, |
221 chrome_test_util::OpenLinkInNewTabMenuItem()); | |
226 | 222 |
227 // Earl Grey cannot preperly synchronize some animations, so adding a | 223 // Earl Grey cannot preperly synchronize some animations, so adding a |
228 // WaitUntilCondition to wait for the new tab opening animation to finish | 224 // WaitUntilCondition to wait for the new tab opening animation to finish |
229 // and the scroll view to become interactable. | 225 // and the scroll view to become interactable. |
230 ConditionBlock condition = ^{ | 226 ConditionBlock condition = ^{ |
231 NSError* error = nil; | 227 NSError* error = nil; |
232 [[EarlGrey | 228 [[EarlGrey |
233 selectElementWithMatcher:WebViewScrollView( | 229 selectElementWithMatcher:WebViewScrollView( |
234 chrome_test_util::GetCurrentWebState())] | 230 chrome_test_util::GetCurrentWebState())] |
235 assertWithMatcher:grey_interactable() | 231 assertWithMatcher:grey_interactable() |
(...skipping 15 matching lines...) Expand all Loading... | |
251 SelectTabAtIndexInCurrentMode(1U); | 247 SelectTabAtIndexInCurrentMode(1U); |
252 | 248 |
253 // Verify url and tab count. | 249 // Verify url and tab count. |
254 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( | 250 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( |
255 destinationURL.GetContent())] | 251 destinationURL.GetContent())] |
256 assertWithMatcher:grey_notNil()]; | 252 assertWithMatcher:grey_notNil()]; |
257 chrome_test_util::AssertMainTabCount(2U); | 253 chrome_test_util::AssertMainTabCount(2U); |
258 } | 254 } |
259 | 255 |
260 @end | 256 @end |
OLD | NEW |