OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 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 "chrome/test/live_sync/live_extensions_sync_test.h" |
| 6 |
| 7 #include <map> |
| 8 #include <string> |
| 9 |
| 10 #include "base/logging.h" |
| 11 #include "base/ref_counted.h" |
| 12 #include "chrome/browser/extensions/extensions_service.h" |
| 13 #include "chrome/browser/profile.h" |
| 14 #include "chrome/browser/themes/browser_theme_provider.h" |
| 15 #include "chrome/common/extensions/extension.h" |
| 16 |
| 17 LiveExtensionsSyncTest::LiveExtensionsSyncTest(TestType test_type) |
| 18 : LiveExtensionsSyncTestBase(test_type) {} |
| 19 |
| 20 LiveExtensionsSyncTest::~LiveExtensionsSyncTest() {} |
| 21 |
| 22 bool LiveExtensionsSyncTest::HasSameExtensionsAsVerifier(int profile) { |
| 23 return HasSameExtensionsHelper(GetProfile(profile), |
| 24 verifier()); |
| 25 } |
| 26 |
| 27 bool LiveExtensionsSyncTest::AllProfilesHaveSameExtensionsAsVerifier() { |
| 28 for (int i = 0; i < num_clients(); ++i) { |
| 29 if (!HasSameExtensionsAsVerifier(i)) |
| 30 return false; |
| 31 } |
| 32 return true; |
| 33 } |
| 34 |
| 35 namespace { |
| 36 |
| 37 enum ExtensionState { DISABLED, PENDING, ENABLED }; |
| 38 |
| 39 typedef std::map<std::string, ExtensionState> ExtensionStateMap; |
| 40 |
| 41 ExtensionStateMap GetExtensionStates(ExtensionsService* extensions_service) { |
| 42 ExtensionStateMap extension_states; |
| 43 |
| 44 const ExtensionList* extensions = extensions_service->extensions(); |
| 45 for (ExtensionList::const_iterator it = extensions->begin(); |
| 46 it != extensions->end(); ++it) { |
| 47 extension_states[(*it)->id()] = ENABLED; |
| 48 } |
| 49 |
| 50 const ExtensionList* disabled_extensions = |
| 51 extensions_service->disabled_extensions(); |
| 52 for (ExtensionList::const_iterator it = disabled_extensions->begin(); |
| 53 it != disabled_extensions->end(); ++it) { |
| 54 extension_states[(*it)->id()] = DISABLED; |
| 55 } |
| 56 |
| 57 const PendingExtensionMap& pending_extensions = |
| 58 extensions_service->pending_extensions(); |
| 59 for (PendingExtensionMap::const_iterator it = pending_extensions.begin(); |
| 60 it != pending_extensions.end(); ++it) { |
| 61 extension_states[it->first] = PENDING; |
| 62 } |
| 63 |
| 64 return extension_states; |
| 65 } |
| 66 |
| 67 } // namespace |
| 68 |
| 69 bool LiveExtensionsSyncTest::HasSameExtensionsHelper( |
| 70 Profile* profile1, Profile* profile2) { |
| 71 ExtensionStateMap extension_states1( |
| 72 GetExtensionStates(profile1->GetExtensionsService())); |
| 73 ExtensionStateMap extension_states2( |
| 74 GetExtensionStates(profile2->GetExtensionsService())); |
| 75 return extension_states1 == extension_states2; |
| 76 } |
OLD | NEW |