OLD | NEW |
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" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 } | 72 } |
73 | 73 |
74 virtual void TearDown() { | 74 virtual void TearDown() { |
75 [controller_ close]; | 75 [controller_ close]; |
76 CocoaTest::TearDown(); | 76 CocoaTest::TearDown(); |
77 } | 77 } |
78 | 78 |
79 // Returns a controller but ownership not transferred. | 79 // Returns a controller but ownership not transferred. |
80 // Only one of these will be valid at a time. | 80 // Only one of these will be valid at a time. |
81 BookmarkBubbleController* ControllerForNode(const BookmarkNode* node) { | 81 BookmarkBubbleController* ControllerForNode(const BookmarkNode* node) { |
82 DCHECK(controller_ == nil); | 82 if (controller_) |
| 83 [controller_ close]; |
83 controller_ = [[BookmarkBubbleController alloc] | 84 controller_ = [[BookmarkBubbleController alloc] |
84 initWithDelegate:delegate_.get() | 85 initWithDelegate:delegate_.get() |
85 parentWindow:test_window() | 86 parentWindow:test_window() |
86 topLeftForBubble:[delegate_ topLeftForBubble] | 87 topLeftForBubble:[delegate_ topLeftForBubble] |
87 model:helper_.profile()->GetBookmarkModel() | 88 model:helper_.profile()->GetBookmarkModel() |
88 node:node | 89 node:node |
89 alreadyBookmarked:YES]; | 90 alreadyBookmarked:YES]; |
90 EXPECT_TRUE([controller_ window]); | 91 EXPECT_TRUE([controller_ window]); |
91 [delegate_ setWindowController:controller_]; | 92 [delegate_ setWindowController:controller_]; |
92 return controller_; | 93 return controller_; |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 | 190 |
190 // simulate a user edit | 191 // simulate a user edit |
191 [controller setTitle:@"oops" parentFolder:@"grandma"]; | 192 [controller setTitle:@"oops" parentFolder:@"grandma"]; |
192 [controller edit:controller]; | 193 [controller edit:controller]; |
193 | 194 |
194 // Make sure bookmark has changed | 195 // Make sure bookmark has changed |
195 EXPECT_EQ(node->GetTitle(), L"oops"); | 196 EXPECT_EQ(node->GetTitle(), L"oops"); |
196 EXPECT_EQ(node->GetParent()->GetTitle(), L"grandma"); | 197 EXPECT_EQ(node->GetParent()->GetTitle(), L"grandma"); |
197 } | 198 } |
198 | 199 |
| 200 // Confirm happiness with parent nodes that have the same name. |
| 201 TEST_F(BookmarkBubbleControllerTest, TestNewParentSameName) { |
| 202 for (int i=0; i<2; i++) { |
| 203 BookmarkModel* model = GetBookmarkModel(); |
| 204 const BookmarkNode* node = model->AddURL(model->GetBookmarkBarNode(), |
| 205 0, |
| 206 L"short-title", |
| 207 GURL("http://www.google.com")); |
| 208 model->AddGroup(model->GetBookmarkBarNode(), 0, L"NAME"); |
| 209 model->AddGroup(model->GetBookmarkBarNode(), 0, L"NAME"); |
| 210 model->AddGroup(model->GetBookmarkBarNode(), 0, L"NAME"); |
| 211 BookmarkBubbleController* controller = ControllerForNode(node); |
| 212 EXPECT_TRUE(controller); |
| 213 |
| 214 // simulate a user edit |
| 215 [controller setParentFolderSelection: |
| 216 model->GetBookmarkBarNode()->GetChild(i)]; |
| 217 [controller edit:controller]; |
| 218 |
| 219 // Make sure bookmark has changed, and that the parent is what we |
| 220 // expect. This proves nobody did searching based on name. |
| 221 EXPECT_EQ(node->GetParent(), model->GetBookmarkBarNode()->GetChild(i)); |
| 222 } |
| 223 } |
| 224 |
199 // Click the "remove" button | 225 // Click the "remove" button |
200 TEST_F(BookmarkBubbleControllerTest, TestRemove) { | 226 TEST_F(BookmarkBubbleControllerTest, TestRemove) { |
201 BookmarkModel* model = GetBookmarkModel(); | 227 BookmarkModel* model = GetBookmarkModel(); |
202 GURL gurl("http://www.google.com"); | 228 GURL gurl("http://www.google.com"); |
203 const BookmarkNode* node = model->AddURL(model->GetBookmarkBarNode(), | 229 const BookmarkNode* node = model->AddURL(model->GetBookmarkBarNode(), |
204 0, | 230 0, |
205 L"Bookie markie title", | 231 L"Bookie markie title", |
206 gurl); | 232 gurl); |
207 BookmarkBubbleController* controller = ControllerForNode(node); | 233 BookmarkBubbleController* controller = ControllerForNode(node); |
208 EXPECT_TRUE(controller); | 234 EXPECT_TRUE(controller); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 L"Bookie markie title", | 290 L"Bookie markie title", |
265 gurl); | 291 gurl); |
266 BookmarkBubbleController* controller = ControllerForNode(node); | 292 BookmarkBubbleController* controller = ControllerForNode(node); |
267 EXPECT_TRUE(controller); | 293 EXPECT_TRUE(controller); |
268 | 294 |
269 [(id)controller cancel:nil]; | 295 [(id)controller cancel:nil]; |
270 EXPECT_TRUE(model->IsBookmarked(gurl)); | 296 EXPECT_TRUE(model->IsBookmarked(gurl)); |
271 } | 297 } |
272 | 298 |
273 } // namespace | 299 } // namespace |
OLD | NEW |