3
import com.canonical.Oxide 1.0
4
import com.canonical.Oxide.Testing 1.0
6
// FIXME: Test navigations in a subwindow (ie, one opened with window.open() and with
7
// window.opener pointing to its parent - we should only get onNavigationRequest
8
// notifications for cross-domain navigations as opposed to all navigations)
15
property string lastRequestUrl: ""
16
property int lastRequestDisposition: NavigationRequest.DispositionCurrentTab
17
property bool lastRequestUserGesture: false
19
property bool shouldReject: false
21
onNavigationRequested: {
23
request.action = NavigationRequest.ActionReject;
27
lastRequestUrl = request.url;
28
lastRequestDisposition = request.disposition;
29
lastRequestUserGesture = request.userGesture;
32
// XXX(chrisccoulson): If we don't do this, then all future calls to
33
// onNewViewRequested fail (we get a null request object)
41
signalName: "navigationRequested"
47
signalName: "newViewRequested"
52
signalName: "urlChanged"
57
name: "NavigationRequest"
61
webView.url = "about:blank";
62
verify(webView.waitForLoadSucceeded(),
63
"Timed out waiting for successful load");
67
webView.shouldReject = false;
68
webView.context.popupBlockerEnabled = true;
71
function test_NavigationRequest1_from_user_gestures_data() {
73
{ link: "#link1", url: "http://localhost:8080/empty.html", modifiers: Qt.NoModifier, disposition: NavigationRequest.DispositionCurrentTab, current: true },
74
{ link: "#link1", url: "http://localhost:8080/empty.html", modifiers: Qt.ShiftModifier, disposition: NavigationRequest.DispositionNewWindow, current: true },
75
{ link: "#link1", url: "http://localhost:8080/empty.html", modifiers: Qt.ControlModifier, disposition: NavigationRequest.DispositionNewBackgroundTab, current: true },
76
{ link: "#link1", url: "http://localhost:8080/empty.html", modifiers: Qt.ShiftModifier | Qt.ControlModifier, disposition: NavigationRequest.DispositionNewForegroundTab, current: true },
77
{ link: "#button1", url: "http://localhost:8080/empty.html", modifiers: Qt.NoModifier, disposition: NavigationRequest.DispositionNewForegroundTab, current: false },
78
{ link: "#button1", url: "http://localhost:8080/empty.html", modifiers: Qt.ShiftModifier, disposition: NavigationRequest.DispositionNewWindow, current: false },
79
{ link: "#button1", url: "http://localhost:8080/empty.html", modifiers: Qt.ControlModifier, disposition: NavigationRequest.DispositionNewBackgroundTab, current: false },
80
{ link: "#button1", url: "http://localhost:8080/empty.html", modifiers: Qt.ShiftModifier | Qt.ControlModifier, disposition: NavigationRequest.DispositionNewForegroundTab, current: false },
81
{ link: "#link2", url: "http://localhost:8080/empty.html", modifiers: Qt.NoModifier, disposition: NavigationRequest.DispositionNewForegroundTab, current: false },
82
{ link: "#link2", url: "http://localhost:8080/empty.html", modifiers: Qt.ShiftModifier, disposition: NavigationRequest.DispositionNewWindow, current: false },
83
{ link: "#link2", url: "http://localhost:8080/empty.html", modifiers: Qt.ControlModifier, disposition: NavigationRequest.DispositionNewBackgroundTab, current: false },
84
{ link: "#link2", url: "http://localhost:8080/empty.html", modifiers: Qt.ShiftModifier | Qt.ControlModifier, disposition: NavigationRequest.DispositionNewForegroundTab, current: false },
85
// XXX(chrisccoulson): These 2 disabled due to https://launchpad.net/bugs/1302743
86
// { link: "#button2", url: "http://localhost:8080/empty.html", modifiers: Qt.NoModifier, disposition: NavigationRequest.DispositionNewPopup, current: false },
87
// { link: "#button2", url: "http://localhost:8080/empty.html", modifiers: Qt.ShiftModifier, disposition: NavigationRequest.DispositionNewPopup, current: false },
88
{ link: "#button2", url: "http://localhost:8080/empty.html", modifiers: Qt.ControlModifier, disposition: NavigationRequest.DispositionNewBackgroundTab, current: false },
89
{ link: "#button2", url: "http://localhost:8080/empty.html", modifiers: Qt.ShiftModifier | Qt.ControlModifier, disposition: NavigationRequest.DispositionNewForegroundTab, current: false },
93
// Test that we get an onNavigationRequested signal for all renderer-initiated
94
// top-level navigations (also verifies that we don't get one for browser-
95
// initiated navigations)
96
function test_NavigationRequest1_from_user_gestures(data) {
97
webView.url = "http://localhost:8080/tst_NavigationRequest.html";
98
verify(webView.waitForLoadSucceeded(),
99
"Timed out waiting for successful load");
101
compare(spy.count, 0,
102
"Shouldn't get an onNavigationRequested signal for browser-initiated navigation");
104
var r = webView.getTestApi().getBoundingClientRectForSelector(data.link);
105
mouseClick(webView, r.x + r.width / 2, r.y + r.height / 2, Qt.LeftButton, data.modifiers);
107
if (data.disposition == NavigationRequest.DispositionCurrentTab) {
108
verify(webView.waitForLoadSucceeded());
113
compare(spy.count, 1, "Should have had an onNavigationRequested signal");
114
compare(webView.lastRequestUrl, data.url);
115
compare(webView.lastRequestDisposition, data.disposition);
116
compare(webView.lastRequestUserGesture, true);
119
function test_NavigationRequest2_no_user_gesture_data() {
120
return test_NavigationRequest1_from_user_gestures_data();
123
// Verify that the userGesture property indicates the appropriate value
124
// for renderer-initiated top-level navigations that don't come from an
126
function test_NavigationRequest2_no_user_gesture(data) {
127
webView.context.popupBlockerEnabled = false;
129
webView.url = "http://localhost:8080/tst_NavigationRequest.html";
130
verify(webView.waitForLoadSucceeded(),
131
"Timed out waiting for successful load");
133
compare(spy.count, 0,
134
"Shouldn't get an onNavigationRequested signal for browser-initiated navigation");
136
webView.getTestApi().evaluateCode(
137
"var e = document.createEvent(\"HTMLEvents\");
138
e.initEvent(\"click\", true, false);
139
document.querySelector(\"" + data.link + "\").dispatchEvent(e);", true);
142
verify(webView.waitForLoadSucceeded());
147
compare(spy.count, 1, "Should have had an onNavigationRequested signal")
148
compare(webView.lastRequestUrl, "http://localhost:8080/empty.html");
149
compare(webView.lastRequestDisposition, data.current ? NavigationRequest.DispositionCurrentTab : NavigationRequest.DispositionNewPopup );
150
compare(webView.lastRequestUserGesture, false);
153
function test_NavigationRequest3_reject_data() {
154
return test_NavigationRequest1_from_user_gestures_data();
157
// Verify that rejecting an onNavigationRequested request for all
158
// renderer-initiated top-level navigations blocks the navigation and that
159
// we don't get any onNewViewRequested signals.
161
// XXX(chrisccoulson): This is a bit hacky, because we use a 100ms delay
162
// before verifying no loads started
163
function test_NavigationRequest3_reject(data) {
164
webView.shouldReject = true;
166
webView.url = "http://localhost:8080/tst_NavigationRequest.html";
167
verify(webView.waitForLoadSucceeded(),
168
"Timed out waiting for successful load");
170
webView.clearLoadEventCounters();
172
var r = webView.getTestApi().getBoundingClientRectForSelector(data.link);
173
mouseClick(webView, r.x + r.width / 2, r.y + r.height / 2, Qt.LeftButton, data.modifiers);
174
webView.waitFor(function() { return false; }, 100);
176
compare(spy.count, 1);
177
compare(newViewSpy.count, 0, "Shouldn't have called onNewViewRequested for rejected navigation");
178
compare(webView.loadsStartedCount, 0, "Shouldn't have started a load for rejected navigation");
181
function test_NavigationRequest4_subframe_data() {
182
return test_NavigationRequest1_from_user_gestures_data();
185
// Verify that we don't get an onNavigationRequested signal for
186
// renderer-initiated subframe navigations unless the disposition is not
187
// DispositionCurrentTab.
188
// We get them for other dispositions via
189
// content::RenderFrameImpl::loadURLExternally(), which is called from
190
// WebCore::DocumentLoader::shouldContinueForNavigationPolicy()
191
function test_NavigationRequest4_subframe(data) {
192
webView.url = "http://localhost:8080/tst_NavigationRequest2.html";
193
verify(webView.waitForLoadSucceeded(),
194
"Timed out waiting for successful load");
196
var frame = webView.rootFrame.childFrames[0];
198
frameSpy.target = frame;
199
var r = webView.getTestApiForFrame(frame).getBoundingClientRectForSelector(data.link);
200
mouseClick(webView, r.x + r.width / 2, r.y + r.height / 2, Qt.LeftButton, data.modifiers);
202
if (data.disposition == NavigationRequest.DispositionCurrentTab) {
204
compare(spy.count, 0, "Shouldn't get onNavigationRequested from CurrentTab subframe navigations");
207
compare(spy.count, 1, "Should get onNavigationRequested from non-CurrentTab subframe navigations");