2010-09-09 Andrey Kosyakov <caseq@chromium.org>
authorcaseq@chromium.org <caseq@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 9 Sep 2010 14:51:29 +0000 (14:51 +0000)
committercaseq@chromium.org <caseq@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 9 Sep 2010 14:51:29 +0000 (14:51 +0000)
        Reviewed by Yury Semikhatsky.

        Web Inspector: use string representation of resource type in extension API
        Fixed Resoruce.Type.toString() to handle Resource.Type.Media.
        https://bugs.webkit.org/show_bug.cgi?id=45286

        Test: inspector/extensions-resources.html

        * English.lproj/localizedStrings.js: Added "media".
        * inspector/front-end/ExtensionServer.js: Added webInspector.resources.Types. Return resource types as strings.
        (WebInspector.ExtensionServer.prototype._convertResource):
        (WebInspector.ExtensionServer.prototype._buildExtensionAPIInjectedScript):
        * inspector/front-end/Resource.js: Added toUIString(), changed toString() to return locale-independent representation.
        (WebInspector.Resource.Type.toUIString):
        (WebInspector.Resource.Type.toString):

2010-09-09  Andrey Kosyakov  <caseq@chromium.org>

        Reviewed by Yury Semikhatsky.

        Web Inspector: use string representation of resource type in extension API
        Split resource tests from the misc. extension API tests, added more resource types.
        https://bugs.webkit.org/show_bug.cgi?id=45286

        * inspector/extensions-api-expected.txt:
        * inspector/extensions-events-expected.txt:
        * inspector/extensions-expected.txt:
        * inspector/extensions-resources-expected.txt: Added.
        * inspector/extensions-resources.html: Added.
        * inspector/extensions.html:
        * inspector/resources/Ahem.ttf: Copied from LayoutTests/fast/css/resources/Ahem.ttf.
        * inspector/resources/abe.png: Copied from LayoutTests/editing/resources/abe.png.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@67084 268f45cc-cd09-0410-ab3c-d52691b4dbfc

13 files changed:
LayoutTests/ChangeLog
LayoutTests/inspector/extensions-api-expected.txt
LayoutTests/inspector/extensions-events-expected.txt
LayoutTests/inspector/extensions-expected.txt
LayoutTests/inspector/extensions-resources-expected.txt [new file with mode: 0644]
LayoutTests/inspector/extensions-resources.html [new file with mode: 0755]
LayoutTests/inspector/extensions.html
LayoutTests/inspector/resources/Ahem.ttf [new file with mode: 0755]
LayoutTests/inspector/resources/abe.png [new file with mode: 0755]
WebCore/ChangeLog
WebCore/English.lproj/localizedStrings.js
WebCore/inspector/front-end/ExtensionServer.js
WebCore/inspector/front-end/Resource.js

index c4e16f6..d038411 100644 (file)
@@ -1,3 +1,20 @@
+2010-09-09  Andrey Kosyakov  <caseq@chromium.org>
+
+        Reviewed by Yury Semikhatsky.
+
+        Web Inspector: use string representation of resource type in extension API
+        Split resource tests from the misc. extension API tests, added more resource types.
+        https://bugs.webkit.org/show_bug.cgi?id=45286
+
+        * inspector/extensions-api-expected.txt:
+        * inspector/extensions-events-expected.txt:
+        * inspector/extensions-expected.txt:
+        * inspector/extensions-resources-expected.txt: Added.
+        * inspector/extensions-resources.html: Added.
+        * inspector/extensions.html:
+        * inspector/resources/Ahem.ttf: Copied from LayoutTests/fast/css/resources/Ahem.ttf.
+        * inspector/resources/abe.png: Copied from LayoutTests/editing/resources/abe.png.
+
 2010-09-09  Pavel Podivilov  <podivilov@chromium.org>
 
         Reviewed by Yury Semikhatsky.
index a9fd2e6..3e66ab6 100644 (file)
@@ -46,6 +46,16 @@ RUNNING TEST: extension_testAPI
             addListener : <function>
             removeListener : <function>
         }
