Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(155)

Side by Side Diff: ios/web/shell/test/page_state_egtest.mm

Issue 2637113004: Wait for scroll offset in testScrollPositionRestoring. (Closed)
Patch Set: fix compile Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 29 matching lines...) Expand all
40 DescribeToBlock describe = ^(id<GREYDescription> description) { 40 DescribeToBlock describe = ^(id<GREYDescription> description) {
41 [description appendText:@"contentOffset"]; 41 [description appendText:@"contentOffset"];
42 }; 42 };
43 return grey_allOf( 43 return grey_allOf(
44 grey_kindOfClass([UIScrollView class]), 44 grey_kindOfClass([UIScrollView class]),
45 [[GREYElementMatcherBlock alloc] initWithMatchesBlock:matches 45 [[GREYElementMatcherBlock alloc] initWithMatchesBlock:matches
46 descriptionBlock:describe], 46 descriptionBlock:describe],
47 nil); 47 nil);
48 } 48 }
49 49
50 // Waits for the web view scroll view is scrolled to |y_offset|.
51 void WaitForOffset(CGFloat y_offset) {
52 CGPoint content_offset = CGPointMake(0.0, y_offset);
53 NSString* content_offset_string = NSStringFromCGPoint(content_offset);
54 NSString* name =
55 [NSString stringWithFormat:@"Wait for scroll view to scroll to %@.",
56 content_offset_string];
57 GREYCondition* condition = [GREYCondition
58 conditionWithName:name
59 block:^BOOL {
60 NSError* error = nil;
61 [[EarlGrey
62 selectElementWithMatcher:web::webViewScrollView()]
63 assertWithMatcher:contentOffset(content_offset)
64 error:&error];
65 return (error == nil);
66 }];
67 NSString* error_text =
68 [NSString stringWithFormat:@"Scroll view did not scroll to %@",
69 content_offset_string];
70 GREYAssert([condition waitWithTimeout:10], error_text);
71 }
72
50 } // namespace 73 } // namespace
51 74
52 using web::test::HttpServer; 75 using web::test::HttpServer;
53 76
54 // Page state test cases for the web shell. 77 // Page state test cases for the web shell.
55 @interface PageStateTestCase : ShellBaseTestCase 78 @interface PageStateTestCase : ShellBaseTestCase
56 @end 79 @end
57 80
58 @implementation PageStateTestCase 81 @implementation PageStateTestCase
59 82
60 // Tests that page scroll position of a page is restored upon returning to the 83 // Tests that page scroll position of a page is restored upon returning to the
61 // page via the back/forward buttons. 84 // page via the back/forward buttons.
62 - (void)testScrollPositionRestoring { 85 - (void)testScrollPositionRestoring {
63 // TODO(crbug.com/670700): Re-enable this test.
64 if (!base::ios::IsRunningOnIOS10OrLater()) {
65 EARL_GREY_TEST_DISABLED(@"Test disabled on pre-iOS 10");
66 }
67 web::test::SetUpFileBasedHttpServer(); 86 web::test::SetUpFileBasedHttpServer();
68 87
69 // Load first URL which is a long page. 88 // Load first URL which is a long page.
70 [ShellEarlGrey loadURL:HttpServer::MakeUrl(kLongPage1)]; 89 [ShellEarlGrey loadURL:HttpServer::MakeUrl(kLongPage1)];
71 90
72 // Scroll the first page and verify the offset. 91 // Scroll the first page and verify the offset.
73 [[EarlGrey selectElementWithMatcher:web::webViewScrollView()] 92 [[EarlGrey selectElementWithMatcher:web::webViewScrollView()]
74 performAction:grey_scrollInDirection(kGREYDirectionDown, kScrollOffset1)]; 93 performAction:grey_scrollInDirection(kGREYDirectionDown, kScrollOffset1)];
75 [[EarlGrey selectElementWithMatcher:web::webViewScrollView()] 94 [[EarlGrey selectElementWithMatcher:web::webViewScrollView()]
76 assertWithMatcher:contentOffset(CGPointMake(0, kScrollOffset1))]; 95 assertWithMatcher:contentOffset(CGPointMake(0, kScrollOffset1))];
77 96
78 // Load second URL, which is also a long page. 97 // Load second URL, which is also a long page.
79 [ShellEarlGrey loadURL:HttpServer::MakeUrl(kLongPage2)]; 98 [ShellEarlGrey loadURL:HttpServer::MakeUrl(kLongPage2)];
80 99
81 // Scroll the second page and verify the offset. 100 // Scroll the second page and verify the offset.
82 [[EarlGrey selectElementWithMatcher:web::webViewScrollView()] 101 [[EarlGrey selectElementWithMatcher:web::webViewScrollView()]
83 performAction:grey_scrollInDirection(kGREYDirectionDown, kScrollOffset2)]; 102 performAction:grey_scrollInDirection(kGREYDirectionDown, kScrollOffset2)];
84 [[EarlGrey selectElementWithMatcher:web::webViewScrollView()] 103 [[EarlGrey selectElementWithMatcher:web::webViewScrollView()]
85 assertWithMatcher:contentOffset(CGPointMake(0, kScrollOffset2))]; 104 assertWithMatcher:contentOffset(CGPointMake(0, kScrollOffset2))];
86 105
87 // Go back and verify that the first page offset has been restored. 106 // Go back and verify that the first page offset has been restored.
88 [[EarlGrey selectElementWithMatcher:web::backButton()] 107 [[EarlGrey selectElementWithMatcher:web::backButton()]
89 performAction:grey_tap()]; 108 performAction:grey_tap()];
90 [[EarlGrey selectElementWithMatcher:web::webViewScrollView()] 109 WaitForOffset(kScrollOffset1);
91 assertWithMatcher:contentOffset(CGPointMake(0, kScrollOffset1))];
92 110
93 // Go forward and verify that the second page offset has been restored. 111 // Go forward and verify that the second page offset has been restored.
94 [[EarlGrey selectElementWithMatcher:web::forwardButton()] 112 [[EarlGrey selectElementWithMatcher:web::forwardButton()]
95 performAction:grey_tap()]; 113 performAction:grey_tap()];
96 [[EarlGrey selectElementWithMatcher:web::webViewScrollView()] 114 WaitForOffset(kScrollOffset2);
97 assertWithMatcher:contentOffset(CGPointMake(0, kScrollOffset2))];
98 } 115 }
99 116
100 @end 117 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698