Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | * http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | "use strict"; |
michael@0 | 5 | |
michael@0 | 6 | const URL = ROOT + "browser_frametree_sample.html"; |
michael@0 | 7 | const URL_FRAMESET = ROOT + "browser_frametree_sample_frameset.html"; |
michael@0 | 8 | |
michael@0 | 9 | /** |
michael@0 | 10 | * This ensures that loading a page normally, aborting a page load, reloading |
michael@0 | 11 | * a page, navigating using the bfcache, and ignoring frames that were |
michael@0 | 12 | * created dynamically work as expect. We expect the frame tree to be reset |
michael@0 | 13 | * when a page starts loading and we also expect a valid frame tree to exist |
michael@0 | 14 | * when it has stopped loading. |
michael@0 | 15 | */ |
michael@0 | 16 | add_task(function test_frametree() { |
michael@0 | 17 | const FRAME_TREE_SINGLE = { href: URL }; |
michael@0 | 18 | const FRAME_TREE_FRAMESET = { |
michael@0 | 19 | href: URL_FRAMESET, |
michael@0 | 20 | children: [{href: URL}, {href: URL}, {href: URL}] |
michael@0 | 21 | }; |
michael@0 | 22 | |
michael@0 | 23 | // Create a tab with a single frame. |
michael@0 | 24 | let tab = gBrowser.addTab(URL); |
michael@0 | 25 | let browser = tab.linkedBrowser; |
michael@0 | 26 | yield promiseNewFrameTree(browser); |
michael@0 | 27 | yield checkFrameTree(browser, FRAME_TREE_SINGLE, |
michael@0 | 28 | "loading a page resets and creates the frame tree correctly"); |
michael@0 | 29 | |
michael@0 | 30 | // Load the frameset and create two frames dynamically, the first on |
michael@0 | 31 | // DOMContentLoaded and the second on load. |
michael@0 | 32 | yield sendMessage(browser, "ss-test:createDynamicFrames", {id: "frames", url: URL}); |
michael@0 | 33 | browser.loadURI(URL_FRAMESET); |
michael@0 | 34 | yield promiseNewFrameTree(browser); |
michael@0 | 35 | yield checkFrameTree(browser, FRAME_TREE_FRAMESET, |
michael@0 | 36 | "dynamic frames created on or after the load event are ignored"); |
michael@0 | 37 | |
michael@0 | 38 | // Go back to the previous single-frame page. There will be no load event as |
michael@0 | 39 | // the page is still in the bfcache. We thus make sure this type of navigation |
michael@0 | 40 | // resets the frame tree. |
michael@0 | 41 | browser.goBack(); |
michael@0 | 42 | yield promiseNewFrameTree(browser); |
michael@0 | 43 | yield checkFrameTree(browser, FRAME_TREE_SINGLE, |
michael@0 | 44 | "loading from bfache resets and creates the frame tree correctly"); |
michael@0 | 45 | |
michael@0 | 46 | // Load the frameset again but abort the load early. |
michael@0 | 47 | // The frame tree should still be reset and created. |
michael@0 | 48 | browser.loadURI(URL_FRAMESET); |
michael@0 | 49 | executeSoon(() => browser.stop()); |
michael@0 | 50 | yield promiseNewFrameTree(browser); |
michael@0 | 51 | |
michael@0 | 52 | // Load the frameset and check the tree again. |
michael@0 | 53 | yield sendMessage(browser, "ss-test:createDynamicFrames", {id: "frames", url: URL}); |
michael@0 | 54 | browser.loadURI(URL_FRAMESET); |
michael@0 | 55 | yield promiseNewFrameTree(browser); |
michael@0 | 56 | yield checkFrameTree(browser, FRAME_TREE_FRAMESET, |
michael@0 | 57 | "reloading a page resets and creates the frame tree correctly"); |
michael@0 | 58 | |
michael@0 | 59 | // Cleanup. |
michael@0 | 60 | gBrowser.removeTab(tab); |
michael@0 | 61 | }); |
michael@0 | 62 | |
michael@0 | 63 | /** |
michael@0 | 64 | * This test ensures that we ignore frames that were created dynamically at or |
michael@0 | 65 | * after the load event. SessionStore can't handle these and will not restore |
michael@0 | 66 | * or collect any data for them. |
michael@0 | 67 | */ |
michael@0 | 68 | add_task(function test_frametree_dynamic() { |
michael@0 | 69 | // The frame tree as expected. The first two frames are static |
michael@0 | 70 | // and the third one was created on DOMContentLoaded. |
michael@0 | 71 | const FRAME_TREE = { |
michael@0 | 72 | href: URL_FRAMESET, |
michael@0 | 73 | children: [{href: URL}, {href: URL}, {href: URL}] |
michael@0 | 74 | }; |
michael@0 | 75 | const FRAME_TREE_REMOVED = { |
michael@0 | 76 | href: URL_FRAMESET, |
michael@0 | 77 | children: [{href: URL}, {href: URL}] |
michael@0 | 78 | }; |
michael@0 | 79 | |
michael@0 | 80 | // Add an empty tab for a start. |
michael@0 | 81 | let tab = gBrowser.addTab("about:blank"); |
michael@0 | 82 | let browser = tab.linkedBrowser; |
michael@0 | 83 | yield promiseBrowserLoaded(browser); |
michael@0 | 84 | |
michael@0 | 85 | // Create dynamic frames on "DOMContentLoaded" and on "load". |
michael@0 | 86 | yield sendMessage(browser, "ss-test:createDynamicFrames", {id: "frames", url: URL}); |
michael@0 | 87 | browser.loadURI(URL_FRAMESET); |
michael@0 | 88 | yield promiseNewFrameTree(browser); |
michael@0 | 89 | |
michael@0 | 90 | // Check that the frame tree does not contain the frame created on "load". |
michael@0 | 91 | // The two static frames and the one created on DOMContentLoaded must be in |
michael@0 | 92 | // the tree. |
michael@0 | 93 | yield checkFrameTree(browser, FRAME_TREE, |
michael@0 | 94 | "frame tree contains first four frames"); |
michael@0 | 95 | |
michael@0 | 96 | // Remove the last frame in the frameset. |
michael@0 | 97 | yield sendMessage(browser, "ss-test:removeLastFrame", {id: "frames"}); |
michael@0 | 98 | // Check that the frame tree didn't change. |
michael@0 | 99 | yield checkFrameTree(browser, FRAME_TREE, |
michael@0 | 100 | "frame tree contains first four frames"); |
michael@0 | 101 | |
michael@0 | 102 | // Remove the last frame in the frameset. |
michael@0 | 103 | yield sendMessage(browser, "ss-test:removeLastFrame", {id: "frames"}); |
michael@0 | 104 | // Check that the frame tree excludes the removed frame. |
michael@0 | 105 | yield checkFrameTree(browser, FRAME_TREE_REMOVED, |
michael@0 | 106 | "frame tree contains first three frames"); |
michael@0 | 107 | |
michael@0 | 108 | // Cleanup. |
michael@0 | 109 | gBrowser.removeTab(tab); |
michael@0 | 110 | }); |
michael@0 | 111 | |
michael@0 | 112 | /** |
michael@0 | 113 | * Checks whether the current frame hierarchy of a given |browser| matches the |
michael@0 | 114 | * |expected| frame hierarchy. |
michael@0 | 115 | */ |
michael@0 | 116 | function checkFrameTree(browser, expected, msg) { |
michael@0 | 117 | return sendMessage(browser, "ss-test:mapFrameTree").then(tree => { |
michael@0 | 118 | is(JSON.stringify(tree), JSON.stringify(expected), msg); |
michael@0 | 119 | }); |
michael@0 | 120 | } |
michael@0 | 121 | |
michael@0 | 122 | /** |
michael@0 | 123 | * Returns a promise that will be resolved when the given |browser| has loaded |
michael@0 | 124 | * and we received messages saying that its frame tree has been reset and |
michael@0 | 125 | * recollected. |
michael@0 | 126 | */ |
michael@0 | 127 | function promiseNewFrameTree(browser) { |
michael@0 | 128 | let reset = promiseContentMessage(browser, "ss-test:onFrameTreeCollected"); |
michael@0 | 129 | let collect = promiseContentMessage(browser, "ss-test:onFrameTreeCollected"); |
michael@0 | 130 | return Promise.all([reset, collect]); |
michael@0 | 131 | } |