| 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/chrome/test/earl_grey/chrome_util.h" |
| 23 #import "ios/testing/wait_util.h" | 24 #import "ios/testing/wait_util.h" |
| 24 #import "ios/web/public/test/earl_grey/web_view_matchers.h" | 25 #import "ios/web/public/test/earl_grey/web_view_matchers.h" |
| 25 #import "ios/web/public/test/http_server.h" | 26 #import "ios/web/public/test/http_server.h" |
| 26 #import "ios/web/public/test/http_server_util.h" | 27 #import "ios/web/public/test/http_server_util.h" |
| 27 #import "ios/web/public/test/response_providers/error_page_response_provider.h" | 28 #import "ios/web/public/test/response_providers/error_page_response_provider.h" |
| 28 #import "ios/web/public/test/web_view_interaction_test_util.h" | 29 #import "ios/web/public/test/web_view_interaction_test_util.h" |
| 29 #include "url/gurl.h" | 30 #include "url/gurl.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 45 DescribeToBlock describe = ^(id<GREYDescription> description) { | 46 DescribeToBlock describe = ^(id<GREYDescription> description) { |
| 46 [description appendText:@"contentOffset"]; | 47 [description appendText:@"contentOffset"]; |
| 47 }; | 48 }; |
| 48 return grey_allOf( | 49 return grey_allOf( |
| 49 grey_kindOfClass([UIScrollView class]), | 50 grey_kindOfClass([UIScrollView class]), |
| 50 [[GREYElementMatcherBlock alloc] initWithMatchesBlock:matches | 51 [[GREYElementMatcherBlock alloc] initWithMatchesBlock:matches |
| 51 descriptionBlock:describe], | 52 descriptionBlock:describe], |
| 52 nil); | 53 nil); |
| 53 } | 54 } |
| 54 | 55 |
| 55 // Hides the toolbar by scrolling down. | |
| 56 void HideToolbarUsingUI() { | |
| 57 [[EarlGrey | |
| 58 selectElementWithMatcher:WebViewScrollView( | |
| 59 chrome_test_util::GetCurrentWebState())] | |
| 60 performAction:grey_swipeFastInDirection(kGREYDirectionUp)]; | |
| 61 } | |
| 62 | |
| 63 // Asserts that the current URL is the |expectedURL| one. | 56 // Asserts that the current URL is the |expectedURL| one. |
| 64 void AssertURLIs(const GURL& expectedURL) { | 57 void AssertURLIs(const GURL& expectedURL) { |
| 65 NSString* description = [NSString | 58 NSString* description = [NSString |
| 66 stringWithFormat:@"Timeout waiting for the url to be %@", | 59 stringWithFormat:@"Timeout waiting for the url to be %@", |
| 67 base::SysUTF8ToNSString(expectedURL.GetContent())]; | 60 base::SysUTF8ToNSString(expectedURL.GetContent())]; |
| 68 | 61 |
| 69 ConditionBlock condition = ^{ | 62 ConditionBlock condition = ^{ |
| 70 NSError* error = nil; | 63 NSError* error = nil; |
| 71 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( | 64 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( |
| 72 expectedURL.GetContent())] | 65 expectedURL.GetContent())] |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 | 111 |
| 119 // Verifies that the toolbar properly appears/disappears when scrolling up/down | 112 // Verifies that the toolbar properly appears/disappears when scrolling up/down |
| 120 // on a PDF that is short in length and wide in width. | 113 // on a PDF that is short in length and wide in width. |
| 121 - (void)testSmallWidePDFScroll { | 114 - (void)testSmallWidePDFScroll { |
| 122 web::test::SetUpFileBasedHttpServer(); | 115 web::test::SetUpFileBasedHttpServer(); |
| 123 GURL URL = web::test::HttpServer::MakeUrl( | 116 GURL URL = web::test::HttpServer::MakeUrl( |
| 124 "http://ios/testing/data/http_server_files/single_page_wide.pdf"); | 117 "http://ios/testing/data/http_server_files/single_page_wide.pdf"); |
| 125 [ChromeEarlGrey loadURL:URL]; | 118 [ChromeEarlGrey loadURL:URL]; |
| 126 | 119 |
| 127 // Test that the toolbar is still visible after a user swipes down. | 120 // Test that the toolbar is still visible after a user swipes down. |
| 128 [[EarlGrey | 121 [ChromeEarlGreyUI swipeDownOnWebView]; |
| 129 selectElementWithMatcher:WebViewScrollView( | |
| 130 chrome_test_util::GetCurrentWebState())] | |
| 131 performAction:grey_swipeFastInDirection(kGREYDirectionDown)]; | |
| 132 chrome_test_util::AssertToolbarVisible(); | 122 chrome_test_util::AssertToolbarVisible(); |
| 133 | 123 |
| 134 // Test that the toolbar is no longer visible after a user swipes up. | 124 // Test that the toolbar is no longer visible after a user swipes up. |
| 135 HideToolbarUsingUI(); | 125 [ChromeEarlGreyUI swipeUpOnWebView]; |
| 136 chrome_test_util::AssertToolbarNotVisible(); | 126 chrome_test_util::AssertToolbarNotVisible(); |
| 137 } | 127 } |
| 138 | 128 |
| 139 // Verifies that the toolbar properly appears/disappears when scrolling up/down | 129 // Verifies that the toolbar properly appears/disappears when scrolling up/down |
| 140 // on a PDF that is long in length and wide in width. | 130 // on a PDF that is long in length and wide in width. |
| 141 - (void)testLongPDFScroll { | 131 - (void)testLongPDFScroll { |
| 142 web::test::SetUpFileBasedHttpServer(); | 132 web::test::SetUpFileBasedHttpServer(); |
| 143 GURL URL = web::test::HttpServer::MakeUrl( | 133 GURL URL = web::test::HttpServer::MakeUrl( |
| 144 "http://ios/testing/data/http_server_files/two_pages.pdf"); | 134 "http://ios/testing/data/http_server_files/two_pages.pdf"); |
| 145 [ChromeEarlGrey loadURL:URL]; | 135 [ChromeEarlGrey loadURL:URL]; |
| 146 | 136 |
| 147 // Test that the toolbar is hidden after a user swipes up. | 137 // Test that the toolbar is hidden after a user swipes up. |
| 148 HideToolbarUsingUI(); | 138 [ChromeEarlGreyUI swipeUpOnWebView]; |
| 149 chrome_test_util::AssertToolbarNotVisible(); | 139 chrome_test_util::AssertToolbarNotVisible(); |
| 150 | 140 |
| 151 // Test that the toolbar is visible after a user swipes down. | 141 // Test that the toolbar is visible after a user swipes down. |
| 152 [[EarlGrey | 142 [ChromeEarlGreyUI swipeDownOnWebView]; |
| 153 selectElementWithMatcher:WebViewScrollView( | |
| 154 chrome_test_util::GetCurrentWebState())] | |
| 155 performAction:grey_swipeFastInDirection(kGREYDirectionDown)]; | |
| 156 chrome_test_util::AssertToolbarVisible(); | 143 chrome_test_util::AssertToolbarVisible(); |
| 157 | 144 |
| 158 // Test that the toolbar is hidden after a user swipes up. | 145 // Test that the toolbar is hidden after a user swipes up. |
| 159 HideToolbarUsingUI(); | 146 [ChromeEarlGreyUI swipeUpOnWebView]; |
| 160 chrome_test_util::AssertToolbarNotVisible(); | 147 chrome_test_util::AssertToolbarNotVisible(); |
| 161 } | 148 } |
| 162 | 149 |
| 163 // Tests that link clicks from a chrome:// to chrome:// link result in the | 150 // Tests that link clicks from a chrome:// to chrome:// link result in the |
| 164 // header being shown even if was not previously shown. | 151 // header being shown even if was not previously shown. |
| 165 - (void)testChromeToChromeURLKeepsHeaderOnScreen { | 152 - (void)testChromeToChromeURLKeepsHeaderOnScreen { |
| 166 const GURL kChromeAboutURL("chrome://chrome-urls"); | 153 const GURL kChromeAboutURL("chrome://chrome-urls"); |
| 167 [ChromeEarlGrey loadURL:kChromeAboutURL]; | 154 [ChromeEarlGrey loadURL:kChromeAboutURL]; |
| 168 | 155 |
| 169 AssertStringIsPresentOnPage("chrome://version"); | 156 AssertStringIsPresentOnPage("chrome://version"); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 188 finished = true; | 175 finished = true; |
| 189 })); | 176 })); |
| 190 | 177 |
| 191 GREYAssert(testing::WaitUntilConditionOrTimeout(1.0, | 178 GREYAssert(testing::WaitUntilConditionOrTimeout(1.0, |
| 192 ^{ | 179 ^{ |
| 193 return finished; | 180 return finished; |
| 194 }), | 181 }), |
| 195 @"JavaScript to hide the toolbar did not complete"); | 182 @"JavaScript to hide the toolbar did not complete"); |
| 196 | 183 |
| 197 // Scroll up to be sure the toolbar can be dismissed by scrolling down. | 184 // Scroll up to be sure the toolbar can be dismissed by scrolling down. |
| 198 [[EarlGrey | 185 [ChromeEarlGreyUI swipeDownOnWebView]; |
| 199 selectElementWithMatcher:WebViewScrollView( | |
| 200 chrome_test_util::GetCurrentWebState())] | |
| 201 performAction:grey_swipeFastInDirection(kGREYDirectionDown)]; | |
| 202 | 186 |
| 203 // Scroll to hide the UI. | 187 // Scroll to hide the UI. |
| 204 HideToolbarUsingUI(); | 188 [ChromeEarlGreyUI swipeUpOnWebView]; |
| 205 chrome_test_util::AssertToolbarNotVisible(); | 189 chrome_test_util::AssertToolbarNotVisible(); |
| 206 | 190 |
| 207 // Test that the toolbar is visible when moving from one chrome:// link to | 191 // Test that the toolbar is visible when moving from one chrome:// link to |
| 208 // another chrome:// link. | 192 // another chrome:// link. |
| 209 chrome_test_util::TapWebViewElementWithId("version"); | 193 chrome_test_util::TapWebViewElementWithId("version"); |
| 210 chrome_test_util::AssertToolbarVisible(); | 194 chrome_test_util::AssertToolbarVisible(); |
| 211 } | 195 } |
| 212 | 196 |
| 213 // Tests hiding and showing of the header with a user scroll on a long page. | 197 // Tests hiding and showing of the header with a user scroll on a long page. |
| 214 - (void)testHideHeaderUserScrollLongPage { | 198 - (void)testHideHeaderUserScrollLongPage { |
| 215 std::map<GURL, std::string> responses; | 199 std::map<GURL, std::string> responses; |
| 216 const GURL URL = web::test::HttpServer::MakeUrl("http://tallpage"); | 200 const GURL URL = web::test::HttpServer::MakeUrl("http://tallpage"); |
| 217 | 201 |
| 218 // A page long enough to ensure that the toolbar goes away on scrolling. | 202 // 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>"; | 203 responses[URL] = "<p style='height:200em'>a</p><p>b</p>"; |
| 220 web::test::SetUpSimpleHttpServer(responses); | 204 web::test::SetUpSimpleHttpServer(responses); |
| 221 | 205 |
| 222 [ChromeEarlGrey loadURL:URL]; | 206 [ChromeEarlGrey loadURL:URL]; |
| 223 chrome_test_util::AssertToolbarVisible(); | 207 chrome_test_util::AssertToolbarVisible(); |
| 224 // Simulate a user scroll down. | 208 // Simulate a user scroll down. |
| 225 HideToolbarUsingUI(); | 209 [ChromeEarlGreyUI swipeUpOnWebView]; |
| 226 chrome_test_util::AssertToolbarNotVisible(); | 210 chrome_test_util::AssertToolbarNotVisible(); |
| 227 // Simulate a user scroll up. | 211 // Simulate a user scroll up. |
| 228 [[EarlGrey | 212 [ChromeEarlGreyUI swipeDownOnWebView]; |
| 229 selectElementWithMatcher:WebViewScrollView( | |
| 230 chrome_test_util::GetCurrentWebState())] | |
| 231 performAction:grey_swipeFastInDirection(kGREYDirectionDown)]; | |
| 232 chrome_test_util::AssertToolbarVisible(); | 213 chrome_test_util::AssertToolbarVisible(); |
| 233 } | 214 } |
| 234 | 215 |
| 235 // Tests that reloading of a page shows the header even if it was not shown | 216 // Tests that reloading of a page shows the header even if it was not shown |
| 236 // previously. | 217 // previously. |
| 237 - (void)testShowHeaderOnReload { | 218 - (void)testShowHeaderOnReload { |
| 238 std::map<GURL, std::string> responses; | 219 std::map<GURL, std::string> responses; |
| 239 const GURL URL = web::test::HttpServer::MakeUrl("http://origin"); | 220 const GURL URL = web::test::HttpServer::MakeUrl("http://origin"); |
| 240 // This is a tall page -- necessary to make sure scrolling can hide away the | 221 // This is a tall page -- necessary to make sure scrolling can hide away the |
| 241 // toolbar safely-- and with a link to reload itself. | 222 // toolbar safely-- and with a link to reload itself. |
| 242 responses[URL] = | 223 responses[URL] = |
| 243 "<p style='height:200em'>Tall page</p>" | 224 "<p style='height:200em'>Tall page</p>" |
| 244 "<a onclick='window.location.reload();' id='link'>link</a>"; | 225 "<a onclick='window.location.reload();' id='link'>link</a>"; |
| 245 web::test::SetUpSimpleHttpServer(responses); | 226 web::test::SetUpSimpleHttpServer(responses); |
| 246 | 227 |
| 247 [ChromeEarlGrey loadURL:URL]; | 228 [ChromeEarlGrey loadURL:URL]; |
| 248 AssertStringIsPresentOnPage("Tall page"); | 229 AssertStringIsPresentOnPage("Tall page"); |
| 249 | 230 |
| 250 // Hide the toolbar. | 231 // Hide the toolbar. |
| 251 HideToolbarUsingUI(); | 232 [ChromeEarlGreyUI swipeUpOnWebView]; |
| 252 chrome_test_util::AssertToolbarNotVisible(); | 233 chrome_test_util::AssertToolbarNotVisible(); |
| 253 | 234 |
| 254 chrome_test_util::TapWebViewElementWithId("link"); | 235 chrome_test_util::TapWebViewElementWithId("link"); |
| 255 | 236 |
| 256 // Main test is here: Make sure the header is still visible! | 237 // Main test is here: Make sure the header is still visible! |
| 257 chrome_test_util::AssertToolbarVisible(); | 238 chrome_test_util::AssertToolbarVisible(); |
| 258 } | 239 } |
| 259 | 240 |
| 260 // Test to make sure the header is shown when a Tab opened by the current Tab is | 241 // 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. | 242 // closed even if the toolbar was not present previously. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 282 javaScript.c_str()); | 263 javaScript.c_str()); |
| 283 | 264 |
| 284 web::test::SetUpSimpleHttpServer(responses); | 265 web::test::SetUpSimpleHttpServer(responses); |
| 285 chrome_test_util::SetContentSettingsBlockPopups(CONTENT_SETTING_ALLOW); | 266 chrome_test_util::SetContentSettingsBlockPopups(CONTENT_SETTING_ALLOW); |
| 286 | 267 |
| 287 [ChromeEarlGrey loadURL:URL]; | 268 [ChromeEarlGrey loadURL:URL]; |
| 288 AssertStringIsPresentOnPage("link1"); | 269 AssertStringIsPresentOnPage("link1"); |
| 289 chrome_test_util::AssertMainTabCount(1); | 270 chrome_test_util::AssertMainTabCount(1); |
| 290 | 271 |
| 291 // Hide the toolbar. | 272 // Hide the toolbar. |
| 292 HideToolbarUsingUI(); | 273 [ChromeEarlGreyUI swipeUpOnWebView]; |
| 293 chrome_test_util::AssertToolbarNotVisible(); | 274 chrome_test_util::AssertToolbarNotVisible(); |
| 294 | 275 |
| 295 // Open new window. | 276 // Open new window. |
| 296 chrome_test_util::TapWebViewElementWithId("link1"); | 277 chrome_test_util::TapWebViewElementWithId("link1"); |
| 297 | 278 |
| 298 // Check that a new Tab was created. | 279 // Check that a new Tab was created. |
| 299 AssertStringIsPresentOnPage("link2"); | 280 AssertStringIsPresentOnPage("link2"); |
| 300 chrome_test_util::AssertMainTabCount(2); | 281 chrome_test_util::AssertMainTabCount(2); |
| 301 | 282 |
| 302 AssertURLIs(destinationURL); | 283 AssertURLIs(destinationURL); |
| 303 | 284 |
| 304 // Hide the toolbar. | 285 // Hide the toolbar. |
| 305 HideToolbarUsingUI(); | 286 [ChromeEarlGreyUI swipeUpOnWebView]; |
| 306 chrome_test_util::AssertToolbarNotVisible(); | 287 chrome_test_util::AssertToolbarNotVisible(); |
| 307 | 288 |
| 308 // Close the tab. | 289 // Close the tab. |
| 309 chrome_test_util::TapWebViewElementWithId("link2"); | 290 chrome_test_util::TapWebViewElementWithId("link2"); |
| 310 AssertStringIsPresentOnPage("link1"); | 291 AssertStringIsPresentOnPage("link1"); |
| 311 | 292 |
| 312 // Make sure the toolbar is on the screen. | 293 // Make sure the toolbar is on the screen. |
| 313 chrome_test_util::AssertMainTabCount(1); | 294 chrome_test_util::AssertMainTabCount(1); |
| 314 chrome_test_util::AssertToolbarVisible(); | 295 chrome_test_util::AssertToolbarVisible(); |
| 315 } | 296 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 333 responses[destinationURL] = manyLines + | 314 responses[destinationURL] = manyLines + |
| 334 "<a href='javascript:void(0)' " | 315 "<a href='javascript:void(0)' " |
| 335 "onclick='window.history.back()' " | 316 "onclick='window.history.back()' " |
| 336 "id='link2'>link2</a>"; | 317 "id='link2'>link2</a>"; |
| 337 web::test::SetUpSimpleHttpServer(responses); | 318 web::test::SetUpSimpleHttpServer(responses); |
| 338 | 319 |
| 339 [ChromeEarlGrey loadURL:originURL]; | 320 [ChromeEarlGrey loadURL:originURL]; |
| 340 | 321 |
| 341 AssertStringIsPresentOnPage("link1"); | 322 AssertStringIsPresentOnPage("link1"); |
| 342 // Dismiss the toolbar. | 323 // Dismiss the toolbar. |
| 343 HideToolbarUsingUI(); | 324 [ChromeEarlGreyUI swipeUpOnWebView]; |
| 344 chrome_test_util::AssertToolbarNotVisible(); | 325 chrome_test_util::AssertToolbarNotVisible(); |
| 345 | 326 |
| 346 // Navigate to the other page. | 327 // Navigate to the other page. |
| 347 chrome_test_util::TapWebViewElementWithId("link1"); | 328 chrome_test_util::TapWebViewElementWithId("link1"); |
| 348 AssertStringIsPresentOnPage("link2"); | 329 AssertStringIsPresentOnPage("link2"); |
| 349 | 330 |
| 350 // Make sure toolbar is shown since a new load has started. | 331 // Make sure toolbar is shown since a new load has started. |
| 351 chrome_test_util::AssertToolbarVisible(); | 332 chrome_test_util::AssertToolbarVisible(); |
| 352 | 333 |
| 353 // Dismiss the toolbar. | 334 // Dismiss the toolbar. |
| 354 HideToolbarUsingUI(); | 335 [ChromeEarlGreyUI swipeUpOnWebView]; |
| 355 chrome_test_util::AssertToolbarNotVisible(); | 336 chrome_test_util::AssertToolbarNotVisible(); |
| 356 | 337 |
| 357 // Go back. | 338 // Go back. |
| 358 chrome_test_util::TapWebViewElementWithId("link2"); | 339 chrome_test_util::TapWebViewElementWithId("link2"); |
| 359 | 340 |
| 360 // Make sure the toolbar has loaded now that a new page has loaded. | 341 // Make sure the toolbar has loaded now that a new page has loaded. |
| 361 chrome_test_util::AssertToolbarVisible(); | 342 chrome_test_util::AssertToolbarVisible(); |
| 362 } | 343 } |
| 363 | 344 |
| 364 // Tests that the header is shown when a native page is loaded from a page where | 345 // Tests that the header is shown when a native page is loaded from a page where |
| 365 // the header was not seen before. | 346 // the header was not seen before. |
| 366 - (void)testShowHeaderOnNativePageLoad { | 347 - (void)testShowHeaderOnNativePageLoad { |
| 367 std::map<GURL, std::string> responses; | 348 std::map<GURL, std::string> responses; |
| 368 const GURL URL = web::test::HttpServer::MakeUrl("http://origin"); | 349 const GURL URL = web::test::HttpServer::MakeUrl("http://origin"); |
| 369 | 350 |
| 370 // A long page representing many lines and a link to go back. | 351 // A long page representing many lines and a link to go back. |
| 371 std::string manyLines = | 352 std::string manyLines = |
| 372 "<p style='height:100em'>a</p>" | 353 "<p style='height:100em'>a</p>" |
| 373 "<a onclick='window.history.back()' id='link'>link</a>"; | 354 "<a onclick='window.history.back()' id='link'>link</a>"; |
| 374 responses[URL] = manyLines; | 355 responses[URL] = manyLines; |
| 375 web::test::SetUpSimpleHttpServer(responses); | 356 web::test::SetUpSimpleHttpServer(responses); |
| 376 | 357 |
| 377 [ChromeEarlGrey loadURL:URL]; | 358 [ChromeEarlGrey loadURL:URL]; |
| 378 AssertStringIsPresentOnPage("link"); | 359 AssertStringIsPresentOnPage("link"); |
| 379 | 360 |
| 380 // Dismiss the toolbar. | 361 // Dismiss the toolbar. |
| 381 HideToolbarUsingUI(); | 362 [ChromeEarlGreyUI swipeUpOnWebView]; |
| 382 chrome_test_util::AssertToolbarNotVisible(); | 363 chrome_test_util::AssertToolbarNotVisible(); |
| 383 | 364 |
| 384 // Go back to NTP, which is a native view. | 365 // Go back to NTP, which is a native view. |
| 385 chrome_test_util::TapWebViewElementWithId("link"); | 366 chrome_test_util::TapWebViewElementWithId("link"); |
| 386 | 367 |
| 387 // Make sure the toolbar is visible now that a new page has loaded. | 368 // Make sure the toolbar is visible now that a new page has loaded. |
| 388 chrome_test_util::AssertToolbarVisible(); | 369 chrome_test_util::AssertToolbarVisible(); |
| 389 } | 370 } |
| 390 | 371 |
| 391 // Tests that the header is shown when loading an error page in a native view | 372 // Tests that the header is shown when loading an error page in a native view |
| 392 // even if fullscreen was enabled previously. | 373 // even if fullscreen was enabled previously. |
| 393 - (void)testShowHeaderOnErrorPage { | 374 - (void)testShowHeaderOnErrorPage { |
| 394 std::map<GURL, std::string> responses; | 375 std::map<GURL, std::string> responses; |
| 395 const GURL URL = web::test::HttpServer::MakeUrl("http://origin"); | 376 const GURL URL = web::test::HttpServer::MakeUrl("http://origin"); |
| 396 // A long page with some simple text -- a long page is necessary so that | 377 // 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. | 378 // enough content is present to ensure that the toolbar can be hidden safely. |
| 398 responses[URL] = base::StringPrintf( | 379 responses[URL] = base::StringPrintf( |
| 399 "<p style='height:100em'>a</p>" | 380 "<p style='height:100em'>a</p>" |
| 400 "<a href=\"%s\" id=\"link\">bad link</a>", | 381 "<a href=\"%s\" id=\"link\">bad link</a>", |
| 401 ErrorPageResponseProvider::GetDnsFailureUrl().spec().c_str()); | 382 ErrorPageResponseProvider::GetDnsFailureUrl().spec().c_str()); |
| 402 std::unique_ptr<web::DataResponseProvider> provider( | 383 std::unique_ptr<web::DataResponseProvider> provider( |
| 403 new ErrorPageResponseProvider(responses)); | 384 new ErrorPageResponseProvider(responses)); |
| 404 web::test::SetUpHttpServer(std::move(provider)); | 385 web::test::SetUpHttpServer(std::move(provider)); |
| 405 | 386 |
| 406 [ChromeEarlGrey loadURL:URL]; | 387 [ChromeEarlGrey loadURL:URL]; |
| 407 HideToolbarUsingUI(); | 388 [ChromeEarlGreyUI swipeUpOnWebView]; |
| 408 chrome_test_util::AssertToolbarNotVisible(); | 389 chrome_test_util::AssertToolbarNotVisible(); |
| 409 | 390 |
| 410 chrome_test_util::TapWebViewElementWithId("link"); | 391 chrome_test_util::TapWebViewElementWithId("link"); |
| 411 AssertURLIs(ErrorPageResponseProvider::GetDnsFailureUrl()); | 392 AssertURLIs(ErrorPageResponseProvider::GetDnsFailureUrl()); |
| 412 chrome_test_util::AssertToolbarVisible(); | 393 chrome_test_util::AssertToolbarVisible(); |
| 413 } | 394 } |
| 414 | 395 |
| 415 @end | 396 @end |
| OLD | NEW |