Coverage Report - org.eclipse.swtbot.swt.finder.widgets.BrowserAuthenticationListenerDelegate
 
Classes in this File Line Coverage Branch Coverage Complexity
BrowserAuthenticationListenerDelegate
0%
0/32
0%
0/8
6
 
 1  
 /*******************************************************************************
 2  
  * Copyright (c) 2010 Ketan Padegaonkar and others.
 3  
  * All rights reserved. This program and the accompanying materials
 4  
  * are made available under the terms of the Eclipse Public License v1.0
 5  
  * which accompanies this distribution, and is available at
 6  
  * http://www.eclipse.org/legal/epl-v10.html
 7  
  * 
 8  
  * Contributors:
 9  
  *     Ketan Padegaonkar - initial API and implementation
 10  
  *******************************************************************************/
 11  
 package org.eclipse.swtbot.swt.finder.widgets;
 12  
 
 13  
 import java.lang.reflect.Method;
 14  
 
 15  
 import org.apache.log4j.Logger;
 16  
 import org.eclipse.swt.SWT;
 17  
 import org.eclipse.swt.browser.Browser;
 18  
 import org.eclipse.swtbot.swt.finder.utils.Credentials;
 19  
 
 20  
 /**
 21  
  * Makes you cringe in your stomach. A workaround for java not being a real programming language. Wrapper for
 22  
  * BrowserAuthenticationListener that should only be used when {@link org.eclipse.swt.browser.AuthenticationListener} is
 23  
  * available. Requires SWT > v3.5.
 24  
  * 
 25  
  * @author Ketan Padegaonkar <KetanPadegaonkar [at] gmail [dot] com>
 26  
  */
 27  
 class BrowserAuthenticationListenerDelegate {
 28  
 
 29  
         private Object        delegate;
 30  
 
 31  0
         BrowserAuthenticationListenerDelegate() {
 32  0
                 if (SWT.getVersion() >= 3500) {
 33  
                         try {
 34  0
                                 this.delegate = Class.forName("org.eclipse.swtbot.swt.finder.widgets.BrowserAuthenticationListener").newInstance();
 35  0
                         } catch (ClassNotFoundException e) {
 36  0
                                 throw new RuntimeException(e);
 37  0
                         } catch (InstantiationException e) {
 38  0
                                 throw new RuntimeException(e);
 39  0
                         } catch (IllegalAccessException e) {
 40  0
                                 throw new RuntimeException(e);
 41  
                         }
 42  
                 } else {
 43  0
                         Logger log = Logger.getLogger(BrowserAuthenticationListenerDelegate.class);
 44  0
                         log.warn("You are running a version of SWT lower than v3.5. Browser authentication may not be available.");
 45  
                 }
 46  0
         }
 47  
 
 48  
         Credentials getCredentials() {
 49  0
                 if (this.delegate == null) {
 50  0
                         return null;
 51  
                 }
 52  
                 try {
 53  0
                         Method method = delegate.getClass().getMethod("getCredentials");
 54  0
                         return (Credentials) method.invoke(this.delegate);
 55  0
                 } catch (Exception e) {
 56  0
                         throw new RuntimeException(e);
 57  
                 }
 58  
         }
 59  
 
 60  
         void setCredentials(Credentials credentials) {
 61  0
                 if (this.delegate == null) {
 62  0
                         return;
 63  
                 }
 64  
                 try {
 65  0
                         Method method = delegate.getClass().getMethod("setCredentials", Credentials.class);
 66  0
                         method.invoke(this.delegate, credentials);
 67  0
                 } catch (Exception e) {
 68  0
                         throw new RuntimeException(e);
 69  
                 }
 70  0
         }
 71  
 
 72  
         void init(Browser widget) {
 73  0
                 if (this.delegate == null) {
 74  0
                         return;
 75  
                 }
 76  
                 try {
 77  0
                         Method method = delegate.getClass().getMethod("init", Browser.class);
 78  0
                         method.invoke(this.delegate, widget);
 79  0
                 } catch (Exception e) {
 80  0
                         throw new RuntimeException(e);
 81  
                 }
 82  0
         }
 83  
 
 84  
 }