chromium/third_party/blink/web_tests/http/tests/security/resources/cross-frame-iframe-for-put-test.html

<!DOCTYPE html>
<html>
<head>
    <script type="text/javascript">
        function log(s)
        {
            document.getElementById("console").appendChild(document.createTextNode(s + "\n"));
        }

        function shouldBe(a, b, shouldNotPrintValues)
        {
            var evalA, evalB;
            try {
                evalA = eval(a);
                evalB = eval(b);
            } catch(e) {
                evalA = e;
            }

            var message;
            if (evalA === evalB) {
                message = "PASS";
                if (!shouldNotPrintValues) {
                    message += ": " + a + " should be '" + evalB + "' and is.";
                } else {
                    message += ": " + a + " matched the expected value.";
                }
            } else {
               message = "*** FAIL: " + a + " should be '" + evalB + "' but instead is " + evalA + ". ***";
            }

            message = String(message).replace(/\n/g, "");
            if (window.testRunner) {
                console.log(message);
            } else {
                log(message);
            }
        }
    </script>
</head>
<body>
    <p>This text is in an iframe.</p>
    <pre id="console"></pre>
    <script>
        // Constructors
        var AttrOld = window.Attr;
        var CDATASectionOld = window.CDATASection;
        var CharacterDataOld = window.CharacterData;
        var CommentOld = window.Comment;
        var CSSRuleOld = window.CSSRule;
        var CSSStyleDeclarationOld = window.CSSStyleDeclaration;
        var DocumentFragmentOld = window.DocumentFragment;
        var DocumentOld = window.Document;
        var DocumentTypeOld = window.DocumentType;
        var DOMExceptionOld = window.DOMException;
        var DOMImplementationOld = window.DOMImplementation;
        var DOMParserOld = window.DOMParser;
        var ElementOld = window.Element;
        var EntityOld = window.Entity;
        var EntityReferenceOld = window.EntityReference;
        var EvalErrorOld = window.EvalError;
        var EventOld = window.Event;
        var HTMLAnchorElementOld = window.HTMLAnchorElement;
        var HTMLAreaElementOld = window.HTMLAreaElement;
        var HTMLBaseElementOld = window.HTMLBaseElement;
        var HTMLBodyElementOld = window.HTMLBodyElement;
        var HTMLBRElementOld = window.HTMLBRElement;
        var HTMLButtonElementOld = window.HTMLButtonElement;
        var HTMLCanvasElementOld = window.HTMLCanvasElement;
        var HTMLDirectoryElementOld = window.HTMLDirectoryElement;
        var HTMLDivElementOld = window.HTMLDivElement;
        var HTMLDListElementOld = window.HTMLDListElement;
        var HTMLDocumentOld = window.HTMLDocument;
        var HTMLElementOld = window.HTMLElement;
        var HTMLFieldSetElementOld = window.HTMLFieldSetElement;
        var HTMLFontElementOld = window.HTMLFontElement;
        var HTMLFormElementOld = window.HTMLFormElement;
        var HTMLFrameElementOld = window.HTMLFrameElement;
        var HTMLFrameSetElementOld = window.HTMLFrameSetElement;
        var HTMLHeadElementOld = window.HTMLHeadElement;
        var HTMLHeadingElementOld = window.HTMLHeadingElement;
        var HTMLHRElementOld = window.HTMLHRElement;
        var HTMLHtmlElementOld = window.HTMLHtmlElement;
        var HTMLIFrameElementOld = window.HTMLIFrameElement;
        var HTMLImageElementOld = window.HTMLImageElement;
        var HTMLInputElementOld = window.HTMLInputElement;
        var HTMLIsIndexElementOld = window.HTMLIsIndexElement;
        var HTMLLabelElementOld = window.HTMLLabelElement;
        var HTMLLegendElementOld = window.HTMLLegendElement;
        var HTMLLIElementOld = window.HTMLLIElement;
        var HTMLLinkElementOld = window.HTMLLinkElement;
        var HTMLMapElementOld = window.HTMLMapElement;
        var HTMLMarqueeElementOld = window.HTMLMarqueeElement;
        var HTMLMenuElementOld = window.HTMLMenuElement;
        var HTMLMetaElementOld = window.HTMLMetaElement;
        var HTMLModElementOld = window.HTMLModElement;
        var HTMLOListElementOld = window.HTMLOListElement;
        var HTMLOptGroupElementOld = window.HTMLOptGroupElement;
        var HTMLOptionElementOld = window.HTMLOptionElement;
        var HTMLParagraphElementOld = window.HTMLParagraphElement;
        var HTMLParamElementOld = window.HTMLParamElement;
        var HTMLPreElementOld = window.HTMLPreElement;
        var HTMLQuoteElementOld = window.HTMLQuoteElement;
        var HTMLScriptElementOld = window.HTMLScriptElement;
        var HTMLSelectElementOld = window.HTMLSelectElement;
        var HTMLStyleElementOld = window.HTMLStyleElement;
        var HTMLTableCaptionElementOld = window.HTMLTableCaptionElement;
        var HTMLTableCellElementOld = window.HTMLTableCellElement;
        var HTMLTableColElementOld = window.HTMLTableColElement;
        var HTMLTableElementOld = window.HTMLTableElement;
        var HTMLTableRowElementOld = window.HTMLTableRowElement;
        var HTMLTableSectionElementOld = window.HTMLTableSectionElement;
        var HTMLTextAreaElementOld = window.HTMLTextAreaElement;
        var HTMLTitleElementOld = window.HTMLTitleElement;
        var HTMLUListElementOld = window.HTMLUListElement;
        var MutationEventOld = window.MutationEvent;
        var NodeFilterOld = window.NodeFilter;
        var NodeOld = window.Node;
        var ProcessingInstructionOld = window.ProcessingInstruction;
        var RangeErrorOld = window.RangeError;
        var RangeOld = window.Range;
        var ReferenceErrorOld = window.ReferenceError;
        var SyntaxErrorOld = window.SyntaxError;
        var TextOld = window.Text;
        var TypeErrorOld = window.TypeError;
        var URIErrorOld = window.URIError;
        var XMLDocumentOld = window.XMLDocument;
        var XMLSerializerOld = window.XMLSerializer;
        var XPathEvaluatorOld = window.XPathEvaluator;
        var XPathResultOld = window.XPathResult;

        // FIXME: find a way to test these Constructors
        // var ImageOld = window.Image;
        // var OptionOld = window.Option;
        // var XMLHttpRequestOld = window.XMLHttpRequest;
        // var XSLTProcessorOld = window.XSLTProcessor;

        // Attributes
        var clientInformationOld = window.clientInformation;
        var closedOld = window.closed;
        var consoleOld = window.console;
        var cryptoOld = window.crypto;
        var defaultStatusOld = window.defaultStatus;
        var defaultstatusOld = window.defaultstatus;
        var devicePixelRatioOld = window.devicePixelRatio;
        var documentOld = window.document;
        var embedsOld = window.embeds;
        var framesOld = window.frames;
        var historyOld = window.history;
        var imagesOld = window.images;
        var innerHeightOld = 150; // This needs to be set explicitily as it is not set a the time of calling
        var innerWidthOld = 300; // This needs to be set explicitily as it is not set a the time of calling
        var lengthOld = window.length;
        var locationbarOld = window.locationbar;
        var menubarOld = window.menubar;
        var nameOld = window.name;
        var navigatorOld = window.navigator;
        var offscreenBufferingOld = window.offscreenBuffering;
        var onabortOld = window.onabort;
        var onbeforeunloadOld = window.onbeforeunload;
        var onblurOld = window.onblur;
        var onchangeOld = window.onchange;
        var onclickOld = window.onclick;
        var ondblclickOld = window.ondblclick;
        var onerrorOld = window.onerror;
        var onfocusOld = window.onfocus;
        var onkeydownOld = window.onkeydown;
        var onkeypressOld = window.onkeypress;
        var onkeyupOld = window.onkeyup;
        var onloadOld = window.onload;
        var onmousedownOld = window.onmousedown;
        var onmousemoveOld = window.onmousemove;
        var onmouseoutOld = window.onmouseout;
        var onmouseoverOld = window.onmouseover;
        var onmouseupOld = window.onmouseup;
        var onmousewheelOld = window.onmousewheel;
        var onresetOld = window.onreset;
        var onresizeOld = window.onresize;
        var onscrollOld = window.onscroll;
        var onsearchOld = window.onsearch;
        var onselectOld = window.onselect;
        var onsubmitOld = window.onsubmit;
        var onunloadOld = window.onunload;
        var openerOld = window.opener;
        var outerHeightOld = window.outerHeight;
        var outerWidthOld = window.outerWidth;
        var pageXOffsetOld = window.pageXOffset;
        var pageYOffsetOld = window.pageYOffset;
        var personalbarOld = window.personalbar;
        var pluginsOld = window.plugins;
        var screenLeftOld = window.screenLeft;
        var screenOld = window.screen;
        var screenTopOld = window.screenTop;
        var screenXOld = window.screenX;
        var screenYOld = window.screenY;
        var scrollbarsOld = window.scrollbars;
        var scrollXOld = window.scrollX;
        var scrollYOld = window.scrollY;
        var selfOld = window.self;
        var statusbarOld = window.statusbar;
        var statusOld = window.status;
        var toolbarOld = window.toolbar;
        var windowOld = window.window;
        var parentOld = window.parent;
        var topOld = window.top;

        // Functions
        var addEventListenerOld = window.addEventListener;
        var alertOld = window.alert;
        var atobOld = window.atob;
        var blurOld = window.blur;
        var btoaOld = window.btoa;
        var captureEventsOld = window.captureEvents;
        var clearIntervalOld = window.clearInterval;
        var clearTimeoutOld = window.clearTimeout;
        var closeOld = window.close;
        var confirmOld = window.confirm;
        var evalOld = window.eval;
        var findOld = window.find;
        var focusOld = window.focus;
        var getComputedStyleOld = window.getComputedStyle;
        var getMatchedCSSRulesOld = window.getMatchedCSSRules;
        var getSelectionOld = window.getSelection;
        var moveByOld = window.moveBy;
        var moveToOld = window.moveTo;
        var openOld = window.open;
        var printOld = window.print;
        var promptOld = window.prompt;
        var releaseEventsOld = window.releaseEvents;
        var removeEventListenerOld = window.removeEventListener;
        var resizeByOld = window.resizeBy;
        var resizeToOld = window.resizeTo;
        var scrollByOld = window.scrollBy;
        var scrollOld = window.scroll;
        var scrollToOld = window.scrollTo;
        var setIntervalOld = window.setInterval;
        var setTimeoutOld = window.setTimeout;
        var stopOld = window.stop;

        // Postpone verifying that old values haven't changed until
        // the main frame notifies us that it has already attempted
        // xss to set the property values.
        window.addEventListener("message", receiveMessage, false);
        function receiveMessage(event) {
            if (event.data != "READY-FOR-OLD-VALUES-VERIFICATION") {
                log("UNEXPECTED MESSAGE: " + event.data);
                return;
            }

            // Constructors
            shouldBe("window.Attr", "AttrOld");
            shouldBe("window.CDATASection", "CDATASectionOld");
            shouldBe("window.CharacterData", "CharacterDataOld");
            shouldBe("window.Comment", "CommentOld");
            shouldBe("window.CSSRule", "CSSRuleOld");
            shouldBe("window.CSSStyleDeclaration", "CSSStyleDeclarationOld");
            shouldBe("window.Document", "DocumentOld");
            shouldBe("window.DocumentFragment", "DocumentFragmentOld");
            shouldBe("window.DocumentType", "DocumentTypeOld");
            shouldBe("window.DOMException", "DOMExceptionOld");
            shouldBe("window.DOMImplementation", "DOMImplementationOld");
            shouldBe("window.DOMParser", "DOMParserOld");
            shouldBe("window.Element", "ElementOld");
            shouldBe("window.Entity", "EntityOld");
            shouldBe("window.EntityReference", "EntityReferenceOld");
            shouldBe("window.EvalError", "EvalErrorOld");
            shouldBe("window.Event", "EventOld");
            shouldBe("window.HTMLAnchorElement", "HTMLAnchorElementOld");
            shouldBe("window.HTMLAreaElement", "HTMLAreaElementOld");
            shouldBe("window.HTMLBaseElement", "HTMLBaseElementOld");
            shouldBe("window.HTMLBodyElement", "HTMLBodyElementOld");
            shouldBe("window.HTMLBRElement", "HTMLBRElementOld");
            shouldBe("window.HTMLButtonElement", "HTMLButtonElementOld");
            shouldBe("window.HTMLCanvasElement", "HTMLCanvasElementOld");
            shouldBe("window.HTMLDirectoryElement", "HTMLDirectoryElementOld");
            shouldBe("window.HTMLDivElement", "HTMLDivElementOld");
            shouldBe("window.HTMLDListElement", "HTMLDListElementOld");
            shouldBe("window.HTMLDocument", "HTMLDocumentOld");
            shouldBe("window.HTMLElement", "HTMLElementOld");
            shouldBe("window.HTMLFieldSetElement", "HTMLFieldSetElementOld");
            shouldBe("window.HTMLFontElement", "HTMLFontElementOld");
            shouldBe("window.HTMLFormElement", "HTMLFormElementOld");
            shouldBe("window.HTMLFrameElement", "HTMLFrameElementOld");
            shouldBe("window.HTMLFrameSetElement", "HTMLFrameSetElementOld");
            shouldBe("window.HTMLHeadElement", "HTMLHeadElementOld");
            shouldBe("window.HTMLHeadingElement", "HTMLHeadingElementOld");
            shouldBe("window.HTMLHRElement", "HTMLHRElementOld");
            shouldBe("window.HTMLHtmlElement", "HTMLHtmlElementOld");
            shouldBe("window.HTMLIFrameElement", "HTMLIFrameElementOld");
            shouldBe("window.HTMLImageElement", "HTMLImageElementOld");
            shouldBe("window.HTMLInputElement", "HTMLInputElementOld");
            shouldBe("window.HTMLIsIndexElement", "HTMLIsIndexElementOld");
            shouldBe("window.HTMLLabelElement", "HTMLLabelElementOld");
            shouldBe("window.HTMLLegendElement", "HTMLLegendElementOld");
            shouldBe("window.HTMLLIElement", "HTMLLIElementOld");
            shouldBe("window.HTMLLinkElement", "HTMLLinkElementOld");
            shouldBe("window.HTMLMapElement", "HTMLMapElementOld");
            shouldBe("window.HTMLMarqueeElement", "HTMLMarqueeElementOld");
            shouldBe("window.HTMLMenuElement", "HTMLMenuElementOld");
            shouldBe("window.HTMLMetaElement", "HTMLMetaElementOld");
            shouldBe("window.HTMLModElement", "HTMLModElementOld");
            shouldBe("window.HTMLOListElement", "HTMLOListElementOld");
            shouldBe("window.HTMLOptGroupElement", "HTMLOptGroupElementOld");
            shouldBe("window.HTMLOptionElement", "HTMLOptionElementOld");
            shouldBe("window.HTMLParagraphElement", "HTMLParagraphElementOld");
            shouldBe("window.HTMLParamElement", "HTMLParamElementOld");
            shouldBe("window.HTMLPreElement", "HTMLPreElementOld");
            shouldBe("window.HTMLQuoteElement", "HTMLQuoteElementOld");
            shouldBe("window.HTMLScriptElement", "HTMLScriptElementOld");
            shouldBe("window.HTMLSelectElement", "HTMLSelectElementOld");
            shouldBe("window.HTMLStyleElement", "HTMLStyleElementOld");
            shouldBe("window.HTMLTableCaptionElement", "HTMLTableCaptionElementOld");
            shouldBe("window.HTMLTableCellElement", "HTMLTableCellElementOld");
            shouldBe("window.HTMLTableColElement", "HTMLTableColElementOld");
            shouldBe("window.HTMLTableElement", "HTMLTableElementOld");
            shouldBe("window.HTMLTableRowElement", "HTMLTableRowElementOld");
            shouldBe("window.HTMLTableSectionElement", "HTMLTableSectionElementOld");
            shouldBe("window.HTMLTextAreaElement", "HTMLTextAreaElementOld");
            shouldBe("window.HTMLTitleElement", "HTMLTitleElementOld");
            shouldBe("window.HTMLUListElement", "HTMLUListElementOld");
            shouldBe("window.MutationEvent", "MutationEventOld");
            shouldBe("window.Node", "NodeOld");
            shouldBe("window.NodeFilter", "NodeFilterOld");
            shouldBe("window.ProcessingInstruction", "ProcessingInstructionOld");
            shouldBe("window.Range", "RangeOld");
            shouldBe("window.RangeError", "RangeErrorOld");
            shouldBe("window.ReferenceError", "ReferenceErrorOld");
            shouldBe("window.SyntaxError", "SyntaxErrorOld");
            shouldBe("window.Text", "TextOld");
            shouldBe("window.TypeError", "TypeErrorOld");
            shouldBe("window.URIError", "URIErrorOld");
            shouldBe("window.XMLDocument", "XMLDocumentOld");
            shouldBe("window.XMLSerializer", "XMLSerializerOld");
            shouldBe("window.XPathEvaluator", "XPathEvaluatorOld");
            shouldBe("window.XPathResult", "XPathResultOld");

            // FIXME: find a way to test these Constructors
            // shouldBe("window.Image", "ImageOld");
            // shouldBe("window.Option", "OptionOld");
            // shouldBe("window.XMLHttpRequest", "XMLHttpRequestOld");
            // shouldBe("window.XSLTProcessor", "XSLTProcessorOld");

            // Attributes
            shouldBe("window.clientInformation", "clientInformationOld");
            shouldBe("window.closed", "closedOld");
            shouldBe("window.console", "consoleOld");
            shouldBe("window.crypto", "cryptoOld");
            shouldBe("window.defaultStatus", "defaultStatusOld");
            shouldBe("window.defaultstatus", "defaultstatusOld");
            shouldBe("window.devicePixelRatio", "devicePixelRatioOld");
            shouldBe("window.document", "documentOld");
            shouldBe("window.embeds", "embedsOld");
            shouldBe("window.frameElement", "null");
            shouldBe("window.frames", "framesOld");
            shouldBe("window.history", "historyOld");
            shouldBe("window.images", "imagesOld");
            shouldBe("window.innerHeight", "innerHeightOld");
            shouldBe("window.innerWidth", "innerWidthOld");
            shouldBe("window.length", "lengthOld");
            shouldBe("window.locationbar", "locationbarOld");
            shouldBe("window.menubar", "menubarOld");
            shouldBe("window.name", "nameOld");
            shouldBe("window.navigator", "navigatorOld");
            shouldBe("window.offscreenBuffering", "offscreenBufferingOld");
            shouldBe("window.onabort", "onabortOld");
            shouldBe("window.onbeforeunload", "onbeforeunloadOld");
            shouldBe("window.onblur", "onblurOld");
            shouldBe("window.onchange", "onchangeOld");
            shouldBe("window.onclick", "onclickOld");
            shouldBe("window.ondblclick", "ondblclickOld");
            shouldBe("window.onerror", "onerrorOld");
            shouldBe("window.onfocus", "onfocusOld");
            shouldBe("window.onkeydown", "onkeydownOld");
            shouldBe("window.onkeypress", "onkeypressOld");
            shouldBe("window.onkeyup", "onkeyupOld");
            shouldBe("window.onload", "onloadOld");
            shouldBe("window.onmousedown", "onmousedownOld");
            shouldBe("window.onmousemove", "onmousemoveOld");
            shouldBe("window.onmouseout", "onmouseoutOld");
            shouldBe("window.onmouseover", "onmouseoverOld");
            shouldBe("window.onmouseup", "onmouseupOld");
            shouldBe("window.onmousewheel", "onmousewheelOld");
            shouldBe("window.onreset", "onresetOld");
            shouldBe("window.onresize", "onresizeOld");
            shouldBe("window.onscroll", "onscrollOld");
            shouldBe("window.onsearch", "onsearchOld");
            shouldBe("window.onselect", "onselectOld");
            shouldBe("window.onsubmit", "onsubmitOld");
            shouldBe("window.onunload", "onunloadOld");
            shouldBe("window.opener", "openerOld");
            shouldBe("window.outerHeight", "outerHeightOld", true); // The result can be dependent on previous tests.
            shouldBe("window.outerWidth", "outerWidthOld", true); // The result can be dependent on previous tests.
            shouldBe("window.pageXOffset", "pageXOffsetOld");
            shouldBe("window.pageYOffset", "pageYOffsetOld");
            shouldBe("window.personalbar", "personalbarOld");
            shouldBe("window.plugins", "pluginsOld");
            shouldBe("window.screen", "screenOld");
            shouldBe("window.screenLeft", "screenLeftOld", true); // The result is based on the physical screen size, so don't display the values.
            shouldBe("window.screenTop", "screenTopOld", true); // The result is based on the physical screen size, so don't display the values.
            shouldBe("window.screenX", "screenXOld", true); // The result is based on the physical screen size, so don't display the values.
            shouldBe("window.screenY", "screenYOld", true); // The result is based on the physical screen size, so don't display the values.
            shouldBe("window.scrollbars", "scrollbarsOld");
            shouldBe("window.scrollX", "scrollXOld");
            shouldBe("window.scrollY", "scrollYOld");
            shouldBe("window.self", "selfOld");
            shouldBe("window.status", "statusOld");
            shouldBe("window.statusbar", "statusbarOld");
            shouldBe("window.toolbar", "toolbarOld");
            shouldBe("window.window", "windowOld");

            // Using shouldBe for parent and top causes extraneous warnings due to cross-orgin toString'ing.
            if (window.parent === parentOld) {
                console.log("PASS: window.parent should be parentOld and is.");
            } else {
                console.log("*** FAIL: window.parent should be parentOld but instead is " + window.parent + ". ***");
            }

            if (window.top === topOld) {
                console.log("PASS: window.top should be topOld and is.");
            } else {
                console.log("*** FAIL: window.top should be topOld but instead is " + window.top + ". ***");
            }

            // Functions
            shouldBe("window.addEventListener", "addEventListenerOld");
            shouldBe("window.alert", "alertOld");
            shouldBe("window.atob", "atobOld");
            shouldBe("window.blur", "blurOld");
            shouldBe("window.btoa", "btoaOld");
            shouldBe("window.captureEvents", "captureEventsOld");
            shouldBe("window.clearInterval", "clearIntervalOld");
            shouldBe("window.clearTimeout", "clearTimeoutOld");
            shouldBe("window.close", "closeOld");
            shouldBe("window.confirm", "confirmOld");
            shouldBe("window.eval", "evalOld");
            shouldBe("window.find", "findOld");
            shouldBe("window.focus", "focusOld");
            shouldBe("window.getComputedStyle", "getComputedStyleOld");
            shouldBe("window.getMatchedCSSRules", "getMatchedCSSRulesOld");
            shouldBe("window.getSelection", "getSelectionOld");
            shouldBe("window.moveBy", "moveByOld");
            shouldBe("window.moveTo", "moveToOld");
            shouldBe("window.open", "openOld");
            shouldBe("window.print", "printOld");
            shouldBe("window.prompt", "promptOld");
            shouldBe("window.releaseEvents", "releaseEventsOld");
            shouldBe("window.removeEventListener", "removeEventListenerOld");
            shouldBe("window.resizeBy", "resizeByOld");
            shouldBe("window.resizeTo", "resizeToOld");
            shouldBe("window.scroll", "scrollOld");
            shouldBe("window.scrollBy", "scrollByOld");
            shouldBe("window.scrollTo", "scrollToOld");
            shouldBe("window.setInterval", "setIntervalOld");
            shouldBe("window.setTimeout", "setTimeoutOld");

            shouldBe("window.stop", "stopOld");

            window.parent.postMessage("TEST-COMPLETED", "*");
        }
    </script>
</body>
</html>