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 // TODO(rickcam): Bug 73183: Add unit tests for image loading | 5 // TODO(rickcam): Bug 73183: Add unit tests for image loading |
6 | 6 |
7 #include <cstdlib> | 7 #include <cstdlib> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "chrome/browser/background/background_application_list_model.h" | 10 #include "chrome/browser/background/background_application_list_model.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 DictionaryValue manifest; | 53 DictionaryValue manifest; |
54 manifest.SetString(extension_manifest_keys::kVersion, "1.0.0.0"); | 54 manifest.SetString(extension_manifest_keys::kVersion, "1.0.0.0"); |
55 manifest.SetString(extension_manifest_keys::kName, name); | 55 manifest.SetString(extension_manifest_keys::kName, name); |
56 if (background_permission) { | 56 if (background_permission) { |
57 ListValue* permissions = new ListValue(); | 57 ListValue* permissions = new ListValue(); |
58 manifest.Set(extension_manifest_keys::kPermissions, permissions); | 58 manifest.Set(extension_manifest_keys::kPermissions, permissions); |
59 permissions->Append(Value::CreateStringValue("background")); | 59 permissions->Append(Value::CreateStringValue("background")); |
60 } | 60 } |
61 std::string error; | 61 std::string error; |
62 scoped_refptr<Extension> extension = Extension::Create( | 62 scoped_refptr<Extension> extension = Extension::Create( |
63 bogus_file_path().AppendASCII(name), Extension::INVALID, manifest, | 63 bogus_file_path().AppendASCII(name), |
64 Extension::STRICT_ERROR_CHECKS, &error); | 64 Extension::INVALID, |
| 65 manifest, |
| 66 Extension::STRICT_ERROR_CHECKS, |
| 67 &error); |
65 // Cannot ASSERT_* here because that attempts an illegitimate return. | 68 // Cannot ASSERT_* here because that attempts an illegitimate return. |
66 // Cannot EXPECT_NE here because that assumes non-pointers unlike EXPECT_EQ | 69 // Cannot EXPECT_NE here because that assumes non-pointers unlike EXPECT_EQ |
67 EXPECT_TRUE(extension.get() != NULL) << error; | 70 EXPECT_TRUE(extension.get() != NULL) << error; |
68 return extension; | 71 return extension; |
69 } | 72 } |
70 | 73 |
71 namespace { | 74 namespace { |
72 std::string GenerateUniqueExtensionName() { | 75 std::string GenerateUniqueExtensionName() { |
73 static int uniqueness = 0; | 76 static int uniqueness = 0; |
74 std::ostringstream output; | 77 std::ostringstream output; |
(...skipping 23 matching lines...) Expand all Loading... |
98 } // namespace | 101 } // namespace |
99 | 102 |
100 // With minimal test logic, verifies behavior over an explicit set of | 103 // With minimal test logic, verifies behavior over an explicit set of |
101 // extensions, of which some are Background Apps and others are not. | 104 // extensions, of which some are Background Apps and others are not. |
102 TEST_F(BackgroundApplicationListModelTest, ExplicitTest) { | 105 TEST_F(BackgroundApplicationListModelTest, ExplicitTest) { |
103 InitializeAndLoadEmptyExtensionService(); | 106 InitializeAndLoadEmptyExtensionService(); |
104 ExtensionService* service = profile_->GetExtensionService(); | 107 ExtensionService* service = profile_->GetExtensionService(); |
105 ASSERT_TRUE(service); | 108 ASSERT_TRUE(service); |
106 ASSERT_TRUE(service->is_ready()); | 109 ASSERT_TRUE(service->is_ready()); |
107 ASSERT_TRUE(service->extensions()); | 110 ASSERT_TRUE(service->extensions()); |
108 ASSERT_TRUE(service->extensions()->empty()); | 111 ASSERT_TRUE(service->extensions()->is_empty()); |
109 scoped_ptr<BackgroundApplicationListModel> model( | 112 scoped_ptr<BackgroundApplicationListModel> model( |
110 new BackgroundApplicationListModel(profile_.get())); | 113 new BackgroundApplicationListModel(profile_.get())); |
111 ASSERT_EQ(0U, model->size()); | 114 ASSERT_EQ(0U, model->size()); |
112 | 115 |
113 scoped_refptr<Extension> ext1 = CreateExtension("alpha", false); | 116 scoped_refptr<Extension> ext1 = CreateExtension("alpha", false); |
114 scoped_refptr<Extension> ext2 = CreateExtension("bravo", false); | 117 scoped_refptr<Extension> ext2 = CreateExtension("bravo", false); |
115 scoped_refptr<Extension> ext3 = CreateExtension("charlie", false); | 118 scoped_refptr<Extension> ext3 = CreateExtension("charlie", false); |
116 scoped_refptr<Extension> bgapp1 = CreateExtension("delta", true); | 119 scoped_refptr<Extension> bgapp1 = CreateExtension("delta", true); |
117 scoped_refptr<Extension> bgapp2 = CreateExtension("echo", true); | 120 scoped_refptr<Extension> bgapp2 = CreateExtension("echo", true); |
118 ASSERT_TRUE(service->extensions() != NULL); | 121 ASSERT_TRUE(service->extensions() != NULL); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 ASSERT_EQ(0U, model->size()); | 167 ASSERT_EQ(0U, model->size()); |
165 } | 168 } |
166 | 169 |
167 // With minimal test logic, verifies behavior with dynamic permissions. | 170 // With minimal test logic, verifies behavior with dynamic permissions. |
168 TEST_F(BackgroundApplicationListModelTest, AddRemovePermissionsTest) { | 171 TEST_F(BackgroundApplicationListModelTest, AddRemovePermissionsTest) { |
169 InitializeAndLoadEmptyExtensionService(); | 172 InitializeAndLoadEmptyExtensionService(); |
170 ExtensionService* service = profile_->GetExtensionService(); | 173 ExtensionService* service = profile_->GetExtensionService(); |
171 ASSERT_TRUE(service); | 174 ASSERT_TRUE(service); |
172 ASSERT_TRUE(service->is_ready()); | 175 ASSERT_TRUE(service->is_ready()); |
173 ASSERT_TRUE(service->extensions()); | 176 ASSERT_TRUE(service->extensions()); |
174 ASSERT_TRUE(service->extensions()->empty()); | 177 ASSERT_TRUE(service->extensions()->is_empty()); |
175 scoped_ptr<BackgroundApplicationListModel> model( | 178 scoped_ptr<BackgroundApplicationListModel> model( |
176 new BackgroundApplicationListModel(profile_.get())); | 179 new BackgroundApplicationListModel(profile_.get())); |
177 ASSERT_EQ(0U, model->size()); | 180 ASSERT_EQ(0U, model->size()); |
178 | 181 |
179 scoped_refptr<Extension> ext = CreateExtension("extension", false); | 182 scoped_refptr<Extension> ext = CreateExtension("extension", false); |
180 scoped_refptr<Extension> bgapp = CreateExtension("application", true); | 183 scoped_refptr<Extension> bgapp = CreateExtension("application", true); |
181 ASSERT_TRUE(service->extensions() != NULL); | 184 ASSERT_TRUE(service->extensions() != NULL); |
182 ASSERT_EQ(0U, service->extensions()->size()); | 185 ASSERT_EQ(0U, service->extensions()->size()); |
183 ASSERT_EQ(0U, model->size()); | 186 ASSERT_EQ(0U, model->size()); |
184 | 187 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 } // namespace | 306 } // namespace |
304 | 307 |
305 // Verifies behavior with a pseudo-randomly generated set of actions: Adding and | 308 // Verifies behavior with a pseudo-randomly generated set of actions: Adding and |
306 // removing extensions, of which some are Background Apps and others are not. | 309 // removing extensions, of which some are Background Apps and others are not. |
307 TEST_F(BackgroundApplicationListModelTest, RandomTest) { | 310 TEST_F(BackgroundApplicationListModelTest, RandomTest) { |
308 InitializeAndLoadEmptyExtensionService(); | 311 InitializeAndLoadEmptyExtensionService(); |
309 ExtensionService* service = profile_->GetExtensionService(); | 312 ExtensionService* service = profile_->GetExtensionService(); |
310 ASSERT_TRUE(service); | 313 ASSERT_TRUE(service); |
311 ASSERT_TRUE(service->is_ready()); | 314 ASSERT_TRUE(service->is_ready()); |
312 ASSERT_TRUE(service->extensions()); | 315 ASSERT_TRUE(service->extensions()); |
313 ASSERT_TRUE(service->extensions()->empty()); | 316 ASSERT_TRUE(service->extensions()->is_empty()); |
314 scoped_ptr<BackgroundApplicationListModel> model( | 317 scoped_ptr<BackgroundApplicationListModel> model( |
315 new BackgroundApplicationListModel(profile_.get())); | 318 new BackgroundApplicationListModel(profile_.get())); |
316 ASSERT_EQ(0U, model->size()); | 319 ASSERT_EQ(0U, model->size()); |
317 | 320 |
318 static const int kIterations = 500; | 321 static const int kIterations = 500; |
319 ExtensionCollection extensions; | 322 ExtensionCollection extensions; |
320 size_t count = 0; | 323 size_t count = 0; |
321 size_t expected = 0; | 324 size_t expected = 0; |
322 srand(RANDOM_SEED); | 325 srand(RANDOM_SEED); |
323 for (int index = 0; index < kIterations; ++index) { | 326 for (int index = 0; index < kIterations; ++index) { |
324 switch (rand() % 3) { | 327 switch (rand() % 3) { |
325 case 0: | 328 case 0: |
326 AddExtension(service, &extensions, model.get(), &expected, &count); | 329 AddExtension(service, &extensions, model.get(), &expected, &count); |
327 break; | 330 break; |
328 case 1: | 331 case 1: |
329 RemoveExtension(service, &extensions, model.get(), &expected, &count); | 332 RemoveExtension(service, &extensions, model.get(), &expected, &count); |
330 break; | 333 break; |
331 case 2: | 334 case 2: |
332 TogglePermission(service, &extensions, model.get(), &expected, &count); | 335 TogglePermission(service, &extensions, model.get(), &expected, &count); |
333 break; | 336 break; |
334 default: | 337 default: |
335 NOTREACHED(); | 338 NOTREACHED(); |
336 break; | 339 break; |
337 } | 340 } |
338 } | 341 } |
339 } | 342 } |
OLD | NEW |