multiple_client_sessions_sync_test.cc revision 868fa2fe829687343ffae624259930155e16dbd8
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/memory/scoped_vector.h" 6#include "base/strings/stringprintf.h" 7#include "chrome/browser/sessions/session_service.h" 8#include "chrome/browser/sync/profile_sync_service_harness.h" 9#include "chrome/browser/sync/test/integration/sessions_helper.h" 10#include "chrome/browser/sync/test/integration/sync_test.h" 11 12using sessions_helper::CheckForeignSessionsAgainst; 13using sessions_helper::CheckInitialState; 14using sessions_helper::OpenTabAndGetLocalWindows; 15using sessions_helper::ScopedWindowMap; 16using sessions_helper::SessionWindowMap; 17using sessions_helper::SyncedSessionVector; 18 19class MultipleClientSessionsSyncTest : public SyncTest { 20 public: 21 MultipleClientSessionsSyncTest() : SyncTest(MULTIPLE_CLIENT) {} 22 virtual ~MultipleClientSessionsSyncTest() {} 23 24 private: 25 DISALLOW_COPY_AND_ASSIGN(MultipleClientSessionsSyncTest); 26}; 27 28// Timeout on Windows, see http://crbug.com/99819 29#if defined(OS_WIN) 30#define MAYBE_AllChanged DISABLED_AllChanged 31#define MAYBE_EncryptedAndChanged DISABLED_EncryptedAndChanged 32#else 33#define MAYBE_AllChanged AllChanged 34#define MAYBE_EncryptedAndChanged EncryptedAndChanged 35#endif 36 37IN_PROC_BROWSER_TEST_F(MultipleClientSessionsSyncTest, MAYBE_AllChanged) { 38 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; 39 std::vector<ScopedWindowMap> client_windows(num_clients()); 40 41 for (int i = 0; i < num_clients(); ++i) { 42 ASSERT_TRUE(CheckInitialState(i)); 43 } 44 45 // Open tabs on all clients and retain window information. 46 for (int i = 0; i < num_clients(); ++i) { 47 SessionWindowMap windows; 48 ASSERT_TRUE(OpenTabAndGetLocalWindows( 49 i, GURL(base::StringPrintf("http://127.0.0.1/bubba%i", i)), &windows)); 50 client_windows[i].Reset(&windows); 51 } 52 53 // Wait for sync. 54 ASSERT_TRUE(AwaitQuiescence()); 55 56 // Get foreign session data from all clients and check it against all 57 // client_windows. 58 for (int i = 0; i < num_clients(); ++i) { 59 ASSERT_TRUE(CheckForeignSessionsAgainst(i, client_windows)); 60 } 61} 62 63IN_PROC_BROWSER_TEST_F(MultipleClientSessionsSyncTest, 64 MAYBE_EncryptedAndChanged) { 65 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; 66 std::vector<ScopedWindowMap> client_windows(num_clients()); 67 68 for (int i = 0; i < num_clients(); ++i) { 69 ASSERT_TRUE(CheckInitialState(i)); 70 } 71 72 // Enable encryption on client 0, should propagate to all other clients. 73 ASSERT_TRUE(EnableEncryption(0, syncer::SESSIONS)); 74 75 // Wait for sync. 76 // TODO(zea): Fix sync completion detection so we don't need this. For now, 77 // the profile sync service harness detects completion before all encryption 78 // changes are propagated. 79 ASSERT_TRUE(GetClient(0)->AwaitGroupSyncCycleCompletion(clients())); 80 81 // Open tabs on all clients and retain window information. 82 for (int i = 0; i < num_clients(); ++i) { 83 SessionWindowMap windows; 84 ASSERT_TRUE(OpenTabAndGetLocalWindows( 85 i, GURL(base::StringPrintf("http://127.0.0.1/bubba%i", i)), &windows)); 86 client_windows[i].Reset(&windows); 87 } 88 89 // Wait for sync. 90 ASSERT_TRUE(AwaitQuiescence()); 91 92 // Get foreign session data from all clients and check it against all 93 // client_windows. 94 for (int i = 0; i < num_clients(); ++i) { 95 ASSERT_TRUE(IsEncrypted(i, syncer::SESSIONS)); 96 ASSERT_TRUE(CheckForeignSessionsAgainst(i, client_windows)); 97 } 98} 99