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