Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: third_party/WebKit/LayoutTests/http/tests/inspector-protocol/inspector-protocol-test.js

Issue 2942573003: [DevTools] New harness for inspector-protocol layout tests (Closed)
Patch Set: Protocol -> dp Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2012 Samsung Electronics. All rights reserved.
3 * Copyright (C) 2013 Google Inc. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
19 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27 var initialize_InspectorTest = function() {
28
29 InspectorTest.evaluateInInspectedPage = function(expression, callback)
30 {
31 InspectorTest.sendCommand("Runtime.evaluate", { expression: expression }, ca llback);
32 }
33
34 InspectorTest.parseURL = function(url)
35 {
36 var result = {};
37 var match = url.match(/^([^:]+):\/\/([^\/:]*)(?::([\d]+))?(?:(\/[^#]*)(?:#(. *))?)?$/i);
38 if (!match)
39 return result;
40 result.scheme = match[1].toLowerCase();
41 result.host = match[2];
42 result.port = match[3];
43 result.path = match[4] || "/";
44 result.fragment = match[5];
45 return result;
46 }
47
48 }
49
50 var outputElement;
51
52 /**
53 * Logs message to process stdout via alert (hopefully implemented with immediat e flush).
54 * @param {string} text
55 */
56 function debugLog(text)
57 {
58 alert(text);
59 }
60
61 /**
62 * @param {string} text
63 */
64 function log(text)
65 {
66 if (!outputElement) {
67 var intermediate = document.createElement("div");
68 document.body.appendChild(intermediate);
69
70 var intermediate2 = document.createElement("div");
71 intermediate.appendChild(intermediate2);
72
73 outputElement = document.createElement("div");
74 outputElement.className = "output";
75 outputElement.id = "output";
76 outputElement.style.whiteSpace = "pre";
77 intermediate2.appendChild(outputElement);
78 }
79 outputElement.appendChild(document.createTextNode(text));
80 outputElement.appendChild(document.createElement("br"));
81 }
82
83 function closeTest()
84 {
85 closeInspector();
86 testRunner.notifyDone();
87 }
88
89 var reloadParam = "__protocol__test__reload__";
90
91 function runTest()
92 {
93 if (!window.testRunner) {
94 console.error("This test requires DumpRenderTree");
95 return;
96 }
97
98 var reloadIndex = window.location.href.lastIndexOf(reloadParam);
99 if (reloadIndex !== -1) {
100 var lastId = window.location.href.substring(reloadIndex + reloadParam.le ngth);
101 window.lastFrontendEvalId = parseInt(lastId, 10);
102 evaluateInFrontend("InspectorTest.pageReloaded();");
103 return;
104 }
105
106 testRunner.dumpAsText();
107 testRunner.waitUntilDone();
108 testRunner.setCanOpenWindows(true);
109
110 openInspector();
111 }
112
113 function closeInspector()
114 {
115 testRunner.closeWebInspector();
116 }
117
118 var lastFrontendEvalId = 0;
119 function evaluateInFrontend(script)
120 {
121 testRunner.evaluateInWebInspector(++lastFrontendEvalId, script);
122 }
123
124 function navigateProtocolTest(url)
125 {
126 url += (url.indexOf("?") === -1 ? "?" : "&") + reloadParam + lastFrontendEva lId;
127 window.location.replace(url);
128 }
129
130 function prepareForReload()
131 {
132 window.location += "#" + reloadParam + lastFrontendEvalId;
133 }
134
135 function openInspector()
136 {
137 var scriptTags = document.getElementsByTagName("script");
138 var scriptUrlBasePath = "";
139 for (var i = 0; i < scriptTags.length; ++i) {
140 var index = scriptTags[i].src.lastIndexOf("/inspector-protocol-test.js") ;
141 if (index > -1 ) {
142 scriptUrlBasePath = scriptTags[i].src.slice(0, index);
143 break;
144 }
145 }
146
147 var dummyFrontendURL = scriptUrlBasePath + "/resources/protocol-test.html";
148 testRunner.showWebInspector("", dummyFrontendURL);
149 // FIXME: rename this 'test' global field across all tests.
150 var testFunction = window.test;
151 if (typeof testFunction === "function") {
152 var initializers = "";
153 for (var symbol in window) {
154 if (!/^initialize_/.test(symbol) || typeof window[symbol] !== "funct ion")
155 continue;
156 initializers += "(" + window[symbol].toString() + ")();\n";
157 }
158 evaluateInFrontend(initializers + "(" + testFunction.toString() +")();") ;
159 return;
160 }
161 // Kill waiting process if failed to send.
162 alert("Failed to send test function");
163 testRunner.notifyDone();
164 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698