summaryrefslogtreecommitdiffstats
path: root/chrome/browser/sync
diff options
context:
space:
mode:
authorakalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-14 08:17:17 +0000
committerakalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-14 08:17:17 +0000
commita4bce59e4e4cf40588be7444ec4f1ca38583b4f8 (patch)
tree184812b5e73e5fdbf0bbea015820e916faa4e379 /chrome/browser/sync
parentcf99ae3ee5400bacdb3a291cc65bf06ee8e13638 (diff)
downloadchromium_src-a4bce59e4e4cf40588be7444ec4f1ca38583b4f8.zip
chromium_src-a4bce59e4e4cf40588be7444ec4f1ca38583b4f8.tar.gz
chromium_src-a4bce59e4e4cf40588be7444ec4f1ca38583b4f8.tar.bz2
[Sync] Revamped ChromeSystemResources tests, fixed memory leak
Undid suppressions. BUG=59019 TEST=Trybots Review URL: http://codereview.chromium.org/3815003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@62517 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/sync')
-rw-r--r--chrome/browser/sync/notifier/chrome_system_resources_unittest.cc99
1 files changed, 53 insertions, 46 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