Changeset 157938 in webkit


Ignore:
Timestamp:
Oct 24, 2013 10:08:23 AM (10 years ago)
Author:
Alexandru Chiculita
Message:

Web Inspector: Add a way to test the Manager and model classes
https://bugs.webkit.org/show_bug.cgi?id=123223

Reviewed by Timothy Hatcher.

Source/WebInspectorUI:

Moved some global functions out of Main.js, so that they can be used in the
layout tests without including Main.js.

  • UserInterface/Main.html: Referenced the new JS files.
  • UserInterface/Main.js:
  • UserInterface/MessageDispatcher.js: Added.

(WebInspector.dispatchNextQueuedMessageFromBackend):
(WebInspector.dispatchMessageFromBackend):

  • UserInterface/URLUtilities.js: Added.

(removeURLFragment):
(relativePath):
(parseURL):
(absoluteURL):
(parseLocationQueryParameters):
(parseQueryString):
(WebInspector.displayNameForURL):
(WebInspector.displayNameForHost):

  • UserInterface/Utilities.js:

LayoutTests:

Added the first new WebInspector layout test file. The test is using InspectorTest.importInspectorScripts
to bootstrap some of the managers/observers/models from the new WebInspector.

  • http/tests/inspector-protocol/resources/InspectorTest.js:

(InspectorTest.importScript):
(InspectorTest.importInspectorScripts):

  • inspector-protocol/model/main-frame-resource-expected.txt: Added.
  • inspector-protocol/model/main-frame-resource.html: Added.
