Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions test/jasmine/tests/gl2d_plot_interact_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,27 @@ describe('Test gl plot side effects', function() {
.catch(failTest)
.then(done);
});

it('@gl should fire *plotly_webglcontextlost* when on webgl context lost', function(done) {
var _mock = Lib.extendDeep({}, require('@mocks/gl2d_12.json'));

Plotly.plot(gd, _mock).then(function() {
return new Promise(function(resolve, reject) {
gd.on('plotly_webglcontextlost', resolve);
setTimeout(reject, 10);

var ev = new window.WebGLContextEvent('webglcontextlost');
var canvas = gd.querySelector('.gl-canvas-context');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I meant by "triggered on any of the canvases losing their context" is, for this one plot we make 3 canvases, each with its own webgl context... any of them could in principle lose its context, right?

> gd.querySelectorAll('canvas')
NodeList(3) [
    canvas.gl-canvas.gl-canvas-context,
    canvas.gl-canvas.gl-canvas-focus,
    canvas.gl-canvas.gl-canvas-pick
]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you caught me being lazy.

Better tests in 905956a

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

even better tests in 3a38d73

canvas.dispatchEvent(ev);
});
})
.then(function(eventData) {
expect((eventData || {}).event).toBeDefined();
expect((eventData || {}).layer).toBe('contextLayer');
})
.catch(failTest)
.then(done);
});
});

describe('Test gl2d plots', function() {
Expand Down
21 changes: 21 additions & 0 deletions test/jasmine/tests/gl3d_plot_interact_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1425,4 +1425,25 @@ describe('Test removal of gl contexts', function() {
})
.then(done);
});

it('@gl should fire *plotly_webglcontextlost* when on webgl context lost', function(done) {
var _mock = Lib.extendDeep({}, require('@mocks/gl3d_marker-arrays.json'));

Plotly.plot(gd, _mock).then(function() {
return new Promise(function(resolve, reject) {
gd.on('plotly_webglcontextlost', resolve);
setTimeout(reject, 10);

var ev = new window.WebGLContextEvent('webglcontextlost');
var canvas = gd.querySelector('div#scene > canvas');
canvas.dispatchEvent(ev);
});
})
.then(function(eventData) {
expect((eventData || {}).event).toBeDefined();
expect((eventData || {}).layer).toBe('scene');
})
.catch(failTest)
.then(done);
});
});