OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/test/live_sync/live_extensions_sync_test.h" | 5 #include "chrome/test/live_sync/live_extensions_sync_test.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/string_number_conversions.h" |
12 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/themes/theme_service.h" | |
15 #include "chrome/common/extensions/extension.h" | 14 #include "chrome/common/extensions/extension.h" |
16 | 15 |
17 LiveExtensionsSyncTest::LiveExtensionsSyncTest(TestType test_type) | 16 LiveExtensionsSyncTest::LiveExtensionsSyncTest(TestType test_type) |
18 : LiveExtensionsSyncTestBase(test_type) {} | 17 : LiveSyncTest(test_type) {} |
19 | 18 |
20 LiveExtensionsSyncTest::~LiveExtensionsSyncTest() {} | 19 LiveExtensionsSyncTest::~LiveExtensionsSyncTest() {} |
21 | 20 |
22 bool LiveExtensionsSyncTest::HasSameExtensionsAsVerifier(int profile) { | 21 bool LiveExtensionsSyncTest::SetupClients() { |
23 return HasSameExtensionsHelper(GetProfile(profile), | 22 if (!LiveSyncTest::SetupClients()) |
24 verifier()); | 23 return false; |
25 } | |
26 | 24 |
27 bool LiveExtensionsSyncTest::AllProfilesHaveSameExtensionsAsVerifier() { | 25 extension_helper_.Setup(this); |
28 for (int i = 0; i < num_clients(); ++i) { | |
29 if (!HasSameExtensionsAsVerifier(i)) | |
30 return false; | |
31 } | |
32 return true; | 26 return true; |
33 } | 27 } |
34 | 28 |
35 namespace { | 29 namespace { |
36 | 30 |
37 enum ExtensionState { DISABLED, PENDING, ENABLED }; | 31 enum ExtensionState { DISABLED, PENDING, ENABLED }; |
38 | 32 |
39 typedef std::map<std::string, ExtensionState> ExtensionStateMap; | 33 typedef std::map<std::string, ExtensionState> ExtensionStateMap; |
40 | 34 |
41 ExtensionStateMap GetExtensionStates(ExtensionService* extensions_service) { | 35 ExtensionStateMap GetExtensionStates(ExtensionService* extensions_service) { |
42 ExtensionStateMap extension_states; | 36 const std::string& profile_name = |
| 37 extensions_service->profile()->GetPath().BaseName().MaybeAsASCII(); |
| 38 |
| 39 ExtensionStateMap extension_state_map; |
43 | 40 |
44 const ExtensionList* extensions = extensions_service->extensions(); | 41 const ExtensionList* extensions = extensions_service->extensions(); |
45 for (ExtensionList::const_iterator it = extensions->begin(); | 42 for (ExtensionList::const_iterator it = extensions->begin(); |
46 it != extensions->end(); ++it) { | 43 it != extensions->end(); ++it) { |
47 extension_states[(*it)->id()] = ENABLED; | 44 extension_state_map[(*it)->id()] = ENABLED; |
| 45 VLOG(2) << "Extension " << (*it)->id() << " in profile " |
| 46 << profile_name << " is enabled"; |
48 } | 47 } |
49 | 48 |
50 const ExtensionList* disabled_extensions = | 49 const ExtensionList* disabled_extensions = |
51 extensions_service->disabled_extensions(); | 50 extensions_service->disabled_extensions(); |
52 for (ExtensionList::const_iterator it = disabled_extensions->begin(); | 51 for (ExtensionList::const_iterator it = disabled_extensions->begin(); |
53 it != disabled_extensions->end(); ++it) { | 52 it != disabled_extensions->end(); ++it) { |
54 extension_states[(*it)->id()] = DISABLED; | 53 extension_state_map[(*it)->id()] = DISABLED; |
| 54 VLOG(2) << "Extension " << (*it)->id() << " in profile " |
| 55 << profile_name << " is disabled"; |
55 } | 56 } |
56 | 57 |
57 const PendingExtensionManager* pending_extension_manager = | 58 const PendingExtensionManager* pending_extension_manager = |
58 extensions_service->pending_extension_manager(); | 59 extensions_service->pending_extension_manager(); |
59 PendingExtensionManager::const_iterator it; | 60 PendingExtensionManager::const_iterator it; |
60 for (it = pending_extension_manager->begin(); | 61 for (it = pending_extension_manager->begin(); |
61 it != pending_extension_manager->end(); ++it) { | 62 it != pending_extension_manager->end(); ++it) { |
62 extension_states[it->first] = PENDING; | 63 extension_state_map[it->first] = PENDING; |
| 64 VLOG(2) << "Extension " << it->first << " in profile " |
| 65 << profile_name << " is pending"; |
63 } | 66 } |
64 | 67 |
65 return extension_states; | 68 return extension_state_map; |
66 } | 69 } |
67 | 70 |
68 } // namespace | 71 } // namespace |
69 | 72 |
70 bool LiveExtensionsSyncTest::HasSameExtensionsHelper( | 73 bool LiveExtensionsSyncTest::AllProfilesHaveSameExtensionsAsVerifier() { |
71 Profile* profile1, Profile* profile2) { | 74 ExtensionStateMap verifier_extension_state_map( |
72 ExtensionStateMap extension_states1( | 75 GetExtensionStates(verifier()->GetExtensionService())); |
73 GetExtensionStates(profile1->GetExtensionService())); | 76 for (int i = 0; i < num_clients(); ++i) { |
74 ExtensionStateMap extension_states2( | 77 ExtensionStateMap extension_state_map( |
75 GetExtensionStates(profile2->GetExtensionService())); | 78 GetExtensionStates(GetProfile(i)->GetExtensionService())); |
76 return extension_states1 == extension_states2; | 79 if (extension_state_map != verifier_extension_state_map) { |
| 80 return false; |
| 81 } |
| 82 } |
| 83 return true; |
77 } | 84 } |
| 85 |
| 86 void LiveExtensionsSyncTest::InstallExtension(Profile* profile, int index) { |
| 87 std::string name = "fakeextension" + base::IntToString(index); |
| 88 return extension_helper_.InstallExtension( |
| 89 profile, name, Extension::TYPE_EXTENSION); |
| 90 } |
| 91 |
| 92 void LiveExtensionsSyncTest::InstallExtensionsPendingForSync( |
| 93 Profile* profile) { |
| 94 extension_helper_.InstallExtensionsPendingForSync( |
| 95 profile, Extension::TYPE_EXTENSION); |
| 96 } |
OLD | NEW |