Implement Window.postMessage for same-origin windows.

This commit is contained in:
Josh Matthews 2016-05-12 14:04:08 -04:00 committed by Ms2ger
parent 1837fcbedd
commit f152bc3b06
83 changed files with 192 additions and 383 deletions

View file

@ -349,6 +349,10 @@ impl Document {
true
}
pub fn origin(&self) -> &Origin {
&self.origin
}
// https://dom.spec.whatwg.org/#concept-document-url
pub fn url(&self) -> &Url {
&self.url

View file

@ -54,6 +54,8 @@
void cancelAnimationFrame(unsigned long handle);
//void postMessage(any message, DOMString targetOrigin, optional sequence<Transferable> transfer);
[Throws]
void postMessage(any message, DOMString targetOrigin);
// also has obsolete members
};

View file

@ -19,8 +19,10 @@ use dom::bindings::global::{GlobalRef, global_root_from_object};
use dom::bindings::inheritance::Castable;
use dom::bindings::js::{JS, MutNullableHeap, Root};
use dom::bindings::num::Finite;
use dom::bindings::refcounted::Trusted;
use dom::bindings::reflector::Reflectable;
use dom::bindings::str::DOMString;
use dom::bindings::structuredclone::StructuredCloneData;
use dom::bindings::utils::{GlobalStaticData, WindowProxyHandler};
use dom::browsingcontext::BrowsingContext;
use dom::console::Console;
@ -33,6 +35,7 @@ use dom::eventtarget::EventTarget;
use dom::history::History;
use dom::htmliframeelement::build_mozbrowser_custom_event;
use dom::location::Location;
use dom::messageevent::MessageEvent;
use dom::navigator::Navigator;
use dom::node::{Node, from_untrusted_node_address, window_from_node};
use dom::performance::Performance;
@ -43,6 +46,7 @@ use gfx_traits::LayerId;
use ipc_channel::ipc::{self, IpcSender};
use js::jsapi::{Evaluate2, HandleObject, HandleValue, JSAutoCompartment, JSContext};
use js::jsapi::{JS_GetRuntime, JS_GC, MutableHandleValue, SetWindowProxy};
use js::jsval::UndefinedValue;
use js::rust::CompileOptionsWrapper;
use js::rust::Runtime;
use libc;
@ -53,6 +57,7 @@ use net_traits::image_cache_thread::{ImageCacheChan, ImageCacheThread};
use net_traits::storage_thread::StorageType;
use num_traits::ToPrimitive;
use open;
use origin::Origin;
use profile_traits::mem;
use profile_traits::time::{ProfilerCategory, TimerMetadata, TimerMetadataFrameType};
use profile_traits::time::{ProfilerChan, TimerMetadataReflowType, profile};
@ -62,9 +67,9 @@ use script_layout_interface::message::{Msg, Reflow, ReflowQueryType, ScriptReflo
use script_layout_interface::reporter::CSSErrorReporter;
use script_layout_interface::rpc::{ContentBoxResponse, ContentBoxesResponse, LayoutRPC};
use script_layout_interface::rpc::{MarginStyleResponse, ResolvedStyleResponse};
use script_runtime::{ScriptChan, ScriptPort, maybe_take_panic_result};
use script_runtime::{ScriptChan, ScriptPort, CommonScriptMsg, ScriptThreadEventCategory, maybe_take_panic_result};
use script_thread::SendableMainThreadScriptChan;
use script_thread::{MainThreadScriptChan, MainThreadScriptMsg, RunnableWrapper};
use script_thread::{MainThreadScriptChan, MainThreadScriptMsg, RunnableWrapper, Runnable};
use script_traits::webdriver_msg::{WebDriverJSError, WebDriverJSResult};
use script_traits::{ConstellationControlMsg, MozBrowserEvent, UntrustedNodeAddress};
use script_traits::{DocumentState, MsDuration, TimerEvent, TimerEventId};
@ -650,6 +655,38 @@ impl WindowMethods for Window {
doc.cancel_animation_frame(ident);
}
// https://html.spec.whatwg.org/multipage/#dom-window-postmessage
fn PostMessage(&self,
cx: *mut JSContext,
message: HandleValue,
origin: DOMString)
-> ErrorResult {
// Step 3-5.
let origin = match &origin[..] {
"*" => None,
"/" => {
// TODO(#12715): Should be the origin of the incumbent settings
// object, not self's.
Some(self.Document().origin().copy())
},
url => match Url::parse(&url) {
Ok(url) => Some(Origin::new(&url)),
Err(_) => return Err(Error::Syntax),
}
};
// Step 1-2, 6-8.
// TODO(#12717): Should implement the `transfer` argument.
let data = try!(StructuredCloneData::write(cx, message));
// Step 9.
let runnable = PostMessageHandler::new(self, origin, data);
let msg = CommonScriptMsg::RunnableMsg(ScriptThreadEventCategory::DomEvent, box runnable);
// TODO(#12718): Use the "posted message task source".
let _ = self.script_chan.send(msg);
Ok(())
}
// https://html.spec.whatwg.org/multipage/#dom-window-captureevents
fn CaptureEvents(&self) {
// This method intentionally does nothing
@ -1767,3 +1804,50 @@ fn debug_reflow_events(id: PipelineId, goal: &ReflowGoal, query_type: &ReflowQue
println!("{}", debug_msg);
}
struct PostMessageHandler {
destination: Trusted<Window>,
origin: Option<Origin>,
message: StructuredCloneData,
}
impl PostMessageHandler {
fn new(window: &Window,
origin: Option<Origin>,
message: StructuredCloneData) -> PostMessageHandler {
PostMessageHandler {
destination: Trusted::new(window),
origin: origin,
message: message,
}
}
}
impl Runnable for PostMessageHandler {
// https://html.spec.whatwg.org/multipage/#dom-window-postmessage steps 10-12.
fn handler(self: Box<PostMessageHandler>) {
let this = *self;
let window = this.destination.root();
// Step 10.
let doc = window.Document();
if let Some(source) = this.origin {
if !source.same_origin(doc.origin()) {
return;
}
}
let cx = window.get_cx();
let globalhandle = window.reflector().get_jsobject();
let _ac = JSAutoCompartment::new(cx, globalhandle.get());
rooted!(in(cx) let mut message = UndefinedValue());
this.message.read(GlobalRef::Window(&*window), message.handle_mut());
// Step 11-12.
// TODO(#12719): set the other attributes.
MessageEvent::dispatch_jsval(window.upcast(),
GlobalRef::Window(&*window),
message.handle());
}
}

View file

@ -1,6 +0,0 @@
[xmlhttprequest-sync-block-defer-scripts.html]
type: testharness
expected: TIMEOUT
[Check that a sync XHR in a defer script blocks later defer scripts from running]
expected: NOTRUN

View file

@ -1,6 +0,0 @@
[xmlhttprequest-sync-not-hang-scriptloader.html]
type: testharness
expected: TIMEOUT
[Ensure that an async script added during a defer script that then does a\n sync XHR still runs]
expected: NOTRUN

View file

@ -1,3 +0,0 @@
[xmlhttprequest-timeout-aborted.html]
type: testharness
expected: TIMEOUT

View file

@ -1,3 +0,0 @@
[xmlhttprequest-timeout-abortedonmain.html]
type: testharness
expected: TIMEOUT

View file

@ -1,3 +0,0 @@
[xmlhttprequest-timeout-overrides.html]
type: testharness
expected: TIMEOUT

View file

@ -1,3 +0,0 @@
[xmlhttprequest-timeout-overridesexpires.html]
type: testharness
expected: TIMEOUT

View file

@ -1,3 +0,0 @@
[xmlhttprequest-timeout-simple.html]
type: testharness
expected: TIMEOUT

View file

@ -1,3 +0,0 @@
[xmlhttprequest-timeout-synconmain.html]
type: testharness
expected: TIMEOUT

View file

@ -1,3 +0,0 @@
[xmlhttprequest-timeout-twice.html]
type: testharness
expected: TIMEOUT

View file

@ -1,6 +1,5 @@
[headers-structure.html]
type: testharness
expected: OK
[Headers has entries method]
expected: FAIL

View file

@ -1,6 +0,0 @@
[001.html]
type: testharness
expected: TIMEOUT
[Cross-origin navigation started from unload handler]
expected: TIMEOUT

View file

@ -1,6 +0,0 @@
[002.html]
type: testharness
expected: TIMEOUT
[Multiple simultaneous navigations]
expected: TIMEOUT

View file

@ -2,5 +2,5 @@
type: testharness
expected: TIMEOUT
[Navigation from unload whilst traversing history]
expected: NOTRUN
expected: TIMEOUT

View file

@ -2,5 +2,5 @@
type: testharness
expected: TIMEOUT
[Navigation from unload whilst traversing cross-origin history]
expected: NOTRUN
expected: TIMEOUT

View file

@ -2,5 +2,5 @@
type: testharness
expected: TIMEOUT
[Child document navigating parent via location ]
expected: NOTRUN
expected: TIMEOUT

View file

@ -2,5 +2,5 @@
type: testharness
expected: TIMEOUT
[Child document navigating parent via submit ]
expected: NOTRUN
expected: TIMEOUT

View file

@ -1,6 +1,5 @@
[navigation_unload_same_origin.html]
type: testharness
expected: TIMEOUT
[Same-origin navigation started from unload handler]
expected: TIMEOUT
expected: FAIL

View file

@ -2,5 +2,5 @@
type: testharness
expected: TIMEOUT
[Check that popups from a sandboxed iframe escape the sandbox if\n allow-popups-to-escape-sandbox is used]
expected: NOTRUN
expected: TIMEOUT

View file

@ -1,6 +0,0 @@
[insecure-protocol.keep-origin-redirect.http.html]
type: testharness
expected: TIMEOUT
[The referrer URL is stripped-referrer when a\n document served over http requires an http\n sub-resource via script-tag using the http-rp\n delivery method with keep-origin-redirect and when\n the target request is cross-origin.]
expected: NOTRUN

View file

@ -1,6 +0,0 @@
[insecure-protocol.no-redirect.http.html]
type: testharness
expected: TIMEOUT
[The referrer URL is stripped-referrer when a\n document served over http requires an http\n sub-resource via script-tag using the http-rp\n delivery method with no-redirect and when\n the target request is cross-origin.]
expected: NOTRUN

View file

@ -1,6 +0,0 @@
[insecure-protocol.swap-origin-redirect.http.html]
type: testharness
expected: TIMEOUT
[The referrer URL is stripped-referrer when a\n document served over http requires an http\n sub-resource via script-tag using the http-rp\n delivery method with swap-origin-redirect and when\n the target request is cross-origin.]
expected: NOTRUN

View file

@ -1,6 +0,0 @@
[insecure-protocol.keep-origin-redirect.http.html]
type: testharness
expected: TIMEOUT
[The referrer URL is stripped-referrer when a\n document served over http requires an http\n sub-resource via script-tag using the http-rp\n delivery method with keep-origin-redirect and when\n the target request is same-origin.]
expected: NOTRUN

View file

@ -1,6 +0,0 @@
[insecure-protocol.no-redirect.http.html]
type: testharness
expected: TIMEOUT
[The referrer URL is stripped-referrer when a\n document served over http requires an http\n sub-resource via script-tag using the http-rp\n delivery method with no-redirect and when\n the target request is same-origin.]
expected: NOTRUN

View file

@ -1,6 +0,0 @@
[insecure-protocol.swap-origin-redirect.http.html]
type: testharness
expected: TIMEOUT
[The referrer URL is stripped-referrer when a\n document served over http requires an http\n sub-resource via script-tag using the http-rp\n delivery method with swap-origin-redirect and when\n the target request is same-origin.]
expected: NOTRUN

View file

@ -1,6 +0,0 @@
[generic.keep-origin-redirect.http.html]
type: testharness
expected: TIMEOUT
[The referrer URL is omitted when a\n document served over http requires an http\n sub-resource via script-tag using the http-rp\n delivery method with keep-origin-redirect and when\n the target request is cross-origin.]
expected: NOTRUN

View file

@ -1,6 +0,0 @@
[generic.no-redirect.http.html]
type: testharness
expected: TIMEOUT
[The referrer URL is omitted when a\n document served over http requires an http\n sub-resource via script-tag using the http-rp\n delivery method with no-redirect and when\n the target request is cross-origin.]
expected: NOTRUN

View file

@ -1,6 +0,0 @@
[generic.swap-origin-redirect.http.html]
type: testharness
expected: TIMEOUT
[The referrer URL is omitted when a\n document served over http requires an http\n sub-resource via script-tag using the http-rp\n delivery method with swap-origin-redirect and when\n the target request is cross-origin.]
expected: NOTRUN

View file

@ -1,6 +0,0 @@
[generic.keep-origin-redirect.http.html]
type: testharness
expected: TIMEOUT
[The referrer URL is omitted when a\n document served over http requires an http\n sub-resource via script-tag using the http-rp\n delivery method with keep-origin-redirect and when\n the target request is same-origin.]
expected: NOTRUN

View file

@ -1,6 +0,0 @@
[generic.no-redirect.http.html]
type: testharness
expected: TIMEOUT
[The referrer URL is omitted when a\n document served over http requires an http\n sub-resource via script-tag using the http-rp\n delivery method with no-redirect and when\n the target request is same-origin.]
expected: NOTRUN

View file

@ -1,6 +0,0 @@
[generic.swap-origin-redirect.http.html]
type: testharness
expected: TIMEOUT
[The referrer URL is omitted when a\n document served over http requires an http\n sub-resource via script-tag using the http-rp\n delivery method with swap-origin-redirect and when\n the target request is same-origin.]
expected: NOTRUN

View file

@ -1,6 +0,0 @@
[cross-origin.keep-origin-redirect.http.html]
type: testharness
expected: TIMEOUT
[The referrer URL is origin when a\n document served over http requires an http\n sub-resource via script-tag using the http-rp\n delivery method with keep-origin-redirect and when\n the target request is cross-origin.]
expected: NOTRUN

View file

@ -1,6 +0,0 @@
[cross-origin.no-redirect.http.html]
type: testharness
expected: TIMEOUT
[The referrer URL is origin when a\n document served over http requires an http\n sub-resource via script-tag using the http-rp\n delivery method with no-redirect and when\n the target request is cross-origin.]
expected: NOTRUN

View file

@ -1,6 +0,0 @@
[cross-origin.swap-origin-redirect.http.html]
type: testharness
expected: TIMEOUT
[The referrer URL is origin when a\n document served over http requires an http\n sub-resource via script-tag using the http-rp\n delivery method with swap-origin-redirect and when\n the target request is cross-origin.]
expected: NOTRUN

View file

@ -1,6 +0,0 @@
[same-origin-insecure.keep-origin-redirect.http.html]
type: testharness
expected: TIMEOUT
[The referrer URL is stripped-referrer when a\n document served over http requires an http\n sub-resource via script-tag using the http-rp\n delivery method with keep-origin-redirect and when\n the target request is same-origin.]
expected: NOTRUN

View file

@ -1,6 +0,0 @@
[same-origin-insecure.no-redirect.http.html]
type: testharness
expected: TIMEOUT
[The referrer URL is stripped-referrer when a\n document served over http requires an http\n sub-resource via script-tag using the http-rp\n delivery method with no-redirect and when\n the target request is same-origin.]
expected: NOTRUN

View file

@ -1,6 +0,0 @@
[same-origin-insecure.swap-origin-redirect.http.html]
type: testharness
expected: TIMEOUT
[The referrer URL is origin when a\n document served over http requires an http\n sub-resource via script-tag using the http-rp\n delivery method with swap-origin-redirect and when\n the target request is same-origin.]
expected: NOTRUN

View file

@ -1,6 +0,0 @@
[generic.keep-origin-redirect.http.html]
type: testharness
expected: TIMEOUT
[The referrer URL is origin when a\n document served over http requires an http\n sub-resource via script-tag using the http-rp\n delivery method with keep-origin-redirect and when\n the target request is cross-origin.]
expected: NOTRUN

View file

@ -1,6 +0,0 @@
[generic.no-redirect.http.html]
type: testharness
expected: TIMEOUT
[The referrer URL is origin when a\n document served over http requires an http\n sub-resource via script-tag using the http-rp\n delivery method with no-redirect and when\n the target request is cross-origin.]
expected: NOTRUN

View file

@ -1,6 +0,0 @@
[generic.swap-origin-redirect.http.html]
type: testharness
expected: TIMEOUT
[The referrer URL is origin when a\n document served over http requires an http\n sub-resource via script-tag using the http-rp\n delivery method with swap-origin-redirect and when\n the target request is cross-origin.]
expected: NOTRUN

View file

@ -1,6 +0,0 @@
[generic.keep-origin-redirect.http.html]
type: testharness
expected: TIMEOUT
[The referrer URL is origin when a\n document served over http requires an http\n sub-resource via script-tag using the http-rp\n delivery method with keep-origin-redirect and when\n the target request is same-origin.]
expected: NOTRUN

View file

@ -1,6 +0,0 @@
[generic.no-redirect.http.html]
type: testharness
expected: TIMEOUT
[The referrer URL is origin when a\n document served over http requires an http\n sub-resource via script-tag using the http-rp\n delivery method with no-redirect and when\n the target request is same-origin.]
expected: NOTRUN

View file

@ -1,6 +0,0 @@
[generic.swap-origin-redirect.http.html]
type: testharness
expected: TIMEOUT
[The referrer URL is origin when a\n document served over http requires an http\n sub-resource via script-tag using the http-rp\n delivery method with swap-origin-redirect and when\n the target request is same-origin.]
expected: NOTRUN

View file

@ -1,6 +1,5 @@
[generic.keep-origin-redirect.http.html]
type: testharness
expected: TIMEOUT
[The referrer URL is origin when a\n document served over http requires an http\n sub-resource via script-tag using the meta-csp\n delivery method with keep-origin-redirect and when\n the target request is cross-origin.]
expected: NOTRUN
expected: FAIL

View file

@ -1,6 +1,5 @@
[generic.no-redirect.http.html]
type: testharness
expected: TIMEOUT
[The referrer URL is origin when a\n document served over http requires an http\n sub-resource via script-tag using the meta-csp\n delivery method with no-redirect and when\n the target request is cross-origin.]
expected: NOTRUN
expected: FAIL

View file

@ -1,6 +1,5 @@
[generic.swap-origin-redirect.http.html]
type: testharness
expected: TIMEOUT
[The referrer URL is origin when a\n document served over http requires an http\n sub-resource via script-tag using the meta-csp\n delivery method with swap-origin-redirect and when\n the target request is cross-origin.]
expected: NOTRUN
expected: FAIL

View file

@ -1,6 +1,5 @@
[generic.keep-origin-redirect.http.html]
type: testharness
expected: TIMEOUT
[The referrer URL is origin when a\n document served over http requires an http\n sub-resource via script-tag using the meta-csp\n delivery method with keep-origin-redirect and when\n the target request is same-origin.]
expected: NOTRUN
expected: FAIL

View file

@ -1,6 +1,5 @@
[generic.no-redirect.http.html]
type: testharness
expected: TIMEOUT
[The referrer URL is origin when a\n document served over http requires an http\n sub-resource via script-tag using the meta-csp\n delivery method with no-redirect and when\n the target request is same-origin.]
expected: NOTRUN
expected: FAIL

View file

@ -1,6 +1,5 @@
[generic.swap-origin-redirect.http.html]
type: testharness
expected: TIMEOUT
[The referrer URL is origin when a\n document served over http requires an http\n sub-resource via script-tag using the meta-csp\n delivery method with swap-origin-redirect and when\n the target request is same-origin.]
expected: NOTRUN
expected: FAIL

View file

@ -1,6 +0,0 @@
[generic.keep-origin-redirect.http.html]
type: testharness
expected: TIMEOUT
[The referrer URL is origin when a\n document served over http requires an http\n sub-resource via script-tag using the meta-referrer\n delivery method with keep-origin-redirect and when\n the target request is cross-origin.]
expected: NOTRUN

View file

@ -1,6 +0,0 @@
[generic.no-redirect.http.html]
type: testharness
expected: TIMEOUT
[The referrer URL is origin when a\n document served over http requires an http\n sub-resource via script-tag using the meta-referrer\n delivery method with no-redirect and when\n the target request is cross-origin.]
expected: NOTRUN

View file

@ -1,6 +0,0 @@
[generic.swap-origin-redirect.http.html]
type: testharness
expected: TIMEOUT
[The referrer URL is origin when a\n document served over http requires an http\n sub-resource via script-tag using the meta-referrer\n delivery method with swap-origin-redirect and when\n the target request is cross-origin.]
expected: NOTRUN

View file

@ -1,6 +0,0 @@
[generic.keep-origin-redirect.http.html]
type: testharness
expected: TIMEOUT
[The referrer URL is origin when a\n document served over http requires an http\n sub-resource via script-tag using the meta-referrer\n delivery method with keep-origin-redirect and when\n the target request is same-origin.]
expected: NOTRUN

View file

@ -1,6 +0,0 @@
[generic.no-redirect.http.html]
type: testharness
expected: TIMEOUT
[The referrer URL is origin when a\n document served over http requires an http\n sub-resource via script-tag using the meta-referrer\n delivery method with no-redirect and when\n the target request is same-origin.]
expected: NOTRUN

View file

@ -1,6 +0,0 @@
[generic.swap-origin-redirect.http.html]
type: testharness
expected: TIMEOUT
[The referrer URL is origin when a\n document served over http requires an http\n sub-resource via script-tag using the meta-referrer\n delivery method with swap-origin-redirect and when\n the target request is same-origin.]
expected: NOTRUN

View file

@ -1,6 +0,0 @@
[cross-origin.keep-origin-redirect.http.html]
type: testharness
expected: TIMEOUT
[The referrer URL is omitted when a\n document served over http requires an http\n sub-resource via script-tag using the http-rp\n delivery method with keep-origin-redirect and when\n the target request is cross-origin.]
expected: NOTRUN

View file

@ -1,6 +0,0 @@
[cross-origin.no-redirect.http.html]
type: testharness
expected: TIMEOUT
[The referrer URL is omitted when a\n document served over http requires an http\n sub-resource via script-tag using the http-rp\n delivery method with no-redirect and when\n the target request is cross-origin.]
expected: NOTRUN

View file

@ -1,6 +0,0 @@
[cross-origin.swap-origin-redirect.http.html]
type: testharness
expected: TIMEOUT
[The referrer URL is omitted when a\n document served over http requires an http\n sub-resource via script-tag using the http-rp\n delivery method with swap-origin-redirect and when\n the target request is cross-origin.]
expected: NOTRUN

View file

@ -1,6 +0,0 @@
[same-origin-insecure.keep-origin-redirect.http.html]
type: testharness
expected: TIMEOUT
[The referrer URL is stripped-referrer when a\n document served over http requires an http\n sub-resource via script-tag using the http-rp\n delivery method with keep-origin-redirect and when\n the target request is same-origin.]
expected: NOTRUN

View file

@ -1,6 +0,0 @@
[same-origin-insecure.no-redirect.http.html]
type: testharness
expected: TIMEOUT
[The referrer URL is stripped-referrer when a\n document served over http requires an http\n sub-resource via script-tag using the http-rp\n delivery method with no-redirect and when\n the target request is same-origin.]
expected: NOTRUN

View file

@ -1,6 +0,0 @@
[same-origin-insecure.swap-origin-redirect.http.html]
type: testharness
expected: TIMEOUT
[The referrer URL is omitted when a\n document served over http requires an http\n sub-resource via script-tag using the http-rp\n delivery method with swap-origin-redirect and when\n the target request is same-origin.]
expected: NOTRUN

View file

@ -1,6 +0,0 @@
[cross-origin.keep-origin-redirect.http.html]
type: testharness
expected: TIMEOUT
[The referrer URL is omitted when a\n document served over http requires an http\n sub-resource via script-tag using the meta-csp\n delivery method with keep-origin-redirect and when\n the target request is cross-origin.]
expected: NOTRUN

View file

@ -1,6 +0,0 @@
[cross-origin.no-redirect.http.html]
type: testharness
expected: TIMEOUT
[The referrer URL is omitted when a\n document served over http requires an http\n sub-resource via script-tag using the meta-csp\n delivery method with no-redirect and when\n the target request is cross-origin.]
expected: NOTRUN

View file

@ -1,6 +0,0 @@
[cross-origin.swap-origin-redirect.http.html]
type: testharness
expected: TIMEOUT
[The referrer URL is omitted when a\n document served over http requires an http\n sub-resource via script-tag using the meta-csp\n delivery method with swap-origin-redirect and when\n the target request is cross-origin.]
expected: NOTRUN

View file

@ -1,6 +1,5 @@
[same-origin-insecure.keep-origin-redirect.http.html]
type: testharness
expected: TIMEOUT
[The referrer URL is stripped-referrer when a\n document served over http requires an http\n sub-resource via script-tag using the meta-csp\n delivery method with keep-origin-redirect and when\n the target request is same-origin.]
expected: NOTRUN
expected: FAIL

View file

@ -1,6 +1,5 @@
[same-origin-insecure.no-redirect.http.html]
type: testharness
expected: TIMEOUT
[The referrer URL is stripped-referrer when a\n document served over http requires an http\n sub-resource via script-tag using the meta-csp\n delivery method with no-redirect and when\n the target request is same-origin.]
expected: NOTRUN
expected: FAIL

View file

@ -1,6 +0,0 @@
[same-origin-insecure.swap-origin-redirect.http.html]
type: testharness
expected: TIMEOUT
[The referrer URL is omitted when a\n document served over http requires an http\n sub-resource via script-tag using the meta-csp\n delivery method with swap-origin-redirect and when\n the target request is same-origin.]
expected: NOTRUN

View file

@ -1,6 +0,0 @@
[cross-origin.keep-origin-redirect.http.html]
type: testharness
expected: TIMEOUT
[The referrer URL is omitted when a\n document served over http requires an http\n sub-resource via script-tag using the meta-referrer\n delivery method with keep-origin-redirect and when\n the target request is cross-origin.]
expected: NOTRUN

View file

@ -1,6 +0,0 @@
[cross-origin.no-redirect.http.html]
type: testharness
expected: TIMEOUT
[The referrer URL is omitted when a\n document served over http requires an http\n sub-resource via script-tag using the meta-referrer\n delivery method with no-redirect and when\n the target request is cross-origin.]
expected: NOTRUN

View file

@ -1,6 +0,0 @@
[cross-origin.swap-origin-redirect.http.html]
type: testharness
expected: TIMEOUT
[The referrer URL is omitted when a\n document served over http requires an http\n sub-resource via script-tag using the meta-referrer\n delivery method with swap-origin-redirect and when\n the target request is cross-origin.]
expected: NOTRUN

View file

@ -1,6 +0,0 @@
[same-origin-insecure.keep-origin-redirect.http.html]
type: testharness
expected: TIMEOUT
[The referrer URL is stripped-referrer when a\n document served over http requires an http\n sub-resource via script-tag using the meta-referrer\n delivery method with keep-origin-redirect and when\n the target request is same-origin.]
expected: NOTRUN

View file

@ -1,6 +0,0 @@
[same-origin-insecure.no-redirect.http.html]
type: testharness
expected: TIMEOUT
[The referrer URL is stripped-referrer when a\n document served over http requires an http\n sub-resource via script-tag using the meta-referrer\n delivery method with no-redirect and when\n the target request is same-origin.]
expected: NOTRUN

View file

@ -1,6 +0,0 @@
[same-origin-insecure.swap-origin-redirect.http.html]
type: testharness
expected: TIMEOUT
[The referrer URL is omitted when a\n document served over http requires an http\n sub-resource via script-tag using the meta-referrer\n delivery method with swap-origin-redirect and when\n the target request is same-origin.]
expected: NOTRUN

View file

@ -1,6 +0,0 @@
[generic.keep-origin-redirect.http.html]
type: testharness
expected: TIMEOUT
[The referrer URL is stripped-referrer when a\n document served over http requires an http\n sub-resource via script-tag using the http-rp\n delivery method with keep-origin-redirect and when\n the target request is cross-origin.]
expected: NOTRUN

View file

@ -1,6 +0,0 @@
[generic.no-redirect.http.html]
type: testharness
expected: TIMEOUT
[The referrer URL is stripped-referrer when a\n document served over http requires an http\n sub-resource via script-tag using the http-rp\n delivery method with no-redirect and when\n the target request is cross-origin.]
expected: NOTRUN

View file

@ -1,6 +0,0 @@
[generic.swap-origin-redirect.http.html]
type: testharness
expected: TIMEOUT
[The referrer URL is stripped-referrer when a\n document served over http requires an http\n sub-resource via script-tag using the http-rp\n delivery method with swap-origin-redirect and when\n the target request is cross-origin.]
expected: NOTRUN

View file

@ -1,6 +0,0 @@
[generic.keep-origin-redirect.http.html]
type: testharness
expected: TIMEOUT
[The referrer URL is stripped-referrer when a\n document served over http requires an http\n sub-resource via script-tag using the http-rp\n delivery method with keep-origin-redirect and when\n the target request is same-origin.]
expected: NOTRUN

View file

@ -1,6 +0,0 @@
[generic.no-redirect.http.html]
type: testharness
expected: TIMEOUT
[The referrer URL is stripped-referrer when a\n document served over http requires an http\n sub-resource via script-tag using the http-rp\n delivery method with no-redirect and when\n the target request is same-origin.]
expected: NOTRUN

View file

@ -1,6 +0,0 @@
[generic.swap-origin-redirect.http.html]
type: testharness
expected: TIMEOUT
[The referrer URL is stripped-referrer when a\n document served over http requires an http\n sub-resource via script-tag using the http-rp\n delivery method with swap-origin-redirect and when\n the target request is same-origin.]
expected: NOTRUN

View file

@ -9102,6 +9102,12 @@
"url": "/_mozilla/mozilla/websocket_connection_fail.html"
}
],
"mozilla/window-postmessage-sameorigin.html": [
{
"path": "mozilla/window-postmessage-sameorigin.html",
"url": "/_mozilla/mozilla/window-postmessage-sameorigin.html"
}
],
"mozilla/window.html": [
{
"path": "mozilla/window.html",

View file

@ -0,0 +1,80 @@
<!doctype html>
<meta charset="utf-8">
<title>Same-origin postMessage on the Window object</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/origin_helpers.js?pipe=sub"></script>
<script>
setup({
explicit_done: true
});
function expect_error(error, message, origin, description) {
return function(setlistener, removelistener, type) {
test(function(t) {
assert_throws(error, function() { postMessage(message, origin) });
}, description + ' (' + type + ')');
}
}
function expect_message(message, origin, test) {
return function(setlistener, removelistener, type) {
async_test(function(t) {
setlistener(t.step_func_done(function(e) {
removelistener(arguments.callee);
assert_true(e.isTrusted);
assert_equals(e.data, message);
}));
postMessage(message, origin);
}, test + ' (' + type + ')');
}
}
function expect_no_message(message, origin, test) {
return function(setlistener, removelistener, type) {
async_test(function(t) {
setlistener(t.step_func_done(function(e) {
removelistener(arguments.callee);
assert_equals(e.data, 'expected-sequencing-message');
}));
postMessage(message, origin);
postMessage('expected-sequencing-message', '*');
}, test + ' (' + type + ')');
}
}
var base_tests = [
function() { return expect_message('basic', '*', 'any origin, cloneable string message') },
function() { return expect_message('basic', '/', 'same origin, cloneable string message') },
function() { return expect_message('basic', HTTP_ORIGIN, 'explicit same origin, cloneable string message') },
function() { return expect_no_message('basic', HTTPS_ORIGIN, 'explicit cross origin, cloneable string message') },
function() { return expect_error(new SyntaxError(), 'basic', 'not-a-url', 'explicit invalid url, cloneable string message') },
function() { return expect_error('DATA_CLONE_ERR', window, '*', 'any origin, non-cloneable message') },
];
var tests = [];
var add_handler = function(listener) { window.onmessage = listener; };
var remove_handler = function(listener) { window.onmessage = null; };
var remove_listener = function(listener) { window.removeEventListener('message', listener); }
var add_listener = function(listener) { window.addEventListener('message', listener); };
for (var i = 0; i < base_tests.length; i++) {
var f = base_tests[i]();
tests.push(f.bind(window, add_listener, remove_listener, "listener"));
tests.push(f.bind(window, add_handler, remove_handler, "handler"));
}
var current_test = 0;
function next_test() {
if (current_test < tests.length) {
tests[current_test++]();
} else {
done();
}
}
add_result_callback(function() {
next_test();
});
next_test();
</script>