15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "base/prefs/pref_service.h"
646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "base/values.h"
746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "chrome/browser/bookmarks/bookmark_model_factory.h"
846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "chrome/browser/bookmarks/chrome_bookmark_client.h"
9f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#include "chrome/browser/bookmarks/chrome_bookmark_client_factory.h"
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/extensions/extension_apitest.h"
1146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "chrome/browser/profiles/profile.h"
1246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "chrome/browser/ui/browser.h"
1346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "components/bookmarks/browser/bookmark_model.h"
1446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "components/bookmarks/browser/bookmark_node.h"
1546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "components/bookmarks/common/bookmark_pref_names.h"
1646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "components/bookmarks/test/bookmark_test_helpers.h"
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
18f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)// Flaky on Windows and Linux. http://crbug.com/383452
19f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#if defined(OS_WIN) || defined(OS_LINUX)
20f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#define MAYBE_Bookmarks DISABLED_Bookmarks
21f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#else
22f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#define MAYBE_Bookmarks Bookmarks
23f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#endif
24f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_Bookmarks) {
2546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  // Add test managed bookmarks to verify that the bookmarks API can read them
2646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  // and can't modify them.
2746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  Profile* profile = browser()->profile();
28f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile);
2946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  ChromeBookmarkClient* client =
30f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      ChromeBookmarkClientFactory::GetForProfile(profile);
3146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  test::WaitForBookmarkModelToLoad(model);
3246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
3346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  base::ListValue list;
3446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  base::DictionaryValue* node = new base::DictionaryValue();
3546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  node->SetString("name", "Managed Bookmark");
3646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  node->SetString("url", "http://www.chromium.org");
3746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  list.Append(node);
3846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  node = new base::DictionaryValue();
3946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  node->SetString("name", "Managed Folder");
4046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  node->Set("children", new base::ListValue());
4146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  list.Append(node);
421320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  profile->GetPrefs()->Set(bookmarks::prefs::kManagedBookmarks, list);
4346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  ASSERT_EQ(2, client->managed_node()->child_count());
4446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_TRUE(RunExtensionTest("bookmarks")) << message_;
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
47