Changeset 206130 in webkit


Ignore:
Timestamp:
Sep 19, 2016 4:36:26 PM (8 years ago)
Author:
commit-queue@webkit.org
Message:

Web Inspector: adopt Object.awaitEvent in LayoutTests/http/tests/inspector
https://bugs.webkit.org/show_bug.cgi?id=162069

Patch by Devin Rousso <Devin Rousso> on 2016-09-19
Reviewed by Brian Burg.

Replace instances of singleFireEventListener with awaitEvent and use promise logic to make
tests more readable.

  • http/tests/inspector/dom/disconnect-dom-tree-after-main-frame-navigation.html:
  • http/tests/inspector/network/copy-as-curl.html:
  • http/tests/inspector/network/resource-timing-expected.txt:
  • http/tests/inspector/network/resource-timing.html:
  • http/tests/inspector/network/xhr-request-data-encoded-correctly.html:
Location:
trunk/LayoutTests
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r206127 r206130  
     12016-09-19  Devin Rousso  <dcrousso+webkit@gmail.com>
     2
     3        Web Inspector: adopt Object.awaitEvent in LayoutTests/http/tests/inspector
     4        https://bugs.webkit.org/show_bug.cgi?id=162069
     5
     6        Reviewed by Brian Burg.
     7
     8        Replace instances of singleFireEventListener with awaitEvent and use promise logic to make
     9        tests more readable.
     10
     11        * http/tests/inspector/dom/disconnect-dom-tree-after-main-frame-navigation.html:
     12        * http/tests/inspector/network/copy-as-curl.html:
     13        * http/tests/inspector/network/resource-timing-expected.txt:
     14        * http/tests/inspector/network/resource-timing.html:
     15        * http/tests/inspector/network/xhr-request-data-encoded-correctly.html:
     16
    1172016-09-16  Jer Noble  <jer.noble@apple.com>
    218
  • trunk/LayoutTests/http/tests/inspector/dom/disconnect-dom-tree-after-main-frame-navigation.html

    r188756 r206130  
    1111        name: "CheckLazyInitializationOfDOMTree",
    1212        description: "Check that DOMTree instances are created lazily.",
    13         test: (resolve, reject) => {
     13        test(resolve, reject) {
    1414            let instances = WebInspector.domTreeManager.retainedObjectsWithPrototype(WebInspector.DOMTree);
    1515            InspectorTest.expectThat(instances.size === 0, "There should not be a DOMTree listening to DOMTreeManager events initially.");
     
    2222        name: "CheckDOMTreeCountAfterUsingGetter",
    2323        description: "Check that the count of connected DOMTrees is correct after initializing them.",
    24         test: (resolve, reject) => {
     24        test(resolve, reject) {
    2525            let mainFrame = WebInspector.frameResourceManager.mainFrame;
    2626            mainFrame.domTree; // Force creation of the root DOM tree.
     
    4646        name: "CheckDOMTreeCountAfterReloading",
    4747        description: "Check that the count of connected DOMTrees is correct after a reload.",
    48         test: (resolve, reject) => {
    49             WebInspector.Frame.singleFireEventListener(WebInspector.Frame.Event.MainResourceDidChange, (event) => {
     48        test(resolve, reject) {
     49            WebInspector.Frame.awaitEvent(WebInspector.Frame.Event.MainResourceDidChange)
     50            .then((event) => {
    5051                let instances = WebInspector.domTreeManager.retainedObjectsWithPrototype(WebInspector.DOMTree);
    5152                InspectorTest.expectThat(instances.size === 0, "There should not be any DOMTrees listening to DOMTreeManager events after a main frame navigation.");
    5253                InspectorTest.log("DOMTree instance count: " + instances.size);
    53                 resolve();
    54             });
     54            })
     55            .then(resolve, reject);
    5556
    5657            InspectorTest.reloadPage();
  • trunk/LayoutTests/http/tests/inspector/network/copy-as-curl.html

    r203132 r206130  
    77function createSimpleGETRequest()
    88{
    9     var request = new XMLHttpRequest();
     9    let request = new XMLHttpRequest();
    1010    request.open("GET", "resources/url?query=true", true);
    1111    request.send();
     
    1414function createGETRequestWithSpecialURL()
    1515{
    16     var request = new XMLHttpRequest();
     16    let request = new XMLHttpRequest();
    1717    request.open("GET", "resources/url'with$special{1..20}chars[] .html", true);
    1818    request.send();
     
    2121function createGETRequestWithSpecialCharsInHeaders()
    2222{
    23     var request = new XMLHttpRequest();
     23    let request = new XMLHttpRequest();
    2424    request.open("GET", "resources/url", true);
    2525    request.setRequestHeader("X-Custom1", "test1");
     
    3131function createGETRequestWithUTF8()
    3232{
    33     var request = new XMLHttpRequest();
     33    let request = new XMLHttpRequest();
    3434    request.open("GET", "resources/url?utf8=👍", true);
    3535    request.send();
     
    3838function createPOSTRequestWithURLEncodedData()
    3939{
    40     var request = new XMLHttpRequest();
     40    let request = new XMLHttpRequest();
    4141    request.open("POST", "resources/url", true);
    4242    request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
     
    4646function createPOSTRequestWithUTF8()
    4747{
    48     var request = new XMLHttpRequest();
     48    let request = new XMLHttpRequest();
    4949    request.open("POST", "resources/url?utf8=👍", true);
    5050    request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
     
    5454function createPUTRequestWithJSON()
    5555{
    56     var request = new XMLHttpRequest();
     56    let request = new XMLHttpRequest();
    5757    request.open("PUT", "resources/url", true);
    5858    request.setRequestHeader("Content-Type", "application/json");
     
    6767        name: "SimpleURLGenerateCURL",
    6868        description: "Generate cURL command from a simple URL.",
    69         test: (resolve, reject) => {
    70             InspectorTest.evaluateInPage("createSimpleGETRequest()");
    71             WebInspector.Frame.singleFireEventListener(WebInspector.Frame.Event.ResourceWasAdded, (event) => {
     69        test(resolve, reject) {
     70            WebInspector.Frame.awaitEvent(WebInspector.Frame.Event.ResourceWasAdded)
     71            .then((event) => {
    7272                let resource = event.data.resource;
    7373                let curl = resource.generateCURLCommand().split(" \\\n");
     
    7777                InspectorTest.expectThat(curl.find((cmd) => cmd.includes('User-Agent')) !== undefined, "Command should contain User-Agent header.");
    7878                InspectorTest.expectThat(curl.find((cmd) => cmd.includes('X-Custom')) === undefined, "Command should not contain a custom header.");
    79                 resolve();
    80             });
     79            })
     80            .then(resolve, reject);
     81
     82            InspectorTest.evaluateInPage("createSimpleGETRequest()");
    8183        }
    8284    });
     
    8587        name: "SpecialURLGenerateCURL",
    8688        description: "Generate cURL command from a URL containing special characters.",
    87         test: (resolve, reject) => {
     89        test(resolve, reject) {
     90            WebInspector.Frame.awaitEvent(WebInspector.Frame.Event.ResourceWasAdded)
     91            .then((event) => {
     92                let resource = event.data.resource;
     93                let curl = resource.generateCURLCommand().split(" \\\n");
     94
     95                InspectorTest.expectThat(curl[0].match("https?://.*?/resources/url\\\\'with\\$special\\\\{1\.\.20\\\\}chars\\\\\\[\\\\\\]%20.html") !== null, "Command should contain valid POSIX escaped URL.");
     96            })
     97            .then(resolve, reject);
     98
    8899            InspectorTest.evaluateInPage("createGETRequestWithSpecialURL()");
    89             WebInspector.Frame.singleFireEventListener(WebInspector.Frame.Event.ResourceWasAdded, (event) => {
    90                 let resource = event.data.resource;
    91                 let curl = resource.generateCURLCommand().split(" \\\n");
    92 
    93                 InspectorTest.expectThat(curl[0].match("https?://.*?/resources/url\\\\'with\\$special\\\\{1\.\.20\\\\}chars\\\\\\[\\\\\\]%20.html") !== null, "Command should contain valid POSIX escaped URL.");
    94                 resolve();
    95             });
    96100        }
    97101    });
     
    100104        name: "SpecialHeadersGenerateCURLValidPOSIXOutput",
    101105        description: "Generate cURL command from a request containing special characters in the headers and verify valid POSIX output.",
    102         test: (resolve, reject) => {
    103             InspectorTest.evaluateInPage("createGETRequestWithSpecialCharsInHeaders()");
    104             WebInspector.Frame.singleFireEventListener(WebInspector.Frame.Event.ResourceWasAdded, (event) => {
     106        test(resolve, reject) {
     107            WebInspector.Frame.awaitEvent(WebInspector.Frame.Event.ResourceWasAdded)
     108            .then((event) => {
    105109                let resource = event.data.resource;
    106110                let curl = resource.generateCURLCommand().split(" \\\n");
     
    109113                InspectorTest.expectThat(curl.find((cmd) => cmd.includes('X-Custom2')) === "-H $'X-Custom2\\'%: \\'Test\\'\\'1\\\\\\'2'", "Command should have correct custom header 2.");
    110114                InspectorTest.expectThat(curl.find((cmd) => cmd.includes('X-Custom3')) === "-H $'X-Custom3: \\'${PWD}'", "Command should have correct custom header 3.");
    111                 resolve();
    112             });
     115            })
     116            .then(resolve, reject);
     117
     118            InspectorTest.evaluateInPage("createGETRequestWithSpecialCharsInHeaders()");
    113119        }
    114120    });
     
    117123        name: "URLWithUTF8GenerateCURL",
    118124        description: "Generate cURL command from a URL containing UTF8 characters.",
    119         test: (resolve, reject) => {
     125        test(resolve, reject) {
     126            WebInspector.Frame.awaitEvent(WebInspector.Frame.Event.ResourceWasAdded)
     127            .then((event) => {
     128                let resource = event.data.resource;
     129                let curl = resource.generateCURLCommand().split(" \\\n");
     130
     131                InspectorTest.expectThat(curl[0].match("https?://.*?/resources/url\\?utf8=%F0%9F%91%8D") !== null, "Command should contain URL with UTF8 characters.");
     132            })
     133            .then(resolve, reject);
     134
    120135            InspectorTest.evaluateInPage("createGETRequestWithUTF8()");
    121             WebInspector.Frame.singleFireEventListener(WebInspector.Frame.Event.ResourceWasAdded, (event) => {
    122                 let resource = event.data.resource;
    123                 let curl = resource.generateCURLCommand().split(" \\\n");
    124 
    125                 InspectorTest.expectThat(curl[0].match("https?://.*?/resources/url\\?utf8=%F0%9F%91%8D") !== null, "Command should contain URL with UTF8 characters.");
    126                 resolve();
    127             });
    128136        }
    129137    });
     
    132140        name: "POSTRequestURLEncodedDataGenerateCURL",
    133141        description: "Generate cURL command from a POST request with URL encoded data.",
    134         test: (resolve, reject) => {
    135             InspectorTest.evaluateInPage("createPOSTRequestWithURLEncodedData()");
    136             WebInspector.Frame.singleFireEventListener(WebInspector.Frame.Event.ResourceWasAdded, (event) => {
     142        test(resolve, reject) {
     143            WebInspector.Frame.awaitEvent(WebInspector.Frame.Event.ResourceWasAdded)
     144            .then((event) => {
    137145                let resource = event.data.resource;
    138146                let curl = resource.generateCURLCommand().split(" \\\n");
     
    141149                InspectorTest.expectThat(curl.find((cmd) => cmd.includes('Content-Type')) === "-H 'Content-Type: application/x-www-form-urlencoded'", "Command should have correct Content-Type.");
    142150                InspectorTest.expectThat(curl.find((cmd) => cmd === "--data $'lorem=ipsum&$dolor=\\'sit\\'&amet={1..20}'") !== undefined, "Command should contain correct data.");
    143                 resolve();
    144             });
     151            })
     152            .then(resolve, reject);
     153
     154            InspectorTest.evaluateInPage("createPOSTRequestWithURLEncodedData()");
    145155        }
    146156    });
     
    149159        name: "POSTRequestURLEncodedDataUTF8GenerateCURL",
    150160        description: "Generate cURL command from a POST request with URL encoded UTF8 data.",
    151         test: (resolve, reject) => {
    152             InspectorTest.evaluateInPage("createPOSTRequestWithUTF8()");
    153             WebInspector.Frame.singleFireEventListener(WebInspector.Frame.Event.ResourceWasAdded, (event) => {
     161        test(resolve, reject) {
     162            WebInspector.Frame.awaitEvent(WebInspector.Frame.Event.ResourceWasAdded)
     163            .then((event) => {
    154164                let resource = event.data.resource;
    155165                let curl = resource.generateCURLCommand().split(" \\\n");
     
    157167                InspectorTest.expectThat(curl[0].match("https?://.*?/resources/url\\?utf8=%F0%9F%91%8D") !== null, "Command should contain URL with UTF8 characters.");
    158168                InspectorTest.expectThat(curl.find((cmd) => cmd === "--data $'\\ud83c\\udf28=\\u26c4\\ufe0f'") !== undefined, "Command should contain correct UTF8 data.");
    159                 resolve();
    160             });
     169            })
     170            .then(resolve, reject);
     171
     172            InspectorTest.evaluateInPage("createPOSTRequestWithUTF8()");
    161173        }
    162174    });
     
    165177        name: "PUTRequestWithJSONGenerateCURL",
    166178        description: "Generate cURL command from a PUT request with JSON data.",
    167         test: (resolve, reject) => {
    168             InspectorTest.evaluateInPage("createPUTRequestWithJSON()");
    169             WebInspector.Frame.singleFireEventListener(WebInspector.Frame.Event.ResourceWasAdded, (event) => {
     179        test(resolve, reject) {
     180            WebInspector.Frame.awaitEvent(WebInspector.Frame.Event.ResourceWasAdded)
     181            .then((event) => {
    170182                let resource = event.data.resource;
    171183                let curl = resource.generateCURLCommand().split(" \\\n");
     
    174186                InspectorTest.expectThat(curl.find((cmd) => cmd.includes('Content-Type')) === "-H 'Content-Type: application/json'", "Command should have JSON Content-Type.");
    175187                InspectorTest.expectThat(curl.find((cmd) => cmd === "--data-binary '{\"update\":\"now\"}'") !== undefined, "Command should contain correct JSON data.");
    176                 resolve();
    177             });
     188            })
     189            .then(resolve, reject);
     190
     191            InspectorTest.evaluateInPage("createPUTRequestWithJSON()");
    178192        }
    179193    });
  • trunk/LayoutTests/http/tests/inspector/network/resource-timing-expected.txt

    r205211 r206130  
    44== Running test suite: ResourceTimingData
    55-- Running test case: CheckResourceTimingInformationForResource
     6PASS: Resource should be createad.
     7PASS: Added Resource received a response.
     8PASS: Added Resource did finish loading.
    69PASS: Newly added resource should have a resource timing model.
    7 PASS: Newly added resource should have a start time.
    8 PASS: Resource should now contain timing information.
    910PASS: Resource should have a start time.
    1011PASS: Resource should have a request start time.
     
    1516PASS: A secure connection should be reused or secureConnectionStart should come after connectStart.
    1617PASS: responseStart should come after requestStart.
    17 PASS: responseEnd should not be available yet.
    1818PASS: responseEnd should come after responseStart.
    1919
  • trunk/LayoutTests/http/tests/inspector/network/resource-timing.html

    r205211 r206130  
    1717        name: "CheckResourceTimingInformationForResource",
    1818        description: "Check if a resource has timing information.",
    19         test: (resolve, reject) => {
     19        test(resolve, reject) {
     20            Promise.all([
     21                WebInspector.Frame.awaitEvent(WebInspector.Frame.Event.ResourceWasAdded),
     22                WebInspector.Resource.awaitEvent(WebInspector.Resource.Event.ResponseReceived),
     23                WebInspector.Resource.awaitEvent(WebInspector.Resource.Event.LoadingDidFinish)
     24            ])
     25            .then(([resourceWasAddedEvent, responseReceivedEvent, loadingDidFinishEvent]) => {
     26                let resource = resourceWasAddedEvent.data.resource;
     27
     28                InspectorTest.expectThat(resource instanceof WebInspector.Resource, "Resource should be createad.");
     29                InspectorTest.expectThat(resource === responseReceivedEvent.target, "Added Resource received a response.");
     30                InspectorTest.expectThat(resource === loadingDidFinishEvent.target, "Added Resource did finish loading.");
     31
     32                let timingData = resource.timingData;
     33                InspectorTest.expectThat(timingData instanceof WebInspector.ResourceTimingData, "Newly added resource should have a resource timing model.");
     34                InspectorTest.expectThat(timingData.startTime > 0, "Resource should have a start time.");
     35                InspectorTest.expectThat(timingData.requestStart > 0, "Resource should have a request start time.");
     36                InspectorTest.expectThat(timingData.responseStart > 0, "Resource should have a response start time.");
     37
     38                InspectorTest.expectThat(typeof timingData.domainLookupStart === "number" && typeof timingData.domainLookupEnd === "number", "domainLookupStart and domainLookupEnd should both be NaN or a number.");
     39                InspectorTest.expectThat(typeof timingData.connectStart === "number" && typeof timingData.connectStart === "number", "connectStart and connectEnd should both be NaN or a number.");
     40
     41                InspectorTest.expectThat(timingData.startTime <= timingData.requestStart, "requestStart should come after startTime.");
     42                InspectorTest.expectThat(isNaN(timingData.secureConnectionStart) || timingData.connectStart <= timingData.secureConnectionStart, "A secure connection should be reused or secureConnectionStart should come after connectStart.");
     43                InspectorTest.expectThat(timingData.requestStart <= timingData.responseStart, "responseStart should come after requestStart.");
     44                InspectorTest.expectThat(timingData.responseStart <= timingData.responseEnd, "responseEnd should come after responseStart.");
     45            })
     46            .then(resolve, reject);
     47
    2048            InspectorTest.evaluateInPage("createRequest()");
    21             WebInspector.Frame.singleFireEventListener(WebInspector.Frame.Event.ResourceWasAdded, (event) => {
    22                 let resource = event.data.resource;
    23 
    24                 InspectorTest.expectThat(resource.timingData instanceof WebInspector.ResourceTimingData, "Newly added resource should have a resource timing model.");
    25                 InspectorTest.expectThat(resource.timingData.startTime, "Newly added resource should have a start time.");
    26 
    27                 resource.singleFireEventListener(WebInspector.Resource.Event.ResponseReceived, (event) => {
    28                     let timingData = resource.timingData;
    29 
    30                     InspectorTest.expectThat(timingData, "Resource should now contain timing information.");
    31                     InspectorTest.expectThat(timingData.startTime > 0, "Resource should have a start time.");
    32                     InspectorTest.expectThat(timingData.requestStart > 0, "Resource should have a request start time.");
    33                     InspectorTest.expectThat(timingData.responseStart > 0, "Resource should have a response start time.");
    34 
    35                     InspectorTest.expectThat(typeof timingData.domainLookupStart === "number" && typeof timingData.domainLookupEnd === "number", "domainLookupStart and domainLookupEnd should both be NaN or a number.");
    36                     InspectorTest.expectThat(typeof timingData.connectStart === "number" && typeof timingData.connectStart === "number", "connectStart and connectEnd should both be NaN or a number.");
    37 
    38                     InspectorTest.expectThat(timingData.startTime <= timingData.requestStart, "requestStart should come after startTime.");
    39                     InspectorTest.expectThat(isNaN(timingData.secureConnectionStart) || timingData.connectStart <= timingData.secureConnectionStart, "A secure connection should be reused or secureConnectionStart should come after connectStart.");
    40                     InspectorTest.expectThat(timingData.requestStart <= timingData.responseStart, "responseStart should come after requestStart.");
    41                     InspectorTest.expectThat(isNaN(timingData.responseEnd), "responseEnd should not be available yet.");
    42                 });
    43 
    44                 resource.singleFireEventListener(WebInspector.Resource.Event.LoadingDidFinish, (event) => {
    45                     let timingData = resource.timingData;
    46                     InspectorTest.expectThat(timingData.responseStart <= timingData.responseEnd, "responseEnd should come after responseStart.");
    47                     resolve();
    48                 });
    49             });
    5049        }
    5150    });
  • trunk/LayoutTests/http/tests/inspector/network/xhr-request-data-encoded-correctly.html

    r202843 r206130  
    66<script>
    77function createXHRResource() {
    8     var request = new XMLHttpRequest();
     8    let request = new XMLHttpRequest();
    99    request.open("POST", "resources/", true);
    1010    request.send("utf8=👍");
     
    1818        name: "XHRWithRequestDataIsEncodedCorrectly",
    1919        description: "XHR with request data is encoded correctly.",
    20         test: (resolve, reject) => {
    21             InspectorTest.evaluateInPage("createXHRResource()");
    22             WebInspector.Frame.singleFireEventListener(WebInspector.Frame.Event.ResourceWasAdded, (event) => {
     20        test(resolve, reject) {
     21            WebInspector.Frame.awaitEvent(WebInspector.Frame.Event.ResourceWasAdded)
     22            .then((event) => {
    2323                let resource = event.data.resource;
    2424                InspectorTest.expectThat(resource instanceof WebInspector.Resource, "Resource should be created.");
    2525                InspectorTest.expectThat(resource.requestData === "utf8=👍", "Request data should have expected content.");
    26                 resource.singleFireEventListener(WebInspector.Resource.Event.LoadingDidFinish, (event) => {
    27                     InspectorTest.pass("Resource load should finish.");
    28                     resolve();
    29                 });
    30             });
     26                return resource.awaitEvent(WebInspector.Resource.Event.LoadingDidFinish);
     27            })
     28            .then((event) => {
     29                InspectorTest.pass("Resource load should finish.");
     30            })
     31            .then(resolve, reject);
     32
     33            InspectorTest.evaluateInPage("createXHRResource()");
    3134        }
    3235    });
    33    
     36
    3437    suite.runTestCasesAndFinish();
    3538}
Note: See TracChangeset for help on using the changeset viewer.