multiple_client_typed_urls_sync_test.cc revision 1320f92c476a1ad9d19dba2a48c72b75566198e9
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 14using typed_urls_helper::AddUrlToHistory; 15using typed_urls_helper::AwaitCheckAllProfilesHaveSameURLsAsVerifier; 16using typed_urls_helper::GetTypedUrlsFromClient; 17 18class MultipleClientTypedUrlsSyncTest : public SyncTest { 19 public: 20 MultipleClientTypedUrlsSyncTest() : SyncTest(MULTIPLE_CLIENT) {} 21 virtual ~MultipleClientTypedUrlsSyncTest() {} 22 23 virtual bool TestUsesSelfNotifications() OVERRIDE { 24 return false; 25 } 26 27 private: 28 DISALLOW_COPY_AND_ASSIGN(MultipleClientTypedUrlsSyncTest); 29}; 30 31// TCM: 3728323 32IN_PROC_BROWSER_TEST_F(MultipleClientTypedUrlsSyncTest, AddToOne) { 33 const base::string16 kHistoryUrl( 34 base::ASCIIToUTF16("http://www.add-one-history.google.com/")); 35 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; 36 37 // Populate one client with a URL, should sync to all others. 38 GURL new_url(kHistoryUrl); 39 AddUrlToHistory(0, new_url); 40 history::URLRows urls = GetTypedUrlsFromClient(0); 41 ASSERT_EQ(1U, urls.size()); 42 ASSERT_EQ(new_url, urls[0].url()); 43 44 // All clients should have this URL. 45 ASSERT_TRUE(AwaitCheckAllProfilesHaveSameURLsAsVerifier()); 46} 47 48IN_PROC_BROWSER_TEST_F(MultipleClientTypedUrlsSyncTest, AddToAll) { 49 const base::string16 kHistoryUrl( 50 base::ASCIIToUTF16("http://www.add-all-history.google.com/")); 51 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; 52 53 // Populate clients with the same URL. 54 for (int i = 0; i < num_clients(); ++i) { 55 history::URLRows urls = GetTypedUrlsFromClient(i); 56 ASSERT_EQ(0U, urls.size()); 57 58 base::string16 unique_url = kHistoryUrl + base::FormatNumber(i); 59 GURL new_url(unique_url); 60 AddUrlToHistory(i, new_url); 61 62 urls = GetTypedUrlsFromClient(i); 63 ASSERT_EQ(1U, urls.size()); 64 ASSERT_EQ(new_url, urls[0].url()); 65 } 66 67 // Verify that all clients have all urls. 68 ASSERT_TRUE(AwaitCheckAllProfilesHaveSameURLsAsVerifier()); 69} 70