| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import <objc/runtime.h> | 5 #import <objc/runtime.h> |
| 6 | 6 |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/mac/scoped_nsautorelease_pool.h" | 8 #include "base/mac/scoped_nsautorelease_pool.h" |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 820 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 831 | 831 |
| 832 NSString* stashPath = | 832 NSString* stashPath = |
| 833 base::SysUTF8ToNSString(chrome_browser_state->GetStatePath().value()); | 833 base::SysUTF8ToNSString(chrome_browser_state->GetStatePath().value()); |
| 834 | 834 |
| 835 base::scoped_nsobject<TabModel> model([[TabModel alloc] | 835 base::scoped_nsobject<TabModel> model([[TabModel alloc] |
| 836 initWithSessionWindow:session_window_.get() | 836 initWithSessionWindow:session_window_.get() |
| 837 sessionService:[SessionServiceIOS sharedService] | 837 sessionService:[SessionServiceIOS sharedService] |
| 838 browserState:chrome_browser_state.get()]); | 838 browserState:chrome_browser_state.get()]); |
| 839 | 839 |
| 840 [model addTabWithURL:kURL referrer:kReferrer windowName:@"window 1"]; | 840 [model addTabWithURL:kURL referrer:kReferrer windowName:@"window 1"]; |
| 841 [model addTabWithURL:kURL referrer:kReferrer windowName:@"window 2"]; | 841 [model insertTabWithURL:kURL |
| 842 [model addTabWithURL:kURL referrer:kReferrer windowName:@"window 3"]; | 842 referrer:kReferrer |
| 843 windowName:@"window 3" |
| 844 opener:[model tabAtIndex:0] |
| 845 atIndex:[model count]]; |
| 846 [model insertTabWithURL:kURL |
| 847 referrer:kReferrer |
| 848 windowName:@"window 3" |
| 849 opener:[model tabAtIndex:1] |
| 850 atIndex:0]; |
| 843 | 851 |
| 844 ASSERT_EQ(3U, [model count]); | 852 ASSERT_EQ(3U, [model count]); |
| 845 model.get().currentTab = [model tabAtIndex:1]; | 853 [model setCurrentTab:[model tabAtIndex:1]]; |
| 854 |
| 855 EXPECT_EQ(nil, [model openerOfTab:[model tabAtIndex:1]]); |
| 856 EXPECT_EQ([model tabAtIndex:1], [model openerOfTab:[model tabAtIndex:2]]); |
| 857 EXPECT_EQ([model tabAtIndex:2], [model openerOfTab:[model tabAtIndex:0]]); |
| 858 |
| 846 // Force state to flush to disk on the main thread so it can be immediately | 859 // Force state to flush to disk on the main thread so it can be immediately |
| 847 // tested below. | 860 // tested below. |
| 848 SessionWindowIOS* window = [model windowForSavingSession]; | 861 SessionWindowIOS* window = [model windowForSavingSession]; |
| 849 [[SessionServiceIOS sharedService] performSaveWindow:window | 862 [[SessionServiceIOS sharedService] performSaveWindow:window |
| 850 toDirectory:stashPath]; | 863 toDirectory:stashPath]; |
| 851 [model browserStateDestroyed]; | 864 [model browserStateDestroyed]; |
| 852 model.reset(); | 865 model.reset(); |
| 853 | 866 |
| 854 // Restoring TabModel session sends asynchronous tasks to IO thread, wait | 867 // Restoring TabModel session sends asynchronous tasks to IO thread, wait |
| 855 // for them to complete after destroying the TabModel. | 868 // for them to complete after destroying the TabModel. |
| 856 base::RunLoop().RunUntilIdle(); | 869 base::RunLoop().RunUntilIdle(); |
| 857 | 870 |
| 858 SessionWindowIOS* sessionWindow = [[SessionServiceIOS sharedService] | 871 SessionWindowIOS* sessionWindow = [[SessionServiceIOS sharedService] |
| 859 loadWindowForBrowserState:chrome_browser_state.get()]; | 872 loadWindowForBrowserState:chrome_browser_state.get()]; |
| 860 | 873 |
| 861 // Create tab model from saved session. | 874 // Create tab model from saved session. |
| 862 base::scoped_nsobject<TestSessionService> test_service( | 875 base::scoped_nsobject<TestSessionService> test_service( |
| 863 [[TestSessionService alloc] init]); | 876 [[TestSessionService alloc] init]); |
| 864 | 877 |
| 865 model.reset([[TabModel alloc] | 878 model.reset([[TabModel alloc] |
| 866 initWithSessionWindow:sessionWindow | 879 initWithSessionWindow:sessionWindow |
| 867 sessionService:test_service | 880 sessionService:test_service |
| 868 browserState:chrome_browser_state.get()]); | 881 browserState:chrome_browser_state.get()]); |
| 869 EXPECT_EQ(model.get().currentTab, [model tabAtIndex:1]); | 882 ASSERT_EQ(3u, [model count]); |
| 883 |
| 884 EXPECT_EQ([model tabAtIndex:1], [model currentTab]); |
| 885 EXPECT_EQ(nil, [model openerOfTab:[model tabAtIndex:1]]); |
| 886 EXPECT_EQ([model tabAtIndex:1], [model openerOfTab:[model tabAtIndex:2]]); |
| 887 EXPECT_EQ([model tabAtIndex:2], [model openerOfTab:[model tabAtIndex:0]]); |
| 888 |
| 870 [model browserStateDestroyed]; | 889 [model browserStateDestroyed]; |
| 871 model.reset(); | 890 model.reset(); |
| 872 | 891 |
| 873 // Restoring TabModel session sends asynchronous tasks to IO thread, wait | 892 // Restoring TabModel session sends asynchronous tasks to IO thread, wait |
| 874 // for them to complete after destroying the TabModel. | 893 // for them to complete after destroying the TabModel. |
| 875 base::RunLoop().RunUntilIdle(); | 894 base::RunLoop().RunUntilIdle(); |
| 876 | 895 |
| 877 // Clean up. | 896 // Clean up. |
| 878 EXPECT_TRUE([[NSFileManager defaultManager] removeItemAtPath:stashPath | 897 EXPECT_TRUE([[NSFileManager defaultManager] removeItemAtPath:stashPath |
| 879 error:nullptr]); | 898 error:nullptr]); |
| 880 } | 899 } |
| 881 | 900 |
| 882 } // anonymous namespace | 901 } // anonymous namespace |
| OLD | NEW |