@@ -70,37 +70,44 @@ public class DefaultSession implements Session {
70
70
private final KnownElements knownElements ;
71
71
private final ThreadPoolExecutor executor ;
72
72
private final Capabilities capabilities ; // todo: Investigate memory model implications of map
73
+ private final Clock clock ;
73
74
// elements inside capabilities.
74
75
private volatile String base64EncodedImage ;
75
76
private volatile long lastAccess ;
76
77
private volatile Thread inUseWithThread = null ;
77
78
private TemporaryFilesystem tempFs ;
78
79
79
80
// This method is to avoid constructor escape of partially constructed session object
80
- public static Session createSession (DriverFactory factory ,
81
- SessionId sessionId , Capabilities capabilities )
82
- throws Exception {
81
+ public static Session createSession (DriverFactory factory , SessionId sessionId ,
82
+ Capabilities capabilities ) throws Exception {
83
+ return createSession (factory , new SystemClock (), sessionId , capabilities );
84
+ }
85
+
86
+ // This method is to avoid constructor escape of partially constructed session object
87
+ public static Session createSession (DriverFactory factory , Clock clock , SessionId sessionId ,
88
+ Capabilities capabilities ) throws Exception {
83
89
File tmpDir = new File (System .getProperty ("java.io.tmpdir" ), sessionId .toString ());
84
90
if (!tmpDir .mkdir ()) {
85
91
throw new WebDriverException ("Cannot create temp directory: " + tmpDir );
86
92
}
87
93
TemporaryFilesystem tempFs = TemporaryFilesystem .getTmpFsBasedOn (tmpDir );
88
94
89
- return new DefaultSession (factory , tempFs , sessionId , capabilities );
95
+ return new DefaultSession (factory , tempFs , clock , sessionId , capabilities );
90
96
}
91
97
92
98
@ VisibleForTesting
93
- public static Session createSession (DriverFactory factory , TemporaryFilesystem tempFs ,
99
+ public static Session createSession (DriverFactory factory , TemporaryFilesystem tempFs , Clock clock ,
94
100
SessionId sessionId , Capabilities capabilities )
95
101
throws Exception {
96
- return new DefaultSession (factory , tempFs , sessionId , capabilities );
102
+ return new DefaultSession (factory , tempFs , clock , sessionId , capabilities );
97
103
}
98
104
99
- private DefaultSession (final DriverFactory factory , TemporaryFilesystem tempFs ,
105
+ private DefaultSession (final DriverFactory factory , TemporaryFilesystem tempFs , Clock clock ,
100
106
SessionId sessionId , final Capabilities capabilities ) throws Exception {
101
107
this .knownElements = new KnownElements ();
102
108
this .sessionId = sessionId ;
103
109
this .tempFs = tempFs ;
110
+ this .clock = clock ;
104
111
final BrowserCreator browserCreator = new BrowserCreator (factory , capabilities );
105
112
final FutureTask <EventFiringWebDriver > webDriverFutureTask =
106
113
new FutureTask <EventFiringWebDriver >(browserCreator );
@@ -141,11 +148,11 @@ private static boolean isQuietModeEnabled(BrowserCreator browserCreator, Capabil
141
148
* Touches the session.
142
149
*/
143
150
public void updateLastAccessTime () {
144
- lastAccess = System . currentTimeMillis ();
151
+ lastAccess = clock . now ();
145
152
}
146
153
147
154
public boolean isTimedOut (long timeout ) {
148
- return timeout > 0 && (lastAccess + timeout ) < System . currentTimeMillis ();
155
+ return timeout > 0 && (lastAccess + timeout ) < clock . now ();
149
156
}
150
157
151
158
public void close () {
0 commit comments