Skip to content

Fix tab sync and add tests. #4660

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 25, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -410,4 +410,35 @@ browserDescribe('WebDriver persistence test', driver => {
}
});
});

context.only('persistence sync across windows and tabs', () => {
it('sync current user across windows', async () => {
const cred: UserCredential = await driver.call(
AnonFunction.SIGN_IN_ANONYMOUSLY
);
const uid = cred.user.uid;
await driver.webDriver.executeScript('window.open(".");');
await driver.selectPopupWindow();
await driver.injectConfigAndInitAuth();
await driver.waitForAuthInit();
const userInPopup = await driver.getUserSnapshot();
expect(userInPopup).not.to.be.null;
expect(userInPopup.uid).to.equal(uid);

await driver.call(CoreFunction.SIGN_OUT);
expect(await driver.getUserSnapshot()).to.be.null;
await driver.selectMainWindow({ noWait: true });
await new Promise(resolve => setTimeout(resolve, 500));
expect(await driver.getUserSnapshot()).to.be.null;

const cred2: UserCredential = await driver.call(
AnonFunction.SIGN_IN_ANONYMOUSLY
);
const uid2 = cred2.user.uid;

await driver.selectPopupWindow();
await new Promise(resolve => setTimeout(resolve, 500));
expect(await driver.getUserSnapshot()).to.contain({ uid: uid2 });
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ function dbPromise(dbRequest) {
reject(dbRequest.error);
});
dbRequest.addEventListener('blocked', () => {
reject(dbRequest.error || 'blocked');
reject('blocked');
});
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,16 @@ export class AuthDriver {
.window(handles.find(h => h !== currentWindowHandle)!);
}

async selectMainWindow(): Promise<void> {
const condition = new Condition(
'Waiting for popup to close',
async driver => {
return (await driver.getAllWindowHandles()).length === 1;
}
);
await this.webDriver.wait(condition);
async selectMainWindow(options: { noWait?: boolean } = {}): Promise<void> {
if (!options.noWait) {
const condition = new Condition(
'Waiting for popup to close',
async driver => {
return (await driver.getAllWindowHandles()).length === 1;
}
);
await this.webDriver.wait(condition);
}
const handles = await this.webDriver.getAllWindowHandles();
return this.webDriver.switchTo().window(handles[0]);
}
Expand All @@ -217,4 +219,14 @@ export class AuthDriver {
await this.webDriver.close();
return this.selectMainWindow();
}

async closeExtraWindows(): Promise<void> {
const handles = await this.webDriver.getAllWindowHandles();
await this.webDriver.switchTo().window(handles[handles.length - 1]);
while (handles.length > 1) {
await this.webDriver.close();
handles.pop();
await this.webDriver.switchTo().window(handles[handles.length - 1]);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ setTimeout(() => {
// It's assumed that the tests will start with a clean slate (i.e.
// no storage).
beforeEach(async () => {
await DRIVER.closeExtraWindows();
await DRIVER.reset();
await DRIVER.injectConfigAndInitAuth();
});
Expand Down