Skip to content

Commit

Permalink
Ensure that autorelease pool is drained between each tests.
Browse files Browse the repository at this point in the history
The TEST macro uses a test fixture of type testing::Test that does
not drain the autorelease pool at the end of the test. Instead use
TEST_F with PlatformTest as the fixture as it drain the autorelease
pool during its TearDown method.

Change all test fixture inheriting from testing::Test to instead
inherit from PlatformTest (also for those using parametrisation).

Changes initially automated with a one-shot script and formatting
fixed by git cl format. Additional changes were necessary to fix
the compilation.

Bug: none
Change-Id: I35651b5aebb7148efee6eaa59d6582c0c6c3b771
Reviewed-on: https://chromium-review.googlesource.com/704821
Commit-Queue: Sylvain Defresne <sdefresne@chromium.org>
Reviewed-by: Rohit Rao (ping after 24h) <rohitrao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#507375}
  • Loading branch information
sdefresne authored and Commit Bot committed Oct 9, 2017
1 parent 1054fb6 commit 6477808
Show file tree
Hide file tree
Showing 166 changed files with 857 additions and 417 deletions.
4 changes: 3 additions & 1 deletion ios/chrome/app/application_delegate/app_state_unittest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -449,8 +449,10 @@ void trackerCreationFailed() {
EXPECT_OCMOCK_VERIFY(browserLauncherMock);
}

using AppStateNoFixtureTest = PlatformTest;