+        Types : {
+            Document : "document"
+            Stylesheet : "stylesheet"
+            Image : "image"
+            Font : "font"
+            Script : "script"
+            XHR : "XHR"
+            Media : "media"
+            Other : "other"
+        }
         getAll : <function>
         get : <function>
     }
index 6b1ba0a..e853630 100644 (file)
@@ -9,7 +9,7 @@ Got callback, arguments dump follows:
 {
     0 : {
         id : <number>
-        type : 7
+        type : "other"
         har : <object>
     }
 }
index a088f40..bd5a952 100644 (file)
@@ -23,13 +23,5 @@ Sidebar created
     setHeight : <function>
     setExpanded : <function>
 }
-RUNNING TEST: extension_testGetAllResources
-resource: .../tests/inspector/inspector-test2.js
-resource: .../LayoutTests/inspector/extensions-test.js
-resource: .../LayoutTests/inspector/extensions.html
-RUNNING TEST: extension_testGetInvalidResource
-Attempted to retrieve invalid resource: {"code":"E_NOTFOUND","description":"Object not found: %s","details":[2128506],"isError":true}
-RUNNING TEST: extension_testResourceNotification
-Resource finished: .../inspector/resources/extension-main.html
 All tests done.
 
diff --git a/LayoutTests/inspector/extensions-resources-expected.txt b/LayoutTests/inspector/extensions-resources-expected.txt
new file mode 100644 (file)
index 0000000..029cbb8
--- /dev/null
@@ -0,0 +1,21 @@
+Tests WebInspector extension API
+
+Page reloaded.
+Started extension.
+Running tests...
+RUNNING TEST: extension_testGetAllResources
+resource: .../tests/inspector/inspector-test2.js, type: script
+resource: .../LayoutTests/inspector/extensions-resources.html, type: document
+resource: .../LayoutTests/inspector/extensions-resources.html, type: XHR
+resource: .../LayoutTests/inspector/extensions-test.js, type: script
+resource: .../inspector/resources/abe.png, type: image
+resource: .../inspector/resources/Ahem.ttf, type: font
+resource: .../inspector/resources/audits-style1.css, type: stylesheet
+resource: .../inspector/resources/missing-image.png, type: other
+RUNNING TEST: extension_testGetInvalidResource
+Attempted to retrieve invalid resource: {"code":"E_NOTFOUND","description":"Object not found: %s","details":[2128506],"isError":true}
+RUNNING TEST: extension_testResourceNotification
+Resource finished: .../LayoutTests/inspector/extensions-resources.html
+All tests done.
+
diff --git a/LayoutTests/inspector/extensions-resources.html b/LayoutTests/inspector/extensions-resources.html
new file mode 100755 (executable)
index 0000000..094da40
--- /dev/null
@@ -0,0 +1,75 @@
+<html>
+<head>
+<link rel="stylesheet" href="resources/audits-style1.css" type="text/css">
+<style>
+@font-face {
+    font-family: 'test';
+    src: url(resources/Ahem.ttf);
+}
+
+p { font-family: 'test'; }
+</style>
+
+<script src="../http/tests/inspector/inspector-test2.js"></script>
+<script src="extensions-test.js"></script>
+<script type="text/javascript">
+
+function extension_testGetAllResources(nextTest)
+{
+    function compareResources(a, b)
+    {
+        return a.har.request.url.localeCompare(b.har.request.url);
+    }
+
+    function onResource(result)
+    {
+        var resources = result.sort(compareResources);
+
+        for (var i = 0; i < resources.length; ++i)
+            output("resource: " + resources[i].har.request.url.replace(/.*((\/[^/]*){3}$)/,"...$1") + ", type: " + resources[i].type);
+    }
+    extension_doXHR(function() {
+        webInspector.resources.getAll(callbackAndNextTest(onResource, nextTest));
+    });
+}
+
+function extension_testGetInvalidResource(nextTest)
+{
+    function onResource(result)
+    {
+        output("Attempted to retrieve invalid resource: " + JSON.stringify(result));
+    }
+    webInspector.resources.get(2128506, callbackAndNextTest(onResource, nextTest));
+}
+
+function doXHR()
+{
+    var xhr = new XMLHttpRequest();
+    xhr.open('GET', location.href, false);
+    xhr.send(null);
+}
+
+function extension_doXHR(callback)
+{
+    webInspector.inspectedWindow.evaluate("doXHR()", callback);
+}
+
+function extension_testResourceNotification(nextTest)
+{
+    function onResourceFinished(resource)
+    {
+        output("Resource finished: " + resource.har.request.url.replace(/.*((\/[^/]*){3}$)/,"...$1"));
+    }
+
+    webInspector.resources.onFinished.addListener(callbackAndNextTest(onResourceFinished, nextTest));
+    extension_doXHR();
+}
+
+</script>
+</head>
+<body onload="runTest()">
+<p>Tests WebInspector extension API</p>
+<img src="resources/abe.png">
+<img src="resources/missing-image.png">
+</body>
+</html>
index ef8996c..1b5412a 100644 (file)
@@ -4,34 +4,6 @@
 <script src="extensions-test.js"></script>
 <script type="text/javascript">
 
