Chromium Code Reviews| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 50 id<GREYMatcher> openImageInNewTabButton() { | 50 id<GREYMatcher> openImageInNewTabButton() { |
| 51 return buttonWithAccessibilityLabelId( | 51 return buttonWithAccessibilityLabelId( |
| 52 IDS_IOS_CONTENT_CONTEXT_OPENIMAGENEWTAB); | 52 IDS_IOS_CONTENT_CONTEXT_OPENIMAGENEWTAB); |
| 53 } | 53 } |
| 54 | 54 |
| 55 // Matcher for the open link in new tab button in the context menu. | 55 // Matcher for the open link in new tab button in the context menu. |
| 56 id<GREYMatcher> openLinkInNewTabButton() { | 56 id<GREYMatcher> openLinkInNewTabButton() { |
| 57 return buttonWithAccessibilityLabelId(IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWTAB); | 57 return buttonWithAccessibilityLabelId(IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWTAB); |
| 58 } | 58 } |
| 59 | 59 |
| 60 // Wait until |matcher| is nil. | |
| 61 void WaitForMatcherBecomesNil(id<GREYMatcher> matcher) { | |
|
baxley
2017/01/19 22:27:40
Can we call it "WaitForMatcher"? I think becoming
liaoyuke
2017/01/19 22:47:44
Acknowledged.
| |
| 62 ConditionBlock condition = ^{ | |
| 63 NSError* error = nil; | |
| 64 [[EarlGrey selectElementWithMatcher:matcher] assertWithMatcher:grey_nil() | |
| 65 error:&error]; | |
| 66 return error == nil; | |
| 67 }; | |
| 68 GREYAssert( | |
| 69 testing::WaitUntilConditionOrTimeout(testing::kWaitForUIElementTimeout, | |
| 70 condition), | |
| 71 [NSString stringWithFormat:@"Waiting for matcher %@ failed.", matcher]); | |
| 72 } | |
| 73 | |
| 60 // Long press on |elementId| to trigger context menu and then tap on | 74 // Long press on |elementId| to trigger context menu and then tap on |
| 61 // |contextMenuItemButton| item. | 75 // |contextMenuItemButton| item. |
| 62 void LongPressElementAndTapOnButton(const char* elementId, | 76 void LongPressElementAndTapOnButton(const char* elementId, |
| 63 id<GREYMatcher> contextMenuItemButton) { | 77 id<GREYMatcher> contextMenuItemButton) { |
| 64 [[EarlGrey selectElementWithMatcher:chrome_test_util:: | 78 [[EarlGrey selectElementWithMatcher:chrome_test_util:: |
| 65 webViewBelongingToWebController()] | 79 webViewBelongingToWebController()] |
| 66 performAction:chrome_test_util::longPressElementForContextMenu(elementId, | 80 performAction:chrome_test_util::longPressElementForContextMenu(elementId, |
| 67 true)]; | 81 true)]; |
| 68 | 82 |
| 69 [[EarlGrey selectElementWithMatcher:contextMenuItemButton] | 83 [[EarlGrey selectElementWithMatcher:contextMenuItemButton] |
| 70 assertWithMatcher:grey_notNil()]; | 84 assertWithMatcher:grey_notNil()]; |
| 71 [[EarlGrey selectElementWithMatcher:contextMenuItemButton] | 85 [[EarlGrey selectElementWithMatcher:contextMenuItemButton] |
| 72 performAction:grey_tap()]; | 86 performAction:grey_tap()]; |
| 73 [[EarlGrey selectElementWithMatcher:contextMenuItemButton] | 87 |
| 74 assertWithMatcher:grey_nil()]; | 88 // Earl Grey cannot preperly synchronize with WKWebView, so adding a |
| 89 // WaitUntilCondition to wait for the context menu to disappear. | |
| 90 WaitForMatcherBecomesNil(contextMenuItemButton); | |
|
baxley
2017/01/19 22:27:40
Were you able to verify that this fixes the proble
liaoyuke
2017/01/19 22:47:44
Speculative. I'll keep an eye on it and once it fa
| |
| 75 } | 91 } |
| 76 | 92 |
| 77 // 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 |
| 78 // 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. |
| 79 // 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. |
| 80 void SelectTabAtIndexInCurrentMode(NSUInteger index) { | 96 void SelectTabAtIndexInCurrentMode(NSUInteger index) { |
| 81 // Delay for 1 second. | 97 // Delay for 1 second. |
| 82 GREYCondition* myCondition = [GREYCondition conditionWithName:@"delay" | 98 GREYCondition* myCondition = [GREYCondition conditionWithName:@"delay" |
| 83 block:^BOOL { | 99 block:^BOOL { |
| 84 return NO; | 100 return NO; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 167 // Verify url and tab count. | 183 // Verify url and tab count. |
| 168 [[EarlGrey selectElementWithMatcher:chrome_test_util::omniboxText( | 184 [[EarlGrey selectElementWithMatcher:chrome_test_util::omniboxText( |
| 169 destinationURL.GetContent())] | 185 destinationURL.GetContent())] |
| 170 assertWithMatcher:grey_notNil()]; | 186 assertWithMatcher:grey_notNil()]; |
| 171 chrome_test_util::AssertMainTabCount(2U); | 187 chrome_test_util::AssertMainTabCount(2U); |
| 172 } | 188 } |
| 173 | 189 |
| 174 // Tests "Open in New Tab" on context menu on a link that requires scrolling | 190 // Tests "Open in New Tab" on context menu on a link that requires scrolling |
| 175 // on the page to verify that context menu can be properly triggered in the | 191 // on the page to verify that context menu can be properly triggered in the |
| 176 // current screen view. | 192 // current screen view. |
| 177 // TODO(crbug.com/681130): Re-enable this test on device. | 193 - (void)testContextMenuOpenInNewTabFromTallPage { |
|
baxley
2017/01/19 22:27:40
Did you have to modify anything to fix this method
liaoyuke
2017/01/19 22:47:44
Acknowledged.
| |
| 178 #if TARGET_IPHONE_SIMULATOR | |
| 179 #define MAYBE_testContextMenuOpenInNewTabFromTallPage \ | |
| 180 testContextMenuOpenInNewTabFromTallPage | |
| 181 #else | |
| 182 #define MAYBE_testContextMenuOpenInNewTabFromTallPage \ | |
| 183 FLAKY_testContextMenuOpenInNewTabFromTallPage | |
| 184 #endif | |
| 185 - (void)MAYBE_testContextMenuOpenInNewTabFromTallPage { | |
| 186 // Set up test simple http server. | 194 // Set up test simple http server. |
| 187 std::map<GURL, std::string> responses; | 195 std::map<GURL, std::string> responses; |
| 188 GURL initialURL = | 196 GURL initialURL = |
| 189 web::test::HttpServer::MakeUrl("http://scenarioContextMenuOpenInNewTab"); | 197 web::test::HttpServer::MakeUrl("http://scenarioContextMenuOpenInNewTab"); |
| 190 GURL destinationURL = web::test::HttpServer::MakeUrl("http://destination"); | 198 GURL destinationURL = web::test::HttpServer::MakeUrl("http://destination"); |
| 191 | 199 |
| 192 // The initial page contains a link to the destination page that is below a | 200 // The initial page contains a link to the destination page that is below a |
| 193 // really tall div so that scrolling is required. | 201 // really tall div so that scrolling is required. |
| 194 responses[initialURL] = | 202 responses[initialURL] = |
| 195 "<div style='height:4000px'></div>" | 203 "<div style='height:4000px'></div>" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 239 SelectTabAtIndexInCurrentMode(1U); | 247 SelectTabAtIndexInCurrentMode(1U); |
| 240 | 248 |
| 241 // Verify url and tab count. | 249 // Verify url and tab count. |
| 242 [[EarlGrey selectElementWithMatcher:chrome_test_util::omniboxText( | 250 [[EarlGrey selectElementWithMatcher:chrome_test_util::omniboxText( |
| 243 destinationURL.GetContent())] | 251 destinationURL.GetContent())] |
| 244 assertWithMatcher:grey_notNil()]; | 252 assertWithMatcher:grey_notNil()]; |
| 245 chrome_test_util::AssertMainTabCount(2U); | 253 chrome_test_util::AssertMainTabCount(2U); |
| 246 } | 254 } |
| 247 | 255 |
| 248 @end | 256 @end |
| OLD | NEW |