| 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/memory/scoped_nsobject.h" | 7 #include "base/mac/scoped_nsobject.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 9 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 10 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_name_folder_controller.h" | 10 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_name_folder_controller.h" |
| 11 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" | 11 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #import "testing/gtest_mac.h" | 13 #import "testing/gtest_mac.h" |
| 14 #include "testing/platform_test.h" | 14 #include "testing/platform_test.h" |
| 15 | 15 |
| 16 class BookmarkNameFolderControllerTest : public CocoaProfileTest { | 16 class BookmarkNameFolderControllerTest : public CocoaProfileTest { |
| 17 }; | 17 }; |
| 18 | 18 |
| 19 | 19 |
| 20 // Simple add of a node (at the end). | 20 // Simple add of a node (at the end). |
| 21 TEST_F(BookmarkNameFolderControllerTest, AddNew) { | 21 TEST_F(BookmarkNameFolderControllerTest, AddNew) { |
| 22 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 22 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); |
| 23 const BookmarkNode* parent = model->bookmark_bar_node(); | 23 const BookmarkNode* parent = model->bookmark_bar_node(); |
| 24 EXPECT_EQ(0, parent->child_count()); | 24 EXPECT_EQ(0, parent->child_count()); |
| 25 | 25 |
| 26 scoped_nsobject<BookmarkNameFolderController> | 26 base::scoped_nsobject<BookmarkNameFolderController> controller( |
| 27 controller([[BookmarkNameFolderController alloc] | 27 [[BookmarkNameFolderController alloc] initWithParentWindow:test_window() |
| 28 initWithParentWindow:test_window() | 28 profile:profile() |
| 29 profile:profile() | 29 parent:parent |
| 30 parent:parent | 30 newIndex:0]); |
| 31 newIndex:0]); | |
| 32 [controller window]; // force nib load | 31 [controller window]; // force nib load |
| 33 | 32 |
| 34 // Do nothing. | 33 // Do nothing. |
| 35 [controller cancel:nil]; | 34 [controller cancel:nil]; |
| 36 EXPECT_EQ(0, parent->child_count()); | 35 EXPECT_EQ(0, parent->child_count()); |
| 37 | 36 |
| 38 // Change name then cancel. | 37 // Change name then cancel. |
| 39 [controller setFolderName:@"Bozo"]; | 38 [controller setFolderName:@"Bozo"]; |
| 40 [controller cancel:nil]; | 39 [controller cancel:nil]; |
| 41 EXPECT_EQ(0, parent->child_count()); | 40 EXPECT_EQ(0, parent->child_count()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 52 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 51 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); |
| 53 const BookmarkNode* parent = model->bookmark_bar_node(); | 52 const BookmarkNode* parent = model->bookmark_bar_node(); |
| 54 | 53 |
| 55 // Add 2 nodes. We will place the new folder in the middle of these. | 54 // Add 2 nodes. We will place the new folder in the middle of these. |
| 56 model->AddURL(parent, 0, ASCIIToUTF16("title 1"), | 55 model->AddURL(parent, 0, ASCIIToUTF16("title 1"), |
| 57 GURL("http://www.google.com")); | 56 GURL("http://www.google.com")); |
| 58 model->AddURL(parent, 1, ASCIIToUTF16("title 3"), | 57 model->AddURL(parent, 1, ASCIIToUTF16("title 3"), |
| 59 GURL("http://www.google.com")); | 58 GURL("http://www.google.com")); |
| 60 EXPECT_EQ(2, parent->child_count()); | 59 EXPECT_EQ(2, parent->child_count()); |
| 61 | 60 |
| 62 scoped_nsobject<BookmarkNameFolderController> | 61 base::scoped_nsobject<BookmarkNameFolderController> controller( |
| 63 controller([[BookmarkNameFolderController alloc] | 62 [[BookmarkNameFolderController alloc] initWithParentWindow:test_window() |
| 64 initWithParentWindow:test_window() | 63 profile:profile() |
| 65 profile:profile() | 64 parent:parent |
| 66 parent:parent | 65 newIndex:1]); |
| 67 newIndex:1]); | |
| 68 [controller window]; // force nib load | 66 [controller window]; // force nib load |
| 69 | 67 |
| 70 // Add a new folder. | 68 // Add a new folder. |
| 71 [controller setFolderName:@"middle"]; | 69 [controller setFolderName:@"middle"]; |
| 72 [controller ok:nil]; | 70 [controller ok:nil]; |
| 73 | 71 |
| 74 // Confirm we now have 3, and that the new one is in the middle. | 72 // Confirm we now have 3, and that the new one is in the middle. |
| 75 EXPECT_EQ(3, parent->child_count()); | 73 EXPECT_EQ(3, parent->child_count()); |
| 76 EXPECT_TRUE(parent->GetChild(1)->is_folder()); | 74 EXPECT_TRUE(parent->GetChild(1)->is_folder()); |
| 77 EXPECT_EQ(ASCIIToUTF16("middle"), parent->GetChild(1)->GetTitle()); | 75 EXPECT_EQ(ASCIIToUTF16("middle"), parent->GetChild(1)->GetTitle()); |
| 78 } | 76 } |
| 79 | 77 |
| 80 // Make sure we are allowed to create a folder named "New Folder". | 78 // Make sure we are allowed to create a folder named "New Folder". |
| 81 TEST_F(BookmarkNameFolderControllerTest, AddNewDefaultName) { | 79 TEST_F(BookmarkNameFolderControllerTest, AddNewDefaultName) { |
| 82 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 80 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); |
| 83 const BookmarkNode* parent = model->bookmark_bar_node(); | 81 const BookmarkNode* parent = model->bookmark_bar_node(); |
| 84 EXPECT_EQ(0, parent->child_count()); | 82 EXPECT_EQ(0, parent->child_count()); |
| 85 | 83 |
| 86 scoped_nsobject<BookmarkNameFolderController> | 84 base::scoped_nsobject<BookmarkNameFolderController> controller( |
| 87 controller([[BookmarkNameFolderController alloc] | 85 [[BookmarkNameFolderController alloc] initWithParentWindow:test_window() |
| 88 initWithParentWindow:test_window() | 86 profile:profile() |
| 89 profile:profile() | 87 parent:parent |
| 90 parent:parent | 88 newIndex:0]); |
| 91 newIndex:0]); | |
| 92 | 89 |
| 93 [controller window]; // force nib load | 90 [controller window]; // force nib load |
| 94 | 91 |
| 95 // Click OK without changing the name | 92 // Click OK without changing the name |
| 96 [controller ok:nil]; | 93 [controller ok:nil]; |
| 97 EXPECT_EQ(1, parent->child_count()); | 94 EXPECT_EQ(1, parent->child_count()); |
| 98 EXPECT_TRUE(parent->GetChild(0)->is_folder()); | 95 EXPECT_TRUE(parent->GetChild(0)->is_folder()); |
| 99 } | 96 } |
| 100 | 97 |
| 101 // Make sure we are allowed to create a folder with an empty name. | 98 // Make sure we are allowed to create a folder with an empty name. |
| 102 TEST_F(BookmarkNameFolderControllerTest, AddNewBlankName) { | 99 TEST_F(BookmarkNameFolderControllerTest, AddNewBlankName) { |
| 103 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 100 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); |
| 104 const BookmarkNode* parent = model->bookmark_bar_node(); | 101 const BookmarkNode* parent = model->bookmark_bar_node(); |
| 105 EXPECT_EQ(0, parent->child_count()); | 102 EXPECT_EQ(0, parent->child_count()); |
| 106 | 103 |
| 107 scoped_nsobject<BookmarkNameFolderController> | 104 base::scoped_nsobject<BookmarkNameFolderController> controller( |
| 108 controller([[BookmarkNameFolderController alloc] | 105 [[BookmarkNameFolderController alloc] initWithParentWindow:test_window() |
| 109 initWithParentWindow:test_window() | 106 profile:profile() |
| 110 profile:profile() | 107 parent:parent |
| 111 parent:parent | 108 newIndex:0]); |
| 112 newIndex:0]); | |
| 113 [controller window]; // force nib load | 109 [controller window]; // force nib load |
| 114 | 110 |
| 115 // Change the name to blank, click OK. | 111 // Change the name to blank, click OK. |
| 116 [controller setFolderName:@""]; | 112 [controller setFolderName:@""]; |
| 117 [controller ok:nil]; | 113 [controller ok:nil]; |
| 118 EXPECT_EQ(1, parent->child_count()); | 114 EXPECT_EQ(1, parent->child_count()); |
| 119 EXPECT_TRUE(parent->GetChild(0)->is_folder()); | 115 EXPECT_TRUE(parent->GetChild(0)->is_folder()); |
| 120 } | 116 } |
| 121 | 117 |
| 122 TEST_F(BookmarkNameFolderControllerTest, Rename) { | 118 TEST_F(BookmarkNameFolderControllerTest, Rename) { |
| 123 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 119 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); |
| 124 const BookmarkNode* parent = model->bookmark_bar_node(); | 120 const BookmarkNode* parent = model->bookmark_bar_node(); |
| 125 const BookmarkNode* folder = model->AddFolder(parent, | 121 const BookmarkNode* folder = model->AddFolder(parent, |
| 126 parent->child_count(), | 122 parent->child_count(), |
| 127 ASCIIToUTF16("folder")); | 123 ASCIIToUTF16("folder")); |
| 128 | 124 |
| 129 // Rename the folder by creating a controller that originates from | 125 // Rename the folder by creating a controller that originates from |
| 130 // the node. | 126 // the node. |
| 131 scoped_nsobject<BookmarkNameFolderController> | 127 base::scoped_nsobject<BookmarkNameFolderController> controller( |
| 132 controller([[BookmarkNameFolderController alloc] | 128 [[BookmarkNameFolderController alloc] initWithParentWindow:test_window() |
| 133 initWithParentWindow:test_window() | 129 profile:profile() |
| 134 profile:profile() | 130 node:folder]); |
| 135 node:folder]); | |
| 136 [controller window]; // force nib load | 131 [controller window]; // force nib load |
| 137 | 132 |
| 138 EXPECT_NSEQ(@"folder", [controller folderName]); | 133 EXPECT_NSEQ(@"folder", [controller folderName]); |
| 139 [controller setFolderName:@"Zobo"]; | 134 [controller setFolderName:@"Zobo"]; |
| 140 [controller ok:nil]; | 135 [controller ok:nil]; |
| 141 EXPECT_EQ(1, parent->child_count()); | 136 EXPECT_EQ(1, parent->child_count()); |
| 142 EXPECT_TRUE(parent->GetChild(0)->is_folder()); | 137 EXPECT_TRUE(parent->GetChild(0)->is_folder()); |
| 143 EXPECT_EQ(ASCIIToUTF16("Zobo"), parent->GetChild(0)->GetTitle()); | 138 EXPECT_EQ(ASCIIToUTF16("Zobo"), parent->GetChild(0)->GetTitle()); |
| 144 } | 139 } |
| 145 | 140 |
| 146 TEST_F(BookmarkNameFolderControllerTest, EditAndConfirmOKButton) { | 141 TEST_F(BookmarkNameFolderControllerTest, EditAndConfirmOKButton) { |
| 147 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 142 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); |
| 148 const BookmarkNode* parent = model->bookmark_bar_node(); | 143 const BookmarkNode* parent = model->bookmark_bar_node(); |
| 149 EXPECT_EQ(0, parent->child_count()); | 144 EXPECT_EQ(0, parent->child_count()); |
| 150 | 145 |
| 151 scoped_nsobject<BookmarkNameFolderController> | 146 base::scoped_nsobject<BookmarkNameFolderController> controller( |
| 152 controller([[BookmarkNameFolderController alloc] | 147 [[BookmarkNameFolderController alloc] initWithParentWindow:test_window() |
| 153 initWithParentWindow:test_window() | 148 profile:profile() |
| 154 profile:profile() | 149 parent:parent |
| 155 parent:parent | 150 newIndex:0]); |
| 156 newIndex:0]); | |
| 157 [controller window]; // force nib load | 151 [controller window]; // force nib load |
| 158 | 152 |
| 159 // We start enabled since the default "New Folder" is added for us. | 153 // We start enabled since the default "New Folder" is added for us. |
| 160 EXPECT_TRUE([[controller okButton] isEnabled]); | 154 EXPECT_TRUE([[controller okButton] isEnabled]); |
| 161 | 155 |
| 162 [controller setFolderName:@"Bozo"]; | 156 [controller setFolderName:@"Bozo"]; |
| 163 EXPECT_TRUE([[controller okButton] isEnabled]); | 157 EXPECT_TRUE([[controller okButton] isEnabled]); |
| 164 [controller setFolderName:@" "]; | 158 [controller setFolderName:@" "]; |
| 165 EXPECT_TRUE([[controller okButton] isEnabled]); | 159 EXPECT_TRUE([[controller okButton] isEnabled]); |
| 166 | 160 |
| 167 [controller setFolderName:@""]; | 161 [controller setFolderName:@""]; |
| 168 EXPECT_TRUE([[controller okButton] isEnabled]); | 162 EXPECT_TRUE([[controller okButton] isEnabled]); |
| 169 } | 163 } |
| 170 | 164 |
| OLD | NEW |