OLD | NEW |
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 #import <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
6 | 6 |
7 #include "base/string16.h" | 7 #include "base/string16.h" |
8 #include "base/sys_string_conversions.h" | 8 #include "base/sys_string_conversions.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/bookmarks/bookmark_model.h" | 10 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 11 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
11 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_editor_controller.h" | 12 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_editor_controller.h" |
12 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" | 13 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
14 #import "testing/gtest_mac.h" | 15 #import "testing/gtest_mac.h" |
15 #include "testing/platform_test.h" | 16 #include "testing/platform_test.h" |
16 | 17 |
17 class BookmarkEditorControllerTest : public CocoaProfileTest { | 18 class BookmarkEditorControllerTest : public CocoaProfileTest { |
18 public: | 19 public: |
19 const BookmarkNode* default_node_; | 20 const BookmarkNode* default_node_; |
20 const BookmarkNode* default_parent_; | 21 const BookmarkNode* default_parent_; |
21 const char* default_name_; | 22 const char* default_name_; |
22 string16 default_title_; | 23 string16 default_title_; |
23 BookmarkEditorController* controller_; | 24 BookmarkEditorController* controller_; |
24 | 25 |
25 virtual void SetUp() { | 26 virtual void SetUp() { |
26 CocoaProfileTest::SetUp(); | 27 CocoaProfileTest::SetUp(); |
27 ASSERT_TRUE(profile()); | 28 ASSERT_TRUE(profile()); |
28 | 29 |
29 BookmarkModel* model = profile()->GetBookmarkModel(); | 30 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); |
30 default_parent_ = model->bookmark_bar_node(); | 31 default_parent_ = model->bookmark_bar_node(); |
31 default_name_ = "http://www.zim-bop-a-dee.com/"; | 32 default_name_ = "http://www.zim-bop-a-dee.com/"; |
32 default_title_ = ASCIIToUTF16("ooh title"); | 33 default_title_ = ASCIIToUTF16("ooh title"); |
33 const BookmarkNode* default_node = model->AddURL(default_parent_, 0, | 34 const BookmarkNode* default_node = model->AddURL(default_parent_, 0, |
34 default_title_, | 35 default_title_, |
35 GURL(default_name_)); | 36 GURL(default_name_)); |
36 controller_ = [[BookmarkEditorController alloc] | 37 controller_ = [[BookmarkEditorController alloc] |
37 initWithParentWindow:test_window() | 38 initWithParentWindow:test_window() |
38 profile:profile() | 39 profile:profile() |
39 parent:default_parent_ | 40 parent:default_parent_ |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 [controller_ setDisplayURL:@"x"]; | 83 [controller_ setDisplayURL:@"x"]; |
83 [controller_ ok:nil]; | 84 [controller_ ok:nil]; |
84 ASSERT_EQ(default_parent_->child_count(), 1); | 85 ASSERT_EQ(default_parent_->child_count(), 1); |
85 const BookmarkNode* child = default_parent_->GetChild(0); | 86 const BookmarkNode* child = default_parent_->GetChild(0); |
86 EXPECT_TRUE(child->url().is_valid()); | 87 EXPECT_TRUE(child->url().is_valid()); |
87 } | 88 } |
88 | 89 |
89 TEST_F(BookmarkEditorControllerTest, NodeDeleted) { | 90 TEST_F(BookmarkEditorControllerTest, NodeDeleted) { |
90 // Delete the bookmark being edited and verify the sheet cancels itself: | 91 // Delete the bookmark being edited and verify the sheet cancels itself: |
91 ASSERT_TRUE([test_window() attachedSheet]); | 92 ASSERT_TRUE([test_window() attachedSheet]); |
92 BookmarkModel* model = profile()->GetBookmarkModel(); | 93 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); |
93 model->Remove(default_parent_, 0); | 94 model->Remove(default_parent_, 0); |
94 ASSERT_FALSE([test_window() attachedSheet]); | 95 ASSERT_FALSE([test_window() attachedSheet]); |
95 } | 96 } |
96 | 97 |
97 TEST_F(BookmarkEditorControllerTest, EditAndConfirmOKButton) { | 98 TEST_F(BookmarkEditorControllerTest, EditAndConfirmOKButton) { |
98 // Confirm OK button enabled/disabled as appropriate: | 99 // Confirm OK button enabled/disabled as appropriate: |
99 // First test the URL. | 100 // First test the URL. |
100 EXPECT_TRUE([controller_ okButtonEnabled]); | 101 EXPECT_TRUE([controller_ okButtonEnabled]); |
101 [controller_ setDisplayURL:@""]; | 102 [controller_ setDisplayURL:@""]; |
102 EXPECT_FALSE([controller_ okButtonEnabled]); | 103 EXPECT_FALSE([controller_ okButtonEnabled]); |
(...skipping 30 matching lines...) Expand all Loading... |
133 } | 134 } |
134 | 135 |
135 class BookmarkEditorControllerNoNodeTest : public CocoaProfileTest { | 136 class BookmarkEditorControllerNoNodeTest : public CocoaProfileTest { |
136 public: | 137 public: |
137 BookmarkEditorController* controller_; | 138 BookmarkEditorController* controller_; |
138 | 139 |
139 virtual void SetUp() { | 140 virtual void SetUp() { |
140 CocoaProfileTest::SetUp(); | 141 CocoaProfileTest::SetUp(); |
141 ASSERT_TRUE(profile()); | 142 ASSERT_TRUE(profile()); |
142 | 143 |
143 BookmarkModel* model = profile()->GetBookmarkModel(); | 144 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); |
144 const BookmarkNode* parent = model->bookmark_bar_node(); | 145 const BookmarkNode* parent = model->bookmark_bar_node(); |
145 controller_ = [[BookmarkEditorController alloc] | 146 controller_ = [[BookmarkEditorController alloc] |
146 initWithParentWindow:test_window() | 147 initWithParentWindow:test_window() |
147 profile:profile() | 148 profile:profile() |
148 parent:parent | 149 parent:parent |
149 node:NULL | 150 node:NULL |
150 url:GURL() | 151 url:GURL() |
151 title:string16() | 152 title:string16() |
152 configuration:BookmarkEditor::NO_TREE]; | 153 configuration:BookmarkEditor::NO_TREE]; |
153 | 154 |
(...skipping 16 matching lines...) Expand all Loading... |
170 class BookmarkEditorControllerYesNodeTest : public CocoaProfileTest { | 171 class BookmarkEditorControllerYesNodeTest : public CocoaProfileTest { |
171 public: | 172 public: |
172 string16 default_title_; | 173 string16 default_title_; |
173 const char* url_name_; | 174 const char* url_name_; |
174 BookmarkEditorController* controller_; | 175 BookmarkEditorController* controller_; |
175 | 176 |
176 virtual void SetUp() { | 177 virtual void SetUp() { |
177 CocoaProfileTest::SetUp(); | 178 CocoaProfileTest::SetUp(); |
178 ASSERT_TRUE(profile()); | 179 ASSERT_TRUE(profile()); |
179 | 180 |
180 BookmarkModel* model = profile()->GetBookmarkModel(); | 181 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); |
181 const BookmarkNode* parent = model->bookmark_bar_node(); | 182 const BookmarkNode* parent = model->bookmark_bar_node(); |
182 default_title_ = ASCIIToUTF16("wooh title"); | 183 default_title_ = ASCIIToUTF16("wooh title"); |
183 url_name_ = "http://www.zoom-baby-doo-da.com/"; | 184 url_name_ = "http://www.zoom-baby-doo-da.com/"; |
184 const BookmarkNode* node = model->AddURL(parent, 0, default_title_, | 185 const BookmarkNode* node = model->AddURL(parent, 0, default_title_, |
185 GURL(url_name_)); | 186 GURL(url_name_)); |
186 controller_ = [[BookmarkEditorController alloc] | 187 controller_ = [[BookmarkEditorController alloc] |
187 initWithParentWindow:test_window() | 188 initWithParentWindow:test_window() |
188 profile:profile() | 189 profile:profile() |
189 parent:parent | 190 parent:parent |
190 node:node | 191 node:node |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 // Set up a small bookmark hierarchy, which will look as follows: | 227 // Set up a small bookmark hierarchy, which will look as follows: |
227 // a b c d | 228 // a b c d |
228 // a-0 b-0 c-0 | 229 // a-0 b-0 c-0 |
229 // a-1 bb-0 c-1 | 230 // a-1 bb-0 c-1 |
230 // a-2 bb-1 c-2 | 231 // a-2 bb-1 c-2 |
231 // bb-2 | 232 // bb-2 |
232 // bb-3 | 233 // bb-3 |
233 // bb-4 | 234 // bb-4 |
234 // b-1 | 235 // b-1 |
235 // b-2 | 236 // b-2 |
236 BookmarkModel& model(*(profile()->GetBookmarkModel())); | 237 BookmarkModel& model(*(BookmarkModelFactory::GetForProfile(profile()))); |
237 const BookmarkNode* root = model.bookmark_bar_node(); | 238 const BookmarkNode* root = model.bookmark_bar_node(); |
238 folder_a_ = model.AddFolder(root, 0, ASCIIToUTF16("a")); | 239 folder_a_ = model.AddFolder(root, 0, ASCIIToUTF16("a")); |
239 model.AddURL(folder_a_, 0, ASCIIToUTF16("a-0"), GURL("http://a-0.com")); | 240 model.AddURL(folder_a_, 0, ASCIIToUTF16("a-0"), GURL("http://a-0.com")); |
240 model.AddURL(folder_a_, 1, ASCIIToUTF16("a-1"), GURL("http://a-1.com")); | 241 model.AddURL(folder_a_, 1, ASCIIToUTF16("a-1"), GURL("http://a-1.com")); |
241 model.AddURL(folder_a_, 2, ASCIIToUTF16("a-2"), GURL("http://a-2.com")); | 242 model.AddURL(folder_a_, 2, ASCIIToUTF16("a-2"), GURL("http://a-2.com")); |
242 | 243 |
243 folder_b_ = model.AddFolder(root, 1, ASCIIToUTF16("b")); | 244 folder_b_ = model.AddFolder(root, 1, ASCIIToUTF16("b")); |
244 model.AddURL(folder_b_, 0, ASCIIToUTF16("b-0"), GURL("http://b-0.com")); | 245 model.AddURL(folder_b_, 0, ASCIIToUTF16("b-0"), GURL("http://b-0.com")); |
245 folder_bb_ = model.AddFolder(folder_b_, 1, ASCIIToUTF16("bb")); | 246 folder_bb_ = model.AddFolder(folder_b_, 1, ASCIIToUTF16("bb")); |
246 model.AddURL(folder_bb_, 0, ASCIIToUTF16("bb-0"), GURL("http://bb-0.com")); | 247 model.AddURL(folder_bb_, 0, ASCIIToUTF16("bb-0"), GURL("http://bb-0.com")); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 CocoaProfileTest::TearDown(); | 293 CocoaProfileTest::TearDown(); |
293 } | 294 } |
294 | 295 |
295 // After changing a node, pointers to the node may be invalid. This | 296 // After changing a node, pointers to the node may be invalid. This |
296 // is because the node itself may not be updated; it may removed and | 297 // is because the node itself may not be updated; it may removed and |
297 // a new one is added in that location. (Implementation detail of | 298 // a new one is added in that location. (Implementation detail of |
298 // BookmarkEditorController). This method updates the class's | 299 // BookmarkEditorController). This method updates the class's |
299 // bookmark_bb_3_ so that it points to the new node for testing. | 300 // bookmark_bb_3_ so that it points to the new node for testing. |
300 void UpdateBB3() { | 301 void UpdateBB3() { |
301 std::vector<const BookmarkNode*> nodes; | 302 std::vector<const BookmarkNode*> nodes; |
302 BookmarkModel* model = profile()->GetBookmarkModel(); | 303 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); |
303 model->GetNodesByURL(bb3_url_1_, &nodes); | 304 model->GetNodesByURL(bb3_url_1_, &nodes); |
304 if (nodes.empty()) | 305 if (nodes.empty()) |
305 model->GetNodesByURL(bb3_url_2_, &nodes); | 306 model->GetNodesByURL(bb3_url_2_, &nodes); |
306 DCHECK(nodes.size()); | 307 DCHECK(nodes.size()); |
307 bookmark_bb_3_ = nodes[0]; | 308 bookmark_bb_3_ = nodes[0]; |
308 } | 309 } |
309 | 310 |
310 }; | 311 }; |
311 | 312 |
312 TEST_F(BookmarkEditorControllerTreeTest, VerifyBookmarkTestModel) { | 313 TEST_F(BookmarkEditorControllerTreeTest, VerifyBookmarkTestModel) { |
313 BookmarkModel& model(*(profile()->GetBookmarkModel())); | 314 BookmarkModel& model(*(BookmarkModelFactory::GetForProfile(profile()))); |
314 model.root_node(); | 315 model.root_node(); |
315 const BookmarkNode& root(*model.bookmark_bar_node()); | 316 const BookmarkNode& root(*model.bookmark_bar_node()); |
316 EXPECT_EQ(4, root.child_count()); | 317 EXPECT_EQ(4, root.child_count()); |
317 const BookmarkNode* child = root.GetChild(0); | 318 const BookmarkNode* child = root.GetChild(0); |
318 EXPECT_EQ(3, child->child_count()); | 319 EXPECT_EQ(3, child->child_count()); |
319 const BookmarkNode* subchild = child->GetChild(0); | 320 const BookmarkNode* subchild = child->GetChild(0); |
320 EXPECT_EQ(0, subchild->child_count()); | 321 EXPECT_EQ(0, subchild->child_count()); |
321 subchild = child->GetChild(1); | 322 subchild = child->GetChild(1); |
322 EXPECT_EQ(0, subchild->child_count()); | 323 EXPECT_EQ(0, subchild->child_count()); |
323 subchild = child->GetChild(2); | 324 subchild = child->GetChild(2); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 | 430 |
430 TEST_F(BookmarkEditorControllerTreeNoNodeTest, NewBookmarkNoNode) { | 431 TEST_F(BookmarkEditorControllerTreeNoNodeTest, NewBookmarkNoNode) { |
431 [controller_ setDisplayName:@"NEW BOOKMARK"]; | 432 [controller_ setDisplayName:@"NEW BOOKMARK"]; |
432 [controller_ setDisplayURL:@"http://NEWURL.com"]; | 433 [controller_ setDisplayURL:@"http://NEWURL.com"]; |
433 [controller_ ok:nil]; | 434 [controller_ ok:nil]; |
434 const BookmarkNode* new_node = folder_bb_->GetChild(5); | 435 const BookmarkNode* new_node = folder_bb_->GetChild(5); |
435 ASSERT_EQ(0, new_node->child_count()); | 436 ASSERT_EQ(0, new_node->child_count()); |
436 EXPECT_EQ(new_node->GetTitle(), ASCIIToUTF16("NEW BOOKMARK")); | 437 EXPECT_EQ(new_node->GetTitle(), ASCIIToUTF16("NEW BOOKMARK")); |
437 EXPECT_EQ(new_node->url(), GURL("http://NEWURL.com")); | 438 EXPECT_EQ(new_node->url(), GURL("http://NEWURL.com")); |
438 } | 439 } |
OLD | NEW |