Web Inspector: model tests should use a special Test.html inspector page
authorbburg@apple.com <bburg@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 27 Feb 2014 22:08:10 +0000 (22:08 +0000)
committerbburg@apple.com <bburg@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 27 Feb 2014 22:08:10 +0000 (22:08 +0000)
https://bugs.webkit.org/show_bug.cgi?id=129190

Reviewed by Timothy Hatcher.

Source/WebCore:

Convert InspectorController::isUnderTest() into a flag, and expose an
Internals method so it can be set by the test before opening the inspector.

Test: inspector/test-harness-trivially-works.html

* inspector/InspectorController.cpp:
(WebCore::InspectorController::evaluateForTestInFrontend):
* inspector/InspectorController.h:
* testing/Internals.cpp:
(WebCore::Internals::setInspectorIsUnderTest): Added.
* testing/Internals.h:
* testing/Internals.idl:

Source/WebInspectorUI:

* UserInterface/Base/Test.js: Added.
(WebInspector.loaded):
(WebInspector.contentLoaded):
(WebInspector.updateDockedState):
(InspectorTest.log):
(InspectorTest.assert):
(InspectorTest.debugLog):
(InspectorTest.completeTest):
(InspectorTest.evaluateInPage):
(InspectorTest.addResult):
(InspectorTest.clearResults):
(InspectorTest.pageLoaded):
(InspectorTest.reportUncaughtException):
(.console.logType):
* UserInterface/Protocol/InspectorBackend.js:
(InspectorBackendClass):
(InspectorBackendClass.prototype.dispatch):
(InspectorBackendClass.prototype.runAfterPendingDispatches):
(InspectorBackendClass.prototype._flushPendingScripts):
* UserInterface/Protocol/InspectorObserver.js:
(WebInspector.InspectorObserver.prototype.evaluateForTestInFrontend):
* UserInterface/Test.html: Added.

Source/WebKit/mac:

Support creating a separate test inspector page, based on the value of
InspectorController::isUnderTest(). Modify the navigation policy to check
the URL against both normal and test inspector pages.

* WebCoreSupport/WebInspectorClient.mm:
(WebInspectorClient::openInspectorFrontend):
(-[WebInspectorWindowController init]):
(-[WebInspectorWindowController initWithInspectedWebView:isUnderTest:]):
Move the initial navigation of the inspector page to this method, and change
the URL based on the value of InspectorController::isUnderTest().

(-[WebInspectorWindowController inspectorTestPagePath]): Added.
(-[WebInspectorWindowController webView:decidePolicyForNavigationAction:request:frame:decisionListener:]):

Source/WebKit2:

Support creating a separate test inspector page, based on the value of
InspectorController::isUnderTest(). Add this as a separate API call for
WebInspectorProxy. Modify the navigation policy to check the URL against
both normal and test inspector pages.

* UIProcess/WebInspectorProxy.cpp:
(WebKit::isMainOrTestInspectorPage):
(WebKit::decidePolicyForNavigationAction):
(WebKit::WebInspectorProxy::createInspectorPageForTest):
* UIProcess/WebInspectorProxy.h:
* UIProcess/WebInspectorProxy.messages.in:
* UIProcess/efl/WebInspectorProxyEfl.cpp:
(WebKit::WebInspectorProxy::inspectorTestPageURL):
* UIProcess/gtk/WebInspectorProxyGtk.cpp:
(WebKit::WebInspectorProxy::inspectorTestPageURL):
* UIProcess/ios/WebInspectorProxyIOS.mm:
(WebKit::WebInspectorProxy::inspectorTestPageURL):
* UIProcess/mac/WebInspectorProxyMac.mm:
(WebKit::WebInspectorProxy::inspectorTestPageURL):
* WebProcess/WebCoreSupport/WebInspectorClient.cpp:
(WebKit::WebInspectorClient::openInspectorFrontend):
* WebProcess/WebPage/WebInspector.cpp: Some drive-by nullptr refactorings.
(WebKit::WebInspector::WebInspector):
(WebKit::WebInspector::createInspectorPage):
(WebKit::WebInspector::createInspectorPageForTest):
(WebKit::WebInspector::destroyInspectorPage):
* WebProcess/WebPage/WebInspector.h:

Tools:

Remove code that immediately opens the Web Inspector based on the file path of the test.
Instead, the test page should request that the inspector open inside its `test()` method.

This change is necessary because otherwise, the inspector would be opened too early for
InspectorController::isUnderTest to get set in time, so the normal Web Inspector page
will get loaded instead of the minimal test page.

* DumpRenderTree/efl/DumpRenderTree.cpp:
(createTestRunner):
* DumpRenderTree/gtk/DumpRenderTree.cpp:
(runTest):
* DumpRenderTree/mac/DumpRenderTree.mm:
(runTest):
* DumpRenderTree/win/DumpRenderTree.cpp:
(runTest):

LayoutTests:

Add a stripped-down version of the inspector test script that's used by
all inspector model tests. Clean up the namespaces so things accessible
from only the test page are part of the `InspectorTestProxy` object.

Add a minimal test that exercises the initialization and communication code
paths on the test page and the inspector page.

* http/tests/inspector-protocol/resources/InspectorTest.js: Add a FIXME.
* inspector/inspector-test.js: Added.
(InspectorTestProxy.register):
(runTest.initializeFrontend):
(runTest.runTestInFrontend):
(runTest):
(InspectorTestProxy.completeTest):
(InspectorTestProxy.debugLog):
(InspectorTestProxy.addResult):
(InspectorTestProxy.clearResults):
(InspectorTestProxy.reportUncaughtException):
* inspector/test-harness-trivially-works-expected.txt: Added.
* inspector/test-harness-trivially-works.html: Added.

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

34 files changed:
LayoutTests/ChangeLog
LayoutTests/http/tests/inspector-protocol/resources/InspectorTest.js
LayoutTests/inspector/inspector-test.js [new file with mode: 0644]
LayoutTests/inspector/test-harness-trivially-works-expected.txt [new file with mode: 0644]
LayoutTests/inspector/test-harness-trivially-works.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/inspector/InspectorController.cpp
Source/WebCore/inspector/InspectorController.h
Source/WebCore/testing/Internals.cpp
Source/WebCore/testing/Internals.h
Source/WebCore/testing/Internals.idl
Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Base/Test.js [new file with mode: 0644]
Source/WebInspectorUI/UserInterface/Protocol/InspectorBackend.js
Source/WebInspectorUI/UserInterface/Protocol/InspectorObserver.js
Source/WebInspectorUI/UserInterface/Test.html [new file with mode: 0644]
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/WebCoreSupport/WebInspectorClient.mm
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/WebInspectorProxy.cpp
Source/WebKit2/UIProcess/WebInspectorProxy.h
Source/WebKit2/UIProcess/WebInspectorProxy.messages.in
Source/WebKit2/UIProcess/efl/WebInspectorProxyEfl.cpp
Source/WebKit2/UIProcess/gtk/WebInspectorProxyGtk.cpp
Source/WebKit2/UIProcess/ios/WebInspectorProxyIOS.mm
Source/WebKit2/UIProcess/mac/WebInspectorProxyMac.mm
Source/WebKit2/WebProcess/WebCoreSupport/WebInspectorClient.cpp
Source/WebKit2/WebProcess/WebPage/WebInspector.cpp
Source/WebKit2/WebProcess/WebPage/WebInspector.h
Tools/ChangeLog
Tools/DumpRenderTree/efl/DumpRenderTree.cpp
Tools/DumpRenderTree/gtk/DumpRenderTree.cpp
Tools/DumpRenderTree/mac/DumpRenderTree.mm
Tools/DumpRenderTree/win/DumpRenderTree.cpp

