| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 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 #include "platform/testing/UnitTestHelpers.h" |
| 6 #include "web/tests/sim/SimRequest.h" |
| 7 #include "web/tests/sim/SimTest.h" |
| 8 |
| 9 namespace blink { |
| 10 |
| 11 using WindowProxyTest = SimTest; |
| 12 |
| 13 // Tests that a WindowProxy is reinitialized after a navigation, even if the new |
| 14 // Document does not use any scripting. |
| 15 TEST_F(WindowProxyTest, ReinitializedAfterNavigation) { |
| 16 // TODO(dcheng): It's nicer to use TestingPlatformSupportWithMockScheduler, |
| 17 // but that leads to random DCHECKs in loading code. |
| 18 |
| 19 SimRequest mainResource("https://example.com/index.html", "text/html"); |
| 20 loadURL("https://example.com/index.html"); |
| 21 mainResource.complete( |
| 22 "<!DOCTYPE html>" |
| 23 "<html><head><script>" |
| 24 "var childWindow;" |
| 25 "function runTest() {" |
| 26 " childWindow = window[0];" |
| 27 " document.querySelector('iframe').onload = runTest2;" |
| 28 " childWindow.location = 'data:text/plain,Initial.';" |
| 29 "}" |
| 30 "function runTest2() {" |
| 31 " try {" |
| 32 " childWindow.location = 'data:text/plain,Final.';" |
| 33 " console.log('PASSED');" |
| 34 " } catch (e) {" |
| 35 " console.log('FAILED');" |
| 36 " }" |
| 37 " document.querySelector('iframe').onload = null;" |
| 38 "}" |
| 39 "</script></head><body onload='runTest()'>" |
| 40 "<iframe></iframe></body></html>"); |
| 41 |
| 42 // Wait for the first data: URL to load |
| 43 testing::runPendingTasks(); |
| 44 |
| 45 // Wait for the second data: URL to load. |
| 46 testing::runPendingTasks(); |
| 47 |
| 48 ASSERT_GT(consoleMessages().size(), 0U); |
| 49 EXPECT_EQ("PASSED", consoleMessages()[0]); |
| 50 } |
| 51 } |
| OLD | NEW |