Changeset 235570 in webkit


Ignore:
Timestamp:
Aug 31, 2018 2:48:18 PM (6 years ago)
Author:
Chris Dumez
Message:

[ WK2 ] http/tests/workers/service/client-*-page-cache.html LayoutTests are flaky
https://bugs.webkit.org/show_bug.cgi?id=183705
<rdar://problem/42440606>

Reviewed by Youenn Fablet.

Source/WebCore:

Add internals.serviceWorkerClientIdentifier() utility function so that a layout test can get the
service worker client identifier of a document.

  • testing/Internals.cpp:

(WebCore::Internals::serviceWorkerClientIdentifier const):

  • testing/Internals.h:
  • testing/Internals.idl:

LayoutTests:

Update Layout tests to not rely on the total number of clients as this is flaky. Instead, check for specific client
identifiers to see if they are present or not.

  • http/tests/workers/service/client-added-to-clients-when-restored-from-page-cache.html:
  • http/tests/workers/service/client-removed-from-clients-while-in-page-cache.html:
  • http/tests/workers/service/resources/getClientIds-worker.js: Renamed from LayoutTests/http/tests/workers/service/resources/getClientCount-worker.js.

(event.then):

  • http/tests/workers/service/serviceworkerclients-matchAll-worker.js:

(async.doTestAfterMessage):

  • http/tests/workers/service/serviceworkerclients-matchAll.https.html:
  • platform/ios-wk2/TestExpectations:
  • platform/mac-wk2/TestExpectations:

Unskip tests as they should no longer be flaky.

