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

Side by Side Diff: chrome/browser/cocoa/about_window_controller_unittest.mm

Issue 338012: About box auto-update improvements (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import <Cocoa/Cocoa.h> 5 #import <Cocoa/Cocoa.h>
6 6
7 #import "base/scoped_nsobject.h" 7 #import "base/scoped_nsobject.h"
8 #import "chrome/app/keystone_glue.h"
8 #import "chrome/browser/cocoa/about_window_controller.h" 9 #import "chrome/browser/cocoa/about_window_controller.h"
9 #include "chrome/browser/cocoa/browser_test_helper.h" 10 #include "chrome/browser/cocoa/browser_test_helper.h"
10 #include "chrome/browser/cocoa/cocoa_test_helper.h" 11 #include "chrome/browser/cocoa/cocoa_test_helper.h"
11 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
12 #include "testing/platform_test.h" 13 #include "testing/platform_test.h"
13 14
14 namespace { 15 namespace {
15 16
17 void PostAutoupdateStatusNotification(AutoupdateStatus status,
18 NSString* version) {
19 NSNumber* statusNumber = [NSNumber numberWithInt:status];
20 NSMutableDictionary* dictionary =
21 [NSMutableDictionary dictionaryWithObjects:&statusNumber
22 forKeys:&kAutoupdateStatusStatus
23 count:1];
24 if (version) {
25 [dictionary setObject:version forKey:kAutoupdateStatusVersion];
26 }
27
28 NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
29 [center postNotificationName:kAutoupdateStatusNotification
30 object:nil
31 userInfo:dictionary];
32 }
33
16 class AboutWindowControllerTest : public PlatformTest { 34 class AboutWindowControllerTest : public PlatformTest {
17 public: 35 public:
18 virtual void SetUp() { 36 virtual void SetUp() {
19 PlatformTest::SetUp(); 37 PlatformTest::SetUp();
20 about_window_controller_.reset([[AboutWindowController alloc] 38 about_window_controller_.reset([[AboutWindowController alloc]
21 initWithProfile:nil]); 39 initWithProfile:nil]);
22 // make sure the nib is loaded 40 // make sure the nib is loaded
23 [about_window_controller_ window]; 41 [about_window_controller_ window];
24 } 42 }
25 43
26 scoped_nsobject<AboutWindowController> about_window_controller_; 44 scoped_nsobject<AboutWindowController> about_window_controller_;
27 }; 45 };
28 46
29 TEST_F(AboutWindowControllerTest, TestCopyright) { 47 TEST_F(AboutWindowControllerTest, TestCopyright) {
30 NSString* text = [BuildAboutWindowLegalTextBlock() string]; 48 NSString* text = [[AboutWindowController legalTextBlock] string];
31 49
32 // Make sure we have the word "Copyright" in it, which is present in all 50 // Make sure we have the word "Copyright" in it, which is present in all
33 // locales. 51 // locales.
34 NSRange range = [text rangeOfString:@"Copyright"]; 52 NSRange range = [text rangeOfString:@"Copyright"];
35 EXPECT_NE(NSNotFound, range.location); 53 EXPECT_NE(NSNotFound, range.location);
36 } 54 }
37 55
38 TEST_F(AboutWindowControllerTest, RemovesLinkAnchors) { 56 TEST_F(AboutWindowControllerTest, RemovesLinkAnchors) {
39 NSString* text = [BuildAboutWindowLegalTextBlock() string]; 57 NSString* text = [[AboutWindowController legalTextBlock] string];
40 58
41 // Make sure that we removed the "BEGIN_LINK" and "END_LINK" anchors. 59 // Make sure that we removed the "BEGIN_LINK" and "END_LINK" anchors.
42 NSRange range = [text rangeOfString:@"BEGIN_LINK"]; 60 NSRange range = [text rangeOfString:@"BEGIN_LINK"];
43 EXPECT_EQ(NSNotFound, range.location); 61 EXPECT_EQ(NSNotFound, range.location);
44 62
45 range = [text rangeOfString:@"END_LINK"]; 63 range = [text rangeOfString:@"END_LINK"];
46 EXPECT_EQ(NSNotFound, range.location); 64 EXPECT_EQ(NSNotFound, range.location);
47 } 65 }
48 66
49 TEST_F(AboutWindowControllerTest, AwakeNibSetsString) { 67 TEST_F(AboutWindowControllerTest, AwakeNibSetsString) {
50 NSAttributedString* legal_text = BuildAboutWindowLegalTextBlock(); 68 NSAttributedString* legal_text = [AboutWindowController legalTextBlock];
51 NSAttributedString* text_storage = 69 NSAttributedString* text_storage =
52 [[about_window_controller_ legalText] textStorage]; 70 [[about_window_controller_ legalText] textStorage];
53 71
54 EXPECT_TRUE([legal_text isEqualToAttributedString:text_storage]); 72 EXPECT_TRUE([legal_text isEqualToAttributedString:text_storage]);
55 } 73 }
56 74
57 TEST_F(AboutWindowControllerTest, TestButton) { 75 TEST_F(AboutWindowControllerTest, TestButton) {
58 NSButton* button = [about_window_controller_ updateButton]; 76 NSButton* button = [about_window_controller_ updateButton];
59 ASSERT_TRUE(button); 77 ASSERT_TRUE(button);
60 78
61 // Not enabled until we know if updates are available. 79 // Not enabled until we know if updates are available.
62 ASSERT_FALSE([button isEnabled]); 80 ASSERT_FALSE([button isEnabled]);
63 [about_window_controller_ upToDateCheckCompleted:YES latestVersion:nil]; 81 PostAutoupdateStatusNotification(kAutoupdateAvailable, nil);
64 ASSERT_TRUE([button isEnabled]); 82 ASSERT_TRUE([button isEnabled]);
65 83
66 // Make sure the button is hooked up 84 // Make sure the button is hooked up
67 ASSERT_EQ([button target], about_window_controller_.get()); 85 ASSERT_EQ([button target], about_window_controller_.get());
68 ASSERT_EQ([button action], @selector(updateNow:)); 86 ASSERT_EQ([button action], @selector(updateNow:));
69 87
70 // Make sure the button is disabled once clicked 88 // Make sure the button is disabled once clicked
71 [about_window_controller_ updateNow:about_window_controller_.get()]; 89 [about_window_controller_ updateNow:about_window_controller_.get()];
72 ASSERT_FALSE([button isEnabled]); 90 ASSERT_FALSE([button isEnabled]);
73 } 91 }
74 92
75 // Doesn't confirm correctness, but does confirm something happens. 93 // Doesn't confirm correctness, but does confirm something happens.
76 TEST_F(AboutWindowControllerTest, TestCallbacks) { 94 TEST_F(AboutWindowControllerTest, TestCallbacks) {
77 NSString *lastText = [[about_window_controller_ updateText] 95 NSString *lastText = [[about_window_controller_ updateText]
78 stringValue]; 96 stringValue];
79 [about_window_controller_ upToDateCheckCompleted:NO latestVersion:@"foo"]; 97 PostAutoupdateStatusNotification(kAutoupdateCurrent, @"foo");
80 ASSERT_FALSE([lastText isEqual:[[about_window_controller_ updateText] 98 ASSERT_FALSE([lastText isEqual:[[about_window_controller_ updateText]
81 stringValue]]); 99 stringValue]]);
82 100
83 lastText = [[about_window_controller_ updateText] stringValue]; 101 lastText = [[about_window_controller_ updateText] stringValue];
84 [about_window_controller_ updateCompleted:NO installs:0]; 102 PostAutoupdateStatusNotification(kAutoupdateCurrent, @"foo");
103 ASSERT_TRUE([lastText isEqual:[[about_window_controller_ updateText]
104 stringValue]]);
105
106 lastText = [[about_window_controller_ updateText] stringValue];
107 PostAutoupdateStatusNotification(kAutoupdateCurrent, @"bar");
108 ASSERT_FALSE([lastText isEqual:[[about_window_controller_ updateText]
109 stringValue]]);
110
111 lastText = [[about_window_controller_ updateText] stringValue];
112 PostAutoupdateStatusNotification(kAutoupdateAvailable, nil);
113 ASSERT_FALSE([lastText isEqual:[[about_window_controller_ updateText]
114 stringValue]]);
115
116 lastText = [[about_window_controller_ updateText] stringValue];
117 PostAutoupdateStatusNotification(kAutoupdateCheckFailed, nil);
118 ASSERT_FALSE([lastText isEqual:[[about_window_controller_ updateText]
119 stringValue]]);
120
121 #if 0
122 // TODO(mark): The kAutoupdateInstalled portion of the test is disabled
123 // because it leaks restart dialogs. If the About box is revised to use
124 // a button within the box to advise a restart instead of popping dialogs,
125 // these tests should be enabled.
126
127 lastText = [[about_window_controller_ updateText] stringValue];
128 PostAutoupdateStatusNotification(kAutoupdateInstalled, @"ver");
129 ASSERT_FALSE([lastText isEqual:[[about_window_controller_ updateText]
130 stringValue]]);
131
132 lastText = [[about_window_controller_ updateText] stringValue];
133 PostAutoupdateStatusNotification(kAutoupdateInstalled, nil);
134 ASSERT_FALSE([lastText isEqual:[[about_window_controller_ updateText]
135 stringValue]]);
136 #endif
137
138 lastText = [[about_window_controller_ updateText] stringValue];
139 PostAutoupdateStatusNotification(kAutoupdateInstallFailed, nil);
85 ASSERT_FALSE([lastText isEqual:[[about_window_controller_ 140 ASSERT_FALSE([lastText isEqual:[[about_window_controller_
86 updateText] stringValue]]); 141 updateText] stringValue]]);
87 } 142 }
88 143
89 } // namespace 144 } // namespace
90
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/about_window_controller.mm ('k') | chrome/browser/cocoa/restart_browser.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698