| 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" |
| 11 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 11 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 12 #include "chrome/browser/bookmarks/chrome_bookmark_client.h" | 12 #include "chrome/browser/bookmarks/managed_bookmark_service_factory.h" |
| 13 #include "chrome/browser/bookmarks/chrome_bookmark_client_factory.h" | |
| 14 #include "chrome/browser/signin/signin_manager_factory.h" | 13 #include "chrome/browser/signin/signin_manager_factory.h" |
| 15 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 16 #include "chrome/browser/ui/browser_window.h" | 15 #include "chrome/browser/ui/browser_window.h" |
| 17 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bubble_controller.h" | 16 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bubble_controller.h" |
| 18 #include "chrome/browser/ui/cocoa/browser_window_controller.h" | 17 #include "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 19 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" | 18 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" |
| 20 #import "chrome/browser/ui/cocoa/info_bubble_window.h" | 19 #import "chrome/browser/ui/cocoa/info_bubble_window.h" |
| 21 #include "chrome/test/base/testing_profile.h" | 20 #include "chrome/test/base/testing_profile.h" |
| 22 #include "components/bookmarks/browser/bookmark_model.h" | 21 #include "components/bookmarks/browser/bookmark_model.h" |
| 22 #include "components/bookmarks/managed/managed_bookmark_service.h" |
| 23 #include "components/signin/core/browser/signin_manager.h" | 23 #include "components/signin/core/browser/signin_manager.h" |
| 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; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 } | 86 } |
| 87 | 87 |
| 88 // Returns a controller but ownership not transferred. | 88 // Returns a controller but ownership not transferred. |
| 89 // Only one of these will be valid at a time. | 89 // Only one of these will be valid at a time. |
| 90 BookmarkBubbleController* ControllerForNode(const BookmarkNode* node) { | 90 BookmarkBubbleController* ControllerForNode(const BookmarkNode* node) { |
| 91 if (controller_ && !IsWindowClosing()) { | 91 if (controller_ && !IsWindowClosing()) { |
| 92 [controller_ close]; | 92 [controller_ close]; |
| 93 controller_ = nil; | 93 controller_ = nil; |
| 94 } | 94 } |
| 95 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 95 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); |
| 96 ChromeBookmarkClient* client = | 96 bookmarks::ManagedBookmarkService* managed = |
| 97 ChromeBookmarkClientFactory::GetForProfile(profile()); | 97 ManagedBookmarkServiceFactory::GetForProfile(profile()); |
| 98 controller_ = [[BookmarkBubbleController alloc] | 98 controller_ = [[BookmarkBubbleController alloc] |
| 99 initWithParentWindow:browser()->window()->GetNativeWindow() | 99 initWithParentWindow:browser()->window()->GetNativeWindow() |
| 100 client:client | 100 managed:managed |
| 101 model:model | 101 model:model |
| 102 node:node | 102 node:node |
| 103 alreadyBookmarked:YES]; | 103 alreadyBookmarked:YES]; |
| 104 EXPECT_TRUE([controller_ window]); | 104 EXPECT_TRUE([controller_ window]); |
| 105 // The window must be gone or we'll fail a unit test with windows left open. | 105 // The window must be gone or we'll fail a unit test with windows left open. |
| 106 [static_cast<InfoBubbleWindow*>([controller_ window]) | 106 [static_cast<InfoBubbleWindow*>([controller_ window]) |
| 107 setAllowedAnimations:info_bubble::kAnimateNone]; | 107 setAllowedAnimations:info_bubble::kAnimateNone]; |
| 108 [controller_ showWindow:nil]; | 108 [controller_ showWindow:nil]; |
| 109 return controller_; | 109 return controller_; |
| 110 } | 110 } |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 EXPECT_EQ(edits_, 0); | 389 EXPECT_EQ(edits_, 0); |
| 390 [button sendAction:[button action] to:[button target]]; | 390 [button sendAction:[button action] to:[button target]]; |
| 391 EXPECT_EQ(edits_, 1); | 391 EXPECT_EQ(edits_, 1); |
| 392 } | 392 } |
| 393 | 393 |
| 394 // Create a controller that simulates the bookmark just now being created by | 394 // Create a controller that simulates the bookmark just now being created by |
| 395 // the user clicking the star, then sending the "cancel" command to represent | 395 // the user clicking the star, then sending the "cancel" command to represent |
| 396 // them pressing escape. The bookmark should not be there. | 396 // them pressing escape. The bookmark should not be there. |
| 397 TEST_F(BookmarkBubbleControllerTest, EscapeRemovesNewBookmark) { | 397 TEST_F(BookmarkBubbleControllerTest, EscapeRemovesNewBookmark) { |
| 398 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 398 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); |
| 399 ChromeBookmarkClient* client = | 399 bookmarks::ManagedBookmarkService* managed = |
| 400 ChromeBookmarkClientFactory::GetForProfile(profile()); | 400 ManagedBookmarkServiceFactory::GetForProfile(profile()); |
| 401 const BookmarkNode* node = CreateTestBookmark(); | 401 const BookmarkNode* node = CreateTestBookmark(); |
| 402 BookmarkBubbleController* controller = [[BookmarkBubbleController alloc] | 402 BookmarkBubbleController* controller = [[BookmarkBubbleController alloc] |
| 403 initWithParentWindow:browser()->window()->GetNativeWindow() | 403 initWithParentWindow:browser()->window()->GetNativeWindow() |
| 404 client:client | 404 managed:managed |
| 405 model:model | 405 model:model |
| 406 node:node | 406 node:node |
| 407 alreadyBookmarked:NO]; // The last param is the key difference. | 407 alreadyBookmarked:NO]; // The last param is the key difference. |
| 408 EXPECT_TRUE([controller window]); | 408 EXPECT_TRUE([controller window]); |
| 409 // Calls release on controller. | 409 // Calls release on controller. |
| 410 [controller cancel:nil]; | 410 [controller cancel:nil]; |
| 411 EXPECT_FALSE(model->IsBookmarked(GURL(kTestBookmarkURL))); | 411 EXPECT_FALSE(model->IsBookmarked(GURL(kTestBookmarkURL))); |
| 412 } | 412 } |
| 413 | 413 |
| 414 // Create a controller where the bookmark already existed prior to clicking | 414 // Create a controller where the bookmark already existed prior to clicking |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 // Normally this would be sent up the responder tree correctly, but since | 483 // 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 | 484 // 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 | 485 // NSApplication. Adding it to NSApplication directly removes the need for |
| 486 // worrying about what the current window with focus is. | 486 // worrying about what the current window with focus is. |
| 487 - (void)editBookmarkNode:(id)sender { | 487 - (void)editBookmarkNode:(id)sender { |
| 488 EXPECT_TRUE([sender respondsToSelector:@selector(node)]); | 488 EXPECT_TRUE([sender respondsToSelector:@selector(node)]); |
| 489 BookmarkBubbleControllerTest::edits_++; | 489 BookmarkBubbleControllerTest::edits_++; |
| 490 } | 490 } |
| 491 | 491 |
| 492 @end | 492 @end |
| OLD | NEW |