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

Side by Side Diff: chrome/test/live_sync/bookmark_model_verifier.h

Issue 7259005: Allow sync integration tests to operate on multiple datatypes: Preferences + Bookmarks (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase (no code changes) Created 9 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
« no previous file with comments | « chrome/chrome_tests.gypi ('k') | chrome/test/live_sync/bookmark_model_verifier.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #ifndef CHROME_TEST_LIVE_SYNC_BOOKMARK_MODEL_VERIFIER_H_
6 #define CHROME_TEST_LIVE_SYNC_BOOKMARK_MODEL_VERIFIER_H_
7 #pragma once
8
9 #include <set>
10 #include <string>
11 #include <vector>
12
13 #include "base/compiler_specific.h"
14 #include "chrome/browser/bookmarks/bookmark_model.h"
15 #include "googleurl/src/gurl.h"
16 #include "third_party/skia/include/core/SkBitmap.h"
17
18 // Helper class that performs operations on a bookmark model and echoes the
19 // changes in a verifier model that can be used as an expected hierarchy to
20 // compare against.
21 // Note: When we refer to the "same" node in |model| and |verifier_model_|,
22 // we mean the same canonical bookmark entity, because |verifier_model_| is
23 // expected to be a replica of |model|.
24 class BookmarkModelVerifier {
25 public:
26 explicit BookmarkModelVerifier(BookmarkModel* model);
27 ~BookmarkModelVerifier();
28
29 // Checks if the hierarchies in |model_a| and |model_b| are equivalent in
30 // terms of the data model and favicon. Returns true if they both match.
31 // Note: Some peripheral fields like creation times are allowed to mismatch.
32 bool ModelsMatch(BookmarkModel* model_a,
33 BookmarkModel* model_b) const WARN_UNUSED_RESULT;
34
35 // Checks if |model| contains any instances of two bookmarks with the same URL
36 // under the same parent folder. Returns true if even one instance is found.
37 bool ContainsDuplicateBookmarks(BookmarkModel* model) const;
38
39 // Checks if the favicon in |node_a| from |model_a| matches that of |node_b|
40 // from |model_b|. Returns true if they match.
41 bool FaviconsMatch(BookmarkModel* model_a,
42 BookmarkModel* model_b,
43 const BookmarkNode* node_a,
44 const BookmarkNode* node_b) const;
45
46 // Checks if the favicon data in |bitmap_a| and |bitmap_b| are equivalent.
47 // Returns true if they match.
48 bool FaviconBitmapsMatch(const SkBitmap& bitmap_a,
49 const SkBitmap& bitmap_b) const;
50
51 // Adds the same bookmark to |model| and |verifier_model_|. See
52 // BookmarkModel::AddURL for details.
53 const BookmarkNode* AddURL(BookmarkModel* model,
54 const BookmarkNode* parent,
55 int index,
56 const string16& title,
57 const GURL& url);
58
59 // Adds the same folder to |model| and |verifier_model_|. See
60 // BookmarkModel::AddFolder for details.
61 const BookmarkNode* AddFolder(BookmarkModel* model,
62 const BookmarkNode* parent,
63 int index,
64 const string16& title);
65
66 // Sets the title of the same node in |model| and |verifier_model_|. See
67 // BookmarkModel::SetTitle for details.
68 void SetTitle(BookmarkModel* model,
69 const BookmarkNode* node,
70 const string16& title);
71
72 // Sets the favicon of the same node in |model| and |verifier_model_| using
73 // the data in |icon_bytes_vector|.
74 // See BookmarkChangeProcessor::ApplyBookmarkFavicon for details.
75 void SetFavicon(BookmarkModel* model,
76 const BookmarkNode* node,
77 const std::vector<unsigned char>& icon_bytes_vector);
78
79 // Gets the favicon associated with |node| in |model|.
80 const SkBitmap& GetFavicon(BookmarkModel* model,
81 const BookmarkNode* node) const;
82
83 // Moves the same node to the same position in both |model| and
84 // |verifier_model_|. See BookmarkModel::Move for details.
85 void Move(BookmarkModel* model,
86 const BookmarkNode* node,
87 const BookmarkNode* new_parent,
88 int index);
89
90 // Removes the same node from |model| and |verifier_model_|. See
91 // BookmarkModel::Remove for details.
92 void Remove(BookmarkModel* model, const BookmarkNode* parent, int index);
93
94 // Sorts children of the same parent node in |model| and |verifier_model_|.
95 // See BookmarkModel::SortChildren for details.
96 void SortChildren(BookmarkModel* model, const BookmarkNode* parent);
97
98 // Reverses the order of children of the same parent node in |model|
99 // and |verifier_model_|.
100 void ReverseChildOrder(BookmarkModel* model, const BookmarkNode* parent);
101
102 // Modifies the url contained in |node| to |new_url|.
103 const BookmarkNode* SetURL(BookmarkModel* model,
104 const BookmarkNode* node,
105 const GURL& new_url);
106
107 void FindNodeInVerifier(BookmarkModel* foreign_model,
108 const BookmarkNode* foreign_node,
109 const BookmarkNode** result);
110
111 // Does a deep comparison of BookmarkNode fields in |model_a| and |model_b|.
112 // Returns true if they are all equal.
113 bool NodesMatch(const BookmarkNode* model_a,
114 const BookmarkNode* model_b) const;
115
116 bool use_verifier_model() const { return use_verifier_model_; }
117
118 void set_use_verifier_model(bool use_verifier_model) {
119 use_verifier_model_ = use_verifier_model;
120 }
121
122 // Returns the number of nodes of node type |node_type| in |model| whose
123 // titles match the string |title|.
124 int CountNodesWithTitlesMatching(BookmarkModel* model,
125 BookmarkNode::Type node_type,
126 const string16& title) const;
127
128 private:
129 // A pointer to the BookmarkModel object within the verifier_profile_ object
130 // in class LiveSyncTest. All verifications are done against this object.
131 BookmarkModel* verifier_model_;
132
133 // A flag that indicates whether bookmark operations should also update the
134 // verifier model or not.
135 bool use_verifier_model_;
136
137 // A collection of URLs for which we have added favicons. Since loading a
138 // favicon is an asynchronous operation and doesn't necessarily invoke a
139 // callback, this collection is used to determine if we must wait for a URL's
140 // favicon to load or not.
141 std::set<GURL> urls_with_favicons_;
142
143 DISALLOW_COPY_AND_ASSIGN(BookmarkModelVerifier);
144 };
145
146 #endif // CHROME_TEST_LIVE_SYNC_BOOKMARK_MODEL_VERIFIER_H_
OLDNEW
« no previous file with comments | « chrome/chrome_tests.gypi ('k') | chrome/test/live_sync/bookmark_model_verifier.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698