| Index: ios/chrome/browser/tabs/tab_model_unittest.mm
|
| diff --git a/ios/chrome/browser/tabs/tab_model_unittest.mm b/ios/chrome/browser/tabs/tab_model_unittest.mm
|
| index 164651983a996068ff58d8841dd72a8d15f732dc..6f182aa5468efab192e61b10fa0eb2a020456341 100644
|
| --- a/ios/chrome/browser/tabs/tab_model_unittest.mm
|
| +++ b/ios/chrome/browser/tabs/tab_model_unittest.mm
|
| @@ -84,22 +84,40 @@ class TabModelTest : public PlatformTest {
|
| chrome_browser_state_ = test_cbs_builder.Build();
|
|
|
| session_window_.reset([[SessionWindowIOS alloc] init]);
|
| +
|
| // Create tab model with just a dummy session service so the async state
|
| // saving doesn't trigger unless actually wanted.
|
| - base::scoped_nsobject<TestSessionService> test_service(
|
| - [[TestSessionService alloc] init]);
|
| - tab_model_.reset([[TabModel alloc]
|
| - initWithSessionWindow:session_window_.get()
|
| - sessionService:test_service
|
| - browserState:chrome_browser_state_.get()]);
|
| - [tab_model_ setWebUsageEnabled:NO];
|
| - [tab_model_ setPrimary:YES];
|
| + SetTabModel(
|
| + CreateTabModel([[[TestSessionService alloc] init] autorelease], nil));
|
| }
|
|
|
| ~TabModelTest() override {
|
| [tab_model_ browserStateDestroyed];
|
| }
|
|
|
| + void SetTabModel(base::scoped_nsobject<TabModel> tab_model) {
|
| + if (tab_model_) {
|
| + @autoreleasepool {
|
| + [tab_model_ browserStateDestroyed];
|
| + tab_model_.reset();
|
| + }
|
| + }
|
| +
|
| + tab_model_ = tab_model;
|
| + }
|
| +
|
| + base::scoped_nsobject<TabModel> CreateTabModel(
|
| + SessionServiceIOS* session_service,
|
| + SessionWindowIOS* session_window) {
|
| + base::scoped_nsobject<TabModel> tab_model([[TabModel alloc]
|
| + initWithSessionWindow:session_window
|
| + sessionService:session_service
|
| + browserState:chrome_browser_state_.get()]);
|
| + [tab_model setWebUsageEnabled:NO];
|
| + [tab_model setPrimary:YES];
|
| + return tab_model;
|
| + }
|
| +
|
| protected:
|
| // Creates a session window with entries named "restored window 1",
|
| // "restored window 2" and "restored window 3" and the second entry
|
| @@ -1091,6 +1109,12 @@ TEST_F(TabModelTest, PersistSelectionChange) {
|
| NSString* stashPath =
|
| base::SysUTF8ToNSString(chrome_browser_state_->GetStatePath().value());
|
|
|
| + // Reset the TabModel with a custom SessionServiceIOS (to control whether
|
| + // data is saved to disk).
|
| + base::scoped_nsobject<TestSessionService> test_session_service(
|
| + [[TestSessionService alloc] init]);
|
| + SetTabModel(CreateTabModel(test_session_service.get(), nil));
|
| +
|
| [tab_model_ insertTabWithURL:GURL(kURL1)
|
| referrer:web::Referrer()
|
| transition:ui::PAGE_TRANSITION_TYPED
|
| @@ -1124,27 +1148,20 @@ TEST_F(TabModelTest, PersistSelectionChange) {
|
|
|
| // Force state to flush to disk on the main thread so it can be immediately
|
| // tested below.
|
| - SessionWindowIOS* window = [tab_model_ windowForSavingSession];
|
| - [[SessionServiceIOS sharedService] performSaveWindow:window
|
| - toDirectory:stashPath];
|
| - [tab_model_ browserStateDestroyed];
|
| - tab_model_.reset();
|
| -
|
| - // Restoring TabModel session sends asynchronous tasks to IO thread, wait
|
| - // for them to complete after destroying the TabModel.
|
| - base::RunLoop().RunUntilIdle();
|
| + [test_session_service setPerformIO:YES];
|
| + [tab_model_ saveSessionImmediately:YES];
|
| + [test_session_service setPerformIO:NO];
|
|
|
| - SessionWindowIOS* sessionWindow = [[SessionServiceIOS sharedService]
|
| - loadWindowForBrowserState:chrome_browser_state_.get()];
|
| + NSString* state_path = base::SysUTF8ToNSString(
|
| + chrome_browser_state_->GetStatePath().AsUTF8Unsafe());
|
| + NSString* session_path =
|
| + [test_session_service sessionPathForDirectory:state_path];
|
| + SessionWindowIOS* session_window =
|
| + [test_session_service loadSessionWindowFromPath:session_path];
|
|
|
| // Create tab model from saved session.
|
| - base::scoped_nsobject<TestSessionService> test_service(
|
| - [[TestSessionService alloc] init]);
|
| + SetTabModel(CreateTabModel(test_session_service.get(), session_window));
|
|
|
| - tab_model_.reset([[TabModel alloc]
|
| - initWithSessionWindow:sessionWindow
|
| - sessionService:test_service
|
| - browserState:chrome_browser_state_.get()]);
|
| ASSERT_EQ(3u, [tab_model_ count]);
|
|
|
| EXPECT_EQ([tab_model_ tabAtIndex:1], [tab_model_ currentTab]);
|
|
|