Home | History | Annotate | Download | only in integration
      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/history/history_types.h"
      9 #include "chrome/browser/sessions/session_service.h"
     10 #include "chrome/browser/sync/profile_sync_service_harness.h"
     11 #include "chrome/browser/sync/test/integration/sync_test.h"
     12 #include "chrome/browser/sync/test/integration/typed_urls_helper.h"
     13 
     14 using typed_urls_helper::AddUrlToHistory;
     15 using typed_urls_helper::AssertAllProfilesHaveSameURLsAsVerifier;
     16 using typed_urls_helper::GetTypedUrlsFromClient;
     17 
     18 class MultipleClientTypedUrlsSyncTest : public SyncTest {
     19  public:
     20   MultipleClientTypedUrlsSyncTest() : SyncTest(MULTIPLE_CLIENT) {}
     21   virtual ~MultipleClientTypedUrlsSyncTest() {}
     22 
     23  private:
     24   DISALLOW_COPY_AND_ASSIGN(MultipleClientTypedUrlsSyncTest);
     25 };
     26 
     27 // TCM: 3728323
     28 IN_PROC_BROWSER_TEST_F(MultipleClientTypedUrlsSyncTest, AddToOne) {
     29   const string16 kHistoryUrl(
     30       ASCIIToUTF16("http://www.add-one-history.google.com/"));
     31   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
     32 
     33   // Populate one client with a URL, should sync to all others.
     34   GURL new_url(kHistoryUrl);
     35   AddUrlToHistory(0, new_url);
     36   history::URLRows urls = GetTypedUrlsFromClient(0);
     37   ASSERT_EQ(1U, urls.size());
     38   ASSERT_EQ(new_url, urls[0].url());
     39 
     40   // Let sync finish.
     41   ASSERT_TRUE(GetClient(0)->AwaitGroupSyncCycleCompletion(clients()));
     42 
     43   // All clients should have this URL.
     44   AssertAllProfilesHaveSameURLsAsVerifier();
     45 }
     46 
     47 IN_PROC_BROWSER_TEST_F(MultipleClientTypedUrlsSyncTest, AddToAll) {
     48   const string16 kHistoryUrl(
     49       ASCIIToUTF16("http://www.add-all-history.google.com/"));
     50   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
     51 
     52   // Populate clients with the same URL.
     53   for (int i = 0; i < num_clients(); ++i) {
     54     history::URLRows urls = GetTypedUrlsFromClient(i);
     55     ASSERT_EQ(0U, urls.size());
     56 
     57     string16 unique_url = kHistoryUrl + base::FormatNumber(i);
     58     GURL new_url(unique_url);
     59     AddUrlToHistory(i, new_url);
     60 
     61     urls = GetTypedUrlsFromClient(i);
     62     ASSERT_EQ(1U, urls.size());
     63     ASSERT_EQ(new_url, urls[0].url());
     64   }
     65 
     66   // Wait for sync.
     67   ASSERT_TRUE(AwaitQuiescence());
     68 
     69   // Verify that all clients have all urls.
     70   AssertAllProfilesHaveSameURLsAsVerifier();
     71 }
     72