Location:
trunk
Files:
5 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r157935 r157938  
     12013-10-24  Alexandru Chiculita  <achicu@adobe.com>
     2
     3        Web Inspector: Add a way to test the Manager and model classes
     4        https://bugs.webkit.org/show_bug.cgi?id=123223
     5
     6        Reviewed by Timothy Hatcher.
     7
     8        Added the first new WebInspector layout test file. The test is using InspectorTest.importInspectorScripts
     9        to bootstrap some of the managers/observers/models from the new WebInspector.
     10
     11        * http/tests/inspector-protocol/resources/InspectorTest.js:
     12        (InspectorTest.importScript):
     13        (InspectorTest.importInspectorScripts):
     14        * inspector-protocol/model/main-frame-resource-expected.txt: Added.
     15        * inspector-protocol/model/main-frame-resource.html: Added.
     16
    1172013-10-24  Alexey Proskuryakov  <ap@apple.com>
    218
  • trunk/LayoutTests/http/tests/inspector-protocol/resources/InspectorTest.js

    r154910 r157938  
    107107    xhr.open("GET", scriptName, false);
    108108    xhr.send(null);
    109     window.eval(xhr.responseText);
     109    if (xhr.status !== 0 && xhr.status !== 200)
     110        throw new Error("Invalid script URL: " + scriptName);
     111    var script = "try { " + xhr.responseText + "} catch (e) { alert(" + JSON.stringify("Error in: " + scriptName) + "); throw e; }";
     112    window.eval(script);
    110113}
     114
     115InspectorTest.importInspectorScripts = function()
     116{
     117    // Note: This function overwrites the InspectorFrontendAPI, so there's currently no
     118    // way to intercept the messages from the backend.
     119
     120    var inspectorScripts = [
     121        "Utilities",
     122        "WebInspector",
     123        "Object",
     124        "InspectorBackend",
     125        "InspectorFrontendAPI",
     126        "InspectorFrontendHostStub",
     127        "InspectorBackendCommands",
     128        "URLUtilities",
     129        "MessageDispatcher",
     130        "Setting",
     131        "PageObserver",
     132        "DOMObserver",
     133        "FrameResourceManager",
     134        "RuntimeManager",
     135        "Frame",
     136        "Revision",
     137        "SourceCodeRevision",
     138        "SourceCode",
     139        "Resource",
     140        "ResourceCollection",
     141        "DOMTreeManager",
     142        "DOMNode",
     143        "ContentFlow",
     144        "DOMTree",
     145        "ExecutionContext",
     146        "ExecutionContextList"
     147    ];
     148    for (var i = 0; i < inspectorScripts.length; ++i)
     149        InspectorTest.importScript("../../../../../Source/WebInspectorUI/UserInterface/" + inspectorScripts[i] + ".js");
     150
     151    // The initialization should be in sync with WebInspector.loaded in Main.js.
     152    // FIXME: As soon as we can support all the observers and managers we should remove UI related tasks
     153    // from WebInspector.loaded, so that it can be used from the LayoutTests.
     154
     155    InspectorBackend.registerPageDispatcher(new WebInspector.PageObserver);
     156    InspectorBackend.registerDOMDispatcher(new WebInspector.DOMObserver);
     157
     158    WebInspector.frameResourceManager = new WebInspector.FrameResourceManager;
     159    WebInspector.domTreeManager = new WebInspector.DOMTreeManager;
     160
     161    InspectorFrontendHost.loaded();
     162}
     163
    111164
    112165window.addEventListener("message", function(event) {
  • trunk/Source/WebInspectorUI/ChangeLog

    r157762 r157938  
     12013-10-24  Alexandru Chiculita  <achicu@adobe.com>
     2
     3        Web Inspector: Add a way to test the Manager and model classes
     4        https://bugs.webkit.org/show_bug.cgi?id=123223
     5
     6        Reviewed by Timothy Hatcher.
     7
     8        Moved some global functions out of Main.js, so that they can be used in the
     9        layout tests without including Main.js.
     10
     11        * UserInterface/Main.html: Referenced the new JS files.
     12        * UserInterface/Main.js:
     13        * UserInterface/MessageDispatcher.js: Added.
     14        (WebInspector.dispatchNextQueuedMessageFromBackend):
     15        (WebInspector.dispatchMessageFromBackend):
     16        * UserInterface/URLUtilities.js: Added.
     17        (removeURLFragment):
     18        (relativePath):
     19        (parseURL):
     20        (absoluteURL):
     21        (parseLocationQueryParameters):
     22        (parseQueryString):
     23        (WebInspector.displayNameForURL):
     24        (WebInspector.displayNameForHost):
     25        * UserInterface/Utilities.js:
     26
    1272013-10-21  Alexandru Chiculita  <achicu@adobe.com>
    228
  • trunk/Source/WebInspectorUI/UserInterface/Main.html

    r157649 r157938  
    144144    <script src="Utilities.js"></script>
    145145    <script src="WebInspector.js"></script>
     146    <script src="URLUtilities.js"></script>
     147    <script src="MessageDispatcher.js"></script>
    146148    <script src="Object.js"></script>
    147149    <script src="CodeMirrorDragToAlterNumberController.js"></script>
  • trunk/Source/WebInspectorUI/UserInterface/Main.js

    r157600 r157938  
    312312}
    313313
    314 WebInspector.messagesToDispatch = [];
    315 
    316 WebInspector.dispatchNextQueuedMessageFromBackend = function()
    317 {
    318     for (var i = 0; i < this.messagesToDispatch.length; ++i)
    319         InspectorBackend.dispatch(this.messagesToDispatch[i]);
    320 
    321     this.messagesToDispatch = [];
    322 
    323     this._dispatchTimeout = null;
    324 }
    325 
    326 WebInspector.dispatchMessageFromBackend = function(message)
    327 {
    328     // Enforce asynchronous interaction between the backend and the frontend by queueing messages.
    329     // The messages are dequeued on a zero delay timeout.
    330 
    331     this.messagesToDispatch.push(message);
    332 
    333     if (this._dispatchTimeout)
    334         return;
    335 
    336     this._dispatchTimeout = setTimeout(this.dispatchNextQueuedMessageFromBackend.bind(this), 0);
    337 }
    338 
    339314WebInspector.sidebarPanelForCurrentContentView = function()
    340315{
     
    377352        return sidebarPanel.treeElementForRepresentedObject(representedObject);
    378353    return null;
    379 }
    380 
    381 WebInspector.displayNameForURL = function(url, urlComponents)
    382 {
    383     if (!urlComponents)
    384         urlComponents = parseURL(url);
    385 
    386     var displayName;
    387     try {
    388         displayName = decodeURIComponent(urlComponents.lastPathComponent || "");
    389     } catch (e) {
    390         displayName = urlComponents.lastPathComponent;
    391     }
    392 
    393     return displayName || WebInspector.displayNameForHost(urlComponents.host) || url;
    394 }
    395 
    396 WebInspector.displayNameForHost = function(host)
    397 {
    398     // FIXME <rdar://problem/11237413>: This should decode punycode hostnames.
    399     return host;
    400354}
    401355
  • trunk/Source/WebInspectorUI/UserInterface/Utilities.js

    r156765 r157938  
    982982}
    983983
    984 function removeURLFragment(url)
    985 {
    986     var hashIndex = url.indexOf("#");
    987     if (hashIndex >= 0)
    988         return url.substring(0, hashIndex);
    989     return url;
    990 }
    991 
    992 function relativePath(path, basePath)
    993 {
    994     console.assert(path.charAt(0) === "/");
    995     console.assert(basePath.charAt(0) === "/");
    996    
    997     var pathComponents = path.split("/");
    998     var baseComponents = basePath.replace(/\/$/, "").split("/");
    999     var finalComponents = [];
    1000 
    1001     var index = 1;
    1002     for (; index < pathComponents.length && index < baseComponents.length; ++index) {
    1003         if (pathComponents[index] !== baseComponents[index])
    1004             break;
    1005     }
    1006 
    1007     for (var i = index; i < baseComponents.length; ++i)
    1008         finalComponents.push("..");
    1009 
    1010     for (var i = index; i < pathComponents.length; ++i)
    1011         finalComponents.push(pathComponents[i]);
    1012 
    1013     return finalComponents.join("/");
    1014 }
    1015 
    1016984function resolveDotsInPath(path)
    1017985{
     
    10481016}
    10491017
    1050 function parseURL(url)
    1051 {
    1052     url = url ? url.trim() : "";
    1053 
    1054     var match = url.match(/^([^:]+):\/\/([^\/:]*)(?::([\d]+))?(?:(\/[^#]*)(?:#(.*))?)?$/i);
    1055     if (!match)
    1056         return {scheme: null, host: null, port: null, path: null, queryString: null, fragment: null, lastPathComponent: null};
    1057 
    1058     var scheme = match[1].toLowerCase();
    1059     var host = match[2].toLowerCase();
    1060     var port = Number(match[3]) || null;
    1061     var wholePath = match[4] || null;
    1062     var fragment = match[5] || null;
    1063     var path = wholePath;
    1064     var queryString = null;
    1065 
    1066     // Split the path and the query string.
    1067     if (wholePath) {
    1068         var indexOfQuery = wholePath.indexOf("?");
    1069         if (indexOfQuery !== -1) {
    1070             path = wholePath.substring(0, indexOfQuery);
    1071             queryString = wholePath.substring(indexOfQuery + 1);
    1072         }
    1073         path = resolveDotsInPath(path);
    1074     }
    1075 
    1076     // Find last path component.
    1077     var lastPathComponent = null;
    1078     if (path && path !== "/") {
    1079         // Skip the trailing slash if there is one.
    1080         var endOffset = path[path.length - 1] === "/" ? 1 : 0;
    1081         var lastSlashIndex = path.lastIndexOf("/", path.length - 1 - endOffset);
    1082         if (lastSlashIndex !== -1)
    1083             lastPathComponent = path.substring(lastSlashIndex + 1, path.length - endOffset);
    1084     }
    1085 
    1086     return {scheme: scheme, host: host, port: port, path: path, queryString: queryString, fragment: fragment, lastPathComponent: lastPathComponent};
    1087 }
    1088 
    1089 function absoluteURL(partialURL, baseURL)
    1090 {
    1091     partialURL = partialURL ? partialURL.trim() : "";
    1092 
    1093     // Return data and javascript URLs as-is.
    1094     if (partialURL.startsWith("data:") || partialURL.startsWith("javascript:") || partialURL.startsWith("mailto:"))
    1095         return partialURL;
    1096 
    1097     // If the URL has a scheme it is already a full URL, so return it.
    1098     if (parseURL(partialURL).scheme)
    1099         return partialURL;
    1100 
    1101     // If there is no partial URL, just return the base URL.
    1102     if (!partialURL)
    1103         return baseURL || null;
    1104 
    1105     var baseURLComponents = parseURL(baseURL);
    1106 
    1107     // The base URL needs to be an absolute URL. Return null if it isn't.
    1108     if (!baseURLComponents.scheme)
    1109         return null;
    1110 
    1111     // A URL that starts with "//" is a full URL without the scheme. Use the base URL scheme.
    1112     if (partialURL[0] === "/" && partialURL[1] === "/")
    1113         return baseURLComponents.scheme + ":" + partialURL;
    1114 
    1115     // The path can be null for URLs that have just a scheme and host (like "http://apple.com"). So make the path be "/".
    1116     if (!baseURLComponents.path)
    1117         baseURLComponents.path = "/";
    1118 
    1119     // Generate the base URL prefix that is used in the rest of the cases.
    1120     var baseURLPrefix = baseURLComponents.scheme + "://" + baseURLComponents.host + (baseURLComponents.port ? (":" + baseURLComponents.port) : "");
    1121 
    1122     // A URL that starts with "?" is just a query string that gets applied to the base URL (replacing the base URL query string and fragment).
    1123     if (partialURL[0] === "?")
    1124         return baseURLPrefix + baseURLComponents.path + partialURL;
    1125 
    1126     // A URL that starts with "/" is an absolute path that gets applied to the base URL (replacing the base URL path, query string and fragment).
    1127     if (partialURL[0] === "/")
    1128         return baseURLPrefix + resolveDotsInPath(partialURL);
    1129 
    1130     // Generate the base path that is used in the final case by removing everything after the last "/" from the base URL's path.
    1131     var basePath = baseURLComponents.path.substring(0, baseURLComponents.path.lastIndexOf("/")) + "/";
    1132     return baseURLPrefix + resolveDotsInPath(basePath + partialURL);
    1133 }
    1134 
    11351018function parseMIMEType(fullMimeType)
    11361019{
     
    11911074    return new RegExp(regexString, regExpFlags);
    11921075}
    1193 
    1194 function parseLocationQueryParameters(arrayResult)
    1195 {
    1196     // The first character is always the "?".
    1197     return parseQueryString(window.location.search.substring(1), arrayResult);
    1198 }
    1199 
    1200 function parseQueryString(queryString, arrayResult)
    1201 {
    1202     if (!queryString)
    1203         return arrayResult ? [] : {};
    1204 
    1205     function decode(string)
    1206     {
    1207         try {
    1208             // Replace "+" with " " then decode precent encoded values.
    1209             return decodeURIComponent(string.replace(/\+/g, " "));
    1210         } catch (e) {
    1211             return string;
    1212         }
    1213     }
    1214 
    1215     var parameters = arrayResult ? [] : {};
    1216     var parameterStrings = queryString.split("&");
    1217     for (var i = 0; i < parameterStrings.length; ++i) {
    1218         var pair = parameterStrings[i].split("=").map(decode);
    1219         if (arrayResult)
    1220             parameters.push({name: pair[0], value: pair[1]});
    1221         else
    1222             parameters[pair[0]] = pair[1];
    1223     }
    1224 
    1225     return parameters;
    1226 }
Note: See TracChangeset for help on using the changeset viewer.