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

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

Issue 10827060: Removing instances of profile_->GetBookmarkModel() as part of converting BookmarkModel to a PKS. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 5 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include "base/memory/scoped_nsobject.h" 5 #include "base/memory/scoped_nsobject.h"
6 #include "base/utf_string_conversions.h" 6 #include "base/utf_string_conversions.h"
7 #include "chrome/browser/bookmarks/bookmark_model.h" 7 #include "chrome/browser/bookmarks/bookmark_model.h"
8 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
8 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button.h" 9 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button.h"
9 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button_cell.h" 10 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button_cell.h"
10 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" 11 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h"
11 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
12 #include "testing/platform_test.h" 13 #include "testing/platform_test.h"
13 #import "ui/base/test/cocoa_test_event_utils.h" 14 #import "ui/base/test/cocoa_test_event_utils.h"
14 15
15 // Fake BookmarkButton delegate to get a pong on mouse entered/exited 16 // Fake BookmarkButton delegate to get a pong on mouse entered/exited
16 @interface FakeButtonDelegate : NSObject<BookmarkButtonDelegate> { 17 @interface FakeButtonDelegate : NSObject<BookmarkButtonDelegate> {
17 @public 18 @public
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 80
80 EXPECT_TRUE([button isEmpty]); 81 EXPECT_TRUE([button isEmpty]);
81 EXPECT_FALSE([button isFolder]); 82 EXPECT_FALSE([button isFolder]);
82 EXPECT_FALSE([button bookmarkNode]); 83 EXPECT_FALSE([button bookmarkNode]);
83 84
84 NSEvent* downEvent = 85 NSEvent* downEvent =
85 cocoa_test_event_utils::LeftMouseDownAtPoint(NSMakePoint(10,10)); 86 cocoa_test_event_utils::LeftMouseDownAtPoint(NSMakePoint(10,10));
86 // Since this returns (does not actually begin a modal drag), success! 87 // Since this returns (does not actually begin a modal drag), success!
87 [button beginDrag:downEvent]; 88 [button beginDrag:downEvent];
88 89
89 BookmarkModel* model = profile()->GetBookmarkModel(); 90 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile());
90 const BookmarkNode* node = model->bookmark_bar_node(); 91 const BookmarkNode* node = model->bookmark_bar_node();
91 [cell setBookmarkNode:node]; 92 [cell setBookmarkNode:node];
92 EXPECT_FALSE([button isEmpty]); 93 EXPECT_FALSE([button isEmpty]);
93 EXPECT_TRUE([button isFolder]); 94 EXPECT_TRUE([button isFolder]);
94 EXPECT_EQ([button bookmarkNode], node); 95 EXPECT_EQ([button bookmarkNode], node);
95 96
96 node = model->AddURL(node, 0, ASCIIToUTF16("hi mom"), 97 node = model->AddURL(node, 0, ASCIIToUTF16("hi mom"),
97 GURL("http://www.google.com")); 98 GURL("http://www.google.com"));
98 [cell setBookmarkNode:node]; 99 [cell setBookmarkNode:node];
99 EXPECT_FALSE([button isEmpty]); 100 EXPECT_FALSE([button isEmpty]);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 scoped_nsobject<BookmarkButton> button; 133 scoped_nsobject<BookmarkButton> button;
133 scoped_nsobject<BookmarkButtonCell> cell; 134 scoped_nsobject<BookmarkButtonCell> cell;
134 scoped_nsobject<FakeButtonDelegate> 135 scoped_nsobject<FakeButtonDelegate>
135 delegate([[FakeButtonDelegate alloc] init]); 136 delegate([[FakeButtonDelegate alloc] init]);
136 button.reset([[BookmarkButton alloc] initWithFrame:NSMakeRect(0,0,500,500)]); 137 button.reset([[BookmarkButton alloc] initWithFrame:NSMakeRect(0,0,500,500)]);
137 cell.reset([[BookmarkButtonCell alloc] initTextCell:@"hi mom"]); 138 cell.reset([[BookmarkButtonCell alloc] initTextCell:@"hi mom"]);
138 [button setCell:cell]; 139 [button setCell:cell];
139 [button setDelegate:delegate]; 140 [button setDelegate:delegate];
140 141
141 // Add a deletable bookmark to the button. 142 // Add a deletable bookmark to the button.
142 BookmarkModel* model = profile()->GetBookmarkModel(); 143 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile());
143 const BookmarkNode* barNode = model->bookmark_bar_node(); 144 const BookmarkNode* barNode = model->bookmark_bar_node();
144 const BookmarkNode* node = model->AddURL(barNode, 0, ASCIIToUTF16("hi mom"), 145 const BookmarkNode* node = model->AddURL(barNode, 0, ASCIIToUTF16("hi mom"),
145 GURL("http://www.google.com")); 146 GURL("http://www.google.com"));
146 [cell setBookmarkNode:node]; 147 [cell setBookmarkNode:node];
147 148
148 // Verify that if canDragBookmarkButtonToTrash is NO then the button can't 149 // Verify that if canDragBookmarkButtonToTrash is NO then the button can't
149 // be dragged to the trash. 150 // be dragged to the trash.
150 delegate.get()->canDragToTrash_ = NO; 151 delegate.get()->canDragToTrash_ = NO;
151 NSDragOperation operation = [button draggingSourceOperationMaskForLocal:NO]; 152 NSDragOperation operation = [button draggingSourceOperationMaskForLocal:NO];
152 EXPECT_EQ(0u, operation & NSDragOperationDelete); 153 EXPECT_EQ(0u, operation & NSDragOperationDelete);
(...skipping 13 matching lines...) Expand all
166 EXPECT_EQ(0, delegate.get()->didDragToTrashCount_); 167 EXPECT_EQ(0, delegate.get()->didDragToTrashCount_);
167 [button draggedImage:nil endedAt:NSZeroPoint operation:NSDragOperationCopy]; 168 [button draggedImage:nil endedAt:NSZeroPoint operation:NSDragOperationCopy];
168 EXPECT_EQ(0, delegate.get()->didDragToTrashCount_); 169 EXPECT_EQ(0, delegate.get()->didDragToTrashCount_);
169 [button draggedImage:nil endedAt:NSZeroPoint operation:NSDragOperationMove]; 170 [button draggedImage:nil endedAt:NSZeroPoint operation:NSDragOperationMove];
170 EXPECT_EQ(0, delegate.get()->didDragToTrashCount_); 171 EXPECT_EQ(0, delegate.get()->didDragToTrashCount_);
171 [button draggedImage:nil endedAt:NSZeroPoint operation:NSDragOperationDelete]; 172 [button draggedImage:nil endedAt:NSZeroPoint operation:NSDragOperationDelete];
172 EXPECT_EQ(1, delegate.get()->didDragToTrashCount_); 173 EXPECT_EQ(1, delegate.get()->didDragToTrashCount_);
173 } 174 }
174 175
175 } 176 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698