Location:
trunk
Files:
11 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r235569 r235570  
     12018-08-31  Chris Dumez  <cdumez@apple.com>
     2
     3        [ WK2 ] http/tests/workers/service/client-*-page-cache.html LayoutTests are flaky
     4        https://bugs.webkit.org/show_bug.cgi?id=183705
     5        <rdar://problem/42440606>
     6
     7        Reviewed by Youenn Fablet.
     8
     9        Update Layout tests to not rely on the total number of clients as this is flaky. Instead, check for specific client
     10        identifiers to see if they are present or not.
     11
     12        * http/tests/workers/service/client-added-to-clients-when-restored-from-page-cache.html:
     13        * http/tests/workers/service/client-removed-from-clients-while-in-page-cache.html:
     14        * http/tests/workers/service/resources/getClientIds-worker.js: Renamed from LayoutTests/http/tests/workers/service/resources/getClientCount-worker.js.
     15        (event.then):
     16        * http/tests/workers/service/serviceworkerclients-matchAll-worker.js:
     17        (async.doTestAfterMessage):
     18        * http/tests/workers/service/serviceworkerclients-matchAll.https.html:
     19
     20        * platform/ios-wk2/TestExpectations:
     21        * platform/mac-wk2/TestExpectations:
     22        Unskip tests as they should no longer be flaky.
     23
    1242018-08-31  John Wilander  <wilander@apple.com>
    225
  • trunk/LayoutTests/http/tests/workers/service/client-added-to-clients-when-restored-from-page-cache.html

    r234061 r235570  
    1414let tries = 0;
    1515
     16let expectedClientIdentifiers = [];
     17
     18function containsExpectedClients(clientIdentifiers)
     19{
     20    for (let expectedIdentifier of expectedClientIdentifiers) {
     21        if (!clientIdentifiers.includes(expectedIdentifier))
     22            return false;
     23    }
     24    return true;
     25}
     26
    1627navigator.serviceWorker.addEventListener("message", function(event) {
    1728  if (step == "BothClientsInitiallyActive") {
    18     if (event.data != 2) {
     29    if (!containsExpectedClients(event.data)) {
    1930      if (++tries > 20) {
    20           log("FAIL: Wrong initial number of clients: " + event.data);
     31          log("FAIL: Wrong initial number of clients");
    2132          finishSWTest();
    2233          return;
    2334      }
    24       worker.postMessage("getClientCount");
     35      worker.postMessage("getClientIds");
    2536      return;
    2637    }
     
    4455       setTimeout(function() {
    4556         step = "SecondClientRestoredFromPageCache";
    46          worker.postMessage("getClientCount");
     57         worker.postMessage("getClientIds");
    4758       }, 0);
    4859    });
     
    5364
    5465  if (step == "SecondClientRestoredFromPageCache") {
    55     if (event.data != 2) {
    56       log("FAIL: Wrong number of clients after one client was restored from page cache: " + event.data);
     66    if (!containsExpectedClients(event.data)) {
     67      log("FAIL: Wrong number of clients after one client was restored from page cache");
    5768      finishSWTest();
    5869    }
     
    6374});
    6475
    65 navigator.serviceWorker.register("resources/getClientCount-worker.js", { }).then(function(registration) {
     76navigator.serviceWorker.register("resources/getClientIds-worker.js", { }).then(function(registration) {
     77    expectedClientIdentifiers.push(internals.serviceWorkerClientIdentifier(document));
     78
    6679    worker = registration.installing;
    6780    otherWindow = open("other_resources/test.html");
    6881    otherWindow.onload = function() {
     82      expectedClientIdentifiers.push(internals.serviceWorkerClientIdentifier(otherWindow.document));
    6983      step = "BothClientsInitiallyActive"
    70       worker.postMessage("getClientCount");
     84      worker.postMessage("getClientIds");
    7185    };
    7286});
  • trunk/LayoutTests/http/tests/workers/service/client-removed-from-clients-while-in-page-cache.html

    r234061 r235570  
    1212}
    1313
     14let topClientIdentifier = null;
     15let windowClientIdentifier = null;
     16
    1417let tries = 0;
     18
     19function containsBothClients(clientIdentifiers)
     20{
     21    return clientIdentifiers.includes(topClientIdentifier) && clientIdentifiers.includes(windowClientIdentifier);
     22}
     23
     24function containsOnlyTopClient(clientIdentifiers)
     25{
     26    return clientIdentifiers.includes(topClientIdentifier) && !clientIdentifiers.includes(windowClientIdentifier);
     27}
    1528
    1629navigator.serviceWorker.addEventListener("message", function(event) {
    1730  if (step == "BothClientsInitiallyActive") {
    18     if (event.data != 2) {
     31    if (!containsBothClients(event.data)) {
    1932      if (++tries > 20) {
    20           log("FAIL: Wrong initial number of clients: " + event.data);
     33          log("FAIL: Wrong initial number of clients");
    2134          finishSWTest();
    2235          return;
    2336      }
    24       worker.postMessage("getClientCount");
     37      worker.postMessage("getClientIds");
    2538      return;
    2639    }
     
    3750       setTimeout(function() {
    3851         step = "OnlyOneClientRemainsActive"
    39          worker.postMessage("getClientCount");
     52         worker.postMessage("getClientIds");
    4053       }, 0);
    4154    });
     
    4659
    4760  if (step == "OnlyOneClientRemainsActive") {
    48     if (event.data != 1) {
    49       log("FAIL: Wrong number of clients after one client entered page cache: " + event.data);
     61    if (!containsOnlyTopClient(event.data)) {
     62      log("FAIL: Wrong number of clients after one client entered page cache");
    5063      finishSWTest();
    5164    }
     
    5669});
    5770
    58 navigator.serviceWorker.register("resources/getClientCount-worker.js", { }).then(function(registration) {
     71navigator.serviceWorker.register("resources/getClientIds-worker.js", { }).then(function(registration) {
     72    topClientIdentifier = internals.serviceWorkerClientIdentifier(document);
     73
    5974    worker = registration.installing;
    6075    otherWindow = open("other_resources/test.html");
    6176    otherWindow.onload = function() {
     77      windowClientIdentifier = internals.serviceWorkerClientIdentifier(otherWindow.document);
    6278      step = "BothClientsInitiallyActive"
    63       worker.postMessage("getClientCount");
     79      worker.postMessage("getClientIds");
    6480    };
    6581});
  • trunk/LayoutTests/http/tests/workers/service/resources/getClientIds-worker.js

    r235569 r235570  
    11self.addEventListener("message", (event) => {
    22    source = event.source;
    3     clients.matchAll({ includeUncontrolled : true }).then(function(clientList) {
    4         source.postMessage(clientList.length);
     3    clients.matchAll({ includeUncontrolled : true }).then(function(clients) {
     4        let ids = [];
     5        for (let client of clients)
     6            ids.push(client.id);
     7        source.postMessage(ids);
    58    });
    69});
  • trunk/LayoutTests/http/tests/workers/service/serviceworkerclients-matchAll-worker.js

    r234107 r235570  
    44}
    55
    6 function matchAllPromise1()
     6function checkClientNotInControlledClients(clientIdentifier)
    77{
    88    return self.clients.matchAll().then((clients) => {
    9         return clients.length === 0 ? "PASS" : "FAIL: expected no matched client, got " + clients.length;
     9        for (let client of clients) {
     10            if (client.id == clientIdentifier)
     11                return "FAIL: Client should not have matched";
     12        }
     13        return "PASS";
    1014    }, (e) => {
    11         return "FAIL: matchAll 1 rejected with " + e;
     15        return "FAIL: First matchAll() request rejected with " + e;
    1216    });
    1317}
    1418
    15 var matchedClients;
    16 function matchAllPromise2()
     19function checkClientInUncontrolledClients(clientIdentifier)
    1720{
    18     return self.clients.matchAll({ includeUncontrolled : true }).then((c) => {
    19         matchedClients = c;
    20         return matchedClients.length === 1 ? "PASS" : "FAIL: expected one matched client, got " + matchedClients.length;
     21    return self.clients.matchAll({ includeUncontrolled : true }).then((clients) => {
     22        for (let client of clients) {
     23            if (client.id == clientIdentifier)
     24                return "PASS";
     25        }
     26        return "FAIL: Client should have matched with includeUncontrolled set to true";
    2127    }, (e) => {
    22         return "FAIL: matchAll 2 rejected with " + e;
     28        return "FAIL: Second matchAll() request rejected with " + e;
    2329    });
    2430}
     
    2733{
    2834    try {
    29         if (event.data !== "start") {
     35        if (event.data.test !== "checkClientIsUncontrolled") {
    3036            event.source.postMessage("FAIL: received unexpected message from client");
     37            return;
     38        }
     39
     40        const clientIdentifier = event.data.identifier;
     41
     42        let result = await checkClientNotInControlledClients(clientIdentifier);
     43        if (result !== "PASS") {
     44            event.source.postMessage(result);
    3145            return;
    3246        }
     
    3650            if (tries)
    3751                await waitFor(50);
    38             result = await matchAllPromise1();
     52            result = await checkClientInUncontrolledClients(clientIdentifier);
    3953        } while (result !== "PASS" && ++tries <= 200);
    4054
    41         if (result !== "PASS") {
    42             event.source.postMessage(result);
    43             return;
    44         }
    45 
    46         tries = 0;
    47         do {
    48             if (tries)
    49                 await waitFor(50);
    50             result = await matchAllPromise2();
    51         } while (result !== "PASS" && ++tries <= 200);
    52 
    53         if (result !== "PASS") {
    54             event.source.postMessage(result);
    55             return;
    56         }
    57         event.source.postMessage("PASS");
     55        event.source.postMessage(result);
    5856    } catch (e) {
    5957        event.source.postMessage("FAIL: received exception " + e);
  • trunk/LayoutTests/http/tests/workers/service/serviceworkerclients-matchAll.https.html

    r225452 r235570  
    2828
    2929promise_test(async (test) => {
     30    const serviceWorkerClientIdentifier = internals.serviceWorkerClientIdentifier(document);
    3031    var promise = new Promise((resolve, reject) => {
    3132        navigator.serviceWorker.addEventListener("message", test.step_func((event) => {
     
    3536    });
    3637
    37     activeWorker.postMessage("start");
     38    activeWorker.postMessage({test: "checkClientIsUncontrolled", identifier: serviceWorkerClientIdentifier });
    3839    await promise;
    3940}, "Test self.clients.matchAll");
  • trunk/LayoutTests/platform/ios-wk2/TestExpectations

    r235468 r235570  
    12781278webkit.org/b/184783 compositing/ios/overflow-scroll-touch-tiles.html [ Pass Failure ]
    12791279
    1280 webkit.org/b/183705 http/tests/workers/service/client-added-to-clients-when-restored-from-page-cache.html [ Pass Failure ]
    1281 webkit.org/b/183705 http/tests/workers/service/client-removed-from-clients-while-in-page-cache.html [ Pass Failure ]
    1282 webkit.org/b/183705 http/tests/workers/service/serviceworkerclients-matchAll.https.html [ Pass Failure ]
    1283 
    12841280webkit.org/b/179853 [ Debug ] imported/blink/fast/text/international-iteration-simple-text.html [ Pass Failure ]
    12851281
  • trunk/LayoutTests/platform/mac-wk2/TestExpectations

    r235569 r235570  
    832832webkit.org/b/186425 [ Debug ] inspector/console/webcore-logging.html [ Pass Failure ]
    833833
    834 webkit.org/b/183705 http/tests/workers/service/client-added-to-clients-when-restored-from-page-cache.html [ Pass Failure ]
    835 webkit.org/b/183705 http/tests/workers/service/client-removed-from-clients-while-in-page-cache.html [ Pass Failure ]
    836 webkit.org/b/183705 http/tests/workers/service/serviceworkerclients-matchAll.https.html [ Pass Failure ]
    837 
    838834webkit.org/b/187658 http/tests/security/bypassing-cors-checks-for-extension-urls.html [ Pass Failure ]
    839835
  • trunk/Source/WebCore/ChangeLog

    r235569 r235570  
     12018-08-31  Chris Dumez  <cdumez@apple.com>
     2
     3        [ WK2 ] http/tests/workers/service/client-*-page-cache.html LayoutTests are flaky
     4        https://bugs.webkit.org/show_bug.cgi?id=183705
     5        <rdar://problem/42440606>
     6
     7        Reviewed by Youenn Fablet.
     8
     9        Add internals.serviceWorkerClientIdentifier() utility function so that a layout test can get the
     10        service worker client identifier of a document.
     11
     12        * testing/Internals.cpp:
     13        (WebCore::Internals::serviceWorkerClientIdentifier const):
     14        * testing/Internals.h:
     15        * testing/Internals.idl:
     16
    1172018-08-31  John Wilander  <wilander@apple.com>
    218
  • trunk/Source/WebCore/testing/Internals.cpp

    r235560 r235570  
    23292329}
    23302330
     2331String Internals::serviceWorkerClientIdentifier(const Document& document) const
     2332{
     2333#if ENABLE(SERVICE_WORKER)
     2334    return ServiceWorkerClientIdentifier { ServiceWorkerProvider::singleton().serviceWorkerConnectionForSession(document.sessionID()).serverConnectionIdentifier(), document.identifier() }.toString();
     2335#else
     2336    UNUSED_PARAM(document);
     2337    return String();
     2338#endif
     2339}
     2340
    23312341RefPtr<WindowProxy> Internals::openDummyInspectorFrontend(const String& url)
    23322342{
  • trunk/Source/WebCore/testing/Internals.h

    r235086 r235570  
    372372    bool isDocumentAlive(uint64_t documentIdentifier) const;
    373373
     374    String serviceWorkerClientIdentifier(const Document&) const;
     375
    374376    RefPtr<WindowProxy> openDummyInspectorFrontend(const String& url);
    375377    void closeDummyInspectorFrontend();
  • trunk/Source/WebCore/testing/Internals.idl

    r235086 r235570  
    625625    boolean isDocumentAlive(unsigned long long documentIdentifier);
    626626
     627    DOMString serviceWorkerClientIdentifier(Document document);
     628
    627629    Promise<void> clearCacheStorageMemoryRepresentation();
    628630    Promise<DOMString> cacheStorageEngineRepresentation();
Note: See TracChangeset for help on using the changeset viewer.