-window.inspectedValue = { str: "foo", num: 42 };
-
-function extension_testGetAllResources(nextTest)
-{
-    function compareResources(a, b)
-    {
-        return a.har.request.url.localeCompare(b.har.request.url);
-    }
-
-    function onResource(result)
-    {
-        var resources = result.sort(compareResources);
-
-        for (var i = 0; i < resources.length; ++i)
-            output("resource: " + resources[i].har.request.url.replace(/.*((\/[^/]*){3}$)/,"...$1"));
-    }
-    webInspector.resources.getAll(callbackAndNextTest(onResource, nextTest));
-}
-
-function extension_testGetInvalidResource(nextTest)
-{
-    function onResource(result)
-    {
-        output("Attempted to retrieve invalid resource: " + JSON.stringify(result));
-    }
-    webInspector.resources.get(2128506, callbackAndNextTest(onResource, nextTest));
-}
-
 function extension_testCreatePanel(nextTest)
 {
     function onPanelCreated(panel)
@@ -53,17 +25,6 @@ function extension_testCreateSidebar(nextTest)
     webInspector.panels.scripts.createSidebarPane("Test Sidebar", "extension-sidebar.html", callbackAndNextTest(onSidebarCreated, nextTest));
 }
 
-function extension_testResourceNotification(nextTest)
-{
-    function onResourceFinished(resource)
-    {
-        output("Resource finished: " + resource.har.request.url.replace(/.*((\/[^/]*){3}$)/,"...$1"));
-    }
-
-    webInspector.resources.onFinished.addListener(callbackAndNextTest(onResourceFinished, nextTest));
-    webInspector.inspectedWindow.evaluate("var xhr = new XMLHttpRequest(); xhr.open('GET', '" + location.href + "', false); xhr.send(null);");
-}
-
 </script>
 </head>
 <body onload="runTest()">
diff --git a/LayoutTests/inspector/resources/Ahem.ttf b/LayoutTests/inspector/resources/Ahem.ttf
new file mode 100755 (executable)
index 0000000..ac81cb0
Binary files /dev/null and b/LayoutTests/inspector/resources/Ahem.ttf differ
diff --git a/LayoutTests/inspector/resources/abe.png b/LayoutTests/inspector/resources/abe.png
new file mode 100755 (executable)
index 0000000..c932536
Binary files /dev/null and b/LayoutTests/inspector/resources/abe.png differ
index d152308..eadd80a 100644 (file)
@@ -1,3 +1,21 @@
+2010-09-09  Andrey Kosyakov  <caseq@chromium.org>
+
+        Reviewed by Yury Semikhatsky.
+
+        Web Inspector: use string representation of resource type in extension API
+        Fixed Resoruce.Type.toString() to handle Resource.Type.Media.
+        https://bugs.webkit.org/show_bug.cgi?id=45286
+
+        Test: inspector/extensions-resources.html
+
+        * English.lproj/localizedStrings.js: Added "media".
+        * inspector/front-end/ExtensionServer.js: Added webInspector.resources.Types. Return resource types as strings.
+        (WebInspector.ExtensionServer.prototype._convertResource):
+        (WebInspector.ExtensionServer.prototype._buildExtensionAPIInjectedScript):
+        * inspector/front-end/Resource.js: Added toUIString(), changed toString() to return locale-independent representation.
+        (WebInspector.Resource.Type.toUIString):
+        (WebInspector.Resource.Type.toString):
+
 2010-09-09  Kristian Amlie  <kristian.amlie@nokia.com>
 
         Reviewed by Andreas Kling.
