diff options
author | mark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-26 19:58:13 +0000 |
---|---|---|
committer | mark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-26 19:58:13 +0000 |
commit | 49aeee5080135d65173fb06f117cbb19f87ae867 (patch) | |
tree | 13ea17786c1cd4c59c833906f3d26ef92a50b091 /chrome/app/keystone_glue_unittest.mm | |
parent | 8dd8ea73b9fc2571777d841a85f0b27f82530455 (diff) | |
download | chromium_src-49aeee5080135d65173fb06f117cbb19f87ae867.zip chromium_src-49aeee5080135d65173fb06f117cbb19f87ae867.tar.gz chromium_src-49aeee5080135d65173fb06f117cbb19f87ae867.tar.bz2 |
About box auto-update improvements.
The About box now knows how to check to see if updates have been installed
in the background without anyone having to click the Update button in the box.
The About box no longer gets stuck in the "installed" state. Even if an
update has been installed, the About box will still check for new updates when
reopened.
BUG=13165, 20488
TEST=Play with the about box and auto-update a whole lot
Review URL: http://codereview.chromium.org/338012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30078 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/app/keystone_glue_unittest.mm')
-rw-r--r-- | chrome/app/keystone_glue_unittest.mm | 76 |
1 files changed, 56 insertions, 20 deletions
diff --git a/chrome/app/keystone_glue_unittest.mm b/chrome/app/keystone_glue_unittest.mm index 614bdbc..90a2f40 100644 --- a/chrome/app/keystone_glue_unittest.mm +++ b/chrome/app/keystone_glue_unittest.mm @@ -14,18 +14,38 @@ @implementation FakeGlueRegistration -- (void)checkForUpdate { } -- (void)startUpdate { } + +// Send the notifications that a real KeystoneGlue object would send. + +- (void)checkForUpdate { + NSNumber* yesNumber = [NSNumber numberWithBool:YES]; + NSString* statusKey = @"Status"; + NSDictionary* dictionary = [NSDictionary dictionaryWithObject:yesNumber + forKey:statusKey]; + NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; + [center postNotificationName:@"KSRegistrationCheckForUpdateNotification" + object:nil + userInfo:dictionary]; +} + +- (void)startUpdate { + NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; + [center postNotificationName:@"KSRegistrationStartUpdateNotification" + object:nil]; +} + @end -@interface FakeKeystoneGlue : KeystoneGlue<KeystoneGlueCallbacks> { +@interface FakeKeystoneGlue : KeystoneGlue { @public BOOL upToDate_; NSString *latestVersion_; BOOL successful_; int installs_; } + +- (void)fakeAboutWindowCallback:(NSNotification*)notification; @end @@ -38,10 +58,23 @@ latestVersion_ = @"foo bar"; successful_ = YES; installs_ = 1010101010; + + // Set up an observer that takes the notification that the About window + // listens for. + NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; + [center addObserver:self + selector:@selector(fakeAboutWindowCallback:) + name:kAutoupdateStatusNotification + object:nil]; } return self; } +- (void)dealloc { + [[NSNotificationCenter defaultCenter] removeObserver:self]; + [super dealloc]; +} + // For mocking - (NSDictionary*)infoDictionary { NSDictionary* dict = [NSDictionary dictionaryWithObjectsAndKeys: @@ -69,21 +102,24 @@ return timer_ ? YES : NO; } -- (void)upToDateCheckCompleted:(BOOL)upToDate - latestVersion:(NSString*)latestVersion { - upToDate_ = upToDate; - latestVersion_ = latestVersion; -} - -- (void)updateCompleted:(BOOL)successful installs:(int)installs { - successful_ = successful; - installs_ = installs; -} - - (void)addFakeRegistration { registration_ = [[FakeGlueRegistration alloc] init]; } +- (void)fakeAboutWindowCallback:(NSNotification*)notification { + NSDictionary* dictionary = [notification userInfo]; + AutoupdateStatus status = static_cast<AutoupdateStatus>( + [[dictionary objectForKey:kAutoupdateStatusStatus] intValue]); + + if (status == kAutoupdateAvailable) { + upToDate_ = NO; + latestVersion_ = [dictionary objectForKey:kAutoupdateStatusVersion]; + } else if (status == kAutoupdateInstallFailed) { + successful_ = NO; + installs_ = 0; + } +} + // Confirm we look like callbacks with nil NSNotifications - (BOOL)confirmCallbacks { return (!upToDate_ && @@ -114,12 +150,16 @@ TEST_F(KeystoneGlueTest, BasicGlobalCreate) { Method loadMethod_ = class_getInstanceMethod([KeystoneGlue class], lks); method_setImplementation(loadMethod_, newLoadImp_); + // Dump any existing KeystoneGlue shared instance so that a new one can be + // created with the mocked methods. + [KeystoneGlue releaseDefaultKeystoneGlue]; KeystoneGlue *glue = [KeystoneGlue defaultKeystoneGlue]; ASSERT_TRUE(glue); // Fix back up the class to the way we found it. method_setImplementation(infoMethod_, oldInfoImp_); method_setImplementation(loadMethod_, oldLoadImp_); + [KeystoneGlue releaseDefaultKeystoneGlue]; } TEST_F(KeystoneGlueTest, BasicUse) { @@ -136,14 +176,10 @@ TEST_F(KeystoneGlueTest, BasicUse) { ASSERT_TRUE([glue hasATimer]); [glue stopTimer]; - ASSERT_TRUE(![glue checkForUpdate:glue] && ![glue startUpdate:glue]); - // Brief exercise of callbacks [glue addFakeRegistration]; - ASSERT_TRUE([glue checkForUpdate:glue]); - [glue checkComplete:nil]; - ASSERT_TRUE([glue startUpdate:glue]); - [glue startUpdateComplete:nil]; + [glue checkForUpdate]; + [glue installUpdate]; ASSERT_TRUE([glue confirmCallbacks]); } |