index 4c7c31d..2e5004e 100644 (file)
@@ -1,3 +1,31 @@
+2014-02-27  Brian Burg  <bburg@apple.com>
+
+        Web Inspector: model tests should use a special Test.html inspector page
+        https://bugs.webkit.org/show_bug.cgi?id=129190
+
+        Reviewed by Timothy Hatcher.
+
+        Add a stripped-down version of the inspector test script that's used by
+        all inspector model tests. Clean up the namespaces so things accessible
+        from only the test page are part of the `InspectorTestProxy` object.
+
+        Add a minimal test that exercises the initialization and communication code
+        paths on the test page and the inspector page.
+
+        * http/tests/inspector-protocol/resources/InspectorTest.js: Add a FIXME.
+        * inspector/inspector-test.js: Added.
+        (InspectorTestProxy.register):
+        (runTest.initializeFrontend):
+        (runTest.runTestInFrontend):
+        (runTest):
+        (InspectorTestProxy.completeTest):
+        (InspectorTestProxy.debugLog):
+        (InspectorTestProxy.addResult):
+        (InspectorTestProxy.clearResults):
+        (InspectorTestProxy.reportUncaughtException):
+        * inspector/test-harness-trivially-works-expected.txt: Added.
+        * inspector/test-harness-trivially-works.html: Added.
+
 2014-02-27  Dirk Schulze  <krit@webkit.org>
 
         Transform more clip-path pixel tests to reference tests
index f124ebf..c390705 100644 (file)
@@ -158,6 +158,8 @@ InspectorTest.importScript = function(scriptName)
     window.eval(script);
 }
 
