From cb731271d403bf3152229438ef4939089ee561c4 Mon Sep 17 00:00:00 2001 From: "edburns%acm.org" Date: Fri, 4 Feb 2005 15:43:47 +0000 Subject: [PATCH] This checkin re-enables currentPage.getDOM(). Please see 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 --- mozilla/java/webclient/build-tests.xml | 2 +- .../webclient/src_moz/CurrentPageImpl.cpp | 31 +++- .../org/mozilla/webclient/DOMTest.java | 140 ++++++++++++++++++ .../test/automated/src/test/HistoryTest0.html | 2 +- 4 files changed, 166 insertions(+), 9 deletions(-) create mode 100644 mozilla/java/webclient/test/automated/src/classes/org/mozilla/webclient/DOMTest.java diff --git a/mozilla/java/webclient/build-tests.xml b/mozilla/java/webclient/build-tests.xml index 4d854689153..f5870bae497 100644 --- a/mozilla/java/webclient/build-tests.xml +++ b/mozilla/java/webclient/build-tests.xml @@ -153,7 +153,6 @@ - @@ -166,6 +165,7 @@ + diff --git a/mozilla/java/webclient/src_moz/CurrentPageImpl.cpp b/mozilla/java/webclient/src_moz/CurrentPageImpl.cpp index 03544700647..bd37031d3a4 100644 --- a/mozilla/java/webclient/src_moz/CurrentPageImpl.cpp +++ b/mozilla/java/webclient/src_moz/CurrentPageImpl.cpp @@ -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 webBrowser; + nativeBrowserControl->mWindow->GetWebBrowser(getter_AddRefs(webBrowser)); + + // get the content DOM window for that web browser + nsCOMPtr domWindow; + nsCOMPtr 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 diff --git a/mozilla/java/webclient/test/automated/src/classes/org/mozilla/webclient/DOMTest.java b/mozilla/java/webclient/test/automated/src/classes/org/mozilla/webclient/DOMTest.java new file mode 100644 index 00000000000..ea4b3779bfd --- /dev/null +++ b/mozilla/java/webclient/test/automated/src/classes/org/mozilla/webclient/DOMTest.java @@ -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 <edburns@acm.org> + */ + +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); + } + +} diff --git a/mozilla/java/webclient/test/automated/src/test/HistoryTest0.html b/mozilla/java/webclient/test/automated/src/test/HistoryTest0.html index aad0a6dee13..6671c17fa93 100644 --- a/mozilla/java/webclient/test/automated/src/test/HistoryTest0.html +++ b/mozilla/java/webclient/test/automated/src/test/HistoryTest0.html @@ -9,7 +9,7 @@

This is page 0 of the history test.

-

next

+

next