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/strings/string16.h" | 7 #include "base/strings/string16.h" |
8 #include "base/strings/sys_string_conversions.h" | 8 #include "base/strings/sys_string_conversions.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 10 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 const BookmarkNode* default_node_; | 25 const BookmarkNode* default_node_; |
26 const BookmarkNode* default_parent_; | 26 const BookmarkNode* default_parent_; |
27 const char* default_name_; | 27 const char* default_name_; |
28 base::string16 default_title_; | 28 base::string16 default_title_; |
29 BookmarkEditorController* controller_; | 29 BookmarkEditorController* controller_; |
30 | 30 |
31 void SetUp() override { | 31 void SetUp() override { |
32 CocoaProfileTest::SetUp(); | 32 CocoaProfileTest::SetUp(); |
33 ASSERT_TRUE(profile()); | 33 ASSERT_TRUE(profile()); |
34 | 34 |
35 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 35 BookmarkModel* model = |
| 36 BookmarkModelFactory::GetForBrowserContext(profile()); |
36 default_parent_ = model->bookmark_bar_node(); | 37 default_parent_ = model->bookmark_bar_node(); |
37 default_name_ = "http://www.zim-bop-a-dee.com/"; | 38 default_name_ = "http://www.zim-bop-a-dee.com/"; |
38 default_title_ = ASCIIToUTF16("ooh title"); | 39 default_title_ = ASCIIToUTF16("ooh title"); |
39 const BookmarkNode* default_node = model->AddURL(default_parent_, 0, | 40 const BookmarkNode* default_node = model->AddURL(default_parent_, 0, |
40 default_title_, | 41 default_title_, |
41 GURL(default_name_)); | 42 GURL(default_name_)); |
42 controller_ = [[BookmarkEditorController alloc] | 43 controller_ = [[BookmarkEditorController alloc] |
43 initWithParentWindow:test_window() | 44 initWithParentWindow:test_window() |
44 profile:profile() | 45 profile:profile() |
45 parent:default_parent_ | 46 parent:default_parent_ |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 [controller_ setDisplayURL:@"x"]; | 89 [controller_ setDisplayURL:@"x"]; |
89 [controller_ ok:nil]; | 90 [controller_ ok:nil]; |
90 ASSERT_EQ(default_parent_->child_count(), 1); | 91 ASSERT_EQ(default_parent_->child_count(), 1); |
91 const BookmarkNode* child = default_parent_->GetChild(0); | 92 const BookmarkNode* child = default_parent_->GetChild(0); |
92 EXPECT_TRUE(child->url().is_valid()); | 93 EXPECT_TRUE(child->url().is_valid()); |
93 } | 94 } |
94 | 95 |
95 TEST_F(BookmarkEditorControllerTest, NodeDeleted) { | 96 TEST_F(BookmarkEditorControllerTest, NodeDeleted) { |
96 // Delete the bookmark being edited and verify the sheet cancels itself: | 97 // Delete the bookmark being edited and verify the sheet cancels itself: |
97 ASSERT_TRUE([test_window() attachedSheet]); | 98 ASSERT_TRUE([test_window() attachedSheet]); |
98 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 99 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
99 model->Remove(default_parent_->GetChild(0)); | 100 model->Remove(default_parent_->GetChild(0)); |
100 ASSERT_FALSE([test_window() attachedSheet]); | 101 ASSERT_FALSE([test_window() attachedSheet]); |
101 } | 102 } |
102 | 103 |
103 TEST_F(BookmarkEditorControllerTest, EditAndConfirmOKButton) { | 104 TEST_F(BookmarkEditorControllerTest, EditAndConfirmOKButton) { |
104 // Confirm OK button enabled/disabled as appropriate: | 105 // Confirm OK button enabled/disabled as appropriate: |
105 // First test the URL. | 106 // First test the URL. |
106 EXPECT_TRUE([controller_ okButtonEnabled]); | 107 EXPECT_TRUE([controller_ okButtonEnabled]); |
107 [controller_ setDisplayURL:@""]; | 108 [controller_ setDisplayURL:@""]; |
108 EXPECT_FALSE([controller_ okButtonEnabled]); | 109 EXPECT_FALSE([controller_ okButtonEnabled]); |
(...skipping 30 matching lines...) Expand all Loading... |
139 } | 140 } |
140 | 141 |
141 class BookmarkEditorControllerNoNodeTest : public CocoaProfileTest { | 142 class BookmarkEditorControllerNoNodeTest : public CocoaProfileTest { |
142 public: | 143 public: |
143 BookmarkEditorController* controller_; | 144 BookmarkEditorController* controller_; |
144 | 145 |
145 void SetUp() override { | 146 void SetUp() override { |
146 CocoaProfileTest::SetUp(); | 147 CocoaProfileTest::SetUp(); |
147 ASSERT_TRUE(profile()); | 148 ASSERT_TRUE(profile()); |
148 | 149 |
149 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 150 BookmarkModel* model = |
| 151 BookmarkModelFactory::GetForBrowserContext(profile()); |
150 const BookmarkNode* parent = model->bookmark_bar_node(); | 152 const BookmarkNode* parent = model->bookmark_bar_node(); |
151 controller_ = [[BookmarkEditorController alloc] | 153 controller_ = [[BookmarkEditorController alloc] |
152 initWithParentWindow:test_window() | 154 initWithParentWindow:test_window() |
153 profile:profile() | 155 profile:profile() |
154 parent:parent | 156 parent:parent |
155 node:NULL | 157 node:NULL |
156 url:GURL() | 158 url:GURL() |
157 title:base::string16() | 159 title:base::string16() |
158 configuration:BookmarkEditor::NO_TREE]; | 160 configuration:BookmarkEditor::NO_TREE]; |
159 | 161 |
(...skipping 15 matching lines...) Expand all Loading... |
175 | 177 |
176 class BookmarkEditorControllerYesNodeTest : public CocoaProfileTest { | 178 class BookmarkEditorControllerYesNodeTest : public CocoaProfileTest { |
177 public: | 179 public: |
178 base::string16 default_title_; | 180 base::string16 default_title_; |
179 BookmarkEditorController* controller_; | 181 BookmarkEditorController* controller_; |
180 | 182 |
181 void SetUp() override { | 183 void SetUp() override { |
182 CocoaProfileTest::SetUp(); | 184 CocoaProfileTest::SetUp(); |
183 ASSERT_TRUE(profile()); | 185 ASSERT_TRUE(profile()); |
184 | 186 |
185 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 187 BookmarkModel* model = |
| 188 BookmarkModelFactory::GetForBrowserContext(profile()); |
186 const BookmarkNode* parent = model->bookmark_bar_node(); | 189 const BookmarkNode* parent = model->bookmark_bar_node(); |
187 default_title_ = ASCIIToUTF16("wooh title"); | 190 default_title_ = ASCIIToUTF16("wooh title"); |
188 const BookmarkNode* node = | 191 const BookmarkNode* node = |
189 model->AddURL(parent, 0, default_title_, | 192 model->AddURL(parent, 0, default_title_, |
190 GURL("http://www.zoom-baby-doo-da.com/")); | 193 GURL("http://www.zoom-baby-doo-da.com/")); |
191 controller_ = [[BookmarkEditorController alloc] | 194 controller_ = [[BookmarkEditorController alloc] |
192 initWithParentWindow:test_window() | 195 initWithParentWindow:test_window() |
193 profile:profile() | 196 profile:profile() |
194 parent:parent | 197 parent:parent |
195 node:node | 198 node:node |
(...skipping 21 matching lines...) Expand all Loading... |
217 | 220 |
218 | 221 |
219 class BookmarkEditorControllerUtf8NodeTest : public CocoaProfileTest { | 222 class BookmarkEditorControllerUtf8NodeTest : public CocoaProfileTest { |
220 public: | 223 public: |
221 BookmarkEditorController* controller_; | 224 BookmarkEditorController* controller_; |
222 | 225 |
223 void SetUp() override { | 226 void SetUp() override { |
224 CocoaProfileTest::SetUp(); | 227 CocoaProfileTest::SetUp(); |
225 ASSERT_TRUE(profile()); | 228 ASSERT_TRUE(profile()); |
226 | 229 |
227 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 230 BookmarkModel* model = |
| 231 BookmarkModelFactory::GetForBrowserContext(profile()); |
228 const BookmarkNode* parent = model->bookmark_bar_node(); | 232 const BookmarkNode* parent = model->bookmark_bar_node(); |
229 base::string16 title = ASCIIToUTF16("wooh title"); | 233 base::string16 title = ASCIIToUTF16("wooh title"); |
230 const char* url_name = "http://www.foobar.com/心得寫作"; | 234 const char* url_name = "http://www.foobar.com/心得寫作"; |
231 const BookmarkNode* node = model->AddURL(parent, 0, title, GURL(url_name)); | 235 const BookmarkNode* node = model->AddURL(parent, 0, title, GURL(url_name)); |
232 controller_ = [[BookmarkEditorController alloc] | 236 controller_ = [[BookmarkEditorController alloc] |
233 initWithParentWindow:test_window() | 237 initWithParentWindow:test_window() |
234 profile:profile() | 238 profile:profile() |
235 parent:parent | 239 parent:parent |
236 node:node | 240 node:node |
237 url:GURL() | 241 url:GURL() |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 // Set up a small bookmark hierarchy, which will look as follows: | 275 // Set up a small bookmark hierarchy, which will look as follows: |
272 // a b c d | 276 // a b c d |
273 // a-0 b-0 c-0 | 277 // a-0 b-0 c-0 |
274 // a-1 bb-0 c-1 | 278 // a-1 bb-0 c-1 |
275 // a-2 bb-1 c-2 | 279 // a-2 bb-1 c-2 |
276 // bb-2 | 280 // bb-2 |
277 // bb-3 | 281 // bb-3 |
278 // bb-4 | 282 // bb-4 |
279 // b-1 | 283 // b-1 |
280 // b-2 | 284 // b-2 |
281 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 285 BookmarkModel* model = |
| 286 BookmarkModelFactory::GetForBrowserContext(profile()); |
282 const BookmarkNode* root = model->bookmark_bar_node(); | 287 const BookmarkNode* root = model->bookmark_bar_node(); |
283 folder_a_ = model->AddFolder(root, 0, ASCIIToUTF16("a")); | 288 folder_a_ = model->AddFolder(root, 0, ASCIIToUTF16("a")); |
284 model->AddURL(folder_a_, 0, ASCIIToUTF16("a-0"), GURL("http://a-0.com")); | 289 model->AddURL(folder_a_, 0, ASCIIToUTF16("a-0"), GURL("http://a-0.com")); |
285 model->AddURL(folder_a_, 1, ASCIIToUTF16("a-1"), GURL("http://a-1.com")); | 290 model->AddURL(folder_a_, 1, ASCIIToUTF16("a-1"), GURL("http://a-1.com")); |
286 model->AddURL(folder_a_, 2, ASCIIToUTF16("a-2"), GURL("http://a-2.com")); | 291 model->AddURL(folder_a_, 2, ASCIIToUTF16("a-2"), GURL("http://a-2.com")); |
287 | 292 |
288 folder_b_ = model->AddFolder(root, 1, ASCIIToUTF16("b")); | 293 folder_b_ = model->AddFolder(root, 1, ASCIIToUTF16("b")); |
289 model->AddURL(folder_b_, 0, ASCIIToUTF16("b-0"), GURL("http://b-0.com")); | 294 model->AddURL(folder_b_, 0, ASCIIToUTF16("b-0"), GURL("http://b-0.com")); |
290 folder_bb_ = model->AddFolder(folder_b_, 1, ASCIIToUTF16("bb")); | 295 folder_bb_ = model->AddFolder(folder_b_, 1, ASCIIToUTF16("bb")); |
291 model->AddURL(folder_bb_, 0, ASCIIToUTF16("bb-0"), GURL("http://bb-0.com")); | 296 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... |
337 CocoaProfileTest::TearDown(); | 342 CocoaProfileTest::TearDown(); |
338 } | 343 } |
339 | 344 |
340 // After changing a node, pointers to the node may be invalid. This | 345 // After changing a node, pointers to the node may be invalid. This |
341 // is because the node itself may not be updated; it may removed and | 346 // is because the node itself may not be updated; it may removed and |
342 // a new one is added in that location. (Implementation detail of | 347 // a new one is added in that location. (Implementation detail of |
343 // BookmarkEditorController). This method updates the class's | 348 // BookmarkEditorController). This method updates the class's |
344 // bookmark_bb_3_ so that it points to the new node for testing. | 349 // bookmark_bb_3_ so that it points to the new node for testing. |
345 void UpdateBB3() { | 350 void UpdateBB3() { |
346 std::vector<const BookmarkNode*> nodes; | 351 std::vector<const BookmarkNode*> nodes; |
347 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 352 BookmarkModel* model = |
| 353 BookmarkModelFactory::GetForBrowserContext(profile()); |
348 model->GetNodesByURL(bb3_url_1_, &nodes); | 354 model->GetNodesByURL(bb3_url_1_, &nodes); |
349 if (nodes.empty()) | 355 if (nodes.empty()) |
350 model->GetNodesByURL(bb3_url_2_, &nodes); | 356 model->GetNodesByURL(bb3_url_2_, &nodes); |
351 DCHECK(nodes.size()); | 357 DCHECK(nodes.size()); |
352 bookmark_bb_3_ = nodes[0]; | 358 bookmark_bb_3_ = nodes[0]; |
353 } | 359 } |
354 | 360 |
355 }; | 361 }; |
356 | 362 |
357 TEST_F(BookmarkEditorControllerTreeTest, VerifyBookmarkTestModel) { | 363 TEST_F(BookmarkEditorControllerTreeTest, VerifyBookmarkTestModel) { |
358 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 364 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
359 model->root_node(); | 365 model->root_node(); |
360 const BookmarkNode* root = model->bookmark_bar_node(); | 366 const BookmarkNode* root = model->bookmark_bar_node(); |
361 EXPECT_EQ(4, root->child_count()); | 367 EXPECT_EQ(4, root->child_count()); |
362 const BookmarkNode* child = root->GetChild(0); | 368 const BookmarkNode* child = root->GetChild(0); |
363 EXPECT_EQ(3, child->child_count()); | 369 EXPECT_EQ(3, child->child_count()); |
364 const BookmarkNode* subchild = child->GetChild(0); | 370 const BookmarkNode* subchild = child->GetChild(0); |
365 EXPECT_EQ(0, subchild->child_count()); | 371 EXPECT_EQ(0, subchild->child_count()); |
366 subchild = child->GetChild(1); | 372 subchild = child->GetChild(1); |
367 EXPECT_EQ(0, subchild->child_count()); | 373 EXPECT_EQ(0, subchild->child_count()); |
368 subchild = child->GetChild(2); | 374 subchild = child->GetChild(2); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 | 480 |
475 TEST_F(BookmarkEditorControllerTreeNoNodeTest, NewBookmarkNoNode) { | 481 TEST_F(BookmarkEditorControllerTreeNoNodeTest, NewBookmarkNoNode) { |
476 [controller_ setDisplayName:@"NEW BOOKMARK"]; | 482 [controller_ setDisplayName:@"NEW BOOKMARK"]; |
477 [controller_ setDisplayURL:@"http://NEWURL.com"]; | 483 [controller_ setDisplayURL:@"http://NEWURL.com"]; |
478 [controller_ ok:nil]; | 484 [controller_ ok:nil]; |
479 const BookmarkNode* new_node = folder_bb_->GetChild(5); | 485 const BookmarkNode* new_node = folder_bb_->GetChild(5); |
480 ASSERT_EQ(0, new_node->child_count()); | 486 ASSERT_EQ(0, new_node->child_count()); |
481 EXPECT_EQ(new_node->GetTitle(), ASCIIToUTF16("NEW BOOKMARK")); | 487 EXPECT_EQ(new_node->GetTitle(), ASCIIToUTF16("NEW BOOKMARK")); |
482 EXPECT_EQ(new_node->url(), GURL("http://NEWURL.com")); | 488 EXPECT_EQ(new_node->url(), GURL("http://NEWURL.com")); |
483 } | 489 } |
OLD | NEW |