Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / sync / test / integration / multiple_client_typed_urls_sync_test.cc
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.
4
5 #include "base/i18n/number_formatting.h"
6 #include "base/memory/scoped_vector.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/sessions/session_service.h"
9 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h"
10 #include "chrome/browser/sync/test/integration/sync_test.h"
11 #include "chrome/browser/sync/test/integration/typed_urls_helper.h"
12 #include "components/history/core/browser/history_types.h"
13
14 using typed_urls_helper::AddUrlToHistory;
15 using typed_urls_helper::AwaitCheckAllProfilesHaveSameURLsAsVerifier;
16 using typed_urls_helper::GetTypedUrlsFromClient;
17
18 class MultipleClientTypedUrlsSyncTest : public SyncTest {
19  public:
20   MultipleClientTypedUrlsSyncTest() : SyncTest(MULTIPLE_CLIENT) {}
21   ~MultipleClientTypedUrlsSyncTest() override {}
22
23   bool TestUsesSelfNotifications() override { return false; }
24
25  private:
26   DISALLOW_COPY_AND_ASSIGN(MultipleClientTypedUrlsSyncTest);
27 };
28
29 // TCM: 3728323
30 IN_PROC_BROWSER_TEST_F(MultipleClientTypedUrlsSyncTest, AddToOne) {
31   const base::string16 kHistoryUrl(
32       base::ASCIIToUTF16("http://www.add-one-history.google.com/"));
33   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
34
35   // Populate one client with a URL, should sync to all others.
36   GURL new_url(kHistoryUrl);
37   AddUrlToHistory(0, new_url);
38   history::URLRows urls = GetTypedUrlsFromClient(0);
39   ASSERT_EQ(1U, urls.size());
40   ASSERT_EQ(new_url, urls[0].url());
41
42   // All clients should have this URL.
43   ASSERT_TRUE(AwaitCheckAllProfilesHaveSameURLsAsVerifier());
44 }
45
46 IN_PROC_BROWSER_TEST_F(MultipleClientTypedUrlsSyncTest, AddToAll) {
47   const base::string16 kHistoryUrl(
48       base::ASCIIToUTF16("http://www.add-all-history.google.com/"));
49   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
50
51   // Populate clients with the same URL.
52   for (int i = 0; i < num_clients(); ++i) {
53     history::URLRows urls = GetTypedUrlsFromClient(i);
54     ASSERT_EQ(0U, urls.size());
55
56     base::string16 unique_url = kHistoryUrl + base::FormatNumber(i);
57     GURL new_url(unique_url);
58     AddUrlToHistory(i, new_url);
59
60     urls = GetTypedUrlsFromClient(i);
61     ASSERT_EQ(1U, urls.size());
62     ASSERT_EQ(new_url, urls[0].url());
63   }
64
65   // Verify that all clients have all urls.
66   ASSERT_TRUE(AwaitCheckAllProfilesHaveSameURLsAsVerifier());
67 }