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

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

Issue 2167533002: [ios] EarlGrey test for scroll position restoration. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed review comment Created 4 years, 5 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/http_server_files/tall_page.html ('k') | 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #import <CoreGraphics/CoreGraphics.h>
6 #import <EarlGrey/EarlGrey.h>
7 #import <Foundation/Foundation.h>
8 #import <XCTest/XCTest.h>
9
10 #import "ios/web/public/test/http_server.h"
11 #include "ios/web/public/test/http_server_util.h"
12 #include "ios/web/shell/test/app/navigation_test_util.h"
13 #import "ios/web/shell/test/earl_grey/shell_matchers.h"
14
15 #if !defined(__has_feature) || !__has_feature(objc_arc)
16 #error "This file requires ARC support."
17 #endif
18
19 namespace {
20
21 // URLs for test pages.
22 const char kLongPage1[] =
23 "http://ios/web/shell/test/http_server_files/tall_page.html";
24 const char kLongPage2[] =
25 "http://ios/web/shell/test/http_server_files/tall_page.html?2";
26
27 // Test scroll offsets.
28 const CGFloat kScrollOffset1 = 20.0f;
29 const CGFloat kScrollOffset2 = 40.0f;
30
31 // Returns a matcher for asserting that element's content offset matches the
32 // given |offset|.
33 id<GREYMatcher> contentOffset(CGPoint offset) {
34 MatchesBlock matches = ^BOOL(UIScrollView* element) {
35 return CGPointEqualToPoint([element contentOffset], offset);
36 };
37 DescribeToBlock describe = ^(id<GREYDescription> description) {
38 [description appendText:@"contentOffset"];
39 };
40 return grey_allOf(
41 grey_kindOfClass([UIScrollView class]),
42 [[GREYElementMatcherBlock alloc] initWithMatchesBlock:matches
43 descriptionBlock:describe],
44 nil);
45 }
46
47 } // namespace
48
49 using web::shell_test_util::LoadUrl;
50 using web::test::HttpServer;
51 using web::webViewContainingText;
52
53 // Page state test cases for the web shell.
54 @interface CRWWebShellPageStateTest : XCTestCase
55 @end
56
57 @implementation CRWWebShellPageStateTest
58
59 // Set up called once for the class.
60 + (void)setUp {
61 [super setUp];
62 [[EarlGrey selectElementWithMatcher:webViewContainingText("Chromium")]
63 assertWithMatcher:grey_notNil()];
64 HttpServer::GetSharedInstance().StartOrDie();
65 }
66
67 // Tear down called once for the class.
68 + (void)tearDown {
69 [super tearDown];
70 HttpServer::GetSharedInstance().Stop();
71 }
72
73 // Tear down called after each test.
74 - (void)tearDown {
75 [super tearDown];
76 HttpServer::GetSharedInstance().RemoveAllResponseProviders();
77 }
78
79 // Tests that page scroll position of a page is restored upon returning to the
80 // page via the back/forward buttons.
81 - (void)testScrollPositionRestoring {
82 web::test::SetUpFileBasedHttpServer();
83
84 // Load first URL which is a long page.
85 LoadUrl(HttpServer::MakeUrl(kLongPage1));
86 // TODO(crbug.com/629116): Remove this once |LoadUrl| waits for the load
87 // completion.
88 [[EarlGrey selectElementWithMatcher:webViewContainingText("List of numbers")]
89 assertWithMatcher:grey_notNil()];
90
91 // Scroll the first page and verify the offset.
92 [[EarlGrey selectElementWithMatcher:web::webViewScrollView()]
93 performAction:grey_scrollInDirection(kGREYDirectionDown, kScrollOffset1)];
94 [[EarlGrey selectElementWithMatcher:web::webViewScrollView()]
95 assertWithMatcher:contentOffset(CGPointMake(0, kScrollOffset1))];
96
97 // Load second URL, which is also a long page.
98 GURL URL2 = HttpServer::MakeUrl(kLongPage2);
99 LoadUrl(URL2);
100 // TODO(crbug.com/629116): Remove these once |LoadUrl| waits for the load
101 // completion.
102 [[EarlGrey selectElementWithMatcher:web::addressFieldText(URL2.spec())]
103 assertWithMatcher:grey_notNil()];
104 [[EarlGrey selectElementWithMatcher:webViewContainingText("List of numbers")]
105 assertWithMatcher:grey_notNil()];
106
107 // Scroll the second page and verify the offset.
108 [[EarlGrey selectElementWithMatcher:web::webViewScrollView()]
109 performAction:grey_scrollInDirection(kGREYDirectionDown, kScrollOffset2)];
110 [[EarlGrey selectElementWithMatcher:web::webViewScrollView()]
111 assertWithMatcher:contentOffset(CGPointMake(0, kScrollOffset2))];
112
113 // Go back and verify that the first page offset has been restored.
114 [[EarlGrey selectElementWithMatcher:web::backButton()]
115 performAction:grey_tap()];
116 [[EarlGrey selectElementWithMatcher:web::webViewScrollView()]
117 assertWithMatcher:contentOffset(CGPointMake(0, kScrollOffset1))];
118
119 // Go forward and verify that the second page offset has been restored.
120 [[EarlGrey selectElementWithMatcher:web::forwardButton()]
121 performAction:grey_tap()];
122 [[EarlGrey selectElementWithMatcher:web::webViewScrollView()]
123 assertWithMatcher:contentOffset(CGPointMake(0, kScrollOffset2))];
124 }
125
126 @end
OLDNEW
« no previous file with comments | « ios/web/shell/test/http_server_files/tall_page.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698