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