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