| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/browser/extensions/extension_service_unittest.h" | 5 #include "chrome/browser/extensions/extension_service_unittest.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 #include "chrome/common/chrome_switches.h" | 54 #include "chrome/common/chrome_switches.h" |
| 55 #include "chrome/common/extensions/extension.h" | 55 #include "chrome/common/extensions/extension.h" |
| 56 #include "chrome/common/extensions/extension_constants.h" | 56 #include "chrome/common/extensions/extension_constants.h" |
| 57 #include "chrome/common/extensions/extension_resource.h" | 57 #include "chrome/common/extensions/extension_resource.h" |
| 58 #include "chrome/common/extensions/url_pattern.h" | 58 #include "chrome/common/extensions/url_pattern.h" |
| 59 #include "chrome/common/pref_names.h" | 59 #include "chrome/common/pref_names.h" |
| 60 #include "chrome/common/string_ordinal.h" | 60 #include "chrome/common/string_ordinal.h" |
| 61 #include "chrome/common/url_constants.h" | 61 #include "chrome/common/url_constants.h" |
| 62 #include "chrome/test/base/testing_profile.h" | 62 #include "chrome/test/base/testing_profile.h" |
| 63 #include "content/browser/appcache/chrome_appcache_service.h" | 63 #include "content/browser/appcache/chrome_appcache_service.h" |
| 64 #include "content/browser/file_system/browser_file_system_helper.h" | |
| 65 #include "content/browser/in_process_webkit/dom_storage_context.h" | 64 #include "content/browser/in_process_webkit/dom_storage_context.h" |
| 66 #include "content/browser/in_process_webkit/webkit_context.h" | 65 #include "content/browser/in_process_webkit/webkit_context.h" |
| 67 #include "content/public/browser/notification_registrar.h" | 66 #include "content/public/browser/notification_registrar.h" |
| 68 #include "content/public/browser/notification_service.h" | 67 #include "content/public/browser/notification_service.h" |
| 69 #include "content/public/browser/plugin_service.h" | 68 #include "content/public/browser/plugin_service.h" |
| 69 #include "content/public/common/content_constants.h" |
| 70 #include "content/test/test_browser_thread.h" | 70 #include "content/test/test_browser_thread.h" |
| 71 #include "googleurl/src/gurl.h" | 71 #include "googleurl/src/gurl.h" |
| 72 #include "grit/browser_resources.h" | 72 #include "grit/browser_resources.h" |
| 73 #include "net/base/cookie_monster.h" | 73 #include "net/base/cookie_monster.h" |
| 74 #include "net/base/cookie_options.h" | 74 #include "net/base/cookie_options.h" |
| 75 #include "net/url_request/url_request_context.h" | 75 #include "net/url_request/url_request_context.h" |
| 76 #include "net/url_request/url_request_context_getter.h" | 76 #include "net/url_request/url_request_context_getter.h" |
| 77 #include "testing/gtest/include/gtest/gtest.h" | 77 #include "testing/gtest/include/gtest/gtest.h" |
| 78 #include "testing/platform_test.h" | 78 #include "testing/platform_test.h" |
| 79 #include "webkit/database/database_tracker.h" | 79 #include "webkit/database/database_tracker.h" |
| 80 #include "webkit/database/database_util.h" | 80 #include "webkit/database/database_util.h" |
| 81 #include "webkit/plugins/npapi/mock_plugin_list.h" | 81 #include "webkit/plugins/npapi/mock_plugin_list.h" |
| 82 #include "webkit/quota/quota_manager.h" | 82 #include "webkit/quota/quota_manager.h" |
| 83 | 83 |
| 84 using content::BrowserContext; |
| 84 using content::BrowserThread; | 85 using content::BrowserThread; |
| 85 using content::PluginService; | 86 using content::PluginService; |
| 86 | 87 |
| 87 namespace keys = extension_manifest_keys; | 88 namespace keys = extension_manifest_keys; |
| 88 | 89 |
| 89 namespace { | 90 namespace { |
| 90 | 91 |
| 91 // Extension ids used during testing. | 92 // Extension ids used during testing. |
| 92 const char* const all_zero = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | 93 const char* const all_zero = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
| 93 const char* const zero_n_one = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab"; | 94 const char* const zero_n_one = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab"; |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 class ExtensionTestingProfile : public TestingProfile { | 369 class ExtensionTestingProfile : public TestingProfile { |
| 369 public: | 370 public: |
| 370 ExtensionTestingProfile() : service_(NULL) { | 371 ExtensionTestingProfile() : service_(NULL) { |
| 371 } | 372 } |
| 372 | 373 |
| 373 void set_extensions_service(ExtensionService* service) { | 374 void set_extensions_service(ExtensionService* service) { |
| 374 service_ = service; | 375 service_ = service; |
| 375 } | 376 } |
| 376 virtual ExtensionService* GetExtensionService() { return service_; } | 377 virtual ExtensionService* GetExtensionService() { return service_; } |
| 377 | 378 |
| 378 virtual ChromeAppCacheService* GetAppCacheService() { | |
| 379 if (!appcache_service_) { | |
| 380 appcache_service_ = new ChromeAppCacheService(NULL); | |
| 381 if (!BrowserThread::PostTask( | |
| 382 BrowserThread::IO, FROM_HERE, | |
| 383 base::Bind( | |
| 384 &ChromeAppCacheService::InitializeOnIOThread, | |
| 385 appcache_service_.get(), | |
| 386 IsOffTheRecord() | |
| 387 ? FilePath() : GetPath().Append(chrome::kAppCacheDirname), | |
| 388 GetResourceContext(), | |
| 389 make_scoped_refptr(GetExtensionSpecialStoragePolicy())))) | |
| 390 NOTREACHED(); | |
| 391 } | |
| 392 return appcache_service_; | |
| 393 } | |
| 394 | |
| 395 virtual fileapi::FileSystemContext* GetFileSystemContext() { | |
| 396 if (!file_system_context_) { | |
| 397 quota::QuotaManager* quota_manager = GetQuotaManager(); | |
| 398 file_system_context_ = CreateFileSystemContext( | |
| 399 GetPath(), IsOffTheRecord(), | |
| 400 GetExtensionSpecialStoragePolicy(), | |
| 401 quota_manager ? quota_manager->proxy() : NULL); | |
| 402 } | |
| 403 return file_system_context_; | |
| 404 } | |
| 405 | |
| 406 private: | 379 private: |
| 407 ExtensionService* service_; | 380 ExtensionService* service_; |
| 408 scoped_refptr<ChromeAppCacheService> appcache_service_; | |
| 409 scoped_refptr<fileapi::FileSystemContext> file_system_context_; | |
| 410 }; | 381 }; |
| 411 | 382 |
| 412 // Our message loop may be used in tests which require it to be an IO loop. | 383 // Our message loop may be used in tests which require it to be an IO loop. |
| 413 ExtensionServiceTestBase::ExtensionServiceTestBase() | 384 ExtensionServiceTestBase::ExtensionServiceTestBase() |
| 414 : loop_(MessageLoop::TYPE_IO), | 385 : loop_(MessageLoop::TYPE_IO), |
| 415 service_(NULL), | 386 service_(NULL), |
| 416 expected_extensions_count_(0), | 387 expected_extensions_count_(0), |
| 417 ui_thread_(BrowserThread::UI, &loop_), | 388 ui_thread_(BrowserThread::UI, &loop_), |
| 418 db_thread_(BrowserThread::DB, &loop_), | 389 db_thread_(BrowserThread::DB, &loop_), |
| 419 webkit_thread_(BrowserThread::WEBKIT_DEPRECATED, &loop_), | 390 webkit_thread_(BrowserThread::WEBKIT_DEPRECATED, &loop_), |
| (...skipping 2677 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3097 EXPECT_TRUE(callback.result_); | 3068 EXPECT_TRUE(callback.result_); |
| 3098 | 3069 |
| 3099 cookie_monster->GetAllCookiesForURLAsync( | 3070 cookie_monster->GetAllCookiesForURLAsync( |
| 3100 ext_url, | 3071 ext_url, |
| 3101 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, | 3072 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, |
| 3102 base::Unretained(&callback))); | 3073 base::Unretained(&callback))); |
| 3103 loop_.RunAllPending(); | 3074 loop_.RunAllPending(); |
| 3104 EXPECT_EQ(1U, callback.list_.size()); | 3075 EXPECT_EQ(1U, callback.list_.size()); |
| 3105 | 3076 |
| 3106 // Open a database. | 3077 // Open a database. |
| 3107 webkit_database::DatabaseTracker* db_tracker = profile_->GetDatabaseTracker(); | 3078 webkit_database::DatabaseTracker* db_tracker = |
| 3079 BrowserContext::GetDatabaseTracker(profile_.get()); |
| 3108 string16 db_name = UTF8ToUTF16("db"); | 3080 string16 db_name = UTF8ToUTF16("db"); |
| 3109 string16 description = UTF8ToUTF16("db_description"); | 3081 string16 description = UTF8ToUTF16("db_description"); |
| 3110 int64 size; | 3082 int64 size; |
| 3111 db_tracker->DatabaseOpened(origin_id, db_name, description, 1, &size); | 3083 db_tracker->DatabaseOpened(origin_id, db_name, description, 1, &size); |
| 3112 db_tracker->DatabaseClosed(origin_id, db_name); | 3084 db_tracker->DatabaseClosed(origin_id, db_name); |
| 3113 std::vector<webkit_database::OriginInfo> origins; | 3085 std::vector<webkit_database::OriginInfo> origins; |
| 3114 db_tracker->GetAllOriginsInfo(&origins); | 3086 db_tracker->GetAllOriginsInfo(&origins); |
| 3115 EXPECT_EQ(1U, origins.size()); | 3087 EXPECT_EQ(1U, origins.size()); |
| 3116 EXPECT_EQ(origin_id, origins[0].GetOrigin()); | 3088 EXPECT_EQ(origin_id, origins[0].GetOrigin()); |
| 3117 | 3089 |
| 3118 // Create local storage. We only simulate this by creating the backing file | 3090 // Create local storage. We only simulate this by creating the backing file |
| 3119 // since webkit is not initialized. | 3091 // since webkit is not initialized. |
| 3120 DOMStorageContext* context = | 3092 DOMStorageContext* context = |
| 3121 profile_->GetWebKitContext()->dom_storage_context(); | 3093 BrowserContext::GetWebKitContext(profile_.get())->dom_storage_context(); |
| 3122 FilePath lso_path = context->GetLocalStorageFilePath(origin_id); | 3094 FilePath lso_path = context->GetLocalStorageFilePath(origin_id); |
| 3123 EXPECT_TRUE(file_util::CreateDirectory(lso_path.DirName())); | 3095 EXPECT_TRUE(file_util::CreateDirectory(lso_path.DirName())); |
| 3124 EXPECT_EQ(0, file_util::WriteFile(lso_path, NULL, 0)); | 3096 EXPECT_EQ(0, file_util::WriteFile(lso_path, NULL, 0)); |
| 3125 EXPECT_TRUE(file_util::PathExists(lso_path)); | 3097 EXPECT_TRUE(file_util::PathExists(lso_path)); |
| 3126 | 3098 |
| 3127 // Create indexed db. Similarly, it is enough to only simulate this by | 3099 // Create indexed db. Similarly, it is enough to only simulate this by |
| 3128 // creating the directory on the disk. | 3100 // creating the directory on the disk. |
| 3129 IndexedDBContext* idb_context = | 3101 IndexedDBContext* idb_context = |
| 3130 profile_->GetWebKitContext()->indexed_db_context(); | 3102 BrowserContext::GetWebKitContext(profile_.get())->indexed_db_context(); |
| 3131 FilePath idb_path = idb_context->GetIndexedDBFilePath(origin_id); | 3103 FilePath idb_path = idb_context->GetIndexedDBFilePath(origin_id); |
| 3132 EXPECT_TRUE(file_util::CreateDirectory(idb_path)); | 3104 EXPECT_TRUE(file_util::CreateDirectory(idb_path)); |
| 3133 EXPECT_TRUE(file_util::DirectoryExists(idb_path)); | 3105 EXPECT_TRUE(file_util::DirectoryExists(idb_path)); |
| 3134 | 3106 |
| 3135 // Uninstall the extension. | 3107 // Uninstall the extension. |
| 3136 service_->UninstallExtension(good_crx, false, NULL); | 3108 service_->UninstallExtension(good_crx, false, NULL); |
| 3137 loop_.RunAllPending(); | 3109 loop_.RunAllPending(); |
| 3138 | 3110 |
| 3139 // Check that the cookie is gone. | 3111 // Check that the cookie is gone. |
| 3140 cookie_monster->GetAllCookiesForURLAsync( | 3112 cookie_monster->GetAllCookiesForURLAsync( |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3206 EXPECT_TRUE(callback.result_); | 3178 EXPECT_TRUE(callback.result_); |
| 3207 | 3179 |
| 3208 cookie_monster->GetAllCookiesForURLAsync( | 3180 cookie_monster->GetAllCookiesForURLAsync( |
| 3209 origin1, | 3181 origin1, |
| 3210 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, | 3182 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, |
| 3211 base::Unretained(&callback))); | 3183 base::Unretained(&callback))); |
| 3212 loop_.RunAllPending(); | 3184 loop_.RunAllPending(); |
| 3213 EXPECT_EQ(1U, callback.list_.size()); | 3185 EXPECT_EQ(1U, callback.list_.size()); |
| 3214 | 3186 |
| 3215 // Open a database. | 3187 // Open a database. |
| 3216 webkit_database::DatabaseTracker* db_tracker = profile_->GetDatabaseTracker(); | 3188 webkit_database::DatabaseTracker* db_tracker = |
| 3189 BrowserContext::GetDatabaseTracker(profile_.get()); |
| 3217 string16 db_name = UTF8ToUTF16("db"); | 3190 string16 db_name = UTF8ToUTF16("db"); |
| 3218 string16 description = UTF8ToUTF16("db_description"); | 3191 string16 description = UTF8ToUTF16("db_description"); |
| 3219 int64 size; | 3192 int64 size; |
| 3220 db_tracker->DatabaseOpened(origin_id, db_name, description, 1, &size); | 3193 db_tracker->DatabaseOpened(origin_id, db_name, description, 1, &size); |
| 3221 db_tracker->DatabaseClosed(origin_id, db_name); | 3194 db_tracker->DatabaseClosed(origin_id, db_name); |
| 3222 std::vector<webkit_database::OriginInfo> origins; | 3195 std::vector<webkit_database::OriginInfo> origins; |
| 3223 db_tracker->GetAllOriginsInfo(&origins); | 3196 db_tracker->GetAllOriginsInfo(&origins); |
| 3224 EXPECT_EQ(1U, origins.size()); | 3197 EXPECT_EQ(1U, origins.size()); |
| 3225 EXPECT_EQ(origin_id, origins[0].GetOrigin()); | 3198 EXPECT_EQ(origin_id, origins[0].GetOrigin()); |
| 3226 | 3199 |
| 3227 // Create local storage. We only simulate this by creating the backing file | 3200 // Create local storage. We only simulate this by creating the backing file |
| 3228 // since webkit is not initialized. | 3201 // since webkit is not initialized. |
| 3229 DOMStorageContext* context = | 3202 DOMStorageContext* context = |
| 3230 profile_->GetWebKitContext()->dom_storage_context(); | 3203 BrowserContext::GetWebKitContext(profile_.get())->dom_storage_context(); |
| 3231 FilePath lso_path = context->GetLocalStorageFilePath(origin_id); | 3204 FilePath lso_path = context->GetLocalStorageFilePath(origin_id); |
| 3232 EXPECT_TRUE(file_util::CreateDirectory(lso_path.DirName())); | 3205 EXPECT_TRUE(file_util::CreateDirectory(lso_path.DirName())); |
| 3233 EXPECT_EQ(0, file_util::WriteFile(lso_path, NULL, 0)); | 3206 EXPECT_EQ(0, file_util::WriteFile(lso_path, NULL, 0)); |
| 3234 EXPECT_TRUE(file_util::PathExists(lso_path)); | 3207 EXPECT_TRUE(file_util::PathExists(lso_path)); |
| 3235 | 3208 |
| 3236 // Create indexed db. Similarly, it is enough to only simulate this by | 3209 // Create indexed db. Similarly, it is enough to only simulate this by |
| 3237 // creating the directory on the disk. | 3210 // creating the directory on the disk. |
| 3238 IndexedDBContext* idb_context = | 3211 IndexedDBContext* idb_context = |
| 3239 profile_->GetWebKitContext()->indexed_db_context(); | 3212 BrowserContext::GetWebKitContext(profile_.get())->indexed_db_context(); |
| 3240 FilePath idb_path = idb_context->GetIndexedDBFilePath(origin_id); | 3213 FilePath idb_path = idb_context->GetIndexedDBFilePath(origin_id); |
| 3241 EXPECT_TRUE(file_util::CreateDirectory(idb_path)); | 3214 EXPECT_TRUE(file_util::CreateDirectory(idb_path)); |
| 3242 EXPECT_TRUE(file_util::DirectoryExists(idb_path)); | 3215 EXPECT_TRUE(file_util::DirectoryExists(idb_path)); |
| 3243 | 3216 |
| 3244 // Uninstall one of them, unlimited storage should still be granted | 3217 // Uninstall one of them, unlimited storage should still be granted |
| 3245 // to the origin. | 3218 // to the origin. |
| 3246 UninstallExtension(id1, false); | 3219 UninstallExtension(id1, false); |
| 3247 EXPECT_EQ(1u, service_->extensions()->size()); | 3220 EXPECT_EQ(1u, service_->extensions()->size()); |
| 3248 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> | 3221 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> |
| 3249 IsStorageUnlimited(origin1)); | 3222 IsStorageUnlimited(origin1)); |
| (...skipping 1559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4809 ASSERT_FALSE(AddPendingSyncInstall()); | 4782 ASSERT_FALSE(AddPendingSyncInstall()); |
| 4810 | 4783 |
| 4811 // Wait for the external source to install. | 4784 // Wait for the external source to install. |
| 4812 WaitForCrxInstall(crx_path_, INSTALL_NEW); | 4785 WaitForCrxInstall(crx_path_, INSTALL_NEW); |
| 4813 ASSERT_TRUE(IsCrxInstalled()); | 4786 ASSERT_TRUE(IsCrxInstalled()); |
| 4814 | 4787 |
| 4815 // Now that the extension is installed, sync request should fail | 4788 // Now that the extension is installed, sync request should fail |
| 4816 // because the extension is already installed. | 4789 // because the extension is already installed. |
| 4817 ASSERT_FALSE(AddPendingSyncInstall()); | 4790 ASSERT_FALSE(AddPendingSyncInstall()); |
| 4818 } | 4791 } |
| OLD | NEW |