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

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

Issue 2642193012: Make EarlGrey matchers compliant with Chromium style. (Closed)
Patch Set: build.gn and rebase Created 3 years, 10 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 | « ios/web/shell/test/navigation_egtest.mm ('k') | ios/web/shell/test/pdf_egtest.mm » ('j') | 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 15 matching lines...) Expand all
26 "http://ios/web/shell/test/http_server_files/tall_page.html"; 26 "http://ios/web/shell/test/http_server_files/tall_page.html";
27 const char kLongPage2[] = 27 const char kLongPage2[] =
28 "http://ios/web/shell/test/http_server_files/tall_page.html?2"; 28 "http://ios/web/shell/test/http_server_files/tall_page.html?2";
29 29
30 // Test scroll offsets. 30 // Test scroll offsets.
31 const CGFloat kScrollOffset1 = 20.0f; 31 const CGFloat kScrollOffset1 = 20.0f;
32 const CGFloat kScrollOffset2 = 40.0f; 32 const CGFloat kScrollOffset2 = 40.0f;
33 33
34 // Returns a matcher for asserting that element's content offset matches the 34 // Returns a matcher for asserting that element's content offset matches the
35 // given |offset|. 35 // given |offset|.
36 id<GREYMatcher> contentOffset(CGPoint offset) { 36 id<GREYMatcher> ContentOffset(CGPoint offset) {
37 MatchesBlock matches = ^BOOL(UIScrollView* element) { 37 MatchesBlock matches = ^BOOL(UIScrollView* element) {
38 return CGPointEqualToPoint([element contentOffset], offset); 38 return CGPointEqualToPoint([element contentOffset], offset);
39 }; 39 };
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|. 50 // Waits for the web view scroll view is scrolled to |y_offset|.
51 void WaitForOffset(CGFloat y_offset) { 51 void WaitForOffset(CGFloat y_offset) {
52 CGPoint content_offset = CGPointMake(0.0, y_offset); 52 CGPoint content_offset = CGPointMake(0.0, y_offset);
53 NSString* content_offset_string = NSStringFromCGPoint(content_offset); 53 NSString* content_offset_string = NSStringFromCGPoint(content_offset);
54 NSString* name = 54 NSString* name =
55 [NSString stringWithFormat:@"Wait for scroll view to scroll to %@.", 55 [NSString stringWithFormat:@"Wait for scroll view to scroll to %@.",
56 content_offset_string]; 56 content_offset_string];
57 GREYCondition* condition = [GREYCondition 57 GREYCondition* condition = [GREYCondition
58 conditionWithName:name 58 conditionWithName:name
59 block:^BOOL { 59 block:^BOOL {
60 NSError* error = nil; 60 NSError* error = nil;
61 [[EarlGrey 61 [[EarlGrey
62 selectElementWithMatcher:web::webViewScrollView()] 62 selectElementWithMatcher:web::WebViewScrollView()]
63 assertWithMatcher:contentOffset(content_offset) 63 assertWithMatcher:ContentOffset(content_offset)
64 error:&error]; 64 error:&error];
65 return (error == nil); 65 return (error == nil);
66 }]; 66 }];
67 NSString* error_text = 67 NSString* error_text =
68 [NSString stringWithFormat:@"Scroll view did not scroll to %@", 68 [NSString stringWithFormat:@"Scroll view did not scroll to %@",
69 content_offset_string]; 69 content_offset_string];
70 GREYAssert([condition waitWithTimeout:10], error_text); 70 GREYAssert([condition waitWithTimeout:10], error_text);
71 } 71 }
72 72
73 } // namespace 73 } // namespace
74 74
75 using web::test::HttpServer; 75 using web::test::HttpServer;
76 76
77 // Page state test cases for the web shell. 77 // Page state test cases for the web shell.
78 @interface PageStateTestCase : ShellBaseTestCase 78 @interface PageStateTestCase : ShellBaseTestCase
79 @end 79 @end
80 80
81 @implementation PageStateTestCase 81 @implementation PageStateTestCase
82 82
83 // 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
84 // page via the back/forward buttons. 84 // page via the back/forward buttons.
85 - (void)testScrollPositionRestoring { 85 - (void)testScrollPositionRestoring {
86 web::test::SetUpFileBasedHttpServer(); 86 web::test::SetUpFileBasedHttpServer();
87 87
88 // Load first URL which is a long page. 88 // Load first URL which is a long page.
89 [ShellEarlGrey loadURL:HttpServer::MakeUrl(kLongPage1)]; 89 [ShellEarlGrey loadURL:HttpServer::MakeUrl(kLongPage1)];
90 90
91 // Scroll the first page and verify the offset. 91 // Scroll the first page and verify the offset.
92 [[EarlGrey selectElementWithMatcher:web::webViewScrollView()] 92 [[EarlGrey selectElementWithMatcher:web::WebViewScrollView()]
93 performAction:grey_scrollInDirection(kGREYDirectionDown, kScrollOffset1)]; 93 performAction:grey_scrollInDirection(kGREYDirectionDown, kScrollOffset1)];
94 [[EarlGrey selectElementWithMatcher:web::webViewScrollView()] 94 [[EarlGrey selectElementWithMatcher:web::WebViewScrollView()]
95 assertWithMatcher:contentOffset(CGPointMake(0, kScrollOffset1))]; 95 assertWithMatcher:ContentOffset(CGPointMake(0, kScrollOffset1))];
96 96
97 // Load second URL, which is also a long page. 97 // Load second URL, which is also a long page.
98 [ShellEarlGrey loadURL:HttpServer::MakeUrl(kLongPage2)]; 98 [ShellEarlGrey loadURL:HttpServer::MakeUrl(kLongPage2)];
99 99
100 // Scroll the second page and verify the offset. 100 // Scroll the second page and verify the offset.
101 [[EarlGrey selectElementWithMatcher:web::webViewScrollView()] 101 [[EarlGrey selectElementWithMatcher:web::WebViewScrollView()]
102 performAction:grey_scrollInDirection(kGREYDirectionDown, kScrollOffset2)]; 102 performAction:grey_scrollInDirection(kGREYDirectionDown, kScrollOffset2)];
103 [[EarlGrey selectElementWithMatcher:web::webViewScrollView()] 103 [[EarlGrey selectElementWithMatcher:web::WebViewScrollView()]
104 assertWithMatcher:contentOffset(CGPointMake(0, kScrollOffset2))]; 104 assertWithMatcher:ContentOffset(CGPointMake(0, kScrollOffset2))];
105 105
106 // 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.
107 [[EarlGrey selectElementWithMatcher:web::backButton()] 107 [[EarlGrey selectElementWithMatcher:web::BackButton()]
108 performAction:grey_tap()]; 108 performAction:grey_tap()];
109 WaitForOffset(kScrollOffset1); 109 WaitForOffset(kScrollOffset1);
110 110
111 // 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.
112 [[EarlGrey selectElementWithMatcher:web::forwardButton()] 112 [[EarlGrey selectElementWithMatcher:web::ForwardButton()]
113 performAction:grey_tap()]; 113 performAction:grey_tap()];
114 WaitForOffset(kScrollOffset2); 114 WaitForOffset(kScrollOffset2);
115 } 115 }
116 116
117 @end 117 @end
OLDNEW
« no previous file with comments | « ios/web/shell/test/navigation_egtest.mm ('k') | ios/web/shell/test/pdf_egtest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698