Chromium Code Reviews| 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" |
| 11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 12 #include "base/strings/sys_string_conversions.h" | 12 #include "base/strings/sys_string_conversions.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #import "ios/chrome/browser/ui/toolbar/toolbar_controller.h" | 14 #import "ios/chrome/browser/ui/toolbar/toolbar_controller.h" |
| 15 #import "ios/chrome/test/app/chrome_test_util.h" | 15 #import "ios/chrome/test/app/chrome_test_util.h" |
| 16 #import "ios/chrome/test/app/settings_test_util.h" | 16 #import "ios/chrome/test/app/settings_test_util.h" |
| 17 #import "ios/chrome/test/app/web_view_interaction_test_util.h" | 17 #import "ios/chrome/test/app/web_view_interaction_test_util.h" |
| 18 #include "ios/chrome/test/earl_grey/chrome_assertions.h" | 18 #include "ios/chrome/test/earl_grey/chrome_assertions.h" |
| 19 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h" | 19 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h" |
| 20 #import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h" | |
| 20 #import "ios/chrome/test/earl_grey/chrome_matchers.h" | 21 #import "ios/chrome/test/earl_grey/chrome_matchers.h" |
| 21 #import "ios/chrome/test/earl_grey/chrome_test_case.h" | 22 #import "ios/chrome/test/earl_grey/chrome_test_case.h" |
| 22 #import "ios/chrome/test/earl_grey/chrome_util.h" | |
| 23 #import "ios/testing/wait_util.h" | 23 #import "ios/testing/wait_util.h" |
| 24 #import "ios/web/public/test/earl_grey/web_view_matchers.h" | 24 #import "ios/web/public/test/earl_grey/web_view_matchers.h" |
| 25 #import "ios/web/public/test/http_server.h" | 25 #import "ios/web/public/test/http_server.h" |
| 26 #import "ios/web/public/test/http_server_util.h" | 26 #import "ios/web/public/test/http_server_util.h" |
| 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 #if !defined(__has_feature) || !__has_feature(objc_arc) | 31 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 32 #error "This file requires ARC support." | 32 #error "This file requires ARC support." |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 97 @implementation FullscreenTestCase | 97 @implementation FullscreenTestCase |
| 98 | 98 |
| 99 // Verifies that the content offset of the web view is set up at the correct | 99 // Verifies that the content offset of the web view is set up at the correct |
| 100 // initial value when initially displaying a PDF. | 100 // initial value when initially displaying a PDF. |
| 101 - (void)testLongPDFInitialState { | 101 - (void)testLongPDFInitialState { |
| 102 web::test::SetUpFileBasedHttpServer(); | 102 web::test::SetUpFileBasedHttpServer(); |
| 103 GURL URL = web::test::HttpServer::MakeUrl( | 103 GURL URL = web::test::HttpServer::MakeUrl( |
| 104 "http://ios/testing/data/http_server_files/two_pages.pdf"); | 104 "http://ios/testing/data/http_server_files/two_pages.pdf"); |
| 105 [ChromeEarlGrey loadURL:URL]; | 105 [ChromeEarlGrey loadURL:URL]; |
| 106 | 106 |
| 107 chrome_test_util::AssertToolbarVisible(); | 107 GREYAssertTrue([ChromeEarlGreyUI waitForToolbarVisible:YES], |
| 108 @"Toolbar was not visible"); | |
| 108 // Initial y scroll position is -56 on iPhone and -95 on iPad, to make room | 109 // Initial y scroll position is -56 on iPhone and -95 on iPad, to make room |
| 109 // for the toolbar. | 110 // for the toolbar. |
| 110 // TODO(crbug.com/618887) Replace use of specific values when API which | 111 // TODO(crbug.com/618887) Replace use of specific values when API which |
| 111 // generates these values is exposed. | 112 // generates these values is exposed. |
| 112 CGFloat yOffset = IsIPadIdiom() ? -95.0 : -56.0; | 113 CGFloat yOffset = IsIPadIdiom() ? -95.0 : -56.0; |
| 113 [[EarlGrey | 114 [[EarlGrey |
| 114 selectElementWithMatcher:web::WebViewScrollView( | 115 selectElementWithMatcher:web::WebViewScrollView( |
| 115 chrome_test_util::GetCurrentWebState())] | 116 chrome_test_util::GetCurrentWebState())] |
| 116 assertWithMatcher:ContentOffset(CGPointMake(0, yOffset))]; | 117 assertWithMatcher:ContentOffset(CGPointMake(0, yOffset))]; |
| 117 } | 118 } |
| 118 | 119 |
| 119 // Verifies that the toolbar properly appears/disappears when scrolling up/down | 120 // Verifies that the toolbar properly appears/disappears when scrolling up/down |
| 120 // on a PDF that is short in length and wide in width. | 121 // on a PDF that is short in length and wide in width. |
| 121 - (void)testSmallWidePDFScroll { | 122 - (void)testSmallWidePDFScroll { |
| 122 web::test::SetUpFileBasedHttpServer(); | 123 web::test::SetUpFileBasedHttpServer(); |
| 123 GURL URL = web::test::HttpServer::MakeUrl( | 124 GURL URL = web::test::HttpServer::MakeUrl( |
| 124 "http://ios/testing/data/http_server_files/single_page_wide.pdf"); | 125 "http://ios/testing/data/http_server_files/single_page_wide.pdf"); |
| 125 [ChromeEarlGrey loadURL:URL]; | 126 [ChromeEarlGrey loadURL:URL]; |
| 126 | 127 |
| 127 // Test that the toolbar is still visible after a user swipes down. | 128 // Test that the toolbar is still visible after a user swipes down. |
| 128 [[EarlGrey | 129 [[EarlGrey |
| 129 selectElementWithMatcher:WebViewScrollView( | 130 selectElementWithMatcher:WebViewScrollView( |
| 130 chrome_test_util::GetCurrentWebState())] | 131 chrome_test_util::GetCurrentWebState())] |
| 131 performAction:grey_swipeFastInDirection(kGREYDirectionDown)]; | 132 performAction:grey_swipeFastInDirection(kGREYDirectionDown)]; |
| 132 chrome_test_util::AssertToolbarVisible(); | 133 GREYAssertTrue([ChromeEarlGreyUI waitForToolbarVisible:YES], |
| 134 @"Toolbar was not visible"); | |
| 133 | 135 |
| 134 // Test that the toolbar is no longer visible after a user swipes up. | 136 // Test that the toolbar is no longer visible after a user swipes up. |
| 135 HideToolbarUsingUI(); | 137 HideToolbarUsingUI(); |
| 136 chrome_test_util::AssertToolbarNotVisible(); | 138 GREYAssertTrue([ChromeEarlGreyUI waitForToolbarVisible:NO], |
| 139 @"Toolbar was visible"); | |
| 140 ; | |
|
Eugene But (OOO till 7-30)
2017/03/14 22:37:47
Extra semicolon. Same comment for many other place
baxley
2017/03/14 23:16:33
Done.
| |
| 137 } | 141 } |
| 138 | 142 |
| 139 // Verifies that the toolbar properly appears/disappears when scrolling up/down | 143 // Verifies that the toolbar properly appears/disappears when scrolling up/down |
| 140 // on a PDF that is long in length and wide in width. | 144 // on a PDF that is long in length and wide in width. |
| 141 - (void)testLongPDFScroll { | 145 - (void)testLongPDFScroll { |
| 142 web::test::SetUpFileBasedHttpServer(); | 146 web::test::SetUpFileBasedHttpServer(); |
| 143 GURL URL = web::test::HttpServer::MakeUrl( | 147 GURL URL = web::test::HttpServer::MakeUrl( |
| 144 "http://ios/testing/data/http_server_files/two_pages.pdf"); | 148 "http://ios/testing/data/http_server_files/two_pages.pdf"); |
| 145 [ChromeEarlGrey loadURL:URL]; | 149 [ChromeEarlGrey loadURL:URL]; |
| 146 | 150 |
| 147 // Test that the toolbar is hidden after a user swipes up. | 151 // Test that the toolbar is hidden after a user swipes up. |
| 148 HideToolbarUsingUI(); | 152 HideToolbarUsingUI(); |
| 149 chrome_test_util::AssertToolbarNotVisible(); | 153 GREYAssertTrue([ChromeEarlGreyUI waitForToolbarVisible:NO], |
| 154 @"Toolbar was visible"); | |
| 155 ; | |
| 150 | 156 |
| 151 // Test that the toolbar is visible after a user swipes down. | 157 // Test that the toolbar is visible after a user swipes down. |
| 152 [[EarlGrey | 158 [[EarlGrey |
| 153 selectElementWithMatcher:WebViewScrollView( | 159 selectElementWithMatcher:WebViewScrollView( |
| 154 chrome_test_util::GetCurrentWebState())] | 160 chrome_test_util::GetCurrentWebState())] |
| 155 performAction:grey_swipeFastInDirection(kGREYDirectionDown)]; | 161 performAction:grey_swipeFastInDirection(kGREYDirectionDown)]; |
| 156 chrome_test_util::AssertToolbarVisible(); | 162 GREYAssertTrue([ChromeEarlGreyUI waitForToolbarVisible:YES], |
| 163 @"Toolbar was not visible"); | |
| 157 | 164 |
| 158 // Test that the toolbar is hidden after a user swipes up. | 165 // Test that the toolbar is hidden after a user swipes up. |
| 159 HideToolbarUsingUI(); | 166 HideToolbarUsingUI(); |
| 160 chrome_test_util::AssertToolbarNotVisible(); | 167 GREYAssertTrue([ChromeEarlGreyUI waitForToolbarVisible:NO], |
| 168 @"Toolbar was visible"); | |
| 169 ; | |
| 161 } | 170 } |
| 162 | 171 |
| 163 // Tests that link clicks from a chrome:// to chrome:// link result in the | 172 // Tests that link clicks from a chrome:// to chrome:// link result in the |
| 164 // header being shown even if was not previously shown. | 173 // header being shown even if was not previously shown. |
| 165 - (void)testChromeToChromeURLKeepsHeaderOnScreen { | 174 - (void)testChromeToChromeURLKeepsHeaderOnScreen { |
| 166 const GURL kChromeAboutURL("chrome://chrome-urls"); | 175 const GURL kChromeAboutURL("chrome://chrome-urls"); |
| 167 [ChromeEarlGrey loadURL:kChromeAboutURL]; | 176 [ChromeEarlGrey loadURL:kChromeAboutURL]; |
| 168 | 177 |
| 169 AssertStringIsPresentOnPage("chrome://version"); | 178 AssertStringIsPresentOnPage("chrome://version"); |
| 170 | 179 |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 195 @"JavaScript to hide the toolbar did not complete"); | 204 @"JavaScript to hide the toolbar did not complete"); |
| 196 | 205 |
| 197 // Scroll up to be sure the toolbar can be dismissed by scrolling down. | 206 // Scroll up to be sure the toolbar can be dismissed by scrolling down. |
| 198 [[EarlGrey | 207 [[EarlGrey |
| 199 selectElementWithMatcher:WebViewScrollView( | 208 selectElementWithMatcher:WebViewScrollView( |
| 200 chrome_test_util::GetCurrentWebState())] | 209 chrome_test_util::GetCurrentWebState())] |
| 201 performAction:grey_swipeFastInDirection(kGREYDirectionDown)]; | 210 performAction:grey_swipeFastInDirection(kGREYDirectionDown)]; |
| 202 | 211 |
| 203 // Scroll to hide the UI. | 212 // Scroll to hide the UI. |
| 204 HideToolbarUsingUI(); | 213 HideToolbarUsingUI(); |
| 205 chrome_test_util::AssertToolbarNotVisible(); | 214 GREYAssertTrue([ChromeEarlGreyUI waitForToolbarVisible:NO], |
| 215 @"Toolbar was visible"); | |
| 216 ; | |
| 206 | 217 |
| 207 // Test that the toolbar is visible when moving from one chrome:// link to | 218 // Test that the toolbar is visible when moving from one chrome:// link to |
| 208 // another chrome:// link. | 219 // another chrome:// link. |
| 209 chrome_test_util::TapWebViewElementWithId("version"); | 220 chrome_test_util::TapWebViewElementWithId("version"); |
| 210 chrome_test_util::AssertToolbarVisible(); | 221 GREYAssertTrue([ChromeEarlGreyUI waitForToolbarVisible:YES], |
| 222 @"Toolbar was not visible"); | |
| 211 } | 223 } |
| 212 | 224 |
| 213 // Tests hiding and showing of the header with a user scroll on a long page. | 225 // Tests hiding and showing of the header with a user scroll on a long page. |
| 214 - (void)testHideHeaderUserScrollLongPage { | 226 - (void)testHideHeaderUserScrollLongPage { |
| 215 std::map<GURL, std::string> responses; | 227 std::map<GURL, std::string> responses; |
| 216 const GURL URL = web::test::HttpServer::MakeUrl("http://tallpage"); | 228 const GURL URL = web::test::HttpServer::MakeUrl("http://tallpage"); |
| 217 | 229 |
| 218 // A page long enough to ensure that the toolbar goes away on scrolling. | 230 // A page long enough to ensure that the toolbar goes away on scrolling. |
| 219 responses[URL] = "<p style='height:200em'>a</p><p>b</p>"; | 231 responses[URL] = "<p style='height:200em'>a</p><p>b</p>"; |
| 220 web::test::SetUpSimpleHttpServer(responses); | 232 web::test::SetUpSimpleHttpServer(responses); |
| 221 | 233 |
| 222 [ChromeEarlGrey loadURL:URL]; | 234 [ChromeEarlGrey loadURL:URL]; |
| 223 chrome_test_util::AssertToolbarVisible(); | 235 GREYAssertTrue([ChromeEarlGreyUI waitForToolbarVisible:YES], |
| 236 @"Toolbar was not visible"); | |
| 224 // Simulate a user scroll down. | 237 // Simulate a user scroll down. |
| 225 HideToolbarUsingUI(); | 238 HideToolbarUsingUI(); |
| 226 chrome_test_util::AssertToolbarNotVisible(); | 239 GREYAssertTrue([ChromeEarlGreyUI waitForToolbarVisible:NO], |
| 240 @"Toolbar was visible"); | |
| 241 ; | |
| 227 // Simulate a user scroll up. | 242 // Simulate a user scroll up. |
| 228 [[EarlGrey | 243 [[EarlGrey |
| 229 selectElementWithMatcher:WebViewScrollView( | 244 selectElementWithMatcher:WebViewScrollView( |
| 230 chrome_test_util::GetCurrentWebState())] | 245 chrome_test_util::GetCurrentWebState())] |
| 231 performAction:grey_swipeFastInDirection(kGREYDirectionDown)]; | 246 performAction:grey_swipeFastInDirection(kGREYDirectionDown)]; |
| 232 chrome_test_util::AssertToolbarVisible(); | 247 GREYAssertTrue([ChromeEarlGreyUI waitForToolbarVisible:YES], |
| 248 @"Toolbar was not visible"); | |
| 233 } | 249 } |
| 234 | 250 |
| 235 // Tests that reloading of a page shows the header even if it was not shown | 251 // Tests that reloading of a page shows the header even if it was not shown |
| 236 // previously. | 252 // previously. |
| 237 - (void)testShowHeaderOnReload { | 253 - (void)testShowHeaderOnReload { |
| 238 std::map<GURL, std::string> responses; | 254 std::map<GURL, std::string> responses; |
| 239 const GURL URL = web::test::HttpServer::MakeUrl("http://origin"); | 255 const GURL URL = web::test::HttpServer::MakeUrl("http://origin"); |
| 240 // This is a tall page -- necessary to make sure scrolling can hide away the | 256 // This is a tall page -- necessary to make sure scrolling can hide away the |
| 241 // toolbar safely-- and with a link to reload itself. | 257 // toolbar safely-- and with a link to reload itself. |
| 242 responses[URL] = | 258 responses[URL] = |
| 243 "<p style='height:200em'>Tall page</p>" | 259 "<p style='height:200em'>Tall page</p>" |
| 244 "<a onclick='window.location.reload();' id='link'>link</a>"; | 260 "<a onclick='window.location.reload();' id='link'>link</a>"; |
| 245 web::test::SetUpSimpleHttpServer(responses); | 261 web::test::SetUpSimpleHttpServer(responses); |
| 246 | 262 |
| 247 [ChromeEarlGrey loadURL:URL]; | 263 [ChromeEarlGrey loadURL:URL]; |
| 248 AssertStringIsPresentOnPage("Tall page"); | 264 AssertStringIsPresentOnPage("Tall page"); |
| 249 | 265 |
| 250 // Hide the toolbar. | 266 // Hide the toolbar. |
| 251 HideToolbarUsingUI(); | 267 HideToolbarUsingUI(); |
| 252 chrome_test_util::AssertToolbarNotVisible(); | 268 GREYAssertTrue([ChromeEarlGreyUI waitForToolbarVisible:NO], |
| 269 @"Toolbar was visible"); | |
| 270 ; | |
| 253 | 271 |
| 254 chrome_test_util::TapWebViewElementWithId("link"); | 272 chrome_test_util::TapWebViewElementWithId("link"); |
| 255 | 273 |
| 256 // Main test is here: Make sure the header is still visible! | 274 // Main test is here: Make sure the header is still visible! |
| 257 chrome_test_util::AssertToolbarVisible(); | 275 GREYAssertTrue([ChromeEarlGreyUI waitForToolbarVisible:YES], |
| 276 @"Toolbar was not visible"); | |
| 258 } | 277 } |
| 259 | 278 |
| 260 // Test to make sure the header is shown when a Tab opened by the current Tab is | 279 // Test to make sure the header is shown when a Tab opened by the current Tab is |
| 261 // closed even if the toolbar was not present previously. | 280 // closed even if the toolbar was not present previously. |
| 262 - (void)testShowHeaderWhenChildTabCloses { | 281 - (void)testShowHeaderWhenChildTabCloses { |
| 263 std::map<GURL, std::string> responses; | 282 std::map<GURL, std::string> responses; |
| 264 const GURL URL = web::test::HttpServer::MakeUrl("http://origin"); | 283 const GURL URL = web::test::HttpServer::MakeUrl("http://origin"); |
| 265 const GURL destinationURL = | 284 const GURL destinationURL = |
| 266 web::test::HttpServer::MakeUrl("http://destination"); | 285 web::test::HttpServer::MakeUrl("http://destination"); |
| 267 // JavaScript to open a window using window.open. | 286 // JavaScript to open a window using window.open. |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 283 | 302 |
| 284 web::test::SetUpSimpleHttpServer(responses); | 303 web::test::SetUpSimpleHttpServer(responses); |
| 285 chrome_test_util::SetContentSettingsBlockPopups(CONTENT_SETTING_ALLOW); | 304 chrome_test_util::SetContentSettingsBlockPopups(CONTENT_SETTING_ALLOW); |
| 286 | 305 |
| 287 [ChromeEarlGrey loadURL:URL]; | 306 [ChromeEarlGrey loadURL:URL]; |
| 288 AssertStringIsPresentOnPage("link1"); | 307 AssertStringIsPresentOnPage("link1"); |
| 289 chrome_test_util::AssertMainTabCount(1); | 308 chrome_test_util::AssertMainTabCount(1); |
| 290 | 309 |
| 291 // Hide the toolbar. | 310 // Hide the toolbar. |
| 292 HideToolbarUsingUI(); | 311 HideToolbarUsingUI(); |
| 293 chrome_test_util::AssertToolbarNotVisible(); | 312 GREYAssertTrue([ChromeEarlGreyUI waitForToolbarVisible:NO], |
| 313 @"Toolbar was visible"); | |
| 314 ; | |
| 294 | 315 |
| 295 // Open new window. | 316 // Open new window. |
| 296 chrome_test_util::TapWebViewElementWithId("link1"); | 317 chrome_test_util::TapWebViewElementWithId("link1"); |
| 297 | 318 |
| 298 // Check that a new Tab was created. | 319 // Check that a new Tab was created. |
| 299 AssertStringIsPresentOnPage("link2"); | 320 AssertStringIsPresentOnPage("link2"); |
| 300 chrome_test_util::AssertMainTabCount(2); | 321 chrome_test_util::AssertMainTabCount(2); |
| 301 | 322 |
| 302 AssertURLIs(destinationURL); | 323 AssertURLIs(destinationURL); |
| 303 | 324 |
| 304 // Hide the toolbar. | 325 // Hide the toolbar. |
| 305 HideToolbarUsingUI(); | 326 HideToolbarUsingUI(); |
| 306 chrome_test_util::AssertToolbarNotVisible(); | 327 GREYAssertTrue([ChromeEarlGreyUI waitForToolbarVisible:NO], |
| 328 @"Toolbar was visible"); | |
| 329 ; | |
| 307 | 330 |
| 308 // Close the tab. | 331 // Close the tab. |
| 309 chrome_test_util::TapWebViewElementWithId("link2"); | 332 chrome_test_util::TapWebViewElementWithId("link2"); |
| 310 AssertStringIsPresentOnPage("link1"); | 333 AssertStringIsPresentOnPage("link1"); |
| 311 | 334 |
| 312 // Make sure the toolbar is on the screen. | 335 // Make sure the toolbar is on the screen. |
| 313 chrome_test_util::AssertMainTabCount(1); | 336 chrome_test_util::AssertMainTabCount(1); |
| 314 chrome_test_util::AssertToolbarVisible(); | 337 GREYAssertTrue([ChromeEarlGreyUI waitForToolbarVisible:YES], |
| 338 @"Toolbar was not visible"); | |
| 315 } | 339 } |
| 316 | 340 |
| 317 // Tests that the header is shown when a regular page (non-native page) is | 341 // Tests that the header is shown when a regular page (non-native page) is |
| 318 // loaded from a page where the header was not see before. | 342 // loaded from a page where the header was not see before. |
| 319 // Also tests that auto-hide works correctly on new page loads. | 343 // Also tests that auto-hide works correctly on new page loads. |
| 320 - (void)testShowHeaderOnRegularPageLoad { | 344 - (void)testShowHeaderOnRegularPageLoad { |
| 321 std::map<GURL, std::string> responses; | 345 std::map<GURL, std::string> responses; |
| 322 const GURL originURL = web::test::HttpServer::MakeUrl("http://origin"); | 346 const GURL originURL = web::test::HttpServer::MakeUrl("http://origin"); |
| 323 const GURL destinationURL = | 347 const GURL destinationURL = |
| 324 web::test::HttpServer::MakeUrl("http://destination"); | 348 web::test::HttpServer::MakeUrl("http://destination"); |
| 325 | 349 |
| 326 const std::string manyLines = | 350 const std::string manyLines = |
| 327 "<p style='height:100em'>a</p><p>End of lines</p>"; | 351 "<p style='height:100em'>a</p><p>End of lines</p>"; |
| 328 | 352 |
| 329 // A long page representing many lines and a link to the destination URL page. | 353 // A long page representing many lines and a link to the destination URL page. |
| 330 responses[originURL] = manyLines + "<a href='" + destinationURL.spec() + | 354 responses[originURL] = manyLines + "<a href='" + destinationURL.spec() + |
| 331 "' id='link1'>link1</a>"; | 355 "' id='link1'>link1</a>"; |
| 332 // A long page representing many lines and a link to go back. | 356 // A long page representing many lines and a link to go back. |
| 333 responses[destinationURL] = manyLines + | 357 responses[destinationURL] = manyLines + |
| 334 "<a href='javascript:void(0)' " | 358 "<a href='javascript:void(0)' " |
| 335 "onclick='window.history.back()' " | 359 "onclick='window.history.back()' " |
| 336 "id='link2'>link2</a>"; | 360 "id='link2'>link2</a>"; |
| 337 web::test::SetUpSimpleHttpServer(responses); | 361 web::test::SetUpSimpleHttpServer(responses); |
| 338 | 362 |
| 339 [ChromeEarlGrey loadURL:originURL]; | 363 [ChromeEarlGrey loadURL:originURL]; |
| 340 | 364 |
| 341 AssertStringIsPresentOnPage("link1"); | 365 AssertStringIsPresentOnPage("link1"); |
| 342 // Dismiss the toolbar. | 366 // Dismiss the toolbar. |
| 343 HideToolbarUsingUI(); | 367 HideToolbarUsingUI(); |
| 344 chrome_test_util::AssertToolbarNotVisible(); | 368 GREYAssertTrue([ChromeEarlGreyUI waitForToolbarVisible:NO], |
| 369 @"Toolbar was visible"); | |
| 370 ; | |
| 345 | 371 |
| 346 // Navigate to the other page. | 372 // Navigate to the other page. |
| 347 chrome_test_util::TapWebViewElementWithId("link1"); | 373 chrome_test_util::TapWebViewElementWithId("link1"); |
| 348 AssertStringIsPresentOnPage("link2"); | 374 AssertStringIsPresentOnPage("link2"); |
| 349 | 375 |
| 350 // Make sure toolbar is shown since a new load has started. | 376 // Make sure toolbar is shown since a new load has started. |
| 351 chrome_test_util::AssertToolbarVisible(); | 377 GREYAssertTrue([ChromeEarlGreyUI waitForToolbarVisible:YES], |
| 378 @"Toolbar was not visible"); | |
| 352 | 379 |
| 353 // Dismiss the toolbar. | 380 // Dismiss the toolbar. |
| 354 HideToolbarUsingUI(); | 381 HideToolbarUsingUI(); |
| 355 chrome_test_util::AssertToolbarNotVisible(); | 382 GREYAssertTrue([ChromeEarlGreyUI waitForToolbarVisible:NO], |
| 383 @"Toolbar was visible"); | |
| 384 ; | |
| 356 | 385 |
| 357 // Go back. | 386 // Go back. |
| 358 chrome_test_util::TapWebViewElementWithId("link2"); | 387 chrome_test_util::TapWebViewElementWithId("link2"); |
| 359 | 388 |
| 360 // Make sure the toolbar has loaded now that a new page has loaded. | 389 // Make sure the toolbar has loaded now that a new page has loaded. |
| 361 chrome_test_util::AssertToolbarVisible(); | 390 GREYAssertTrue([ChromeEarlGreyUI waitForToolbarVisible:YES], |
| 391 @"Toolbar was not visible"); | |
| 362 } | 392 } |
| 363 | 393 |
| 364 // Tests that the header is shown when a native page is loaded from a page where | 394 // Tests that the header is shown when a native page is loaded from a page where |
| 365 // the header was not seen before. | 395 // the header was not seen before. |
| 366 - (void)testShowHeaderOnNativePageLoad { | 396 - (void)testShowHeaderOnNativePageLoad { |
| 367 std::map<GURL, std::string> responses; | 397 std::map<GURL, std::string> responses; |
| 368 const GURL URL = web::test::HttpServer::MakeUrl("http://origin"); | 398 const GURL URL = web::test::HttpServer::MakeUrl("http://origin"); |
| 369 | 399 |
| 370 // A long page representing many lines and a link to go back. | 400 // A long page representing many lines and a link to go back. |
| 371 std::string manyLines = | 401 std::string manyLines = |
| 372 "<p style='height:100em'>a</p>" | 402 "<p style='height:100em'>a</p>" |
| 373 "<a onclick='window.history.back()' id='link'>link</a>"; | 403 "<a onclick='window.history.back()' id='link'>link</a>"; |
| 374 responses[URL] = manyLines; | 404 responses[URL] = manyLines; |
| 375 web::test::SetUpSimpleHttpServer(responses); | 405 web::test::SetUpSimpleHttpServer(responses); |
| 376 | 406 |
| 377 [ChromeEarlGrey loadURL:URL]; | 407 [ChromeEarlGrey loadURL:URL]; |
| 378 AssertStringIsPresentOnPage("link"); | 408 AssertStringIsPresentOnPage("link"); |
| 379 | 409 |
| 380 // Dismiss the toolbar. | 410 // Dismiss the toolbar. |
| 381 HideToolbarUsingUI(); | 411 HideToolbarUsingUI(); |
| 382 chrome_test_util::AssertToolbarNotVisible(); | 412 GREYAssertTrue([ChromeEarlGreyUI waitForToolbarVisible:NO], |
| 413 @"Toolbar was visible"); | |
| 414 ; | |
| 383 | 415 |
| 384 // Go back to NTP, which is a native view. | 416 // Go back to NTP, which is a native view. |
| 385 chrome_test_util::TapWebViewElementWithId("link"); | 417 chrome_test_util::TapWebViewElementWithId("link"); |
| 386 | 418 |
| 387 // Make sure the toolbar is visible now that a new page has loaded. | 419 // Make sure the toolbar is visible now that a new page has loaded. |
| 388 chrome_test_util::AssertToolbarVisible(); | 420 GREYAssertTrue([ChromeEarlGreyUI waitForToolbarVisible:YES], |
| 421 @"Toolbar was not visible"); | |
| 389 } | 422 } |
| 390 | 423 |
| 391 // Tests that the header is shown when loading an error page in a native view | 424 // Tests that the header is shown when loading an error page in a native view |
| 392 // even if fullscreen was enabled previously. | 425 // even if fullscreen was enabled previously. |
| 393 - (void)testShowHeaderOnErrorPage { | 426 - (void)testShowHeaderOnErrorPage { |
| 394 std::map<GURL, std::string> responses; | 427 std::map<GURL, std::string> responses; |
| 395 const GURL URL = web::test::HttpServer::MakeUrl("http://origin"); | 428 const GURL URL = web::test::HttpServer::MakeUrl("http://origin"); |
| 396 // A long page with some simple text -- a long page is necessary so that | 429 // A long page with some simple text -- a long page is necessary so that |
| 397 // enough content is present to ensure that the toolbar can be hidden safely. | 430 // enough content is present to ensure that the toolbar can be hidden safely. |
| 398 responses[URL] = base::StringPrintf( | 431 responses[URL] = base::StringPrintf( |
| 399 "<p style='height:100em'>a</p>" | 432 "<p style='height:100em'>a</p>" |
| 400 "<a href=\"%s\" id=\"link\">bad link</a>", | 433 "<a href=\"%s\" id=\"link\">bad link</a>", |
| 401 ErrorPageResponseProvider::GetDnsFailureUrl().spec().c_str()); | 434 ErrorPageResponseProvider::GetDnsFailureUrl().spec().c_str()); |
| 402 std::unique_ptr<web::DataResponseProvider> provider( | 435 std::unique_ptr<web::DataResponseProvider> provider( |
| 403 new ErrorPageResponseProvider(responses)); | 436 new ErrorPageResponseProvider(responses)); |
| 404 web::test::SetUpHttpServer(std::move(provider)); | 437 web::test::SetUpHttpServer(std::move(provider)); |
| 405 | 438 |
| 406 [ChromeEarlGrey loadURL:URL]; | 439 [ChromeEarlGrey loadURL:URL]; |
| 407 HideToolbarUsingUI(); | 440 HideToolbarUsingUI(); |
| 408 chrome_test_util::AssertToolbarNotVisible(); | 441 GREYAssertTrue([ChromeEarlGreyUI waitForToolbarVisible:NO], |
| 442 @"Toolbar was visible"); | |
| 443 ; | |
| 409 | 444 |
| 410 chrome_test_util::TapWebViewElementWithId("link"); | 445 chrome_test_util::TapWebViewElementWithId("link"); |
| 411 AssertURLIs(ErrorPageResponseProvider::GetDnsFailureUrl()); | 446 AssertURLIs(ErrorPageResponseProvider::GetDnsFailureUrl()); |
| 412 chrome_test_util::AssertToolbarVisible(); | 447 GREYAssertTrue([ChromeEarlGreyUI waitForToolbarVisible:YES], |
| 448 @"Toolbar was not visible"); | |
| 413 } | 449 } |
| 414 | 450 |
| 415 @end | 451 @end |
| OLD | NEW |