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 #include "chrome/browser/ui/views/bookmarks/bookmark_context_menu.h" | 5 #include "chrome/browser/ui/views/bookmarks/bookmark_context_menu.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
88 content::TestBrowserThread file_thread_; | 88 content::TestBrowserThread file_thread_; |
89 scoped_ptr<TestingProfile> profile_; | 89 scoped_ptr<TestingProfile> profile_; |
90 BookmarkModel* model_; | 90 BookmarkModel* model_; |
91 TestingPageNavigator navigator_; | 91 TestingPageNavigator navigator_; |
92 | 92 |
93 private: | 93 private: |
94 // Creates the following structure: | 94 // Creates the following structure: |
95 // a | 95 // a |
96 // F1 | 96 // F1 |
97 // f1a | 97 // f1a |
98 // -f1b as "chrome://settings" | |
98 // F11 | 99 // F11 |
99 // f11a | 100 // f11a |
100 // F2 | 101 // F2 |
101 // F3 | 102 // F3 |
102 // F4 | 103 // F4 |
103 // f4a | 104 // f4a |
104 void AddTestData() { | 105 void AddTestData() { |
105 const BookmarkNode* bb_node = model_->bookmark_bar_node(); | 106 const BookmarkNode* bb_node = model_->bookmark_bar_node(); |
106 std::string test_base = "file:///c:/tmp/"; | 107 std::string test_base = "file:///c:/tmp/"; |
107 model_->AddURL(bb_node, 0, ASCIIToUTF16("a"), GURL(test_base + "a")); | 108 model_->AddURL(bb_node, 0, ASCIIToUTF16("a"), GURL(test_base + "a")); |
108 const BookmarkNode* f1 = model_->AddFolder(bb_node, 1, ASCIIToUTF16("F1")); | 109 const BookmarkNode* f1 = model_->AddFolder(bb_node, 1, ASCIIToUTF16("F1")); |
109 model_->AddURL(f1, 0, ASCIIToUTF16("f1a"), GURL(test_base + "f1a")); | 110 model_->AddURL(f1, 0, ASCIIToUTF16("f1a"), GURL(test_base + "f1a")); |
110 const BookmarkNode* f11 = model_->AddFolder(f1, 1, ASCIIToUTF16("F11")); | 111 model_->AddURL(f1, 1, ASCIIToUTF16("f1b"), GURL("chrome://settings")); |
112 const BookmarkNode* f11 = model_->AddFolder(f1, 2, ASCIIToUTF16("F11")); | |
111 model_->AddURL(f11, 0, ASCIIToUTF16("f11a"), GURL(test_base + "f11a")); | 113 model_->AddURL(f11, 0, ASCIIToUTF16("f11a"), GURL(test_base + "f11a")); |
112 model_->AddFolder(bb_node, 2, ASCIIToUTF16("F2")); | 114 model_->AddFolder(bb_node, 2, ASCIIToUTF16("F2")); |
113 model_->AddFolder(bb_node, 3, ASCIIToUTF16("F3")); | 115 model_->AddFolder(bb_node, 3, ASCIIToUTF16("F3")); |
114 const BookmarkNode* f4 = model_->AddFolder(bb_node, 4, ASCIIToUTF16("F4")); | 116 const BookmarkNode* f4 = model_->AddFolder(bb_node, 4, ASCIIToUTF16("F4")); |
115 model_->AddURL(f4, 0, ASCIIToUTF16("f4a"), GURL(test_base + "f4a")); | 117 model_->AddURL(f4, 0, ASCIIToUTF16("f4a"), GURL(test_base + "f4a")); |
116 } | 118 } |
117 }; | 119 }; |
118 | 120 |
119 // Tests Deleting from the menu. | 121 // Tests Deleting from the menu. |
120 TEST_F(BookmarkContextMenuTest, DeleteURL) { | 122 TEST_F(BookmarkContextMenuTest, DeleteURL) { |
121 std::vector<const BookmarkNode*> nodes; | 123 std::vector<const BookmarkNode*> nodes; |
122 nodes.push_back(model_->bookmark_bar_node()->GetChild(0)); | 124 nodes.push_back(model_->bookmark_bar_node()->GetChild(0)); |
123 BookmarkContextMenu controller( | 125 BookmarkContextMenu controller( |
124 NULL, NULL, profile_.get(), NULL, nodes[0]->parent(), nodes, false); | 126 NULL, NULL, profile_.get(), NULL, nodes[0]->parent(), nodes, false); |
125 GURL url = model_->bookmark_bar_node()->GetChild(0)->url(); | 127 GURL url = model_->bookmark_bar_node()->GetChild(0)->url(); |
126 ASSERT_TRUE(controller.IsCommandEnabled(IDC_BOOKMARK_BAR_REMOVE)); | 128 ASSERT_TRUE(controller.IsCommandEnabled(IDC_BOOKMARK_BAR_REMOVE)); |
127 // Delete the URL. | 129 // Delete the URL. |
128 controller.ExecuteCommand(IDC_BOOKMARK_BAR_REMOVE); | 130 controller.ExecuteCommand(IDC_BOOKMARK_BAR_REMOVE); |
129 // Model shouldn't have URL anymore. | 131 // Model shouldn't have URL anymore. |
130 ASSERT_FALSE(model_->IsBookmarked(url)); | 132 ASSERT_FALSE(model_->IsBookmarked(url)); |
131 } | 133 } |
132 | 134 |
133 // Tests open all on a folder with a couple of bookmarks. | 135 // Tests open all on a folder with a couple of bookmarks. |
134 TEST_F(BookmarkContextMenuTest, OpenAll) { | 136 TEST_F(BookmarkContextMenuTest, OpenAll) { |
135 const BookmarkNode* folder = model_->bookmark_bar_node()->GetChild(1); | 137 const BookmarkNode* folder = model_->bookmark_bar_node()->GetChild(1); |
136 chrome::OpenAll(NULL, &navigator_, folder, NEW_FOREGROUND_TAB); | 138 chrome::OpenAll(NULL, &navigator_, folder, NEW_FOREGROUND_TAB, NULL); |
137 | 139 |
138 // Should have navigated to F1's child but not F11's child. | 140 // Should have navigated to F1's child but not F11's child. |
141 ASSERT_EQ(static_cast<size_t>(2), navigator_.urls_.size()); | |
tfarina
2012/12/19 15:55:03
s/static_cast<size_t>(2)/2U
| |
142 ASSERT_TRUE(folder->GetChild(0)->url() == navigator_.urls_[0]); | |
143 } | |
144 | |
145 // Tests open all on a folder with a couple of bookmarks in incognito window. | |
146 TEST_F(BookmarkContextMenuTest, OpenAllIngonito) { | |
147 const BookmarkNode* folder = model_->bookmark_bar_node()->GetChild(1); | |
148 chrome::OpenAll(NULL, &navigator_, folder, OFF_THE_RECORD, NULL); | |
149 | |
150 // Should have navigated to only f1a but not f2a. | |
139 ASSERT_EQ(static_cast<size_t>(1), navigator_.urls_.size()); | 151 ASSERT_EQ(static_cast<size_t>(1), navigator_.urls_.size()); |
140 ASSERT_TRUE(folder->GetChild(0)->url() == navigator_.urls_[0]); | 152 ASSERT_TRUE(folder->GetChild(0)->url() == navigator_.urls_[0]); |
141 } | 153 } |
142 | 154 |
143 // Tests the enabled state of the menus when supplied an empty vector. | 155 // Tests the enabled state of the menus when supplied an empty vector. |
144 TEST_F(BookmarkContextMenuTest, EmptyNodes) { | 156 TEST_F(BookmarkContextMenuTest, EmptyNodes) { |
145 BookmarkContextMenu controller( | 157 BookmarkContextMenu controller( |
146 NULL, NULL, profile_.get(), NULL, model_->other_node(), | 158 NULL, NULL, profile_.get(), NULL, model_->other_node(), |
147 std::vector<const BookmarkNode*>(), false); | 159 std::vector<const BookmarkNode*>(), false); |
148 EXPECT_FALSE(controller.IsCommandEnabled(IDC_BOOKMARK_BAR_OPEN_ALL)); | 160 EXPECT_FALSE(controller.IsCommandEnabled(IDC_BOOKMARK_BAR_OPEN_ALL)); |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
314 ASSERT_EQ(bb_node->GetChild(0)->url(), bb_node->GetChild(1)->url()); | 326 ASSERT_EQ(bb_node->GetChild(0)->url(), bb_node->GetChild(1)->url()); |
315 | 327 |
316 controller.reset(new BookmarkContextMenu( | 328 controller.reset(new BookmarkContextMenu( |
317 NULL, NULL, profile_.get(), NULL, nodes[0]->parent(), nodes, false)); | 329 NULL, NULL, profile_.get(), NULL, nodes[0]->parent(), nodes, false)); |
318 // Cut the URL. | 330 // Cut the URL. |
319 controller->ExecuteCommand(IDC_CUT); | 331 controller->ExecuteCommand(IDC_CUT); |
320 ASSERT_TRUE(bb_node->GetChild(0)->is_url()); | 332 ASSERT_TRUE(bb_node->GetChild(0)->is_url()); |
321 ASSERT_TRUE(bb_node->GetChild(1)->is_folder()); | 333 ASSERT_TRUE(bb_node->GetChild(1)->is_folder()); |
322 ASSERT_EQ(old_count, bb_node->child_count()); | 334 ASSERT_EQ(old_count, bb_node->child_count()); |
323 } | 335 } |
OLD | NEW |