Title: [105596] trunk
Revision
105596
Author
[email protected]
Date
2012-01-23 01:02:56 -0800 (Mon, 23 Jan 2012)

Log Message

Web Inspector: HAR pageref attributes are wrong and inconsistent with pages array
https://bugs.webkit.org/show_bug.cgi?id=76398

Reviewed by Pavel Feldman.

Source/WebCore:

- introduce a notion of LoadPage;
- move page load times to LoadPage;
- associate network resources with LoadPage;
- export pages for all available resoruces to HAR, not just the last page;
- use page ids, not document URLs in HAR entries to refer to pages;
- use page URL as a title field of a HAR page;

* inspector/front-end/AuditsPanel.js:
(WebInspector.AuditsPanel):
* inspector/front-end/HAREntry.js:
(WebInspector.HAREntry.prototype.build):
(WebInspector.HAREntry.prototype.get responseCompression):
(WebInspector.HARLog.prototype._buildPages):
(WebInspector.HARLog.prototype._convertPage):
(WebInspector.HARLog.prototype._pageEventTime):
* inspector/front-end/NetworkLog.js:
(WebInspector.NetworkLog):
(WebInspector.NetworkLog.prototype._mainFrameNavigated):
(WebInspector.NetworkLog.prototype._onResourceStarted):
(WebInspector.Page):
(WebInspector.Page.prototype.get id):
(WebInspector.Page.prototype.get url):
(WebInspector.Page.prototype.get contentLoadTime):
(WebInspector.Page.prototype.set contentLoadTime):
(WebInspector.Page.prototype.get loadTime):
(WebInspector.Page.prototype.set loadTime):
(WebInspector.Page.prototype.get startTime):
(WebInspector.Page.prototype._bindResource):
* inspector/front-end/NetworkManager.js:
(WebInspector.NetworkDispatcher.prototype.requestServedFromMemoryCache):
* inspector/front-end/Resource.js:
(WebInspector.Resource.prototype.get page):
(WebInspector.Resource.prototype.set page):
* inspector/front-end/ResourceTreeModel.js:
(WebInspector.ResourceTreeFrame):
(WebInspector.ResourceTreeFrame.prototype.get page):
(WebInspector.PageDispatcher.prototype.domContentEventFired):
(WebInspector.PageDispatcher.prototype.loadEventFired):

LayoutTests:

* http/tests/inspector/resource-har-headers-expected.txt:
* http/tests/inspector/resource-parameters-expected.txt:
* platform/chromium/http/tests/inspector/resource-har-conversion-expected.txt:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (105595 => 105596)


--- trunk/LayoutTests/ChangeLog	2012-01-23 08:58:25 UTC (rev 105595)
+++ trunk/LayoutTests/ChangeLog	2012-01-23 09:02:56 UTC (rev 105596)
@@ -1,3 +1,14 @@
+2012-01-20  Andrey Kosyakov  <[email protected]>
+
+        Web Inspector: HAR pageref attributes are wrong and inconsistent with pages array
+        https://bugs.webkit.org/show_bug.cgi?id=76398
+
+        Reviewed by Pavel Feldman.
+
+        * http/tests/inspector/resource-har-headers-expected.txt:
+        * http/tests/inspector/resource-parameters-expected.txt:
+        * platform/chromium/http/tests/inspector/resource-har-conversion-expected.txt:
+
 2012-01-23  Philippe Normand  <[email protected]>
 
         Unreviewed, GTK gardening, marked a test as flaky and unskipped

Modified: trunk/LayoutTests/http/tests/inspector/resource-har-headers-expected.txt (105595 => 105596)


