This checkin re-enables

CurrentPage.copyCurrentSelectionToSystemClipboard() and provides a unit
test for it.

Next step is getCurrentURL.

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

- new test suite for CurrentPage.  Currently only has
  testCopyCurrentSelectionToSystemClipboard().

M build-tests.xml

- add CurrentPage TestSuite with one test.

M src_moz/CurrentPageImpl.cpp

- re-implement nativeCopyCurrentSelectionToSystemClipboard()


git-svn-id: svn://10.0.0.236/trunk@168900 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
edburns%acm.org
2005-02-07 04:59:50 +00:00
parent 97e4a99da0
commit 0327496b81
3 changed files with 166 additions and 4 deletions

View File

@@ -0,0 +1,165 @@
/*
* $Id: CurrentPageTest.java,v 1.3 2005-02-07 04:59:50 edburns%acm.org Exp $
*/
/*
*
* 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.TestSuite;
import junit.framework.TestResult;
import junit.framework.Test;
import java.util.Enumeration;
import java.awt.Frame;
import java.awt.BorderLayout;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.ClipboardOwner;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.DataFlavor;
import java.io.File;
import java.io.FileInputStream;
import java.io.BufferedReader;
// CurrentPageTest.java
public class CurrentPageTest extends WebclientTestCase implements ClipboardOwner {
public CurrentPageTest(String name) {
super(name);
try {
BrowserControlFactory.setAppData(getBrowserBinDir());
}
catch (Exception e) {
fail();
}
}
public static Test suite() {
TestSuite result = createServerTestSuite();
result.addTestSuite(CurrentPageTest.class);
return (result);
}
static EventRegistration2 eventRegistration;
static CurrentPage2 currentPage = null;
static boolean keepWaiting;
//
// Constants
//
//
// ClipboardOwner
//
public void lostOwnership(Clipboard clipboard,
Transferable contents) {
}
//
// Testcases
//
public void testCopyCurrentSelectionToSystemClipboard() 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);
currentPage = (CurrentPage2)
firstBrowserControl.queryInterface(BrowserControl.CURRENT_PAGE_NAME);
assertNotNull(currentPage);
eventRegistration.addDocumentLoadListener(listener = new DocumentLoadListenerImpl() {
public void doEndCheck() {
CurrentPageTest.keepWaiting = false;
}
});
Thread.currentThread().sleep(3000);
//
// load four files.
//
CurrentPageTest.keepWaiting = true;
nav.loadURL("http://localhost:5243/HistoryTest0.html");
// keep waiting until the previous load completes
while (CurrentPageTest.keepWaiting) {
Thread.currentThread().sleep(1000);
}
CurrentPageTest.keepWaiting = true;
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable contents;
Thread.currentThread().sleep(3000);
currentPage.selectAll();
currentPage.copyCurrentSelectionToSystemClipboard();
contents = clipboard.getContents(this);
assertNotNull(contents);
DataFlavor bestTextFlavor = DataFlavor.getTextPlainUnicodeFlavor();
BufferedReader clipReader =
new BufferedReader(bestTextFlavor.getReaderForText(contents));
String contentLine;
StringBuffer buf = new StringBuffer();
while (null != (contentLine = clipReader.readLine())) {
buf.append(contentLine);
System.out.println(contentLine);
}
assertEquals("HistoryTest0This is page 0 of the history test.next",
buf.toString());
frame.setVisible(false);
BrowserControlFactory.deleteBrowserControl(firstBrowserControl);
}
}