~osomon/oxide/ensure-files-exist

« back to all changes in this revision

Viewing changes to qt/tests/qmltests/ssl/tst_WebPreferences_mixedContent.qml

  • Committer: Olivier Tilloy
  • Date: 2014-09-25 16:27:09 UTC
  • mfrom: (677.1.95 oxide)
  • Revision ID: olivier.tilloy@canonical.com-20140925162709-h8bai0f1nfaf7cfy
Merge the latest changes from trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import QtQuick 2.0
 
2
import QtTest 1.0
 
3
import com.canonical.Oxide 1.0
 
4
import com.canonical.Oxide.Testing 1.0
 
5
 
 
6
TestWebView {
 
7
  id: webView
 
8
  width: 200
 
9
  height: 200
 
10
 
 
11
  SignalSpy {
 
12
    id: displaySpy
 
13
    target: webView.preferences
 
14
    signalName: "canDisplayInsecureContentChanged"
 
15
  }
 
16
  SignalSpy {
 
17
    id: runSpy
 
18
    target: webView.preferences
 
19
    signalName: "canRunInsecureContentChanged"
 
20
  }
 
21
  SignalSpy {
 
22
    id: blockedSpy
 
23
    target: webView
 
24
    signalName: "blockedContentChanged"
 
25
  }
 
26
 
 
27
  TestCase {
 
28
    id: test
 
29
    name: "WebPreferences_mixedContent"
 
30
    when: windowShown
 
31
 
 
32
    function init() {
 
33
      webView.url = "about:blank";
 
34
      verify(webView.waitForLoadSucceeded());
 
35
      compare(webView.blockedContent, WebView.ContentTypeNone);
 
36
 
 
37
      displaySpy.clear();
 
38
      runSpy.clear();
 
39
      blockedSpy.clear();
 
40
    }
 
41
 
 
42
 
 
43
    function test_WebPreferences_mixedContent1_api_data() {
 
44
      return [
 
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 }
 
49
      ];
 
50
    }
 
51
 
 
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);
 
59
 
 
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);
 
64
    }
 
65
 
 
66
    function test_WebPreferences_mixedContent2_block_main_frame_data() {
 
67
      return [
 
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 }
 
72
      ];
 
73
    }
 
74
 
 
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;
 
79
      }
 
80
      function _can_run_script() {
 
81
        return webView.title == "Ran insecure!";
 
82
      }
 
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)";
 
88
      }
 
89
 
 
90
      webView.preferences.canDisplayInsecureContent = data.display;
 
91
      webView.preferences.canRunInsecureContent = data.run;
 
92
 
 
93
      webView.url = "https://testsuite/tst_WebPreferences_mixedContent.html";
 
94
      verify(webView.waitForLoadSucceeded());
 
95
 
 
96
      compare(_can_display(), data.display);
 
97
      compare(_can_run_script(), data.run);
 
98
      compare(_can_run_css(), data.run);
 
99
 
 
100
      compare(!(webView.blockedContent & WebView.ContentTypeMixedDisplay), data.display);
 
101
      compare(!(webView.blockedContent & WebView.ContentTypeMixedScript), data.run);
 
102
      compare(blockedSpy.count, data.blockedCount);
 
103
    }
 
104
 
 
105
    function test_WebPreferences_mixedContent3_block_sub_frame_data() {
 
106
      return [
 
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 }
 
111
      ];
 
112
    }
 
113
 
 
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;
 
118
      }
 
119
      function _can_run_script() {
 
120
        return webView.getTestApiForFrame(webView.rootFrame.childFrames[0]).evaluateCode(
 
121
"return document.title;", true) == "Ran insecure!";
 
122
      }
 
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)";
 
128
      }
 
129
 
 
130
      webView.preferences.canDisplayInsecureContent = data.display;
 
131
      webView.preferences.canRunInsecureContent = data.run;
 
132
 
 
133
      webView.url = "https://testsuite/tst_WebPreferences_mixedContent_subframe.html";
 
134
      verify(webView.waitForLoadSucceeded());
 
135
 
 
136
      compare(_can_display(), data.display);
 
137
      compare(_can_run_script(), data.run);
 
138
      compare(_can_run_css(), data.run);
 
139
 
 
140
      compare(!(webView.blockedContent & WebView.ContentTypeMixedDisplay), data.display);
 
141
      compare(!(webView.blockedContent & WebView.ContentTypeMixedScript), data.run);
 
142
      compare(blockedSpy.count, data.blockedCount);
 
143
    }
 
144
  }
 
145
}