OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/mac/scoped_nsobject.h" | 8 #include "base/mac/scoped_nsobject.h" |
9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "content/public/browser/notification_service.h" | 24 #include "content/public/browser/notification_service.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
26 #import "testing/gtest_mac.h" | 26 #import "testing/gtest_mac.h" |
27 #include "testing/platform_test.h" | 27 #include "testing/platform_test.h" |
28 | 28 |
29 using base::ASCIIToUTF16; | 29 using base::ASCIIToUTF16; |
30 using bookmarks::BookmarkModel; | 30 using bookmarks::BookmarkModel; |
31 using bookmarks::BookmarkNode; | 31 using bookmarks::BookmarkNode; |
32 using content::WebContents; | 32 using content::WebContents; |
33 | 33 |
34 // Watch for bookmark pulse notifications so we can confirm they were sent. | |
35 @interface BookmarkPulseObserver : NSObject { | |
36 int notifications_; | |
37 } | |
38 @property (assign, nonatomic) int notifications; | |
39 @end | |
40 | |
41 | |
42 @implementation BookmarkPulseObserver | |
43 | |
44 @synthesize notifications = notifications_; | |
45 | |
46 - (id)init { | |
47 if ((self = [super init])) { | |
48 [[NSNotificationCenter defaultCenter] | |
49 addObserver:self | |
50 selector:@selector(pulseBookmarkNotification:) | |
51 name:bookmark_button::kPulseBookmarkButtonNotification | |
52 object:nil]; | |
53 } | |
54 return self; | |
55 } | |
56 | |
57 - (void)pulseBookmarkNotification:(NSNotificationCenter *)notification { | |
58 notifications_++; | |
59 } | |
60 | |
61 - (void)dealloc { | |
62 [[NSNotificationCenter defaultCenter] removeObserver:self]; | |
63 [super dealloc]; | |
64 } | |
65 | |
66 @end | |
67 | |
68 | |
69 namespace { | 34 namespace { |
70 | 35 |
71 // URL of the test bookmark. | 36 // URL of the test bookmark. |
72 const char kTestBookmarkURL[] = "http://www.google.com"; | 37 const char kTestBookmarkURL[] = "http://www.google.com"; |
73 | 38 |
74 class BookmarkBubbleControllerTest : public CocoaProfileTest { | 39 class BookmarkBubbleControllerTest : public CocoaProfileTest { |
75 public: | 40 public: |
76 static int edits_; | 41 static int edits_; |
77 BookmarkBubbleController* controller_; | 42 BookmarkBubbleController* controller_; |
78 | 43 |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 if ([[item title] length] == 0 && | 200 if ([[item title] length] == 0 && |
236 static_cast<const BookmarkNode*>([[item representedObject] | 201 static_cast<const BookmarkNode*>([[item representedObject] |
237 pointerValue]) == node2) { | 202 pointerValue]) == node2) { |
238 blankFolderFound = YES; | 203 blankFolderFound = YES; |
239 break; | 204 break; |
240 } | 205 } |
241 } | 206 } |
242 EXPECT_TRUE(blankFolderFound); | 207 EXPECT_TRUE(blankFolderFound); |
243 } | 208 } |
244 | 209 |
245 | |
246 // Click on edit; bubble gets closed. | 210 // Click on edit; bubble gets closed. |
247 TEST_F(BookmarkBubbleControllerTest, TestEdit) { | 211 TEST_F(BookmarkBubbleControllerTest, TestEdit) { |
248 const BookmarkNode* node = CreateTestBookmark(); | 212 const BookmarkNode* node = CreateTestBookmark(); |
249 BookmarkBubbleController* controller = ControllerForNode(node); | 213 BookmarkBubbleController* controller = ControllerForNode(node); |
250 EXPECT_TRUE(controller); | 214 EXPECT_TRUE(controller); |
251 | 215 |
252 EXPECT_EQ(edits_, 0); | 216 EXPECT_EQ(edits_, 0); |
253 EXPECT_FALSE(IsWindowClosing()); | 217 EXPECT_FALSE(IsWindowClosing()); |
254 [controller edit:controller]; | 218 [controller edit:controller]; |
255 EXPECT_EQ(edits_, 1); | 219 EXPECT_EQ(edits_, 1); |
256 EXPECT_TRUE(IsWindowClosing()); | 220 EXPECT_TRUE(IsWindowClosing()); |
257 } | 221 } |
258 | 222 |
259 // CallClose; bubble gets closed. | 223 // CallClose; bubble gets closed. |
260 // Also confirm pulse notifications get sent. | 224 // Also confirm pulse notifications get sent. |
261 TEST_F(BookmarkBubbleControllerTest, TestClose) { | 225 TEST_F(BookmarkBubbleControllerTest, TestClose) { |
262 const BookmarkNode* node = CreateTestBookmark(); | 226 const BookmarkNode* node = CreateTestBookmark(); |
263 EXPECT_EQ(edits_, 0); | 227 EXPECT_EQ(edits_, 0); |
264 | 228 |
265 base::scoped_nsobject<BookmarkPulseObserver> observer( | |
266 [[BookmarkPulseObserver alloc] init]); | |
267 EXPECT_EQ([observer notifications], 0); | |
268 BookmarkBubbleController* controller = ControllerForNode(node); | 229 BookmarkBubbleController* controller = ControllerForNode(node); |
| 230 EXPECT_EQ(node, controller.pulsingBookmarkNode); |
269 EXPECT_TRUE(controller); | 231 EXPECT_TRUE(controller); |
270 EXPECT_FALSE(IsWindowClosing()); | 232 EXPECT_FALSE(IsWindowClosing()); |
271 EXPECT_EQ([observer notifications], 1); | |
272 [controller ok:controller]; | 233 [controller ok:controller]; |
273 EXPECT_EQ(edits_, 0); | 234 EXPECT_EQ(edits_, 0); |
274 EXPECT_TRUE(IsWindowClosing()); | 235 EXPECT_TRUE(IsWindowClosing()); |
275 EXPECT_EQ([observer notifications], 2); | 236 EXPECT_EQ(nullptr, controller.pulsingBookmarkNode); |
276 } | 237 } |
277 | 238 |
278 // User changes title and parent folder in the UI | 239 // User changes title and parent folder in the UI |
279 TEST_F(BookmarkBubbleControllerTest, TestUserEdit) { | 240 TEST_F(BookmarkBubbleControllerTest, TestUserEdit) { |
280 BookmarkModel* model = GetBookmarkModel(); | 241 BookmarkModel* model = GetBookmarkModel(); |
281 EXPECT_TRUE(model); | 242 EXPECT_TRUE(model); |
282 const BookmarkNode* bookmarkBarNode = model->bookmark_bar_node(); | 243 const BookmarkNode* bookmarkBarNode = model->bookmark_bar_node(); |
283 EXPECT_TRUE(bookmarkBarNode); | 244 EXPECT_TRUE(bookmarkBarNode); |
284 const BookmarkNode* node = model->AddURL(bookmarkBarNode, | 245 const BookmarkNode* node = model->AddURL(bookmarkBarNode, |
285 0, | 246 0, |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 // Normally this would be sent up the responder tree correctly, but since | 444 // Normally this would be sent up the responder tree correctly, but since |
484 // tests run in the background, key window and main window are never set on | 445 // tests run in the background, key window and main window are never set on |
485 // NSApplication. Adding it to NSApplication directly removes the need for | 446 // NSApplication. Adding it to NSApplication directly removes the need for |
486 // worrying about what the current window with focus is. | 447 // worrying about what the current window with focus is. |
487 - (void)editBookmarkNode:(id)sender { | 448 - (void)editBookmarkNode:(id)sender { |
488 EXPECT_TRUE([sender respondsToSelector:@selector(node)]); | 449 EXPECT_TRUE([sender respondsToSelector:@selector(node)]); |
489 BookmarkBubbleControllerTest::edits_++; | 450 BookmarkBubbleControllerTest::edits_++; |
490 } | 451 } |
491 | 452 |
492 @end | 453 @end |
OLD | NEW |