--- trunk/LayoutTests/http/tests/inspector/resource-har-headers-expected.txt	2012-01-23 08:58:25 UTC (rev 105595)
+++ trunk/LayoutTests/http/tests/inspector/resource-har-headers-expected.txt	2012-01-23 09:02:56 UTC (rev 105596)
@@ -19,7 +19,6 @@
     }
 }
 HAR:{
-    pageref : "http://example.com/inspector-test.js"
     startedDateTime : <object>
     time : <number>
     request : {

Added: trunk/LayoutTests/http/tests/inspector/resource-har-pages-expected.txt (0 => 105596)


--- trunk/LayoutTests/http/tests/inspector/resource-har-pages-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/inspector/resource-har-pages-expected.txt	2012-01-23 09:02:56 UTC (rev 105596)
@@ -0,0 +1,31 @@
+Tests conversion of Inspector's resource representation into HAR format.
+
+Page reloaded.
+{
+    0 : {
+        startedDateTime : <plausible>
+        id : <string>
+        title : "http://127.0.0.1:8000/resources/redirect.php?url=""
+        pageTimings : {
+            onContentLoad : <number>
+            onLoad : <number>
+        }
+    }
+    1 : {
+        startedDateTime : <plausible>
+        id : <string>
+        title : "http://127.0.0.1:8000/inspector/resource-har-pages.html"
+        pageTimings : {
+            onContentLoad : <number>
+            onLoad : <number>
+        }
+    }
+}
+page: page_2 url: http://127.0.0.1:8000/inspector/inspector-test.js
+page: page_2 url: http://127.0.0.1:8000/inspector/resource-har-pages.html
+page: page_2 url: http://127.0.0.1:8000/inspector/resources-test.js
+page: page_1 url: http://127.0.0.1:8000/inspector/resources/har-pages-iframe.html
+page: page_1 url: http://127.0.0.1:8000/inspector/resources/har-pages-navigation-target.html
+page: page_1 url: http://127.0.0.1:8000/inspector/resources/source1.js
+page: page_1 url: http://127.0.0.1:8000/resources/redirect.php?url=""
+
Property changes on: trunk/LayoutTests/http/tests/inspector/resource-har-pages-expected.txt
___________________________________________________________________

Added: svn:eol-style

Added: trunk/LayoutTests/http/tests/inspector/resource-har-pages.html (0 => 105596)


--- trunk/LayoutTests/http/tests/inspector/resource-har-pages.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/inspector/resource-har-pages.html	2012-01-23 09:02:56 UTC (rev 105596)
@@ -0,0 +1,64 @@
+<!doctype html>
+<html>
+<head>
+<script src=""
+<script src=""
+
+<script>
+
+var test = function()
+{
+    function step1()
+    {
+        var hadNavigation = false;
+
+        function onResourceFinished(event)
+        {
+            var resource = event.data;
+            if (/\/har-pages-navigation-target\.html$/.test(resource.url))
+                hadNavigation = true;
+            if (hadNavigation && /\/resource-har-pages\.html$/.test(resource.url)) {
+                WebInspector.networkManager.removeEventListener(WebInspector.NetworkManager.EventTypes.ResourceFinished, onResourceFinished)
+                step2();
+            }
+        }
+        WebInspector.inspectorView.setCurrentPanel(WebInspector.panels.network);
+        var networkLogView = WebInspector.panels.network._networkLogView;
+        // networkLogView.clear();
+        networkLogView._preserveLogToggle.toggled = true;
+        WebInspector.networkManager.addEventListener(WebInspector.NetworkManager.EventTypes.ResourceFinished, onResourceFinished);
+        InspectorTest.evaluateInPage("location.href = '';");
+    }
+
+    function step2()
+    {
+        var log = (new WebInspector.HARLog(WebInspector.panels.network._networkLogView._resources)).build();
+        InspectorTest.addObject(log.pages, InspectorTest.HARPropertyFormattersWithSize);
+
+        // Filter out favicon.ico requests that only appear on certain platforms.
+        log.entries = log.entries.filter(function(entry) {
+            return !/favicon\.ico$/.test(entry.request.url);
+        });
+        log.entries.sort(InspectorTest.resourceURLComparer);
+        for (var i = 0; i < log.entries.length; ++i) {
+            var entry = log.entries[i];
+            InspectorTest.addResult("page: " + entry.pageref + " url: " + entry.request.url);
+        }
+        InspectorTest.completeTest();
+    }
+
+    step1();
+}
+
+</script>
+
+
+</head>
+
+<body _onload_="runTest()">
+<p>
+Tests conversion of Inspector's resource representation into HAR format.
+</p>
+
+</body>
+</html>
Property changes on: trunk/LayoutTests/http/tests/inspector/resource-har-pages.html
___________________________________________________________________

Added: svn:eol-style

Modified: trunk/LayoutTests/http/tests/inspector/resource-parameters-expected.txt (105595 => 105596)


--- trunk/LayoutTests/http/tests/inspector/resource-parameters-expected.txt	2012-01-23 08:58:25 UTC (rev 105595)
+++ trunk/LayoutTests/http/tests/inspector/resource-parameters-expected.txt	2012-01-23 09:02:56 UTC (rev 105596)
@@ -3,7 +3,6 @@
   
 
 {
-    pageref : "http://localhost:8000/inspector/resources/post-target.cgi?queryParam1=queryValue1&queryParam2=#fragmentParam1=fragmentValue1&fragmentParam2="
     startedDateTime : <plausible>
     time : <number>
     request : {

Modified: trunk/LayoutTests/platform/chromium/http/tests/inspector/resource-har-conversion-expected.txt (105595 => 105596)


--- trunk/LayoutTests/platform/chromium/http/tests/inspector/resource-har-conversion-expected.txt	2012-01-23 08:58:25 UTC (rev 105595)
+++ trunk/LayoutTests/platform/chromium/http/tests/inspector/resource-har-conversion-expected.txt	2012-01-23 09:02:56 UTC (rev 105596)
@@ -11,7 +11,7 @@
         {
             startedDateTime : <plausible>
             id : <string>
-            title : ""
+            title : "http://127.0.0.1:8000/inspector/resource-har-conversion.html"
             pageTimings : {
                 onContentLoad : <number>
                 onLoad : <number>
@@ -20,7 +20,6 @@
     ]
     entries : [
         {
-            pageref : "http://127.0.0.1:8000/inspector/resource-har-conversion.html"
             startedDateTime : <plausible>
             time : <number>
             request : {
@@ -107,9 +106,9 @@
             cache : {
             }
             timings : <object>
+            pageref : "page_1"
         }
         {
-            pageref : "http://127.0.0.1:8000/inspector/resource-har-conversion.html"
             startedDateTime : <plausible>
             time : <number>
             request : {
@@ -143,9 +142,9 @@
             cache : {
             }
             timings : <object>
+            pageref : "page_1"
         }
         {
-            pageref : "http://127.0.0.1:8000/inspector/resource-har-conversion.html"
             startedDateTime : <plausible>
             time : <number>
             request : {
@@ -178,9 +177,9 @@
             cache : {
             }
             timings : <object>
+            pageref : "page_1"
         }
         {
-            pageref : "http://127.0.0.1:8000/inspector/resource-har-conversion.html"
             startedDateTime : <plausible>
             time : <number>
             request : {
@@ -218,6 +217,7 @@
             cache : {
             }
             timings : <object>
+            pageref : "page_1"
         }
     ]
 }

Modified: trunk/Source/WebCore/ChangeLog (105595 => 105596)


--- trunk/Source/WebCore/ChangeLog	2012-01-23 08:58:25 UTC (rev 105595)
+++ trunk/Source/WebCore/ChangeLog	2012-01-23 09:02:56 UTC (rev 105596)
@@ -1,3 +1,49 @@
+2012-01-20  Andrey Kosyakov  <[email protected]>
+
+        Web Inspector: HAR pageref attributes are wrong and inconsistent with pages array
+        https://bugs.webkit.org/show_bug.cgi?id=76398
+
+        Reviewed by Pavel Feldman.
+
+        - introduce a notion of LoadPage;
+        - move page load times to LoadPage;
+        - associate network resources with LoadPage;
+        - export pages for all available resoruces to HAR, not just the last page;
+        - use page ids, not document URLs in HAR entries to refer to pages;
+        - use page URL as a title field of a HAR page;
+
+        * inspector/front-end/AuditsPanel.js:
+        (WebInspector.AuditsPanel):
+        * inspector/front-end/HAREntry.js:
+        (WebInspector.HAREntry.prototype.build):
+        (WebInspector.HAREntry.prototype.get responseCompression):
+        (WebInspector.HARLog.prototype._buildPages):
+        (WebInspector.HARLog.prototype._convertPage):
+        (WebInspector.HARLog.prototype._pageEventTime):
+        * inspector/front-end/NetworkLog.js:
+        (WebInspector.NetworkLog):
+        (WebInspector.NetworkLog.prototype._mainFrameNavigated):
+        (WebInspector.NetworkLog.prototype._onResourceStarted):
+        (WebInspector.Page):
+        (WebInspector.Page.prototype.get id):
+        (WebInspector.Page.prototype.get url):
+        (WebInspector.Page.prototype.get contentLoadTime):
+        (WebInspector.Page.prototype.set contentLoadTime):
+        (WebInspector.Page.prototype.get loadTime):
+        (WebInspector.Page.prototype.set loadTime):
+        (WebInspector.Page.prototype.get startTime):
+        (WebInspector.Page.prototype._bindResource):
+        * inspector/front-end/NetworkManager.js:
+        (WebInspector.NetworkDispatcher.prototype.requestServedFromMemoryCache):
+        * inspector/front-end/Resource.js:
+        (WebInspector.Resource.prototype.get page):
+        (WebInspector.Resource.prototype.set page):
+        * inspector/front-end/ResourceTreeModel.js:
+        (WebInspector.ResourceTreeFrame):
+        (WebInspector.ResourceTreeFrame.prototype.get page):
+        (WebInspector.PageDispatcher.prototype.domContentEventFired):
+        (WebInspector.PageDispatcher.prototype.loadEventFired):
+
 2012-01-22  Mario Sanchez Prada  <[email protected]>
 
         [GTK] ATK text-caret-moved and text-selection-changed events not being emitted

Modified: trunk/Source/WebCore/inspector/front-end/AuditsPanel.js (105595 => 105596)


--- trunk/Source/WebCore/inspector/front-end/AuditsPanel.js	2012-01-23 08:58:25 UTC (rev 105595)
+++ trunk/Source/WebCore/inspector/front-end/AuditsPanel.js	2012-01-23 09:02:56 UTC (rev 105596)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011 Google Inc. All rights reserved.
+ * Copyright (C) 2012 Google Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -61,8 +61,7 @@
     for (var id in this.categoriesById)
         this._launcherView.addCategory(this.categoriesById[id]);
 
-    WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.OnLoad, this._onLoadEventFired, this);
-    WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.DOMContentLoaded, this._domContentLoadedEventFired, this);
+    WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.OnLoad, this._didMainResourceLoad, this);
 }
 
 WebInspector.AuditsPanel.prototype = {
@@ -76,27 +75,6 @@
         return [this.clearResultsButton.element];
     },
 
-    get mainResourceLoadTime()
-    {
-        return this._mainResourceLoadTime;
-    },
-
-    _onLoadEventFired: function(event)
-    {
-        this._mainResourceLoadTime = event.data;
-        this._didMainResourceLoad();
-    },
-
-    get mainResourceDOMContentTime()
-    {
-        return this._mainResourceDOMContentTime;
-    },
-
-    _domContentLoadedEventFired: function(event)
-    {
-        this._mainResourceDOMContentTime = event.data;
-    },
-
     get categoriesById()
     {
         return this._auditCategoriesById;

Modified: trunk/Source/WebCore/inspector/front-end/HAREntry.js (105595 => 105596)


--- trunk/Source/WebCore/inspector/front-end/HAREntry.js	2012-01-23 08:58:25 UTC (rev 105595)
+++ trunk/Source/WebCore/inspector/front-end/HAREntry.js	2012-01-23 09:02:56 UTC (rev 105596)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011 Google Inc. All rights reserved.
+ * Copyright (C) 2012 Google Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -49,8 +49,7 @@
      */
     build: function()
     {
-        return {
-            pageref: this._resource.documentURL,
+        var entry =  {
             startedDateTime: new Date(this._resource.startTime * 1000),
             time: WebInspector.HAREntry._toMilliseconds(this._resource.duration),
             request: this._buildRequest(),
@@ -58,6 +57,10 @@
             cache: { }, // Not supported yet.
             timings: this._buildTimings()
         };
+        var page = WebInspector.networkLog.pageLoadForResource(this._resource);
+        if (page)
+            entry.pageref = "page_" + page.id;
+        return entry;
     },
 
     /**
@@ -251,11 +254,11 @@
     },
 
     /**
-     * @return {number}
+     * @return {number|undefined}
      */
     get responseCompression()
     {
-        if (this._resource.cahced || this._resource.statusCode === 304)
+        if (this._resource.cached || this._resource.statusCode === 304)
             return;
         return this._resource.resourceSize - (this._resource.transferSize - this._resource.responseHeadersSize);
     }
@@ -303,24 +306,32 @@
      */
     _buildPages: function()
     {
-        return [
-            {
-                startedDateTime: new Date(WebInspector.networkLog.mainResourceStartTime * 1000),
-                id: WebInspector.inspectedPageURL,
-                title: "",
-                pageTimings: this.buildMainResourceTimings()
-            }
-        ];
+        var seenIdentifiers = {};
+        var pages = [];
+        for (var i = 0; i < this._resources.length; ++i) {
+            var page = WebInspector.networkLog.pageLoadForResource(this._resources[i]);
+            if (!page || seenIdentifiers[page.id])
+                continue;
+            seenIdentifiers[page.id] = true;
+            pages.push(this._convertPage(page));
+        }
+        return pages;
     },
 
     /**
+     * @param {WebInspector.PageLoad} page
      * @return {Object}
      */
-    buildMainResourceTimings: function()
+    _convertPage: function(page)
     {
         return {
-             onContentLoad: this._pageEventTime(WebInspector.mainResourceDOMContentTime),
-             onLoad: this._pageEventTime(WebInspector.mainResourceLoadTime),
+            startedDateTime: new Date(page.startTime * 1000),
+            id: "page_" + page.id,
+            title: page.url, // We don't have actual page title here. URL is probably better than nothing.
+            pageTimings: {
+                onContentLoad: this._pageEventTime(page, page.contentLoadTime),
+                onLoad: this._pageEventTime(page, page.loadTime)
+            }
         }
     },
 
@@ -334,12 +345,13 @@
     },
 
     /**
+     * @param {WebInspector.PageLoad} page
      * @param {number} time
      * @return {number}
      */
-    _pageEventTime: function(time)
+    _pageEventTime: function(page, time)
     {
-        var startTime = WebInspector.mainResourceStartTime;
+        var startTime = page.startTime;
         if (time === -1 || startTime === -1)
             return -1;
         return WebInspector.HAREntry._toMilliseconds(time - startTime);

Modified: trunk/Source/WebCore/inspector/front-end/NetworkLog.js (105595 => 105596)


--- trunk/Source/WebCore/inspector/front-end/NetworkLog.js	2012-01-23 08:58:25 UTC (rev 105595)
+++ trunk/Source/WebCore/inspector/front-end/NetworkLog.js	2012-01-23 09:02:56 UTC (rev 105596)
@@ -34,9 +34,10 @@
 WebInspector.NetworkLog = function()
 {
     this._resources = [];
-    this._mainResourceStartTime = null;
     WebInspector.networkManager.addEventListener(WebInspector.NetworkManager.EventTypes.ResourceStarted, this._onResourceStarted, this);
-    WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.MainFrameNavigated, this._mainFrameNavigated, this);
+    WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.MainFrameNavigated, this._onMainFrameNavigated, this);
+    WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.OnLoad, this._onLoad, this);
+    WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.DOMContentLoaded, this._onDOMContentLoaded, this);
 }
 
 WebInspector.NetworkLog.prototype = {
@@ -49,28 +50,30 @@
     },
 
     /**
-     * @return {?Date}
+     * @param {WebInspector.Resource} resource
+     * @return {WebInspector.PageLoad}
      */
-    get mainResourceStartTime()
+    pageLoadForResource: function(resource)
     {
-        return this._mainResourceStartTime;
+        return resource.__page;
     },
 
     /**
      * @param {WebInspector.Event} event
      */
-    _mainFrameNavigated: function(event)
+    _onMainFrameNavigated: function(event)
     {
         var mainFrame = /** type {WebInspector.ResourceTreeFrame} */ event.data;
-        this._mainResourceStartTime = null;
         // Preserve resources from the new session.
+        this._currentPageLoad = null;
         var oldResources = this._resources.splice(0, this._resources.length);
         for (var i = 0; i < oldResources.length; ++i) {
             var resource = oldResources[i];
             if (resource.loaderId === mainFrame.loaderId) {
-                if (!this._mainResourceStartTime && mainFrame.url ="" resource.url)
-                    this._mainResourceStartTime = resource.startTime;
+                if (!this._currentPageLoad)
+                    this._currentPageLoad = new WebInspector.PageLoad(resource);
                 this._resources.push(resource);
+                resource.__page = this._currentPageLoad;
             }
         }
     },
@@ -82,10 +85,43 @@
     {
         var resource = /** @type {WebInspector.Resource} */ event.data;
         this._resources.push(resource);
-    }
+        resource.__page = this._currentPageLoad;
+    },
+
+    /**
+     * @param {WebInspector.Event} event
+     */
+    _onDOMContentLoaded: function(event)
+    {
+        if (this._currentPageLoad)
+            this._currentPageLoad.contentLoadTime = event.data;
+    },
+
+    /**
+     * @param {WebInspector.Event} event
+     */
+    _onLoad: function(event)
+    {
+        if (this._currentPageLoad)
+            this._currentPageLoad.loadTime = event.data;
+    },
+
 }
 
 /**
  * @type {WebInspector.NetworkLog}
  */
 WebInspector.networkLog = null;