+// FIXME: Move model tests off of the stub inspector page, and delete this function
+// since it's now implemented as Test.html. <https://webkit.org/b/129217>
 InspectorTest.initializeInspectorModels = function()
 {
     // Catch any errors and finish the test early.
diff --git a/LayoutTests/inspector/inspector-test.js b/LayoutTests/inspector/inspector-test.js
new file mode 100644 (file)
index 0000000..d14d4a6
--- /dev/null
@@ -0,0 +1,137 @@
+/*
+ * Copyright (C) 2013, 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+// This namespace is injected into every test page. Its functions are invoked by
+// InspectorTest methods on the inspector page via RuntimeAgent.evaluate() calls.
+InspectorTestProxy = {};
+InspectorTestProxy._initializers = [];
+
+// Helper scripts like `debugger-test.js` must register their initialization
+// function with this method so it will be marshalled to the inspector page.
+InspectorTestProxy.register = function(initializer)
+{
+    if (typeof initializer === "function")
+        this._initializers.push(initializer.toString());
+}
+
+// This function is called by the test document's body onload handler.
+
+// It initializes the inspector and loads any `*-test.js` helper scripts
+// into the inspector page context.
+function runTest()
+{
+    // Set up the test page before the load event fires.
+    testRunner.dumpAsText();
+    testRunner.waitUntilDone();
+
+    if (window.internals)
+        internals.setInspectorIsUnderTest(true);
+    testRunner.showWebInspector();
+
+    // This function runs the initializer functions in the Inspector page.
+    function initializeFrontend(initializersArray)
+    {
+        for (var initializer of initializersArray) {
+            try {
+                initializer();
+            } catch (e) {
+                console.error("Exception in test initialization: " + e, e.stack || "(no stack trace)");
+                InspectorTest.completeTest();
+            }
+        }
+    }
+
+    // This function runs the test() method in the Inspector page.
+    function runTestInFrontend(testFunction)
+    {
+        try {
+            testFunction();
+        } catch (e) {
+            console.error("Exception during test execution: " + e, e.stack || "(no stack trace)");
+            InspectorTest.completeTest();
+        }
+    }
+
+    var codeStringToEvaluate = "(" + initializeFrontend.toString() + ")([" + InspectorTestProxy._initializers + "]);";
+    testRunner.evaluateInWebInspector(0, codeStringToEvaluate);
+
+    // `test` refers to a function defined in global scope in the test HTML page.
+    codeStringToEvaluate = "(" + runTestInFrontend.toString() + ")(" + test.toString() + ");";
+    testRunner.evaluateInWebInspector(0, codeStringToEvaluate);
+}
+
+InspectorTestProxy.completeTest = function()
+{
+    // Close inspector asynchrously in case we want to test tear-down behavior.
+    setTimeout(function() {
+        testRunner.closeWebInspector();
+        setTimeout(function() {
+            testRunner.notifyDone();
+        }, 0);
+    }, 0);
+}
+
+// Logs message to unbuffered process stdout, avoiding timeouts.
+// only be used to debug tests and not to produce normal test output.
+InspectorTestProxy.debugLog = function(message)
+{
+    window.alert(message);
+}
+
+// Add and clear test output from the results window.
+InspectorTestProxy.addResult = function(text)
+{
+    // For early errors triggered when loading the test page, write to stderr.
+    if (!document.body) {
+        this.debugLog(text);
+        this.completeTest();
+    }
+
+    if (!this._resultElement) {
+        this._resultElement = document.createElement("pre");
+        this._resultElement.id = "output";
+        document.body.appendChild(this._resultElement);
+    }
+    this._resultElement.appendChild(document.createTextNode(text));
+    this._resultElement.appendChild(document.createElement("br"));
+}
+
+InspectorTestProxy.clearResults = function()
+{
+    if (this._resultElement) {
+        this._resultElement.parentNode.removeChild(this._resultElement);
+        delete this._resultElement;
+    }
+}
+
+InspectorTestProxy.reportUncaughtException = function(message, url, lineNumber)
+{
+    var result = "Uncaught exception in test page: " + message + " [" + url + ":" + lineNumber + "]";
+    InspectorTestProxy.addResult(result);
+    InspectorTestProxy.completeTest();
+}
+
+// Catch syntax errors, type errors, and other exceptions. Run this before loading other files.
+window.onerror = InspectorTestProxy.reportUncaughtException;
diff --git a/LayoutTests/inspector/test-harness-trivially-works-expected.txt b/LayoutTests/inspector/test-harness-trivially-works-expected.txt
new file mode 100644 (file)
index 0000000..63ecb0a
--- /dev/null
@@ -0,0 +1,4 @@
+Tests that the test harness for non-stub inspector tests can load and run a test.
+
+Logged a message from the inspector page.
+
diff --git a/LayoutTests/inspector/test-harness-trivially-works.html b/LayoutTests/inspector/test-harness-trivially-works.html
new file mode 100644 (file)
index 0000000..c08ae1a
--- /dev/null
@@ -0,0 +1,15 @@
+<html>
+<head>
+<script type="text/javascript" src="inspector-test.js"></script>
+<script>
+function test()
+{
+    InspectorTest.log("Logged a message from the inspector page.");
+    InspectorTest.completeTest();
+}
+</script>
+</head>
+<body onload="runTest()">
+<p>Tests that the test harness for non-stub inspector tests can load and run a test.</p>
+</body>
+</html>
index db3ef99..64805d7 100644 (file)
@@ -1,3 +1,23 @@
+2014-02-27  Brian Burg  <bburg@apple.com>
+
+        Web Inspector: model tests should use a special Test.html inspector page
+        https://bugs.webkit.org/show_bug.cgi?id=129190
+
+        Reviewed by Timothy Hatcher.
+
+        Convert InspectorController::isUnderTest() into a flag, and expose an
+        Internals method so it can be set by the test before opening the inspector.
+
+        Test: inspector/test-harness-trivially-works.html
+
+        * inspector/InspectorController.cpp:
+        (WebCore::InspectorController::evaluateForTestInFrontend):
+        * inspector/InspectorController.h:
+        * testing/Internals.cpp:
+        (WebCore::Internals::setInspectorIsUnderTest): Added.
+        * testing/Internals.h:
+        * testing/Internals.idl:
+
 2014-02-27  Joseph Pecoraro  <pecoraro@apple.com>
 
         Unreviewed build fix after r164824.
index 18f2faf..e64df0b 100644 (file)
@@ -304,14 +304,8 @@ void InspectorController::setProcessId(long processId)
     IdentifiersFactory::setProcessId(processId);
 }
 
-bool InspectorController::isUnderTest()
-{
-    return m_isUnderTest;
-}
-
 void InspectorController::evaluateForTestInFrontend(long callId, const String& script)
 {
-    m_isUnderTest = true;
     m_inspectorAgent->evaluateForTestInFrontend(callId, script);
 }
 
index 8722d67..0c1c864 100644 (file)
@@ -112,7 +112,8 @@ public:
 
     PassRefPtr<Inspector::InspectorObject> buildObjectForHighlightedNode() const;
 
-    bool isUnderTest();
+    bool isUnderTest() const { return m_isUnderTest; }
+    void setIsUnderTest(bool isUnderTest) { m_isUnderTest = isUnderTest; }
     void evaluateForTestInFrontend(long callId, const String& script);
 
     bool profilerEnabled() const;
index 66b9d5e..2af0a22 100644 (file)
@@ -1534,6 +1534,17 @@ void Internals::setJavaScriptProfilingEnabled(bool enabled, ExceptionCode& ec)
 
     page->inspectorController().setProfilerEnabled(enabled);
 }
+
+void Internals::setInspectorIsUnderTest(bool isUnderTest, ExceptionCode& ec)
+{
+    Page* page = contextDocument()->frame()->page();
+    if (!page) {
+        ec = INVALID_ACCESS_ERR;
+        return;
+    }
+
+    page->inspectorController().setIsUnderTest(isUnderTest);
+}
 #endif // ENABLE(INSPECTOR)
 
 bool Internals::hasGrammarMarker(int from, int length, ExceptionCode&)
index 0d45bea..1b99573 100644 (file)
@@ -235,6 +235,7 @@ public:
     void closeDummyInspectorFrontend();
     void setInspectorResourcesDataSizeLimits(int maximumResourcesContentSize, int maximumSingleResourceContentSize, ExceptionCode&);
     void setJavaScriptProfilingEnabled(bool enabled, ExceptionCode&);
+    void setInspectorIsUnderTest(bool isUnderTest, ExceptionCode&);
 #endif
 
     String counterValue(Element*);
index 3571fb9..b609ea7 100644 (file)
     [Conditional=INSPECTOR] void closeDummyInspectorFrontend();
     [Conditional=INSPECTOR, RaisesException] void setInspectorResourcesDataSizeLimits(long maximumResourcesContentSize, long maximumSingleResourceContentSize);
     [Conditional=INSPECTOR, RaisesException] void setJavaScriptProfilingEnabled(boolean creates);
+    [Conditional=INSPECTOR, RaisesException] void setInspectorIsUnderTest(boolean isUnderTest);
 
     DOMString counterValue(Element element);
     long pageNumber(Element element, optional float pageWidth, optional float pageHeight);
index cc4e440..a7880cd 100644 (file)
@@ -1,3 +1,33 @@
+2014-02-27  Brian Burg  <bburg@apple.com>
+
+        Web Inspector: model tests should use a special Test.html inspector page
+        https://bugs.webkit.org/show_bug.cgi?id=129190
+
+        Reviewed by Timothy Hatcher.
+
+        * UserInterface/Base/Test.js: Added.
+        (WebInspector.loaded):
+        (WebInspector.contentLoaded):
+        (WebInspector.updateDockedState):
+        (InspectorTest.log):
+        (InspectorTest.assert):
+        (InspectorTest.debugLog):
+        (InspectorTest.completeTest):
+        (InspectorTest.evaluateInPage):
+        (InspectorTest.addResult):
+        (InspectorTest.clearResults):
+        (InspectorTest.pageLoaded):
+        (InspectorTest.reportUncaughtException):
+        (.console.logType):
+        * UserInterface/Protocol/InspectorBackend.js:
+        (InspectorBackendClass):
+        (InspectorBackendClass.prototype.dispatch):
+        (InspectorBackendClass.prototype.runAfterPendingDispatches):
+        (InspectorBackendClass.prototype._flushPendingScripts):
+        * UserInterface/Protocol/InspectorObserver.js:
+        (WebInspector.InspectorObserver.prototype.evaluateForTestInFrontend):
+        * UserInterface/Test.html: Added.
+
 2014-02-27  Joseph Pecoraro  <pecoraro@apple.com>
 
         Web Inspector: JSContext inspection should report exceptions in the console
diff --git a/Source/WebInspectorUI/UserInterface/Base/Test.js b/Source/WebInspectorUI/UserInterface/Base/Test.js
new file mode 100644 (file)
index 0000000..232ee34
--- /dev/null
@@ -0,0 +1,163 @@
+/*
+ * Copyright (C) 2013, 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+WebInspector.loaded = function()
+{
+    // Register observers for events from the InspectorBackend.
+    // The initialization order should match the same in Main.js.
+    InspectorBackend.registerInspectorDispatcher(new WebInspector.InspectorObserver);
+    InspectorBackend.registerPageDispatcher(new WebInspector.PageObserver);
+    InspectorBackend.registerDOMDispatcher(new WebInspector.DOMObserver);
+    InspectorBackend.registerDebuggerDispatcher(new WebInspector.DebuggerObserver);
+    InspectorBackend.registerCSSDispatcher(new WebInspector.CSSObserver);
+    InspectorBackend.registerRuntimeDispatcher(new WebInspector.RuntimeObserver);
+
+    // Instantiate controllers used by tests.
+    this.frameResourceManager = new WebInspector.FrameResourceManager;
+    this.domTreeManager = new WebInspector.DOMTreeManager;
+    this.cssStyleManager = new WebInspector.CSSStyleManager;
+    this.runtimeManager = new WebInspector.RuntimeManager;
+    this.debuggerManager = new WebInspector.DebuggerManager;
+    this.probeManager = new WebInspector.ProbeManager;
+
+    document.addEventListener("DOMContentLoaded", this.contentLoaded.bind(this));
+
+    // Enable agents.
+    InspectorAgent.enable();
+
+    // Establish communication with the InspectorBackend.
+    InspectorFrontendHost.loaded();
+}
+
+WebInspector.contentLoaded = function() {
+    // Signal that the frontend is now ready to receive messages.
+    InspectorFrontendAPI.loadCompleted();
+}
+
+// Add stubs that are called by the frontend API.
+WebInspector.updateDockedState = function()
+{
+}
+
+// InspectorTest contains extra methods that are only available to test code running
+// in the Web Inspector page. They rely on equivalents in the actual test page
+// which are provided by `inspector-test.js`.
+InspectorTest = {};
+
+// Note: Additional InspectorTest methods are included on a per-test basis from
+// files like `debugger-test.js`.
+
+// Appends a log message in the test document.
+InspectorTest.log = function(message)
+{
+    this.evaluateInPage("InspectorTestProxy.addResult(" + JSON.stringify(message) + ")");
+}
+
+// Appends an assert message in the test document.
+InspectorTest.assert = function(condition, message)
+{
+    var status = condition ? "PASS" : "FAIL";
+    this.evaluateInPage("InspectorTestProxy.addResult(" + JSON.stringify(status + ": " + message) + ")");
+}
+
+// This function should only be used to debug tests and not to produce normal test output.
+InspectorTest.debugLog = function(message)
+{
+    this.evaluateInPage("InspectorTestProxy.debugLog(" + JSON.stringify(message) + ")");
+}
+
+InspectorTest.completeTest = function()
+{
+    InspectorBackend.runAfterPendingDispatches(this.evaluateInPage.bind(this, "InspectorTestProxy.completeTest()"));
+}
+
+InspectorTest.evaluateInPage = function(codeString)
+{
+    // If we load this page outside of the inspector, or hit an early error when loading
+    // the test frontend, then defer evaluating the commands (indefinitely in the former case).
+    if (!RuntimeAgent) {
+        InspectorTest._originalConsoleMethods["error"]("Tried to evaluate in test page, but connection not yet established:", codeString);
+        return;
+    }
+
+    RuntimeAgent.evaluate(codeString, "test", false);
+}
+
+InspectorTest.addResult = function(text)
+{
+    this._results.push(text);
+    // If the test page reloaded, then we need to re-add the results from before the navigation.
+    if (this._shouldRebuildResults) {
+        delete this._shouldRebuildResults;
+
+        this.clearResults();
+        for (var result of this._results)
+            InspectorTest.evaluateInPage("InspectorTestProxy.addResult(unescape('" + escape(text) + "'))");
+    }
+
+    InspectorTest.evaluateInPage("InspectorTestProxy.addResult(unescape('" + escape(text) + "'))");
+}
+
+InspectorTest.clearResults = function(text)
+{
+    InspectorTest.evaluateInPage("InspectorTestProxy.clearResults()");
+}
+
+InspectorTest.pageLoaded = function()
+{
+    InspectorTest._shouldRebuildResults = true;
+    InspectorTest.addResult("Page reloaded.");
+}
+
+InspectorTest.reportUncaughtException = function(message, url, lineNumber)
+{
+    var result = "Uncaught exception in inspector page: " + message + " [" + url + ":" + lineNumber + "]";
+
+    // If the connection to the test page is not set up, then just dump to console and give up.
+    // Errors encountered this early can be debugged by loading Test.html in a normal browser page.
+    if (!InspectorFrontendHost || !InspectorBackend) {
+        InspectorTest._originalConsoleMethods["error"](result);
+        return;
+    }
+
+    InspectorTest.addResult(result);
+    InspectorTest.completeTest();
+}
+
+// Initialize reporting mechanisms before loading the rest of the inspector page.
+InspectorTest._results = [];
+InspectorTest._shouldRebuildResults = true;
+InspectorTest._originalConsoleMethods = {};
+
+// Catch syntax errors, type errors, and other exceptions. Run this before loading other files.
+window.onerror = InspectorTest.reportUncaughtException;
+
+for (var logType of ["log", "error", "info"]) {
+    // Redirect console methods to log messages into the test page's DOM.
+    InspectorTest._originalConsoleMethods[logType] = console[logType].bind(console);
+    console[logType] = function() {
+        InspectorTest.addResult(logType.toUpperCase() + ": " + Array.prototype.slice.call(arguments).toString());
+    };
+}
index 4ae4422..3acaddf 100644 (file)
@@ -40,6 +40,7 @@ function InspectorBackendClass()
     this._domainDispatchers = {};
     this._eventArgs = {};
     this._replyArgs = {};
+    this._deferredScripts = [];
 
     this.dumpInspectorTimeStats = false;
     this.dumpInspectorProtocolMessages = false;
@@ -218,8 +219,8 @@ InspectorBackendClass.prototype = {
                     console.log("time-stats: " + callback.methodName + " = " + (processingStartTime - callback.sendRequestTime) + " + " + (Date.now() - processingStartTime));
             }
 
-            if (this._scripts && !this._pendingResponsesCount)
-                this.runAfterPendingDispatches();
+            if (this._deferredScripts.length && !this._pendingResponsesCount)
+                this._flushPendingScripts();
 
             return;
         } else {
@@ -227,7 +228,7 @@ InspectorBackendClass.prototype = {
             var domainName = method[0];
             var functionName = method[1];
             if (!(domainName in this._domainDispatchers)) {
-                console.error("Protocol Error: the message is for non-existing domain '" + domainName + "'");
+                console.error("Protocol Error: Attempted to dispatch method '" + functionName + "' for non-existing domain '" + domainName + "'");
                 return;
             }
             var dispatcher = this._domainDispatchers[domainName];
@@ -264,23 +265,27 @@ InspectorBackendClass.prototype = {
         console.error("Request with id = " + messageObject.id + " failed. " + JSON.stringify(messageObject.error));
     },
 
-    /**
-     * @param {string=} script
-     */
     runAfterPendingDispatches: function(script)
     {
-        if (!this._scripts)
-            this._scripts = [];
+        console.assert(script);
+        console.assert(typeof script === "function");
 
-        if (script)
-            this._scripts.push(script);
+        if (!this._pendingResponsesCount)
+            script.call(this);
+        else
+            this._deferredScripts.push(script);
+    },
 
-        if (!this._pendingResponsesCount) {
-            var scripts = this._scripts;
-            this._scripts = [];
-            for (var id = 0; id < scripts.length; ++id)
-                 scripts[id].call(this);
-        }
+    // Private
+
+    _flushPendingScripts: function()
+    {
+        console.assert(!this._pendingResponsesCount);
+
+        var scriptsToRun = this._deferredScripts;
+        this._deferredScripts = [];
+        for (var script of scriptsToRun)
+            script.call(this);
     }
 }
 
