1*ca5bdfe8SCarl Marcum /** 2*ca5bdfe8SCarl Marcum * Licensed to the Apache Software Foundation (ASF) under one 3*ca5bdfe8SCarl Marcum * or more contributor license agreements. See the NOTICE file 4*ca5bdfe8SCarl Marcum * distributed with this work for additional information 5*ca5bdfe8SCarl Marcum * regarding copyright ownership. The ASF licenses this file 6*ca5bdfe8SCarl Marcum * to you under the Apache License, Version 2.0 (the 7*ca5bdfe8SCarl Marcum * "License"); you may not use this file except in compliance 8*ca5bdfe8SCarl Marcum * with the License. You may obtain a copy of the License at 9*ca5bdfe8SCarl Marcum * <p> 10*ca5bdfe8SCarl Marcum * http://www.apache.org/licenses/LICENSE-2.0 11*ca5bdfe8SCarl Marcum * <p> 12*ca5bdfe8SCarl Marcum * Unless required by applicable law or agreed to in writing, 13*ca5bdfe8SCarl Marcum * software distributed under the License is distributed on an 14*ca5bdfe8SCarl Marcum * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15*ca5bdfe8SCarl Marcum * KIND, either express or implied. See the License for the 16*ca5bdfe8SCarl Marcum * specific language governing permissions and limitations 17*ca5bdfe8SCarl Marcum * under the License. 18*ca5bdfe8SCarl Marcum */ 19*ca5bdfe8SCarl Marcum 20*ca5bdfe8SCarl Marcum package fvt.gui.sw.hyperlink; 21*ca5bdfe8SCarl Marcum 22*ca5bdfe8SCarl Marcum import static org.junit.Assert.*; 23*ca5bdfe8SCarl Marcum import static org.openoffice.test.common.Testspace.*; 24*ca5bdfe8SCarl Marcum import static org.openoffice.test.vcl.Tester.*; 25*ca5bdfe8SCarl Marcum import static testlib.gui.AppTool.*; 26*ca5bdfe8SCarl Marcum import static testlib.gui.UIMap.*; 27*ca5bdfe8SCarl Marcum 28*ca5bdfe8SCarl Marcum import java.awt.Rectangle; 29*ca5bdfe8SCarl Marcum import java.io.File; 30*ca5bdfe8SCarl Marcum 31*ca5bdfe8SCarl Marcum import org.junit.AfterClass; 32*ca5bdfe8SCarl Marcum import org.junit.Before; 33*ca5bdfe8SCarl Marcum import org.junit.BeforeClass; 34*ca5bdfe8SCarl Marcum import org.junit.Rule; 35*ca5bdfe8SCarl Marcum import org.junit.Test; 36*ca5bdfe8SCarl Marcum 37*ca5bdfe8SCarl Marcum import org.junit.runner.RunWith; 38*ca5bdfe8SCarl Marcum import org.junit.runners.Parameterized; 39*ca5bdfe8SCarl Marcum import org.junit.runners.Parameterized.Parameters; 40*ca5bdfe8SCarl Marcum 41*ca5bdfe8SCarl Marcum import java.util.Arrays; 42*ca5bdfe8SCarl Marcum import java.util.Collection; 43*ca5bdfe8SCarl Marcum 44*ca5bdfe8SCarl Marcum import org.openoffice.test.common.FileUtil; 45*ca5bdfe8SCarl Marcum import org.openoffice.test.common.GraphicsUtil; 46*ca5bdfe8SCarl Marcum import org.openoffice.test.common.Logger; 47*ca5bdfe8SCarl Marcum 48*ca5bdfe8SCarl Marcum import testlib.gui.SCTool; 49*ca5bdfe8SCarl Marcum 50*ca5bdfe8SCarl Marcum /** 51*ca5bdfe8SCarl Marcum * Class to test that clicking certain hyperlinks in a document display 52*ca5bdfe8SCarl Marcum * a warning dialog. 53*ca5bdfe8SCarl Marcum */ 54*ca5bdfe8SCarl Marcum @RunWith(Parameterized.class) 55*ca5bdfe8SCarl Marcum public class WarningDialog { 56*ca5bdfe8SCarl Marcum 57*ca5bdfe8SCarl Marcum private String link; 58*ca5bdfe8SCarl Marcum private String type; 59*ca5bdfe8SCarl Marcum 60*ca5bdfe8SCarl Marcum @Parameters data()61*ca5bdfe8SCarl Marcum public static Collection<Object[]> data() { 62*ca5bdfe8SCarl Marcum return Arrays.asList(new Object[][]{ 63*ca5bdfe8SCarl Marcum // links with extensions 64*ca5bdfe8SCarl Marcum {"nfs://nonexistant.url.com/evil.jar", "nfs with .jar"}, 65*ca5bdfe8SCarl Marcum {"dav://nonexistant.url.com/evil.jar", "dav with .jar"}, 66*ca5bdfe8SCarl Marcum {"smb://nonexistant.url.com/evil.jar", "smb with .jar"}, 67*ca5bdfe8SCarl Marcum // with path and no extension 68*ca5bdfe8SCarl Marcum {"nfs://nonexistant.url.com/evil", "nfs with path"}, 69*ca5bdfe8SCarl Marcum {"dav://nonexistant.url.com/evil", "dav with path"}, 70*ca5bdfe8SCarl Marcum {"smb://nonexistant.url.com/evil", "smb with path"}, 71*ca5bdfe8SCarl Marcum // host only 72*ca5bdfe8SCarl Marcum {"nfs://nonexistant.url.com", "nfs host only"}, 73*ca5bdfe8SCarl Marcum {"dav://nonexistant.url.com", "dav host only"}, 74*ca5bdfe8SCarl Marcum {"smb://nonexistant.url.com", "smb host only"} 75*ca5bdfe8SCarl Marcum }); 76*ca5bdfe8SCarl Marcum } 77*ca5bdfe8SCarl Marcum 78*ca5bdfe8SCarl Marcum @Rule 79*ca5bdfe8SCarl Marcum public Logger log = Logger.getLogger(this); 80*ca5bdfe8SCarl Marcum 81*ca5bdfe8SCarl Marcum @BeforeClass beforeClass()82*ca5bdfe8SCarl Marcum public static void beforeClass() { 83*ca5bdfe8SCarl Marcum app.clean(); 84*ca5bdfe8SCarl Marcum } 85*ca5bdfe8SCarl Marcum 86*ca5bdfe8SCarl Marcum @AfterClass afterClass()87*ca5bdfe8SCarl Marcum public static void afterClass() { 88*ca5bdfe8SCarl Marcum app.stop(); 89*ca5bdfe8SCarl Marcum } 90*ca5bdfe8SCarl Marcum 91*ca5bdfe8SCarl Marcum @Before before()92*ca5bdfe8SCarl Marcum public void before() { 93*ca5bdfe8SCarl Marcum app.stop(); 94*ca5bdfe8SCarl Marcum app.start(); 95*ca5bdfe8SCarl Marcum } 96*ca5bdfe8SCarl Marcum WarningDialog(String link, String type)97*ca5bdfe8SCarl Marcum public WarningDialog(String link, String type) { 98*ca5bdfe8SCarl Marcum this.link = link; 99*ca5bdfe8SCarl Marcum this.type = type; 100*ca5bdfe8SCarl Marcum } 101*ca5bdfe8SCarl Marcum 102*ca5bdfe8SCarl Marcum /** 103*ca5bdfe8SCarl Marcum * Test open a hyperlink in a text document. 104*ca5bdfe8SCarl Marcum * 1. New a text document 105*ca5bdfe8SCarl Marcum * 2. Insert a hyperlink 106*ca5bdfe8SCarl Marcum * 3. Open hyperlink 107*ca5bdfe8SCarl Marcum * 4. Verify security warning dialog is displayed 108*ca5bdfe8SCarl Marcum * 109*ca5bdfe8SCarl Marcum * @throws Exception 110*ca5bdfe8SCarl Marcum */ 111*ca5bdfe8SCarl Marcum @Test testHyperlinkDisplaysWarning()112*ca5bdfe8SCarl Marcum public void testHyperlinkDisplaysWarning() throws Exception { 113*ca5bdfe8SCarl Marcum // Create a new text document 114*ca5bdfe8SCarl Marcum newTextDocument(); 115*ca5bdfe8SCarl Marcum writer.waitForExistence(10, 2); 116*ca5bdfe8SCarl Marcum // open the hyperlink dialog 117*ca5bdfe8SCarl Marcum writer.typeKeys("<alt i>"); // insert menu 118*ca5bdfe8SCarl Marcum writer.typeKeys("h"); // hyperlink 119*ca5bdfe8SCarl Marcum hyperlinkInetPathComboBox.setText(link); //target 120*ca5bdfe8SCarl Marcum hyperlinkInetText.setText(link); // displayed text 121*ca5bdfe8SCarl Marcum hyperlinkDialogOkBtn.click(); // apply 122*ca5bdfe8SCarl Marcum hyperlinkDialogCancelBtn.click(); // close 123*ca5bdfe8SCarl Marcum sleep(1); 124*ca5bdfe8SCarl Marcum typeKeys("<shift F10>"); // context menu 125*ca5bdfe8SCarl Marcum typeKeys("o"); // open hyperlink 126*ca5bdfe8SCarl Marcum // we can't be sure of the language so just check for the dialog 127*ca5bdfe8SCarl Marcum boolean msgExists = activeMsgBox.exists(1); // wait 1 second for the dialog 128*ca5bdfe8SCarl Marcum if (msgExists) { 129*ca5bdfe8SCarl Marcum activeMsgBox.no(); // close dialog 130*ca5bdfe8SCarl Marcum } 131*ca5bdfe8SCarl Marcum assertTrue("warning not displayed for " + type, msgExists); 132*ca5bdfe8SCarl Marcum discard(); 133*ca5bdfe8SCarl Marcum } 134*ca5bdfe8SCarl Marcum 135*ca5bdfe8SCarl Marcum }