| 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 #import "ios/web/public/test/http_server.h" | 10 #import "ios/web/public/test/http_server.h" |
| 11 #include "ios/web/public/test/http_server_util.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_base_test_case.h" | 12 #import "ios/web/shell/test/earl_grey/shell_base_test_case.h" |
| 13 #import "ios/web/shell/test/earl_grey/shell_earl_grey.h" |
| 14 #import "ios/web/shell/test/earl_grey/shell_matchers.h" | 14 #import "ios/web/shell/test/earl_grey/shell_matchers.h" |
| 15 | 15 |
| 16 #if !defined(__has_feature) || !__has_feature(objc_arc) | 16 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 17 #error "This file requires ARC support." | 17 #error "This file requires ARC support." |
| 18 #endif | 18 #endif |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 // URLs for test pages. | 22 // URLs for test pages. |
| 23 const char kLongPage1[] = | 23 const char kLongPage1[] = |
| (...skipping 16 matching lines...) Expand all Loading... |
| 40 }; | 40 }; |
| 41 return grey_allOf( | 41 return grey_allOf( |
| 42 grey_kindOfClass([UIScrollView class]), | 42 grey_kindOfClass([UIScrollView class]), |
| 43 [[GREYElementMatcherBlock alloc] initWithMatchesBlock:matches | 43 [[GREYElementMatcherBlock alloc] initWithMatchesBlock:matches |
| 44 descriptionBlock:describe], | 44 descriptionBlock:describe], |
| 45 nil); | 45 nil); |
| 46 } | 46 } |
| 47 | 47 |
| 48 } // namespace | 48 } // namespace |
| 49 | 49 |
| 50 using web::shell_test_util::LoadUrl; | |
| 51 using web::test::HttpServer; | 50 using web::test::HttpServer; |
| 52 using web::webViewContainingText; | |
| 53 | 51 |
| 54 // Page state test cases for the web shell. | 52 // Page state test cases for the web shell. |
| 55 @interface PageStateTestCase : ShellBaseTestCase | 53 @interface PageStateTestCase : ShellBaseTestCase |
| 56 @end | 54 @end |
| 57 | 55 |
| 58 @implementation PageStateTestCase | 56 @implementation PageStateTestCase |
| 59 | 57 |
| 60 // Tests that page scroll position of a page is restored upon returning to the | 58 // Tests that page scroll position of a page is restored upon returning to the |
| 61 // page via the back/forward buttons. | 59 // page via the back/forward buttons. |
| 62 - (void)testScrollPositionRestoring { | 60 - (void)testScrollPositionRestoring { |
| 63 web::test::SetUpFileBasedHttpServer(); | 61 web::test::SetUpFileBasedHttpServer(); |
| 64 | 62 |
| 65 // Load first URL which is a long page. | 63 // Load first URL which is a long page. |
| 66 LoadUrl(HttpServer::MakeUrl(kLongPage1)); | 64 [ShellEarlGrey loadURL:HttpServer::MakeUrl(kLongPage1)]; |
| 67 // TODO(crbug.com/629116): Remove this once |LoadUrl| waits for the load | |
| 68 // completion. | |
| 69 [[EarlGrey selectElementWithMatcher:webViewContainingText("List of numbers")] | |
| 70 assertWithMatcher:grey_notNil()]; | |
| 71 | 65 |
| 72 // Scroll the first page and verify the offset. | 66 // Scroll the first page and verify the offset. |
| 73 [[EarlGrey selectElementWithMatcher:web::webViewScrollView()] | 67 [[EarlGrey selectElementWithMatcher:web::webViewScrollView()] |
| 74 performAction:grey_scrollInDirection(kGREYDirectionDown, kScrollOffset1)]; | 68 performAction:grey_scrollInDirection(kGREYDirectionDown, kScrollOffset1)]; |
| 75 [[EarlGrey selectElementWithMatcher:web::webViewScrollView()] | 69 [[EarlGrey selectElementWithMatcher:web::webViewScrollView()] |
| 76 assertWithMatcher:contentOffset(CGPointMake(0, kScrollOffset1))]; | 70 assertWithMatcher:contentOffset(CGPointMake(0, kScrollOffset1))]; |
| 77 | 71 |
| 78 // Load second URL, which is also a long page. | 72 // Load second URL, which is also a long page. |
| 79 GURL URL2 = HttpServer::MakeUrl(kLongPage2); | 73 [ShellEarlGrey loadURL:HttpServer::MakeUrl(kLongPage2)]; |
| 80 LoadUrl(URL2); | |
| 81 // TODO(crbug.com/629116): Remove these once |LoadUrl| waits for the load | |
| 82 // completion. | |
| 83 [[EarlGrey selectElementWithMatcher:web::addressFieldText(URL2.spec())] | |
| 84 assertWithMatcher:grey_notNil()]; | |
| 85 [[EarlGrey selectElementWithMatcher:webViewContainingText("List of numbers")] | |
| 86 assertWithMatcher:grey_notNil()]; | |
| 87 | 74 |
| 88 // Scroll the second page and verify the offset. | 75 // Scroll the second page and verify the offset. |
| 89 [[EarlGrey selectElementWithMatcher:web::webViewScrollView()] | 76 [[EarlGrey selectElementWithMatcher:web::webViewScrollView()] |
| 90 performAction:grey_scrollInDirection(kGREYDirectionDown, kScrollOffset2)]; | 77 performAction:grey_scrollInDirection(kGREYDirectionDown, kScrollOffset2)]; |
| 91 [[EarlGrey selectElementWithMatcher:web::webViewScrollView()] | 78 [[EarlGrey selectElementWithMatcher:web::webViewScrollView()] |
| 92 assertWithMatcher:contentOffset(CGPointMake(0, kScrollOffset2))]; | 79 assertWithMatcher:contentOffset(CGPointMake(0, kScrollOffset2))]; |
| 93 | 80 |
| 94 // Go back and verify that the first page offset has been restored. | 81 // Go back and verify that the first page offset has been restored. |
| 95 [[EarlGrey selectElementWithMatcher:web::backButton()] | 82 [[EarlGrey selectElementWithMatcher:web::backButton()] |
| 96 performAction:grey_tap()]; | 83 performAction:grey_tap()]; |
| 97 [[EarlGrey selectElementWithMatcher:web::webViewScrollView()] | 84 [[EarlGrey selectElementWithMatcher:web::webViewScrollView()] |
| 98 assertWithMatcher:contentOffset(CGPointMake(0, kScrollOffset1))]; | 85 assertWithMatcher:contentOffset(CGPointMake(0, kScrollOffset1))]; |
| 99 | 86 |
| 100 // Go forward and verify that the second page offset has been restored. | 87 // Go forward and verify that the second page offset has been restored. |
| 101 [[EarlGrey selectElementWithMatcher:web::forwardButton()] | 88 [[EarlGrey selectElementWithMatcher:web::forwardButton()] |
| 102 performAction:grey_tap()]; | 89 performAction:grey_tap()]; |
| 103 [[EarlGrey selectElementWithMatcher:web::webViewScrollView()] | 90 [[EarlGrey selectElementWithMatcher:web::webViewScrollView()] |
| 104 assertWithMatcher:contentOffset(CGPointMake(0, kScrollOffset2))]; | 91 assertWithMatcher:contentOffset(CGPointMake(0, kScrollOffset2))]; |
| 105 } | 92 } |
| 106 | 93 |
| 107 @end | 94 @end |
| OLD | NEW |