1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/test/test_listener_ios.h"
7 #import <Foundation/Foundation.h>
9 #include "base/mac/scoped_nsautorelease_pool.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 // The iOS watchdog timer will kill an app that doesn't spin the main event
13 // loop often enough. This uses a Gtest TestEventListener to spin the current
14 // loop after each test finishes. However, if any individual test takes too
15 // long, it is still possible that the app will get killed.
19 class IOSRunLoopListener : public testing::EmptyTestEventListener {
21 virtual void OnTestEnd(const testing::TestInfo& test_info);
24 void IOSRunLoopListener::OnTestEnd(const testing::TestInfo& test_info) {
25 base::mac::ScopedNSAutoreleasePool scoped_pool;
27 // At the end of the test, spin the default loop for a moment.
28 NSDate* stop_date = [NSDate dateWithTimeIntervalSinceNow:0.001];
29 [[NSRunLoop currentRunLoop] runUntilDate:stop_date];
36 namespace test_listener_ios {
38 void RegisterTestEndListener() {
39 testing::TestEventListeners& listeners =
40 testing::UnitTest::GetInstance()->listeners();
41 listeners.Append(new IOSRunLoopListener);
44 } // namespace test_listener_ios