1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
|
// Tags: GUI JDK1.3
// Copyright (C) 2006 Red Hat, Inc.
// Written by Gary Benson <gbenson@redhat.com>
// This file is part of Mauve.
// Mauve is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2, or (at your option)
// any later version.
// Mauve is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Mauve; see the file COPYING. If not, write to
// the Free Software Foundation, 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.
package gnu.testlet.java.awt.Toolkit;
import java.awt.AWTEvent;
import java.awt.AWTPermission;
import java.awt.Frame;
import java.awt.JobAttributes;
import java.awt.PageAttributes;
import java.awt.Toolkit;
import java.awt.event.AWTEventListener;
import java.security.Permission;
import java.util.Properties;
import gnu.testlet.Testlet;
import gnu.testlet.TestHarness;
import gnu.testlet.TestSecurityManager;
public class security implements Testlet
{
public void test(TestHarness harness)
{
try {
Toolkit toolkit = Toolkit.getDefaultToolkit();
toolkit.getSystemEventQueue();
AWTEventListener listener = new TestEventListener();
Frame frame = new Frame();
Properties props = new Properties();
JobAttributes jobattrs = new JobAttributes();
PageAttributes pageattrs = new PageAttributes();
Permission[] listenToAllAWTEvents = new Permission[] {
new AWTPermission("listenToAllAWTEvents")};
Permission[] queuePrintJob = new Permission[] {
new RuntimePermission("queuePrintJob")};
Permission[] accessClipboard = new Permission[] {
new AWTPermission("accessClipboard")};
Permission[] accessEventQueue = new Permission[] {
new AWTPermission("accessEventQueue")};
TestSecurityManager sm = new TestSecurityManager(harness);
try {
sm.install();
// throwpoint: java.awt.Toolkit-addAWTEventListener
harness.checkPoint("addAWTEventListener");
try {
sm.prepareChecks(listenToAllAWTEvents);
toolkit.addAWTEventListener(listener, AWTEvent.KEY_EVENT_MASK);
sm.checkAllChecked();
}
catch (SecurityException ex) {
harness.debug(ex);
harness.check(false, "unexpected check");
}
// throwpoint: java.awt.Toolkit-removeAWTEventListener
harness.checkPoint("removeAWTEventListener");
try {
sm.prepareChecks(listenToAllAWTEvents);
toolkit.removeAWTEventListener(listener);
sm.checkAllChecked();
}
catch (SecurityException ex) {
harness.debug(ex);
harness.check(false, "unexpected check");
}
// throwpoint: java.awt.Toolkit-getPrintJob(Frame, String, Properties)
harness.checkPoint("getPrintJob(3-arg)");
try {
sm.prepareHaltingChecks(queuePrintJob);
toolkit.getPrintJob(frame, "Test job", props);
harness.check(false);
}
catch (TestSecurityManager.SuccessException ex) {
harness.check(true);
}
catch (SecurityException ex) {
harness.debug(ex);
harness.check(false, "unexpected check");
}
// throwpoint: java.awt.Toolkit-getPrintJob(Frame, String, JobAttributes, PageAttributes)
harness.checkPoint("getPrintJob(4-arg)");
try {
sm.prepareHaltingChecks(queuePrintJob);
toolkit.getPrintJob(frame, "Test job", jobattrs, pageattrs);
harness.check(false);
}
catch (TestSecurityManager.SuccessException ex) {
harness.check(true);
}
catch (SecurityException ex) {
harness.debug(ex);
harness.check(false, "unexpected check");
}
// throwpoint: java.awt.Toolkit-getSystemClipboard
harness.checkPoint("getSystemClipboard");
try {
sm.prepareChecks(accessClipboard);
toolkit.getSystemClipboard();
sm.checkAllChecked();
}
catch (SecurityException ex) {
harness.debug(ex);
harness.check(false, "unexpected check");
}
// throwpoint: java.awt.Toolkit-getSystemEventQueue
harness.checkPoint("getSystemEventQueue");
try {
sm.prepareChecks(accessEventQueue);
toolkit.getSystemEventQueue();
sm.checkAllChecked();
}
catch (SecurityException ex) {
harness.debug(ex);
harness.check(false, "unexpected check");
}
}
finally {
sm.uninstall();
}
}
catch (Exception ex) {
harness.debug(ex);
harness.check(false, "Unexpected exception");
}
}
private static class TestEventListener implements AWTEventListener
{
public void eventDispatched(AWTEvent event)
{
}
}
}
|