|
| 1 | +/* |
| 2 | + * #%L |
| 3 | + * GwtMaterial |
| 4 | + * %% |
| 5 | + * Copyright (C) 2015 - 2020 GwtMaterialDesign |
| 6 | + * %% |
| 7 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | + * you may not use this file except in compliance with the License. |
| 9 | + * You may obtain a copy of the License at |
| 10 | + * |
| 11 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | + * |
| 13 | + * Unless required by applicable law or agreed to in writing, software |
| 14 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | + * See the License for the specific language governing permissions and |
| 17 | + * limitations under the License. |
| 18 | + * #L% |
| 19 | + */ |
| 20 | +/* |
| 21 | + * Copyright 2008 Google Inc. |
| 22 | + * |
| 23 | + * Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 24 | + * use this file except in compliance with the License. You may obtain a copy of |
| 25 | + * the License at |
| 26 | + * |
| 27 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 28 | + * |
| 29 | + * Unless required by applicable law or agreed to in writing, software |
| 30 | + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 31 | + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 32 | + * License for the specific language governing permissions and limitations under |
| 33 | + * the License. |
| 34 | + */ |
| 35 | +package com.google.gwt.junit; |
| 36 | + |
| 37 | +import com.google.gwt.core.ext.TreeLogger; |
| 38 | +import com.google.gwt.core.ext.UnableToCompleteException; |
| 39 | + |
| 40 | +import java.util.Collections; |
| 41 | +import java.util.Set; |
| 42 | + |
| 43 | +/** |
| 44 | + * An abstract class that handles the details of launching a browser. |
| 45 | + */ |
| 46 | +//TODO: Temporary workaround for old HTMLUnitTest that is not compatible with latest JQuery 3.x |
| 47 | +public abstract class RunStyle { |
| 48 | + |
| 49 | + /** |
| 50 | + * The containing shell. |
| 51 | + */ |
| 52 | + protected final JUnitShell shell; |
| 53 | + |
| 54 | + private int tries = 1; |
| 55 | + |
| 56 | + private Set<String> userAgents; |
| 57 | + |
| 58 | + /** |
| 59 | + * Constructor for RunStyle. Any subclass must provide a constructor with the |
| 60 | + * same signature since this will be how the RunStyle is created via |
| 61 | + * reflection. |
| 62 | + * |
| 63 | + * @param shell the containing shell |
| 64 | + */ |
| 65 | + public RunStyle(JUnitShell shell) { |
| 66 | + this.shell = shell; |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * Tests whether the test was interrupted. |
| 71 | + * |
| 72 | + * @return the interrupted hosts, or null if not interrupted |
| 73 | + */ |
| 74 | + public String[] getInterruptedHosts() { |
| 75 | + return null; |
| 76 | + } |
| 77 | + |
| 78 | + /** |
| 79 | + * Get the host name of the local system to use in URLs. This method returns |
| 80 | + * the host address instead of the host name in case the test target cannot |
| 81 | + * resolve the host name. |
| 82 | + * |
| 83 | + * @return the host name of the local system |
| 84 | + */ |
| 85 | + public String getLocalHostName() { |
| 86 | + return "localhost"; |
| 87 | + } |
| 88 | + |
| 89 | + /** |
| 90 | + * Returns the platforms specific to this run style. |
| 91 | + */ |
| 92 | + public Set<Platform> getPlatforms() { |
| 93 | + return Collections.emptySet(); |
| 94 | + } |
| 95 | + |
| 96 | + /** |
| 97 | + * Returns user agents for this run style. |
| 98 | + * |
| 99 | + * @return the user agents, or {@code null} if unknown |
| 100 | + */ |
| 101 | + public Set<String> getUserAgents() { |
| 102 | + return userAgents; |
| 103 | + } |
| 104 | + |
| 105 | + /** |
| 106 | + * Returns the number of times this test should be tried to run. A test |
| 107 | + * succeeds if it succeeds even once. |
| 108 | + * |
| 109 | + * @return the number of attempts |
| 110 | + */ |
| 111 | + public int getTries() { |
| 112 | + return tries; |
| 113 | + } |
| 114 | + |
| 115 | + /** |
| 116 | + * Initialize the runstyle with any supplied arguments, and return the number |
| 117 | + * of clients this runstyle controls. |
| 118 | + * |
| 119 | + * @param args arguments passed in -runStyle option, null if none supplied |
| 120 | + * @return the number of clients, or -1 if initialization was unsuccessful |
| 121 | + */ |
| 122 | + public abstract int initialize(String args); |
| 123 | + |
| 124 | + /** |
| 125 | + * Requests initial launch of the browser. This should only be called once per |
| 126 | + * instance of RunStyle. |
| 127 | + * |
| 128 | + * @param moduleName the module to run |
| 129 | + * @throws UnableToCompleteException |
| 130 | + */ |
| 131 | + public abstract void launchModule(String moduleName) |
| 132 | + throws UnableToCompleteException; |
| 133 | + |
| 134 | + /** |
| 135 | + * Sets the number of times a test should be tried -- it succeeds if any |
| 136 | + * attempt succeeds. |
| 137 | + * |
| 138 | + * @param tries number of attempts |
| 139 | + */ |
| 140 | + public void setTries(int tries) { |
| 141 | + this.tries = tries; |
| 142 | + } |
| 143 | + |
| 144 | + /** |
| 145 | + * Sets the associated user agents for this run style. |
| 146 | + */ |
| 147 | + public void setUserAgents(Set<String> userAgents) { |
| 148 | + this.userAgents = userAgents; |
| 149 | + } |
| 150 | + |
| 151 | + /** |
| 152 | + * Setup this RunStyle for the selected mode. |
| 153 | + * |
| 154 | + * @param logger TreeLogger to use for any messages |
| 155 | + * @param developmentMode true if we are running in development mode rather |
| 156 | + * that web/production mode |
| 157 | + * @return false if we should abort processing due to an unsupported mode or |
| 158 | + * an error setting up for that mode |
| 159 | + */ |
| 160 | + public boolean setupMode(TreeLogger logger, boolean developmentMode) { |
| 161 | + return true; |
| 162 | + } |
| 163 | + |
| 164 | + /** |
| 165 | + * Whether the embedded server should ever generate resources. Development |
| 166 | + * mode needs this, but not with -noserver. |
| 167 | + * |
| 168 | + * @return true if resources should be automatically generated by the server. |
| 169 | + */ |
| 170 | + public boolean shouldAutoGenerateResources() { |
| 171 | + // TODO(spoon) does Production Mode get simpler if this is turned on? |
| 172 | + return true; |
| 173 | + } |
| 174 | + |
| 175 | + /** |
| 176 | + * Gets the shell logger. |
| 177 | + */ |
| 178 | + protected TreeLogger getLogger() { |
| 179 | + return shell.getTopLogger(); |
| 180 | + } |
| 181 | +} |
0 commit comments