browser/components/sessionstore/test/browser_pageStyle.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 const URL = getRootDirectory(gTestPath) + "browser_pageStyle_sample.html";
michael@0 7 const URL_NESTED = getRootDirectory(gTestPath) + "browser_pageStyle_sample_nested.html";
michael@0 8
michael@0 9 /**
michael@0 10 * This test ensures that page style information is correctly persisted.
michael@0 11 */
michael@0 12 add_task(function page_style() {
michael@0 13 let tab = gBrowser.addTab(URL);
michael@0 14 let browser = tab.linkedBrowser;
michael@0 15 yield promiseBrowserLoaded(browser);
michael@0 16 let sheets = yield getStyleSheets(browser);
michael@0 17
michael@0 18 // Enable all style sheets one by one.
michael@0 19 for (let [title, disabled] of sheets) {
michael@0 20 yield enableStyleSheetsForSet(browser, title);
michael@0 21
michael@0 22 let tab2 = gBrowser.duplicateTab(tab);
michael@0 23 yield promiseTabRestored(tab2);
michael@0 24
michael@0 25 let sheets = yield getStyleSheets(tab2.linkedBrowser);
michael@0 26 let enabled = sheets.filter(([title, disabled]) => !disabled);
michael@0 27
michael@0 28 if (title.startsWith("fail_")) {
michael@0 29 ok(!enabled.length, "didn't restore " + title);
michael@0 30 } else {
michael@0 31 ok(enabled.length == 1 && enabled[0][0] == title, "restored " + title);
michael@0 32 }
michael@0 33
michael@0 34 gBrowser.removeTab(tab2);
michael@0 35 }
michael@0 36
michael@0 37 // Disable all styles and verify that this is correctly persisted.
michael@0 38 yield setAuthorStyleDisabled(browser, true);
michael@0 39
michael@0 40 let tab2 = gBrowser.duplicateTab(tab);
michael@0 41 yield promiseTabRestored(tab2);
michael@0 42
michael@0 43 let authorStyleDisabled = yield getAuthorStyleDisabled(tab2.linkedBrowser);
michael@0 44 ok(authorStyleDisabled, "disabled all stylesheets");
michael@0 45
michael@0 46 // Clean up.
michael@0 47 gBrowser.removeTab(tab);
michael@0 48 gBrowser.removeTab(tab2);
michael@0 49 });
michael@0 50
michael@0 51 /**
michael@0 52 * This test ensures that page style notification from nested documents are
michael@0 53 * received and the page style is persisted correctly.
michael@0 54 */
michael@0 55 add_task(function nested_page_style() {
michael@0 56 let tab = gBrowser.addTab(URL_NESTED);
michael@0 57 let browser = tab.linkedBrowser;
michael@0 58 yield promiseBrowserLoaded(browser);
michael@0 59
michael@0 60 yield enableSubDocumentStyleSheetsForSet(browser, "alternate");
michael@0 61 gBrowser.removeTab(tab);
michael@0 62
michael@0 63 let [{state: {pageStyle}}] = JSON.parse(ss.getClosedTabData(window));
michael@0 64 let expected = JSON.stringify({children: [{pageStyle: "alternate"}]});
michael@0 65 is(JSON.stringify(pageStyle), expected, "correct pageStyle persisted");
michael@0 66 });
michael@0 67
michael@0 68 function getStyleSheets(browser) {
michael@0 69 return sendMessage(browser, "ss-test:getStyleSheets");
michael@0 70 }
michael@0 71
michael@0 72 function enableStyleSheetsForSet(browser, name) {
michael@0 73 return sendMessage(browser, "ss-test:enableStyleSheetsForSet", name);
michael@0 74 }
michael@0 75
michael@0 76 function enableSubDocumentStyleSheetsForSet(browser, name) {
michael@0 77 return sendMessage(browser, "ss-test:enableSubDocumentStyleSheetsForSet", {
michael@0 78 id: "iframe", set: name
michael@0 79 });
michael@0 80 }
michael@0 81
michael@0 82 function getAuthorStyleDisabled(browser) {
michael@0 83 return sendMessage(browser, "ss-test:getAuthorStyleDisabled");
michael@0 84 }
michael@0 85
michael@0 86 function setAuthorStyleDisabled(browser, val) {
michael@0 87 return sendMessage(browser, "ss-test:setAuthorStyleDisabled", val)
michael@0 88 }

mercurial