Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3037)

Unified Diff: chrome/app/keystone_glue_unittest.mm

Issue 338012: About box auto-update improvements (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/app/keystone_glue.mm ('k') | chrome/browser/app_controller_mac.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/app/keystone_glue_unittest.mm
===================================================================
--- chrome/app/keystone_glue_unittest.mm (revision 30049)
+++ chrome/app/keystone_glue_unittest.mm (working copy)
@@ -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,19 +102,22 @@
return timer_ ? YES : NO;
}
-- (void)upToDateCheckCompleted:(BOOL)upToDate
- latestVersion:(NSString*)latestVersion {
- upToDate_ = upToDate;
- latestVersion_ = latestVersion;
+- (void)addFakeRegistration {
+ registration_ = [[FakeGlueRegistration alloc] init];
}
-- (void)updateCompleted:(BOOL)successful installs:(int)installs {
- successful_ = successful;
- installs_ = installs;
-}
+- (void)fakeAboutWindowCallback:(NSNotification*)notification {
+ NSDictionary* dictionary = [notification userInfo];
+ AutoupdateStatus status = static_cast<AutoupdateStatus>(
+ [[dictionary objectForKey:kAutoupdateStatusStatus] intValue]);
-- (void)addFakeRegistration {
- registration_ = [[FakeGlueRegistration alloc] init];
+ 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
@@ -114,12 +150,16 @@
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 @@
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]);
}
Property changes on: chrome/app/keystone_glue_unittest.mm
___________________________________________________________________
Added: svn:eol-style
+ LF
« no previous file with comments | « chrome/app/keystone_glue.mm ('k') | chrome/browser/app_controller_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698