Coverage Report - org.eclipse.swtbot.swt.finder.widgets.BrowserAuthenticationListener
 
Classes in this File Line Coverage Branch Coverage Complexity
BrowserAuthenticationListener
0%
0/13
0%
0/2
1.4
BrowserAuthenticationListener$1
0%
0/4
N/A
1.4
 
 1  0
 /*******************************************************************************
 2  
  * Copyright (c) 2010 Obeo 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  
  *     Mariot Chauvin, Obeo - initial API and implementation
 10  
  *******************************************************************************/
 11  
 
 12  
 package org.eclipse.swtbot.swt.finder.widgets;
 13  
 
 14  
 import org.eclipse.swt.browser.AuthenticationEvent;
 15  
 import org.eclipse.swt.browser.AuthenticationListener;
 16  
 import org.eclipse.swt.browser.Browser;
 17  
 import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
 18  
 import org.eclipse.swtbot.swt.finder.results.VoidResult;
 19  
 import org.eclipse.swtbot.swt.finder.utils.Credentials;
 20  
 
 21  
 /**
 22  
  * A browser authentication listener.
 23  
  * This implementation requires SWT 3.5 or later version.
 24  
  * @author mchauvin
 25  
  */
 26  0
 final class BrowserAuthenticationListener implements AuthenticationListener {
 27  
         
 28  
         private Credentials        credentials;
 29  
 
 30  
         public void init(final Browser widget) {
 31  0
                 UIThreadRunnable.syncExec(new VoidResult() {
 32  
                         public void run() {
 33  0
                                 widget.addAuthenticationListener(BrowserAuthenticationListener.this);
 34  0
                         }
 35  
                 });
 36  0
         }
 37  
         
 38  
         public void setCredentials(Credentials credentials) {
 39  0
                 this.credentials = credentials;
 40  0
         }
 41  
 
 42  
         public Credentials getCredentials() {
 43  0
                 return this.credentials;
 44  
         }
 45  
 
 46  
         public void authenticate(AuthenticationEvent event) {
 47  0
                 if (credentials == null) {
 48  0
                         event.doit = false;
 49  0
                         return;
 50  
                 }
 51  0
                 event.doit = true;
 52  0
                 event.user = credentials.username();
 53  0
                 event.password = credentials.password();
 54  0
         }
 55  
 
 56  
 }