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

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

Issue 2805099: Pulse new bookmarks (as triggered by bookmark bubble). If not possible, ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 5 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 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 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/scoped_nsobject.h" 8 #include "base/scoped_nsobject.h"
9 #import "chrome/browser/cocoa/bookmark_bubble_controller.h" 9 #import "chrome/browser/cocoa/bookmark_bubble_controller.h"
10 #include "chrome/browser/cocoa/browser_test_helper.h" 10 #include "chrome/browser/cocoa/browser_test_helper.h"
11 #include "chrome/browser/cocoa/browser_window_controller.h" 11 #include "chrome/browser/cocoa/browser_window_controller.h"
12 #import "chrome/browser/cocoa/cocoa_test_helper.h" 12 #import "chrome/browser/cocoa/cocoa_test_helper.h"
13 #import "chrome/browser/cocoa/info_bubble_window.h" 13 #import "chrome/browser/cocoa/info_bubble_window.h"
14 #include "chrome/common/notification_service.h" 14 #include "chrome/common/notification_service.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "testing/platform_test.h" 16 #include "testing/platform_test.h"
17 17
18 // Watch for bookmark pulse notifications so we can confirm they were sent.
19 @interface BookmarkPulseObserver : NSObject {
20 int notifications_;
21 }
22 @property (assign, nonatomic) int notifications;
23 @end
24
25
26 @implementation BookmarkPulseObserver
27
28 @synthesize notifications = notifications_;
29
30 - (id)init {
31 if ((self = [super init])) {
32 [[NSNotificationCenter defaultCenter]
33 addObserver:self
34 selector:@selector(pulseBookmarkNotification:)
35 name:bookmark_button::kPulseBookmarkButtonNotification
36 object:nil];
37 }
38 return self;
39 }
40
41 - (void)pulseBookmarkNotification:(NSNotificationCenter *)notification {
42 notifications_++;
43 }
44
45 - (void)dealloc {
46 [[NSNotificationCenter defaultCenter] removeObserver:self];
47 [super dealloc];
48 }
49
50 @end
51
52
18 namespace { 53 namespace {
19 54
20 class BookmarkBubbleControllerTest : public CocoaTest { 55 class BookmarkBubbleControllerTest : public CocoaTest {
21 public: 56 public:
22 static int edits_; 57 static int edits_;
23 BrowserTestHelper helper_; 58 BrowserTestHelper helper_;
24 BookmarkBubbleController* controller_; 59 BookmarkBubbleController* controller_;
25 60
26 BookmarkBubbleControllerTest() : controller_(nil) { 61 BookmarkBubbleControllerTest() : controller_(nil) {
27 edits_ = 0; 62 edits_ = 0;
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 EXPECT_TRUE(controller); 215 EXPECT_TRUE(controller);
181 216
182 EXPECT_EQ(edits_, 0); 217 EXPECT_EQ(edits_, 0);
183 EXPECT_FALSE(IsWindowClosing()); 218 EXPECT_FALSE(IsWindowClosing());
184 [controller edit:controller]; 219 [controller edit:controller];
185 EXPECT_EQ(edits_, 1); 220 EXPECT_EQ(edits_, 1);
186 EXPECT_TRUE(IsWindowClosing()); 221 EXPECT_TRUE(IsWindowClosing());
187 } 222 }
188 223
189 // CallClose; bubble gets closed. 224 // CallClose; bubble gets closed.
225 // Also confirm pulse notifications get sent.
190 TEST_F(BookmarkBubbleControllerTest, TestClose) { 226 TEST_F(BookmarkBubbleControllerTest, TestClose) {
191 BookmarkModel* model = GetBookmarkModel(); 227 BookmarkModel* model = GetBookmarkModel();
192 const BookmarkNode* node = model->AddURL(model->GetBookmarkBarNode(), 228 const BookmarkNode* node = model->AddURL(model->GetBookmarkBarNode(),
193 0, 229 0,
194 L"Bookie markie title", 230 L"Bookie markie title",
195 GURL("http://www.google.com")); 231 GURL("http://www.google.com"));
196 EXPECT_EQ(edits_, 0); 232 EXPECT_EQ(edits_, 0);
197 233
234 scoped_nsobject<BookmarkPulseObserver> observer([[BookmarkPulseObserver alloc]
235 init]);
236 EXPECT_EQ([observer notifications], 0);
198 BookmarkBubbleController* controller = ControllerForNode(node); 237 BookmarkBubbleController* controller = ControllerForNode(node);
199 EXPECT_TRUE(controller); 238 EXPECT_TRUE(controller);
200 EXPECT_FALSE(IsWindowClosing()); 239 EXPECT_FALSE(IsWindowClosing());
240 EXPECT_EQ([observer notifications], 1);
201 [controller ok:controller]; 241 [controller ok:controller];
202 EXPECT_EQ(edits_, 0); 242 EXPECT_EQ(edits_, 0);
203 EXPECT_TRUE(IsWindowClosing()); 243 EXPECT_TRUE(IsWindowClosing());
244 EXPECT_EQ([observer notifications], 2);
204 } 245 }
205 246
206 // User changes title and parent folder in the UI 247 // User changes title and parent folder in the UI
207 TEST_F(BookmarkBubbleControllerTest, TestUserEdit) { 248 TEST_F(BookmarkBubbleControllerTest, TestUserEdit) {
208 BookmarkModel* model = GetBookmarkModel(); 249 BookmarkModel* model = GetBookmarkModel();
209 EXPECT_TRUE(model); 250 EXPECT_TRUE(model);
210 const BookmarkNode* bookmarkBarNode = model->GetBookmarkBarNode(); 251 const BookmarkNode* bookmarkBarNode = model->GetBookmarkBarNode();
211 EXPECT_TRUE(bookmarkBarNode); 252 EXPECT_TRUE(bookmarkBarNode);
212 const BookmarkNode* node = model->AddURL(bookmarkBarNode, 253 const BookmarkNode* node = model->AddURL(bookmarkBarNode,
213 0, 254 0,
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 // Normally this would be sent up the responder tree correctly, but since 465 // Normally this would be sent up the responder tree correctly, but since
425 // tests run in the background, key window and main window are never set on 466 // tests run in the background, key window and main window are never set on
426 // NSApplication. Adding it to NSApplication directly removes the need for 467 // NSApplication. Adding it to NSApplication directly removes the need for
427 // worrying about what the current window with focus is. 468 // worrying about what the current window with focus is.
428 - (void)editBookmarkNode:(id)sender { 469 - (void)editBookmarkNode:(id)sender {
429 EXPECT_TRUE([sender respondsToSelector:@selector(node)]); 470 EXPECT_TRUE([sender respondsToSelector:@selector(node)]);
430 BookmarkBubbleControllerTest::edits_++; 471 BookmarkBubbleControllerTest::edits_++;
431 } 472 }
432 473
433 @end 474 @end
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/bookmark_bubble_controller.mm ('k') | chrome/browser/cocoa/bookmark_button.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698