Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Unified Diff: ios/chrome/browser/tabs/tab_model_unittest.mm

Issue 2678883002: Add a ScopedNSAutoreleasePool to TabModelTest.PersistSelectionChange (Closed)
Patch Set: Add comments. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 42b4af4061c625814bca4b1e0998a161dde4f6d4..bb9133a49e80db7eb53de13b22de44f2741e1f47 100644
--- a/ios/chrome/browser/tabs/tab_model_unittest.mm
+++ b/ios/chrome/browser/tabs/tab_model_unittest.mm
@@ -832,6 +832,14 @@ TEST_F(TabModelTest, PersistSelectionChange) {
TestChromeBrowserState::Builder test_cbs_builder;
auto chrome_browser_state = test_cbs_builder.Build();
+ // Tabs register some observers with the ChromeBrowserState in an ObserverList
+ // that assert it is empty in its destructor. As Tab are Objective-C object,
+ // it is necessary to use a local pool to ensure all autoreleased object that
+ // may reference those Tabs are deallocated before the TestChromeBrowserState
+ // is destroyed (this cannot use the TabModelTest ScopedNSAutoreleasePool as
+ // it will be drained after the local variable chrome_browser_state).
+ base::mac::ScopedNSAutoreleasePool pool;
+
NSString* stashPath =
base::SysUTF8ToNSString(chrome_browser_state->GetStatePath().value());
@@ -853,6 +861,9 @@ TEST_F(TabModelTest, PersistSelectionChange) {
toDirectory:stashPath];
[model browserStateDestroyed];
model.reset();
+
+ // Restoring TabModel session sends asynchronous tasks to IO thread, wait
+ // for them to complete after destroying the TabModel.
base::RunLoop().RunUntilIdle();
SessionWindowIOS* sessionWindow = [[SessionServiceIOS sharedService]
@@ -868,6 +879,11 @@ TEST_F(TabModelTest, PersistSelectionChange) {
browserState:chrome_browser_state.get()]);
EXPECT_EQ(model.get().currentTab, [model tabAtIndex:1]);
[model browserStateDestroyed];
+ model.reset();
+
+ // Restoring TabModel session sends asynchronous tasks to IO thread, wait
+ // for them to complete after destroying the TabModel.
+ base::RunLoop().RunUntilIdle();
// Clean up.
EXPECT_TRUE([[NSFileManager defaultManager] removeItemAtPath:stashPath
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698