index 7164645..8b74c78 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2013, 2014 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -33,9 +33,15 @@ WebInspector.InspectorObserver.prototype = {
 
     // Events defined by the "Inspector" domain.
 
-    evaluateForTestInFrontend: function(testCallId, script)
+    // FIXME: Remove plumbing for callIdentifier parameter from backend, as it's not used.
+    evaluateForTestInFrontend: function(callIdentifier, script)
     {
-        // FIXME: Not implemented.
+        if (!InspectorFrontendHost.isUnderTest())
+            return;
+
+        InspectorBackend.runAfterPendingDispatches(function() {
+            window.eval(script);
+        });
     },
 
     inspect: function(payload, hints)
diff --git a/Source/WebInspectorUI/UserInterface/Test.html b/Source/WebInspectorUI/UserInterface/Test.html
new file mode 100644 (file)
index 0000000..0f54dc3
--- /dev/null
@@ -0,0 +1,98 @@
+<!--
+ * Copyright (C) 2013, 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+-->
+<!DOCTYPE html>
+<html>
+<head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+    <!--
+    These resouces should match the order and groups used in Main.html.
+    -->
+    <script src="Base/WebInspector.js"></script>
+    <script src="Base/Test.js"></script>
+
+    <script src="Base/Object.js"></script>
+    <script src="Base/DOMUtilities.js"></script>
+    <script src="Base/URLUtilities.js"></script>
+    <script src="Base/Utilities.js"></script>
+
+    <script src="Protocol/InspectorBackend.js"></script>
+    <script src="Protocol/InspectorFrontendAPI.js"></script>
+    <script src="Protocol/InspectorFrontendHostStub.js"></script>
+    <script src="Protocol/LoadInspectorBackendCommands.js"></script>
+    <script src="Protocol/MessageDispatcher.js"></script>
+
+    <script src="Protocol/InspectorObserver.js"></script>
+    <script src="Protocol/CSSObserver.js"></script>
+    <script src="Protocol/DOMObserver.js"></script>
+    <script src="Protocol/DOMStorageObserver.js"></script>
+    <script src="Protocol/DebuggerObserver.js"></script>
+    <script src="Protocol/PageObserver.js"></script>
+    <script src="Protocol/RemoteObject.js"></script>
+    <script src="Protocol/RuntimeObserver.js"></script>
+
+    <script src="Models/BreakpointAction.js"></script>
+    <script src="Models/Breakpoint.js"></script>
+    <script src="Models/Color.js"></script>
+    <script src="Models/ContentFlow.js"></script>
+    <script src="Models/DOMNode.js"></script>
+    <script src="Models/DOMStorageObject.js"></script>
+    <script src="Models/DOMTree.js"></script>
+    <script src="Models/ExecutionContext.js"></script>
+    <script src="Models/ExecutionContextList.js"></script>
+    <script src="Models/Frame.js"></script>
+    <script src="Models/IndexedDatabase.js"></script>
+    <script src="Models/IndexedDatabaseObjectStore.js"></script>
+    <script src="Models/IndexedDatabaseObjectStoreIndex.js"></script>
+    <script src="Models/Probe.js"></script>
+    <script src="Models/ProbeSet.js"></script>
+    <script src="Models/ProbeSetDataFrame.js"></script>
+    <script src="Models/ProbeSetDataTable.js"></script>
+
+    <script src="Models/SourceCode.js"></script>
+    <script src="Models/Resource.js"></script>
+    <script src="Models/ResourceCollection.js"></script>
+    <script src="Models/Revision.js"></script>
+    <script src="Models/Script.js"></script>
+    <script src="Models/Setting.js"></script>
+    <script src="Models/SourceCodeLocation.js"></script>
+    <script src="Models/SourceCodeRevision.js"></script>
+    <script src="Models/SourceMapResource.js"></script>
+    <script src="Models/TextRange.js"></script>
+
+    <script src="Controllers/CSSStyleManager.js"></script>
+    <script src="Controllers/DOMTreeManager.js"></script>
+    <script src="Controllers/DebuggerManager.js"></script>
+    <script src="Controllers/FrameResourceManager.js"></script>
+    <script src="Controllers/ProbeManager.js"></script>
+    <script src="Controllers/RuntimeManager.js"></script>
+    <script src="Controllers/StorageManager.js"></script>
+
+    <script type="text/javascript">
+        WebInspector.loaded();
+    </script>
+</head>
+<body>
+</body>
+</html>
index 0ee6317..823fc49 100644 (file)
@@ -1,3 +1,24 @@
+2014-02-27  Brian Burg  <bburg@apple.com>
+
+        Web Inspector: model tests should use a special Test.html inspector page
+        https://bugs.webkit.org/show_bug.cgi?id=129190
+
+        Reviewed by Timothy Hatcher.
+
+        Support creating a separate test inspector page, based on the value of
+        InspectorController::isUnderTest(). Modify the navigation policy to check
+        the URL against both normal and test inspector pages.
+
+        * WebCoreSupport/WebInspectorClient.mm:
+        (WebInspectorClient::openInspectorFrontend):
+        (-[WebInspectorWindowController init]):
+        (-[WebInspectorWindowController initWithInspectedWebView:isUnderTest:]):
+        Move the initial navigation of the inspector page to this method, and change
+        the URL based on the value of InspectorController::isUnderTest().
+
+        (-[WebInspectorWindowController inspectorTestPagePath]): Added.
+        (-[WebInspectorWindowController webView:decidePolicyForNavigationAction:request:frame:decisionListener:]):
+
 2014-02-27  Pratik Solanki  <psolanki@apple.com>
 
         Assertion failure at CachedResource.h:196: ASSERT(!m_purgeableData)
index 7910ea2..61ce695 100644 (file)
@@ -108,8 +108,9 @@ using namespace WebCore;
     BOOL _visible;
     BOOL _destroyingInspectorView;
 }
