Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(233)

Side by Side Diff: chrome/browser/ui/cocoa/bookmarks/bookmark_bubble_controller_unittest.mm

Issue 306293006: Introduce ChromeBookmarkClientFactory (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@364865
Patch Set: Add missing dependency in components/policy/policy_browser.gypi Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/chrome_bookmark_client.h"
13 #include "chrome/browser/bookmarks/chrome_bookmark_client_factory.h"
13 #include "chrome/browser/signin/signin_manager_factory.h" 14 #include "chrome/browser/signin/signin_manager_factory.h"
14 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/browser_window.h" 16 #include "chrome/browser/ui/browser_window.h"
16 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bubble_controller.h" 17 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bubble_controller.h"
17 #include "chrome/browser/ui/cocoa/browser_window_controller.h" 18 #include "chrome/browser/ui/cocoa/browser_window_controller.h"
18 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" 19 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h"
19 #import "chrome/browser/ui/cocoa/info_bubble_window.h" 20 #import "chrome/browser/ui/cocoa/info_bubble_window.h"
20 #include "chrome/test/base/testing_profile.h" 21 #include "chrome/test/base/testing_profile.h"
22 #include "components/bookmarks/browser/bookmark_model.h"
21 #include "components/signin/core/browser/signin_manager.h" 23 #include "components/signin/core/browser/signin_manager.h"
22 #include "content/public/browser/notification_service.h" 24 #include "content/public/browser/notification_service.h"
23 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
24 #import "testing/gtest_mac.h" 26 #import "testing/gtest_mac.h"
25 #include "testing/platform_test.h" 27 #include "testing/platform_test.h"
26 28
27 using base::ASCIIToUTF16; 29 using base::ASCIIToUTF16;
28 using content::WebContents; 30 using content::WebContents;
29 31
30 // Watch for bookmark pulse notifications so we can confirm they were sent. 32 // Watch for bookmark pulse notifications so we can confirm they were sent.
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 CocoaProfileTest::TearDown(); 83 CocoaProfileTest::TearDown();
82 } 84 }
83 85
84 // Returns a controller but ownership not transferred. 86 // Returns a controller but ownership not transferred.
85 // Only one of these will be valid at a time. 87 // Only one of these will be valid at a time.
86 BookmarkBubbleController* ControllerForNode(const BookmarkNode* node) { 88 BookmarkBubbleController* ControllerForNode(const BookmarkNode* node) {
87 if (controller_ && !IsWindowClosing()) { 89 if (controller_ && !IsWindowClosing()) {
88 [controller_ close]; 90 [controller_ close];
89 controller_ = nil; 91 controller_ = nil;
90 } 92 }
93 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile());
91 ChromeBookmarkClient* client = 94 ChromeBookmarkClient* client =
92 BookmarkModelFactory::GetChromeBookmarkClientForProfile(profile()); 95 ChromeBookmarkClientFactory::GetForProfile(profile());
93 controller_ = [[BookmarkBubbleController alloc] 96 controller_ = [[BookmarkBubbleController alloc]
94 initWithParentWindow:browser()->window()->GetNativeWindow() 97 initWithParentWindow:browser()->window()->GetNativeWindow()
95 client:client 98 client:client
99 model:model
96 node:node 100 node:node
97 alreadyBookmarked:YES]; 101 alreadyBookmarked:YES];
98 EXPECT_TRUE([controller_ window]); 102 EXPECT_TRUE([controller_ window]);
99 // The window must be gone or we'll fail a unit test with windows left open. 103 // The window must be gone or we'll fail a unit test with windows left open.
100 [static_cast<InfoBubbleWindow*>([controller_ window]) 104 [static_cast<InfoBubbleWindow*>([controller_ window])
101 setAllowedAnimations:info_bubble::kAnimateNone]; 105 setAllowedAnimations:info_bubble::kAnimateNone];
102 [controller_ showWindow:nil]; 106 [controller_ showWindow:nil];
103 return controller_; 107 return controller_;
104 } 108 }
105 109
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 [button selectItemWithTitle:[[controller class] chooseAnotherFolderString]]; 386 [button selectItemWithTitle:[[controller class] chooseAnotherFolderString]];
383 EXPECT_EQ(edits_, 0); 387 EXPECT_EQ(edits_, 0);
384 [button sendAction:[button action] to:[button target]]; 388 [button sendAction:[button action] to:[button target]];
385 EXPECT_EQ(edits_, 1); 389 EXPECT_EQ(edits_, 1);
386 } 390 }
387 391
388 // Create a controller that simulates the bookmark just now being created by 392 // Create a controller that simulates the bookmark just now being created by
389 // the user clicking the star, then sending the "cancel" command to represent 393 // the user clicking the star, then sending the "cancel" command to represent
390 // them pressing escape. The bookmark should not be there. 394 // them pressing escape. The bookmark should not be there.
391 TEST_F(BookmarkBubbleControllerTest, EscapeRemovesNewBookmark) { 395 TEST_F(BookmarkBubbleControllerTest, EscapeRemovesNewBookmark) {
396 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile());
392 ChromeBookmarkClient* client = 397 ChromeBookmarkClient* client =
393 BookmarkModelFactory::GetChromeBookmarkClientForProfile(profile()); 398 ChromeBookmarkClientFactory::GetForProfile(profile());
394 const BookmarkNode* node = CreateTestBookmark(); 399 const BookmarkNode* node = CreateTestBookmark();
395 BookmarkBubbleController* controller = 400 BookmarkBubbleController* controller = [[BookmarkBubbleController alloc]
396 [[BookmarkBubbleController alloc] 401 initWithParentWindow:browser()->window()->GetNativeWindow()
397 initWithParentWindow:browser()->window()->GetNativeWindow() 402 client:client
398 client:client 403 model:model
399 node:node 404 node:node
400 alreadyBookmarked:NO]; // The last param is the key difference. 405 alreadyBookmarked:NO]; // The last param is the key difference.
401 EXPECT_TRUE([controller window]); 406 EXPECT_TRUE([controller window]);
402 // Calls release on controller. 407 // Calls release on controller.
403 [controller cancel:nil]; 408 [controller cancel:nil];
404 EXPECT_FALSE(client->model()->IsBookmarked(GURL(kTestBookmarkURL))); 409 EXPECT_FALSE(model->IsBookmarked(GURL(kTestBookmarkURL)));
405 } 410 }
406 411
407 // Create a controller where the bookmark already existed prior to clicking 412 // Create a controller where the bookmark already existed prior to clicking
408 // the star and test that sending a cancel command doesn't change the state 413 // the star and test that sending a cancel command doesn't change the state
409 // of the bookmark. 414 // of the bookmark.
410 TEST_F(BookmarkBubbleControllerTest, EscapeDoesntTouchExistingBookmark) { 415 TEST_F(BookmarkBubbleControllerTest, EscapeDoesntTouchExistingBookmark) {
411 const BookmarkNode* node = CreateTestBookmark(); 416 const BookmarkNode* node = CreateTestBookmark();
412 BookmarkBubbleController* controller = ControllerForNode(node); 417 BookmarkBubbleController* controller = ControllerForNode(node);
413 EXPECT_TRUE(controller); 418 EXPECT_TRUE(controller);
414 419
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 // 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
477 // 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
478 // NSApplication. Adding it to NSApplication directly removes the need for 483 // NSApplication. Adding it to NSApplication directly removes the need for
479 // worrying about what the current window with focus is. 484 // worrying about what the current window with focus is.
480 - (void)editBookmarkNode:(id)sender { 485 - (void)editBookmarkNode:(id)sender {
481 EXPECT_TRUE([sender respondsToSelector:@selector(node)]); 486 EXPECT_TRUE([sender respondsToSelector:@selector(node)]);
482 BookmarkBubbleControllerTest::edits_++; 487 BookmarkBubbleControllerTest::edits_++;
483 } 488 }
484 489
485 @end 490 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698