summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/sync/notifier/chrome_system_resources_unittest.cc99
-rw-r--r--tools/heapcheck/suppressions.txt6
-rw-r--r--tools/valgrind/memcheck/suppressions.txt7
3 files changed, 53 insertions, 59 deletions
diff --git a/chrome/browser/sync/notifier/chrome_system_resources_unittest.cc b/chrome/browser/sync/notifier/chrome_system_resources_unittest.cc
index 12b4080..fa5f456 100644
--- a/chrome/browser/sync/notifier/chrome_system_resources_unittest.cc
+++ b/chrome/browser/sync/notifier/chrome_system_resources_unittest.cc
@@ -6,7 +6,9 @@
#include <string>
+#include "base/callback.h"
#include "base/message_loop.h"
+#include "base/tuple.h"
#include "google/cacheinvalidation/invalidation-client.h"
#include "chrome/browser/sync/notifier/state_writer.h"
#include "testing/gmock/include/gmock/gmock.h"
@@ -16,48 +18,56 @@ namespace sync_notifier {
namespace {
using ::testing::_;
+using ::testing::SaveArg;
class MockStateWriter : public StateWriter {
public:
MOCK_METHOD1(WriteState, void(const std::string&));
};
-void ShouldNotRun() {
- ADD_FAILURE();
-}
-
-class ChromeSystemResourcesTest : public testing::Test {
+class MockClosure : public Callback0::Type {
public:
- // Used as a callback.
- void IncrementCounter() {
- ++counter_;
- }
+ MOCK_METHOD1(RunWithParams, void(const Tuple0&));
+};
- // Used as a callback.
- void ExpectTrue(bool result) {
- EXPECT_TRUE(result);
- }
+class MockStorageCallback : public Callback1<bool>::Type {
+ public:
+ MOCK_METHOD1(RunWithParams, void(const Tuple1<bool>&));
+};
+class ChromeSystemResourcesTest : public testing::Test {
protected:
- ChromeSystemResourcesTest() :
- chrome_system_resources_(&mock_state_writer_),
- counter_(0) {}
+ ChromeSystemResourcesTest()
+ : chrome_system_resources_(&mock_state_writer_) {}
virtual ~ChromeSystemResourcesTest() {}
void ScheduleShouldNotRun() {
- chrome_system_resources_.ScheduleImmediately(
- invalidation::NewPermanentCallback(&ShouldNotRun));
- chrome_system_resources_.ScheduleWithDelay(
- invalidation::TimeDelta::FromSeconds(0),
- invalidation::NewPermanentCallback(&ShouldNotRun));
+ {
+ // Owned by ScheduleImmediately.
+ MockClosure* should_not_run = new MockClosure();
+ EXPECT_CALL(*should_not_run, RunWithParams(_)).Times(0);
+ chrome_system_resources_.ScheduleImmediately(should_not_run);
+ }
+ {
+ // Owned by ScheduleOnListenerThread.
+ MockClosure* should_not_run = new MockClosure();
+ EXPECT_CALL(*should_not_run, RunWithParams(_)).Times(0);
+ chrome_system_resources_.ScheduleOnListenerThread(should_not_run);
+ }
+ {
+ // Owned by ScheduleWithDelay.
+ MockClosure* should_not_run = new MockClosure();
+ EXPECT_CALL(*should_not_run, RunWithParams(_)).Times(0);
+ chrome_system_resources_.ScheduleWithDelay(
+ invalidation::TimeDelta::FromSeconds(0), should_not_run);
+ }
}
// Needed by |chrome_system_resources_|.
MessageLoop message_loop_;
MockStateWriter mock_state_writer_;
ChromeSystemResources chrome_system_resources_;
- int counter_;
private:
DISALLOW_COPY_AND_ASSIGN(ChromeSystemResourcesTest);
@@ -101,49 +111,46 @@ TEST_F(ChromeSystemResourcesTest, ScheduleAndDestroy) {
TEST_F(ChromeSystemResourcesTest, ScheduleImmediately) {
chrome_system_resources_.StartScheduler();
- chrome_system_resources_.ScheduleImmediately(
- invalidation::NewPermanentCallback(
- this, &ChromeSystemResourcesTest::IncrementCounter));
- EXPECT_EQ(0, counter_);
+ // Owned by ScheduleImmediately.
+ MockClosure* mock_closure = new MockClosure();
+ EXPECT_CALL(*mock_closure, RunWithParams(_));
+ chrome_system_resources_.ScheduleImmediately(mock_closure);
message_loop_.RunAllPending();
- EXPECT_EQ(1, counter_);
}
TEST_F(ChromeSystemResourcesTest, ScheduleOnListenerThread) {
chrome_system_resources_.StartScheduler();
- chrome_system_resources_.ScheduleOnListenerThread(
- invalidation::NewPermanentCallback(
- this, &ChromeSystemResourcesTest::IncrementCounter));
+ // Owned by ScheduleOnListenerThread.
+ MockClosure* mock_closure = new MockClosure();
+ EXPECT_CALL(*mock_closure, RunWithParams(_));
+ chrome_system_resources_.ScheduleOnListenerThread(mock_closure);
EXPECT_FALSE(chrome_system_resources_.IsRunningOnInternalThread());
- EXPECT_EQ(0, counter_);
message_loop_.RunAllPending();
- EXPECT_EQ(1, counter_);
}
TEST_F(ChromeSystemResourcesTest, ScheduleWithZeroDelay) {
chrome_system_resources_.StartScheduler();
+ // Owned by ScheduleWithDelay.
+ MockClosure* mock_closure = new MockClosure();
+ EXPECT_CALL(*mock_closure, RunWithParams(_));
chrome_system_resources_.ScheduleWithDelay(
- invalidation::TimeDelta::FromSeconds(0),
- invalidation::NewPermanentCallback(
- this, &ChromeSystemResourcesTest::IncrementCounter));
- EXPECT_EQ(0, counter_);
+ invalidation::TimeDelta::FromSeconds(0), mock_closure);
message_loop_.RunAllPending();
- EXPECT_EQ(1, counter_);
}
// TODO(akalin): Figure out how to test with a non-zero delay.
TEST_F(ChromeSystemResourcesTest, WriteState) {
+ chrome_system_resources_.StartScheduler();
EXPECT_CALL(mock_state_writer_, WriteState(_));
-
- // Explicitness hack here to work around broken callback
- // implementations.
- ChromeSystemResourcesTest* run_object = this;
- void (ChromeSystemResourcesTest::*run_function)(bool) =
- &ChromeSystemResourcesTest::ExpectTrue;
-
- chrome_system_resources_.WriteState(
- "state", invalidation::NewPermanentCallback(run_object, run_function));
+ // Owned by WriteState.
+ MockStorageCallback* mock_storage_callback = new MockStorageCallback();
+ Tuple1<bool> results(false);
+ EXPECT_CALL(*mock_storage_callback, RunWithParams(_))
+ .WillOnce(SaveArg<0>(&results));
+ chrome_system_resources_.WriteState("state", mock_storage_callback);
+ message_loop_.RunAllPending();
+ EXPECT_TRUE(results.a);
}
} // namespace
diff --git a/tools/heapcheck/suppressions.txt b/tools/heapcheck/suppressions.txt
index 30ecd75..79228a7 100644
--- a/tools/heapcheck/suppressions.txt
+++ b/tools/heapcheck/suppressions.txt
@@ -1124,9 +1124,3 @@
fun:main
fun:__libc_start_main
}
-{
- bug_59019
- Heapcheck:Leak
- fun:invalidation::NewPermanentCallback
- fun:sync_notifier::::ChromeSystemResourcesTest_WriteState_Test::TestBody
-}
diff --git a/tools/valgrind/memcheck/suppressions.txt b/tools/valgrind/memcheck/suppressions.txt
index 46bb391..dba9aa2 100644
--- a/tools/valgrind/memcheck/suppressions.txt
+++ b/tools/valgrind/memcheck/suppressions.txt
@@ -2917,13 +2917,6 @@
fun:_ZN11MessageLoop10RunHandlerEv
}
{
- bug_59019
- Memcheck:Leak
- fun:_Znw*
- fun:_ZN12invalidation20NewPermanentCallbackIN13sync_notifier93_GLOBAL__N_chrome_browser_sync_notifier_chrome_system_resources_unittest.cc_00000000_B83B3F7125ChromeSystemResourcesTestEbEEPN9Callback1IT0_E4TypeEPT_MS9_FvS5_E
- fun:_ZN13sync_notifier93_GLOBAL__N_chrome_browser_sync_notifier_chrome_system_resources_unittest.cc_00000000_B83B3F7141ChromeSystemResourcesTest_WriteState_Test8TestBodyEv
-}
-{
bug_59023
Memcheck:Leak
fun:_Znw*