Commit ecde7f96 authored by Robert Knight's avatar Robert Knight

Handle client-side navigations in guests

Notify the sidebar when the URL of the current document changes. This
will trigger the sidebar to reload annotations.
parent 8fb22b27
......@@ -194,6 +194,10 @@ export class Guest {
this._integration = createIntegration(this, {
contentPartner: config.contentPartner,
});
this._integration.on('uriChanged', async () => {
const metadata = await this.getDocumentInfo();
this._sidebarRPC.call('documentInfoChanged', metadata);
});
/**
* Channel for host-guest communication.
......
import { TinyEmitter } from 'tiny-emitter';
import { delay } from '../../test-util/wait';
import { Guest, $imports } from '../guest';
......@@ -126,7 +128,7 @@ describe('Guest', () => {
fakeFrameFillsAncestor = sinon.stub().returns(true);
fakeIntegration = {
fakeIntegration = Object.assign(new TinyEmitter(), {
anchor: sinon.stub(),
canAnnotate: sinon.stub().returns(true),
contentContainer: sinon.stub().returns({}),
......@@ -139,7 +141,7 @@ describe('Guest', () => {
}),
scrollToAnchor: sinon.stub().resolves(),
uri: sinon.stub().resolves('https://example.com/test.pdf'),
};
});
fakeCreateIntegration = sinon.stub().returns(fakeIntegration);
......@@ -1308,6 +1310,38 @@ describe('Guest', () => {
});
});
it('sends new document metadata and URIs to sidebar after a client-side navigation', async () => {
fakeIntegration.uri.resolves('https://example.com/page-1');
fakeIntegration.getMetadata.resolves({ title: 'Page 1' });
createGuest();
const sidebarRPCCall = sidebarRPC().call;
await delay(0);
assert.calledWith(sidebarRPCCall, 'documentInfoChanged', {
uri: 'https://example.com/page-1',
metadata: {
title: 'Page 1',
},
frameIdentifier: null,
});
sidebarRPCCall.resetHistory();
fakeIntegration.uri.resolves('https://example.com/page-2');
fakeIntegration.getMetadata.resolves({ title: 'Page 2' });
fakeIntegration.emit('uriChanged');
await delay(0);
assert.calledWith(sidebarRPCCall, 'documentInfoChanged', {
uri: 'https://example.com/page-2',
metadata: {
title: 'Page 2',
},
frameIdentifier: null,
});
});
describe('#fitSideBySide', () => {
it('attempts to fit content alongside sidebar', () => {
const guest = createGuest();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment