Chromium Code Reviews| OLD | NEW |
|---|---|
| (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" | |
|
baxley
2016/07/20 15:27:25
import?
Eugene But (OOO till 7-30)
2016/07/20 16:09:40
This header does not have any Objective-C code (un
| |
| 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(id element) { | |
|
baxley
2016/07/20 15:27:25
should this UIView* instead of id? More question t
Eugene But (OOO till 7-30)
2016/07/20 16:09:40
UIView does not have |contentOffset| method and I'
| |
| 35 return CGPointEqualToPoint([element contentOffset], offset); | |
| 36 }; | |
| 37 DescribeToBlock describe = ^(id<GREYDescription> description) { | |
| 38 [description appendText:@"contentOffset"]; | |
| 39 }; | |
| 40 return [[GREYElementMatcherBlock alloc] initWithMatchesBlock:matches | |
| 41 descriptionBlock:describe]; | |
| 42 } | |
| 43 | |
| 44 } // namespace | |
| 45 | |
| 46 using web::shell_test_util::LoadUrl; | |
| 47 using web::test::HttpServer; | |
| 48 using web::webViewContainingText; | |
| 49 | |
| 50 // Page state test cases for the web shell. | |
| 51 @interface CRWWebShellPageStateTest : XCTestCase | |
| 52 @end | |
| 53 | |
| 54 @implementation CRWWebShellPageStateTest | |
| 55 | |
| 56 // Set up called once for the class. | |
| 57 + (void)setUp { | |
| 58 [super setUp]; | |
| 59 [[EarlGrey selectElementWithMatcher:webViewContainingText("Chromium")] | |
| 60 assertWithMatcher:grey_notNil()]; | |
| 61 HttpServer::GetSharedInstance().StartOrDie(); | |
| 62 } | |
| 63 | |
| 64 // Tear down called once for the class. | |
| 65 + (void)tearDown { | |
| 66 [super tearDown]; | |
| 67 HttpServer::GetSharedInstance().Stop(); | |
| 68 } | |
| 69 | |
| 70 // Tear down called after each test. | |
| 71 - (void)tearDown { | |
| 72 [super tearDown]; | |
| 73 HttpServer::GetSharedInstance().RemoveAllResponseProviders(); | |
| 74 } | |
| 75 | |
| 76 // Tests that page scroll position of a page is restored upon returning to the | |
| 77 // page via the back/forward buttons. | |
| 78 - (void)testScrollPositionRestoring { | |
| 79 web::test::SetUpFileBasedHttpServer(); | |
| 80 | |
| 81 // Load first URL which is a long page. | |
| 82 LoadUrl(HttpServer::MakeUrl(kLongPage1)); | |
| 83 // TODO(crbug.com/629116): Remove this once |LoadUrl| waits for the load | |
| 84 // completion. | |
| 85 [[EarlGrey selectElementWithMatcher:webViewContainingText("List of numbers")] | |
| 86 assertWithMatcher:grey_notNil()]; | |
| 87 | |
| 88 // Scroll the first page and verify the offset. | |
| 89 [[EarlGrey selectElementWithMatcher:web::webViewScrollView()] | |
| 90 performAction:grey_scrollInDirection(kGREYDirectionDown, kScrollOffset1)]; | |
| 91 [[EarlGrey selectElementWithMatcher:web::webViewScrollView()] | |
| 92 assertWithMatcher:contentOffset(CGPointMake(0, kScrollOffset1))]; | |
| 93 | |
| 94 // Load second URL, which is also a long page. | |
| 95 GURL URL2 = HttpServer::MakeUrl(kLongPage2); | |
| 96 LoadUrl(URL2); | |
| 97 // TODO(crbug.com/629116): Remove these once |LoadUrl| waits for the load | |
| 98 // completion. | |
| 99 [[EarlGrey selectElementWithMatcher:web::addressFieldText(URL2.spec())] | |
| 100 assertWithMatcher:grey_notNil()]; | |
| 101 [[EarlGrey selectElementWithMatcher:webViewContainingText("List of numbers")] | |
| 102 assertWithMatcher:grey_notNil()]; | |
| 103 | |
| 104 // Scroll the second page and verify the offset. | |
| 105 [[EarlGrey selectElementWithMatcher:web::webViewScrollView()] | |
| 106 performAction:grey_scrollInDirection(kGREYDirectionDown, kScrollOffset2)]; | |
| 107 [[EarlGrey selectElementWithMatcher:web::webViewScrollView()] | |
| 108 assertWithMatcher:contentOffset(CGPointMake(0, kScrollOffset2))]; | |
| 109 | |
| 110 // Go back and verify that the first page offset has been restored. | |
| 111 [[EarlGrey selectElementWithMatcher:web::backButton()] | |
| 112 performAction:grey_tap()]; | |
| 113 [[EarlGrey selectElementWithMatcher:web::webViewScrollView()] | |
| 114 assertWithMatcher:contentOffset(CGPointMake(0, kScrollOffset1))]; | |
| 115 | |
| 116 // Go forward and verify that the second page offset has been restored. | |
| 117 [[EarlGrey selectElementWithMatcher:web::forwardButton()] | |
| 118 performAction:grey_tap()]; | |
| 119 [[EarlGrey selectElementWithMatcher:web::webViewScrollView()] | |
| 120 assertWithMatcher:contentOffset(CGPointMake(0, kScrollOffset2))]; | |
| 121 } | |
| 122 | |
| 123 @end | |
| OLD | NEW |