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 "base/bind_helpers.h" |
5 #include "base/location.h" | 6 #include "base/location.h" |
| 7 #include "base/memory/scoped_ptr.h" |
6 #include "base/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
7 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
8 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
9 #include "build/build_config.h" | 11 #include "build/build_config.h" |
10 #include "chrome/browser/browser_process.h" | |
11 #include "chrome/browser/chrome_notification_types.h" | 12 #include "chrome/browser/chrome_notification_types.h" |
12 #include "chrome/browser/content_settings/cookie_settings_factory.h" | 13 #include "chrome/browser/content_settings/cookie_settings_factory.h" |
13 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 14 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
14 #include "chrome/browser/extensions/api/content_settings/content_settings_api.h" | 15 #include "chrome/browser/extensions/api/content_settings/content_settings_api.h" |
15 #include "chrome/browser/extensions/extension_apitest.h" | 16 #include "chrome/browser/extensions/extension_apitest.h" |
| 17 #include "chrome/browser/lifetime/keep_alive_types.h" |
| 18 #include "chrome/browser/lifetime/scoped_keep_alive.h" |
16 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/ui/browser.h" | 20 #include "chrome/browser/ui/browser.h" |
18 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
19 #include "components/content_settings/core/browser/cookie_settings.h" | 22 #include "components/content_settings/core/browser/cookie_settings.h" |
20 #include "components/content_settings/core/browser/host_content_settings_map.h" | 23 #include "components/content_settings/core/browser/host_content_settings_map.h" |
21 #include "components/prefs/pref_service.h" | 24 #include "components/prefs/pref_service.h" |
22 #include "content/public/browser/notification_service.h" | 25 #include "content/public/browser/notification_service.h" |
23 #include "content/public/browser/plugin_service.h" | 26 #include "content/public/browser/plugin_service.h" |
24 #include "content/public/common/content_switches.h" | 27 #include "content/public/common/content_switches.h" |
25 #include "content/public/common/webplugininfo.h" | 28 #include "content/public/common/webplugininfo.h" |
26 #include "content/public/test/test_utils.h" | 29 #include "content/public/test/test_utils.h" |
27 #include "extensions/browser/extension_registry.h" | 30 #include "extensions/browser/extension_registry.h" |
28 #include "extensions/browser/test_extension_registry_observer.h" | 31 #include "extensions/browser/test_extension_registry_observer.h" |
29 | 32 |
30 namespace { | |
31 | |
32 void ReleaseBrowserProcessModule() { | |
33 g_browser_process->ReleaseModule(); | |
34 } | |
35 | |
36 } // namespace | |
37 | |
38 namespace extensions { | 33 namespace extensions { |
39 | 34 |
40 class ExtensionContentSettingsApiTest : public ExtensionApiTest { | 35 class ExtensionContentSettingsApiTest : public ExtensionApiTest { |
41 public: | 36 public: |
42 ExtensionContentSettingsApiTest() : profile_(NULL) {} | 37 ExtensionContentSettingsApiTest() : profile_(NULL) {} |
43 | 38 |
44 void SetUpCommandLine(base::CommandLine* command_line) override { | 39 void SetUpCommandLine(base::CommandLine* command_line) override { |
45 ExtensionApiTest::SetUpCommandLine(command_line); | 40 ExtensionApiTest::SetUpCommandLine(command_line); |
46 command_line->AppendSwitch(switches::kDisablePluginsDiscovery); | 41 command_line->AppendSwitch(switches::kDisablePluginsDiscovery); |
47 } | 42 } |
48 | 43 |
49 void SetUpOnMainThread() override { | 44 void SetUpOnMainThread() override { |
50 ExtensionApiTest::SetUpOnMainThread(); | 45 ExtensionApiTest::SetUpOnMainThread(); |
51 | 46 |
52 // The browser might get closed later (and therefore be destroyed), so we | 47 // The browser might get closed later (and therefore be destroyed), so we |
53 // save the profile. | 48 // save the profile. |
54 profile_ = browser()->profile(); | 49 profile_ = browser()->profile(); |
55 | 50 |
56 // Closing the last browser window also releases a module reference. Make | 51 // Closing the last browser window also releases a KeepAlive. Make |
57 // sure it's not the last one, so the message loop doesn't quit | 52 // sure it's not the last one, so the message loop doesn't quit |
58 // unexpectedly. | 53 // unexpectedly. |
59 g_browser_process->AddRefModule(); | 54 keep_alive_.reset(new ScopedKeepAlive(KeepAliveOrigin::BROWSER, |
| 55 KeepAliveRestartOption::DISABLED)); |
60 } | 56 } |
61 | 57 |
62 void TearDownOnMainThread() override { | 58 void TearDownOnMainThread() override { |
63 // ReleaseBrowserProcessModule() needs to be called in a message loop, so we | 59 // BrowserProcess::Shutdown() needs to be called in a message loop, so we |
64 // post a task to do it, then run the message loop. | 60 // post a task to release the keep alive, then run the message loop. |
65 base::ThreadTaskRunnerHandle::Get()->PostTask( | 61 base::ThreadTaskRunnerHandle::Get()->PostTask( |
66 FROM_HERE, base::Bind(&ReleaseBrowserProcessModule)); | 62 FROM_HERE, base::Bind(&scoped_ptr<ScopedKeepAlive>::reset, |
| 63 base::Unretained(&keep_alive_), nullptr)); |
67 content::RunAllPendingInMessageLoop(); | 64 content::RunAllPendingInMessageLoop(); |
68 | 65 |
69 ExtensionApiTest::TearDownOnMainThread(); | 66 ExtensionApiTest::TearDownOnMainThread(); |
70 } | 67 } |
71 | 68 |
72 protected: | 69 protected: |
73 void CheckContentSettingsSet() { | 70 void CheckContentSettingsSet() { |
74 HostContentSettingsMap* map = | 71 HostContentSettingsMap* map = |
75 HostContentSettingsMapFactory::GetForProfile(profile_); | 72 HostContentSettingsMapFactory::GetForProfile(profile_); |
76 content_settings::CookieSettings* cookie_settings = | 73 content_settings::CookieSettings* cookie_settings = |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 map->GetContentSetting( | 230 map->GetContentSetting( |
234 url, url, CONTENT_SETTINGS_TYPE_PPAPI_BROKER, std::string())); | 231 url, url, CONTENT_SETTINGS_TYPE_PPAPI_BROKER, std::string())); |
235 EXPECT_EQ(CONTENT_SETTING_ASK, | 232 EXPECT_EQ(CONTENT_SETTING_ASK, |
236 map->GetContentSetting( | 233 map->GetContentSetting( |
237 url, url, CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, | 234 url, url, CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, |
238 std::string())); | 235 std::string())); |
239 } | 236 } |
240 | 237 |
241 private: | 238 private: |
242 Profile* profile_; | 239 Profile* profile_; |
| 240 scoped_ptr<ScopedKeepAlive> keep_alive_; |
243 }; | 241 }; |
244 | 242 |
245 // http://crbug.com/177163 | 243 // http://crbug.com/177163 |
246 #if defined(OS_WIN) && !defined(NDEBUG) | 244 #if defined(OS_WIN) && !defined(NDEBUG) |
247 #define MAYBE_Standard DISABLED_Standard | 245 #define MAYBE_Standard DISABLED_Standard |
248 #else | 246 #else |
249 #define MAYBE_Standard Standard | 247 #define MAYBE_Standard Standard |
250 #endif | 248 #endif |
251 IN_PROC_BROWSER_TEST_F(ExtensionContentSettingsApiTest, MAYBE_Standard) { | 249 IN_PROC_BROWSER_TEST_F(ExtensionContentSettingsApiTest, MAYBE_Standard) { |
252 CheckContentSettingsDefault(); | 250 CheckContentSettingsDefault(); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 << message_; | 297 << message_; |
300 } | 298 } |
301 | 299 |
302 IN_PROC_BROWSER_TEST_F(ExtensionContentSettingsApiTest, | 300 IN_PROC_BROWSER_TEST_F(ExtensionContentSettingsApiTest, |
303 UnsupportedDefaultSettings) { | 301 UnsupportedDefaultSettings) { |
304 const char kExtensionPath[] = "content_settings/unsupporteddefaultsettings"; | 302 const char kExtensionPath[] = "content_settings/unsupporteddefaultsettings"; |
305 EXPECT_TRUE(RunExtensionSubtest(kExtensionPath, "test.html")) << message_; | 303 EXPECT_TRUE(RunExtensionSubtest(kExtensionPath, "test.html")) << message_; |
306 } | 304 } |
307 | 305 |
308 } // namespace extensions | 306 } // namespace extensions |
OLD | NEW |