This checkin re-enables currentPage.getDOM(). Please see

<http://lxr.mozilla.org/mozilla/source/java/webclient/test/automated/src/classes/org/mozilla/webclient/DOMTest.java>
for a trivial usage example.

Next step is to continue to flesh out CurrentPage methods.

Ed

A test/automated/src/classes/org/mozilla/webclient/DOMTest.java

- show basic DOM functionality

M build-tests.xml

- Add new DOM test

M src_moz/CurrentPageImpl.cpp

- re-expose DOM functionality

M test/automated/src/test/HistoryTest0.html

- Add an ID to the anchor so we can do getElementById() on it.


git-svn-id: svn://10.0.0.236/trunk@168790 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
edburns%acm.org
2005-02-04 15:43:47 +00:00
parent 585847bdbc
commit cb731271d4
4 changed files with 166 additions and 9 deletions

View File

@@ -153,7 +153,6 @@
<classpath refid="test.classpath"/>
<formatter type="plain" usefile="false"/>
<test name="org.mozilla.webclient.BrowserControlFactoryTest"/>
<test name="org.mozilla.webclient.ProfileManagerTest"/>
<test name="org.mozilla.webclient.BookmarksTest"/>
@@ -166,6 +165,7 @@
<test name="org.mozilla.webclient.KeyListenerTest"/>
<test name="org.mozilla.webclient.DocumentLoadListenerTest"/>
<test name="org.mozilla.webclient.WindowCreatorTest"/>
<test name="org.mozilla.webclient.DOMTest"/>
<!-- non running
<test name="org.mozilla.webclient.wrapper_native.gtk.TestGtkBrowserControlCanvas"/>
-->

View File

@@ -37,6 +37,10 @@
#include "NativeBrowserControl.h"
#include "EmbedWindow.h"
#include "nsIWebBrowser.h"
#include "nsIDOMWindow.h"
#include "nsIDOMDocument.h"
#include "nsCRT.h"
#if 0 // convenience
@@ -216,6 +220,8 @@ JNIEXPORT jstring JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_Curren
return urlString;
}
#endif
JNIEXPORT jobject JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_CurrentPageImpl_nativeGetDOM
(JNIEnv *env, jobject obj, jint nativeBCPtr)
{
@@ -229,10 +235,23 @@ JNIEXPORT jobject JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_Curren
::util_ThrowExceptionToJava(env, "Exception: null nativeBCPtr passed to raptorWebShellGetDOM");
return nsnull;
}
if (nsnull == nativeBrowserControl->currentDocument ||
nsnull == (documentLong = (jlong) nativeBrowserControl->currentDocument.get())){
// get the web browser
nsCOMPtr<nsIWebBrowser> webBrowser;
nativeBrowserControl->mWindow->GetWebBrowser(getter_AddRefs(webBrowser));
// get the content DOM window for that web browser
nsCOMPtr<nsIDOMWindow> domWindow;
nsCOMPtr<nsIDOMDocument> domDocument;
webBrowser->GetContentDOMWindow(getter_AddRefs(domWindow));
if (!domWindow) {
return nsnull;
}
domWindow->GetDocument(getter_AddRefs(domDocument));
if (!domDocument) {
return nsnull;
}
documentLong = (jlong) domDocument.get();
if (nsnull == (clazz = ::util_FindClass(env,
"org/mozilla/dom/DOMAccessor"))) {
@@ -245,15 +264,13 @@ JNIEXPORT jobject JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_Curren
return nsnull;
}
wsGetDOMEvent * actionEvent = new wsGetDOMEvent(env, clazz, mid, documentLong);
PLEvent * event = (PLEvent*) *actionEvent;
result = (jobject) ::util_PostSynchronousEvent(nativeBrowserControl, event);
result = (jobject) util_CallStaticObjectMethodlongArg(env, clazz, mid,
documentLong);
return result;
}
#if 0 // convenience
/*
* Class: org_mozilla_webclient_impl_wrapper_0005fnative_CurrentPageImpl
* Method: nativeGetSource

View File

@@ -0,0 +1,140 @@
/*
* $Id: DOMTest.java,v 1.1 2005-02-04 15:43:47 edburns%acm.org Exp $
*/
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Sun
* Microsystems, Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s): Ed Burns &lt;edburns@acm.org&gt;
*/
package org.mozilla.webclient;
import junit.framework.Test;
import junit.framework.TestSuite;
import java.util.Enumeration;
import java.awt.Frame;
import java.awt.BorderLayout;
import java.awt.Robot;
import java.io.File;
import java.io.FileInputStream;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
// DOMTest.java
public class DOMTest extends WebclientTestCase {
public DOMTest(String name) {
super(name);
try {
BrowserControlFactory.setAppData(getBrowserBinDir());
}
catch (Exception e) {
fail();
}
}
public static Test suite() {
TestSuite result = createServerTestSuite();
result.addTestSuite(DOMTest.class);
return (result);
}
static EventRegistration2 eventRegistration;
static boolean keepWaiting;
//
// Constants
//
//
// Testcases
//
public void testHttpLoad() throws Exception {
BrowserControl firstBrowserControl = null;
DocumentLoadListenerImpl listener = null;
Selection selection = null;
firstBrowserControl = BrowserControlFactory.newBrowserControl();
assertNotNull(firstBrowserControl);
BrowserControlCanvas canvas = (BrowserControlCanvas)
firstBrowserControl.queryInterface(BrowserControl.BROWSER_CONTROL_CANVAS_NAME);
eventRegistration = (EventRegistration2)
firstBrowserControl.queryInterface(BrowserControl.EVENT_REGISTRATION_NAME);
assertNotNull(canvas);
Frame frame = new Frame();
frame.setUndecorated(true);
frame.setBounds(0, 0, 640, 480);
frame.add(canvas, BorderLayout.CENTER);
frame.setVisible(true);
canvas.setVisible(true);
Navigation2 nav = (Navigation2)
firstBrowserControl.queryInterface(BrowserControl.NAVIGATION_NAME);
assertNotNull(nav);
final CurrentPage2 currentPage = (CurrentPage2)
firstBrowserControl.queryInterface(BrowserControl.CURRENT_PAGE_NAME);
assertNotNull(currentPage);
//
// try loading a file over HTTP
//
DOMTest.keepWaiting = true;
eventRegistration.addDocumentLoadListener(listener = new DocumentLoadListenerImpl() {
public void doEndCheck() {
DOMTest.keepWaiting = false;
}
});
String url = "http://localhost:5243/HistoryTest0.html";
Thread.currentThread().sleep(3000);
nav.loadURL(url);
// keep waiting until the previous load completes
while (DOMTest.keepWaiting) {
Thread.currentThread().sleep(1000);
}
Document dom = currentPage.getDOM();
assertNotNull(dom);
Node node = dom.getElementById("HistoryTest1.html");
assertNotNull(node);
assertEquals(1, node.getNodeType());
node = node.getFirstChild();
assertEquals("next", node.getNodeValue());
frame.setVisible(false);
BrowserControlFactory.deleteBrowserControl(firstBrowserControl);
}
}

View File

@@ -9,7 +9,7 @@
<p>This is page 0 of the history test.</p>
<p><a href="HistoryTest1.html">next</a></p>
<p><a id="HistoryTest1.html" href="HistoryTest1.html">next</a></p>
<hr>