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 <CoreGraphics/CoreGraphics.h> | 5 #import <CoreGraphics/CoreGraphics.h> |
| 6 #import <EarlGrey/EarlGrey.h> | 6 #import <EarlGrey/EarlGrey.h> |
| 7 #import <Foundation/Foundation.h> | 7 #import <Foundation/Foundation.h> |
| 8 #import <XCTest/XCTest.h> | 8 #import <XCTest/XCTest.h> |
| 9 | 9 |
| 10 #include "base/ios/ios_util.h" | 10 #include "base/ios/ios_util.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 46 assertWithMatcher:grey_scrollViewContentOffset(offset) | 46 assertWithMatcher:grey_scrollViewContentOffset(offset) |
| 47 error:&error]; | 47 error:&error]; |
| 48 return (error == nil); | 48 return (error == nil); |
| 49 }]; | 49 }]; |
| 50 NSString* error_text = | 50 NSString* error_text = |
| 51 [NSString stringWithFormat:@"Scroll view did not scroll to %@", | 51 [NSString stringWithFormat:@"Scroll view did not scroll to %@", |
| 52 content_offset_string]; | 52 content_offset_string]; |
| 53 GREYAssert([condition waitWithTimeout:10], error_text); | 53 GREYAssert([condition waitWithTimeout:10], error_text); |
| 54 } | 54 } |
| 55 | 55 |
| 56 // Loads the long page at |url|, scrolls to the top, and waits for the offset to | |
| 57 // be {0, 0} before returning. | |
| 58 void LoadLongPageAndScrollToTop(const GURL& url) { | |
| 59 // Load the page and swipe down. | |
| 60 [ShellEarlGrey loadURL:url]; | |
| 61 [[EarlGrey selectElementWithMatcher:web::WebViewScrollView()] | |
| 62 performAction:grey_swipeFastInDirection(kGREYDirectionDown)]; | |
|
baxley
2017/04/06 13:02:39
Can you use grey_scrollToContentEdge instead? grey
Eugene But (OOO till 7-30)
2017/04/06 15:28:46
Why do we need to scroll the page to the top? If t
kkhorimoto
2017/04/06 23:48:10
I've updated to use scrollToContentEdge.
I agree
Eugene But (OOO till 7-30)
2017/04/07 00:45:49
Does this test actually fail on Flaky bots? Should
kkhorimoto
2017/04/12 05:03:28
I've investigated, and it turns out that that's no
| |
| 63 // Waits for the {0, 0} offset. | |
| 64 WaitForOffset(0.0); | |
|
baxley
2017/04/06 13:02:38
This may not be necessary if we do the call to gre
kkhorimoto
2017/04/06 23:48:10
I left it in since at best it will help reduce fla
| |
| 65 } | |
| 66 | |
| 56 } // namespace | 67 } // namespace |
| 57 | 68 |
| 58 using web::test::HttpServer; | 69 using web::test::HttpServer; |
| 59 | 70 |
| 60 // Page state test cases for the web shell. | 71 // Page state test cases for the web shell. |
| 61 @interface PageStateTestCase : WebShellTestCase | 72 @interface PageStateTestCase : WebShellTestCase |
| 62 @end | 73 @end |
| 63 | 74 |
| 64 @implementation PageStateTestCase | 75 @implementation PageStateTestCase |
| 65 | 76 |
| 66 // Tests that page scroll position of a page is restored upon returning to the | 77 // Tests that page scroll position of a page is restored upon returning to the |
| 67 // page via the back/forward buttons. | 78 // page via the back/forward buttons. |
| 68 // TODO(crbug.com/702410): This test flakily fails when it scrolls too far down | 79 - (void)testScrollPositionRestoring { |
| 69 // the page. | |
| 70 - (void)FLAKY_testScrollPositionRestoring { | |
| 71 web::test::SetUpFileBasedHttpServer(); | 80 web::test::SetUpFileBasedHttpServer(); |
| 72 | 81 |
| 73 // Load first URL which is a long page. | 82 // Load first URL which is a long page. |
|
baxley
2017/04/06 13:02:39
Do you want to delete this comment? I think the ne
kkhorimoto
2017/04/06 23:48:10
Done.
| |
| 74 [ShellEarlGrey loadURL:HttpServer::MakeUrl(kLongPage1)]; | 83 LoadLongPageAndScrollToTop(HttpServer::MakeUrl(kLongPage1)); |
| 75 | 84 |
| 76 // Scroll the first page and verify the offset. | 85 // Scroll the first page and verify the offset. |
| 77 [[EarlGrey selectElementWithMatcher:web::WebViewScrollView()] | 86 [[EarlGrey selectElementWithMatcher:web::WebViewScrollView()] |
| 78 performAction:grey_scrollInDirection(kGREYDirectionDown, kOffset1)]; | 87 performAction:grey_scrollInDirection(kGREYDirectionDown, kOffset1)]; |
| 79 [[EarlGrey selectElementWithMatcher:web::WebViewScrollView()] | 88 [[EarlGrey selectElementWithMatcher:web::WebViewScrollView()] |
| 80 assertWithMatcher:grey_scrollViewContentOffset(CGPointMake(0, kOffset1))]; | 89 assertWithMatcher:grey_scrollViewContentOffset(CGPointMake(0, kOffset1))]; |
| 81 | 90 |
| 82 // Load second URL, which is also a long page. | 91 // Load second URL, which is also a long page. |
|
baxley
2017/04/06 13:02:39
Delete comment?
kkhorimoto
2017/04/06 23:48:10
Done.
| |
| 83 [ShellEarlGrey loadURL:HttpServer::MakeUrl(kLongPage2)]; | 92 LoadLongPageAndScrollToTop(HttpServer::MakeUrl(kLongPage2)); |
| 84 | 93 |
| 85 // Scroll the second page and verify the offset. | 94 // Scroll the second page and verify the offset. |
| 86 [[EarlGrey selectElementWithMatcher:web::WebViewScrollView()] | 95 [[EarlGrey selectElementWithMatcher:web::WebViewScrollView()] |
| 87 performAction:grey_scrollInDirection(kGREYDirectionDown, kOffset2)]; | 96 performAction:grey_scrollInDirection(kGREYDirectionDown, kOffset2)]; |
| 88 [[EarlGrey selectElementWithMatcher:web::WebViewScrollView()] | 97 [[EarlGrey selectElementWithMatcher:web::WebViewScrollView()] |
| 89 assertWithMatcher:grey_scrollViewContentOffset(CGPointMake(0, kOffset2))]; | 98 assertWithMatcher:grey_scrollViewContentOffset(CGPointMake(0, kOffset2))]; |
| 90 | 99 |
| 91 // Go back and verify that the first page offset has been restored. | 100 // Go back and verify that the first page offset has been restored. |
| 92 [[EarlGrey selectElementWithMatcher:web::BackButton()] | 101 [[EarlGrey selectElementWithMatcher:web::BackButton()] |
| 93 performAction:grey_tap()]; | 102 performAction:grey_tap()]; |
| 94 WaitForOffset(kOffset1); | 103 WaitForOffset(kOffset1); |
| 95 | 104 |
| 96 // Go forward and verify that the second page offset has been restored. | 105 // Go forward and verify that the second page offset has been restored. |
| 97 [[EarlGrey selectElementWithMatcher:web::ForwardButton()] | 106 [[EarlGrey selectElementWithMatcher:web::ForwardButton()] |
| 98 performAction:grey_tap()]; | 107 performAction:grey_tap()]; |
| 99 WaitForOffset(kOffset2); | 108 WaitForOffset(kOffset2); |
| 100 } | 109 } |
| 101 | 110 |
| 102 @end | 111 @end |
| OLD | NEW |