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