Skip to content

Commit

Permalink
Get slice tests running in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
chinedufn committed Feb 28, 2020
1 parent 6684987 commit 638bd6f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 72 deletions.
15 changes: 0 additions & 15 deletions crates/web-sys/tests/wasm/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,21 +151,6 @@ export function new_title() {
return document.createElement("title");
}

export function new_webgl_rendering_context() {
const canvas = document.createElement('canvas');
return canvas.getContext('webgl');
}

export function new_webgl2_rendering_context() {
const canvas = document.createElement('canvas');
return canvas.getContext('webgl2');
}

export function new_websocket () {
const websocket = new WebSocket("");
return websocket;
}

export function new_xpath_result() {
let xmlDoc = new DOMParser().parseFromString("<root><value>tomato</value></root>", "application/xml");
let xpathResult = xmlDoc.evaluate("/root//value", xmlDoc, null, XPathResult.ANY_TYPE, null);
Expand Down
98 changes: 41 additions & 57 deletions crates/web-sys/tests/wasm/whitelisted_immutable_slices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,80 +10,64 @@
//!
//! @see https://github.com/rustwasm/wasm-bindgen/issues/1005
use wasm_bindgen::prelude::*;
use web_sys::{WebGl2RenderingContext, WebGlRenderingContext, WebSocket};
use wasm_bindgen_test::*;
use wasm_bindgen::{JsValue, JsCast};

wasm_bindgen_test_configure!(run_in_browser);

#[wasm_bindgen(module = "/tests/wasm/element.js")]
extern "C" {
fn new_webgl_rendering_context() -> WebGlRenderingContext;
fn new_webgl2_rendering_context() -> WebGl2RenderingContext;
fn new_websocket() -> WebSocket;
// TODO: Add a function to create another type to test here.
// These functions come from element.js
}

// Ensure that our whitelisted WebGlRenderingContext methods work
// GECKODRIVER=geckodriver cargo test -p web-sys --target wasm32-unknown-unknown --all-features test_webgl_rendering_context_immutable_slices
#[wasm_bindgen_test]
// Ensure that our whitelisted WebGlRenderingContext methods compile with immutable slices.
fn test_webgl_rendering_context_immutable_slices() {
let gl = new_webgl_rendering_context();
let gl = JsValue::null().unchecked_into::<WebGlRenderingContext>();

gl.vertex_attrib1fv_with_f32_array(0, &[1.]);
gl.vertex_attrib2fv_with_f32_array(0, &[1.]);
gl.vertex_attrib3fv_with_f32_array(0, &[1.]);
gl.vertex_attrib4fv_with_f32_array(0, &[1.]);
gl.vertex_attrib1fv_with_f32_array(0, &[1.]);
gl.vertex_attrib2fv_with_f32_array(0, &[1.]);
gl.vertex_attrib3fv_with_f32_array(0, &[1.]);
gl.vertex_attrib4fv_with_f32_array(0, &[1.]);

gl.uniform1fv_with_f32_array(None, &[1.]);
gl.uniform2fv_with_f32_array(None, &[1.]);
gl.uniform3fv_with_f32_array(None, &[1.]);
gl.uniform4fv_with_f32_array(None, &[1.]);
gl.uniform1fv_with_f32_array(None, &[1.]);
gl.uniform2fv_with_f32_array(None, &[1.]);
gl.uniform3fv_with_f32_array(None, &[1.]);
gl.uniform4fv_with_f32_array(None, &[1.]);

gl.uniform_matrix2fv_with_f32_array(None, false, &[1.]);
gl.uniform_matrix3fv_with_f32_array(None, false, &[1.]);
gl.uniform_matrix4fv_with_f32_array(None, false, &[1.]);
gl.uniform_matrix2fv_with_f32_array(None, false, &[1.]);
gl.uniform_matrix3fv_with_f32_array(None, false, &[1.]);
gl.uniform_matrix4fv_with_f32_array(None, false, &[1.]);

gl.tex_image_2d_with_i32_and_i32_and_i32_and_format_and_type_and_opt_u8_array(
0,
0,
0,
0,
0,
0,
0,
0,
Some(&[1]),
);
gl.tex_sub_image_2d_with_i32_and_i32_and_u32_and_type_and_opt_u8_array(
0,
0,
0,
0,
0,
0,
0,
0,
Some(&[1]),
);
gl.compressed_tex_image_2d_with_u8_array(0, 0, 0, 0, 0, 0, &[1]);
gl.tex_image_2d_with_i32_and_i32_and_i32_and_format_and_type_and_opt_u8_array(
0,
0,
0,
0,
0,
0,
0,
0,
Some(&[1]),
);
gl.tex_sub_image_2d_with_i32_and_i32_and_u32_and_type_and_opt_u8_array(
0,
0,
0,
0,
0,
0,
0,
0,
Some(&[1]),
);
gl.compressed_tex_image_2d_with_u8_array(0, 0, 0, 0, 0, 0, &[1]);
}

// GECKODRIVER=geckodriver cargo test -p web-sys --target wasm32-unknown-unknown --all-features test_webgl2_rendering_context_immutable_slices
#[wasm_bindgen_test]
// Ensure that our whitelisted WebGl2RenderingContext methods compile with immutable slices.
fn test_webgl2_rendering_context_immutable_slices() {
let gl = new_webgl2_rendering_context();
let gl = JsValue::null().unchecked_into::<WebGl2RenderingContext>();

gl.tex_image_3d_with_opt_u8_array(0, 0, 0, 0, 0, 0, 0, 0, 0, Some(&[1]));
gl.tex_sub_image_3d_with_opt_u8_array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, Some(&[1]));
gl.compressed_tex_image_3d_with_u8_array(0, 0, 0, 0, 0, 0, 0, &[1]);
}

// GECKODRIVER=geckodriver cargo test -p web-sys --target wasm32-unknown-unknown --all-features test_websocket_immutable_slices
#[wasm_bindgen_test]
// Ensure that our whitelisted WebSocket methods compile with immutable slices.
fn test_websocket_immutable_slices() {
let ws = new_websocket();
let ws = JsValue::null().unchecked_into::<WebSocket>();
ws.send_with_u8_array(&[0]);
}

Expand Down

0 comments on commit 638bd6f

Please sign in to comment.