3
import com.canonical.Oxide 1.0
4
import com.canonical.Oxide.Testing 1.0
15
property rect lastRequestPosition: Qt.rect(0,0,0,0)
16
property int lastRequestDisposition: NewViewRequest.DispositionCurrentTab
19
lastRequestPosition = request.position;
20
lastRequestDisposition = request.disposition;
27
signalName: "newViewRequested"
33
signalName: "navigationRequested"
38
name: "NewViewRequest"
42
webView.context.popupBlockerEnabled = true;
47
function test_NewViewRequest1_from_user_gesture_data() {
49
{ selector: "#button1", modifiers: Qt.NoModifier, disposition: NewViewRequest.DispositionNewForegroundTab, style: "window-open" },
50
{ selector: "#button1", modifiers: Qt.ShiftModifier, disposition: NewViewRequest.DispositionNewWindow, style: "window-open" },
51
{ selector: "#button1", modifiers: Qt.ControlModifier, disposition: NewViewRequest.DispositionNewBackgroundTab, style: "window-open" },
52
{ selector: "#button1", modifiers: Qt.ShiftModifier | Qt.ControlModifier, disposition: NewViewRequest.DispositionNewForegroundTab, style: "window-open" },
53
{ selector: "#button2", modifiers: Qt.NoModifier, disposition: NewViewRequest.DispositionNewPopup, style: "window-open" },
54
{ selector: "#button2", modifiers: Qt.ShiftModifier, disposition: NewViewRequest.DispositionNewPopup, style: "window-open" },
55
{ selector: "#button2", modifiers: Qt.ControlModifier, disposition: NewViewRequest.DispositionNewBackgroundTab, style: "window-open" },
56
{ selector: "#button2", modifiers: Qt.ShiftModifier | Qt.ControlModifier, disposition: NewViewRequest.DispositionNewForegroundTab, style: "window-open" },
57
{ selector: "#link1", modifiers: Qt.NoModifier, disposition: NewViewRequest.DispositionNewForegroundTab, style: "link-new-window" },
58
{ selector: "#link1", modifiers: Qt.ShiftModifier, disposition: NewViewRequest.DispositionNewWindow, style: "link-new-window" },
59
{ selector: "#link1", modifiers: Qt.ControlModifier, disposition: NewViewRequest.DispositionNewBackgroundTab, style: "link-new-window" },
60
{ selector: "#link1", modifiers: Qt.ShiftModifier | Qt.ControlModifier, disposition: NewViewRequest.DispositionNewForegroundTab, style: "link-new-window" },
61
{ selector: "#link2", modifiers: Qt.NoModifier, disposition: NewViewRequest.DispositionCurrentTab, style: "link" },
62
{ selector: "#link2", modifiers: Qt.ShiftModifier, disposition: NewViewRequest.DispositionNewWindow, style: "link" },
63
{ selector: "#link2", modifiers: Qt.ControlModifier, disposition: NewViewRequest.DispositionNewBackgroundTab, style: "link" },
64
{ selector: "#link2", modifiers: Qt.ShiftModifier | Qt.ControlModifier, disposition: NewViewRequest.DispositionNewForegroundTab, style: "link" }
68
function test_NewViewRequest1_from_user_gesture(data) {
69
webView.url = "http://localhost:8080/tst_NewViewRequest.html";
70
verify(webView.waitForLoadSucceeded(),
71
"Timed out waiting for successful load");
73
var r = webView.getTestApi().getBoundingClientRectForSelector(data.selector);
74
mouseClick(webView, r.x + r.width / 2, r.y + r.height / 2, Qt.LeftButton, data.modifiers);
76
if (data.disposition == NewViewRequest.DispositionCurrentTab) {
77
verify(webView.waitForLoadSucceeded());
78
compare(spy.count, 0);
81
compare(spy.count, 1);
83
if (data.style != "link-new-window") {
84
// XXX: This will fail if the request is outside of the screen's availableRect
85
// (including shell chrome). The figures are set to make this unlikely though
86
if (data.style == "window-open") {
87
compare(webView.lastRequestPosition.x, 100, "Unexpected position.x");
88
compare(webView.lastRequestPosition.y, 100, "Unexpected position.y");
90
compare(webView.lastRequestPosition.width, data.style == "window-open" ? 200 : webView.width, "Unexpected position.width");
91
compare(webView.lastRequestPosition.height, data.style == "window-open" ? 200 : webView.height, "Unexpected position.height");
93
compare(webView.lastRequestDisposition, data.disposition, "Unexpected disposition");
96
compare(navSpy.count, 1);
99
function test_NewViewRequest2_no_user_gesture_data() {
100
return test_NewViewRequest1_from_user_gesture_data();
103
function test_NewViewRequest2_no_user_gesture(data) {
104
webView.context.popupBlockerEnabled = false;
106
if (data.style == "link") {
110
webView.url = "http://localhost:8080/tst_NewViewRequest.html";
111
verify(webView.waitForLoadSucceeded(),
112
"Timed out waiting for successful load");
114
webView.getTestApi().evaluateCode(
115
"var e = document.createEvent(\"HTMLEvents\");
116
e.initEvent(\"click\", true, false);
117
document.querySelector(\"" + data.selector + "\").dispatchEvent(e);", true);
121
compare(spy.count, 1);
122
compare(navSpy.count, 1);
124
if (data.style != "link-new-window") {
125
// XXX: This will fail if the request is outside of the screen's availableRect
126
// (including shell chrome). The figures are set to make this unlikely though
127
compare(webView.lastRequestPosition.x, 100, "Unexpected position.x");
128
compare(webView.lastRequestPosition.y, 100, "Unexpected position.y");
129
compare(webView.lastRequestPosition.width, 200, "Unexpected position.width");
130
compare(webView.lastRequestPosition.height, 200, "Unexpected position.height");
132
compare(webView.lastRequestDisposition, NewViewRequest.DispositionNewPopup,
133
"Unexpected disposition");