OLD | NEW |
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/extensions/api/bookmark_manager_private/bookmark_manage
r_private_api.h" | 5 #include "chrome/browser/extensions/api/bookmark_manager_private/bookmark_manage
r_private_api.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/values.h" |
10 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 11 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 12 #include "chrome/browser/bookmarks/chrome_bookmark_client.h" |
11 #include "chrome/browser/extensions/extension_apitest.h" | 13 #include "chrome/browser/extensions/extension_apitest.h" |
12 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
14 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
15 #include "components/bookmarks/browser/bookmark_model.h" | 17 #include "components/bookmarks/browser/bookmark_model.h" |
| 18 #include "components/bookmarks/common/bookmark_pref_names.h" |
16 #include "components/bookmarks/test/bookmark_test_helpers.h" | 19 #include "components/bookmarks/test/bookmark_test_helpers.h" |
17 #include "components/user_prefs/user_prefs.h" | 20 #include "components/user_prefs/user_prefs.h" |
18 | 21 |
19 // Times out on win syzyasan, http://crbug.com/166026 | 22 // Times out on win syzyasan, http://crbug.com/166026 |
20 #if defined(SYZYASAN) | 23 #if defined(SYZYASAN) |
21 #define MAYBE_BookmarkManager DISABLED_BookmarkManager | 24 #define MAYBE_BookmarkManager DISABLED_BookmarkManager |
22 #else | 25 #else |
23 #define MAYBE_BookmarkManager BookmarkManager | 26 #define MAYBE_BookmarkManager BookmarkManager |
24 #endif | 27 #endif |
25 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_BookmarkManager) { | 28 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_BookmarkManager) { |
| 29 // Add managed bookmarks. |
| 30 Profile* profile = browser()->profile(); |
| 31 ChromeBookmarkClient* client = |
| 32 BookmarkModelFactory::GetChromeBookmarkClientForProfile(profile); |
| 33 BookmarkModel* model = client->model(); |
| 34 test::WaitForBookmarkModelToLoad(model); |
| 35 |
| 36 base::ListValue list; |
| 37 base::DictionaryValue* node = new base::DictionaryValue(); |
| 38 node->SetString("name", "Managed Bookmark"); |
| 39 node->SetString("url", "http://www.chromium.org"); |
| 40 list.Append(node); |
| 41 node = new base::DictionaryValue(); |
| 42 node->SetString("name", "Managed Folder"); |
| 43 node->Set("children", new base::ListValue()); |
| 44 list.Append(node); |
| 45 profile->GetPrefs()->Set(prefs::kManagedBookmarks, list); |
| 46 ASSERT_EQ(2, client->managed_node()->child_count()); |
| 47 |
26 ASSERT_TRUE(RunComponentExtensionTest("bookmark_manager/standard")) | 48 ASSERT_TRUE(RunComponentExtensionTest("bookmark_manager/standard")) |
27 << message_; | 49 << message_; |
28 } | 50 } |
29 | 51 |
30 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, BookmarkManagerEditDisabled) { | 52 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, BookmarkManagerEditDisabled) { |
31 Profile* profile = browser()->profile(); | 53 Profile* profile = browser()->profile(); |
32 | 54 |
33 // Provide some testing data here, since bookmark editing will be disabled | 55 // Provide some testing data here, since bookmark editing will be disabled |
34 // within the extension. | 56 // within the extension. |
35 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile); | 57 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile); |
36 test::WaitForBookmarkModelToLoad(model); | 58 test::WaitForBookmarkModelToLoad(model); |
37 const BookmarkNode* bar = model->bookmark_bar_node(); | 59 const BookmarkNode* bar = model->bookmark_bar_node(); |
38 const BookmarkNode* folder = | 60 const BookmarkNode* folder = |
39 model->AddFolder(bar, 0, base::ASCIIToUTF16("Folder")); | 61 model->AddFolder(bar, 0, base::ASCIIToUTF16("Folder")); |
40 model->AddURL(bar, 1, base::ASCIIToUTF16("AAA"), | 62 model->AddURL(bar, 1, base::ASCIIToUTF16("AAA"), |
41 GURL("http://aaa.example.com")); | 63 GURL("http://aaa.example.com")); |
42 model->AddURL(folder, 0, base::ASCIIToUTF16("BBB"), | 64 model->AddURL(folder, 0, base::ASCIIToUTF16("BBB"), |
43 GURL("http://bbb.example.com")); | 65 GURL("http://bbb.example.com")); |
44 | 66 |
45 PrefService* prefs = user_prefs::UserPrefs::Get(profile); | 67 PrefService* prefs = user_prefs::UserPrefs::Get(profile); |
46 prefs->SetBoolean(prefs::kEditBookmarksEnabled, false); | 68 prefs->SetBoolean(prefs::kEditBookmarksEnabled, false); |
47 | 69 |
48 ASSERT_TRUE(RunComponentExtensionTest("bookmark_manager/edit_disabled")) | 70 ASSERT_TRUE(RunComponentExtensionTest("bookmark_manager/edit_disabled")) |
49 << message_; | 71 << message_; |
50 } | 72 } |
OLD | NEW |