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

Side by Side Diff: chrome/browser/sync/test/integration/two_client_bookmarks_sync_test.cc

Issue 549193002: Skip managed bookmarks at the BookmarkChangeProcessor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix test Created 6 years, 3 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
« no previous file with comments | « chrome/browser/sync/test/integration/bookmarks_helper.cc ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/rand_util.h" 5 #include "base/rand_util.h"
6 #include "base/run_loop.h"
7 #include "base/values.h"
8 #include "chrome/browser/policy/profile_policy_connector_factory.h"
6 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
7 #include "chrome/browser/sync/test/integration/bookmarks_helper.h" 10 #include "chrome/browser/sync/test/integration/bookmarks_helper.h"
8 #include "chrome/browser/sync/test/integration/passwords_helper.h" 11 #include "chrome/browser/sync/test/integration/passwords_helper.h"
9 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h" 12 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h"
10 #include "chrome/browser/sync/test/integration/sync_integration_test_util.h" 13 #include "chrome/browser/sync/test/integration/sync_integration_test_util.h"
11 #include "chrome/browser/sync/test/integration/sync_test.h" 14 #include "chrome/browser/sync/test/integration/sync_test.h"
15 #include "components/policy/core/common/mock_configuration_policy_provider.h"
16 #include "components/policy/core/common/policy_map.h"
17 #include "policy/policy_constants.h"
12 #include "sync/internal_api/public/sessions/sync_session_snapshot.h" 18 #include "sync/internal_api/public/sessions/sync_session_snapshot.h"
19 #include "testing/gmock/include/gmock/gmock.h"
13 #include "ui/base/layout.h" 20 #include "ui/base/layout.h"
14 21
15 using bookmarks_helper::AddFolder; 22 using bookmarks_helper::AddFolder;
16 using bookmarks_helper::AddURL; 23 using bookmarks_helper::AddURL;
17 using bookmarks_helper::AllModelsMatch; 24 using bookmarks_helper::AllModelsMatch;
18 using bookmarks_helper::AllModelsMatchVerifier; 25 using bookmarks_helper::AllModelsMatchVerifier;
19 using bookmarks_helper::ContainsDuplicateBookmarks; 26 using bookmarks_helper::ContainsDuplicateBookmarks;
20 using bookmarks_helper::CountBookmarksWithTitlesMatching; 27 using bookmarks_helper::CountBookmarksWithTitlesMatching;
21 using bookmarks_helper::CreateFavicon; 28 using bookmarks_helper::CreateFavicon;
22 using bookmarks_helper::GetBookmarkBarNode; 29 using bookmarks_helper::GetBookmarkBarNode;
30 using bookmarks_helper::GetManagedNode;
23 using bookmarks_helper::GetOtherNode; 31 using bookmarks_helper::GetOtherNode;
24 using bookmarks_helper::GetSyncedBookmarksNode; 32 using bookmarks_helper::GetSyncedBookmarksNode;
25 using bookmarks_helper::GetUniqueNodeByURL; 33 using bookmarks_helper::GetUniqueNodeByURL;
26 using bookmarks_helper::HasNodeWithURL; 34 using bookmarks_helper::HasNodeWithURL;
27 using bookmarks_helper::IndexedFolderName; 35 using bookmarks_helper::IndexedFolderName;
28 using bookmarks_helper::IndexedSubfolderName; 36 using bookmarks_helper::IndexedSubfolderName;
29 using bookmarks_helper::IndexedSubsubfolderName; 37 using bookmarks_helper::IndexedSubsubfolderName;
30 using bookmarks_helper::IndexedURL; 38 using bookmarks_helper::IndexedURL;
31 using bookmarks_helper::IndexedURLTitle; 39 using bookmarks_helper::IndexedURLTitle;
32 using bookmarks_helper::Move; 40 using bookmarks_helper::Move;
33 using bookmarks_helper::Remove; 41 using bookmarks_helper::Remove;
34 using bookmarks_helper::RemoveAll; 42 using bookmarks_helper::RemoveAll;
35 using bookmarks_helper::ReverseChildOrder; 43 using bookmarks_helper::ReverseChildOrder;
36 using bookmarks_helper::SetFavicon; 44 using bookmarks_helper::SetFavicon;
37 using bookmarks_helper::SetTitle; 45 using bookmarks_helper::SetTitle;
38 using bookmarks_helper::SetURL; 46 using bookmarks_helper::SetURL;
39 using bookmarks_helper::SortChildren; 47 using bookmarks_helper::SortChildren;
40 using passwords_helper::SetDecryptionPassphrase; 48 using passwords_helper::SetDecryptionPassphrase;
41 using passwords_helper::SetEncryptionPassphrase; 49 using passwords_helper::SetEncryptionPassphrase;
42 using sync_integration_test_util::AwaitCommitActivityCompletion; 50 using sync_integration_test_util::AwaitCommitActivityCompletion;
43 using sync_integration_test_util::AwaitPassphraseAccepted; 51 using sync_integration_test_util::AwaitPassphraseAccepted;
44 using sync_integration_test_util::AwaitPassphraseRequired; 52 using sync_integration_test_util::AwaitPassphraseRequired;
45 53
46 const std::string kGenericURL = "http://www.host.ext:1234/path/filename"; 54 namespace {
47 const std::string kGenericURLTitle = "URL Title"; 55
48 const std::string kGenericFolderName = "Folder Name"; 56 const char kGenericURL[] = "http://www.host.ext:1234/path/filename";
49 const std::string kGenericSubfolderName = "Subfolder Name"; 57 const char kGenericURLTitle[] = "URL Title";
50 const std::string kGenericSubsubfolderName = "Subsubfolder Name"; 58 const char kGenericFolderName[] = "Folder Name";
51 const char* kValidPassphrase = "passphrase!"; 59 const char kGenericSubfolderName[] = "Subfolder Name";
60 const char kValidPassphrase[] = "passphrase!";
61
62 } // namespace
52 63
53 class TwoClientBookmarksSyncTest : public SyncTest { 64 class TwoClientBookmarksSyncTest : public SyncTest {
54 public: 65 public:
55 TwoClientBookmarksSyncTest() : SyncTest(TWO_CLIENT) {} 66 TwoClientBookmarksSyncTest() : SyncTest(TWO_CLIENT) {}
56 virtual ~TwoClientBookmarksSyncTest() {} 67 virtual ~TwoClientBookmarksSyncTest() {}
57 68
69 virtual void TearDownInProcessBrowserTestFixture() OVERRIDE {
70 SyncTest::TearDownInProcessBrowserTestFixture();
71 policy_provider_.Shutdown();
72 }
73
74 protected:
75 // Needs to be deleted after all Profiles are deleted.
76 policy::MockConfigurationPolicyProvider policy_provider_;
77
58 private: 78 private:
59 DISALLOW_COPY_AND_ASSIGN(TwoClientBookmarksSyncTest); 79 DISALLOW_COPY_AND_ASSIGN(TwoClientBookmarksSyncTest);
60 }; 80 };
61 81
62 class LegacyTwoClientBookmarksSyncTest : public SyncTest { 82 class LegacyTwoClientBookmarksSyncTest : public SyncTest {
63 public: 83 public:
64 LegacyTwoClientBookmarksSyncTest() : SyncTest(TWO_CLIENT_LEGACY) {} 84 LegacyTwoClientBookmarksSyncTest() : SyncTest(TWO_CLIENT_LEGACY) {}
65 virtual ~LegacyTwoClientBookmarksSyncTest() {} 85 virtual ~LegacyTwoClientBookmarksSyncTest() {}
66 86
67 private: 87 private:
(...skipping 1967 matching lines...) Expand 10 before | Expand all | Expand 10 after
2035 2055
2036 // Remove all 2056 // Remove all
2037 RemoveAll(0); 2057 RemoveAll(0);
2038 2058
2039 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); 2059 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
2040 // Verify other node has no children now. 2060 // Verify other node has no children now.
2041 EXPECT_EQ(0, GetOtherNode(0)->child_count()); 2061 EXPECT_EQ(0, GetOtherNode(0)->child_count());
2042 EXPECT_EQ(0, GetBookmarkBarNode(0)->child_count()); 2062 EXPECT_EQ(0, GetBookmarkBarNode(0)->child_count());
2043 ASSERT_TRUE(AllModelsMatch()); 2063 ASSERT_TRUE(AllModelsMatch());
2044 } 2064 }
2065
2066 // Verifies that managed bookmarks (installed by policy) don't get synced.
2067 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest, ManagedBookmarks) {
2068 // Make sure the first Profile has an overridden policy provider.
2069 EXPECT_CALL(policy_provider_, IsInitializationComplete(testing::_))
2070 .WillRepeatedly(testing::Return(true));
2071 policy::ProfilePolicyConnectorFactory::GetInstance()->PushProviderForTesting(
2072 &policy_provider_);
2073
2074 // Set up sync.
2075 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
2076 ASSERT_TRUE(AllModelsMatchVerifier());
2077
2078 // Verify that there are no managed bookmarks at startup in either profile.
2079 // The Managed Bookmarks folder should not be visible at this stage.
2080 const BookmarkNode* managed_node0 = GetManagedNode(0);
2081 ASSERT_TRUE(managed_node0->empty());
2082 ASSERT_FALSE(managed_node0->IsVisible());
2083 const BookmarkNode* managed_node1 = GetManagedNode(1);
2084 ASSERT_TRUE(managed_node1->empty());
2085 ASSERT_FALSE(managed_node1->IsVisible());
2086
2087 // Verify that the bookmark bar node is empty on both profiles too.
2088 const BookmarkNode* bar_node0 = GetBookmarkBarNode(0);
2089 ASSERT_TRUE(bar_node0->empty());
2090 ASSERT_TRUE(bar_node0->IsVisible());
2091 const BookmarkNode* bar_node1 = GetBookmarkBarNode(1);
2092 ASSERT_TRUE(bar_node1->empty());
2093 ASSERT_TRUE(bar_node1->IsVisible());
2094
2095 // Verify that adding a bookmark is observed by the second Profile.
2096 GURL google_url("http://www.google.com");
2097 ASSERT_TRUE(AddURL(0, "Google", google_url) != NULL);
2098 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
2099 ASSERT_TRUE(AllModelsMatchVerifier());
2100 ASSERT_EQ(1, bar_node0->child_count());
2101 ASSERT_EQ(1, bar_node1->child_count());
2102
2103 // Set the ManagedBookmarks policy for the first Profile,
2104 // which will add one new managed bookmark.
2105 base::DictionaryValue* bookmark = new base::DictionaryValue();
2106 bookmark->SetString("name", "Managed bookmark");
2107 bookmark->SetString("url", "youtube.com");
2108 base::ListValue* list = new base::ListValue();
2109 list->Append(bookmark);
2110 policy::PolicyMap policy;
2111 policy.Set(policy::key::kManagedBookmarks,
2112 policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER,
2113 list, NULL);
2114 policy_provider_.UpdateChromePolicy(policy);
2115 base::RunLoop().RunUntilIdle();
2116
2117 // Now add another user bookmark and wait for it to sync.
2118 ASSERT_TRUE(AddURL(0, "Google 2", google_url) != NULL);
2119 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
2120 ASSERT_TRUE(AllModelsMatchVerifier());
2121
2122 EXPECT_FALSE(GetSyncService(0)->HasUnrecoverableError());
2123 EXPECT_FALSE(GetSyncService(1)->HasUnrecoverableError());
2124
2125 // Verify that the managed bookmark exists in the local model of the first
2126 // Profile, and has a child node.
2127 ASSERT_EQ(1, managed_node0->child_count());
2128 ASSERT_TRUE(managed_node0->IsVisible());
2129 EXPECT_EQ(GURL("http://youtube.com/"), managed_node0->GetChild(0)->url());
2130
2131 // Verify that the second Profile didn't get this node.
2132 ASSERT_EQ(0, managed_node1->child_count());
2133 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/test/integration/bookmarks_helper.cc ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698