Chromium Code Reviews| Index: ios/chrome/browser/native_app_launcher/native_app_navigation_controller_unittest.mm |
| diff --git a/ios/chrome/browser/native_app_launcher/native_app_navigation_controller_unittest.mm b/ios/chrome/browser/native_app_launcher/native_app_navigation_controller_unittest.mm |
| index 0607c78083f9b212766da3401b2041ebe71e6c4f..0e8b1827f2478fefbb87f0b265d8eac08138963c 100644 |
| --- a/ios/chrome/browser/native_app_launcher/native_app_navigation_controller_unittest.mm |
| +++ b/ios/chrome/browser/native_app_launcher/native_app_navigation_controller_unittest.mm |
| @@ -64,6 +64,7 @@ class NativeAppNavigationControllerTest : public ChromeWebTest { |
| void TearDown() override { |
| base::RemoveActionCallback(action_callback_); |
| + controller_ = nil; |
| ChromeWebTest::TearDown(); |
| } |
| @@ -123,38 +124,49 @@ TEST_F(NativeAppNavigationControllerTest, TestUMA) { |
| // Tests presenting NativeAppInfoBar after page is loaded. |
| TEST_F(NativeAppNavigationControllerTest, NativeAppInfoBar) { |
| - SetExpectedActionName("MobileGALInstallInfoBarDirectNavigation"); |
| - InfoBarManagerImpl::CreateForWebState(web_state()); |
| - |
| - // Set up fake metadata. |
| - FakeNativeAppWhitelistManager* fakeManager = |
| - [[FakeNativeAppWhitelistManager alloc] init]; |
| - IOSChromeScopedTestingChromeBrowserProvider provider( |
| - base::MakeUnique<FakeChromeBrowserProvider>(fakeManager)); |
| - FakeNativeAppMetadata* metadata = [[FakeNativeAppMetadata alloc] init]; |
| - fakeManager.metadata = metadata; |
| - metadata.appName = @"App"; |
| - metadata.appId = @"App-ID"; |
| - |
| - // Load the page to trigger infobar presentation. |
| - LoadHtml(@"<html><body></body></html>", GURL("http://test.com")); |
| - |
| - // Verify that infobar was presented |
| - auto* infobar_manager = InfoBarManagerImpl::FromWebState(web_state()); |
| - ASSERT_EQ(1U, infobar_manager->infobar_count()); |
| - infobars::InfoBar* infobar = infobar_manager->infobar_at(0); |
| - auto* delegate = infobar->delegate()->AsNativeAppInfoBarDelegate(); |
| - ASSERT_TRUE(delegate); |
| - |
| - // Verify infobar appearance. |
| - EXPECT_EQ("Open this page in the App app?", |
| - base::UTF16ToUTF8(delegate->GetInstallText())); |
| - EXPECT_EQ("Open this page in the App app?", |
| - base::UTF16ToUTF8(delegate->GetLaunchText())); |
| - EXPECT_EQ("Open in App", base::UTF16ToUTF8(delegate->GetOpenPolicyText())); |
| - EXPECT_EQ("Just once", base::UTF16ToUTF8(delegate->GetOpenOnceText())); |
| - EXPECT_EQ("Always", base::UTF16ToUTF8(delegate->GetOpenAlwaysText())); |
| - EXPECT_NSEQ(@"App-ID", delegate->GetAppId()); |
| + // An autorelease pool is used here to make sure that objects autoreleased |
| + // during the running of this test are released at the end of the test, and |
| + // not caught by the root pool. This is important as some DCHECKs run when |
| + // objects like NativeAppNavigationController are released, and they expect |
| + // that the web thread state is still coherent at this time (i.e. the |
| + // expected web threads (UI, DB, etc.) are still running and valid. If left |
| + // to the root autoreleasepool there is no guarantee that objects will be |
| + // released in the correct order, causing test flake or failures. |
| + |
| + @autoreleasepool { |
|
Eugene But (OOO till 7-30)
2017/06/02 23:18:37
How about using ScopedNSAutoreleasePool? This will
PL
2017/06/05 23:26:18
I think the @autoreleasepool is supposed to be mor
|
| + SetExpectedActionName("MobileGALInstallInfoBarDirectNavigation"); |
| + InfoBarManagerImpl::CreateForWebState(web_state()); |
| + |
| + // Set up fake metadata. |
| + FakeNativeAppWhitelistManager* fakeManager = |
| + [[FakeNativeAppWhitelistManager alloc] init]; |
| + IOSChromeScopedTestingChromeBrowserProvider provider( |
| + base::MakeUnique<FakeChromeBrowserProvider>(fakeManager)); |
| + FakeNativeAppMetadata* metadata = [[FakeNativeAppMetadata alloc] init]; |
| + fakeManager.metadata = metadata; |
| + metadata.appName = @"App"; |
| + metadata.appId = @"App-ID"; |
| + |
| + // Load the page to trigger infobar presentation. |
| + LoadHtml(@"<html><body></body></html>", GURL("http://test.com")); |
| + |
| + // Verify that infobar was presented |
| + auto* infobar_manager = InfoBarManagerImpl::FromWebState(web_state()); |
| + ASSERT_EQ(1U, infobar_manager->infobar_count()); |
| + infobars::InfoBar* infobar = infobar_manager->infobar_at(0); |
| + auto* delegate = infobar->delegate()->AsNativeAppInfoBarDelegate(); |
| + ASSERT_TRUE(delegate); |
| + |
| + // Verify infobar appearance. |
| + EXPECT_EQ("Open this page in the App app?", |
| + base::UTF16ToUTF8(delegate->GetInstallText())); |
| + EXPECT_EQ("Open this page in the App app?", |
| + base::UTF16ToUTF8(delegate->GetLaunchText())); |
| + EXPECT_EQ("Open in App", base::UTF16ToUTF8(delegate->GetOpenPolicyText())); |
| + EXPECT_EQ("Just once", base::UTF16ToUTF8(delegate->GetOpenOnceText())); |
| + EXPECT_EQ("Always", base::UTF16ToUTF8(delegate->GetOpenAlwaysText())); |
| + EXPECT_NSEQ(@"App-ID", delegate->GetAppId()); |
| + } |
| } |
| TEST_F(NativeAppNavigationControllerTest, |