| 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" |
| 11 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_editor_controller.h" | 11 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_editor_controller.h" |
| 12 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" | 12 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" |
| 13 #include "chrome/test/base/testing_profile.h" | 13 #include "chrome/test/base/testing_profile.h" |
| 14 #include "components/bookmarks/browser/bookmark_model.h" | 14 #include "components/bookmarks/browser/bookmark_model.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #import "testing/gtest_mac.h" | 16 #import "testing/gtest_mac.h" |
| 17 #include "testing/platform_test.h" | 17 #include "testing/platform_test.h" |
| 18 | 18 |
| 19 using base::ASCIIToUTF16; | 19 using base::ASCIIToUTF16; |
| 20 | 20 |
| 21 class BookmarkEditorControllerTest : public CocoaProfileTest { | 21 class BookmarkEditorControllerTest : public CocoaProfileTest { |
| 22 public: | 22 public: |
| 23 const BookmarkNode* default_node_; | 23 const BookmarkNode* default_node_; |
| 24 const BookmarkNode* default_parent_; | 24 const BookmarkNode* default_parent_; |
| 25 const char* default_name_; | 25 const char* default_name_; |
| 26 base::string16 default_title_; | 26 base::string16 default_title_; |
| 27 BookmarkEditorController* controller_; | 27 BookmarkEditorController* controller_; |
| 28 | 28 |
| 29 virtual void SetUp() OVERRIDE { | 29 virtual void SetUp() override { |
| 30 CocoaProfileTest::SetUp(); | 30 CocoaProfileTest::SetUp(); |
| 31 ASSERT_TRUE(profile()); | 31 ASSERT_TRUE(profile()); |
| 32 | 32 |
| 33 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 33 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); |
| 34 default_parent_ = model->bookmark_bar_node(); | 34 default_parent_ = model->bookmark_bar_node(); |
| 35 default_name_ = "http://www.zim-bop-a-dee.com/"; | 35 default_name_ = "http://www.zim-bop-a-dee.com/"; |
| 36 default_title_ = ASCIIToUTF16("ooh title"); | 36 default_title_ = ASCIIToUTF16("ooh title"); |
| 37 const BookmarkNode* default_node = model->AddURL(default_parent_, 0, | 37 const BookmarkNode* default_node = model->AddURL(default_parent_, 0, |
| 38 default_title_, | 38 default_title_, |
| 39 GURL(default_name_)); | 39 GURL(default_name_)); |
| 40 controller_ = [[BookmarkEditorController alloc] | 40 controller_ = [[BookmarkEditorController alloc] |
| 41 initWithParentWindow:test_window() | 41 initWithParentWindow:test_window() |
| 42 profile:profile() | 42 profile:profile() |
| 43 parent:default_parent_ | 43 parent:default_parent_ |
| 44 node:default_node | 44 node:default_node |
| 45 url:GURL() | 45 url:GURL() |
| 46 title:base::string16() | 46 title:base::string16() |
| 47 configuration:BookmarkEditor::NO_TREE]; | 47 configuration:BookmarkEditor::NO_TREE]; |
| 48 [controller_ runAsModalSheet]; | 48 [controller_ runAsModalSheet]; |
| 49 } | 49 } |
| 50 | 50 |
| 51 virtual void TearDown() OVERRIDE { | 51 virtual void TearDown() override { |
| 52 controller_ = NULL; | 52 controller_ = NULL; |
| 53 CocoaProfileTest::TearDown(); | 53 CocoaProfileTest::TearDown(); |
| 54 } | 54 } |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 TEST_F(BookmarkEditorControllerTest, NoEdit) { | 57 TEST_F(BookmarkEditorControllerTest, NoEdit) { |
| 58 [controller_ cancel:nil]; | 58 [controller_ cancel:nil]; |
| 59 ASSERT_EQ(default_parent_->child_count(), 1); | 59 ASSERT_EQ(default_parent_->child_count(), 1); |
| 60 const BookmarkNode* child = default_parent_->GetChild(0); | 60 const BookmarkNode* child = default_parent_->GetChild(0); |
| 61 EXPECT_EQ(child->GetTitle(), default_title_); | 61 EXPECT_EQ(child->GetTitle(), default_title_); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 [controller_ cancel:nil]; | 133 [controller_ cancel:nil]; |
| 134 urlColorB = [controller_ urlFieldColor]; | 134 urlColorB = [controller_ urlFieldColor]; |
| 135 EXPECT_TRUE(urlColorB); | 135 EXPECT_TRUE(urlColorB); |
| 136 EXPECT_NSEQ(urlColorA, urlColorB); | 136 EXPECT_NSEQ(urlColorA, urlColorB); |
| 137 } | 137 } |
| 138 | 138 |
| 139 class BookmarkEditorControllerNoNodeTest : public CocoaProfileTest { | 139 class BookmarkEditorControllerNoNodeTest : public CocoaProfileTest { |
| 140 public: | 140 public: |
| 141 BookmarkEditorController* controller_; | 141 BookmarkEditorController* controller_; |
| 142 | 142 |
| 143 virtual void SetUp() OVERRIDE { | 143 virtual void SetUp() override { |
| 144 CocoaProfileTest::SetUp(); | 144 CocoaProfileTest::SetUp(); |
| 145 ASSERT_TRUE(profile()); | 145 ASSERT_TRUE(profile()); |
| 146 | 146 |
| 147 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 147 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); |
| 148 const BookmarkNode* parent = model->bookmark_bar_node(); | 148 const BookmarkNode* parent = model->bookmark_bar_node(); |
| 149 controller_ = [[BookmarkEditorController alloc] | 149 controller_ = [[BookmarkEditorController alloc] |
| 150 initWithParentWindow:test_window() | 150 initWithParentWindow:test_window() |
| 151 profile:profile() | 151 profile:profile() |
| 152 parent:parent | 152 parent:parent |
| 153 node:NULL | 153 node:NULL |
| 154 url:GURL() | 154 url:GURL() |
| 155 title:base::string16() | 155 title:base::string16() |
| 156 configuration:BookmarkEditor::NO_TREE]; | 156 configuration:BookmarkEditor::NO_TREE]; |
| 157 | 157 |
| 158 [controller_ runAsModalSheet]; | 158 [controller_ runAsModalSheet]; |
| 159 } | 159 } |
| 160 | 160 |
| 161 virtual void TearDown() OVERRIDE { | 161 virtual void TearDown() override { |
| 162 controller_ = NULL; | 162 controller_ = NULL; |
| 163 CocoaProfileTest::TearDown(); | 163 CocoaProfileTest::TearDown(); |
| 164 } | 164 } |
| 165 }; | 165 }; |
| 166 | 166 |
| 167 TEST_F(BookmarkEditorControllerNoNodeTest, NoNodeNoTree) { | 167 TEST_F(BookmarkEditorControllerNoNodeTest, NoNodeNoTree) { |
| 168 EXPECT_NSEQ(@"", [controller_ displayName]); | 168 EXPECT_NSEQ(@"", [controller_ displayName]); |
| 169 EXPECT_EQ(nil, [controller_ displayURL]); | 169 EXPECT_EQ(nil, [controller_ displayURL]); |
| 170 EXPECT_FALSE([controller_ okButtonEnabled]); | 170 EXPECT_FALSE([controller_ okButtonEnabled]); |
| 171 [controller_ cancel:nil]; | 171 [controller_ cancel:nil]; |
| 172 } | 172 } |
| 173 | 173 |
| 174 class BookmarkEditorControllerYesNodeTest : public CocoaProfileTest { | 174 class BookmarkEditorControllerYesNodeTest : public CocoaProfileTest { |
| 175 public: | 175 public: |
| 176 base::string16 default_title_; | 176 base::string16 default_title_; |
| 177 BookmarkEditorController* controller_; | 177 BookmarkEditorController* controller_; |
| 178 | 178 |
| 179 virtual void SetUp() OVERRIDE { | 179 virtual void SetUp() override { |
| 180 CocoaProfileTest::SetUp(); | 180 CocoaProfileTest::SetUp(); |
| 181 ASSERT_TRUE(profile()); | 181 ASSERT_TRUE(profile()); |
| 182 | 182 |
| 183 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 183 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); |
| 184 const BookmarkNode* parent = model->bookmark_bar_node(); | 184 const BookmarkNode* parent = model->bookmark_bar_node(); |
| 185 default_title_ = ASCIIToUTF16("wooh title"); | 185 default_title_ = ASCIIToUTF16("wooh title"); |
| 186 const BookmarkNode* node = | 186 const BookmarkNode* node = |
| 187 model->AddURL(parent, 0, default_title_, | 187 model->AddURL(parent, 0, default_title_, |
| 188 GURL("http://www.zoom-baby-doo-da.com/")); | 188 GURL("http://www.zoom-baby-doo-da.com/")); |
| 189 controller_ = [[BookmarkEditorController alloc] | 189 controller_ = [[BookmarkEditorController alloc] |
| 190 initWithParentWindow:test_window() | 190 initWithParentWindow:test_window() |
| 191 profile:profile() | 191 profile:profile() |
| 192 parent:parent | 192 parent:parent |
| 193 node:node | 193 node:node |
| 194 url:GURL() | 194 url:GURL() |
| 195 title:base::string16() | 195 title:base::string16() |
| 196 configuration:BookmarkEditor::NO_TREE]; | 196 configuration:BookmarkEditor::NO_TREE]; |
| 197 | 197 |
| 198 [controller_ runAsModalSheet]; | 198 [controller_ runAsModalSheet]; |
| 199 } | 199 } |
| 200 | 200 |
| 201 virtual void TearDown() OVERRIDE { | 201 virtual void TearDown() override { |
| 202 controller_ = NULL; | 202 controller_ = NULL; |
| 203 CocoaProfileTest::TearDown(); | 203 CocoaProfileTest::TearDown(); |
| 204 } | 204 } |
| 205 }; | 205 }; |
| 206 | 206 |
| 207 TEST_F(BookmarkEditorControllerYesNodeTest, YesNodeShowTree) { | 207 TEST_F(BookmarkEditorControllerYesNodeTest, YesNodeShowTree) { |
| 208 EXPECT_NSEQ(base::SysUTF16ToNSString(default_title_), | 208 EXPECT_NSEQ(base::SysUTF16ToNSString(default_title_), |
| 209 [controller_ displayName]); | 209 [controller_ displayName]); |
| 210 EXPECT_NSEQ([NSString stringWithCString:"www.zoom-baby-doo-da.com" | 210 EXPECT_NSEQ([NSString stringWithCString:"www.zoom-baby-doo-da.com" |
| 211 encoding:NSUTF8StringEncoding], | 211 encoding:NSUTF8StringEncoding], |
| 212 [controller_ displayURL]); | 212 [controller_ displayURL]); |
| 213 [controller_ cancel:nil]; | 213 [controller_ cancel:nil]; |
| 214 } | 214 } |
| 215 | 215 |
| 216 | 216 |
| 217 class BookmarkEditorControllerUtf8NodeTest : public CocoaProfileTest { | 217 class BookmarkEditorControllerUtf8NodeTest : public CocoaProfileTest { |
| 218 public: | 218 public: |
| 219 BookmarkEditorController* controller_; | 219 BookmarkEditorController* controller_; |
| 220 | 220 |
| 221 virtual void SetUp() OVERRIDE { | 221 virtual void SetUp() override { |
| 222 CocoaProfileTest::SetUp(); | 222 CocoaProfileTest::SetUp(); |
| 223 ASSERT_TRUE(profile()); | 223 ASSERT_TRUE(profile()); |
| 224 | 224 |
| 225 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 225 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); |
| 226 const BookmarkNode* parent = model->bookmark_bar_node(); | 226 const BookmarkNode* parent = model->bookmark_bar_node(); |
| 227 base::string16 title = ASCIIToUTF16("wooh title"); | 227 base::string16 title = ASCIIToUTF16("wooh title"); |
| 228 const char* url_name = "http://www.foobar.com/心得寫作"; | 228 const char* url_name = "http://www.foobar.com/心得寫作"; |
| 229 const BookmarkNode* node = model->AddURL(parent, 0, title, GURL(url_name)); | 229 const BookmarkNode* node = model->AddURL(parent, 0, title, GURL(url_name)); |
| 230 controller_ = [[BookmarkEditorController alloc] | 230 controller_ = [[BookmarkEditorController alloc] |
| 231 initWithParentWindow:test_window() | 231 initWithParentWindow:test_window() |
| 232 profile:profile() | 232 profile:profile() |
| 233 parent:parent | 233 parent:parent |
| 234 node:node | 234 node:node |
| 235 url:GURL() | 235 url:GURL() |
| 236 title:base::string16() | 236 title:base::string16() |
| 237 configuration:BookmarkEditor::NO_TREE]; | 237 configuration:BookmarkEditor::NO_TREE]; |
| 238 | 238 |
| 239 [controller_ runAsModalSheet]; | 239 [controller_ runAsModalSheet]; |
| 240 } | 240 } |
| 241 | 241 |
| 242 virtual void TearDown() OVERRIDE { | 242 virtual void TearDown() override { |
| 243 controller_ = NULL; | 243 controller_ = NULL; |
| 244 CocoaProfileTest::TearDown(); | 244 CocoaProfileTest::TearDown(); |
| 245 } | 245 } |
| 246 }; | 246 }; |
| 247 | 247 |
| 248 TEST_F(BookmarkEditorControllerUtf8NodeTest, DisplayUtf8Name) { | 248 TEST_F(BookmarkEditorControllerUtf8NodeTest, DisplayUtf8Name) { |
| 249 // The "http://" prefix is trimmed, but the UTF-8 formatted characters remain. | 249 // The "http://" prefix is trimmed, but the UTF-8 formatted characters remain. |
| 250 EXPECT_NSEQ([NSString stringWithCString:"www.foobar.com/心得寫作" | 250 EXPECT_NSEQ([NSString stringWithCString:"www.foobar.com/心得寫作" |
| 251 encoding:NSUTF8StringEncoding], | 251 encoding:NSUTF8StringEncoding], |
| 252 [controller_ displayURL]); | 252 [controller_ displayURL]); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 return [[BookmarkEditorController alloc] | 314 return [[BookmarkEditorController alloc] |
| 315 initWithParentWindow:test_window() | 315 initWithParentWindow:test_window() |
| 316 profile:profile() | 316 profile:profile() |
| 317 parent:folder_bb_ | 317 parent:folder_bb_ |
| 318 node:bookmark_bb_3_ | 318 node:bookmark_bb_3_ |
| 319 url:GURL() | 319 url:GURL() |
| 320 title:base::string16() | 320 title:base::string16() |
| 321 configuration:BookmarkEditor::SHOW_TREE]; | 321 configuration:BookmarkEditor::SHOW_TREE]; |
| 322 } | 322 } |
| 323 | 323 |
| 324 virtual void SetUp() OVERRIDE { | 324 virtual void SetUp() override { |
| 325 CocoaProfileTest::SetUp(); | 325 CocoaProfileTest::SetUp(); |
| 326 ASSERT_TRUE(profile()); | 326 ASSERT_TRUE(profile()); |
| 327 | 327 |
| 328 CreateModel(); | 328 CreateModel(); |
| 329 controller_ = CreateController(); | 329 controller_ = CreateController(); |
| 330 [controller_ runAsModalSheet]; | 330 [controller_ runAsModalSheet]; |
| 331 } | 331 } |
| 332 | 332 |
| 333 virtual void TearDown() OVERRIDE { | 333 virtual void TearDown() override { |
| 334 controller_ = NULL; | 334 controller_ = NULL; |
| 335 CocoaProfileTest::TearDown(); | 335 CocoaProfileTest::TearDown(); |
| 336 } | 336 } |
| 337 | 337 |
| 338 // After changing a node, pointers to the node may be invalid. This | 338 // After changing a node, pointers to the node may be invalid. This |
| 339 // is because the node itself may not be updated; it may removed and | 339 // is because the node itself may not be updated; it may removed and |
| 340 // a new one is added in that location. (Implementation detail of | 340 // a new one is added in that location. (Implementation detail of |
| 341 // BookmarkEditorController). This method updates the class's | 341 // BookmarkEditorController). This method updates the class's |
| 342 // bookmark_bb_3_ so that it points to the new node for testing. | 342 // bookmark_bb_3_ so that it points to the new node for testing. |
| 343 void UpdateBB3() { | 343 void UpdateBB3() { |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 TEST_F(BookmarkEditorControllerTreeTest, AddFolderWithFolderSelected) { | 450 TEST_F(BookmarkEditorControllerTreeTest, AddFolderWithFolderSelected) { |
| 451 // Folders are NOT added unless the OK button is pressed. | 451 // Folders are NOT added unless the OK button is pressed. |
| 452 [controller_ newFolder:nil]; | 452 [controller_ newFolder:nil]; |
| 453 [controller_ cancel:nil]; | 453 [controller_ cancel:nil]; |
| 454 EXPECT_EQ(5, folder_bb_->child_count()); | 454 EXPECT_EQ(5, folder_bb_->child_count()); |
| 455 } | 455 } |
| 456 | 456 |
| 457 class BookmarkEditorControllerTreeNoNodeTest : | 457 class BookmarkEditorControllerTreeNoNodeTest : |
| 458 public BookmarkEditorControllerTreeTest { | 458 public BookmarkEditorControllerTreeTest { |
| 459 public: | 459 public: |
| 460 virtual BookmarkEditorController* CreateController() OVERRIDE { | 460 virtual BookmarkEditorController* CreateController() override { |
| 461 return [[BookmarkEditorController alloc] | 461 return [[BookmarkEditorController alloc] |
| 462 initWithParentWindow:test_window() | 462 initWithParentWindow:test_window() |
| 463 profile:profile() | 463 profile:profile() |
| 464 parent:folder_bb_ | 464 parent:folder_bb_ |
| 465 node:nil | 465 node:nil |
| 466 url:GURL() | 466 url:GURL() |
| 467 title:base::string16() | 467 title:base::string16() |
| 468 configuration:BookmarkEditor::SHOW_TREE]; | 468 configuration:BookmarkEditor::SHOW_TREE]; |
| 469 } | 469 } |
| 470 | 470 |
| 471 }; | 471 }; |
| 472 | 472 |
| 473 TEST_F(BookmarkEditorControllerTreeNoNodeTest, NewBookmarkNoNode) { | 473 TEST_F(BookmarkEditorControllerTreeNoNodeTest, NewBookmarkNoNode) { |
| 474 [controller_ setDisplayName:@"NEW BOOKMARK"]; | 474 [controller_ setDisplayName:@"NEW BOOKMARK"]; |
| 475 [controller_ setDisplayURL:@"http://NEWURL.com"]; | 475 [controller_ setDisplayURL:@"http://NEWURL.com"]; |
| 476 [controller_ ok:nil]; | 476 [controller_ ok:nil]; |
| 477 const BookmarkNode* new_node = folder_bb_->GetChild(5); | 477 const BookmarkNode* new_node = folder_bb_->GetChild(5); |
| 478 ASSERT_EQ(0, new_node->child_count()); | 478 ASSERT_EQ(0, new_node->child_count()); |
| 479 EXPECT_EQ(new_node->GetTitle(), ASCIIToUTF16("NEW BOOKMARK")); | 479 EXPECT_EQ(new_node->GetTitle(), ASCIIToUTF16("NEW BOOKMARK")); |
| 480 EXPECT_EQ(new_node->url(), GURL("http://NEWURL.com")); | 480 EXPECT_EQ(new_node->url(), GURL("http://NEWURL.com")); |
| 481 } | 481 } |
| OLD | NEW |