| 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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 // Verify url and tab count. | 182 // Verify url and tab count. |
| 183 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( | 183 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( |
| 184 destinationURL.GetContent())] | 184 destinationURL.GetContent())] |
| 185 assertWithMatcher:grey_notNil()]; | 185 assertWithMatcher:grey_notNil()]; |
| 186 chrome_test_util::AssertMainTabCount(2U); | 186 chrome_test_util::AssertMainTabCount(2U); |
| 187 } | 187 } |
| 188 | 188 |
| 189 // Tests "Open in New Tab" on context menu on a link that requires scrolling | 189 // Tests "Open in New Tab" on context menu on a link that requires scrolling |
| 190 // on the page to verify that context menu can be properly triggered in the | 190 // on the page to verify that context menu can be properly triggered in the |
| 191 // current screen view. | 191 // current screen view. |
| 192 // TODO(crbug.com/701104): This test is flaky because sometimes it doesn't | 192 - (void)testContextMenuOpenInNewTabFromTallPage { |
| 193 // scroll down far enough for the link to be visible. | |
| 194 - (void)FLAKY_testContextMenuOpenInNewTabFromTallPage { | |
| 195 // Set up test simple http server. | 193 // Set up test simple http server. |
| 196 std::map<GURL, std::string> responses; | 194 std::map<GURL, std::string> responses; |
| 197 GURL initialURL = | 195 GURL initialURL = |
| 198 web::test::HttpServer::MakeUrl("http://scenarioContextMenuOpenInNewTab"); | 196 web::test::HttpServer::MakeUrl("http://scenarioContextMenuOpenInNewTab"); |
| 199 GURL destinationURL = web::test::HttpServer::MakeUrl("http://destination"); | 197 GURL destinationURL = web::test::HttpServer::MakeUrl("http://destination"); |
| 200 | 198 |
| 201 // The initial page contains a link to the destination page that is below a | 199 // The initial page contains a link to the destination page that is below a |
| 202 // really tall div so that scrolling is required. | 200 // really tall div so that scrolling is required. |
| 203 responses[initialURL] = | 201 responses[initialURL] = |
| 204 "<div style='height:4000px'></div>" | 202 "<div style='height:4000px'></div>" |
| 205 "<a style='margin-left:50px' href='" + | 203 "<a style='margin-left:50px' href='" + |
| 206 destinationURL.spec() + "' id='link'>link</a>"; | 204 destinationURL.spec() + "' id='link'>link</a>"; |
| 207 responses[destinationURL] = kDestinationHtml; | 205 responses[destinationURL] = kDestinationHtml; |
| 208 | 206 |
| 209 web::test::SetUpSimpleHttpServer(responses); | 207 web::test::SetUpSimpleHttpServer(responses); |
| 210 [ChromeEarlGrey loadURL:initialURL]; | 208 [ChromeEarlGrey loadURL:initialURL]; |
| 211 chrome_test_util::AssertMainTabCount(1U); | 209 chrome_test_util::AssertMainTabCount(1U); |
| 212 | 210 |
| 213 // Scroll down on the web view to make the link visible. | 211 // Scroll down on the web view to make the link visible. |
| 212 // grey_swipeFastInDirecton will quickly scroll towards the bottom, and then |
| 213 // grey_scrollToContentEdge guarantees the content edge is reached. Two |
| 214 // methods are used because the first one is much faster, but doesn't |
| 215 // guarantee the link becomes visible. |
| 216 // TODO(crbug.com/702272): Try to replace this with one EarlGrey method call. |
| 214 [[EarlGrey | 217 [[EarlGrey |
| 215 selectElementWithMatcher:WebViewScrollView( | 218 selectElementWithMatcher:WebViewScrollView( |
| 216 chrome_test_util::GetCurrentWebState())] | 219 chrome_test_util::GetCurrentWebState())] |
| 217 performAction:grey_swipeFastInDirection(kGREYDirectionUp)]; | 220 performAction:grey_swipeFastInDirection(kGREYDirectionUp)]; |
| 221 [[EarlGrey |
| 222 selectElementWithMatcher:WebViewScrollView( |
| 223 chrome_test_util::GetCurrentWebState())] |
| 224 performAction:grey_scrollToContentEdge(kGREYContentEdgeBottom)]; |
| 225 |
| 218 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( | 226 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( |
| 219 kDestinationLinkID)] | 227 kDestinationLinkID)] |
| 220 assertWithMatcher:grey_notNil()]; | 228 assertWithMatcher:grey_notNil()]; |
| 221 | 229 |
| 222 LongPressElementAndTapOnButton(kDestinationLinkID, OpenLinkInNewTabButton()); | 230 LongPressElementAndTapOnButton(kDestinationLinkID, OpenLinkInNewTabButton()); |
| 223 | 231 |
| 224 // Earl Grey cannot preperly synchronize some animations, so adding a | 232 // Earl Grey cannot preperly synchronize some animations, so adding a |
| 225 // WaitUntilCondition to wait for the new tab opening animation to finish | 233 // WaitUntilCondition to wait for the new tab opening animation to finish |
| 226 // and the scroll view to become interactable. | 234 // and the scroll view to become interactable. |
| 227 ConditionBlock condition = ^{ | 235 ConditionBlock condition = ^{ |
| (...skipping 20 matching lines...) Expand all Loading... |
| 248 SelectTabAtIndexInCurrentMode(1U); | 256 SelectTabAtIndexInCurrentMode(1U); |
| 249 | 257 |
| 250 // Verify url and tab count. | 258 // Verify url and tab count. |
| 251 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( | 259 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( |
| 252 destinationURL.GetContent())] | 260 destinationURL.GetContent())] |
| 253 assertWithMatcher:grey_notNil()]; | 261 assertWithMatcher:grey_notNil()]; |
| 254 chrome_test_util::AssertMainTabCount(2U); | 262 chrome_test_util::AssertMainTabCount(2U); |
| 255 } | 263 } |
| 256 | 264 |
| 257 @end | 265 @end |
| OLD | NEW |