-- (id)initWithInspectedWebView:(WebView *)webView;
+- (id)initWithInspectedWebView:(WebView *)webView isUnderTest:(BOOL)isUnderTest;
 - (NSString *)inspectorPagePath;
+- (NSString *)inspectorTestPagePath;
 - (WebView *)webView;
 - (void)attach;
 - (void)detach;
@@ -141,7 +142,7 @@ void WebInspectorClient::inspectorDestroyed()
 
 InspectorFrontendChannel* WebInspectorClient::openInspectorFrontend(InspectorController* inspectorController)
 {
-    RetainPtr<WebInspectorWindowController> windowController = adoptNS([[WebInspectorWindowController alloc] initWithInspectedWebView:m_webView]);
+    RetainPtr<WebInspectorWindowController> windowController = adoptNS([[WebInspectorWindowController alloc] initWithInspectedWebView:m_webView isUnderTest:inspectorController->isUnderTest()]);
     [windowController.get() setInspectorClient:this];
 
     m_frontendPage = core([windowController.get() webView]);
@@ -420,20 +421,22 @@ void WebInspectorFrontendClient::append(const String& suggestedURL, const String
 
     [preferences release];
 
-    NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL fileURLWithPath:[self inspectorPagePath]]];
-    [[_webView mainFrame] loadRequest:request];
-    [request release];
-
     [self setWindowFrameAutosaveName:@"Web Inspector 2"];
     return self;
 }
 
