diff options
Diffstat (limited to 'org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/RestrictedTopicParameter.java')
-rw-r--r-- | org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/RestrictedTopicParameter.java | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/RestrictedTopicParameter.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/RestrictedTopicParameter.java new file mode 100644 index 000000000..1a572e151 --- /dev/null +++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/RestrictedTopicParameter.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * Copyright (c) 2008 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + +package org.eclipse.ua.tests.help.webapp; + +import org.eclipse.help.internal.base.BaseHelpSystem; +import org.eclipse.help.internal.base.HelpBasePlugin; +import org.eclipse.help.internal.webapp.data.UrlUtil; + +import junit.framework.TestCase; + +/** + * Test for function which determines whether a topic path can be passed to the content frame + */ + +public class RestrictedTopicParameter extends TestCase { + + private static final String RESTRICT_TOPIC = "restrictTopicParameter"; + private boolean restrictTopic; + private int helpMode; + + protected void setUp() throws Exception { + restrictTopic = HelpBasePlugin.getDefault().getPluginPreferences().getBoolean(RESTRICT_TOPIC); + helpMode = BaseHelpSystem.getMode(); + } + + protected void tearDown() throws Exception { + setRestrictTopic(restrictTopic); + BaseHelpSystem.setMode(helpMode); + } + + private void setRestrictTopic(boolean isRestrict) { + HelpBasePlugin.getDefault().getPluginPreferences().setValue(RESTRICT_TOPIC, isRestrict); + } + + public void testWorkbenchMode() { + BaseHelpSystem.setMode(BaseHelpSystem.MODE_WORKBENCH); + setRestrictTopic(true); + assertTrue(UrlUtil.isValidTopicURL("http://www.eclipse.org")); + assertTrue(UrlUtil.isValidTopicURL("https://www.eclipse.org")); + setRestrictTopic(false); + assertTrue(UrlUtil.isValidTopicURL("http://www.eclipse.org")); + assertTrue(UrlUtil.isValidTopicURL("https://www.eclipse.org")); + } + + public void testStandaloneMode() { + BaseHelpSystem.setMode(BaseHelpSystem.MODE_STANDALONE); + setRestrictTopic(true); + assertTrue(UrlUtil.isValidTopicURL("http://www.eclipse.org")); + assertTrue(UrlUtil.isValidTopicURL("https://www.eclipse.org")); + setRestrictTopic(false); + assertTrue(UrlUtil.isValidTopicURL("http://www.eclipse.org")); + assertTrue(UrlUtil.isValidTopicURL("https://www.eclipse.org")); + } + + public void testInfocenterUnrestricted() { + BaseHelpSystem.setMode(BaseHelpSystem.MODE_INFOCENTER); + setRestrictTopic(false); + assertTrue(UrlUtil.isValidTopicURL("http://www.eclipse.org")); + assertTrue(UrlUtil.isValidTopicURL("https://www.eclipse.org")); + assertTrue(UrlUtil.isValidTopicURL("org.eclipse.platform.doc.user/reference/ref-43.htm")); + } + + public void testInfocenterResestricted() { + BaseHelpSystem.setMode(BaseHelpSystem.MODE_INFOCENTER); + setRestrictTopic(true); + assertFalse(UrlUtil.isValidTopicURL("http://www.eclipse.org")); + assertFalse(UrlUtil.isValidTopicURL("https://www.eclipse.org")); + assertFalse(UrlUtil.isValidTopicURL("HTTP://www.eclipse.org")); + assertFalse(UrlUtil.isValidTopicURL("file://somepath.html")); + assertTrue(UrlUtil.isValidTopicURL("org.eclipse.platform.doc.user/reference/ref-43.htm")); + } + +} |