| 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 12 matching lines...) Expand all Loading... |
| 23 #import "ios/web/public/test/earl_grey/web_view_matchers.h" | 23 #import "ios/web/public/test/earl_grey/web_view_matchers.h" |
| 24 #import "ios/web/public/test/http_server.h" | 24 #import "ios/web/public/test/http_server.h" |
| 25 #import "ios/web/public/test/http_server_util.h" | 25 #import "ios/web/public/test/http_server_util.h" |
| 26 #include "url/gurl.h" | 26 #include "url/gurl.h" |
| 27 | 27 |
| 28 #if !defined(__has_feature) || !__has_feature(objc_arc) | 28 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 29 #error "This file requires ARC support." | 29 #error "This file requires ARC support." |
| 30 #endif | 30 #endif |
| 31 | 31 |
| 32 using chrome_test_util::ButtonWithAccessibilityLabelId; | 32 using chrome_test_util::ButtonWithAccessibilityLabelId; |
| 33 using chrome_test_util::OpenLinkInNewTabButton; |
| 33 | 34 |
| 34 namespace { | 35 namespace { |
| 35 const char kUrlChromiumLogoPage[] = | 36 const char kUrlChromiumLogoPage[] = |
| 36 "http://ios/testing/data/http_server_files/chromium_logo_page.html"; | 37 "http://ios/testing/data/http_server_files/chromium_logo_page.html"; |
| 37 const char kUrlChromiumLogoImg[] = | 38 const char kUrlChromiumLogoImg[] = |
| 38 "http://ios/testing/data/http_server_files/chromium_logo.png"; | 39 "http://ios/testing/data/http_server_files/chromium_logo.png"; |
| 39 const char kUrlInitialPage[] = "http://scenarioContextMenuOpenInNewTab"; | 40 const char kUrlInitialPage[] = "http://scenarioContextMenuOpenInNewTab"; |
| 40 const char kUrlDestinationPage[] = "http://destination"; | 41 const char kUrlDestinationPage[] = "http://destination"; |
| 41 const char kChromiumImageID[] = "chromium_image"; | 42 const char kChromiumImageID[] = "chromium_image"; |
| 42 const char kDestinationLinkID[] = "link"; | 43 const char kDestinationLinkID[] = "link"; |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 | 168 |
| 168 // The initial page contains a link to the destination page. | 169 // The initial page contains a link to the destination page. |
| 169 responses[initialURL] = "<a style='margin-left:50px' href='" + | 170 responses[initialURL] = "<a style='margin-left:50px' href='" + |
| 170 destinationURL.spec() + "' id='link'>link</a>"; | 171 destinationURL.spec() + "' id='link'>link</a>"; |
| 171 responses[destinationURL] = kDestinationHtml; | 172 responses[destinationURL] = kDestinationHtml; |
| 172 | 173 |
| 173 web::test::SetUpSimpleHttpServer(responses); | 174 web::test::SetUpSimpleHttpServer(responses); |
| 174 [ChromeEarlGrey loadURL:initialURL]; | 175 [ChromeEarlGrey loadURL:initialURL]; |
| 175 chrome_test_util::AssertMainTabCount(1U); | 176 chrome_test_util::AssertMainTabCount(1U); |
| 176 | 177 |
| 177 LongPressElementAndTapOnButton(kDestinationLinkID, | 178 LongPressElementAndTapOnButton(kDestinationLinkID, OpenLinkInNewTabButton()); |
| 178 chrome_test_util::OpenLinkInNewTabMenuItem()); | |
| 179 | 179 |
| 180 SelectTabAtIndexInCurrentMode(1U); | 180 SelectTabAtIndexInCurrentMode(1U); |
| 181 | 181 |
| 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 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 210 | 210 |
| 211 // Scroll down on the web view to make the link visible. | 211 // Scroll down on the web view to make the link visible. |
| 212 [[EarlGrey | 212 [[EarlGrey |
| 213 selectElementWithMatcher:WebViewScrollView( | 213 selectElementWithMatcher:WebViewScrollView( |
| 214 chrome_test_util::GetCurrentWebState())] | 214 chrome_test_util::GetCurrentWebState())] |
| 215 performAction:grey_swipeFastInDirection(kGREYDirectionUp)]; | 215 performAction:grey_swipeFastInDirection(kGREYDirectionUp)]; |
| 216 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( | 216 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( |
| 217 kDestinationLinkID)] | 217 kDestinationLinkID)] |
| 218 assertWithMatcher:grey_notNil()]; | 218 assertWithMatcher:grey_notNil()]; |
| 219 | 219 |
| 220 LongPressElementAndTapOnButton(kDestinationLinkID, | 220 LongPressElementAndTapOnButton(kDestinationLinkID, OpenLinkInNewTabButton()); |
| 221 chrome_test_util::OpenLinkInNewTabMenuItem()); | |
| 222 | 221 |
| 223 // Earl Grey cannot preperly synchronize some animations, so adding a | 222 // Earl Grey cannot preperly synchronize some animations, so adding a |
| 224 // WaitUntilCondition to wait for the new tab opening animation to finish | 223 // WaitUntilCondition to wait for the new tab opening animation to finish |
| 225 // and the scroll view to become interactable. | 224 // and the scroll view to become interactable. |
| 226 ConditionBlock condition = ^{ | 225 ConditionBlock condition = ^{ |
| 227 NSError* error = nil; | 226 NSError* error = nil; |
| 228 [[EarlGrey | 227 [[EarlGrey |
| 229 selectElementWithMatcher:WebViewScrollView( | 228 selectElementWithMatcher:WebViewScrollView( |
| 230 chrome_test_util::GetCurrentWebState())] | 229 chrome_test_util::GetCurrentWebState())] |
| 231 assertWithMatcher:grey_interactable() | 230 assertWithMatcher:grey_interactable() |
| (...skipping 15 matching lines...) Expand all Loading... |
| 247 SelectTabAtIndexInCurrentMode(1U); | 246 SelectTabAtIndexInCurrentMode(1U); |
| 248 | 247 |
| 249 // Verify url and tab count. | 248 // Verify url and tab count. |
| 250 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( | 249 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( |
| 251 destinationURL.GetContent())] | 250 destinationURL.GetContent())] |
| 252 assertWithMatcher:grey_notNil()]; | 251 assertWithMatcher:grey_notNil()]; |
| 253 chrome_test_util::AssertMainTabCount(2U); | 252 chrome_test_util::AssertMainTabCount(2U); |
| 254 } | 253 } |
| 255 | 254 |
| 256 @end | 255 @end |
| OLD | NEW |