third_party/pcsc-lite/naclport/server_clients_management/src/permissions_checking/user-prompting-checker-unittest.js
/**
 * Wraps the given test function, providing the necessary setup and teardown.
 * @param {!Object} fakeInitialStorageData Fake data to be returned from
 * chrome.storage.local.get().
 * @param {Object?} expectedStorageDataToBeWritten If non-null, then the
 * expected data to be passed into chrome.storage.local.set(); if null, then
 * set() isn't expected to be called.
 * @param {!MockedDialogBehavior} mockedDialogBehavior If |NOT_RUN|, then the
 * GSC.PopupOpener.runModalDialog method is not expected to be called;
 * otherwise, the called method will return the corresponding result.
 * @param {function(!UserPromptingChecker):!goog.Promise} testCallback The test
 * function to be run after the needed setup; must return a promise of the test
 * result.
 * @return {function():!goog.Promise} The wrapped test function, which returns a
 * promise of the test result and the result of teardown.
 */
Wraps the given test function, providing the necessary setup and teardown.
@param {!Object} fakeInitialStorageData Fake data to be returned from
chrome.storage.local.get().
@param {Object?} expectedStorageDataToBeWritten If non-null, then the
expected data to be passed into chrome.storage.local.set(); if null, then
set() isn't expected to be called.
@param {!MockedDialogBehavior} mockedDialogBehavior If |NOT_RUN|, then the
GSC.PopupOpener.runModalDialog method is not expected to be called;
otherwise, the called method will return the corresponding result.
@param {function(!UserPromptingChecker):!goog.Promise} testCallback The test
function to be run after the needed setup; must return a promise of the test
result.
@return {function():!goog.Promise} The wrapped test function, which returns a
promise of the test result and the result of teardown.
Wraps the given test function providing the necessary setup and teardown . @param { !Object } fakeInitialStorageData Fake data to be returned from chrome . storage . local . get () . @param { Object? } expectedStorageDataToBeWritten If non - null then the expected data to be passed into chrome . storage . local . set () ; if null then set () isn ' t expected to be called . @param { !MockedDialogBehavior } mockedDialogBehavior If |NOT_RUN| then the GSC . PopupOpener . runModalDialog method is not expected to be called ; otherwise the called method will return the corresponding result . @param { function ( !UserPromptingChecker ) : !goog . Promise } testCallback The test function to be run after the needed setup ; must return a promise of the test result . @return { function () : !goog . Promise } The wrapped test function which returns a promise of the test result and the result of teardown .
function makeTest(
    fakeInitialStorageData, expectedStorageDataToBeWritten,
    mockedDialogBehavior, testCallback) {
  return function() {
    const mockControl = new goog.testing.MockControl;
    const propertyReplacer = new goog.testing.PropertyReplacer;
    function cleanup() {
      mockControl.$tearDown();
      mockControl.$resetAll();
      propertyReplacer.reset();
    }
    function verifyAndCleanup() {
      try {
        mockControl.$verifyAll();
      } finally {
        cleanup();
      }
    }
    setUpKnownAppsRegistryMock(mockControl);
    setUpChromeStorageMock(
        mockControl, propertyReplacer, fakeInitialStorageData,
        expectedStorageDataToBeWritten);
    setUpDialogMock(mockControl, mockedDialogBehavior);
    mockControl.$replayAll();
    let testPromise;
    try {
      testPromise = testCallback(new UserPromptingChecker);
    } catch (exc) {
      cleanup();
      throw exc;
    }
    return testPromise.then(verifyAndCleanup, verifyAndCleanup);
  };
}
function makeTest ( fakeInitialStorageData , expectedStorageDataToBeWritten , mockedDialogBehavior , testCallback ) { return function ( ) { const mockControl = new goog . testing . MockControl ; const propertyReplacer = new goog . testing . PropertyReplacer ; function cleanup ( ) { mockControl . $tearDown ( ) ; mockControl . $resetAll ( ) ; propertyReplacer . reset ( ) ; } function verifyAndCleanup ( ) { try { mockControl . $verifyAll ( ) ; } finally { cleanup ( ) ; } } setUpKnownAppsRegistryMock ( mockControl ) ; setUpChromeStorageMock ( mockControl , propertyReplacer , fakeInitialStorageData , expectedStorageDataToBeWritten ) ; setUpDialogMock ( mockControl , mockedDialogBehavior ) ; mockControl . $replayAll ( ) ; let testPromise ; try { testPromise = testCallback ( new UserPromptingChecker ) ; } catch ( exc ) { cleanup ( ) ; throw exc ; } return testPromise . then ( verifyAndCleanup , verifyAndCleanup ) ; } ; }
Wraps the given test function, providing the necessary setup and teardown.
Wraps the given test function providing the necessary setup and teardown .
/** @preserveTry */ // Cleanup regardless of the mock verification outcome. /** @preserveTry */ // Cleanup after the test fatally failed synchronously. // Verify mocks and cleanup after the test completes or fails. Note that // it's crucial that the returned promise is a child promise which is tied // with the success of verification and cleanup.