@@ -208,13 +208,125 @@ struct DashboardWindowSmokeTests {
208208 #expect( controller. _testLinkBrowserActiveTabIndex == 0 )
209209 }
210210
211+ @Test func `dashboard link browser calculates final drag insertion indexes`() {
212+ let midpoints : [ CGFloat ] = [ 50 , 150 , 250 ]
213+ let cases : [ ( currentIndex: Int , locationX: CGFloat , targetIndex: Int ? , order: [ Int ] ) ] = [
214+ ( 0 , 100 , nil , [ 0 , 1 , 2 ] ) ,
215+ ( 0 , 150 , 1 , [ 1 , 0 , 2 ] ) ,
216+ ( 0 , 200 , 1 , [ 1 , 0 , 2 ] ) ,
217+ ( 0 , 300 , 2 , [ 1 , 2 , 0 ] ) ,
218+ ( 2 , 100 , 1 , [ 0 , 2 , 1 ] ) ,
219+ ( 2 , 0 , 0 , [ 2 , 0 , 1 ] ) ,
220+ ( 1 , 150 , nil , [ 0 , 1 , 2 ] ) ,
221+ ]
222+ for testCase in cases {
223+ let targetIndex = DashboardLinkBrowserTabBar . dropIndex (
224+ currentIndex: testCase. currentIndex,
225+ itemMidpoints: midpoints,
226+ locationX: testCase. locationX)
227+ #expect( targetIndex == testCase. targetIndex)
228+
229+ var order = Array ( midpoints. indices)
230+ if let targetIndex {
231+ let moved = order. remove ( at: testCase. currentIndex)
232+ order. insert ( moved, at: targetIndex)
233+ }
234+ #expect( order == testCase. order)
235+ }
236+ }
237+
238+ @Test func `dashboard link browser retires initial URL after later navigation`() throws {
239+ let view = DashboardLinkBrowserView ( websiteDataStore: . default( ) )
240+ defer { view. closeBrowser ( ) }
241+ let requestedURL = try #require( URL ( string: " http://127.0.0.1:1/short " ) )
242+ let currentURL = try #require( URL ( string: " http://127.0.0.1:1/final " ) )
243+ view. open ( requestedURL)
244+ let webView = try #require( view. _testActiveWebView)
245+ let initialNavigation = NSObject ( )
246+ view. _testStartNavigation ( initialNavigation, in: webView)
247+ view. navigationWillStart ( currentURL, in: webView)
248+
249+ view. open ( requestedURL)
250+ #expect( view. _testTabCount == 1 )
251+ #expect( view. _testActiveWebView === webView)
252+
253+ view. open ( currentURL)
254+ #expect( view. _testTabCount == 1 )
255+ #expect( view. _testActiveWebView === webView)
256+
257+ view. _testFinishNavigation ( initialNavigation, at: currentURL, in: webView)
258+ view. open ( requestedURL)
259+ #expect( view. _testTabCount == 1 )
260+ #expect( view. _testActiveWebView === webView)
261+
262+ view. _testStartNavigation ( NSObject ( ) , in: webView)
263+ view. navigationWillStart ( currentURL, in: webView)
264+ view. open ( requestedURL)
265+ #expect( view. _testTabCount == 2 )
266+ #expect( view. _testActiveWebView !== webView)
267+ }
268+
269+ @Test func `dashboard link browser retires initial URL when navigation is replaced`() throws {
270+ let view = DashboardLinkBrowserView ( websiteDataStore: . default( ) )
271+ defer { view. closeBrowser ( ) }
272+ let requestedURL = try #require( URL ( string: " http://127.0.0.1:1/short " ) )
273+ let redirectURL = try #require( URL ( string: " http://127.0.0.1:1/redirect " ) )
274+ let replacementURL = try #require( URL ( string: " http://127.0.0.1:1/replacement " ) )
275+ view. open ( requestedURL)
276+ let webView = try #require( view. _testActiveWebView)
277+ view. _testStartNavigation ( NSObject ( ) , in: webView)
278+ view. navigationWillStart ( redirectURL, in: webView)
279+ view. _testStartNavigation ( NSObject ( ) , in: webView)
280+ view. navigationWillStart ( replacementURL, in: webView)
281+
282+ view. open ( requestedURL)
283+
284+ #expect( view. _testTabCount == 2 )
285+ #expect( view. _testActiveWebView !== webView)
286+ }
287+
288+ @Test func `dashboard link browser retires initial URL when redirected navigation fails`() throws {
289+ let view = DashboardLinkBrowserView ( websiteDataStore: . default( ) )
290+ defer { view. closeBrowser ( ) }
291+ let requestedURL = try #require( URL ( string: " http://127.0.0.1:1/short " ) )
292+ let redirectURL = try #require( URL ( string: " http://127.0.0.1:1/redirect " ) )
293+ view. open ( requestedURL)
294+ let webView = try #require( view. _testActiveWebView)
295+ view. _testStartNavigation ( NSObject ( ) , in: webView)
296+ view. navigationWillStart ( redirectURL, in: webView)
297+ view. navigationDidFail ( for: webView)
298+
299+ view. open ( requestedURL)
300+
301+ #expect( view. _testTabCount == 2 )
302+ #expect( view. _testActiveWebView !== webView)
303+ }
304+
305+ @Test func `dashboard link browser prefers current URL over initial alias`() throws {
306+ let view = DashboardLinkBrowserView ( websiteDataStore: . default( ) )
307+ defer { view. closeBrowser ( ) }
308+ let requestedURL = try #require( URL ( string: " http://127.0.0.1:1/short " ) )
309+ let currentURL = try #require( URL ( string: " http://127.0.0.1:1/final " ) )
310+ view. open ( requestedURL)
311+ let redirectedWebView = try #require( view. _testActiveWebView)
312+ view. navigationWillStart ( currentURL, in: redirectedWebView)
313+ view. _testOpenInNewTab ( requestedURL)
314+ let currentWebView = try #require( view. _testActiveWebView)
315+ view. _testSelectTab ( at: 0 )
316+
317+ view. open ( requestedURL)
318+
319+ #expect( view. _testTabCount == 2 )
320+ #expect( view. _testActiveWebView === currentWebView)
321+ }
322+
211323 @Test func `dashboard link browser menu disables URL actions for blank tab`() throws {
212324 let view = DashboardLinkBrowserView ( websiteDataStore: . default( ) )
213325 let url = try #require( URL ( string: " http://127.0.0.1:1/blank " ) )
214326 view. open ( url)
215327 let webView = try #require( view. _testActiveWebView)
216328 #expect( webView. url == nil )
217- view. navigationDidFinish ( for: webView)
329+ view. navigationURLDidChange ( for: webView)
218330 let menu = try #require( view. _testContextMenu ( forTabAt: 0 ) )
219331 #expect( !menu. items [ 0 ] . isEnabled)
220332 #expect( !menu. items [ 1 ] . isEnabled)
0 commit comments