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