Skip to content

Commit

Permalink
test: make test_scriptNavigate_checkEvents stable (#2901)
Browse files Browse the repository at this point in the history
Address #2900

+ remove extra `await` and `async` from unit tests
  • Loading branch information
sadym-chromium committed Dec 17, 2024
1 parent dfcee4a commit 27c7d62
Show file tree
Hide file tree
Showing 4 changed files with 185 additions and 393 deletions.
64 changes: 32 additions & 32 deletions src/bidiMapper/modules/context/NavigationTracker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ describe('NavigationTracker', () => {
let eventManager: SinonStubbedInstance<EventManager>;
let initialNavigationId: string;

async function assertNoNavigationEvents() {
function assertNoNavigationEvents() {
// `eventManager.registerEvent` is safe do be used unbound.
// eslint-disable-next-line @typescript-eslint/unbound-method
sinon.assert.notCalled(eventManager.registerEvent);
}

async function assertNavigationEvent(
function assertNavigationEvent(
this: void,
eventName: string,
navigationId: string | sinon.SinonMatcher,
Expand Down Expand Up @@ -89,14 +89,14 @@ describe('NavigationTracker', () => {
navigationTracker.navigationCommandFinished(navigation, undefined);

// Assert navigation is not finished.
await assertNoNavigationEvents();
assertNoNavigationEvents();

// Fragment navigation should not update the current navigation.
assert.equal(navigationTracker.currentNavigationId, initialNavigationId);

navigationTracker.navigatedWithinDocument(SOME_URL, 'fragment');

await assertNavigationEvent(
assertNavigationEvent(
ChromiumBidi.BrowsingContext.EventNames.FragmentNavigated,
navigation.navigationId,
SOME_URL,
Expand All @@ -114,7 +114,7 @@ describe('NavigationTracker', () => {
it('started', async () => {
const navigation = navigationTracker.createPendingNavigation(SOME_URL);

await assertNoNavigationEvents();
assertNoNavigationEvents();
assert.equal(navigation.url, SOME_URL);
assert.equal(navigationTracker.url, INITIAL_URL);
assert.equal(
Expand All @@ -124,7 +124,7 @@ describe('NavigationTracker', () => {

navigationTracker.frameStartedNavigating(ANOTHER_URL, LOADER_ID);

await assertNavigationEvent(
assertNavigationEvent(
ChromiumBidi.BrowsingContext.EventNames.NavigationStarted,
navigation.navigationId,
ANOTHER_URL,
Expand All @@ -138,7 +138,7 @@ describe('NavigationTracker', () => {

navigationTracker.navigationCommandFinished(navigation, LOADER_ID);

await assertNoNavigationEvents();
assertNoNavigationEvents();
assert.equal(navigation.url, ANOTHER_URL);
assert.equal(navigationTracker.url, ANOTHER_URL);
assert.equal(
Expand All @@ -148,11 +148,11 @@ describe('NavigationTracker', () => {

navigationTracker.loadPageEvent(ANOTHER_LOADER_ID);

await assertNoNavigationEvents();
assertNoNavigationEvents();

navigationTracker.loadPageEvent(LOADER_ID);

await assertNoNavigationEvents();
assertNoNavigationEvents();
assert.equal(
(await navigation.finished).eventName,
NavigationEventName.Load,
Expand All @@ -164,15 +164,15 @@ describe('NavigationTracker', () => {
const navigation = navigationTracker.createPendingNavigation(SOME_URL);
navigationTracker.frameStartedNavigating(ANOTHER_URL, LOADER_ID);

await assertNavigationEvent(
assertNavigationEvent(
ChromiumBidi.BrowsingContext.EventNames.NavigationStarted,
navigation.navigationId,
ANOTHER_URL,
);

navigationTracker.frameRequestedNavigation(YET_ANOTHER_URL);

await assertNavigationEvent(
assertNavigationEvent(
ChromiumBidi.BrowsingContext.EventNames.NavigationAborted,
navigation.navigationId,
ANOTHER_URL,
Expand All @@ -190,15 +190,15 @@ describe('NavigationTracker', () => {
const navigation = navigationTracker.createPendingNavigation(SOME_URL);
navigationTracker.frameStartedNavigating(ANOTHER_URL, LOADER_ID);

await assertNavigationEvent(
assertNavigationEvent(
ChromiumBidi.BrowsingContext.EventNames.NavigationStarted,
navigation.navigationId,
ANOTHER_URL,
);

navigationTracker.failNavigation(navigation, ERROR_MESSAGE);

await assertNavigationEvent(
assertNavigationEvent(
ChromiumBidi.BrowsingContext.EventNames.NavigationFailed,
navigation.navigationId,
ANOTHER_URL,
Expand All @@ -220,15 +220,15 @@ describe('NavigationTracker', () => {
const navigation = navigationTracker.createPendingNavigation(SOME_URL);
navigationTracker.frameStartedNavigating(ANOTHER_URL, LOADER_ID);

await assertNavigationEvent(
assertNavigationEvent(
ChromiumBidi.BrowsingContext.EventNames.NavigationStarted,
navigation.navigationId,
ANOTHER_URL,
);

navigationTracker.networkLoadingFailed(LOADER_ID, ERROR_MESSAGE);

await assertNavigationEvent(
assertNavigationEvent(
ChromiumBidi.BrowsingContext.EventNames.NavigationFailed,
navigation.navigationId,
ANOTHER_URL,
Expand All @@ -248,10 +248,10 @@ describe('NavigationTracker', () => {
});

describe('Renderer initiated navigation', () => {
it('should process fragment navigation', async () => {
it('should process fragment navigation', () => {
navigationTracker.navigatedWithinDocument(SOME_URL, 'fragment');

await assertNavigationEvent(
assertNavigationEvent(
ChromiumBidi.BrowsingContext.EventNames.FragmentNavigated,
sinon.match.any,
SOME_URL,
Expand All @@ -262,10 +262,10 @@ describe('NavigationTracker', () => {
});

describe('cross-document navigation', () => {
it('started', async () => {
it('started', () => {
navigationTracker.frameRequestedNavigation(SOME_URL);

await assertNoNavigationEvents();
assertNoNavigationEvents();
assert.equal(
navigationTracker.currentNavigationId,
initialNavigationId,
Expand All @@ -274,7 +274,7 @@ describe('NavigationTracker', () => {

navigationTracker.frameStartedNavigating(ANOTHER_URL, LOADER_ID);

await assertNavigationEvent(
assertNavigationEvent(
ChromiumBidi.BrowsingContext.EventNames.NavigationStarted,
sinon.match.any,
ANOTHER_URL,
Expand All @@ -288,18 +288,18 @@ describe('NavigationTracker', () => {

navigationTracker.frameNavigated(YET_ANOTHER_URL, LOADER_ID);

await assertNoNavigationEvents();
assertNoNavigationEvents();
assert.equal(navigationTracker.url, YET_ANOTHER_URL);

navigationTracker.loadPageEvent(LOADER_ID);

await assertNoNavigationEvents();
assertNoNavigationEvents();
});

it('aborted by script-initiated navigation', async () => {
it('aborted by script-initiated navigation', () => {
navigationTracker.frameRequestedNavigation(SOME_URL);

await assertNoNavigationEvents();
assertNoNavigationEvents();
assert.equal(
navigationTracker.currentNavigationId,
initialNavigationId,
Expand All @@ -308,15 +308,15 @@ describe('NavigationTracker', () => {

navigationTracker.frameStartedNavigating(ANOTHER_URL, LOADER_ID);

await assertNavigationEvent(
assertNavigationEvent(
ChromiumBidi.BrowsingContext.EventNames.NavigationStarted,
sinon.match.any,
ANOTHER_URL,
);

navigationTracker.frameRequestedNavigation(YET_ANOTHER_URL);

await assertNavigationEvent(
assertNavigationEvent(
ChromiumBidi.BrowsingContext.EventNames.NavigationAborted,
sinon.match.any,
ANOTHER_URL,
Expand All @@ -328,19 +328,19 @@ describe('NavigationTracker', () => {
assert.equal(navigationTracker.url, INITIAL_URL);
});

it('aborted by command navigation', async () => {
it('aborted by command navigation', () => {
navigationTracker.frameRequestedNavigation(SOME_URL);
navigationTracker.frameStartedNavigating(ANOTHER_URL, LOADER_ID);

await assertNavigationEvent(
assertNavigationEvent(
ChromiumBidi.BrowsingContext.EventNames.NavigationStarted,
sinon.match.any,
ANOTHER_URL,
);

navigationTracker.createPendingNavigation(YET_ANOTHER_URL);

await assertNavigationEvent(
assertNavigationEvent(
ChromiumBidi.BrowsingContext.EventNames.NavigationAborted,
sinon.match.any,
ANOTHER_URL,
Expand All @@ -352,19 +352,19 @@ describe('NavigationTracker', () => {
assert.equal(navigationTracker.url, INITIAL_URL);
});

it('failed network', async () => {
it('failed network', () => {
navigationTracker.frameRequestedNavigation(SOME_URL);
navigationTracker.frameStartedNavigating(ANOTHER_URL, LOADER_ID);

await assertNavigationEvent(
assertNavigationEvent(
ChromiumBidi.BrowsingContext.EventNames.NavigationStarted,
sinon.match.any,
ANOTHER_URL,
);

navigationTracker.networkLoadingFailed(LOADER_ID, ERROR_MESSAGE);

await assertNavigationEvent(
assertNavigationEvent(
ChromiumBidi.BrowsingContext.EventNames.NavigationFailed,
sinon.match.any,
ANOTHER_URL,
Expand Down
Loading

0 comments on commit 27c7d62

Please sign in to comment.