Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <!-- |
michael@0 | 4 | https://bugzilla.mozilla.org/show_bug.cgi?id=458091 |
michael@0 | 5 | --> |
michael@0 | 6 | <head> |
michael@0 | 7 | <title>Test for Bug 458091</title> |
michael@0 | 8 | <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 9 | <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script> |
michael@0 | 10 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
michael@0 | 11 | </head> |
michael@0 | 12 | <body> |
michael@0 | 13 | <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=458091">Mozilla Bug 458091</a> |
michael@0 | 14 | |
michael@0 | 15 | <div id="content" style="display: none"> |
michael@0 | 16 | |
michael@0 | 17 | </div> |
michael@0 | 18 | <pre id="test"> |
michael@0 | 19 | <a id="testlink1" target="_blank" href="javascript:window.opener.finish(sessionStorage['testItem']);window.close();">Javascript Link</a> |
michael@0 | 20 | <a id="testlink2" target="_blank" href="bug458091_child.html">HTTP Link</a> |
michael@0 | 21 | <a id="testlink3" target="alreadyOpened" href="bug458091_child.html">Target Link</a> |
michael@0 | 22 | <script type="application/javascript"> |
michael@0 | 23 | |
michael@0 | 24 | /** Test for Bug 458091 **/ |
michael@0 | 25 | |
michael@0 | 26 | var gTestWin; |
michael@0 | 27 | var gRunningTests = 0; |
michael@0 | 28 | |
michael@0 | 29 | function runNextTest() |
michael@0 | 30 | { |
michael@0 | 31 | if (gTests.length > 0) { |
michael@0 | 32 | var test = gTests.shift(); |
michael@0 | 33 | test(); |
michael@0 | 34 | } else { |
michael@0 | 35 | SimpleTest.finish(); |
michael@0 | 36 | } |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | function finish(val) |
michael@0 | 40 | { |
michael@0 | 41 | is(val, "correct value", |
michael@0 | 42 | "New window should access the correct session storage"); |
michael@0 | 43 | if (--gRunningTests == 0) { |
michael@0 | 44 | runNextTest(); |
michael@0 | 45 | } |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 49 | |
michael@0 | 50 | function test1() { |
michael@0 | 51 | sessionStorage["testItem"] = "correct value"; |
michael@0 | 52 | |
michael@0 | 53 | gRunningTests++; |
michael@0 | 54 | window.open('javascript:window.opener.finish(sessionStorage["testItem"]);window.close();'); |
michael@0 | 55 | |
michael@0 | 56 | gRunningTests++; |
michael@0 | 57 | window.open("bug458091_child.html"); |
michael@0 | 58 | |
michael@0 | 59 | gRunningTests++; |
michael@0 | 60 | sendMouseEvent({type: "click"}, "testlink1"); |
michael@0 | 61 | |
michael@0 | 62 | gRunningTests++; |
michael@0 | 63 | sendMouseEvent({type: "click"}, "testlink2"); |
michael@0 | 64 | |
michael@0 | 65 | // targetted load into an existing window |
michael@0 | 66 | var testWin = window.open("about:blank", "alreadyOpened"); |
michael@0 | 67 | gRunningTests++; |
michael@0 | 68 | sendMouseEvent({type: "click"}, "testlink3"); |
michael@0 | 69 | |
michael@0 | 70 | // window.location into an existing window. Leave the window open |
michael@0 | 71 | // for further tests... |
michael@0 | 72 | gRunningTests++; |
michael@0 | 73 | gTestWin = window.open("about:blank", "testWindow"); |
michael@0 | 74 | gTestWin.location = 'javascript:window.opener.finish(sessionStorage["testItem"]);'; |
michael@0 | 75 | } |
michael@0 | 76 | |
michael@0 | 77 | function test2() { |
michael@0 | 78 | // Now change session storage and load a new item in gTestWin, to |
michael@0 | 79 | // verify that they properly diverged after window.open(). |
michael@0 | 80 | gRunningTests++; |
michael@0 | 81 | sessionStorage["testItem"] = "incorrect value"; |
michael@0 | 82 | gTestWin.location = 'javascript:window.opener.finish(sessionStorage["testItem"]);'; |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | function test3() |
michael@0 | 86 | { |
michael@0 | 87 | // Now, with session storage still changed, try the window.open() |
michael@0 | 88 | // path, make sure it doesn't overwrite the session storage. |
michael@0 | 89 | gRunningTests++; |
michael@0 | 90 | window.open('javascript:window.opener.finish(sessionStorage["testItem"]);window.close();', |
michael@0 | 91 | "testWindow"); |
michael@0 | 92 | } |
michael@0 | 93 | |
michael@0 | 94 | var gTests = [test1, test2, test3]; |
michael@0 | 95 | runNextTest(); |
michael@0 | 96 | |
michael@0 | 97 | </script> |
michael@0 | 98 | </pre> |
michael@0 | 99 | </body> |
michael@0 | 100 | </html> |