+
+/**
+ * @constructor
+ * @param {WebInspector.Resource} mainResource
+ */
+WebInspector.PageLoad = function(mainResource)
+{
+    this.id = ++WebInspector.PageLoad._lastIdentifier;
+    this.url = ""
+    this.startTime = mainResource.startTime;
+}
+
+WebInspector.PageLoad._lastIdentifier = 0;

Modified: trunk/Source/WebCore/inspector/front-end/ResourceTreeModel.js (105595 => 105596)


--- trunk/Source/WebCore/inspector/front-end/ResourceTreeModel.js	2012-01-23 08:58:25 UTC (rev 105595)
+++ trunk/Source/WebCore/inspector/front-end/ResourceTreeModel.js	2012-01-23 09:02:56 UTC (rev 105596)
@@ -613,17 +613,11 @@
     domContentEventFired: function(time)
     {
         this._resourceTreeModel.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes.DOMContentLoaded, time);
-
-        // FIXME: the only client is HAR, fix it there.
-        WebInspector.mainResourceDOMContentTime = time;
     },
 
     loadEventFired: function(time)
     {
         this._resourceTreeModel.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes.OnLoad, time);
-
-        // FIXME: the only client is HAR, fix it there.
-        WebInspector.mainResourceLoadTime = time;
     },
 
     frameNavigated: function(frame)
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to