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

Side by Side Diff: chrome/browser/ui/bookmarks/bookmark_ui_utils_unittest.cc

Issue 242693003: Introduce BookmarkClient interface to abstract embedder (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Work around STL android bug Created 6 years, 8 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
OLDNEW
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/bookmarks/bookmark_utils.h" 5 #include "chrome/browser/ui/bookmarks/bookmark_utils.h"
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/bookmarks/bookmark_model.h" 8 #include "chrome/browser/bookmarks/bookmark_model.h"
9 #include "chrome/browser/bookmarks/test_bookmark_client.h"
9 #include "chrome/test/base/testing_profile.h" 10 #include "chrome/test/base/testing_profile.h"
10 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
11 12
12 #if !defined(OS_ANDROID) && !defined(OS_IOS) 13 #if !defined(OS_ANDROID) && !defined(OS_IOS)
13 14
14 using base::ASCIIToUTF16; 15 using base::ASCIIToUTF16;
15 16
16 namespace { 17 namespace {
17 18
18 TEST(BookmarkUIUtilsTest, HasBookmarkURLs) { 19 TEST(BookmarkUIUtilsTest, HasBookmarkURLs) {
19 BookmarkModel model(NULL, false); 20 test::TestBookmarkClient client;
21 scoped_ptr<BookmarkModel> model(client.CreateModel(false));
20 22
21 std::vector<const BookmarkNode*> nodes; 23 std::vector<const BookmarkNode*> nodes;
22 24
23 // This tests that |nodes| contains an URL. 25 // This tests that |nodes| contains an URL.
24 const BookmarkNode* page1 = model.AddURL(model.bookmark_bar_node(), 0, 26 const BookmarkNode* page1 = model->AddURL(model->bookmark_bar_node(),
25 ASCIIToUTF16("Google"), 27 0,
26 GURL("http://google.com")); 28 ASCIIToUTF16("Google"),
29 GURL("http://google.com"));
27 nodes.push_back(page1); 30 nodes.push_back(page1);
28 EXPECT_TRUE(chrome::HasBookmarkURLs(nodes)); 31 EXPECT_TRUE(chrome::HasBookmarkURLs(nodes));
29 32
30 nodes.clear(); 33 nodes.clear();
31 34
32 // This tests that |nodes| does not contain any URL. 35 // This tests that |nodes| does not contain any URL.
33 const BookmarkNode* folder1 = model.AddFolder(model.bookmark_bar_node(), 0, 36 const BookmarkNode* folder1 =
34 ASCIIToUTF16("Folder1")); 37 model->AddFolder(model->bookmark_bar_node(), 0, ASCIIToUTF16("Folder1"));
35 nodes.push_back(folder1); 38 nodes.push_back(folder1);
36 EXPECT_FALSE(chrome::HasBookmarkURLs(nodes)); 39 EXPECT_FALSE(chrome::HasBookmarkURLs(nodes));
37 40
38 // This verifies if HasBookmarkURLs iterates through immediate children. 41 // This verifies if HasBookmarkURLs iterates through immediate children.
39 model.AddURL(folder1, 0, ASCIIToUTF16("Foo"), GURL("http://randomsite.com")); 42 model->AddURL(folder1, 0, ASCIIToUTF16("Foo"), GURL("http://randomsite.com"));
40 EXPECT_TRUE(chrome::HasBookmarkURLs(nodes)); 43 EXPECT_TRUE(chrome::HasBookmarkURLs(nodes));
41 44
42 // This verifies that HasBookmarkURLS does not iterate through descendants. 45 // This verifies that HasBookmarkURLS does not iterate through descendants.
43 // i.e, it should not find an URL inside a two or three level hierarchy. 46 // i.e, it should not find an URL inside a two or three level hierarchy.
44 // So we add another folder to |folder1| and add another page to that new 47 // So we add another folder to |folder1| and add another page to that new
45 // folder to create a two level hierarchy. 48 // folder to create a two level hierarchy.
46 49
47 // But first we have to remove the URL from |folder1|. 50 // But first we have to remove the URL from |folder1|.
48 model.Remove(folder1, 0); 51 model->Remove(folder1, 0);
49 52
50 const BookmarkNode* subfolder1 = model.AddFolder(folder1, 0, 53 const BookmarkNode* subfolder1 =
51 ASCIIToUTF16("Subfolder1")); 54 model->AddFolder(folder1, 0, ASCIIToUTF16("Subfolder1"));
52 55
53 // Now add the URL to that |subfolder1|. 56 // Now add the URL to that |subfolder1|.
54 model.AddURL(subfolder1, 0, ASCIIToUTF16("BAR"), GURL("http://bar-foo.com")); 57 model->AddURL(subfolder1, 0, ASCIIToUTF16("BAR"), GURL("http://bar-foo.com"));
55 EXPECT_FALSE(chrome::HasBookmarkURLs(nodes)); 58 EXPECT_FALSE(chrome::HasBookmarkURLs(nodes));
56 } 59 }
57 60
58 TEST(BookmarkUIUtilsTest, HasBookmarkURLsAllowedInIncognitoMode) { 61 TEST(BookmarkUIUtilsTest, HasBookmarkURLsAllowedInIncognitoMode) {
59 BookmarkModel model(NULL, false); 62 test::TestBookmarkClient client;
63 scoped_ptr<BookmarkModel> model(client.CreateModel(false));
60 TestingProfile profile; 64 TestingProfile profile;
61 65
62 std::vector<const BookmarkNode*> nodes; 66 std::vector<const BookmarkNode*> nodes;
63 67
64 // This tests that |nodes| contains an disabled-in-incognito URL. 68 // This tests that |nodes| contains an disabled-in-incognito URL.
65 const BookmarkNode* page1 = model.AddURL(model.bookmark_bar_node(), 0, 69 const BookmarkNode* page1 = model->AddURL(model->bookmark_bar_node(),
66 ASCIIToUTF16("BookmarkManager"), 70 0,
67 GURL("chrome://bookmarks")); 71 ASCIIToUTF16("BookmarkManager"),
72 GURL("chrome://bookmarks"));
68 nodes.push_back(page1); 73 nodes.push_back(page1);
69 EXPECT_FALSE(chrome::HasBookmarkURLsAllowedInIncognitoMode(nodes, &profile)); 74 EXPECT_FALSE(chrome::HasBookmarkURLsAllowedInIncognitoMode(nodes, &profile));
70 nodes.clear(); 75 nodes.clear();
71 76
72 // This tests that |nodes| contains an URL that can be opened in incognito 77 // This tests that |nodes| contains an URL that can be opened in incognito
73 // mode. 78 // mode.
74 const BookmarkNode* page2 = model.AddURL(model.bookmark_bar_node(), 0, 79 const BookmarkNode* page2 = model->AddURL(model->bookmark_bar_node(),
75 ASCIIToUTF16("Google"), 80 0,
76 GURL("http://google.com")); 81 ASCIIToUTF16("Google"),
82 GURL("http://google.com"));
77 nodes.push_back(page2); 83 nodes.push_back(page2);
78 EXPECT_TRUE(chrome::HasBookmarkURLsAllowedInIncognitoMode(nodes, &profile)); 84 EXPECT_TRUE(chrome::HasBookmarkURLsAllowedInIncognitoMode(nodes, &profile));
79 85
80 nodes.clear(); 86 nodes.clear();
81 87
82 // This tests that |nodes| does not contain any URL. 88 // This tests that |nodes| does not contain any URL.
83 const BookmarkNode* folder1 = model.AddFolder(model.bookmark_bar_node(), 0, 89 const BookmarkNode* folder1 =
84 ASCIIToUTF16("Folder1")); 90 model->AddFolder(model->bookmark_bar_node(), 0, ASCIIToUTF16("Folder1"));
85 nodes.push_back(folder1); 91 nodes.push_back(folder1);
86 EXPECT_FALSE(chrome::HasBookmarkURLsAllowedInIncognitoMode(nodes, &profile)); 92 EXPECT_FALSE(chrome::HasBookmarkURLsAllowedInIncognitoMode(nodes, &profile));
87 93
88 // This verifies if HasBookmarkURLsAllowedInIncognitoMode iterates through 94 // This verifies if HasBookmarkURLsAllowedInIncognitoMode iterates through
89 // immediate children. 95 // immediate children.
90 // Add disabled-in-incognito url. 96 // Add disabled-in-incognito url.
91 model.AddURL(folder1, 0, ASCIIToUTF16("Foo"), GURL("chrome://bookmarks")); 97 model->AddURL(folder1, 0, ASCIIToUTF16("Foo"), GURL("chrome://bookmarks"));
92 EXPECT_FALSE(chrome::HasBookmarkURLsAllowedInIncognitoMode(nodes, &profile)); 98 EXPECT_FALSE(chrome::HasBookmarkURLsAllowedInIncognitoMode(nodes, &profile));
93 // Add normal url. 99 // Add normal url.
94 model.AddURL(folder1, 0, ASCIIToUTF16("Foo"), GURL("http://randomsite.com")); 100 model->AddURL(folder1, 0, ASCIIToUTF16("Foo"), GURL("http://randomsite.com"));
95 EXPECT_TRUE(chrome::HasBookmarkURLsAllowedInIncognitoMode(nodes, &profile)); 101 EXPECT_TRUE(chrome::HasBookmarkURLsAllowedInIncognitoMode(nodes, &profile));
96 102
97 // This verifies that HasBookmarkURLsAllowedInIncognitoMode does not iterate 103 // This verifies that HasBookmarkURLsAllowedInIncognitoMode does not iterate
98 // through descendants. 104 // through descendants.
99 // i.e, it should not find an URL inside a two or three level hierarchy. 105 // i.e, it should not find an URL inside a two or three level hierarchy.
100 // So we add another folder to |folder1| and add another page to that new 106 // So we add another folder to |folder1| and add another page to that new
101 // folder to create a two level hierarchy. 107 // folder to create a two level hierarchy.
102 108
103 // But first we have to remove the URL from |folder1|. 109 // But first we have to remove the URL from |folder1|.
104 model.Remove(folder1, 0); 110 model->Remove(folder1, 0);
105 111
106 const BookmarkNode* subfolder1 = model.AddFolder(folder1, 0, 112 const BookmarkNode* subfolder1 =
107 ASCIIToUTF16("Subfolder1")); 113 model->AddFolder(folder1, 0, ASCIIToUTF16("Subfolder1"));
108 114
109 // Now add the URL to that |subfolder1|. 115 // Now add the URL to that |subfolder1|.
110 model.AddURL(subfolder1, 0, ASCIIToUTF16("BAR"), GURL("http://bar-foo.com")); 116 model->AddURL(subfolder1, 0, ASCIIToUTF16("BAR"), GURL("http://bar-foo.com"));
111 EXPECT_FALSE(chrome::HasBookmarkURLsAllowedInIncognitoMode(nodes, &profile)); 117 EXPECT_FALSE(chrome::HasBookmarkURLsAllowedInIncognitoMode(nodes, &profile));
112 } 118 }
113 119
114 } // namespace 120 } // namespace
115 #endif 121 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698