| 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/stringprintf.h" | 5 #include "base/stringprintf.h" |
| 6 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
| 7 #include "chrome/browser/background/background_contents_service.h" | 7 #include "chrome/browser/background/background_contents_service.h" |
| 8 #include "chrome/browser/background/background_contents_service_factory.h" | 8 #include "chrome/browser/background/background_contents_service_factory.h" |
| 9 #include "chrome/browser/extensions/extension_apitest.h" | 9 #include "chrome/browser/extensions/extension_apitest.h" |
| 10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/common/chrome_notification_types.h" |
| 13 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
| 14 #include "chrome/common/extensions/extension.h" | 15 #include "chrome/common/extensions/extension.h" |
| 15 #include "chrome/test/base/ui_test_utils.h" | 16 #include "chrome/test/base/ui_test_utils.h" |
| 17 #include "content/test/test_notification_tracker.h" |
| 16 #include "net/base/mock_host_resolver.h" | 18 #include "net/base/mock_host_resolver.h" |
| 17 | 19 |
| 18 class AppBackgroundPageApiTest : public ExtensionApiTest { | 20 class AppBackgroundPageApiTest : public ExtensionApiTest { |
| 19 public: | 21 public: |
| 20 void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 22 void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 21 ExtensionApiTest::SetUpCommandLine(command_line); | 23 ExtensionApiTest::SetUpCommandLine(command_line); |
| 22 command_line->AppendSwitch(switches::kDisablePopupBlocking); | 24 command_line->AppendSwitch(switches::kDisablePopupBlocking); |
| 23 command_line->AppendSwitch(switches::kAllowHTTPBackgroundPage); | 25 command_line->AppendSwitch(switches::kAllowHTTPBackgroundPage); |
| 24 } | 26 } |
| 25 | 27 |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 ASSERT_TRUE(CreateApp(app_manifest, &app_dir)); | 139 ASSERT_TRUE(CreateApp(app_manifest, &app_dir)); |
| 138 ASSERT_TRUE(LoadExtension(app_dir)); | 140 ASSERT_TRUE(LoadExtension(app_dir)); |
| 139 | 141 |
| 140 const Extension* extension = GetSingleLoadedExtension(); | 142 const Extension* extension = GetSingleLoadedExtension(); |
| 141 ASSERT_TRUE( | 143 ASSERT_TRUE( |
| 142 BackgroundContentsServiceFactory::GetForProfile(browser()->profile())-> | 144 BackgroundContentsServiceFactory::GetForProfile(browser()->profile())-> |
| 143 GetAppBackgroundContents(ASCIIToUTF16(extension->id()))); | 145 GetAppBackgroundContents(ASCIIToUTF16(extension->id()))); |
| 144 } | 146 } |
| 145 | 147 |
| 146 IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, NoJsBackgroundPage) { | 148 IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, NoJsBackgroundPage) { |
| 149 // Make sure that no BackgroundContentses get deleted (a signal that repeated |
| 150 // window.open calls recreate instances, instead of being no-ops). |
| 151 TestNotificationTracker background_deleted_tracker; |
| 152 background_deleted_tracker.ListenFor( |
| 153 chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED, |
| 154 content::Source<Profile>(browser()->profile())); |
| 155 |
| 147 host_resolver()->AddRule("a.com", "127.0.0.1"); | 156 host_resolver()->AddRule("a.com", "127.0.0.1"); |
| 148 ASSERT_TRUE(StartTestServer()); | 157 ASSERT_TRUE(StartTestServer()); |
| 149 | 158 |
| 150 std::string app_manifest = base::StringPrintf( | 159 std::string app_manifest = base::StringPrintf( |
| 151 "{" | 160 "{" |
| 152 " \"name\": \"App\"," | 161 " \"name\": \"App\"," |
| 153 " \"version\": \"0.1\"," | 162 " \"version\": \"0.1\"," |
| 154 " \"manifest_version\": 2," | 163 " \"manifest_version\": 2," |
| 155 " \"app\": {" | 164 " \"app\": {" |
| 156 " \"urls\": [" | 165 " \"urls\": [" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 175 const Extension* extension = GetSingleLoadedExtension(); | 184 const Extension* extension = GetSingleLoadedExtension(); |
| 176 ASSERT_FALSE( | 185 ASSERT_FALSE( |
| 177 BackgroundContentsServiceFactory::GetForProfile(browser()->profile())-> | 186 BackgroundContentsServiceFactory::GetForProfile(browser()->profile())-> |
| 178 GetAppBackgroundContents(ASCIIToUTF16(extension->id()))); | 187 GetAppBackgroundContents(ASCIIToUTF16(extension->id()))); |
| 179 // The test makes sure that window.open returns null. | 188 // The test makes sure that window.open returns null. |
| 180 ASSERT_TRUE(RunExtensionTest("app_background_page/no_js")) << message_; | 189 ASSERT_TRUE(RunExtensionTest("app_background_page/no_js")) << message_; |
| 181 // And after it runs there should be a background page. | 190 // And after it runs there should be a background page. |
| 182 ASSERT_TRUE( | 191 ASSERT_TRUE( |
| 183 BackgroundContentsServiceFactory::GetForProfile(browser()->profile())-> | 192 BackgroundContentsServiceFactory::GetForProfile(browser()->profile())-> |
| 184 GetAppBackgroundContents(ASCIIToUTF16(extension->id()))); | 193 GetAppBackgroundContents(ASCIIToUTF16(extension->id()))); |
| 194 |
| 195 EXPECT_EQ(0u, background_deleted_tracker.size()); |
| 185 } | 196 } |
| 186 | 197 |
| 187 IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, NoJsManifestBackgroundPage) { | 198 IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, NoJsManifestBackgroundPage) { |
| 188 host_resolver()->AddRule("a.com", "127.0.0.1"); | 199 host_resolver()->AddRule("a.com", "127.0.0.1"); |
| 189 ASSERT_TRUE(StartTestServer()); | 200 ASSERT_TRUE(StartTestServer()); |
| 190 | 201 |
| 191 std::string app_manifest = base::StringPrintf( | 202 std::string app_manifest = base::StringPrintf( |
| 192 "{" | 203 "{" |
| 193 " \"name\": \"App\"," | 204 " \"name\": \"App\"," |
| 194 " \"version\": \"0.1\"," | 205 " \"version\": \"0.1\"," |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 " \"permissions\": [\"background\"]" | 316 " \"permissions\": [\"background\"]" |
| 306 "}", | 317 "}", |
| 307 test_server()->host_port_pair().port(), | 318 test_server()->host_port_pair().port(), |
| 308 test_server()->host_port_pair().port()); | 319 test_server()->host_port_pair().port()); |
| 309 | 320 |
| 310 FilePath app_dir; | 321 FilePath app_dir; |
| 311 ASSERT_TRUE(CreateApp(app_manifest, &app_dir)); | 322 ASSERT_TRUE(CreateApp(app_manifest, &app_dir)); |
| 312 ASSERT_TRUE(LoadExtension(app_dir)); | 323 ASSERT_TRUE(LoadExtension(app_dir)); |
| 313 ASSERT_TRUE(RunExtensionTest("app_background_page/bg_open")) << message_; | 324 ASSERT_TRUE(RunExtensionTest("app_background_page/bg_open")) << message_; |
| 314 } | 325 } |
| OLD | NEW |