mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1201535 - Test view source of srcdoc frames. r=mconley
This commit is contained in:
parent
b6eaa634fb
commit
d413f521fb
@ -7,5 +7,6 @@ support-files = head.js
|
||||
[browser_bug713810.js]
|
||||
[browser_contextmenu.js]
|
||||
[browser_gotoline.js]
|
||||
[browser_srcdoc.js]
|
||||
[browser_viewsourceprefs.js]
|
||||
skip-if = e10s # Bug ?????? - obscure failure (Syntax highlighting off - Got true, expected false)
|
||||
|
30
toolkit/components/viewsource/test/browser/browser_srcdoc.js
Normal file
30
toolkit/components/viewsource/test/browser/browser_srcdoc.js
Normal file
@ -0,0 +1,30 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
const frameSource = `<a href="about:mozilla">good</a>`;
|
||||
const source = `<html><iframe srcdoc='${frameSource}' id="f"></iframe></html>`;
|
||||
|
||||
add_task(function*() {
|
||||
let url = `data:text/html,${source}`;
|
||||
yield BrowserTestUtils.withNewTab({ gBrowser, url }, checkFrameSource);
|
||||
});
|
||||
|
||||
function* checkFrameSource() {
|
||||
let sourceTab = yield openViewFrameSourceTab("#f");
|
||||
registerCleanupFunction(function() {
|
||||
gBrowser.removeTab(sourceTab);
|
||||
});
|
||||
|
||||
yield waitForSourceLoaded(sourceTab);
|
||||
|
||||
let browser = gBrowser.selectedBrowser;
|
||||
let textContent = yield ContentTask.spawn(browser, {}, function*() {
|
||||
return content.document.body.textContent;
|
||||
});
|
||||
is(textContent, frameSource, "Correct content loaded");
|
||||
let id = yield ContentTask.spawn(browser, {}, function*() {
|
||||
return content.document.body.id;
|
||||
});
|
||||
is(id, "viewsource", "View source mode enabled")
|
||||
}
|
@ -49,17 +49,54 @@ function testViewSourceWindow(aURI, aTestCallback, aCloseCallback) {
|
||||
* within an existing selection.
|
||||
* @returns the new tab which shows the source.
|
||||
*/
|
||||
function* openViewPartialSourceWindow(aCSSSelector) {
|
||||
var contentAreaContextMenu = document.getElementById("contentAreaContextMenu");
|
||||
let popupShownPromise = BrowserTestUtils.waitForEvent(contentAreaContextMenu, "popupshown");
|
||||
function* openViewPartialSourceTab(aCSSSelector) {
|
||||
let contentAreaContextMenuPopup =
|
||||
document.getElementById("contentAreaContextMenu");
|
||||
let popupShownPromise =
|
||||
BrowserTestUtils.waitForEvent(contentAreaContextMenuPopup, "popupshown");
|
||||
yield BrowserTestUtils.synthesizeMouseAtCenter(aCSSSelector,
|
||||
{ type: "contextmenu", button: 2}, gBrowser.selectedBrowser);
|
||||
{ type: "contextmenu", button: 2 }, gBrowser.selectedBrowser);
|
||||
yield popupShownPromise;
|
||||
|
||||
let newTabPromise = BrowserTestUtils.waitForNewTab(gBrowser, null);
|
||||
|
||||
let popupHiddenPromise = BrowserTestUtils.waitForEvent(contentAreaContextMenu, "popuphidden");
|
||||
EventUtils.synthesizeMouseAtCenter(document.getElementById("context-viewpartialsource-selection"), {});
|
||||
let popupHiddenPromise =
|
||||
BrowserTestUtils.waitForEvent(contentAreaContextMenuPopup, "popuphidden");
|
||||
let item = document.getElementById("context-viewpartialsource-selection");
|
||||
EventUtils.synthesizeMouseAtCenter(item, {});
|
||||
yield popupHiddenPromise;
|
||||
|
||||
return (yield newTabPromise);
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens a view source tab for a frame (View Frame Source) within the
|
||||
* currently selected browser in gBrowser.
|
||||
*
|
||||
* @param aCSSSelector - used to specify the frame to view the source of.
|
||||
* @returns the new tab which shows the source.
|
||||
*/
|
||||
function* openViewFrameSourceTab(aCSSSelector) {
|
||||
let contentAreaContextMenuPopup =
|
||||
document.getElementById("contentAreaContextMenu");
|
||||
let popupShownPromise =
|
||||
BrowserTestUtils.waitForEvent(contentAreaContextMenuPopup, "popupshown");
|
||||
yield BrowserTestUtils.synthesizeMouseAtCenter(aCSSSelector,
|
||||
{ type: "contextmenu", button: 2 }, gBrowser.selectedBrowser);
|
||||
yield popupShownPromise;
|
||||
|
||||
let frameContextMenu = document.getElementById("frame");
|
||||
popupShownPromise =
|
||||
BrowserTestUtils.waitForEvent(frameContextMenu, "popupshown");
|
||||
EventUtils.synthesizeMouseAtCenter(frameContextMenu, {});
|
||||
yield popupShownPromise;
|
||||
|
||||
let newTabPromise = BrowserTestUtils.waitForNewTab(gBrowser, null);
|
||||
|
||||
let popupHiddenPromise =
|
||||
BrowserTestUtils.waitForEvent(frameContextMenu, "popuphidden");
|
||||
let item = document.getElementById("context-viewframesource");
|
||||
EventUtils.synthesizeMouseAtCenter(item, {});
|
||||
yield popupHiddenPromise;
|
||||
|
||||
return (yield newTabPromise);
|
||||
@ -72,6 +109,19 @@ registerCleanupFunction(function() {
|
||||
windows.getNext().close();
|
||||
});
|
||||
|
||||
/**
|
||||
* For a given view source tab, wait for the source loading step to complete.
|
||||
*/
|
||||
function waitForSourceLoaded(tab) {
|
||||
return new Promise(resolve => {
|
||||
let mm = tab.linkedBrowser.messageManager;
|
||||
mm.addMessageListener("ViewSource:SourceLoaded", function sourceLoaded() {
|
||||
mm.removeMessageListener("ViewSource:SourceLoaded", sourceLoaded);
|
||||
setTimeout(resolve, 0);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Open a new document in a new tab, select part of it, and view the source of
|
||||
* that selection. The document is not closed afterwards.
|
||||
@ -80,7 +130,7 @@ registerCleanupFunction(function() {
|
||||
* @param aCSSSelector - used to specify a node to select. All of this node's
|
||||
* children will be selected.
|
||||
* @returns the new tab which shows the source.
|
||||
*/
|
||||
*/
|
||||
function* openDocumentSelect(aURI, aCSSSelector) {
|
||||
let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, aURI);
|
||||
registerCleanupFunction(function() {
|
||||
@ -92,16 +142,10 @@ function* openDocumentSelect(aURI, aCSSSelector) {
|
||||
content.getSelection().selectAllChildren(element);
|
||||
});
|
||||
|
||||
let newtab = yield openViewPartialSourceWindow(aCSSSelector);
|
||||
let newtab = yield openViewPartialSourceTab(aCSSSelector);
|
||||
|
||||
// Wait until the source has been loaded.
|
||||
yield new Promise(resolve => {
|
||||
let mm = newtab.linkedBrowser.messageManager;
|
||||
mm.addMessageListener("ViewSource:SourceLoaded", function selectionDrawn() {
|
||||
mm.removeMessageListener("ViewSource:SourceLoaded", selectionDrawn);
|
||||
setTimeout(resolve, 0);
|
||||
});
|
||||
});
|
||||
yield waitForSourceLoaded(newtab);
|
||||
|
||||
return newtab;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user