tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

helpers.js (1587B)


      1 'use strict';
      2 
      3 // These tests rely on the User Agent providing an implementation of
      4 // platform contacts backends.
      5 //
      6 // In Chromium-based browsers this implementation is provided by a polyfill
      7 // in order to reduce the amount of test-only code shipped to users. To enable
      8 // these tests the browser must be run with these options:
      9 //
     10 //   --enable-blink-features=MojoJS,MojoJSTest
     11 async function loadChromiumResources() {
     12  await import('/resources/chromium/contacts_manager_mock.js');
     13 }
     14 
     15 // User Agents must provide their own implementation of `WebContacts`,
     16 // which must contain the following this interface:
     17 // class WebContactsTest {
     18 //   /** @param {?Array<!ContactInfo>} contacts */
     19 //   setSelectedContacts(contacts);
     20 // }
     21 async function createWebContactsTest() {
     22  if (typeof WebContactsTest === 'undefined') {
     23    if (isChromiumBased) {
     24      await loadChromiumResources();
     25    }
     26  }
     27  assert_implements(WebContactsTest, 'WebContactsTest is unavailable.');
     28  return new WebContactsTest();
     29 }
     30 
     31 // Creates a Promise test for |func| given the |description|. The |func| will
     32 // be executed with `setSelectedContacts` which will allow tests to mock out
     33 // the result of calling navigator.contacts.select. `setSelectedContacts`
     34 // accepts a nullable Array of ContactInfos.
     35 function contactsTestWithUserActivation(func, description) {
     36  promise_test(async test => {
     37    const webContactsTest = await createWebContactsTest();
     38    await window.test_driver.bless('request contacts');
     39    return func(test, contacts => webContactsTest.setSelectedContacts(contacts));
     40  }, description);
     41 }