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 "base/prefs/pref_service.h"
6 #include "base/values.h"
7 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
8 #include "chrome/browser/bookmarks/managed_bookmark_service_factory.h"
9 #include "chrome/browser/extensions/extension_apitest.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/ui/browser.h"
12 #include "components/bookmarks/browser/bookmark_model.h"
13 #include "components/bookmarks/browser/bookmark_node.h"
14 #include "components/bookmarks/common/bookmark_pref_names.h"
15 #include "components/bookmarks/managed/managed_bookmark_service.h"
16 #include "components/bookmarks/test/bookmark_test_helpers.h"
18 using bookmarks::BookmarkModel
;
20 // Flaky on Windows and Linux. http://crbug.com/383452
21 #if defined(OS_WIN) || defined(OS_LINUX)
22 #define MAYBE_Bookmarks DISABLED_Bookmarks
24 #define MAYBE_Bookmarks Bookmarks
26 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, MAYBE_Bookmarks
) {
27 // Add test managed and supervised bookmarks to verify that the bookmarks API
28 // can read them and can't modify them.
29 Profile
* profile
= browser()->profile();
30 BookmarkModel
* model
= BookmarkModelFactory::GetForProfile(profile
);
31 bookmarks::ManagedBookmarkService
* managed
=
32 ManagedBookmarkServiceFactory::GetForProfile(profile
);
33 bookmarks::test::WaitForBookmarkModelToLoad(model
);
37 base::DictionaryValue
* node
= new base::DictionaryValue();
38 node
->SetString("name", "Managed Bookmark");
39 node
->SetString("url", "http://www.chromium.org");
41 node
= new base::DictionaryValue();
42 node
->SetString("name", "Managed Folder");
43 node
->Set("children", new base::ListValue());
45 profile
->GetPrefs()->Set(bookmarks::prefs::kManagedBookmarks
, list
);
46 ASSERT_EQ(2, managed
->managed_node()->child_count());
51 base::DictionaryValue
* node
= new base::DictionaryValue();
52 node
->SetString("name", "Supervised Bookmark");
53 node
->SetString("url", "http://www.pbskids.org");
55 node
= new base::DictionaryValue();
56 node
->SetString("name", "Supervised Folder");
57 node
->Set("children", new base::ListValue());
59 profile
->GetPrefs()->Set(bookmarks::prefs::kSupervisedBookmarks
, list
);
60 ASSERT_EQ(2, managed
->supervised_node()->child_count());
63 ASSERT_TRUE(RunExtensionTest("bookmarks")) << message_
;