-- (id)initWithInspectedWebView:(WebView *)webView
+- (id)initWithInspectedWebView:(WebView *)webView isUnderTest:(BOOL)isUnderTest
 {
     if (!(self = [self init]))
         return nil;
 
     _inspectedWebView = webView;
+
+    NSString *pagePath = isUnderTest ? [self inspectorTestPagePath] : [self inspectorPagePath];
+    NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL fileURLWithPath: pagePath]];
+    [[_webView mainFrame] loadRequest:request];
+    [request release];
+
     return self;
 }
 
@@ -455,6 +458,16 @@ void WebInspectorFrontendClient::append(const String& suggestedURL, const String
     return path;
 }
 
+- (NSString *)inspectorTestPagePath
+{
+    // Call the soft link framework function to dlopen it, then [NSBundle bundleWithIdentifier:] will work.
+    WebInspectorUILibrary();
+
+    NSString *path = [[NSBundle bundleWithIdentifier:@"com.apple.WebInspectorUI"] pathForResource:@"Test" ofType:@"html"];
+    ASSERT([path length]);
+    return path;
+}
+
 // MARK: -
 
 - (WebView *)webView
@@ -749,6 +762,12 @@ void WebInspectorFrontendClient::append(const String& suggestedURL, const String
         return;
     }
 
+    // Allow loading of the test inspector file.
+    if ([[request URL] isFileURL] && [[[request URL] path] isEqualToString:[self inspectorTestPagePath]]) {
+        [listener use];
+        return;
+    }
+
     // Prevent everything else from loading in the inspector's page.
     [listener ignore];
 
index 11b59aa..98b57b2 100644 (file)
@@ -1,3 +1,38 @@
+2014-02-27  Brian Burg  <bburg@apple.com>
+
+        Web Inspector: model tests should use a special Test.html inspector page
+        https://bugs.webkit.org/show_bug.cgi?id=129190
+
+        Reviewed by Timothy Hatcher.
+
+        Support creating a separate test inspector page, based on the value of
+        InspectorController::isUnderTest(). Add this as a separate API call for
+        WebInspectorProxy. Modify the navigation policy to check the URL against
+        both normal and test inspector pages.
+
+        * UIProcess/WebInspectorProxy.cpp:
+        (WebKit::isMainOrTestInspectorPage):
+        (WebKit::decidePolicyForNavigationAction):
+        (WebKit::WebInspectorProxy::createInspectorPageForTest):
+        * UIProcess/WebInspectorProxy.h:
+        * UIProcess/WebInspectorProxy.messages.in:
+        * UIProcess/efl/WebInspectorProxyEfl.cpp:
+        (WebKit::WebInspectorProxy::inspectorTestPageURL):
+        * UIProcess/gtk/WebInspectorProxyGtk.cpp:
+        (WebKit::WebInspectorProxy::inspectorTestPageURL):
+        * UIProcess/ios/WebInspectorProxyIOS.mm:
+        (WebKit::WebInspectorProxy::inspectorTestPageURL):
+        * UIProcess/mac/WebInspectorProxyMac.mm:
+        (WebKit::WebInspectorProxy::inspectorTestPageURL):
+        * WebProcess/WebCoreSupport/WebInspectorClient.cpp:
+        (WebKit::WebInspectorClient::openInspectorFrontend):
+        * WebProcess/WebPage/WebInspector.cpp: Some drive-by nullptr refactorings.
+        (WebKit::WebInspector::WebInspector):
+        (WebKit::WebInspector::createInspectorPage):
+        (WebKit::WebInspector::createInspectorPageForTest):
+        (WebKit::WebInspector::destroyInspectorPage):
+        * WebProcess/WebPage/WebInspector.h:
+
 2014-02-27  Anders Carlsson  <andersca@apple.com>
 
         Make WebProcessProxy::pages() return an IteratorRange
index 08fe835..9b9c98d 100644 (file)
@@ -362,15 +362,19 @@ bool WebInspectorProxy::isInspectorPage(WebPageProxy& page)
     return WebInspectorPageGroups::shared().isInspectorPageGroup(page.pageGroup());
 }
 
-static bool isMainInspectorPage(const WebInspectorProxy* webInspectorProxy, WKURLRequestRef requestRef)
+static bool isMainOrTestInspectorPage(const WebInspectorProxy* webInspectorProxy, WKURLRequestRef requestRef)
 {
     // Use URL so we can compare just the paths.
-    URL inspectorURL(URL(), webInspectorProxy->inspectorPageURL());
+    URL mainPageURL(URL(), webInspectorProxy->inspectorPageURL());
+    URL testPageURL(URL(), webInspectorProxy->inspectorTestPageURL());
     URL requestURL(URL(), toImpl(requestRef)->resourceRequest().url());
 
-    ASSERT(WebCore::SchemeRegistry::shouldTreatURLSchemeAsLocal(inspectorURL.protocol()));
+    ASSERT(WebCore::SchemeRegistry::shouldTreatURLSchemeAsLocal(mainPageURL.protocol()));
+    ASSERT(WebCore::SchemeRegistry::shouldTreatURLSchemeAsLocal(testPageURL.protocol()));
 
-    return WebCore::SchemeRegistry::shouldTreatURLSchemeAsLocal(requestURL.protocol()) && decodeURLEscapeSequences(requestURL.path()) == decodeURLEscapeSequences(inspectorURL.path());
+    bool isMainPageURL = decodeURLEscapeSequences(requestURL.path()) == decodeURLEscapeSequences(mainPageURL.path());
+    bool isTestPageURL = decodeURLEscapeSequences(requestURL.path()) == decodeURLEscapeSequences(testPageURL.path());
+    return WebCore::SchemeRegistry::shouldTreatURLSchemeAsLocal(requestURL.protocol()) && (isMainPageURL || isTestPageURL);
 }
 
 static void decidePolicyForNavigationAction(WKPageRef, WKFrameRef frameRef, WKFrameNavigationType, WKEventModifiers, WKEventMouseButton, WKFrameRef, WKURLRequestRef requestRef, WKFramePolicyListenerRef listenerRef, WKTypeRef, const void* clientInfo)
