|
1 | 1 | import * as TKUnit from '../../tk-unit'; |
2 | | -import { PercentLength, unsetValue, Frame } from '@nativescript/core'; |
| 2 | +import { PercentLength, unsetValue, Frame, Page } from '@nativescript/core'; |
3 | 3 | export * from './frame-tests-common'; |
4 | 4 |
|
5 | 5 | export function test_percent_width_and_height_set_to_page_support() { |
@@ -62,3 +62,34 @@ export function test_percent_margin_set_to_page_support() { |
62 | 62 | TKUnit.assertTrue(PercentLength.equals(currentPage.marginRight, 0)); |
63 | 63 | TKUnit.assertTrue(PercentLength.equals(currentPage.marginBottom, 0)); |
64 | 64 | } |
| 65 | + |
| 66 | +export function test_back_after_activity_recreation(done: (error?: Error) => void) { |
| 67 | + const frame = Frame.topmost(); |
| 68 | + frame.navigate({ create: () => new Page(), clearHistory: true, animated: false }); |
| 69 | + TKUnit.waitUntilReady(() => frame.navigationQueueIsEmpty(), 15); |
| 70 | + const previous = frame.currentPage; |
| 71 | + frame.navigate({ create: () => new Page(), animated: false }); |
| 72 | + TKUnit.waitUntilReady(() => frame.navigationQueueIsEmpty(), 15); |
| 73 | + const activity = frame.android.activity; |
| 74 | + activity.recreate(); |
| 75 | + |
| 76 | + const deadline = Date.now() + 10000; |
| 77 | + let wentBack = false; |
| 78 | + const poll = () => { |
| 79 | + try { |
| 80 | + if (!wentBack && frame.android.activity !== activity && frame.isLoaded && frame.currentPage.isLoaded) { |
| 81 | + wentBack = true; |
| 82 | + frame.goBack(); |
| 83 | + } else if (wentBack && frame.navigationQueueIsEmpty()) { |
| 84 | + TKUnit.assertEqual(frame.currentPage, previous, 'Back resumes after early native attachment'); |
| 85 | + done(); |
| 86 | + return; |
| 87 | + } |
| 88 | + TKUnit.assertTrue(Date.now() < deadline, wentBack ? 'Back navigation stalled after Activity recreation' : 'Activity recreated and Frame loaded'); |
| 89 | + setTimeout(poll, 50); |
| 90 | + } catch (e) { |
| 91 | + done(e); |
| 92 | + } |
| 93 | + }; |
| 94 | + setTimeout(poll, 50); |
| 95 | +} |
0 commit comments