OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 |
11 #include "base/at_exit.h" | 11 #include "base/at_exit.h" |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
15 #include "base/file_util.h" | 15 #include "base/file_util.h" |
16 #include "base/files/file_enumerator.h" | 16 #include "base/files/file_enumerator.h" |
17 #include "base/files/scoped_temp_dir.h" | 17 #include "base/files/scoped_temp_dir.h" |
18 #include "base/json/json_file_value_serializer.h" | 18 #include "base/json/json_file_value_serializer.h" |
19 #include "base/json/json_reader.h" | 19 #include "base/json/json_reader.h" |
20 #include "base/json/json_string_value_serializer.h" | 20 #include "base/json/json_string_value_serializer.h" |
21 #include "base/memory/scoped_ptr.h" | 21 #include "base/memory/scoped_ptr.h" |
22 #include "base/memory/weak_ptr.h" | 22 #include "base/memory/weak_ptr.h" |
23 #include "base/message_loop/message_loop.h" | 23 #include "base/message_loop/message_loop.h" |
24 #include "base/path_service.h" | 24 #include "base/path_service.h" |
| 25 #include "base/run_loop.h" |
25 #include "base/stl_util.h" | 26 #include "base/stl_util.h" |
26 #include "base/strings/string16.h" | 27 #include "base/strings/string16.h" |
27 #include "base/strings/string_number_conversions.h" | 28 #include "base/strings/string_number_conversions.h" |
28 #include "base/strings/string_util.h" | 29 #include "base/strings/string_util.h" |
29 #include "base/strings/utf_string_conversions.h" | 30 #include "base/strings/utf_string_conversions.h" |
30 #include "base/version.h" | 31 #include "base/version.h" |
31 #include "chrome/browser/browser_process.h" | 32 #include "chrome/browser/browser_process.h" |
32 #include "chrome/browser/chrome_notification_types.h" | 33 #include "chrome/browser/chrome_notification_types.h" |
33 #include "chrome/browser/extensions/app_sync_data.h" | 34 #include "chrome/browser/extensions/app_sync_data.h" |
34 #include "chrome/browser/extensions/component_loader.h" | 35 #include "chrome/browser/extensions/component_loader.h" |
(...skipping 4058 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4093 // Load a test extension. | 4094 // Load a test extension. |
4094 base::FilePath path = data_dir_; | 4095 base::FilePath path = data_dir_; |
4095 path = path.AppendASCII("good.crx"); | 4096 path = path.AppendASCII("good.crx"); |
4096 const Extension* extension = InstallCRX(path, INSTALL_NEW); | 4097 const Extension* extension = InstallCRX(path, INSTALL_NEW); |
4097 ASSERT_TRUE(extension); | 4098 ASSERT_TRUE(extension); |
4098 GURL ext_url(extension->url()); | 4099 GURL ext_url(extension->url()); |
4099 std::string origin_id = webkit_database::GetIdentifierFromOrigin(ext_url); | 4100 std::string origin_id = webkit_database::GetIdentifierFromOrigin(ext_url); |
4100 | 4101 |
4101 // Set a cookie for the extension. | 4102 // Set a cookie for the extension. |
4102 net::CookieMonster* cookie_monster = | 4103 net::CookieMonster* cookie_monster = |
4103 profile_->GetRequestContextForExtensions()->GetURLRequestContext()-> | 4104 content::GetCookieStoreForScheme( |
4104 cookie_store()->GetCookieMonster(); | 4105 BrowserContext::GetDefaultStoragePartition(profile_.get()), |
| 4106 ext_url.scheme())->GetCookieMonster(); |
4105 ASSERT_TRUE(cookie_monster); | 4107 ASSERT_TRUE(cookie_monster); |
4106 net::CookieOptions options; | 4108 net::CookieOptions options; |
4107 cookie_monster->SetCookieWithOptionsAsync( | 4109 cookie_monster->SetCookieWithOptionsAsync( |
4108 ext_url, "dummy=value", options, | 4110 ext_url, "dummy=value", options, |
4109 base::Bind(&ExtensionCookieCallback::SetCookieCallback, | 4111 base::Bind(&ExtensionCookieCallback::SetCookieCallback, |
4110 base::Unretained(&callback))); | 4112 base::Unretained(&callback))); |
4111 base::RunLoop().RunUntilIdle(); | 4113 base::RunLoop().RunUntilIdle(); |
4112 EXPECT_TRUE(callback.result_); | 4114 EXPECT_TRUE(callback.result_); |
4113 | 4115 |
4114 cookie_monster->GetAllCookiesForURLAsync( | 4116 cookie_monster->GetAllCookiesForURLAsync( |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4209 EXPECT_TRUE(extension->web_extent().MatchesURL( | 4211 EXPECT_TRUE(extension->web_extent().MatchesURL( |
4210 extensions::AppLaunchInfo::GetFullLaunchURL(extension))); | 4212 extensions::AppLaunchInfo::GetFullLaunchURL(extension))); |
4211 const GURL origin2( | 4213 const GURL origin2( |
4212 extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin()); | 4214 extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin()); |
4213 EXPECT_EQ(origin1, origin2); | 4215 EXPECT_EQ(origin1, origin2); |
4214 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> | 4216 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> |
4215 IsStorageUnlimited(origin2)); | 4217 IsStorageUnlimited(origin2)); |
4216 | 4218 |
4217 // Set a cookie for the extension. | 4219 // Set a cookie for the extension. |
4218 net::CookieMonster* cookie_monster = | 4220 net::CookieMonster* cookie_monster = |
4219 profile_->GetRequestContext()->GetURLRequestContext()-> | 4221 content::GetCookieStoreForScheme( |
4220 cookie_store()->GetCookieMonster(); | 4222 BrowserContext::GetDefaultStoragePartition(profile_.get()), |
| 4223 origin1.scheme())->GetCookieMonster(); |
4221 ASSERT_TRUE(cookie_monster); | 4224 ASSERT_TRUE(cookie_monster); |
4222 net::CookieOptions options; | 4225 net::CookieOptions options; |
4223 cookie_monster->SetCookieWithOptionsAsync( | 4226 cookie_monster->SetCookieWithOptionsAsync( |
4224 origin1, "dummy=value", options, | 4227 origin1, "dummy=value", options, |
4225 base::Bind(&ExtensionCookieCallback::SetCookieCallback, | 4228 base::Bind(&ExtensionCookieCallback::SetCookieCallback, |
4226 base::Unretained(&callback))); | 4229 base::Unretained(&callback))); |
4227 base::RunLoop().RunUntilIdle(); | 4230 base::RunLoop().RunUntilIdle(); |
4228 EXPECT_TRUE(callback.result_); | 4231 EXPECT_TRUE(callback.result_); |
4229 | 4232 |
4230 cookie_monster->GetAllCookiesForURLAsync( | 4233 cookie_monster->GetAllCookiesForURLAsync( |
(...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4923 TEST(ExtensionServiceTestSimple, Enabledness) { | 4926 TEST(ExtensionServiceTestSimple, Enabledness) { |
4924 // Make sure the PluginService singleton is destroyed at the end of the test. | 4927 // Make sure the PluginService singleton is destroyed at the end of the test. |
4925 base::ShadowingAtExitManager at_exit_manager; | 4928 base::ShadowingAtExitManager at_exit_manager; |
4926 #if defined(ENABLE_PLUGINS) | 4929 #if defined(ENABLE_PLUGINS) |
4927 content::PluginService::GetInstance()->Init(); | 4930 content::PluginService::GetInstance()->Init(); |
4928 content::PluginService::GetInstance()->DisablePluginsDiscoveryForTesting(); | 4931 content::PluginService::GetInstance()->DisablePluginsDiscoveryForTesting(); |
4929 #endif | 4932 #endif |
4930 | 4933 |
4931 ExtensionErrorReporter::Init(false); // no noisy errors | 4934 ExtensionErrorReporter::Init(false); // no noisy errors |
4932 ExtensionsReadyRecorder recorder; | 4935 ExtensionsReadyRecorder recorder; |
| 4936 content::TestBrowserThreadBundle thread_bundle; |
4933 scoped_ptr<TestingProfile> profile(new TestingProfile()); | 4937 scoped_ptr<TestingProfile> profile(new TestingProfile()); |
4934 content::TestBrowserThreadBundle thread_bundle_; | |
4935 #if defined OS_CHROMEOS | 4938 #if defined OS_CHROMEOS |
4936 chromeos::ScopedTestDeviceSettingsService device_settings_service; | 4939 chromeos::ScopedTestDeviceSettingsService device_settings_service; |
4937 chromeos::ScopedTestCrosSettings cros_settings; | 4940 chromeos::ScopedTestCrosSettings cros_settings; |
4938 scoped_ptr<chromeos::ScopedTestUserManager> user_manager( | 4941 scoped_ptr<chromeos::ScopedTestUserManager> user_manager( |
4939 new chromeos::ScopedTestUserManager); | 4942 new chromeos::ScopedTestUserManager); |
4940 #endif | 4943 #endif |
4941 scoped_ptr<CommandLine> command_line; | 4944 scoped_ptr<CommandLine> command_line; |
4942 base::FilePath install_dir = profile->GetPath() | 4945 base::FilePath install_dir = profile->GetPath() |
4943 .AppendASCII(extensions::kInstallDirectoryName); | 4946 .AppendASCII(extensions::kInstallDirectoryName); |
4944 | 4947 |
(...skipping 1433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6378 EXPECT_TRUE(notifications.CheckNotifications( | 6381 EXPECT_TRUE(notifications.CheckNotifications( |
6379 chrome::NOTIFICATION_EXTENSION_INSTALLED)); | 6382 chrome::NOTIFICATION_EXTENSION_INSTALLED)); |
6380 | 6383 |
6381 EXPECT_TRUE(service_->GetInstalledExtension(id)); | 6384 EXPECT_TRUE(service_->GetInstalledExtension(id)); |
6382 EXPECT_FALSE(service_->extensions()->Contains(id)); | 6385 EXPECT_FALSE(service_->extensions()->Contains(id)); |
6383 EXPECT_TRUE(service_->blacklisted_extensions()->Contains(id)); | 6386 EXPECT_TRUE(service_->blacklisted_extensions()->Contains(id)); |
6384 EXPECT_TRUE(service_->extension_prefs()->IsExtensionBlacklisted(id)); | 6387 EXPECT_TRUE(service_->extension_prefs()->IsExtensionBlacklisted(id)); |
6385 EXPECT_TRUE( | 6388 EXPECT_TRUE( |
6386 service_->extension_prefs()->IsBlacklistedExtensionAcknowledged(id)); | 6389 service_->extension_prefs()->IsBlacklistedExtensionAcknowledged(id)); |
6387 } | 6390 } |
OLD | NEW |