<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[56732] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/56732">56732</a></dd>
<dt>Author</dt> <dd>apavlov@chromium.org</dd>
<dt>Date</dt> <dd>2010-03-29 10:59:51 -0700 (Mon, 29 Mar 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>2010-03-29  Alexander Pavlov  &lt;apavlov@chromium.org&gt;

        Reviewed by Pavel Feldman.

        Web Inspector: Cover the Audits panel with tests
        https://bugs.webkit.org/show_bug.cgi?id=36613

        LayoutTests:
        * inspector/audits-panel-functional-expected.txt: Added.
        * inspector/audits-panel-functional.html: Added.
        * inspector/resources/audits-script1.js: Added.
        (foo1):
        * inspector/resources/audits-script2.js: Added.
        (foo2):
        * inspector/resources/audits-script3.js: Added.
        (foo3):

        WebCore:
        * English.lproj/localizedStrings.js:
        * inspector/front-end/AuditResultView.js:
        (WebInspector.AuditResultView):
        (WebInspector.AuditCategoryResultPane.ruleSorter):
        (WebInspector.AuditCategoryResultPane):
        * inspector/front-end/AuditRules.js:
        (WebInspector.AuditRules.GzipRule.prototype.doRun):
        (WebInspector.AuditRules.CombineExternalResourcesRule.prototype.doRun):
        (WebInspector.AuditRules.UnusedCssRule.prototype.doRun.evalCallback.selectorsCallback):
        (WebInspector.AuditRules.ImageDimensionsRule.prototype.doRun):
        (WebInspector.AuditRules.CssInHeadRule.prototype.doRun):
        (WebInspector.AuditRules.CookieSizeRule.prototype.processCookies):
        * inspector/front-end/AuditsPanel.js:
        (WebInspector.AuditRuleResult.linkifyDisplayName):
        (WebInspector.AuditRuleResult.resourceDomain):
        (WebInspector.AuditRuleResult.prototype.addURL):
        * inspector/front-end/inspector.js:
        (WebInspector.displayNameForURL):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkWebCoreChangeLog">trunk/WebCore/ChangeLog</a></li>
<li><a href="#trunkWebCoreEnglishlprojlocalizedStringsjs">trunk/WebCore/English.lproj/localizedStrings.js</a></li>
<li><a href="#trunkWebCoreinspectorfrontendAuditResultViewjs">trunk/WebCore/inspector/front-end/AuditResultView.js</a></li>
<li><a href="#trunkWebCoreinspectorfrontendAuditRulesjs">trunk/WebCore/inspector/front-end/AuditRules.js</a></li>
<li><a href="#trunkWebCoreinspectorfrontendAuditsPaneljs">trunk/WebCore/inspector/front-end/AuditsPanel.js</a></li>
<li><a href="#trunkWebCoreinspectorfrontendinspectorjs">trunk/WebCore/inspector/front-end/inspector.js</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (56731 => 56732)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2010-03-29 17:50:17 UTC (rev 56731)
+++ trunk/LayoutTests/ChangeLog        2010-03-29 17:59:51 UTC (rev 56732)
</span><span class="lines">@@ -2,6 +2,22 @@
</span><span class="cx"> 
</span><span class="cx">         Reviewed by Pavel Feldman.
</span><span class="cx"> 
</span><ins>+        Web Inspector: Cover the Audits panel with tests
+        https://bugs.webkit.org/show_bug.cgi?id=36613
+
+        * inspector/audits-panel-functional-expected.txt: Added.
+        * inspector/audits-panel-functional.html: Added.
+        * inspector/resources/audits-script1.js: Added.
+        (foo1):
+        * inspector/resources/audits-script2.js: Added.
+        (foo2):
+        * inspector/resources/audits-script3.js: Added.
+        (foo3):
+
+2010-03-29  Alexander Pavlov  &lt;apavlov@chromium.org&gt;
+
+        Reviewed by Pavel Feldman.
+
</ins><span class="cx">         Web Inspector should highlight when clicking a node's closing tag
</span><span class="cx">         https://bugs.webkit.org/show_bug.cgi?id=16258
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/WebCore/ChangeLog (56731 => 56732)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebCore/ChangeLog        2010-03-29 17:50:17 UTC (rev 56731)
+++ trunk/WebCore/ChangeLog        2010-03-29 17:59:51 UTC (rev 56732)
</span><span class="lines">@@ -1,3 +1,33 @@
</span><ins>+2010-03-29  Alexander Pavlov  &lt;apavlov@chromium.org&gt;
+
+        Reviewed by Pavel Feldman.
+
+        Web Inspector: Cover the Audits panel with tests
+        https://bugs.webkit.org/show_bug.cgi?id=36613
+
+        Sort results, add a few drive-by fixes and refactorings to improve testability.
+
+        Test: inspector/audits-panel-functional.html
+
+        * English.lproj/localizedStrings.js:
+        * inspector/front-end/AuditResultView.js:
+        (WebInspector.AuditResultView):
+        (WebInspector.AuditCategoryResultPane.ruleSorter):
+        (WebInspector.AuditCategoryResultPane):
+        * inspector/front-end/AuditRules.js:
+        (WebInspector.AuditRules.GzipRule.prototype.doRun):
+        (WebInspector.AuditRules.CombineExternalResourcesRule.prototype.doRun):
+        (WebInspector.AuditRules.UnusedCssRule.prototype.doRun.evalCallback.selectorsCallback):
+        (WebInspector.AuditRules.ImageDimensionsRule.prototype.doRun):
+        (WebInspector.AuditRules.CssInHeadRule.prototype.doRun):
+        (WebInspector.AuditRules.CookieSizeRule.prototype.processCookies):
+        * inspector/front-end/AuditsPanel.js:
+        (WebInspector.AuditRuleResult.linkifyDisplayName):
+        (WebInspector.AuditRuleResult.resourceDomain):
+        (WebInspector.AuditRuleResult.prototype.addURL):
+        * inspector/front-end/inspector.js:
+        (WebInspector.displayNameForURL):
+
</ins><span class="cx"> 2010-03-29  Jocelyn Turcotte  &lt;jocelyn.turcotte@nokia.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Reviewed by nobody, build fix.
</span></span></pre></div>
<a id="trunkWebCoreEnglishlprojlocalizedStringsjs"></a>
<div class="binary"><h4>Modified: trunk/WebCore/English.lproj/localizedStrings.js</h4>
<pre class="diff"><span>
<span class="cx">(Binary files differ)
</span></span></pre></div>
<a id="trunkWebCoreinspectorfrontendAuditResultViewjs"></a>
<div class="modfile"><h4>Modified: trunk/WebCore/inspector/front-end/AuditResultView.js (56731 => 56732)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebCore/inspector/front-end/AuditResultView.js        2010-03-29 17:50:17 UTC (rev 56731)
+++ trunk/WebCore/inspector/front-end/AuditResultView.js        2010-03-29 17:59:51 UTC (rev 56732)
</span><span class="lines">@@ -33,6 +33,10 @@
</span><span class="cx">     WebInspector.View.call(this);
</span><span class="cx">     this.element.className = &quot;audit-result-view&quot;;
</span><span class="cx"> 
</span><ins>+    function categorySorter(a, b) {
+        return (a.title || &quot;&quot;).localeCompare(b.title || &quot;&quot;);
+    }
+    categoryResults.sort(categorySorter);
</ins><span class="cx">     for (var i = 0; i &lt; categoryResults.length; ++i)
</span><span class="cx">         this.element.appendChild(new WebInspector.AuditCategoryResultPane(categoryResults[i]).element);
</span><span class="cx"> }
</span><span class="lines">@@ -49,6 +53,17 @@
</span><span class="cx"> 
</span><span class="cx">     this._treeOutline = new TreeOutline(treeOutlineElement);
</span><span class="cx">     this._treeOutline.expandTreeElementsWhenArrowing = true;
</span><ins>+
+    function ruleSorter(a, b)
+    {
+        var result = WebInspector.AuditRule.SeverityOrder[a.severity || 0] - WebInspector.AuditRule.SeverityOrder[b.severity || 0];
+        if (!result)
+            result = (a.value || &quot;&quot;).localeCompare(b.value || &quot;&quot;);
+        return result;
+    }
+
+    categoryResult.ruleResults.sort(ruleSorter);
+
</ins><span class="cx">     for (var i = 0; i &lt; categoryResult.ruleResults.length; ++i) {
</span><span class="cx">         var ruleResult = categoryResult.ruleResults[i];
</span><span class="cx">         var treeElement = this._appendResult(this._treeOutline, ruleResult);
</span></span></pre></div>
<a id="trunkWebCoreinspectorfrontendAuditRulesjs"></a>
<div class="modfile"><h4>Modified: trunk/WebCore/inspector/front-end/AuditRules.js (56731 => 56732)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebCore/inspector/front-end/AuditRules.js        2010-03-29 17:50:17 UTC (rev 56731)
+++ trunk/WebCore/inspector/front-end/AuditRules.js        2010-03-29 17:59:51 UTC (rev 56732)
</span><span class="lines">@@ -92,7 +92,7 @@
</span><span class="cx">                 }
</span><span class="cx">                 var savings = 2 * size / 3;
</span><span class="cx">                 totalSavings += savings;
</span><del>-                summary.addChild(String.sprintf(&quot;%s could save ~%s&quot;, WebInspector.linkifyURL(resource.url), Number.bytesToString(savings)));
</del><ins>+                summary.addChild(String.sprintf(&quot;%s could save ~%s&quot;, WebInspector.AuditRuleResult.linkifyDisplayName(resource.url), Number.bytesToString(savings)));
</ins><span class="cx">                 result.violationCount++;
</span><span class="cx">             }
</span><span class="cx">         }
</span><span class="lines">@@ -138,7 +138,7 @@
</span><span class="cx">             if (extraResourceCount &lt;= 0)
</span><span class="cx">                 continue;
</span><span class="cx">             penalizedResourceCount += extraResourceCount - 1;
</span><del>-            summary.addChild(String.sprintf(&quot;%d %s resources served from %s.&quot;, domainResources.length, this._resourceTypeName, domain));
</del><ins>+            summary.addChild(String.sprintf(&quot;%d %s resources served from %s.&quot;, domainResources.length, this._resourceTypeName, WebInspector.AuditRuleResult.resourceDomain(domain)));
</ins><span class="cx">             result.violationCount += domainResources.length;
</span><span class="cx">         }
</span><span class="cx">         if (!penalizedResourceCount)
</span><span class="lines">@@ -323,7 +323,7 @@
</span><span class="cx">                     if (!unusedRules.length)
</span><span class="cx">                         continue;
</span><span class="cx"> 
</span><del>-                    var url = styleSheet.href ? WebInspector.linkifyURL(styleSheet.href) : String.sprintf(&quot;Inline block #%d&quot;, ++inlineBlockOrdinal);
</del><ins>+                    var url = styleSheet.href ? WebInspector.AuditRuleResult.linkifyDisplayName(styleSheet.href) : String.sprintf(&quot;Inline block #%d&quot;, ++inlineBlockOrdinal);
</ins><span class="cx">                     var pctUnused = Math.round(100 * unusedStylesheetSize / stylesheetSize);
</span><span class="cx">                     if (!summary)
</span><span class="cx">                         summary = result.addChild(&quot;&quot;, true);
</span><span class="lines">@@ -628,7 +628,7 @@
</span><span class="cx">             var map = context.urlToNoDimensionCount;
</span><span class="cx">             for (var url in map) {
</span><span class="cx">                 var entry = entry || result.addChild(&quot;A width and height should be specified for all images in order to speed up page display. The following image(s) are missing a width and/or height:&quot;, true);
</span><del>-                var value = WebInspector.linkifyURL(url);
</del><ins>+                var value = WebInspector.AuditRuleResult.linkifyDisplayName(url);
</ins><span class="cx">                 if (map[url] &gt; 1)
</span><span class="cx">                     value += String.sprintf(&quot; (%d uses)&quot;, map[url]);
</span><span class="cx">                 entry.addChild(value);
</span><span class="lines">@@ -728,11 +728,13 @@
</span><span class="cx">             var outputMessages = [];
</span><span class="cx">             for (var url in evalResult) {
</span><span class="cx">                 var urlViolations = evalResult[url];
</span><del>-                if (urlViolations[0])
-                    result.addChild(String.sprintf(&quot;%s style block(s) in the %s body should be moved to the document head.&quot;, urlViolations[0], WebInspector.linkifyURL(url)));
</del><ins>+                if (urlViolations[0]) {
+                    result.addChild(String.sprintf(&quot;%s style block(s) in the %s body should be moved to the document head.&quot;, urlViolations[0], WebInspector.AuditRuleResult.linkifyDisplayName(url)));
+                    result.violationCount += urlViolations[0];
+                }
</ins><span class="cx">                 for (var i = 0; i &lt; urlViolations[1].length; ++i)
</span><del>-                    result.addChild(String.sprintf(&quot;Link node %s should be moved to the document head in %s&quot;, WebInspector.linkifyURL(urlViolations[1])), WebInspector.linkifyURL(url));
-                result.violationCount += urlViolations.length;
</del><ins>+                    result.addChild(String.sprintf(&quot;Link node %s should be moved to the document head in %s&quot;, WebInspector.AuditRuleResult.linkifyDisplayName(urlViolations[1])), WebInspector.AuditRuleResult.linkifyDisplayName(url));
+                result.violationCount += urlViolations[1].length;
</ins><span class="cx">             }
</span><span class="cx">             summary.value = String.sprintf(&quot;CSS in the document body adversely impacts rendering performance.&quot;);
</span><span class="cx">             callback(result);
</span><span class="lines">@@ -947,7 +949,7 @@
</span><span class="cx">         for (var i = 0, len = sortedCookieSizes.length; i &lt; len; ++i) {
</span><span class="cx">             var maxCookieSize = sortedCookieSizes[i].maxCookieSize;
</span><span class="cx">             if (maxCookieSize &gt; this._maxBytesThreshold)
</span><del>-                hugeCookieDomains.push(sortedCookieSizes[i].domain + &quot;: &quot; + Number.bytesToString(maxCookieSize));
</del><ins>+                hugeCookieDomains.push(WebInspector.AuditRuleResult.resourceDomain(sortedCookieSizes[i].domain) + &quot;: &quot; + Number.bytesToString(maxCookieSize));
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         var bigAvgCookieDomains = [];
</span><span class="lines">@@ -956,7 +958,7 @@
</span><span class="cx">             var domain = sortedCookieSizes[i].domain;
</span><span class="cx">             var avgCookieSize = sortedCookieSizes[i].avgCookieSize;
</span><span class="cx">             if (avgCookieSize &gt; this._avgBytesThreshold &amp;&amp; avgCookieSize &lt; this._maxBytesThreshold)
</span><del>-                bigAvgCookieDomains.push(domain + &quot;: &quot; + Number.bytesToString(avgCookieSize));
</del><ins>+                bigAvgCookieDomains.push(WebInspector.AuditRuleResult.resourceDomain(domain) + &quot;: &quot; + Number.bytesToString(avgCookieSize));
</ins><span class="cx">         }
</span><span class="cx">         result.addChild(String.sprintf(&quot;The average cookie size for all requests on this page is %s&quot;, Number.bytesToString(avgAllCookiesSize)));
</span><span class="cx"> 
</span><span class="lines">@@ -969,7 +971,7 @@
</span><span class="cx"> 
</span><span class="cx">         if (bigAvgCookieDomains.length) {
</span><span class="cx">             var entry = result.addChild(String.sprintf(&quot;The following domains have an average cookie size in excess of %d bytes. Reducing the size of cookies for these domains can reduce the time it takes to send requests.&quot;, this._avgBytesThreshold), true);
</span><del>-            entry.addURLs(bigAvgCookieDomains.length);
</del><ins>+            entry.addURLs(bigAvgCookieDomains);
</ins><span class="cx">             result.violationCount += bigAvgCookieDomains.length;
</span><span class="cx">         }
</span><span class="cx">     }
</span></span></pre></div>
<a id="trunkWebCoreinspectorfrontendAuditsPaneljs"></a>
<div class="modfile"><h4>Modified: trunk/WebCore/inspector/front-end/AuditsPanel.js (56731 => 56732)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebCore/inspector/front-end/AuditsPanel.js        2010-03-29 17:50:17 UTC (rev 56731)
+++ trunk/WebCore/inspector/front-end/AuditsPanel.js        2010-03-29 17:59:51 UTC (rev 56732)
</span><span class="lines">@@ -345,6 +345,12 @@
</span><span class="cx">     Severe: &quot;severe&quot;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+WebInspector.AuditRule.SeverityOrder = {
+    &quot;info&quot;: 3,
+    &quot;warning&quot;: 2,
+    &quot;severe&quot;: 1
+}
+
</ins><span class="cx"> WebInspector.AuditRule.prototype = {
</span><span class="cx">     get id()
</span><span class="cx">     {
</span><span class="lines">@@ -395,6 +401,16 @@
</span><span class="cx">     this.violationCount = 0;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+WebInspector.AuditRuleResult.linkifyDisplayName = function(url)
+{
+    return WebInspector.linkifyURL(url, WebInspector.displayNameForURL(url));
+}
+
+WebInspector.AuditRuleResult.resourceDomain = function(domain)
+{
+    return domain || WebInspector.UIString(&quot;[empty domain]&quot;);
+}
+
</ins><span class="cx"> WebInspector.AuditRuleResult.prototype = {
</span><span class="cx">     addChild: function(value, expanded, className)
</span><span class="cx">     {
</span><span class="lines">@@ -407,7 +423,7 @@
</span><span class="cx"> 
</span><span class="cx">     addURL: function(url)
</span><span class="cx">     {
</span><del>-        return this.addChild(WebInspector.linkifyURL(url));
</del><ins>+        return this.addChild(WebInspector.AuditRuleResult.linkifyDisplayName(url));
</ins><span class="cx">     },
</span><span class="cx"> 
</span><span class="cx">     addURLs: function(urls)
</span></span></pre></div>
<a id="trunkWebCoreinspectorfrontendinspectorjs"></a>
<div class="modfile"><h4>Modified: trunk/WebCore/inspector/front-end/inspector.js (56731 => 56732)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebCore/inspector/front-end/inspector.js        2010-03-29 17:50:17 UTC (rev 56731)
+++ trunk/WebCore/inspector/front-end/inspector.js        2010-03-29 17:59:51 UTC (rev 56732)
</span><span class="lines">@@ -1517,9 +1517,8 @@
</span><span class="cx">     var index = WebInspector.mainResource.url.indexOf(lastPathComponent);
</span><span class="cx">     if (index !== -1 &amp;&amp; index + lastPathComponent.length === WebInspector.mainResource.url.length) {
</span><span class="cx">         var baseURL = WebInspector.mainResource.url.substring(0, index);
</span><del>-        if (url.indexOf(baseURL) === 0) {
</del><ins>+        if (url.indexOf(baseURL) === 0)
</ins><span class="cx">             return url.substring(index);
</span><del>-        }
</del><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     return url.trimURL(WebInspector.mainResource.domain);
</span></span></pre>
</div>
</div>

</body>
</html>