private URL getRawUrl() { // TODO(simon): I can see this being baaad. Page page = lastPage(); if (page == null) { return null; } return page.getUrl(); }
private static String getFileExtension(final Page enclosedPage) { if (enclosedPage != null) { if (enclosedPage.isHtmlPage()) { return "html"; } final URL url = enclosedPage.getUrl(); if (url.getPath().contains(".")) { return StringUtils.substringAfterLast(url.getPath(), "."); } } return ".unknown"; }
private static String getFileExtension(final Page enclosedPage) { if (enclosedPage != null) { if (enclosedPage.isHtmlPage()) { return "html"; } final URL url = enclosedPage.getUrl(); if (url.getPath().contains(".")) { return StringUtils.substringAfterLast(url.getPath(), "."); } } return ".unknown"; }
private static String getKey(final Type type, final Page page) { switch (type) { case GLOBAL_STORAGE: return page.getUrl().getHost(); case LOCAL_STORAGE: final URL url = page.getUrl(); return url.getProtocol() + "://" + url.getHost() + ':' + url.getProtocol(); case SESSION_STORAGE: final WebWindow topWindow = page.getEnclosingWindow() .getTopWindow(); return Integer.toHexString(topWindow.hashCode()); default: return null; } }
private static String getKey(final Type type, final Page page) { switch (type) { case GLOBAL_STORAGE: return page.getUrl().getHost(); case LOCAL_STORAGE: final URL url = page.getUrl(); return url.getProtocol() + "://" + url.getHost() + ':' + url.getProtocol(); case SESSION_STORAGE: final WebWindow topWindow = page.getEnclosingWindow() .getTopWindow(); return Integer.toHexString(topWindow.hashCode()); default: return null; } }
/** * Returns this location's current URL. * @return this location's current URL */ private URL getUrl() { return window_.getWebWindow().getEnclosedPage().getUrl(); }
/** * Returns this location's current URL. * @return this location's current URL */ private URL getUrl() { return window_.getWebWindow().getEnclosedPage().getUrl(); }
/** * {@inheritDoc} */ @Override protected boolean isJavaScriptInitializationNeeded() { final Page enclosedPage = getEnclosedPage(); return getScriptableObject() == null || enclosedPage.getUrl() == WebClient.URL_ABOUT_BLANK || !(enclosedPage.getWebResponse() instanceof StringWebResponse); // TODO: find a better way to distinguish content written by document.open(),... }
private static XmlPage createParserErrorXmlPage(final String message, final WebWindow webWindow) throws IOException { final String xml = "<parsererror xmlns=\"http://www.mozilla.org/newlayout/xml/parsererror.xml\">\n" + message + "\n" + "<sourcetext></sourcetext>\n" + "</parsererror>"; final WebResponse webResponse = new StringWebResponse(xml, webWindow.getEnclosedPage().getUrl()); return new XmlPage(webResponse, webWindow, false); }
/** * {@inheritDoc} */ @Override protected boolean isJavaScriptInitializationNeeded() { final Page enclosedPage = getEnclosedPage(); return getScriptableObject() == null || enclosedPage.getUrl() == WebClient.URL_ABOUT_BLANK || !(enclosedPage.getWebResponse() instanceof StringWebResponse); // TODO: find a better way to distinguish content written by document.open(),... }
private static XmlPage createParserErrorXmlPage(final String message, final WebWindow webWindow) throws IOException { final String xml = "<parsererror xmlns=\"http://www.mozilla.org/newlayout/xml/parsererror.xml\">\n" + message + "\n" + "<sourcetext></sourcetext>\n" + "</parsererror>"; final WebResponse webResponse = new StringWebResponse(xml, webWindow.getEnclosedPage().getUrl()); return new XmlPage(webResponse, webWindow, false); }
@Override public String getCurrentUrl() { getWebClient(); // check that session is active Page page = getCurrentWindow().getTopWindow().getEnclosedPage(); if (page == null) { return null; } URL url = page.getUrl(); if (url == null) { return null; } return url.toString(); }
/** * Initializes the object. * * @param window the window that this location belongs to */ public void initialize(final Window window) { window_ = window; if (window_ != null && window_.getWebWindow().getEnclosedPage() != null) { setHash(window_.getWebWindow().getEnclosedPage().getUrl().getRef()); } }
/** * Initializes the object. * * @param window the window that this location belongs to */ public void initialize(final Window window) { window_ = window; if (window_ != null && window_.getWebWindow().getEnclosedPage() != null) { setHash(window_.getWebWindow().getEnclosedPage().getUrl().getRef()); } }
/** * Constructor. * @param browserVersion the simulated browser version * @param worker the started worker * @throws Exception in case of problem */ DedicatedWorkerGlobalScope(final Window owningWindow, final Context context, final BrowserVersion browserVersion, final Worker worker) throws Exception { context.initStandardObjects(this); final ClassConfiguration config = AbstractJavaScriptConfiguration.getClassConfiguration( DedicatedWorkerGlobalScope.class, browserVersion); final HtmlUnitScriptable prototype = JavaScriptEngine.configureClass(config, null, browserVersion); setPrototype(prototype); owningWindow_ = owningWindow; final URL currentURL = owningWindow.getWebWindow().getEnclosedPage().getUrl(); origin_ = currentURL.getProtocol() + "://" + currentURL.getHost() + ':' + currentURL.getPort(); worker_ = worker; }
/** * Constructor. * @param browserVersion the simulated browser version * @param worker the started worker * @throws Exception in case of problem */ DedicatedWorkerGlobalScope(final Window owningWindow, final Context context, final BrowserVersion browserVersion, final Worker worker) throws Exception { context.initStandardObjects(this); final ClassConfiguration config = AbstractJavaScriptConfiguration.getClassConfiguration( DedicatedWorkerGlobalScope.class, browserVersion); final HtmlUnitScriptable prototype = JavaScriptEngine.configureClass(config, null, browserVersion); setPrototype(prototype); owningWindow_ = owningWindow; final URL currentURL = owningWindow.getWebWindow().getEnclosedPage().getUrl(); origin_ = currentURL.getProtocol() + "://" + currentURL.getHost() + ':' + currentURL.getPort(); worker_ = worker; }
/** * Loads the content of the contained frames. This is done after the page is completely loaded, to allow script * contained in the frames to reference elements from the page located after the closing </frame> tag. * @throws FailingHttpStatusCodeException if the server returns a failing status code AND the property * {@link WebClient#setThrowExceptionOnFailingStatusCode(boolean)} is set to {@code true} */ void loadFrames() throws FailingHttpStatusCodeException { for (final FrameWindow w : getFrames()) { final BaseFrameElement frame = w.getFrameElement(); // test if the frame should really be loaded: // if a script has already changed its content, it should be skipped // use == and not equals(...) to identify initial content (versus URL set to "about:blank") if (frame.getEnclosedWindow() != null && WebClient.URL_ABOUT_BLANK == frame.getEnclosedPage().getUrl() && !frame.isContentLoaded()) { frame.loadInnerPage(); } } }
/** * Test if the provided URL is the one of one of the parents which would cause an infinite loop. * @param url the URL to test * @return {@code false} if no parent has already this URL */ private boolean isAlreadyLoadedByAncestor(final URL url) { WebWindow window = getPage().getEnclosingWindow(); while (window != null) { if (UrlUtils.sameFile(url, window.getEnclosedPage().getUrl())) { return true; } if (window == window.getParentWindow()) { // TODO: should getParentWindow() return null on top windows? window = null; } else { window = window.getParentWindow(); } } return false; }
public <P extends Page> P getPage(Class<P> pageType, URL url) { Page page; try { page = client.getPage(url); } catch (FailingHttpStatusCodeException e) { throw AbstractTestCase.failure("Cannot get initial page", e); } catch (IOException e) { throw AbstractTestCase.failure("Cannot get initial page", e); } if (pageType.isInstance(page)) { currentPage = page; return pageType.cast(page); } else { throw AbstractTestCase.failure("Was expecting an HTML page instead of " + page + " for URL " + page.getUrl()); } }
/** * Loads the content of the contained frames. This is done after the page is completely loaded, to allow script * contained in the frames to reference elements from the page located after the closing </frame> tag. * @throws FailingHttpStatusCodeException if the server returns a failing status code AND the property * {@link WebClient#setThrowExceptionOnFailingStatusCode(boolean)} is set to {@code true} */ void loadFrames() throws FailingHttpStatusCodeException { for (final FrameWindow w : getFrames()) { final BaseFrameElement frame = w.getFrameElement(); // test if the frame should really be loaded: // if a script has already changed its content, it should be skipped // use == and not equals(...) to identify initial content (versus URL set to "about:blank") if (frame.getEnclosedWindow() != null && WebClient.URL_ABOUT_BLANK == frame.getEnclosedPage().getUrl() && !frame.isContentLoaded()) { frame.loadInnerPage(); } } }