Commit 9366e48d authored by Elly Fong-Jones's avatar Elly Fong-Jones Committed by Commit Bot

sheriff: re-enable KeystoneGlueTests

These tests were disabled a while ago when they broke. This change:
1) Implements some parts of FakeKeystoneGlue and FakeKeystoneRegistration
   so that these tests pass
2) Updates the BasicUse test to more closely check the contract of
   KeystoneGlue

Bug: 16360
Change-Id: Ic28de2440f792751cf856e8ea61d5ff309c23f94
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1757368
Auto-Submit: Elly Fong-Jones <ellyjones@chromium.org>
Reviewed-by: default avatarMark Mentovai <mark@chromium.org>
Commit-Queue: Elly Fong-Jones <ellyjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#688722}
parent f297c517
...@@ -28,7 +28,11 @@ namespace ksr = keystone_registration; ...@@ -28,7 +28,11 @@ namespace ksr = keystone_registration;
} }
- (BOOL)registerWithParameters:(NSDictionary*)args { - (BOOL)registerWithParameters:(NSDictionary*)args {
return NO; NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
[center postNotificationName:ksr::KSRegistrationDidCompleteNotification
object:nil
userInfo:@{ksr::KSRegistrationStatusKey : @1}];
return YES;
} }
- (BOOL)promoteWithParameters:(NSDictionary*)args - (BOOL)promoteWithParameters:(NSDictionary*)args
...@@ -70,8 +74,10 @@ namespace ksr = keystone_registration; ...@@ -70,8 +74,10 @@ namespace ksr = keystone_registration;
- (void)startUpdate { - (void)startUpdate {
NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
[center postNotificationName:ksr::KSRegistrationStartUpdateNotification [center
object:nil]; postNotificationName:ksr::KSRegistrationStartUpdateNotification
object:nil
userInfo:@{ksr::KSUpdateCheckSuccessfullyInstalledKey : @1}];
} }
@end @end
...@@ -125,8 +131,9 @@ namespace ksr = keystone_registration; ...@@ -125,8 +131,9 @@ namespace ksr = keystone_registration;
return dict; return dict;
} }
// For mocking
- (BOOL)loadKeystoneRegistration { - (BOOL)loadKeystoneRegistration {
// The real loadKeystoneRegistration adds a real registration.
[self addFakeRegistration];
return YES; return YES;
} }
...@@ -161,14 +168,6 @@ namespace ksr = keystone_registration; ...@@ -161,14 +168,6 @@ namespace ksr = keystone_registration;
} }
} }
// Confirm we look like callbacks with nil NSNotifications
- (BOOL)confirmCallbacks {
return (!upToDate_ &&
(latestVersion_ == nil) &&
!successful_ &&
(installs_ == 0));
}
@end @end
@interface KeystoneGlue (PrivateMethods) @interface KeystoneGlue (PrivateMethods)
...@@ -185,8 +184,7 @@ class KeystoneGlueTest : public PlatformTest { ...@@ -185,8 +184,7 @@ class KeystoneGlueTest : public PlatformTest {
base::test::TaskEnvironment task_environment_; base::test::TaskEnvironment task_environment_;
}; };
// DISABLED because the mocking isn't currently working. TEST_F(KeystoneGlueTest, BasicGlobalCreate) {
TEST_F(KeystoneGlueTest, DISABLED_BasicGlobalCreate) {
// Allow creation of a KeystoneGlue by mocking out a few calls // Allow creation of a KeystoneGlue by mocking out a few calls
SEL ids = @selector(infoDictionary); SEL ids = @selector(infoDictionary);
IMP oldInfoImp_ = [[KeystoneGlue class] instanceMethodForSelector:ids]; IMP oldInfoImp_ = [[KeystoneGlue class] instanceMethodForSelector:ids];
...@@ -200,16 +198,22 @@ TEST_F(KeystoneGlueTest, DISABLED_BasicGlobalCreate) { ...@@ -200,16 +198,22 @@ TEST_F(KeystoneGlueTest, DISABLED_BasicGlobalCreate) {
Method loadMethod_ = class_getInstanceMethod([KeystoneGlue class], lks); Method loadMethod_ = class_getInstanceMethod([KeystoneGlue class], lks);
method_setImplementation(loadMethod_, newLoadImp_); method_setImplementation(loadMethod_, newLoadImp_);
SEL afr = @selector(addFakeRegistration);
IMP oldAddFake_ = [[KeystoneGlue class] instanceMethodForSelector:afr];
IMP newAddFake_ = [[FakeKeystoneGlue class] instanceMethodForSelector:afr];
Method addMethod_ = class_getInstanceMethod([KeystoneGlue class], afr);
method_setImplementation(loadMethod_, newAddFake_);
KeystoneGlue *glue = [KeystoneGlue defaultKeystoneGlue]; KeystoneGlue *glue = [KeystoneGlue defaultKeystoneGlue];
ASSERT_TRUE(glue); ASSERT_TRUE(glue);
// Fix back up the class to the way we found it. // Fix back up the class to the way we found it.
method_setImplementation(infoMethod_, oldInfoImp_); method_setImplementation(infoMethod_, oldInfoImp_);
method_setImplementation(loadMethod_, oldLoadImp_); method_setImplementation(loadMethod_, oldLoadImp_);
method_setImplementation(addMethod_, oldAddFake_);
} }
// DISABLED because the mocking isn't currently working. TEST_F(KeystoneGlueTest, BasicUse) {
TEST_F(KeystoneGlueTest, DISABLED_BasicUse) {
FakeKeystoneGlue* glue = [[[FakeKeystoneGlue alloc] init] autorelease]; FakeKeystoneGlue* glue = [[[FakeKeystoneGlue alloc] init] autorelease];
[glue loadParameters]; [glue loadParameters];
ASSERT_TRUE([glue dictReadCorrectly]); ASSERT_TRUE([glue dictReadCorrectly]);
...@@ -223,11 +227,15 @@ TEST_F(KeystoneGlueTest, DISABLED_BasicUse) { ...@@ -223,11 +227,15 @@ TEST_F(KeystoneGlueTest, DISABLED_BasicUse) {
ASSERT_TRUE([glue hasATimer]); ASSERT_TRUE([glue hasATimer]);
[glue stopTimer]; [glue stopTimer];
// Brief exercise of callbacks // Checking for an update should succeed, yielding kAutoupdateAvailable:
[glue addFakeRegistration];
[glue checkForUpdate]; [glue checkForUpdate];
ASSERT_EQ([glue recentStatus], kAutoupdateAvailable);
// And applying the update should also succeed:
[glue installUpdate]; [glue installUpdate];
ASSERT_TRUE([glue confirmCallbacks]); ASSERT_EQ([glue recentStatus], kAutoupdateInstalling);
// The rest of the update install is asynchronous & happens on a worker
// thread, so don't check it here.
} }
TEST_F(KeystoneGlueTest, isValidSystemKeystone_Nils) { TEST_F(KeystoneGlueTest, isValidSystemKeystone_Nils) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment