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 {"smb://nonexistant.url.com", "smb host only"} 75 }); 76 } 77 78 @Rule 79 public Logger log = Logger.getLogger(this); 80 81 @BeforeClass beforeClass()82 public static void beforeClass() { 83 app.clean(); 84 } 85 86 @AfterClass afterClass()87 public static void afterClass() { 88 app.stop(); 89 } 90 91 @Before before()92 public void before() { 93 app.stop(); 94 app.start(); 95 } 96 WarningDialog(String link, String type)97 public WarningDialog(String link, String type) { 98 this.link = link; 99 this.type = type; 100 } 101 102 /** 103 * Test open a hyperlink in a text document. 104 * 1. New a text document 105 * 2. Insert a hyperlink 106 * 3. Open hyperlink 107 * 4. Verify security warning dialog is displayed 108 * 109 * @throws Exception 110 */ 111 @Test testHyperlinkDisplaysWarning()112 public void testHyperlinkDisplaysWarning() throws Exception { 113 // Create a new text document 114 newTextDocument(); 115 writer.waitForExistence(10, 2); 116 // open the hyperlink dialog 117 writer.typeKeys("<alt i>"); // insert menu 118 writer.typeKeys("h"); // hyperlink 119 hyperlinkInetPathComboBox.setText(link); //target 120 hyperlinkInetText.setText(link); // displayed text 121 hyperlinkDialogOkBtn.click(); // apply 122 hyperlinkDialogCancelBtn.click(); // close 123 sleep(1); 124 typeKeys("<shift F10>"); // context menu 125 typeKeys("o"); // open hyperlink 126 // we can't be sure of the language so just check for the dialog 127 boolean msgExists = activeMsgBox.exists(1); // wait 1 second for the dialog 128 if (msgExists) { 129 activeMsgBox.no(); // close dialog 130 } 131 assertTrue("warning not displayed for " + type, msgExists); 132 discard(); 133 } 134 135 }