| 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 #include <string> |    5 #include <string> | 
|    6  |    6  | 
|    7 #include "base/message_loop.h" |    7 #include "base/message_loop.h" | 
|    8 #include "base/string_util.h" |    8 #include "base/string_util.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" | 
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  125         model_->AddFolder(model_->other_node(), 1, ASCIIToUTF16("OF1")); |  125         model_->AddFolder(model_->other_node(), 1, ASCIIToUTF16("OF1")); | 
|  126     model_->AddURL(of1, 0, ASCIIToUTF16("of1a"), GURL(test_base + "of1a")); |  126     model_->AddURL(of1, 0, ASCIIToUTF16("of1a"), GURL(test_base + "of1a")); | 
|  127   } |  127   } | 
|  128  |  128  | 
|  129   scoped_ptr<BookmarkEditorView> editor_; |  129   scoped_ptr<BookmarkEditorView> editor_; | 
|  130 }; |  130 }; | 
|  131  |  131  | 
|  132 // Makes sure the tree model matches that of the bookmark bar model. |  132 // Makes sure the tree model matches that of the bookmark bar model. | 
|  133 TEST_F(BookmarkEditorViewTest, ModelsMatch) { |  133 TEST_F(BookmarkEditorViewTest, ModelsMatch) { | 
|  134   CreateEditor(profile_.get(), NULL, |  134   CreateEditor(profile_.get(), NULL, | 
|  135                BookmarkEditor::EditDetails::AddNodeInFolder(NULL), |  135                BookmarkEditor::EditDetails::AddNodeInFolder(NULL, -1), | 
|  136                BookmarkEditorView::SHOW_TREE); |  136                BookmarkEditorView::SHOW_TREE); | 
|  137   BookmarkEditorView::EditorNode* editor_root = editor_tree_model()->GetRoot(); |  137   BookmarkEditorView::EditorNode* editor_root = editor_tree_model()->GetRoot(); | 
|  138   // The root should have two or three children: bookmark bar, other bookmarks |  138   // The root should have two or three children: bookmark bar, other bookmarks | 
|  139   // and conditionally synced bookmarks. |  139   // and conditionally synced bookmarks. | 
|  140   if (model_->synced_node()->IsVisible()) { |  140   if (model_->synced_node()->IsVisible()) { | 
|  141     ASSERT_EQ(3, editor_root->child_count()); |  141     ASSERT_EQ(3, editor_root->child_count()); | 
|  142   } else { |  142   } else { | 
|  143     ASSERT_EQ(2, editor_root->child_count()); |  143     ASSERT_EQ(2, editor_root->child_count()); | 
|  144   } |  144   } | 
|  145  |  145  | 
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  256  |  256  | 
|  257   // F21 should have one child, F211. |  257   // F21 should have one child, F211. | 
|  258   const BookmarkNode* mf21 = mf2->GetChild(0); |  258   const BookmarkNode* mf21 = mf2->GetChild(0); | 
|  259   ASSERT_EQ(1, mf21->child_count()); |  259   ASSERT_EQ(1, mf21->child_count()); | 
|  260   ASSERT_EQ(ASCIIToUTF16("F211"), mf21->GetChild(0)->GetTitle()); |  260   ASSERT_EQ(ASCIIToUTF16("F211"), mf21->GetChild(0)->GetTitle()); | 
|  261 } |  261 } | 
|  262  |  262  | 
|  263 // Brings up the editor, creating a new URL on the bookmark bar. |  263 // Brings up the editor, creating a new URL on the bookmark bar. | 
|  264 TEST_F(BookmarkEditorViewTest, NewURL) { |  264 TEST_F(BookmarkEditorViewTest, NewURL) { | 
|  265   CreateEditor(profile_.get(), NULL, |  265   CreateEditor(profile_.get(), NULL, | 
|  266                BookmarkEditor::EditDetails::AddNodeInFolder(NULL), |  266                BookmarkEditor::EditDetails::AddNodeInFolder(NULL, -1), | 
|  267                BookmarkEditorView::SHOW_TREE); |  267                BookmarkEditorView::SHOW_TREE); | 
|  268  |  268  | 
|  269   SetURLText(UTF8ToWide(GURL(base_path() + "a").spec())); |  269   SetURLText(UTF8ToWide(GURL(base_path() + "a").spec())); | 
|  270   SetTitleText(L"new_a"); |  270   SetTitleText(L"new_a"); | 
|  271  |  271  | 
|  272   ApplyEdits(editor_tree_model()->GetRoot()->GetChild(0)); |  272   ApplyEdits(editor_tree_model()->GetRoot()->GetChild(0)); | 
|  273  |  273  | 
|  274   const BookmarkNode* bb_node = |  274   const BookmarkNode* bb_node = | 
|  275       profile_->GetBookmarkModel()->bookmark_bar_node(); |  275       profile_->GetBookmarkModel()->bookmark_bar_node(); | 
|  276   ASSERT_EQ(4, bb_node->child_count()); |  276   ASSERT_EQ(4, bb_node->child_count()); | 
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  318  |  318  | 
|  319   const BookmarkNode* new_node = other_node->GetChild(0); |  319   const BookmarkNode* new_node = other_node->GetChild(0); | 
|  320  |  320  | 
|  321   EXPECT_EQ(ASCIIToUTF16("new_a"), new_node->GetTitle()); |  321   EXPECT_EQ(ASCIIToUTF16("new_a"), new_node->GetTitle()); | 
|  322 } |  322 } | 
|  323  |  323  | 
|  324 // Creates a new folder. |  324 // Creates a new folder. | 
|  325 TEST_F(BookmarkEditorViewTest, NewFolder) { |  325 TEST_F(BookmarkEditorViewTest, NewFolder) { | 
|  326   const BookmarkNode* bb_node = model_->bookmark_bar_node(); |  326   const BookmarkNode* bb_node = model_->bookmark_bar_node(); | 
|  327   BookmarkEditor::EditDetails details = |  327   BookmarkEditor::EditDetails details = | 
|  328       BookmarkEditor::EditDetails::AddFolder(bb_node); |  328       BookmarkEditor::EditDetails::AddFolder(bb_node, -1); | 
|  329   details.urls.push_back(std::make_pair(GURL(base_path() + "x"), |  329   details.urls.push_back(std::make_pair(GURL(base_path() + "x"), | 
|  330                                         ASCIIToUTF16("z"))); |  330                                         ASCIIToUTF16("z"))); | 
|  331   CreateEditor(profile_.get(), bb_node, details, BookmarkEditorView::SHOW_TREE); |  331   CreateEditor(profile_.get(), bb_node, details, BookmarkEditorView::SHOW_TREE); | 
|  332  |  332  | 
|  333   // The url field shouldn't be visible. |  333   // The url field shouldn't be visible. | 
|  334   EXPECT_FALSE(URLTFHasParent()); |  334   EXPECT_FALSE(URLTFHasParent()); | 
|  335   SetTitleText(L"new_F"); |  335   SetTitleText(L"new_F"); | 
|  336  |  336  | 
|  337   ApplyEdits(editor_tree_model()->GetRoot()->GetChild(0)); |  337   ApplyEdits(editor_tree_model()->GetRoot()->GetChild(0)); | 
|  338  |  338  | 
|  339   // Make sure the folder was created. |  339   // Make sure the folder was created. | 
|  340   ASSERT_EQ(4, bb_node->child_count()); |  340   ASSERT_EQ(4, bb_node->child_count()); | 
|  341   const BookmarkNode* new_node = bb_node->GetChild(3); |  341   const BookmarkNode* new_node = bb_node->GetChild(3); | 
|  342   EXPECT_EQ(BookmarkNode::FOLDER, new_node->type()); |  342   EXPECT_EQ(BookmarkNode::FOLDER, new_node->type()); | 
|  343   EXPECT_EQ(ASCIIToUTF16("new_F"), new_node->GetTitle()); |  343   EXPECT_EQ(ASCIIToUTF16("new_F"), new_node->GetTitle()); | 
|  344   // The node should have one child. |  344   // The node should have one child. | 
|  345   ASSERT_EQ(1, new_node->child_count()); |  345   ASSERT_EQ(1, new_node->child_count()); | 
|  346   const BookmarkNode* new_child = new_node->GetChild(0); |  346   const BookmarkNode* new_child = new_node->GetChild(0); | 
|  347   // Make sure the child url/title match. |  347   // Make sure the child url/title match. | 
|  348   EXPECT_EQ(BookmarkNode::URL, new_child->type()); |  348   EXPECT_EQ(BookmarkNode::URL, new_child->type()); | 
|  349   EXPECT_EQ(WideToUTF16Hack(details.urls[0].second), new_child->GetTitle()); |  349   EXPECT_EQ(WideToUTF16Hack(details.urls[0].second), new_child->GetTitle()); | 
|  350   EXPECT_EQ(details.urls[0].first, new_child->url()); |  350   EXPECT_EQ(details.urls[0].first, new_child->url()); | 
|  351 } |  351 } | 
|  352  |  352  | 
|  353 // Creates a new folder and selects a different folder for the folder to appear |  353 // Creates a new folder and selects a different folder for the folder to appear | 
|  354 // in then the editor is initially created showing. |  354 // in then the editor is initially created showing. | 
|  355 TEST_F(BookmarkEditorViewTest, MoveFolder) { |  355 TEST_F(BookmarkEditorViewTest, MoveFolder) { | 
|  356   BookmarkEditor::EditDetails details = BookmarkEditor::EditDetails::AddFolder( |  356   BookmarkEditor::EditDetails details = BookmarkEditor::EditDetails::AddFolder( | 
|  357       model_->bookmark_bar_node()); |  357       model_->bookmark_bar_node(), -1); | 
|  358   details.urls.push_back(std::make_pair(GURL(base_path() + "x"), |  358   details.urls.push_back(std::make_pair(GURL(base_path() + "x"), | 
|  359                                         ASCIIToUTF16("z"))); |  359                                         ASCIIToUTF16("z"))); | 
|  360   CreateEditor(profile_.get(), model_->bookmark_bar_node(), |  360   CreateEditor(profile_.get(), model_->bookmark_bar_node(), | 
|  361                details, BookmarkEditorView::SHOW_TREE); |  361                details, BookmarkEditorView::SHOW_TREE); | 
|  362  |  362  | 
|  363   SetTitleText(L"new_F"); |  363   SetTitleText(L"new_F"); | 
|  364  |  364  | 
|  365   // Create the folder in the 'other' folder. |  365   // Create the folder in the 'other' folder. | 
|  366   ApplyEdits(editor_tree_model()->GetRoot()->GetChild(1)); |  366   ApplyEdits(editor_tree_model()->GetRoot()->GetChild(1)); | 
|  367  |  367  | 
|  368   // Make sure the folder we edited is still there. |  368   // Make sure the folder we edited is still there. | 
|  369   ASSERT_EQ(3, model_->other_node()->child_count()); |  369   ASSERT_EQ(3, model_->other_node()->child_count()); | 
|  370   const BookmarkNode* new_node = model_->other_node()->GetChild(2); |  370   const BookmarkNode* new_node = model_->other_node()->GetChild(2); | 
|  371   EXPECT_EQ(BookmarkNode::FOLDER, new_node->type()); |  371   EXPECT_EQ(BookmarkNode::FOLDER, new_node->type()); | 
|  372   EXPECT_EQ(ASCIIToUTF16("new_F"), new_node->GetTitle()); |  372   EXPECT_EQ(ASCIIToUTF16("new_F"), new_node->GetTitle()); | 
|  373   // The node should have one child. |  373   // The node should have one child. | 
|  374   ASSERT_EQ(1, new_node->child_count()); |  374   ASSERT_EQ(1, new_node->child_count()); | 
|  375   const BookmarkNode* new_child = new_node->GetChild(0); |  375   const BookmarkNode* new_child = new_node->GetChild(0); | 
|  376   // Make sure the child url/title match. |  376   // Make sure the child url/title match. | 
|  377   EXPECT_EQ(BookmarkNode::URL, new_child->type()); |  377   EXPECT_EQ(BookmarkNode::URL, new_child->type()); | 
|  378   EXPECT_EQ(WideToUTF16Hack(details.urls[0].second), new_child->GetTitle()); |  378   EXPECT_EQ(WideToUTF16Hack(details.urls[0].second), new_child->GetTitle()); | 
|  379   EXPECT_EQ(details.urls[0].first, new_child->url()); |  379   EXPECT_EQ(details.urls[0].first, new_child->url()); | 
|  380 } |  380 } | 
| OLD | NEW |