3
import com.canonical.Oxide 1.0
4
import com.canonical.Oxide.Testing 1.0
13
target: webView.preferences
14
signalName: "canDisplayInsecureContentChanged"
18
target: webView.preferences
19
signalName: "canRunInsecureContentChanged"
24
signalName: "blockedContentChanged"
29
name: "WebPreferences_mixedContent"
33
webView.url = "about:blank";
34
verify(webView.waitForLoadSucceeded());
35
compare(webView.blockedContent, WebView.ContentTypeNone);
43
function test_WebPreferences_mixedContent1_api_data() {
45
{ display: true, run: false, displayChanged: false, runChanged: false },
46
{ display: false, run: false, displayChanged: true, runChanged: false },
47
{ display: false, run: true, displayChanged: false, runChanged: true },
48
{ display: true, run: true, displayChanged: true, runChanged: false }
52
function test_WebPreferences_mixedContent1_api(data) {
53
// Verify we can set and read back the correct value, and that setting
54
// the same value doesn't result in another signal
55
webView.preferences.canDisplayInsecureContent = data.display;
56
compare(webView.preferences.canDisplayInsecureContent, data.display)
57
webView.preferences.canDisplayInsecureContent = data.display;
58
compare(displaySpy.count, data.displayChanged ? 1 : 0);
60
webView.preferences.canRunInsecureContent = data.run;
61
compare(webView.preferences.canRunInsecureContent, data.run);
62
webView.preferences.canRunInsecureContent = data.run;
63
compare(runSpy.count, data.runChanged ? 1 : 0);
66
function test_WebPreferences_mixedContent2_block_main_frame_data() {
68
{ display: true, run: false, blockedCount: 2 },
69
{ display: false, run: false, blockedCount: 3 },
70
{ display: false, run: true, blockedCount: 2 },
71
{ display: true, run: true, blockedCount: 1 }
75
function test_WebPreferences_mixedContent2_block_main_frame(data) {
76
function _can_display() {
77
return webView.getTestApi().evaluateCode("
78
return document.getElementsByTagName(\"img\")[0].width;", true) == 150;
80
function _can_run_script() {
81
return webView.title == "Ran insecure!";
83
function _can_run_css() {
84
return webView.getTestApi().evaluateCode("
85
var elem = document.getElementsByTagName(\"p\")[0];
86
var style = window.getComputedStyle(elem);
87
return style.getPropertyValue(\"color\");", true) == "rgb(255, 0, 0)";
90
webView.preferences.canDisplayInsecureContent = data.display;
91
webView.preferences.canRunInsecureContent = data.run;
93
webView.url = "https://testsuite/tst_WebPreferences_mixedContent.html";
94
verify(webView.waitForLoadSucceeded());
96
compare(_can_display(), data.display);
97
compare(_can_run_script(), data.run);
98
compare(_can_run_css(), data.run);
100
compare(!(webView.blockedContent & WebView.ContentTypeMixedDisplay), data.display);
101
compare(!(webView.blockedContent & WebView.ContentTypeMixedScript), data.run);
102
compare(blockedSpy.count, data.blockedCount);
105
function test_WebPreferences_mixedContent3_block_sub_frame_data() {
107
{ display: true, run: false, blockedCount: 2 },
108
{ display: false, run: false, blockedCount: 3 },
109
{ display: false, run: true, blockedCount: 2 },
110
{ display: true, run: true, blockedCount: 1 }
114
function test_WebPreferences_mixedContent3_block_sub_frame(data) {
115
function _can_display() {
116
return webView.getTestApiForFrame(webView.rootFrame.childFrames[0]).evaluateCode("
117
return document.getElementsByTagName(\"img\")[0].width;", true) == 150;
119
function _can_run_script() {
120
return webView.getTestApiForFrame(webView.rootFrame.childFrames[0]).evaluateCode(
121
"return document.title;", true) == "Ran insecure!";
123
function _can_run_css() {
124
return webView.getTestApiForFrame(webView.rootFrame.childFrames[0]).evaluateCode("
125
var elem = document.getElementsByTagName(\"p\")[0];
126
var style = window.getComputedStyle(elem);
127
return style.getPropertyValue(\"color\");", true) == "rgb(255, 0, 0)";
130
webView.preferences.canDisplayInsecureContent = data.display;
131
webView.preferences.canRunInsecureContent = data.run;
133
webView.url = "https://testsuite/tst_WebPreferences_mixedContent_subframe.html";
134
verify(webView.waitForLoadSucceeded());
136
compare(_can_display(), data.display);
137
compare(_can_run_script(), data.run);
138
compare(_can_run_css(), data.run);
140
compare(!(webView.blockedContent & WebView.ContentTypeMixedDisplay), data.display);
141
compare(!(webView.blockedContent & WebView.ContentTypeMixedScript), data.run);
142
compare(blockedSpy.count, data.blockedCount);