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

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

Issue 23570009: bookmarks: Cleanup, remove BookmarkModelTestUtils class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/bookmarks/bookmark_model_test_utils.h"
6
7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/bookmarks/bookmark_model.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "url/gurl.h"
11
12 namespace {
13
14 // Helper function which does the actual work of creating the nodes for
15 // a particular level in the hierarchy.
16 std::string::size_type AddNodesFromString(BookmarkModel* model,
17 const BookmarkNode* node,
18 const std::string& model_string,
19 std::string::size_type start_pos) {
20 DCHECK(node);
21 int index = node->child_count();
22 static const std::string folder_tell(":[");
23 std::string::size_type end_pos = model_string.find(' ', start_pos);
24 while (end_pos != std::string::npos) {
25 std::string::size_type part_length = end_pos - start_pos;
26 std::string node_name = model_string.substr(start_pos, part_length);
27 // Are we at the end of a folder group?
28 if (node_name != "]") {
29 // No, is it a folder?
30 std::string tell;
31 if (part_length > 2)
32 tell = node_name.substr(part_length - 2, 2);
33 if (tell == folder_tell) {
34 node_name = node_name.substr(0, part_length - 2);
35 const BookmarkNode* new_node =
36 model->AddFolder(node, index, UTF8ToUTF16(node_name));
37 end_pos = AddNodesFromString(model, new_node, model_string,
38 end_pos + 1);
39 } else {
40 std::string url_string("http://");
41 url_string += std::string(node_name.begin(), node_name.end());
42 url_string += ".com";
43 model->AddURL(node, index, UTF8ToUTF16(node_name), GURL(url_string));
44 ++end_pos;
45 }
46 ++index;
47 start_pos = end_pos;
48 end_pos = model_string.find(' ', start_pos);
49 } else {
50 ++end_pos;
51 break;
52 }
53 }
54 return end_pos;
55 }
56
57 } // namespace
58
59 // static
60 std::string BookmarkModelTestUtils::ModelStringFromNode(
61 const BookmarkNode* node) {
62 // Since the children of the node are not available as a vector,
63 // we'll just have to do it the hard way.
64 int child_count = node->child_count();
65 std::string child_string;
66 for (int i = 0; i < child_count; ++i) {
67 const BookmarkNode* child = node->GetChild(i);
68 if (child->is_folder()) {
69 child_string += UTF16ToUTF8(child->GetTitle()) + ":[ " +
70 ModelStringFromNode(child) + "] ";
71 } else {
72 child_string += UTF16ToUTF8(child->GetTitle()) + " ";
73 }
74 }
75 return child_string;
76 }
77
78 // static
79 void BookmarkModelTestUtils::AddNodesFromModelString(
80 BookmarkModel* model,
81 const BookmarkNode* node,
82 const std::string& model_string) {
83 DCHECK(node);
84 std::string::size_type start_pos = 0;
85 std::string::size_type end_pos =
86 AddNodesFromString(model, node, model_string, start_pos);
87 DCHECK(end_pos == std::string::npos);
88 }
OLDNEW
« no previous file with comments | « chrome/browser/bookmarks/bookmark_model_test_utils.h ('k') | chrome/browser/bookmarks/bookmark_model_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698