| 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 <EarlGrey/EarlGrey.h> | 5 #import <EarlGrey/EarlGrey.h> |
| 6 #import <UIKit/UIKit.h> | 6 #import <UIKit/UIKit.h> |
| 7 #import <XCTest/XCTest.h> | 7 #import <XCTest/XCTest.h> |
| 8 | 8 |
| 9 #include "base/ios/ios_util.h" | 9 #include "base/ios/ios_util.h" |
| 10 #include "base/mac/bind_objc_block.h" | 10 #include "base/mac/bind_objc_block.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 #import "ios/web/public/test/response_providers/error_page_response_provider.h" | 27 #import "ios/web/public/test/response_providers/error_page_response_provider.h" |
| 28 #import "ios/web/public/test/web_view_interaction_test_util.h" | 28 #import "ios/web/public/test/web_view_interaction_test_util.h" |
| 29 #include "url/gurl.h" | 29 #include "url/gurl.h" |
| 30 | 30 |
| 31 namespace { | 31 namespace { |
| 32 | 32 |
| 33 // TODO(crbug.com/638674): Move this to a shared location as it is a duplicate | 33 // TODO(crbug.com/638674): Move this to a shared location as it is a duplicate |
| 34 // of ios/web/shell/test/page_state_egtest.mm. | 34 // of ios/web/shell/test/page_state_egtest.mm. |
| 35 // Returns a matcher for asserting that element's content offset matches the | 35 // Returns a matcher for asserting that element's content offset matches the |
| 36 // given |offset|. | 36 // given |offset|. |
| 37 id<GREYMatcher> contentOffset(CGPoint offset) { | 37 id<GREYMatcher> ContentOffset(CGPoint offset) { |
| 38 MatchesBlock matches = ^BOOL(UIScrollView* element) { | 38 MatchesBlock matches = ^BOOL(UIScrollView* element) { |
| 39 return CGPointEqualToPoint([element contentOffset], offset); | 39 return CGPointEqualToPoint([element contentOffset], offset); |
| 40 }; | 40 }; |
| 41 DescribeToBlock describe = ^(id<GREYDescription> description) { | 41 DescribeToBlock describe = ^(id<GREYDescription> description) { |
| 42 [description appendText:@"contentOffset"]; | 42 [description appendText:@"contentOffset"]; |
| 43 }; | 43 }; |
| 44 return grey_allOf( | 44 return grey_allOf( |
| 45 grey_kindOfClass([UIScrollView class]), | 45 grey_kindOfClass([UIScrollView class]), |
| 46 [[GREYElementMatcherBlock alloc] initWithMatchesBlock:matches | 46 [[GREYElementMatcherBlock alloc] initWithMatchesBlock:matches |
| 47 descriptionBlock:describe], | 47 descriptionBlock:describe], |
| 48 nil); | 48 nil); |
| 49 } | 49 } |
| 50 | 50 |
| 51 // Hides the toolbar by scrolling down. | 51 // Hides the toolbar by scrolling down. |
| 52 void HideToolbarUsingUI() { | 52 void HideToolbarUsingUI() { |
| 53 [[EarlGrey | 53 [[EarlGrey |
| 54 selectElementWithMatcher:webViewScrollView( | 54 selectElementWithMatcher:WebViewScrollView( |
| 55 chrome_test_util::GetCurrentWebState())] | 55 chrome_test_util::GetCurrentWebState())] |
| 56 performAction:grey_swipeFastInDirection(kGREYDirectionUp)]; | 56 performAction:grey_swipeFastInDirection(kGREYDirectionUp)]; |
| 57 } | 57 } |
| 58 | 58 |
| 59 // Asserts that the current URL is the |expectedURL| one. | 59 // Asserts that the current URL is the |expectedURL| one. |
| 60 void AssertURLIs(const GURL& expectedURL) { | 60 void AssertURLIs(const GURL& expectedURL) { |
| 61 NSString* description = [NSString | 61 NSString* description = [NSString |
| 62 stringWithFormat:@"Timeout waiting for the url to be %@", | 62 stringWithFormat:@"Timeout waiting for the url to be %@", |
| 63 base::SysUTF8ToNSString(expectedURL.GetContent())]; | 63 base::SysUTF8ToNSString(expectedURL.GetContent())]; |
| 64 | 64 |
| 65 ConditionBlock condition = ^{ | 65 ConditionBlock condition = ^{ |
| 66 NSError* error = nil; | 66 NSError* error = nil; |
| 67 [[EarlGrey selectElementWithMatcher:chrome_test_util::omniboxText( | 67 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( |
| 68 expectedURL.GetContent())] | 68 expectedURL.GetContent())] |
| 69 assertWithMatcher:grey_notNil() | 69 assertWithMatcher:grey_notNil() |
| 70 error:&error]; | 70 error:&error]; |
| 71 return (error == nil); | 71 return (error == nil); |
| 72 }; | 72 }; |
| 73 GREYAssert(testing::WaitUntilConditionOrTimeout(1.0, condition), description); | 73 GREYAssert(testing::WaitUntilConditionOrTimeout(1.0, condition), description); |
| 74 } | 74 } |
| 75 | 75 |
| 76 // Asserts that the current web view containers contains |text|. | 76 // Asserts that the current web view containers contains |text|. |
| 77 void AssertStringIsPresentOnPage(const std::string& text) { | 77 void AssertStringIsPresentOnPage(const std::string& text) { |
| 78 id<GREYMatcher> response_matcher = | 78 id<GREYMatcher> response_matcher = |
| 79 chrome_test_util::webViewContainingText(text); | 79 chrome_test_util::WebViewContainingText(text); |
| 80 [[EarlGrey selectElementWithMatcher:response_matcher] | 80 [[EarlGrey selectElementWithMatcher:response_matcher] |
| 81 assertWithMatcher:grey_notNil()]; | 81 assertWithMatcher:grey_notNil()]; |
| 82 } | 82 } |
| 83 | 83 |
| 84 } // namespace | 84 } // namespace |
| 85 | 85 |
| 86 #pragma mark - Tests | 86 #pragma mark - Tests |
| 87 | 87 |
| 88 // Fullscreens tests for Chrome. | 88 // Fullscreens tests for Chrome. |
| 89 @interface FullscreenTestCase : ChromeTestCase | 89 @interface FullscreenTestCase : ChromeTestCase |
| (...skipping 10 matching lines...) Expand all Loading... |
| 100 "http://ios/testing/data/http_server_files/two_pages.pdf"); | 100 "http://ios/testing/data/http_server_files/two_pages.pdf"); |
| 101 [ChromeEarlGrey loadURL:URL]; | 101 [ChromeEarlGrey loadURL:URL]; |
| 102 | 102 |
| 103 chrome_test_util::AssertToolbarVisible(); | 103 chrome_test_util::AssertToolbarVisible(); |
| 104 // Initial y scroll position is -56 on iPhone and -95 on iPad, to make room | 104 // Initial y scroll position is -56 on iPhone and -95 on iPad, to make room |
| 105 // for the toolbar. | 105 // for the toolbar. |
| 106 // TODO(crbug.com/618887) Replace use of specific values when API which | 106 // TODO(crbug.com/618887) Replace use of specific values when API which |
| 107 // generates these values is exposed. | 107 // generates these values is exposed. |
| 108 CGFloat yOffset = IsIPadIdiom() ? -95.0 : -56.0; | 108 CGFloat yOffset = IsIPadIdiom() ? -95.0 : -56.0; |
| 109 [[EarlGrey | 109 [[EarlGrey |
| 110 selectElementWithMatcher:web::webViewScrollView( | 110 selectElementWithMatcher:web::WebViewScrollView( |
| 111 chrome_test_util::GetCurrentWebState())] | 111 chrome_test_util::GetCurrentWebState())] |
| 112 assertWithMatcher:contentOffset(CGPointMake(0, yOffset))]; | 112 assertWithMatcher:ContentOffset(CGPointMake(0, yOffset))]; |
| 113 } | 113 } |
| 114 | 114 |
| 115 // Verifies that the toolbar properly appears/disappears when scrolling up/down | 115 // Verifies that the toolbar properly appears/disappears when scrolling up/down |
| 116 // on a PDF that is short in length and wide in width. | 116 // on a PDF that is short in length and wide in width. |
| 117 - (void)testSmallWidePDFScroll { | 117 - (void)testSmallWidePDFScroll { |
| 118 web::test::SetUpFileBasedHttpServer(); | 118 web::test::SetUpFileBasedHttpServer(); |
| 119 GURL URL = web::test::HttpServer::MakeUrl( | 119 GURL URL = web::test::HttpServer::MakeUrl( |
| 120 "http://ios/testing/data/http_server_files/single_page_wide.pdf"); | 120 "http://ios/testing/data/http_server_files/single_page_wide.pdf"); |
| 121 [ChromeEarlGrey loadURL:URL]; | 121 [ChromeEarlGrey loadURL:URL]; |
| 122 | 122 |
| 123 // Test that the toolbar is still visible after a user swipes down. | 123 // Test that the toolbar is still visible after a user swipes down. |
| 124 [[EarlGrey | 124 [[EarlGrey |
| 125 selectElementWithMatcher:webViewScrollView( | 125 selectElementWithMatcher:WebViewScrollView( |
| 126 chrome_test_util::GetCurrentWebState())] | 126 chrome_test_util::GetCurrentWebState())] |
| 127 performAction:grey_swipeFastInDirection(kGREYDirectionDown)]; | 127 performAction:grey_swipeFastInDirection(kGREYDirectionDown)]; |
| 128 chrome_test_util::AssertToolbarVisible(); | 128 chrome_test_util::AssertToolbarVisible(); |
| 129 | 129 |
| 130 // Test that the toolbar is no longer visible after a user swipes up. | 130 // Test that the toolbar is no longer visible after a user swipes up. |
| 131 HideToolbarUsingUI(); | 131 HideToolbarUsingUI(); |
| 132 chrome_test_util::AssertToolbarNotVisible(); | 132 chrome_test_util::AssertToolbarNotVisible(); |
| 133 } | 133 } |
| 134 | 134 |
| 135 // Verifies that the toolbar properly appears/disappears when scrolling up/down | 135 // Verifies that the toolbar properly appears/disappears when scrolling up/down |
| 136 // on a PDF that is long in length and wide in width. | 136 // on a PDF that is long in length and wide in width. |
| 137 - (void)testLongPDFScroll { | 137 - (void)testLongPDFScroll { |
| 138 web::test::SetUpFileBasedHttpServer(); | 138 web::test::SetUpFileBasedHttpServer(); |
| 139 GURL URL = web::test::HttpServer::MakeUrl( | 139 GURL URL = web::test::HttpServer::MakeUrl( |
| 140 "http://ios/testing/data/http_server_files/two_pages.pdf"); | 140 "http://ios/testing/data/http_server_files/two_pages.pdf"); |
| 141 [ChromeEarlGrey loadURL:URL]; | 141 [ChromeEarlGrey loadURL:URL]; |
| 142 | 142 |
| 143 // Test that the toolbar is hidden after a user swipes up. | 143 // Test that the toolbar is hidden after a user swipes up. |
| 144 HideToolbarUsingUI(); | 144 HideToolbarUsingUI(); |
| 145 chrome_test_util::AssertToolbarNotVisible(); | 145 chrome_test_util::AssertToolbarNotVisible(); |
| 146 | 146 |
| 147 // Test that the toolbar is visible after a user swipes down. | 147 // Test that the toolbar is visible after a user swipes down. |
| 148 [[EarlGrey | 148 [[EarlGrey |
| 149 selectElementWithMatcher:webViewScrollView( | 149 selectElementWithMatcher:WebViewScrollView( |
| 150 chrome_test_util::GetCurrentWebState())] | 150 chrome_test_util::GetCurrentWebState())] |
| 151 performAction:grey_swipeFastInDirection(kGREYDirectionDown)]; | 151 performAction:grey_swipeFastInDirection(kGREYDirectionDown)]; |
| 152 chrome_test_util::AssertToolbarVisible(); | 152 chrome_test_util::AssertToolbarVisible(); |
| 153 | 153 |
| 154 // Test that the toolbar is hidden after a user swipes up. | 154 // Test that the toolbar is hidden after a user swipes up. |
| 155 HideToolbarUsingUI(); | 155 HideToolbarUsingUI(); |
| 156 chrome_test_util::AssertToolbarNotVisible(); | 156 chrome_test_util::AssertToolbarNotVisible(); |
| 157 } | 157 } |
| 158 | 158 |
| 159 // Tests that link clicks from a chrome:// to chrome:// link result in the | 159 // Tests that link clicks from a chrome:// to chrome:// link result in the |
| (...skipping 25 matching lines...) Expand all Loading... |
| 185 })); | 185 })); |
| 186 | 186 |
| 187 GREYAssert(testing::WaitUntilConditionOrTimeout(1.0, | 187 GREYAssert(testing::WaitUntilConditionOrTimeout(1.0, |
| 188 ^{ | 188 ^{ |
| 189 return finished; | 189 return finished; |
| 190 }), | 190 }), |
| 191 @"JavaScript to hide the toolbar did not complete"); | 191 @"JavaScript to hide the toolbar did not complete"); |
| 192 | 192 |
| 193 // Scroll up to be sure the toolbar can be dismissed by scrolling down. | 193 // Scroll up to be sure the toolbar can be dismissed by scrolling down. |
| 194 [[EarlGrey | 194 [[EarlGrey |
| 195 selectElementWithMatcher:webViewScrollView( | 195 selectElementWithMatcher:WebViewScrollView( |
| 196 chrome_test_util::GetCurrentWebState())] | 196 chrome_test_util::GetCurrentWebState())] |
| 197 performAction:grey_swipeFastInDirection(kGREYDirectionDown)]; | 197 performAction:grey_swipeFastInDirection(kGREYDirectionDown)]; |
| 198 | 198 |
| 199 // Scroll to hide the UI. | 199 // Scroll to hide the UI. |
| 200 HideToolbarUsingUI(); | 200 HideToolbarUsingUI(); |
| 201 chrome_test_util::AssertToolbarNotVisible(); | 201 chrome_test_util::AssertToolbarNotVisible(); |
| 202 | 202 |
| 203 // Test that the toolbar is visible when moving from one chrome:// link to | 203 // Test that the toolbar is visible when moving from one chrome:// link to |
| 204 // another chrome:// link. | 204 // another chrome:// link. |
| 205 chrome_test_util::TapWebViewElementWithId("version"); | 205 chrome_test_util::TapWebViewElementWithId("version"); |
| 206 chrome_test_util::AssertToolbarVisible(); | 206 chrome_test_util::AssertToolbarVisible(); |
| 207 } | 207 } |
| 208 | 208 |
| 209 // Tests hiding and showing of the header with a user scroll on a long page. | 209 // Tests hiding and showing of the header with a user scroll on a long page. |
| 210 - (void)testHideHeaderUserScrollLongPage { | 210 - (void)testHideHeaderUserScrollLongPage { |
| 211 std::map<GURL, std::string> responses; | 211 std::map<GURL, std::string> responses; |
| 212 const GURL URL = web::test::HttpServer::MakeUrl("http://tallpage"); | 212 const GURL URL = web::test::HttpServer::MakeUrl("http://tallpage"); |
| 213 | 213 |
| 214 // A page long enough to ensure that the toolbar goes away on scrolling. | 214 // A page long enough to ensure that the toolbar goes away on scrolling. |
| 215 responses[URL] = "<p style='height:200em'>a</p><p>b</p>"; | 215 responses[URL] = "<p style='height:200em'>a</p><p>b</p>"; |
| 216 web::test::SetUpSimpleHttpServer(responses); | 216 web::test::SetUpSimpleHttpServer(responses); |
| 217 | 217 |
| 218 [ChromeEarlGrey loadURL:URL]; | 218 [ChromeEarlGrey loadURL:URL]; |
| 219 chrome_test_util::AssertToolbarVisible(); | 219 chrome_test_util::AssertToolbarVisible(); |
| 220 // Simulate a user scroll down. | 220 // Simulate a user scroll down. |
| 221 HideToolbarUsingUI(); | 221 HideToolbarUsingUI(); |
| 222 chrome_test_util::AssertToolbarNotVisible(); | 222 chrome_test_util::AssertToolbarNotVisible(); |
| 223 // Simulate a user scroll up. | 223 // Simulate a user scroll up. |
| 224 [[EarlGrey | 224 [[EarlGrey |
| 225 selectElementWithMatcher:webViewScrollView( | 225 selectElementWithMatcher:WebViewScrollView( |
| 226 chrome_test_util::GetCurrentWebState())] | 226 chrome_test_util::GetCurrentWebState())] |
| 227 performAction:grey_swipeFastInDirection(kGREYDirectionDown)]; | 227 performAction:grey_swipeFastInDirection(kGREYDirectionDown)]; |
| 228 chrome_test_util::AssertToolbarVisible(); | 228 chrome_test_util::AssertToolbarVisible(); |
| 229 } | 229 } |
| 230 | 230 |
| 231 // Tests that reloading of a page shows the header even if it was not shown | 231 // Tests that reloading of a page shows the header even if it was not shown |
| 232 // previously. | 232 // previously. |
| 233 - (void)testShowHeaderOnReload { | 233 - (void)testShowHeaderOnReload { |
| 234 std::map<GURL, std::string> responses; | 234 std::map<GURL, std::string> responses; |
| 235 const GURL URL = web::test::HttpServer::MakeUrl("http://origin"); | 235 const GURL URL = web::test::HttpServer::MakeUrl("http://origin"); |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 [ChromeEarlGrey loadURL:URL]; | 402 [ChromeEarlGrey loadURL:URL]; |
| 403 HideToolbarUsingUI(); | 403 HideToolbarUsingUI(); |
| 404 chrome_test_util::AssertToolbarNotVisible(); | 404 chrome_test_util::AssertToolbarNotVisible(); |
| 405 | 405 |
| 406 chrome_test_util::TapWebViewElementWithId("link"); | 406 chrome_test_util::TapWebViewElementWithId("link"); |
| 407 AssertURLIs(ErrorPageResponseProvider::GetDnsFailureUrl()); | 407 AssertURLIs(ErrorPageResponseProvider::GetDnsFailureUrl()); |
| 408 chrome_test_util::AssertToolbarVisible(); | 408 chrome_test_util::AssertToolbarVisible(); |
| 409 } | 409 } |
| 410 | 410 |
| 411 @end | 411 @end |
| OLD | NEW |