Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Side by Side Diff: chrome/browser/bookmarks/bookmark_node_data_unittest.cc

Issue 10821097: Removing instances of profile_->GetBookmarkModel() as part of converting BookmarkModel to a PKS. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "base/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "base/message_loop.h" 6 #include "base/message_loop.h"
7 #include "base/string16.h" 7 #include "base/string16.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/bookmarks/bookmark_model.h" 9 #include "chrome/browser/bookmarks/bookmark_model.h"
10 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
10 #include "chrome/browser/bookmarks/bookmark_node_data.h" 11 #include "chrome/browser/bookmarks/bookmark_node_data.h"
11 #include "chrome/test/base/testing_profile.h" 12 #include "chrome/test/base/testing_profile.h"
12 #include "content/public/test/test_browser_thread.h" 13 #include "content/public/test/test_browser_thread.h"
13 #include "googleurl/src/gurl.h" 14 #include "googleurl/src/gurl.h"
14 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
15 #include "ui/base/dragdrop/os_exchange_data.h" 16 #include "ui/base/dragdrop/os_exchange_data.h"
16 #include "ui/base/dragdrop/os_exchange_data_provider_win.h" 17 #include "ui/base/dragdrop/os_exchange_data_provider_win.h"
17 18
18 using content::BrowserThread; 19 using content::BrowserThread;
19 20
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 EXPECT_EQ(title, drag_data.elements[0].title); 71 EXPECT_EQ(title, drag_data.elements[0].title);
71 EXPECT_EQ(0, drag_data.elements[0].children.size()); 72 EXPECT_EQ(0, drag_data.elements[0].children.size());
72 } 73 }
73 74
74 TEST_F(BookmarkNodeDataTest, URL) { 75 TEST_F(BookmarkNodeDataTest, URL) {
75 // Write a single node representing a URL to the clipboard. 76 // Write a single node representing a URL to the clipboard.
76 TestingProfile profile; 77 TestingProfile profile;
77 profile.CreateBookmarkModel(false); 78 profile.CreateBookmarkModel(false);
78 profile.BlockUntilBookmarkModelLoaded(); 79 profile.BlockUntilBookmarkModelLoaded();
79 profile.SetID(L"id"); 80 profile.SetID(L"id");
80 BookmarkModel* model = profile.GetBookmarkModel(); 81 BookmarkModel* model = BookmarkModelFactory::GetForProfile(&profile);
81 const BookmarkNode* root = model->bookmark_bar_node(); 82 const BookmarkNode* root = model->bookmark_bar_node();
82 GURL url(GURL("http://foo.com")); 83 GURL url(GURL("http://foo.com"));
83 const string16 title(ASCIIToUTF16("blah")); 84 const string16 title(ASCIIToUTF16("blah"));
84 const BookmarkNode* node = model->AddURL(root, 0, title, url); 85 const BookmarkNode* node = model->AddURL(root, 0, title, url);
85 BookmarkNodeData drag_data(node); 86 BookmarkNodeData drag_data(node);
86 EXPECT_TRUE(drag_data.is_valid()); 87 EXPECT_TRUE(drag_data.is_valid());
87 ASSERT_EQ(1, drag_data.elements.size()); 88 ASSERT_EQ(1, drag_data.elements.size());
88 EXPECT_TRUE(drag_data.elements[0].is_url); 89 EXPECT_TRUE(drag_data.elements[0].is_url);
89 EXPECT_EQ(url, drag_data.elements[0].url); 90 EXPECT_EQ(url, drag_data.elements[0].url);
90 EXPECT_EQ(title, drag_data.elements[0].title); 91 EXPECT_EQ(title, drag_data.elements[0].title);
(...skipping 22 matching lines...) Expand all
113 EXPECT_EQ(url, read_url); 114 EXPECT_EQ(url, read_url);
114 EXPECT_EQ(title, read_title); 115 EXPECT_EQ(title, read_title);
115 } 116 }
116 117
117 // Tests writing a folder to the clipboard. 118 // Tests writing a folder to the clipboard.
118 TEST_F(BookmarkNodeDataTest, Folder) { 119 TEST_F(BookmarkNodeDataTest, Folder) {
119 TestingProfile profile; 120 TestingProfile profile;
120 profile.CreateBookmarkModel(false); 121 profile.CreateBookmarkModel(false);
121 profile.BlockUntilBookmarkModelLoaded(); 122 profile.BlockUntilBookmarkModelLoaded();
122 profile.SetID(L"id"); 123 profile.SetID(L"id");
123 BookmarkModel* model = profile.GetBookmarkModel(); 124 BookmarkModel* model = BookmarkModelFactory::GetForProfile(&profile);
124 const BookmarkNode* root = model->bookmark_bar_node(); 125 const BookmarkNode* root = model->bookmark_bar_node();
125 const BookmarkNode* g1 = model->AddFolder(root, 0, ASCIIToUTF16("g1")); 126 const BookmarkNode* g1 = model->AddFolder(root, 0, ASCIIToUTF16("g1"));
126 const BookmarkNode* g11 = model->AddFolder(g1, 0, ASCIIToUTF16("g11")); 127 const BookmarkNode* g11 = model->AddFolder(g1, 0, ASCIIToUTF16("g11"));
127 const BookmarkNode* g12 = model->AddFolder(g1, 0, ASCIIToUTF16("g12")); 128 const BookmarkNode* g12 = model->AddFolder(g1, 0, ASCIIToUTF16("g12"));
128 129
129 BookmarkNodeData drag_data(g12); 130 BookmarkNodeData drag_data(g12);
130 EXPECT_TRUE(drag_data.is_valid()); 131 EXPECT_TRUE(drag_data.is_valid());
131 ASSERT_EQ(1, drag_data.elements.size()); 132 ASSERT_EQ(1, drag_data.elements.size());
132 EXPECT_EQ(g12->GetTitle(), drag_data.elements[0].title); 133 EXPECT_EQ(g12->GetTitle(), drag_data.elements[0].title);
133 EXPECT_FALSE(drag_data.elements[0].is_url); 134 EXPECT_FALSE(drag_data.elements[0].is_url);
(...skipping 18 matching lines...) Expand all
152 TestingProfile profile2; 153 TestingProfile profile2;
153 EXPECT_TRUE(read_data.GetFirstNode(&profile2) == NULL); 154 EXPECT_TRUE(read_data.GetFirstNode(&profile2) == NULL);
154 } 155 }
155 156
156 // Tests reading/writing a folder with children. 157 // Tests reading/writing a folder with children.
157 TEST_F(BookmarkNodeDataTest, FolderWithChild) { 158 TEST_F(BookmarkNodeDataTest, FolderWithChild) {
158 TestingProfile profile; 159 TestingProfile profile;
159 profile.SetID(L"id"); 160 profile.SetID(L"id");
160 profile.CreateBookmarkModel(false); 161 profile.CreateBookmarkModel(false);
161 profile.BlockUntilBookmarkModelLoaded(); 162 profile.BlockUntilBookmarkModelLoaded();
162 BookmarkModel* model = profile.GetBookmarkModel(); 163 BookmarkModel* model = BookmarkModelFactory::GetForProfile(&profile);
163 const BookmarkNode* root = model->bookmark_bar_node(); 164 const BookmarkNode* root = model->bookmark_bar_node();
164 const BookmarkNode* folder = model->AddFolder(root, 0, ASCIIToUTF16("g1")); 165 const BookmarkNode* folder = model->AddFolder(root, 0, ASCIIToUTF16("g1"));
165 166
166 GURL url(GURL("http://foo.com")); 167 GURL url(GURL("http://foo.com"));
167 const string16 title(ASCIIToUTF16("blah2")); 168 const string16 title(ASCIIToUTF16("blah2"));
168 169
169 model->AddURL(folder, 0, title, url); 170 model->AddURL(folder, 0, title, url);
170 171
171 BookmarkNodeData drag_data(folder); 172 BookmarkNodeData drag_data(folder);
172 173
(...skipping 18 matching lines...) Expand all
191 const BookmarkNode* r_folder = read_data.GetFirstNode(&profile); 192 const BookmarkNode* r_folder = read_data.GetFirstNode(&profile);
192 EXPECT_TRUE(folder == r_folder); 193 EXPECT_TRUE(folder == r_folder);
193 } 194 }
194 195
195 // Tests reading/writing of multiple nodes. 196 // Tests reading/writing of multiple nodes.
196 TEST_F(BookmarkNodeDataTest, MultipleNodes) { 197 TEST_F(BookmarkNodeDataTest, MultipleNodes) {
197 TestingProfile profile; 198 TestingProfile profile;
198 profile.SetID(L"id"); 199 profile.SetID(L"id");
199 profile.CreateBookmarkModel(false); 200 profile.CreateBookmarkModel(false);
200 profile.BlockUntilBookmarkModelLoaded(); 201 profile.BlockUntilBookmarkModelLoaded();
201 BookmarkModel* model = profile.GetBookmarkModel(); 202 BookmarkModel* model = BookmarkModelFactory::GetForProfile(&profile);
202 const BookmarkNode* root = model->bookmark_bar_node(); 203 const BookmarkNode* root = model->bookmark_bar_node();
203 const BookmarkNode* folder = model->AddFolder(root, 0, ASCIIToUTF16("g1")); 204 const BookmarkNode* folder = model->AddFolder(root, 0, ASCIIToUTF16("g1"));
204 205
205 GURL url(GURL("http://foo.com")); 206 GURL url(GURL("http://foo.com"));
206 const string16 title(ASCIIToUTF16("blah2")); 207 const string16 title(ASCIIToUTF16("blah2"));
207 208
208 const BookmarkNode* url_node = model->AddURL(folder, 0, title, url); 209 const BookmarkNode* url_node = model->AddURL(folder, 0, title, url);
209 210
210 // Write the nodes to the clipboard. 211 // Write the nodes to the clipboard.
211 std::vector<const BookmarkNode*> nodes; 212 std::vector<const BookmarkNode*> nodes;
(...skipping 24 matching lines...) Expand all
236 // And make sure we get the node back. 237 // And make sure we get the node back.
237 std::vector<const BookmarkNode*> read_nodes = read_data.GetNodes(&profile); 238 std::vector<const BookmarkNode*> read_nodes = read_data.GetNodes(&profile);
238 ASSERT_EQ(2, read_nodes.size()); 239 ASSERT_EQ(2, read_nodes.size());
239 EXPECT_TRUE(read_nodes[0] == folder); 240 EXPECT_TRUE(read_nodes[0] == folder);
240 EXPECT_TRUE(read_nodes[1] == url_node); 241 EXPECT_TRUE(read_nodes[1] == url_node);
241 242
242 // Asking for the first node should return NULL with more than one element 243 // Asking for the first node should return NULL with more than one element
243 // present. 244 // present.
244 EXPECT_TRUE(read_data.GetFirstNode(&profile) == NULL); 245 EXPECT_TRUE(read_data.GetFirstNode(&profile) == NULL);
245 } 246 }
OLDNEW
« no previous file with comments | « chrome/browser/bookmarks/bookmark_node_data.cc ('k') | chrome/browser/bookmarks/bookmark_pasteboard_helper_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698