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