index c26c15f..28cdf1a 100644 (file)
Binary files a/WebCore/English.lproj/localizedStrings.js and b/WebCore/English.lproj/localizedStrings.js differ
index f410d8c..bdf3a25 100644 (file)
@@ -103,7 +103,7 @@ WebInspector.ExtensionServer.prototype = {
     {
         return {
             id: resource.identifier,
-            type: resource.type,
+            type: WebInspector.Resource.Type.toString(resource.type),
             har: (new WebInspector.HAREntry(resource)).build(),
         };
     },
@@ -321,10 +321,20 @@ WebInspector.ExtensionServer.prototype = {
 
     _buildExtensionAPIInjectedScript: function()
     {
+        var resourceTypes = {};
+        var resourceTypeProperties = Object.getOwnPropertyNames(WebInspector.Resource.Type);
+        for (var i = 0; i < resourceTypeProperties.length; ++i) {
+             var propName = resourceTypeProperties[i];
+             var propValue = WebInspector.Resource.Type[propName];
+             if (typeof propValue === "number")
+                 resourceTypes[propName] = WebInspector.Resource.Type.toString(propValue);
+        }
+
         return "(function(){ " +
             "var private = {};" +
             "(" + WebInspector.commonExtensionSymbols.toString() + ")(private);" +
             "(" + WebInspector.injectedExtensionAPI.toString() + ").apply(this, arguments);" +
+            "webInspector.resources.Types = " + JSON.stringify(resourceTypes) + ";" +
             "})";
     },
 
index 06a610d..de87047 100644 (file)
@@ -52,24 +52,33 @@ WebInspector.Resource.Type = {
         return (type === this.Document) || (type === this.Stylesheet) || (type === this.Script) || (type === this.XHR);
     },
 
+    toUIString: function(type)
+    {
+        return WebInspector.UIString(WebInspector.Resource.Type.toString(type));
+    },
+
+    // Returns locale-independent string identifier of resource type (primarily for use in extension API).
+    // The IDs need to be kept in sync with webInspector.resoureces.Types object in ExtensionAPI.js.
     toString: function(type)
     {
         switch (type) {
             case this.Document:
-                return WebInspector.UIString("document");
+                return "document";
             case this.Stylesheet:
-                return WebInspector.UIString("stylesheet");
+                return "stylesheet";
             case this.Image:
-                return WebInspector.UIString("image");
+                return "image";
             case this.Font:
-                return WebInspector.UIString("font");
+                return "font";
             case this.Script:
-                return WebInspector.UIString("script");
+                return "script";
             case this.XHR:
-                return WebInspector.UIString("XHR");
+                return "XHR";
+            case this.Media:
+                return "media";
             case this.Other:
             default:
-                return WebInspector.UIString("other");
+                return "other";
         }
     }
 }
@@ -603,7 +612,7 @@ WebInspector.Resource.prototype = {
                         this.url,
                         null,
                         1,
-                        String.sprintf(WebInspector.Warnings.IncorrectMIMEType.message, WebInspector.Resource.Type.toString(this.type), this.mimeType),
+                        String.sprintf(WebInspector.Warnings.IncorrectMIMEType.message, WebInspector.Resource.Type.toUIString(this.type), this.mimeType),
                         null,
                         null);
                 break;