@@ -385,7 +389,7 @@ static void decidePolicyForNavigationAction(WKPageRef, WKFrameRef frameRef, WKFr
     ASSERT(webInspectorProxy);
 
     // Allow loading of the main inspector file.
-    if (isMainInspectorPage(webInspectorProxy, requestRef)) {
+    if (isMainOrTestInspectorPage(webInspectorProxy, requestRef)) {
         toImpl(listenerRef)->use();
         return;
     }
@@ -476,6 +480,42 @@ void WebInspectorProxy::createInspectorPage(uint64_t& inspectorPageID, WebPageCr
     m_createdInspectorPage = true;
 }
 
+void WebInspectorProxy::createInspectorPageForTest(uint64_t& inspectorPageID, WebPageCreationParameters& inspectorPageParameters)
+{
+    inspectorPageID = 0;
+
+    if (!m_page)
+        return;
+
+    m_isAttached = false;
+
+    WebPageProxy* inspectorPage = platformCreateInspectorPage();
+    ASSERT(inspectorPage);
+    if (!inspectorPage)
+        return;
+
+    inspectorPageID = inspectorPage->pageID();
+    inspectorPageParameters = inspectorPage->creationParameters();
+
+    WKPagePolicyClientV1 policyClient = {
+        { 1, this },
+        0, /* decidePolicyForNavigationAction_deprecatedForUseWithV0 */
+        0, /* decidePolicyForNewWindowAction */
+        0, /* decidePolicyForResponse_deprecatedForUseWithV0 */
+        0, /* unableToImplementPolicy */
+        decidePolicyForNavigationAction,
+        0, /* decidePolicyForResponse */
+    };
+
+    WKPageSetPagePolicyClient(toAPI(inspectorPage), &policyClient.base);
+
+    m_page->process().assumeReadAccessToBaseURL(inspectorBaseURL());
+
+    inspectorPage->loadRequest(URL(URL(), inspectorTestPageURL()));
+
+    m_createdInspectorPage = true;
+}
+
 void WebInspectorProxy::open()
 {
     m_isVisible = true;
index 0457c47..17a7498 100644 (file)
@@ -134,8 +134,9 @@ public:
 
     static bool isInspectorPage(WebPageProxy&);
 
-    // Implemented the platform WebInspectorProxy file
+    // Provided by platform WebInspectorProxy implementations.
     String inspectorPageURL() const;
+    String inspectorTestPageURL() const;
     String inspectorBaseURL() const;
 
 #if ENABLE(INSPECTOR_SERVER)
@@ -173,6 +174,7 @@ private:
 
     // Called by WebInspectorProxy messages
     void createInspectorPage(uint64_t& inspectorPageID, WebPageCreationParameters&);
+    void createInspectorPageForTest(uint64_t& inspectorPageID, WebPageCreationParameters&);
     void didClose();
     void bringToFront();
     void attachAvailabilityChanged(bool);
index 2add42f..e6c944d 100644 (file)
@@ -24,6 +24,7 @@
 
 messages -> WebInspectorProxy {
     CreateInspectorPage() -> (uint64_t inspectorPageID, WebKit::WebPageCreationParameters inspectorPageParameters)
+    CreateInspectorPageForTest() -> (uint64_t inspectorPageID, WebKit::WebPageCreationParameters inspectorPageParameters)
     DidClose()
     BringToFront()
     InspectedURLChanged(String urlString)
index f6c2a8f..a80ab63 100644 (file)
@@ -177,6 +177,15 @@ String WebInspectorProxy::inspectorPageURL() const
     return builder.toString();
 }
 
+String WebInspectorProxy::inspectorTestPageURL() const
+{
+    StringBuilder builder;
+    builder.append(inspectorBaseURL());
+    builder.appendLiteral("/Test.html");
+
+    return builder.toString();
+}
+
 String WebInspectorProxy::inspectorBaseURL() const
 {
     return "file://" + WebCore::inspectorResourcePath();
index 231bc4f..579b099 100644 (file)
@@ -153,6 +153,11 @@ String WebInspectorProxy::inspectorPageURL() const
     return String("resource:///org/webkitgtk/inspector/UserInterface/Main.html");
 }
 
+String WebInspectorProxy::inspectorTestPageURL() const
+{
+    return String("resource:///org/webkitgtk/inspector/UserInterface/Test.html");
+}
+
 String WebInspectorProxy::inspectorBaseURL() const
 {
     return String("resource:///org/webkitgtk/inspector/UserInterface/");
index 64ba337..6275f26 100644 (file)
@@ -112,6 +112,12 @@ String WebInspectorProxy::inspectorPageURL() const
     return String();
 }
 
+String WebInspectorProxy::inspectorTestPageURL() const
+{
+    notImplemented();
+    return String();
+}
+
 String WebInspectorProxy::inspectorBaseURL() const
 {
     notImplemented();
index 20c423e..3a1634d 100644 (file)
@@ -757,6 +757,17 @@ String WebInspectorProxy::inspectorPageURL() const
     return [[NSURL fileURLWithPath:path] absoluteString];
 }
 
+String WebInspectorProxy::inspectorTestPageURL() const
+{
+    // Call the soft link framework function to dlopen it, then [NSBundle bundleWithIdentifier:] will work.
+    WebInspectorUILibrary();
+
+    NSString *path = [[NSBundle bundleWithIdentifier:@"com.apple.WebInspectorUI"] pathForResource:@"Test" ofType:@"html"];
+    ASSERT([path length]);
+
+    return [[NSURL fileURLWithPath:path] absoluteString];
+}
+
 String WebInspectorProxy::inspectorBaseURL() const
 {
     // Call the soft link framework function to dlopen it, then [NSBundle bundleWithIdentifier:] will work.
index 76e0b8d..bf7c307 100644 (file)
@@ -47,9 +47,9 @@ void WebInspectorClient::inspectorDestroyed()
     delete this;
 }
 
-WebCore::InspectorFrontendChannel* WebInspectorClient::openInspectorFrontend(InspectorController*)
+WebCore::InspectorFrontendChannel* WebInspectorClient::openInspectorFrontend(InspectorController* controller)
 {
-    WebPage* inspectorPage = m_page->inspector()->createInspectorPage();
+    WebPage* inspectorPage = controller->isUnderTest() ? m_page->inspector()->createInspectorPageForTest() : m_page->inspector()->createInspectorPage();
     ASSERT_UNUSED(inspectorPage, inspectorPage);
     return this;
 }
index cecc9a5..60c8f95 100644 (file)
@@ -53,8 +53,8 @@ PassRefPtr<WebInspector> WebInspector::create(WebPage* page, InspectorFrontendCh
 
 WebInspector::WebInspector(WebPage* page, InspectorFrontendChannel* frontendChannel)
     : m_page(page)
-    , m_inspectorPage(0)
-    , m_frontendClient(0)
+    , m_inspectorPage(nullptr)
+    , m_frontendClient(nullptr)
     , m_frontendChannel(frontendChannel)
 #if PLATFORM(COCOA)
     , m_hasLocalizedStringsURL(false)
@@ -69,7 +69,7 @@ WebInspector::WebInspector(WebPage* page, InspectorFrontendChannel* frontendChan
 WebPage* WebInspector::createInspectorPage()
 {
     if (!m_page)
-        return 0;
+        return nullptr;
 
     ASSERT(!m_inspectorPage);
     ASSERT(!m_frontendClient);
@@ -80,11 +80,41 @@ WebPage* WebInspector::createInspectorPage()
     if (!WebProcess::shared().parentProcessConnection()->sendSync(Messages::WebInspectorProxy::CreateInspectorPage(),
             Messages::WebInspectorProxy::CreateInspectorPage::Reply(inspectorPageID, parameters),
             m_page->pageID(), std::chrono::milliseconds::max())) {
-        return 0;
+        return nullptr;
     }
 
     if (!inspectorPageID)
-        return 0;
+        return nullptr;
+
+    WebProcess::shared().createWebPage(inspectorPageID, parameters);
+    m_inspectorPage = WebProcess::shared().webPage(inspectorPageID);
+    ASSERT(m_inspectorPage);
+
+    auto frontendClient = std::make_unique<WebInspectorFrontendClient>(m_page, m_inspectorPage);
+    m_frontendClient = frontendClient.get();
+    m_inspectorPage->corePage()->inspectorController().setInspectorFrontendClient(std::move(frontendClient));
+    return m_inspectorPage;
+}
+
+WebPage* WebInspector::createInspectorPageForTest()
+{
+    if (!m_page)
+        return nullptr;
+
+    ASSERT(!m_inspectorPage);
+    ASSERT(!m_frontendClient);
+
+    uint64_t inspectorPageID = 0;
+    WebPageCreationParameters parameters;
+
+    if (!WebProcess::shared().parentProcessConnection()->sendSync(Messages::WebInspectorProxy::CreateInspectorPageForTest(),
+            Messages::WebInspectorProxy::CreateInspectorPageForTest::Reply(inspectorPageID, parameters),
+            m_page->pageID(), std::chrono::milliseconds::max())) {
+        return nullptr;
+    }
+
+    if (!inspectorPageID)
+        return nullptr;
 
     WebProcess::shared().createWebPage(inspectorPageID, parameters);
     m_inspectorPage = WebProcess::shared().webPage(inspectorPageID);
@@ -98,9 +128,9 @@ WebPage* WebInspector::createInspectorPage()
 
 void WebInspector::destroyInspectorPage()
 {
-    m_inspectorPage = 0;
-    m_frontendClient = 0;
-    m_frontendChannel = 0;
+    m_inspectorPage = nullptr;
+    m_frontendClient = nullptr;
+    m_frontendChannel = nullptr;
 }
 
 // Called from WebInspectorFrontendClient
index ba3e49c..f27d5eb 100644 (file)
@@ -82,6 +82,7 @@ private:
 
     // Called from WebInspectorClient
     WebPage* createInspectorPage();
+    WebPage* createInspectorPageForTest();
     void destroyInspectorPage();
 
     // Called from WebInspectorFrontendClient
index 3fbf9df..964d328 100644 (file)
@@ -1,3 +1,26 @@
+2014-02-27  Brian Burg  <bburg@apple.com>
+
+        Web Inspector: model tests should use a special Test.html inspector page
+        https://bugs.webkit.org/show_bug.cgi?id=129190
+
+        Reviewed by Timothy Hatcher.
+
+        Remove code that immediately opens the Web Inspector based on the file path of the test.
+        Instead, the test page should request that the inspector open inside its `test()` method.
+
+        This change is necessary because otherwise, the inspector would be opened too early for
+        InspectorController::isUnderTest to get set in time, so the normal Web Inspector page
+        will get loaded instead of the minimal test page.
+
+        * DumpRenderTree/efl/DumpRenderTree.cpp:
+        (createTestRunner):
+        * DumpRenderTree/gtk/DumpRenderTree.cpp:
+        (runTest):
+        * DumpRenderTree/mac/DumpRenderTree.mm:
+        (runTest):
+        * DumpRenderTree/win/DumpRenderTree.cpp:
+        (runTest):
+
 2014-02-27  Laszlo Vidacs  <lvidacs.u-szeged@partner.samsung.com>
 
         check-webkit-style indentation false alarm in WebKit/win/WebNodeHighlight.cpp
index e1cad36..d8a5b56 100644 (file)
@@ -156,11 +156,6 @@ static bool shouldDumpAsText(const String& pathOrURL)
     return pathOrURL.contains("dumpAsText/");
 }
 
-static bool shouldOpenWebInspector(const String& pathOrURL)
-{
-    return pathOrURL.contains("inspector/");
-}
-
 static void sendPixelResultsEOF()
 {
     puts("#EOF");
@@ -243,8 +238,6 @@ static void createTestRunner(const String& testURL, const String& expectedPixelH
         gTestRunner->setDumpFrameLoadCallbacks(true);
 
     gTestRunner->setDeveloperExtrasEnabled(true);
-    if (shouldOpenWebInspector(testURL))
-        gTestRunner->showWebInspector();
 
     gTestRunner->setDumpHistoryDelegateCallbacks(isGlobalHistoryTest(testURL));
 
index 72aecb5..ee7e79c 100644 (file)
@@ -111,11 +111,6 @@ static bool shouldLogFrameLoadDelegates(const string& pathOrURL)
     return pathOrURL.find("loading/") != string::npos;
 }
 
-static bool shouldOpenWebInspector(const string& pathOrURL)
-{
-    return pathOrURL.find("inspector/") != string::npos;
-}
-
 static bool shouldDumpAsText(const string& pathOrURL)
 {
     return pathOrURL.find("dumpAsText/") != string::npos;
@@ -759,8 +754,6 @@ static void runTest(const string& inputLine)
 
     if (shouldEnableDeveloperExtras(testURL)) {
         gTestRunner->setDeveloperExtrasEnabled(true);
-        if (shouldOpenWebInspector(testURL))
-            gTestRunner->showWebInspector();
         if (shouldDumpAsText(testURL)) {
             gTestRunner->setDumpAsText(true);
             gTestRunner->setGeneratePixelResults(false);
index 816e76e..a462d65 100644 (file)
@@ -1598,11 +1598,6 @@ static bool shouldLogHistoryDelegates(const char* pathOrURL)
     return strstr(pathOrURL, "globalhistory/");
 }
 
-static bool shouldOpenWebInspector(const char* pathOrURL)
-{
-    return strstr(pathOrURL, "inspector/");
-}
-
 static bool shouldDumpAsText(const char* pathOrURL)
 {
     return strstr(pathOrURL, "dumpAsText/");
@@ -1765,8 +1760,6 @@ static void runTest(const string& inputLine)
 
     if (shouldEnableDeveloperExtras(pathOrURL.c_str())) {
         gTestRunner->setDeveloperExtrasEnabled(true);
-        if (shouldOpenWebInspector(pathOrURL.c_str()))
-            gTestRunner->showWebInspector();
         if (shouldDumpAsText(pathOrURL.c_str())) {
             gTestRunner->setDumpAsText(true);
             gTestRunner->setGeneratePixelResults(false);
index 6befaae..d2eb35c 100644 (file)
@@ -813,11 +813,6 @@ static bool shouldLogHistoryDelegates(const char* pathOrURL)
     return strstr(pathOrURL, "/globalhistory/") || strstr(pathOrURL, "\\globalhistory\\");
 }
 
-static bool shouldOpenWebInspector(const char* pathOrURL)
-{
-    return strstr(pathOrURL, "/inspector/") || strstr(pathOrURL, "\\inspector\\");
-}
-
 static bool shouldDumpAsText(const char* pathOrURL)
 {
     return strstr(pathOrURL, "/dumpAsText/") || strstr(pathOrURL, "\\dumpAsText\\");
@@ -1108,11 +1103,9 @@ static void runTest(const string& inputLine)
 
     resetWebViewToConsistentStateBeforeTesting();
 
-    if (shouldEnableDeveloperExtras(pathOrURL.c_str())) {
+    if (shouldEnableDeveloperExtras(pathOrURL.c_str()))
         gTestRunner->setDeveloperExtrasEnabled(true);
-        if (shouldOpenWebInspector(pathOrURL.c_str()))
-            gTestRunner->showWebInspector();
-    }
+
     if (shouldDumpAsText(pathOrURL.c_str())) {
         gTestRunner->setDumpAsText(true);
         gTestRunner->setGeneratePixelResults(false);