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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/bookmarks/recently_used_folders_combo_model.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/bookmarks/bookmark_model.h"
10 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
11 #include "chrome/test/base/testing_profile.h"
12 #include "chrome/test/base/ui_test_utils.h"
13 #include "content/public/test/test_browser_thread.h"
14 #include "testing/gtest/include/gtest/gtest.h"
16 using content::BrowserThread
;
18 class RecentlyUsedFoldersComboModelTest
: public testing::Test
{
20 RecentlyUsedFoldersComboModelTest();
22 virtual void SetUp() OVERRIDE
;
23 virtual void TearDown() OVERRIDE
;
26 BookmarkModel
* GetModel();
29 base::MessageLoopForUI message_loop_
;
30 content::TestBrowserThread ui_thread_
;
31 content::TestBrowserThread file_thread_
;
32 scoped_ptr
<TestingProfile
> profile_
;
34 DISALLOW_COPY_AND_ASSIGN(RecentlyUsedFoldersComboModelTest
);
37 RecentlyUsedFoldersComboModelTest::RecentlyUsedFoldersComboModelTest()
38 : ui_thread_(BrowserThread::UI
, &message_loop_
),
39 file_thread_(BrowserThread::FILE, &message_loop_
) {
42 void RecentlyUsedFoldersComboModelTest::SetUp() {
43 profile_
.reset(new TestingProfile());
44 profile_
->CreateBookmarkModel(true);
45 ui_test_utils::WaitForBookmarkModelToLoad(GetModel());
48 void RecentlyUsedFoldersComboModelTest::TearDown() {
49 // Flush the message loop to make application verifiers happy.
50 message_loop_
.RunUntilIdle();
53 BookmarkModel
* RecentlyUsedFoldersComboModelTest::GetModel() {
54 return BookmarkModelFactory::GetForProfile(profile_
.get());
57 // Verifies there are no duplicate nodes in the model.
58 TEST_F(RecentlyUsedFoldersComboModelTest
, NoDups
) {
59 const BookmarkNode
* new_node
= GetModel()->AddURL(
60 GetModel()->bookmark_bar_node(), 0, ASCIIToUTF16("a"),
62 RecentlyUsedFoldersComboModel
model(GetModel(), new_node
);
63 std::set
<string16
> items
;
64 for (int i
= 0; i
< model
.GetItemCount(); ++i
) {
65 if (!model
.IsItemSeparatorAt(i
))
66 EXPECT_EQ(0u, items
.count(model
.GetItemAt(i
)));