// Test that -willResignActive set cold start to NO and launch record.
TEST(AppStateNoFixtureTest, willResignActive) {
TEST_F(AppStateNoFixtureTest, willResignActive) {
// Setup.
id tabModel = [OCMockObject mockForClass:[TabModel class]];
[[tabModel expect] recordSessionMetrics];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
#error "This file requires ARC support."
#endif

using BackgroundActivityTest = PlatformTest;

// Verifies that -application:performFetchWithCompletionHandler: calls the
// browser launcher in background state and uploads the report.
TEST(BackgroundActivityTest, performFetchWithCompletionHandler) {
TEST_F(BackgroundActivityTest, performFetchWithCompletionHandler) {
// Setup.
[[PreviousSessionInfo sharedInstance] setIsFirstSessionAfterUpgrade:NO];

Expand Down Expand Up @@ -58,7 +60,7 @@ ScopedBlockSwizzler crash_report_completion_handler_swizzler(

// Verifies that -handleEventsForBackgroundURLSession:completionHandler: calls
// the browser launcher in background state.
TEST(BackgroundActivityTest, handleEventsForBackgroundURLSession) {
TEST_F(BackgroundActivityTest, handleEventsForBackgroundURLSession) {
// Setup.
// BrowserLauncher mock.
id browser_launcher =
Expand Down
12 changes: 9 additions & 3 deletions ios/chrome/app/application_delegate/metrics_mediator_unittest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,11 @@ int getExpectedValue(int number) {
return 1;
}

using MetricsMediatorTest = PlatformTest;

// Verifies that connectionTypeChanged correctly enables or disables the
// uploading in the breakpad and in the metrics service.
TEST(MetricsMediatorTest, connectionTypeChanged) {
TEST_F(MetricsMediatorTest, connectionTypeChanged) {
[[PreviousSessionInfo sharedInstance] setIsFirstSessionAfterUpgrade:NO];
MetricsMediatorMock* mock_metrics_helper = [[MetricsMediatorMock alloc] init];

Expand Down Expand Up @@ -216,8 +218,10 @@ void initiateMetricsMediator(BOOL coldStart, int tabCount) {
verifySwizzleHasBeenCalled();
}

using MetricsMediatorNoFixtureTest = PlatformTest;

// Tests that +logDateInUserDefaults logs the date in UserDefaults.
TEST(MetricsMediatorNoFixtureTest, logDateInUserDefaultsTest) {
TEST_F(MetricsMediatorNoFixtureTest, logDateInUserDefaultsTest) {
// Setup.
[[NSUserDefaults standardUserDefaults]
removeObjectForKey:metrics_mediator::kAppEnteredBackgroundDateKey];
Expand All @@ -238,7 +242,9 @@ void initiateMetricsMediator(BOOL coldStart, int tabCount) {

#pragma mark - processCrashReportsPresentAtStartup tests.

class MetricsMediatorShutdownTypeTest : public testing::TestWithParam<int> {};
class MetricsMediatorShutdownTypeTest
: public PlatformTest,
public testing::WithParamInterface<int> {};

// Verifies that the Breakpad controller gets called appropriately when
// processCrashReportsPresentAtStartup is invoked.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,12 @@ conditionBlock getCompletionHandler() {

#pragma mark - Tests.

using UserActivityHandlerNoFixtureTest = PlatformTest;

// Tests that Chrome notifies the user if we are passing a correct
// userActivityType.
TEST(UserActivityHandlerNoFixtureTest,
willContinueUserActivityCorrectActivity) {
TEST_F(UserActivityHandlerNoFixtureTest,
willContinueUserActivityCorrectActivity) {
EXPECT_TRUE([UserActivityHandler
willContinueUserActivityWithType:handoff::kChromeHandoffActivityType]);

Expand All @@ -181,8 +183,8 @@ conditionBlock getCompletionHandler() {

// Tests that Chrome does not notifies the user if we are passing an incorrect
// userActivityType.
TEST(UserActivityHandlerNoFixtureTest,
willContinueUserActivityIncorrectActivity) {
TEST_F(UserActivityHandlerNoFixtureTest,
willContinueUserActivityIncorrectActivity) {
EXPECT_FALSE([UserActivityHandler
willContinueUserActivityWithType:[handoff::kChromeHandoffActivityType
stringByAppendingString:@"test"]]);
Expand All @@ -195,9 +197,11 @@ conditionBlock getCompletionHandler() {
EXPECT_FALSE([UserActivityHandler willContinueUserActivityWithType:nil]);
}

using UserActivityHandlerNoFixtureTest = PlatformTest;

// Tests that Chrome does not continue the activity is the activity type is
// random.
TEST(UserActivityHandlerNoFixtureTest, continueUserActivityFromGarbage) {
TEST_F(UserActivityHandlerNoFixtureTest, continueUserActivityFromGarbage) {
// Setup.
NSString* handoffWithSuffix =
[handoff::kChromeHandoffActivityType stringByAppendingString:@"test"];
Expand Down Expand Up @@ -230,7 +234,7 @@ conditionBlock getCompletionHandler() {

// Tests that Chrome does not continue the activity if the webpage url is not
// set.
TEST(UserActivityHandlerNoFixtureTest, continueUserActivityNoWebpage) {
TEST_F(UserActivityHandlerNoFixtureTest, continueUserActivityNoWebpage) {
// Setup.
NSUserActivity* userActivity = [[NSUserActivity alloc]
initWithActivityType:handoff::kChromeHandoffActivityType];
Expand All @@ -253,8 +257,8 @@ conditionBlock getCompletionHandler() {

// Tests that Chrome does not continue the activity if the activity is a
// Spotlight action of an unknown type.
TEST(UserActivityHandlerNoFixtureTest,
continueUserActivitySpotlightActionFromGarbage) {
TEST_F(UserActivityHandlerNoFixtureTest,
continueUserActivitySpotlightActionFromGarbage) {
// Only test Spotlight if it is enabled and available on the device.
if (!spotlight::IsSpotlightAvailable()) {
return;
Expand Down Expand Up @@ -292,7 +296,7 @@ conditionBlock getCompletionHandler() {

// Tests that Chrome continues the activity if the application is in background
// by saving the url to startupParameters.
TEST(UserActivityHandlerNoFixtureTest, continueUserActivityBackground) {
TEST_F(UserActivityHandlerNoFixtureTest, continueUserActivityBackground) {
// Setup.
NSUserActivity* userActivity = [[NSUserActivity alloc]
initWithActivityType:handoff::kChromeHandoffActivityType];
Expand Down Expand Up @@ -327,7 +331,7 @@ conditionBlock getCompletionHandler() {

// Tests that Chrome continues the activity if the application is in foreground
// by opening a new tab.
TEST(UserActivityHandlerNoFixtureTest, continueUserActivityForeground) {
TEST_F(UserActivityHandlerNoFixtureTest, continueUserActivityForeground) {
// Setup.
NSUserActivity* userActivity = [[NSUserActivity alloc]
initWithActivityType:handoff::kChromeHandoffActivityType];
Expand Down Expand Up @@ -453,7 +457,7 @@ conditionBlock getCompletionHandler() {
}

// Tests that handleStartupParameters with a non-U2F url opens a new tab.
TEST(UserActivityHandlerNoFixtureTest, handleStartupParamsNonU2F) {
TEST_F(UserActivityHandlerNoFixtureTest, handleStartupParamsNonU2F) {
// Setup.
GURL gurl("http://www.google.com");

Expand Down Expand Up @@ -487,7 +491,7 @@ conditionBlock getCompletionHandler() {
}

// Tests that handleStartupParameters with a U2F url opens in the correct tab.
TEST(UserActivityHandlerNoFixtureTest, handleStartupParamsU2F) {
TEST_F(UserActivityHandlerNoFixtureTest, handleStartupParamsU2F) {
// Setup.
GURL gurl("chromium://u2f-callback?isU2F=1&tabID=B05B1860");
NSString* tabID = [U2FController tabIDFromResponseURL:gurl];
Expand Down
14 changes: 8 additions & 6 deletions ios/chrome/app/deferred_initialization_runner_unittest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@
#error "This file requires ARC support."
#endif

TEST(DeferredInitializationRunnerTest, TestSharedInstance) {
using DeferredInitializationRunnerTest = PlatformTest;

TEST_F(DeferredInitializationRunnerTest, TestSharedInstance) {
EXPECT_TRUE([DeferredInitializationRunner sharedInstance]);
// Cancelling a non-existing block does nothing.
[[DeferredInitializationRunner sharedInstance]
cancelBlockNamed:@"Invalid Name"];
}

// Tests that all blocks added on the queue are executed after a delay.
TEST(DeferredInitializationRunnerTest, TestRunBlockSequentially) {
TEST_F(DeferredInitializationRunnerTest, TestRunBlockSequentially) {
// Setup.
__block bool firstFlag = NO;
__block bool secondFlag = NO;
Expand Down Expand Up @@ -58,7 +60,7 @@

// Tests that runBlockIfNecessary does not execute the block if it has already
// been executed and runs synchronously the one not executed.
TEST(DeferredInitializationRunnerTest, TestRunBlock) {
TEST_F(DeferredInitializationRunnerTest, TestRunBlock) {
// Setup.
__block bool quickFlag = NO;
__block bool slowFlag = NO;
Expand Down Expand Up @@ -98,7 +100,7 @@

// Tests that a block is not executed when cancelled and it is removed from the
// remaining blocks list.
TEST(DeferredInitializationRunnerTest, TestCancelBlock) {
TEST_F(DeferredInitializationRunnerTest, TestCancelBlock) {
// Setup.
__block BOOL blockFinished = NO;
DeferredInitializationRunner* runner =
Expand All @@ -121,7 +123,7 @@
}

// Tests that a cancelled block will do nothing when run by name.
TEST(DeferredInitializationRunnerTest, TestCancelledBlockDoNothing) {
TEST_F(DeferredInitializationRunnerTest, TestCancelledBlockDoNothing) {
// Setup.
__block BOOL blockFinished = NO;
DeferredInitializationRunner* runner =
Expand All @@ -145,7 +147,7 @@

// Tests that adding a block with the same name as an existing block will
// override the existing one.
TEST(DeferredInitializationRunnerTest, TestSecondBlockInvalidatesFirst) {
TEST_F(DeferredInitializationRunnerTest, TestSecondBlockInvalidatesFirst) {
// Setup.
__block int blockRunCount = 0;
ProceduralBlock runBlock = ^() {
Expand Down
4 changes: 3 additions & 1 deletion ios/chrome/app/main_application_delegate_unittest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
#error "This file requires ARC support."
#endif

using MainApplicationDelegateTest = PlatformTest;

// Tests that the application does not crash if |applicationDidEnterBackground|
// is called when the application is launched in background.
// http://crbug.com/437307
TEST(MainApplicationDelegateTest, CrashIfNotInitialized) {
TEST_F(MainApplicationDelegateTest, CrashIfNotInitialized) {
// Save both ChromeBrowserProvider as MainController register new instance.
ios::ChromeBrowserProvider* stashed_chrome_browser_provider =
ios::GetChromeBrowserProvider();
Expand Down
3 changes: 2 additions & 1 deletion ios/chrome/app/spotlight/spotlight_manager_unittest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/gtest_mac.h"
#include "testing/platform_test.h"

#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
Expand Down Expand Up @@ -60,7 +61,7 @@
return result;
}

class SpotlightManagerTest : public testing::Test {
class SpotlightManagerTest : public PlatformTest {
protected:
SpotlightManagerTest() {
model_ = bookmarks::TestBookmarkClient::CreateModel();
Expand Down
5 changes: 4 additions & 1 deletion ios/chrome/browser/app_startup_parameters_unittest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "ios/chrome/browser/app_startup_parameters.h"

#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
#include "url/gurl.h"

#if !defined(__has_feature) || !__has_feature(objc_arc)
Expand All @@ -19,7 +20,9 @@
bool expected_complete_payment_request;
};

TEST(AppStartupParameters, QueryParametersPaymentRequest) {
using AppStartupParametersTest = PlatformTest;

TEST_F(AppStartupParametersTest, QueryParametersPaymentRequest) {
const UniversalLinkDecodeTestCase test_cases[] = {
{
GURL("https://goo.gl/ioschrome/"), {}, false,
Expand Down
4 changes: 3 additions & 1 deletion ios/chrome/browser/callback_counter_unittest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
#error "This file requires ARC support."
#endif

using CallbackCounterTest = PlatformTest;

// Tests that CallbackCounter works with 2 callbacks.
TEST(CallbackCounterTest, Basic) {
TEST_F(CallbackCounterTest, Basic) {
__block BOOL block_was_called = NO;
scoped_refptr<CallbackCounter> callback_counter =
new CallbackCounter(base::BindBlockArc(^{
Expand Down
11 changes: 7 additions & 4 deletions ios/chrome/browser/chrome_url_util_unittest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "ios/chrome/browser/chrome_url_constants.h"
#import "net/base/mac/url_conversions.h"
#import "testing/gtest_mac.h"
#include "testing/platform_test.h"
#include "url/gurl.h"

#if !defined(__has_feature) || !__has_feature(objc_arc)
Expand All @@ -17,7 +18,9 @@

namespace {

TEST(ChromeURLUtilTest, TestIsExternalFileReference) {
using ChromeURLUtilTest = PlatformTest;

TEST_F(ChromeURLUtilTest, TestIsExternalFileReference) {
GURL external_url("chrome://external-file/foo/bar");
GURL not_external_url("chrome://foo/bar");
GURL still_not_external_url("http://external-file/foo/bar");
Expand All @@ -35,7 +38,7 @@
};

// Tests UrlHasChromeScheme with NSURL* parameter.
TEST(ChromeURLUtilTest, NSURLHasChromeScheme) {
TEST_F(ChromeURLUtilTest, NSURLHasChromeScheme) {
for (unsigned int i = 0; i < arraysize(kSchemeTestData); ++i) {
const char* url = kSchemeTestData[i];
NSURL* nsurl = [NSURL URLWithString:base::SysUTF8ToNSString(url)];
Expand All @@ -46,7 +49,7 @@
}

// Tests UrlHasChromeScheme with const GURL& paramter.
TEST(ChromeURLUtilTest, GURLHasChromeScheme) {
TEST_F(ChromeURLUtilTest, GURLHasChromeScheme) {
for (unsigned int i = 0; i < arraysize(kSchemeTestData); ++i) {
GURL gurl(kSchemeTestData[i]);
bool result = UrlHasChromeScheme(gurl);
Expand All @@ -55,7 +58,7 @@
}
}

TEST(ChromeURLUtilTest, GetBundleURLScheme) {
TEST_F(ChromeURLUtilTest, GetBundleURLScheme) {
// Verifies that there is some default values.
ChromeAppConstants* constants = [ChromeAppConstants sharedInstance];
NSString* originalScheme = [constants getBundleURLScheme];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "components/ntp_snippets/category.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"

#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
Expand All @@ -21,9 +22,11 @@ @implementation ContentSuggestionsCategoryWrapperSubclassTest

#pragma mark - Tests.

using ContentSuggestionsCategoryWrapperTest = PlatformTest;

// Tests that the category returned by the wrapper is the one given in the
// initializer.
TEST(ContentSuggestionsCategoryWrapperTest, GetCategory) {
TEST_F(ContentSuggestionsCategoryWrapperTest, GetCategory) {
// Setup.
ntp_snippets::Category category = ntp_snippets::Category::FromIDValue(2);
ContentSuggestionsCategoryWrapper* wrapper =
Expand All @@ -34,7 +37,7 @@ @implementation ContentSuggestionsCategoryWrapperSubclassTest
}

// Tests that two wrappers created with equal categories are equal.
TEST(ContentSuggestionsCategoryWrapperTest, AreWrappersEqual) {
TEST_F(ContentSuggestionsCategoryWrapperTest, AreWrappersEqual) {
// Setup.
ntp_snippets::Category category = ntp_snippets::Category::FromIDValue(2);
ContentSuggestionsCategoryWrapper* wrapper =
Expand All @@ -50,7 +53,7 @@ @implementation ContentSuggestionsCategoryWrapperSubclassTest
}

// Tests that two wrappers created with different categories are not equal.
TEST(ContentSuggestionsCategoryWrapperTest, AreWrappersDifferent) {
TEST_F(ContentSuggestionsCategoryWrapperTest, AreWrappersDifferent) {
// Setup.
ntp_snippets::Category category = ntp_snippets::Category::FromIDValue(2);
ContentSuggestionsCategoryWrapper* wrapper =
Expand All @@ -65,7 +68,7 @@ @implementation ContentSuggestionsCategoryWrapperSubclassTest
}

// Tests the equality between a wrapper an different type of objects.
TEST(ContentSuggestionsCategoryWrapperTest, DifferentObject) {
TEST_F(ContentSuggestionsCategoryWrapperTest, DifferentObject) {
// Setup.
ntp_snippets::Category category = ntp_snippets::Category::FromIDValue(2);
ContentSuggestionsCategoryWrapper* wrapper =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@
#include "testing/gtest/include/gtest/gtest.h"

#include "base/logging.h"
#include "testing/platform_test.h"

#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif

namespace {

TEST(DropAndNavigateTest, Instantiation) {
using DropAndNavigateTest = PlatformTest;

TEST_F(DropAndNavigateTest, Instantiation) {
#if defined(__IPHONE_11_0) && (__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_11_0)
if (@available(iOS 11, *)) {
DropAndNavigateInteraction* interaction =
Expand Down
Loading

0 comments on commit 6477808

Please sign in to comment.