1 // Copyright (c) 2014 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/strings/stringprintf.h"
6 #include "chrome/browser/sync/test/integration/bookmarks_helper.h"
7 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h"
8 #include "chrome/browser/sync/test/integration/sync_test.h"
9 #include "components/bookmarks/browser/bookmark_node.h"
11 // The E2E_ONLY tests are designed to run only against real backend
12 // servers. They are disabled on regular bots. http://crbug.com/431366
13 #define E2E_ONLY(x) DISABLED_##x
15 using bookmarks_helper::AddURL
;
16 using bookmarks_helper::AwaitAllModelsMatch
;
17 using bookmarks_helper::CountAllBookmarks
;
18 using bookmarks_helper::GetBookmarkBarNode
;
20 class TwoClientE2ETest
: public SyncTest
{
22 TwoClientE2ETest() : SyncTest(TWO_CLIENT
) {}
23 ~TwoClientE2ETest() override
{}
24 bool TestUsesSelfNotifications() override
{ return false; }
27 DISALLOW_COPY_AND_ASSIGN(TwoClientE2ETest
);
30 IN_PROC_BROWSER_TEST_F(TwoClientE2ETest
, E2E_ONLY(SanitySetup
)) {
31 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
34 IN_PROC_BROWSER_TEST_F(TwoClientE2ETest
, E2E_ONLY(OneClientAddsBookmark
)) {
35 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
36 // All profiles should sync same bookmarks.
37 ASSERT_TRUE(AwaitAllModelsMatch()) <<
38 "Initial bookmark models did not match for all profiles";
39 // For clean profiles, the bookmarks count should be zero. We are not
40 // enforcing this, we only check that the final count is equal to initial
41 // count plus new bookmarks count.
42 int init_bookmarks_count
= CountAllBookmarks(0);
44 // Add one new bookmark to the first profile.
46 AddURL(0, "Google URL 0", GURL("http://www.google.com/0")) != NULL
);
48 // Blocks and waits for bookmarks models in all profiles to match.
49 ASSERT_TRUE(AwaitAllModelsMatch());
50 // Check that total number of bookmarks is as expected.
51 for (int i
= 0; i
< num_clients(); ++i
) {
52 ASSERT_EQ(CountAllBookmarks(i
), init_bookmarks_count
+ 1) <<
53 "Total bookmark count is wrong.";
57 IN_PROC_BROWSER_TEST_F(TwoClientE2ETest
, E2E_ONLY(TwoClientsAddBookmarks
)) {
58 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
59 // ALl profiles should sync same bookmarks.
60 ASSERT_TRUE(AwaitAllModelsMatch()) <<
61 "Initial bookmark models did not match for all profiles";
62 // For clean profiles, the bookmarks count should be zero. We are not
63 // enforcing this, we only check that the final count is equal to initial
64 // count plus new bookmarks count.
65 int init_bookmarks_count
= CountAllBookmarks(0);
67 // Add one new bookmark per profile.
68 for (int i
= 0; i
< num_clients(); ++i
) {
69 ASSERT_TRUE(AddURL(i
, base::StringPrintf("Google URL %d", i
),
70 GURL(base::StringPrintf("http://www.google.com/%d", i
))) != NULL
);
73 // Blocks and waits for bookmarks models in all profiles to match.
74 ASSERT_TRUE(AwaitAllModelsMatch());
76 // Check that total number of bookmarks is as expected.
77 for (int i
= 0; i
< num_clients(); ++i
) {
78 ASSERT_EQ(CountAllBookmarks(i
), init_bookmarks_count
+ num_clients()) <<
79 "Total bookmark count is wrong.";
83 // Verify that a bookmark added on a client with bookmark syncing disabled gets
84 // synced to a second client once bookmark syncing is re-enabled.
85 IN_PROC_BROWSER_TEST_F(TwoClientE2ETest
, AddBookmarkWhileDisabled
) {
86 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
87 ASSERT_TRUE(AwaitAllModelsMatch())
88 << "Initial bookmark models did not match for all profiles";
89 const int initial_count
= CountAllBookmarks(0);
91 // Verify that we can sync. Add a bookmark on the first client and verify it's
92 // synced to the second client.
93 const std::string url_title
= "a happy little url";
94 const GURL
url("https://example.com");
95 ASSERT_TRUE(AddURL(0, GetBookmarkBarNode(0), 0, url_title
, url
) != NULL
);
96 ASSERT_TRUE(AwaitAllModelsMatch());
97 ASSERT_EQ(initial_count
+ 1, CountAllBookmarks(0));
98 ASSERT_EQ(initial_count
+ 1, CountAllBookmarks(1));
100 // Disable bookmark syncing on the first client, add another bookmark,
101 // re-enable bookmark syncing and see that the second bookmark reaches the
103 ASSERT_TRUE(GetClient(0)->DisableSyncForDatatype(syncer::BOOKMARKS
));
104 const std::string url_title_2
= "another happy little url";
105 const GURL
url_2("https://example.com/second");
106 ASSERT_TRUE(AddURL(0, GetBookmarkBarNode(0), 0, url_title_2
, url_2
) != NULL
);
107 ASSERT_TRUE(GetClient(0)->EnableSyncForDatatype(syncer::BOOKMARKS
));
108 ASSERT_TRUE(AwaitAllModelsMatch());
109 ASSERT_EQ(initial_count
+ 2, CountAllBookmarks(0));
110 ASSERT_EQ(initial_count
+ 2, CountAllBookmarks(1));