| 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 #include "core/frame/FrameHost.h" | 5 #include "core/frame/FrameHost.h" |
| 6 #include "core/frame/FrameView.h" | 6 #include "core/frame/FrameView.h" |
| 7 #include "core/frame/TopControls.h" | 7 #include "core/frame/TopControls.h" |
| 8 #include "core/html/HTMLFrameOwnerElement.h" | 8 #include "core/html/HTMLFrameOwnerElement.h" |
| 9 #include "core/page/Page.h" | 9 #include "core/page/Page.h" |
| 10 #include "platform/testing/URLTestHelpers.h" | 10 #include "platform/testing/URLTestHelpers.h" |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 // Test that no root scroller element is set if setRootScroller isn't called on | 165 // Test that no root scroller element is set if setRootScroller isn't called on |
| 166 // any elements. The document element should be the default effective root | 166 // any elements. The document element should be the default effective root |
| 167 // scroller. | 167 // scroller. |
| 168 TEST_F(RootScrollerTest, TestDefaultRootScroller) | 168 TEST_F(RootScrollerTest, TestDefaultRootScroller) |
| 169 { | 169 { |
| 170 initialize("overflow-scrolling.html"); | 170 initialize("overflow-scrolling.html"); |
| 171 | 171 |
| 172 ASSERT_EQ(nullptr, mainFrame()->document()->rootScroller()); | 172 ASSERT_EQ(nullptr, mainFrame()->document()->rootScroller()); |
| 173 | 173 |
| 174 Element* htmlElement = mainFrame()->document()->documentElement(); | 174 Element* htmlElement = mainFrame()->document()->documentElement(); |
| 175 EXPECT_TRUE(mainFrame()->document()->isEffectiveRootScroller(*htmlElement)); | 175 EXPECT_EQ(htmlElement, mainFrame()->document()->effectiveRootScroller()); |
| 176 } | 176 } |
| 177 | 177 |
| 178 // Tests that setting an element as the root scroller causes it to control url | 178 // Tests that setting an element as the root scroller causes it to control url |
| 179 // bar hiding and overscroll. | 179 // bar hiding and overscroll. |
| 180 TEST_F(RootScrollerTest, TestSetRootScroller) | 180 TEST_F(RootScrollerTest, TestSetRootScroller) |
| 181 { | 181 { |
| 182 initialize("root-scroller.html"); | 182 initialize("root-scroller.html"); |
| 183 | 183 |
| 184 Element* container = mainFrame()->document()->getElementById("container"); | 184 Element* container = mainFrame()->document()->getElementById("container"); |
| 185 TrackExceptionState exceptionState; | 185 TrackExceptionState exceptionState; |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 { | 287 { |
| 288 initialize("root-scroller.html"); | 288 initialize("root-scroller.html"); |
| 289 | 289 |
| 290 ASSERT_EQ(nullptr, mainFrame()->document()->rootScroller()); | 290 ASSERT_EQ(nullptr, mainFrame()->document()->rootScroller()); |
| 291 | 291 |
| 292 Element* container = mainFrame()->document()->getElementById("container"); | 292 Element* container = mainFrame()->document()->getElementById("container"); |
| 293 TrackExceptionState exceptionState; | 293 TrackExceptionState exceptionState; |
| 294 mainFrame()->document()->setRootScroller(container, exceptionState); | 294 mainFrame()->document()->setRootScroller(container, exceptionState); |
| 295 | 295 |
| 296 ASSERT_EQ(container, mainFrame()->document()->rootScroller()); | 296 ASSERT_EQ(container, mainFrame()->document()->rootScroller()); |
| 297 ASSERT_TRUE(mainFrame()->document()->isEffectiveRootScroller(*container)); | 297 ASSERT_EQ(container, mainFrame()->document()->effectiveRootScroller()); |
| 298 | 298 |
| 299 mainFrame()->document()->body()->removeChild(container); | 299 mainFrame()->document()->body()->removeChild(container); |
| 300 mainFrameView()->updateAllLifecyclePhases(); | 300 mainFrameView()->updateAllLifecyclePhases(); |
| 301 | 301 |
| 302 ASSERT_EQ(container, mainFrame()->document()->rootScroller()); | 302 ASSERT_EQ(container, mainFrame()->document()->rootScroller()); |
| 303 ASSERT_FALSE(mainFrame()->document()->isEffectiveRootScroller(*container)); | 303 ASSERT_NE(container, mainFrame()->document()->effectiveRootScroller()); |
| 304 } | 304 } |
| 305 | 305 |
| 306 // Tests that setting an element that isn't a valid scroller as the root | 306 // Tests that setting an element that isn't a valid scroller as the root |
| 307 // scroller doesn't change the effective root scroller. | 307 // scroller doesn't change the effective root scroller. |
| 308 TEST_F(RootScrollerTest, TestSetRootScrollerOnInvalidElement) | 308 TEST_F(RootScrollerTest, TestSetRootScrollerOnInvalidElement) |
| 309 { | 309 { |
| 310 initialize("root-scroller.html"); | 310 initialize("root-scroller.html"); |
| 311 | 311 |
| 312 { | 312 { |
| 313 // Set to a non-block element. Should be rejected and a console message | 313 // Set to a non-block element. Should be rejected and a console message |
| 314 // logged. | 314 // logged. |
| 315 Element* element = mainFrame()->document()->getElementById("nonBlock"); | 315 Element* element = mainFrame()->document()->getElementById("nonBlock"); |
| 316 TrackExceptionState exceptionState; | 316 TrackExceptionState exceptionState; |
| 317 mainFrame()->document()->setRootScroller(element, exceptionState); | 317 mainFrame()->document()->setRootScroller(element, exceptionState); |
| 318 mainFrameView()->updateAllLifecyclePhases(); | 318 mainFrameView()->updateAllLifecyclePhases(); |
| 319 ASSERT_EQ(element, mainFrame()->document()->rootScroller()); | 319 ASSERT_EQ(element, mainFrame()->document()->rootScroller()); |
| 320 ASSERT_FALSE( | 320 ASSERT_NE(element, mainFrame()->document()->effectiveRootScroller()); |
| 321 mainFrame()->document()->isEffectiveRootScroller(*element)); | |
| 322 } | 321 } |
| 323 | 322 |
| 324 { | 323 { |
| 325 // Set to an element with no size. | 324 // Set to an element with no size. |
| 326 Element* element = mainFrame()->document()->getElementById("empty"); | 325 Element* element = mainFrame()->document()->getElementById("empty"); |
| 327 TrackExceptionState exceptionState; | 326 TrackExceptionState exceptionState; |
| 328 mainFrame()->document()->setRootScroller(element, exceptionState); | 327 mainFrame()->document()->setRootScroller(element, exceptionState); |
| 329 mainFrameView()->updateAllLifecyclePhases(); | 328 mainFrameView()->updateAllLifecyclePhases(); |
| 330 ASSERT_EQ(element, mainFrame()->document()->rootScroller()); | 329 ASSERT_EQ(element, mainFrame()->document()->rootScroller()); |
| 331 ASSERT_FALSE( | 330 ASSERT_NE(element, mainFrame()->document()->effectiveRootScroller()); |
| 332 mainFrame()->document()->isEffectiveRootScroller(*element)); | |
| 333 } | 331 } |
| 334 } | 332 } |
| 335 | 333 |
| 336 // Test that the effective root scroller resets to the default element when the | 334 // Test that the effective root scroller resets to the default element when the |
| 337 // current root scroller element becomes invalid as a scroller. | 335 // current root scroller element becomes invalid as a scroller. |
| 338 TEST_F(RootScrollerTest, TestRootScrollerBecomesInvalid) | 336 TEST_F(RootScrollerTest, TestRootScrollerBecomesInvalid) |
| 339 { | 337 { |
| 340 initialize("root-scroller.html"); | 338 initialize("root-scroller.html"); |
| 341 | 339 |
| 342 Element* htmlElement = mainFrame()->document()->documentElement(); | 340 Element* htmlElement = mainFrame()->document()->documentElement(); |
| 343 Element* container = mainFrame()->document()->getElementById("container"); | 341 Element* container = mainFrame()->document()->getElementById("container"); |
| 344 TrackExceptionState exceptionState; | 342 TrackExceptionState exceptionState; |
| 345 | 343 |
| 346 ASSERT_EQ(nullptr, mainFrame()->document()->rootScroller()); | 344 ASSERT_EQ(nullptr, mainFrame()->document()->rootScroller()); |
| 347 ASSERT_TRUE(mainFrame()->document()->isEffectiveRootScroller(*htmlElement)); | 345 ASSERT_EQ(htmlElement, mainFrame()->document()->effectiveRootScroller()); |
| 348 | 346 |
| 349 { | 347 { |
| 350 mainFrame()->document()->setRootScroller(container, exceptionState); | 348 mainFrame()->document()->setRootScroller(container, exceptionState); |
| 351 mainFrameView()->updateAllLifecyclePhases(); | 349 mainFrameView()->updateAllLifecyclePhases(); |
| 352 | 350 |
| 353 ASSERT_EQ(container, mainFrame()->document()->rootScroller()); | 351 ASSERT_EQ(container, mainFrame()->document()->rootScroller()); |
| 354 ASSERT_TRUE( | 352 ASSERT_EQ(container, mainFrame()->document()->effectiveRootScroller()); |
| 355 mainFrame()->document()->isEffectiveRootScroller(*container)); | |
| 356 | 353 |
| 357 executeScript( | 354 executeScript( |
| 358 "document.querySelector('#container').style.display = 'inline'"); | 355 "document.querySelector('#container').style.display = 'inline'"); |
| 359 mainFrameView()->updateAllLifecyclePhases(); | 356 mainFrameView()->updateAllLifecyclePhases(); |
| 360 | 357 |
| 361 ASSERT_EQ(container, mainFrame()->document()->rootScroller()); | 358 ASSERT_EQ(container, mainFrame()->document()->rootScroller()); |
| 362 ASSERT_TRUE( | 359 ASSERT_EQ(htmlElement, |
| 363 mainFrame()->document()->isEffectiveRootScroller(*htmlElement)); | 360 mainFrame()->document()->effectiveRootScroller()); |
| 364 } | 361 } |
| 365 | 362 |
| 366 executeScript( | 363 executeScript( |
| 367 "document.querySelector('#container').style.display = 'block'"); | 364 "document.querySelector('#container').style.display = 'block'"); |
| 368 mainFrame()->document()->setRootScroller(nullptr, exceptionState); | 365 mainFrame()->document()->setRootScroller(nullptr, exceptionState); |
| 369 mainFrameView()->updateAllLifecyclePhases(); | 366 mainFrameView()->updateAllLifecyclePhases(); |
| 370 ASSERT_EQ(nullptr, mainFrame()->document()->rootScroller()); | 367 ASSERT_EQ(nullptr, mainFrame()->document()->rootScroller()); |
| 371 ASSERT_TRUE(mainFrame()->document()->isEffectiveRootScroller(*htmlElement)); | 368 ASSERT_EQ(htmlElement, mainFrame()->document()->effectiveRootScroller()); |
| 372 | 369 |
| 373 { | 370 { |
| 374 mainFrame()->document()->setRootScroller(container, exceptionState); | 371 mainFrame()->document()->setRootScroller(container, exceptionState); |
| 375 mainFrameView()->updateAllLifecyclePhases(); | 372 mainFrameView()->updateAllLifecyclePhases(); |
| 376 | 373 |
| 377 ASSERT_EQ(container, mainFrame()->document()->rootScroller()); | 374 ASSERT_EQ(container, mainFrame()->document()->rootScroller()); |
| 378 ASSERT_TRUE( | 375 ASSERT_EQ(container, mainFrame()->document()->effectiveRootScroller()); |
| 379 mainFrame()->document()->isEffectiveRootScroller(*container)); | |
| 380 | 376 |
| 381 executeScript( | 377 executeScript( |
| 382 "document.querySelector('#container').style.width = '98%'"); | 378 "document.querySelector('#container').style.width = '98%'"); |
| 383 mainFrameView()->updateAllLifecyclePhases(); | 379 mainFrameView()->updateAllLifecyclePhases(); |
| 384 | 380 |
| 385 ASSERT_EQ(container, mainFrame()->document()->rootScroller()); | 381 ASSERT_EQ(container, mainFrame()->document()->rootScroller()); |
| 386 ASSERT_TRUE( | 382 ASSERT_EQ(htmlElement, |
| 387 mainFrame()->document()->isEffectiveRootScroller(*htmlElement)); | 383 mainFrame()->document()->effectiveRootScroller()); |
| 388 } | 384 } |
| 389 } | 385 } |
| 390 | 386 |
| 391 // Tests that setting the root scroller of the top document to an element that | 387 // Tests that setting the root scroller of the top document to an element that |
| 392 // belongs to a nested document works. | 388 // belongs to a nested document works. |
| 393 TEST_F(RootScrollerTest, TestSetRootScrollerOnElementInIframe) | 389 TEST_F(RootScrollerTest, TestSetRootScrollerOnElementInIframe) |
| 394 { | 390 { |
| 395 initialize("root-scroller-iframe.html"); | 391 initialize("root-scroller-iframe.html"); |
| 396 | 392 |
| 397 ASSERT_EQ(nullptr, mainFrame()->document()->rootScroller()); | 393 ASSERT_EQ(nullptr, mainFrame()->document()->rootScroller()); |
| 398 | 394 |
| 399 { | 395 { |
| 400 // Trying to set an element from a nested document should fail. | 396 // Trying to set an element from a nested document should fail. |
| 401 HTMLFrameOwnerElement* iframe = toHTMLFrameOwnerElement( | 397 HTMLFrameOwnerElement* iframe = toHTMLFrameOwnerElement( |
| 402 mainFrame()->document()->getElementById("iframe")); | 398 mainFrame()->document()->getElementById("iframe")); |
| 403 Element* innerContainer = | 399 Element* innerContainer = |
| 404 iframe->contentDocument()->getElementById("container"); | 400 iframe->contentDocument()->getElementById("container"); |
| 405 | 401 |
| 406 TrackExceptionState exceptionState; | 402 TrackExceptionState exceptionState; |
| 407 mainFrame()->document()->setRootScroller( | 403 mainFrame()->document()->setRootScroller( |
| 408 innerContainer, | 404 innerContainer, |
| 409 exceptionState); | 405 exceptionState); |
| 410 mainFrameView()->updateAllLifecyclePhases(); | 406 mainFrameView()->updateAllLifecyclePhases(); |
| 411 | 407 |
| 412 ASSERT_EQ(innerContainer, mainFrame()->document()->rootScroller()); | 408 ASSERT_EQ(innerContainer, mainFrame()->document()->rootScroller()); |
| 413 ASSERT_TRUE( | 409 ASSERT_EQ(innerContainer, |
| 414 mainFrame()->document()->isEffectiveRootScroller(*innerContainer)); | 410 mainFrame()->document()->effectiveRootScroller()); |
| 415 } | 411 } |
| 416 | 412 |
| 417 { | 413 { |
| 418 // Setting the iframe itself should also work. | 414 // Setting the iframe itself should also work. |
| 419 HTMLFrameOwnerElement* iframe = toHTMLFrameOwnerElement( | 415 HTMLFrameOwnerElement* iframe = toHTMLFrameOwnerElement( |
| 420 mainFrame()->document()->getElementById("iframe")); | 416 mainFrame()->document()->getElementById("iframe")); |
| 421 | 417 |
| 422 TrackExceptionState exceptionState; | 418 TrackExceptionState exceptionState; |
| 423 mainFrame()->document()->setRootScroller(iframe, exceptionState); | 419 mainFrame()->document()->setRootScroller(iframe, exceptionState); |
| 424 mainFrameView()->updateAllLifecyclePhases(); | 420 mainFrameView()->updateAllLifecyclePhases(); |
| 425 | 421 |
| 426 ASSERT_EQ(iframe, mainFrame()->document()->rootScroller()); | 422 ASSERT_EQ(iframe, mainFrame()->document()->rootScroller()); |
| 427 ASSERT_TRUE( | 423 ASSERT_EQ(iframe, mainFrame()->document()->effectiveRootScroller()); |
| 428 mainFrame()->document()->isEffectiveRootScroller(*iframe)); | |
| 429 } | 424 } |
| 430 } | 425 } |
| 431 | 426 |
| 432 // Tests that setting a valid element as the root scroller on a document within | 427 // Tests that setting a valid element as the root scroller on a document within |
| 433 // an iframe works as expected. | 428 // an iframe works as expected. |
| 434 TEST_F(RootScrollerTest, TestRootScrollerWithinIframe) | 429 TEST_F(RootScrollerTest, TestRootScrollerWithinIframe) |
| 435 { | 430 { |
| 436 initialize("root-scroller-iframe.html"); | 431 initialize("root-scroller-iframe.html"); |
| 437 | 432 |
| 438 ASSERT_EQ(nullptr, mainFrame()->document()->rootScroller()); | 433 ASSERT_EQ(nullptr, mainFrame()->document()->rootScroller()); |
| 439 | 434 |
| 440 { | 435 { |
| 441 HTMLFrameOwnerElement* iframe = toHTMLFrameOwnerElement( | 436 HTMLFrameOwnerElement* iframe = toHTMLFrameOwnerElement( |
| 442 mainFrame()->document()->getElementById("iframe")); | 437 mainFrame()->document()->getElementById("iframe")); |
| 443 | 438 |
| 444 ASSERT_TRUE(iframe->contentDocument()->isEffectiveRootScroller( | 439 ASSERT_EQ(iframe->contentDocument()->documentElement(), |
| 445 *iframe->contentDocument()->documentElement())); | 440 iframe->contentDocument()->effectiveRootScroller()); |
| 446 | 441 |
| 447 Element* innerContainer = | 442 Element* innerContainer = |
| 448 iframe->contentDocument()->getElementById("container"); | 443 iframe->contentDocument()->getElementById("container"); |
| 449 TrackExceptionState exceptionState; | 444 TrackExceptionState exceptionState; |
| 450 iframe->contentDocument()->setRootScroller( | 445 iframe->contentDocument()->setRootScroller( |
| 451 innerContainer, | 446 innerContainer, |
| 452 exceptionState); | 447 exceptionState); |
| 453 mainFrameView()->updateAllLifecyclePhases(); | 448 mainFrameView()->updateAllLifecyclePhases(); |
| 454 | 449 |
| 455 ASSERT_EQ(innerContainer, iframe->contentDocument()->rootScroller()); | 450 ASSERT_EQ(innerContainer, iframe->contentDocument()->rootScroller()); |
| 456 ASSERT_TRUE(iframe->contentDocument()->isEffectiveRootScroller( | 451 ASSERT_EQ(innerContainer, |
| 457 *innerContainer)); | 452 iframe->contentDocument()->effectiveRootScroller()); |
| 458 } | 453 } |
| 459 } | 454 } |
| 460 | 455 |
| 461 // Tests that trying to set an element as the root scroller of a document inside | 456 // Tests that trying to set an element as the root scroller of a document inside |
| 462 // an iframe fails when that element belongs to the parent document. | 457 // an iframe fails when that element belongs to the parent document. |
| 463 // TODO(bokan): Recent changes mean this is now possible but should be fixed. | 458 // TODO(bokan): Recent changes mean this is now possible but should be fixed. |
| 464 TEST_F(RootScrollerTest, DISABLED_TestSetRootScrollerOnElementFromOutsideIframe) | 459 TEST_F(RootScrollerTest, DISABLED_TestSetRootScrollerOnElementFromOutsideIframe) |
| 465 { | 460 { |
| 466 initialize("root-scroller-iframe.html"); | 461 initialize("root-scroller-iframe.html"); |
| 467 | 462 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 490 body, | 485 body, |
| 491 exceptionState); | 486 exceptionState); |
| 492 | 487 |
| 493 ASSERT_EQ(body, iframe->contentDocument()->rootScroller()); | 488 ASSERT_EQ(body, iframe->contentDocument()->rootScroller()); |
| 494 } | 489 } |
| 495 } | 490 } |
| 496 | 491 |
| 497 } // namespace | 492 } // namespace |
| 498 | 493 |
| 499 } // namespace blink | 494 } // namespace blink |
| OLD | NEW |