chromium/chrome/test/data/extensions/api_test/service_worker/worker_based_background/events_to_stopped_worker/service_worker_background.js

// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

var seenLoading = false;

chrome.tabs.onUpdated.addListener(function localListener (
    tabId, changeInfo, tab) {
  if (changeInfo.status === 'loading') {
    if (seenLoading == true) {
      chrome.test.sendMessage('ERROR');
    } else {
      seenLoading = true;
    }
  } else if (changeInfo.status === 'complete') {
    chrome.test.sendMessage(seenLoading == true ? 'finished' : 'ERROR');
  }
});

chrome.test.sendMessage('ready');