browser/components/sessionstore/test/browser_sessionHistory.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

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 /**
michael@0 7 * Ensure that starting a load invalidates shistory.
michael@0 8 */
michael@0 9 add_task(function test_load_start() {
michael@0 10 // Create a new tab.
michael@0 11 let tab = gBrowser.addTab("about:blank");
michael@0 12 let browser = tab.linkedBrowser;
michael@0 13 yield promiseBrowserLoaded(browser);
michael@0 14
michael@0 15 // Load a new URI but remove the tab before it has finished loading.
michael@0 16 browser.loadURI("about:mozilla");
michael@0 17 yield promiseContentMessage(browser, "ss-test:onFrameTreeReset");
michael@0 18 gBrowser.removeTab(tab);
michael@0 19
michael@0 20 // Undo close the tab.
michael@0 21 tab = ss.undoCloseTab(window, 0);
michael@0 22 browser = tab.linkedBrowser;
michael@0 23 yield promiseBrowserLoaded(browser);
michael@0 24
michael@0 25 // Check that the correct URL was restored.
michael@0 26 is(browser.currentURI.spec, "about:mozilla", "url is correct");
michael@0 27
michael@0 28 // Cleanup.
michael@0 29 gBrowser.removeTab(tab);
michael@0 30 });
michael@0 31
michael@0 32 /**
michael@0 33 * Ensure that purging shistory invalidates.
michael@0 34 */
michael@0 35 add_task(function test_purge() {
michael@0 36 // Create a new tab.
michael@0 37 let tab = gBrowser.addTab("about:mozilla");
michael@0 38 let browser = tab.linkedBrowser;
michael@0 39 yield promiseBrowserLoaded(browser);
michael@0 40
michael@0 41 // Create a second shistory entry.
michael@0 42 browser.loadURI("about:robots");
michael@0 43 yield promiseBrowserLoaded(browser);
michael@0 44
michael@0 45 // Check that we now have two shistory entries.
michael@0 46 SyncHandlers.get(browser).flush();
michael@0 47 let {entries} = JSON.parse(ss.getTabState(tab));
michael@0 48 is(entries.length, 2, "there are two shistory entries");
michael@0 49
michael@0 50 // Purge session history.
michael@0 51 yield sendMessage(browser, "ss-test:purgeSessionHistory");
michael@0 52
michael@0 53 // Check that we are left with a single shistory entry.
michael@0 54 SyncHandlers.get(browser).flush();
michael@0 55 let {entries} = JSON.parse(ss.getTabState(tab));
michael@0 56 is(entries.length, 1, "there is one shistory entry");
michael@0 57
michael@0 58 // Cleanup.
michael@0 59 gBrowser.removeTab(tab);
michael@0 60 });
michael@0 61
michael@0 62 /**
michael@0 63 * Ensure that anchor navigation invalidates shistory.
michael@0 64 */
michael@0 65 add_task(function test_hashchange() {
michael@0 66 const URL = "data:text/html;charset=utf-8,<a id=a href=%23>clickme</a>";
michael@0 67
michael@0 68 // Create a new tab.
michael@0 69 let tab = gBrowser.addTab(URL);
michael@0 70 let browser = tab.linkedBrowser;
michael@0 71 yield promiseBrowserLoaded(browser);
michael@0 72
michael@0 73 // Check that we start with a single shistory entry.
michael@0 74 SyncHandlers.get(browser).flush();
michael@0 75 let {entries} = JSON.parse(ss.getTabState(tab));
michael@0 76 is(entries.length, 1, "there is one shistory entry");
michael@0 77
michael@0 78 // Click the link and wait for a hashchange event.
michael@0 79 browser.messageManager.sendAsyncMessage("ss-test:click", {id: "a"});
michael@0 80 yield promiseContentMessage(browser, "ss-test:hashchange");
michael@0 81
michael@0 82 // Check that we now have two shistory entries.
michael@0 83 SyncHandlers.get(browser).flush();
michael@0 84 let {entries} = JSON.parse(ss.getTabState(tab));
michael@0 85 is(entries.length, 2, "there are two shistory entries");
michael@0 86
michael@0 87 // Cleanup.
michael@0 88 gBrowser.removeTab(tab);
michael@0 89 });
michael@0 90
michael@0 91 /**
michael@0 92 * Ensure that loading pages from the bfcache invalidates shistory.
michael@0 93 */
michael@0 94 add_task(function test_pageshow() {
michael@0 95 const URL = "data:text/html;charset=utf-8,<h1>first</h1>";
michael@0 96 const URL2 = "data:text/html;charset=utf-8,<h1>second</h1>";
michael@0 97
michael@0 98 // Create a new tab.
michael@0 99 let tab = gBrowser.addTab(URL);
michael@0 100 let browser = tab.linkedBrowser;
michael@0 101 yield promiseBrowserLoaded(browser);
michael@0 102
michael@0 103 // Create a second shistory entry.
michael@0 104 browser.loadURI(URL2);
michael@0 105 yield promiseBrowserLoaded(browser);
michael@0 106
michael@0 107 // Go back to the previous url which is loaded from the bfcache.
michael@0 108 browser.goBack();
michael@0 109 yield promiseContentMessage(browser, "ss-test:onFrameTreeCollected");
michael@0 110 is(browser.currentURI.spec, URL, "correct url after going back");
michael@0 111
michael@0 112 // Check that loading from bfcache did invalidate shistory.
michael@0 113 SyncHandlers.get(browser).flush();
michael@0 114 let {index} = JSON.parse(ss.getTabState(tab));
michael@0 115 is(index, 1, "first history entry is selected");
michael@0 116
michael@0 117 // Cleanup.
michael@0 118 gBrowser.removeTab(tab);
michael@0 119 });
michael@0 120
michael@0 121 /**
michael@0 122 * Ensure that subframe navigation invalidates shistory.
michael@0 123 */
michael@0 124 add_task(function test_subframes() {
michael@0 125 const URL = "data:text/html;charset=utf-8," +
michael@0 126 "<iframe src=http%3A//example.com/ name=t></iframe>" +
michael@0 127 "<a id=a1 href=http%3A//example.com/1 target=t>clickme</a>" +
michael@0 128 "<a id=a2 href=http%3A//example.com/%23 target=t>clickme</a>";
michael@0 129
michael@0 130 // Create a new tab.
michael@0 131 let tab = gBrowser.addTab(URL);
michael@0 132 let browser = tab.linkedBrowser;
michael@0 133 yield promiseBrowserLoaded(browser);
michael@0 134
michael@0 135 // Check that we have a single shistory entry.
michael@0 136 SyncHandlers.get(browser).flush();
michael@0 137 let {entries} = JSON.parse(ss.getTabState(tab));
michael@0 138 is(entries.length, 1, "there is one shistory entry");
michael@0 139 is(entries[0].children.length, 1, "the entry has one child");
michael@0 140
michael@0 141 // Navigate the subframe.
michael@0 142 browser.messageManager.sendAsyncMessage("ss-test:click", {id: "a1"});
michael@0 143 yield promiseBrowserLoaded(browser, false /* don't ignore subframes */);
michael@0 144
michael@0 145 // Check shistory.
michael@0 146 SyncHandlers.get(browser).flush();
michael@0 147 let {entries} = JSON.parse(ss.getTabState(tab));
michael@0 148 is(entries.length, 2, "there now are two shistory entries");
michael@0 149 is(entries[1].children.length, 1, "the second entry has one child");
michael@0 150
michael@0 151 // Go back in history.
michael@0 152 browser.goBack();
michael@0 153 yield promiseBrowserLoaded(browser, false /* don't ignore subframes */);
michael@0 154
michael@0 155 // Navigate the subframe again.
michael@0 156 browser.messageManager.sendAsyncMessage("ss-test:click", {id: "a2"});
michael@0 157 yield promiseContentMessage(browser, "ss-test:hashchange");
michael@0 158
michael@0 159 // Check shistory.
michael@0 160 SyncHandlers.get(browser).flush();
michael@0 161 let {entries} = JSON.parse(ss.getTabState(tab));
michael@0 162 is(entries.length, 2, "there now are two shistory entries");
michael@0 163 is(entries[1].children.length, 1, "the second entry has one child");
michael@0 164
michael@0 165 // Cleanup.
michael@0 166 gBrowser.removeTab(tab);
michael@0 167 });
michael@0 168
michael@0 169 /**
michael@0 170 * Ensure that navigating from an about page invalidates shistory.
michael@0 171 */
michael@0 172 add_task(function test_about_page_navigate() {
michael@0 173 // Create a new tab.
michael@0 174 let tab = gBrowser.addTab("about:blank");
michael@0 175 let browser = tab.linkedBrowser;
michael@0 176 yield promiseBrowserLoaded(browser);
michael@0 177
michael@0 178 // Check that we have a single shistory entry.
michael@0 179 SyncHandlers.get(browser).flush();
michael@0 180 let {entries} = JSON.parse(ss.getTabState(tab));
michael@0 181 is(entries.length, 1, "there is one shistory entry");
michael@0 182 is(entries[0].url, "about:blank", "url is correct");
michael@0 183
michael@0 184 browser.loadURI("about:robots");
michael@0 185 yield promiseBrowserLoaded(browser);
michael@0 186
michael@0 187 // Check that we have changed the history entry.
michael@0 188 SyncHandlers.get(browser).flush();
michael@0 189 let {entries} = JSON.parse(ss.getTabState(tab));
michael@0 190 is(entries.length, 1, "there is one shistory entry");
michael@0 191 is(entries[0].url, "about:robots", "url is correct");
michael@0 192
michael@0 193 // Cleanup.
michael@0 194 gBrowser.removeTab(tab);
michael@0 195 });
michael@0 196
michael@0 197 /**
michael@0 198 * Ensure that history.pushState and history.replaceState invalidate shistory.
michael@0 199 */
michael@0 200 add_task(function test_pushstate_replacestate() {
michael@0 201 // Create a new tab.
michael@0 202 let tab = gBrowser.addTab("http://example.com/1");
michael@0 203 let browser = tab.linkedBrowser;
michael@0 204 yield promiseBrowserLoaded(browser);
michael@0 205
michael@0 206 // Check that we have a single shistory entry.
michael@0 207 SyncHandlers.get(browser).flush();
michael@0 208 let {entries} = JSON.parse(ss.getTabState(tab));
michael@0 209 is(entries.length, 1, "there is one shistory entry");
michael@0 210 is(entries[0].url, "http://example.com/1", "url is correct");
michael@0 211
michael@0 212 browser.messageManager.
michael@0 213 sendAsyncMessage("ss-test:historyPushState", {url: 'test-entry/'});
michael@0 214 yield promiseContentMessage(browser, "ss-test:historyPushState");
michael@0 215
michael@0 216 // Check that we have added the history entry.
michael@0 217 SyncHandlers.get(browser).flush();
michael@0 218 let {entries} = JSON.parse(ss.getTabState(tab));
michael@0 219 is(entries.length, 2, "there is another shistory entry");
michael@0 220 is(entries[1].url, "http://example.com/test-entry/", "url is correct");
michael@0 221
michael@0 222 // Disabled until replaceState invalidation is supported. See Bug 967028.
michael@0 223 browser.messageManager.
michael@0 224 sendAsyncMessage("ss-test:historyReplaceState", {url: 'test-entry2/'});
michael@0 225 yield promiseContentMessage(browser, "ss-test:historyReplaceState");
michael@0 226
michael@0 227 // Check that we have modified the history entry.
michael@0 228 SyncHandlers.get(browser).flush();
michael@0 229 let {entries} = JSON.parse(ss.getTabState(tab));
michael@0 230 is(entries.length, 2, "there is still two shistory entries");
michael@0 231 is(entries[1].url, "http://example.com/test-entry/test-entry2/", "url is correct");
michael@0 232
michael@0 233 // Cleanup.
michael@0 234 gBrowser.removeTab(tab);
michael@0 235 });

mercurial