| 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/mac/scoped_nsobject.h" | 7 #include "base/mac/scoped_nsobject.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 CocoaProfileTest::TearDown(); | 75 CocoaProfileTest::TearDown(); |
| 76 } | 76 } |
| 77 | 77 |
| 78 // Returns a controller but ownership not transferred. | 78 // Returns a controller but ownership not transferred. |
| 79 // Only one of these will be valid at a time. | 79 // Only one of these will be valid at a time. |
| 80 BookmarkBubbleController* ControllerForNode(const BookmarkNode* node) { | 80 BookmarkBubbleController* ControllerForNode(const BookmarkNode* node) { |
| 81 if (controller_ && !IsWindowClosing()) { | 81 if (controller_ && !IsWindowClosing()) { |
| 82 [controller_ close]; | 82 [controller_ close]; |
| 83 controller_ = nil; | 83 controller_ = nil; |
| 84 } | 84 } |
| 85 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 85 BookmarkModel* model = |
| 86 BookmarkModelFactory::GetForBrowserContext(profile()); |
| 86 bookmarks::ManagedBookmarkService* managed = | 87 bookmarks::ManagedBookmarkService* managed = |
| 87 ManagedBookmarkServiceFactory::GetForProfile(profile()); | 88 ManagedBookmarkServiceFactory::GetForProfile(profile()); |
| 88 controller_ = [[BookmarkBubbleController alloc] | 89 controller_ = [[BookmarkBubbleController alloc] |
| 89 initWithParentWindow:browser()->window()->GetNativeWindow() | 90 initWithParentWindow:browser()->window()->GetNativeWindow() |
| 90 bubbleObserver:&test_observer_ | 91 bubbleObserver:&test_observer_ |
| 91 managed:managed | 92 managed:managed |
| 92 model:model | 93 model:model |
| 93 node:node | 94 node:node |
| 94 alreadyBookmarked:YES]; | 95 alreadyBookmarked:YES]; |
| 95 EXPECT_TRUE([controller_ window]); | 96 EXPECT_TRUE([controller_ window]); |
| 96 // The window must be gone or we'll fail a unit test with windows left open. | 97 // The window must be gone or we'll fail a unit test with windows left open. |
| 97 [static_cast<InfoBubbleWindow*>([controller_ window]) | 98 [static_cast<InfoBubbleWindow*>([controller_ window]) |
| 98 setAllowedAnimations:info_bubble::kAnimateNone]; | 99 setAllowedAnimations:info_bubble::kAnimateNone]; |
| 99 [controller_ showWindow:nil]; | 100 [controller_ showWindow:nil]; |
| 100 return controller_; | 101 return controller_; |
| 101 } | 102 } |
| 102 | 103 |
| 103 BookmarkModel* GetBookmarkModel() { | 104 BookmarkModel* GetBookmarkModel() { |
| 104 return BookmarkModelFactory::GetForProfile(profile()); | 105 return BookmarkModelFactory::GetForBrowserContext(profile()); |
| 105 } | 106 } |
| 106 | 107 |
| 107 const BookmarkNode* CreateTestBookmark() { | 108 const BookmarkNode* CreateTestBookmark() { |
| 108 BookmarkModel* model = GetBookmarkModel(); | 109 BookmarkModel* model = GetBookmarkModel(); |
| 109 return model->AddURL(model->bookmark_bar_node(), | 110 return model->AddURL(model->bookmark_bar_node(), |
| 110 0, | 111 0, |
| 111 ASCIIToUTF16("Bookie markie title"), | 112 ASCIIToUTF16("Bookie markie title"), |
| 112 GURL(kTestBookmarkURL)); | 113 GURL(kTestBookmarkURL)); |
| 113 } | 114 } |
| 114 | 115 |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 [button selectItemWithTitle:[[controller class] chooseAnotherFolderString]]; | 385 [button selectItemWithTitle:[[controller class] chooseAnotherFolderString]]; |
| 385 EXPECT_EQ(edits_, 0); | 386 EXPECT_EQ(edits_, 0); |
| 386 [button sendAction:[button action] to:[button target]]; | 387 [button sendAction:[button action] to:[button target]]; |
| 387 EXPECT_EQ(edits_, 1); | 388 EXPECT_EQ(edits_, 1); |
| 388 } | 389 } |
| 389 | 390 |
| 390 // Create a controller that simulates the bookmark just now being created by | 391 // Create a controller that simulates the bookmark just now being created by |
| 391 // the user clicking the star, then sending the "cancel" command to represent | 392 // the user clicking the star, then sending the "cancel" command to represent |
| 392 // them pressing escape. The bookmark should not be there. | 393 // them pressing escape. The bookmark should not be there. |
| 393 TEST_F(BookmarkBubbleControllerTest, EscapeRemovesNewBookmark) { | 394 TEST_F(BookmarkBubbleControllerTest, EscapeRemovesNewBookmark) { |
| 394 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 395 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
| 395 bookmarks::ManagedBookmarkService* managed = | 396 bookmarks::ManagedBookmarkService* managed = |
| 396 ManagedBookmarkServiceFactory::GetForProfile(profile()); | 397 ManagedBookmarkServiceFactory::GetForProfile(profile()); |
| 397 const BookmarkNode* node = CreateTestBookmark(); | 398 const BookmarkNode* node = CreateTestBookmark(); |
| 398 BookmarkBubbleController* controller = [[BookmarkBubbleController alloc] | 399 BookmarkBubbleController* controller = [[BookmarkBubbleController alloc] |
| 399 initWithParentWindow:browser()->window()->GetNativeWindow() | 400 initWithParentWindow:browser()->window()->GetNativeWindow() |
| 400 bubbleObserver:&test_observer_ | 401 bubbleObserver:&test_observer_ |
| 401 managed:managed | 402 managed:managed |
| 402 model:model | 403 model:model |
| 403 node:node | 404 node:node |
| 404 alreadyBookmarked:NO]; // The last param is the key difference. | 405 alreadyBookmarked:NO]; // The last param is the key difference. |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 // Normally this would be sent up the responder tree correctly, but since | 481 // Normally this would be sent up the responder tree correctly, but since |
| 481 // tests run in the background, key window and main window are never set on | 482 // tests run in the background, key window and main window are never set on |
| 482 // NSApplication. Adding it to NSApplication directly removes the need for | 483 // NSApplication. Adding it to NSApplication directly removes the need for |
| 483 // worrying about what the current window with focus is. | 484 // worrying about what the current window with focus is. |
| 484 - (void)editBookmarkNode:(id)sender { | 485 - (void)editBookmarkNode:(id)sender { |
| 485 EXPECT_TRUE([sender respondsToSelector:@selector(node)]); | 486 EXPECT_TRUE([sender respondsToSelector:@selector(node)]); |
| 486 BookmarkBubbleControllerTest::edits_++; | 487 BookmarkBubbleControllerTest::edits_++; |
| 487 } | 488 } |
| 488 | 489 |
| 489 @end | 490 @end |
| OLD | NEW |