| 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" | 12 #include "ios/web/shell/test/app/navigation_test_util.h" |
| 13 #import "ios/web/shell/test/earl_grey/shell_base_test_case.h" |
| 13 #import "ios/web/shell/test/earl_grey/shell_matchers.h" | 14 #import "ios/web/shell/test/earl_grey/shell_matchers.h" |
| 14 | 15 |
| 15 #if !defined(__has_feature) || !__has_feature(objc_arc) | 16 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 16 #error "This file requires ARC support." | 17 #error "This file requires ARC support." |
| 17 #endif | 18 #endif |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 // URLs for test pages. | 22 // URLs for test pages. |
| 22 const char kLongPage1[] = | 23 const char kLongPage1[] = |
| (...skipping 21 matching lines...) Expand all Loading... |
| 44 nil); | 45 nil); |
| 45 } | 46 } |
| 46 | 47 |
| 47 } // namespace | 48 } // namespace |
| 48 | 49 |
| 49 using web::shell_test_util::LoadUrl; | 50 using web::shell_test_util::LoadUrl; |
| 50 using web::test::HttpServer; | 51 using web::test::HttpServer; |
| 51 using web::webViewContainingText; | 52 using web::webViewContainingText; |
| 52 | 53 |
| 53 // Page state test cases for the web shell. | 54 // Page state test cases for the web shell. |
| 54 @interface CRWWebShellPageStateTest : XCTestCase | 55 @interface CRWWebShellPageStateTest : ShellBaseTestCase |
| 56 |
| 55 @end | 57 @end |
| 56 | 58 |
| 57 @implementation CRWWebShellPageStateTest | 59 @implementation CRWWebShellPageStateTest |
| 58 | 60 |
| 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 | 61 // Tests that page scroll position of a page is restored upon returning to the |
| 80 // page via the back/forward buttons. | 62 // page via the back/forward buttons. |
| 81 - (void)testScrollPositionRestoring { | 63 - (void)testScrollPositionRestoring { |
| 82 web::test::SetUpFileBasedHttpServer(); | 64 web::test::SetUpFileBasedHttpServer(); |
| 83 | 65 |
| 84 // Load first URL which is a long page. | 66 // Load first URL which is a long page. |
| 85 LoadUrl(HttpServer::MakeUrl(kLongPage1)); | 67 LoadUrl(HttpServer::MakeUrl(kLongPage1)); |
| 86 // TODO(crbug.com/629116): Remove this once |LoadUrl| waits for the load | 68 // TODO(crbug.com/629116): Remove this once |LoadUrl| waits for the load |
| 87 // completion. | 69 // completion. |
| 88 [[EarlGrey selectElementWithMatcher:webViewContainingText("List of numbers")] | 70 [[EarlGrey selectElementWithMatcher:webViewContainingText("List of numbers")] |
| (...skipping 28 matching lines...) Expand all Loading... |
| 117 assertWithMatcher:contentOffset(CGPointMake(0, kScrollOffset1))]; | 99 assertWithMatcher:contentOffset(CGPointMake(0, kScrollOffset1))]; |
| 118 | 100 |
| 119 // Go forward and verify that the second page offset has been restored. | 101 // Go forward and verify that the second page offset has been restored. |
| 120 [[EarlGrey selectElementWithMatcher:web::forwardButton()] | 102 [[EarlGrey selectElementWithMatcher:web::forwardButton()] |
| 121 performAction:grey_tap()]; | 103 performAction:grey_tap()]; |
| 122 [[EarlGrey selectElementWithMatcher:web::webViewScrollView()] | 104 [[EarlGrey selectElementWithMatcher:web::webViewScrollView()] |
| 123 assertWithMatcher:contentOffset(CGPointMake(0, kScrollOffset2))]; | 105 assertWithMatcher:contentOffset(CGPointMake(0, kScrollOffset2))]; |
| 124 } | 106 } |
| 125 | 107 |
| 126 @end | 108 @end |
| OLD | NEW |