mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1102210 - Test for Android History (normal and redirected page loads) r=rnewman
This commit is contained in:
parent
17fc4df582
commit
5e09ee810e
8
mobile/android/base/tests/javascript_redirect.sjs
Normal file
8
mobile/android/base/tests/javascript_redirect.sjs
Normal file
@ -0,0 +1,8 @@
|
||||
function handleRequest(request, response)
|
||||
{
|
||||
let page = "<!DOCTYPE html><html><head><script>window.opener = null; location.replace('" + request.queryString + "')</script></head><body><p>Redirecting...</p></body></html>";
|
||||
|
||||
response.setStatusLine("1.0", 200, "OK");
|
||||
response.setHeader("Content-Type", "text/html; charset=utf-8", false);
|
||||
response.write(page);
|
||||
}
|
@ -104,6 +104,7 @@ skip-if = android_version == "10"
|
||||
[testDebuggerServer]
|
||||
[testDeviceSearchEngine]
|
||||
[testFilePicker]
|
||||
[testHistoryService]
|
||||
[testJNI]
|
||||
# [testMozPay] # see bug 945675
|
||||
[testNetworkManager]
|
||||
|
5
mobile/android/base/tests/simple_redirect.sjs
Normal file
5
mobile/android/base/tests/simple_redirect.sjs
Normal file
@ -0,0 +1,5 @@
|
||||
function handleRequest(request, response)
|
||||
{
|
||||
response.setStatusLine(request.httpVersion, 301, "Moved Permanently");
|
||||
response.setHeader("Location", request.queryString, false);
|
||||
}
|
12
mobile/android/base/tests/testHistoryService.java
Normal file
12
mobile/android/base/tests/testHistoryService.java
Normal file
@ -0,0 +1,12 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.mozilla.gecko.tests;
|
||||
|
||||
public class testHistoryService extends JavascriptTest {
|
||||
|
||||
public testHistoryService() {
|
||||
super("testHistoryService.js");
|
||||
}
|
||||
}
|
130
mobile/android/base/tests/testHistoryService.js
Normal file
130
mobile/android/base/tests/testHistoryService.js
Normal file
@ -0,0 +1,130 @@
|
||||
// -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
"use strict";
|
||||
|
||||
const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
|
||||
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
function ok(passed, text) {
|
||||
do_report_result(passed, text, Components.stack.caller, false);
|
||||
}
|
||||
|
||||
// Make the timer global so it doesn't get GC'd
|
||||
let gTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
|
||||
|
||||
function sleep(wait) {
|
||||
return new Promise((resolve, reject) => {
|
||||
do_print("sleep start");
|
||||
gTimer.initWithCallback({
|
||||
notify: function () {
|
||||
do_print("sleep end");
|
||||
resolve();
|
||||
},
|
||||
}, wait, gTimer.TYPE_ONE_SHOT);
|
||||
});
|
||||
}
|
||||
|
||||
function promiseLoadEvent(browser, url, eventType="load") {
|
||||
return new Promise((resolve, reject) => {
|
||||
do_print("Wait browser event: " + eventType);
|
||||
|
||||
function handle(event) {
|
||||
// Since we'll be redirecting, don't make assumptions about the given URL and the loaded URL
|
||||
if (event.target != browser.contentDocument || event.target.location.href == "about:blank") {
|
||||
do_print("Skipping spurious '" + eventType + "' event" + " for " + event.target.location.href);
|
||||
return;
|
||||
}
|
||||
|
||||
browser.removeEventListener(eventType, handle, true);
|
||||
do_print("Browser event received: " + eventType);
|
||||
resolve(event);
|
||||
}
|
||||
|
||||
browser.addEventListener(eventType, handle, true);
|
||||
if (url) {
|
||||
browser.loadURI(url);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Wait 4 seconds for the pending visits to flush (which should happen in 3 seconds)
|
||||
const PENDING_VISIT_WAIT = 4000;
|
||||
|
||||
// Manage the saved history visits so we can compare in the tests
|
||||
let gVisitURLs = [];
|
||||
function visitObserver(subject, topic, data) {
|
||||
let uri = subject.QueryInterface(Ci.nsIURI);
|
||||
do_print("Observer: " + uri.spec);
|
||||
gVisitURLs.push(uri.spec);
|
||||
};
|
||||
|
||||
// Track the <browser> where the tests are happening
|
||||
let gBrowser;
|
||||
|
||||
add_test(function setup_browser() {
|
||||
let chromeWin = Services.wm.getMostRecentWindow("navigator:browser");
|
||||
let BrowserApp = chromeWin.BrowserApp;
|
||||
|
||||
do_register_cleanup(function cleanup() {
|
||||
Services.obs.removeObserver(visitObserver, "link-visited");
|
||||
BrowserApp.closeTab(BrowserApp.getTabForBrowser(browser));
|
||||
});
|
||||
|
||||
Services.obs.addObserver(visitObserver, "link-visited", false);
|
||||
|
||||
// Load a blank page
|
||||
let url = "about:blank";
|
||||
gBrowser = BrowserApp.addTab(url, { selected: true, parentId: BrowserApp.selectedTab.id }).browser;
|
||||
gBrowser.addEventListener("load", function startTests(event) {
|
||||
gBrowser.removeEventListener("load", startTests, true);
|
||||
Services.tm.mainThread.dispatch(run_next_test, Ci.nsIThread.DISPATCH_NORMAL);
|
||||
}, true);
|
||||
});
|
||||
|
||||
add_task(function* () {
|
||||
// Wait for any initial page loads to be saved to history
|
||||
yield sleep(PENDING_VISIT_WAIT);
|
||||
|
||||
// Load a simple HTML page with no redirects
|
||||
gVisitURLs = [];
|
||||
yield promiseLoadEvent(gBrowser, "http://example.org/tests/robocop/robocop_blank_01.html");
|
||||
yield sleep(PENDING_VISIT_WAIT);
|
||||
|
||||
do_print("visit counts: " + gVisitURLs.length);
|
||||
ok(gVisitURLs.length == 1, "Simple visit makes 1 history item");
|
||||
|
||||
do_print("visit URL: " + gVisitURLs[0]);
|
||||
ok(gVisitURLs[0] == "http://example.org/tests/robocop/robocop_blank_01.html", "Simple visit makes final history item");
|
||||
|
||||
// Load a simple HTML page via a 301 temporary redirect
|
||||
gVisitURLs = [];
|
||||
yield promiseLoadEvent(gBrowser, "http://example.org/tests/robocop/simple_redirect.sjs?http://example.org/tests/robocop/robocop_blank_02.html");
|
||||
yield sleep(PENDING_VISIT_WAIT);
|
||||
|
||||
do_print("visit counts: " + gVisitURLs.length);
|
||||
ok(gVisitURLs.length == 1, "Simple 301 redirect makes 1 history item");
|
||||
|
||||
do_print("visit URL: " + gVisitURLs[0]);
|
||||
ok(gVisitURLs[0] == "http://example.org/tests/robocop/robocop_blank_02.html", "Simple 301 redirect makes final history item");
|
||||
|
||||
// Load a simple HTML page via a JavaScript redirect
|
||||
gVisitURLs = [];
|
||||
yield promiseLoadEvent(gBrowser, "http://example.org/tests/robocop/javascript_redirect.sjs?http://example.org/tests/robocop/robocop_blank_03.html");
|
||||
yield sleep(PENDING_VISIT_WAIT);
|
||||
|
||||
do_print("visit counts: " + gVisitURLs.length);
|
||||
ok(gVisitURLs.length == 2, "JavaScript redirect makes 2 history items");
|
||||
|
||||
do_print("visit URL 1: " + gVisitURLs[0]);
|
||||
ok(gVisitURLs[0] == "http://example.org/tests/robocop/javascript_redirect.sjs?http://example.org/tests/robocop/robocop_blank_03.html", "JavaScript redirect makes intermediate history item");
|
||||
|
||||
do_print("visit URL 2: " + gVisitURLs[1]);
|
||||
ok(gVisitURLs[1] == "http://example.org/tests/robocop/robocop_blank_03.html", "JavaScript redirect makes final history item");
|
||||
});
|
||||
|
||||
run_next_test();
|
Loading…
Reference in New Issue
Block a user