| 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" |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 FilePath app_dir; | 136 FilePath app_dir; |
| 137 ASSERT_TRUE(CreateApp(app_manifest, &app_dir)); | 137 ASSERT_TRUE(CreateApp(app_manifest, &app_dir)); |
| 138 ASSERT_TRUE(LoadExtension(app_dir)); | 138 ASSERT_TRUE(LoadExtension(app_dir)); |
| 139 | 139 |
| 140 const Extension* extension = GetSingleLoadedExtension(); | 140 const Extension* extension = GetSingleLoadedExtension(); |
| 141 ASSERT_TRUE( | 141 ASSERT_TRUE( |
| 142 BackgroundContentsServiceFactory::GetForProfile(browser()->profile())-> | 142 BackgroundContentsServiceFactory::GetForProfile(browser()->profile())-> |
| 143 GetAppBackgroundContents(ASCIIToUTF16(extension->id()))); | 143 GetAppBackgroundContents(ASCIIToUTF16(extension->id()))); |
| 144 } | 144 } |
| 145 | 145 |
| 146 IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, NoJsBackgroundPage) { |
| 147 host_resolver()->AddRule("a.com", "127.0.0.1"); |
| 148 ASSERT_TRUE(StartTestServer()); |
| 149 |
| 150 std::string app_manifest = base::StringPrintf( |
| 151 "{" |
| 152 " \"name\": \"App\"," |
| 153 " \"version\": \"0.1\"," |
| 154 " \"manifest_version\": 2," |
| 155 " \"app\": {" |
| 156 " \"urls\": [" |
| 157 " \"http://a.com/\"" |
| 158 " ]," |
| 159 " \"launch\": {" |
| 160 " \"web_url\": \"http://a.com:%d/test.html\"" |
| 161 " }" |
| 162 " }," |
| 163 " \"permissions\": [\"background\"]," |
| 164 " \"background\": {" |
| 165 " \"allow_js_access\": false" |
| 166 " }" |
| 167 "}", |
| 168 test_server()->host_port_pair().port()); |
| 169 |
| 170 FilePath app_dir; |
| 171 ASSERT_TRUE(CreateApp(app_manifest, &app_dir)); |
| 172 ASSERT_TRUE(LoadExtension(app_dir)); |
| 173 |
| 174 // There isn't a background page loaded initially. |
| 175 const Extension* extension = GetSingleLoadedExtension(); |
| 176 ASSERT_FALSE( |
| 177 BackgroundContentsServiceFactory::GetForProfile(browser()->profile())-> |
| 178 GetAppBackgroundContents(ASCIIToUTF16(extension->id()))); |
| 179 // The test makes sure that window.open returns null. |
| 180 ASSERT_TRUE(RunExtensionTest("app_background_page/no_js")) << message_; |
| 181 // And after it runs there should be a background page. |
| 182 ASSERT_TRUE( |
| 183 BackgroundContentsServiceFactory::GetForProfile(browser()->profile())-> |
| 184 GetAppBackgroundContents(ASCIIToUTF16(extension->id()))); |
| 185 } |
| 186 |
| 146 IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, NoJsManifestBackgroundPage) { | 187 IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, NoJsManifestBackgroundPage) { |
| 147 host_resolver()->AddRule("a.com", "127.0.0.1"); | 188 host_resolver()->AddRule("a.com", "127.0.0.1"); |
| 148 ASSERT_TRUE(StartTestServer()); | 189 ASSERT_TRUE(StartTestServer()); |
| 149 | 190 |
| 150 std::string app_manifest = base::StringPrintf( | 191 std::string app_manifest = base::StringPrintf( |
| 151 "{" | 192 "{" |
| 152 " \"name\": \"App\"," | 193 " \"name\": \"App\"," |
| 153 " \"version\": \"0.1\"," | 194 " \"version\": \"0.1\"," |
| 154 " \"manifest_version\": 2," | 195 " \"manifest_version\": 2," |
| 155 " \"app\": {" | 196 " \"app\": {" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 171 | 212 |
| 172 FilePath app_dir; | 213 FilePath app_dir; |
| 173 ASSERT_TRUE(CreateApp(app_manifest, &app_dir)); | 214 ASSERT_TRUE(CreateApp(app_manifest, &app_dir)); |
| 174 ASSERT_TRUE(LoadExtension(app_dir)); | 215 ASSERT_TRUE(LoadExtension(app_dir)); |
| 175 | 216 |
| 176 // The background page should load, but window.open should return null. | 217 // The background page should load, but window.open should return null. |
| 177 const Extension* extension = GetSingleLoadedExtension(); | 218 const Extension* extension = GetSingleLoadedExtension(); |
| 178 ASSERT_TRUE( | 219 ASSERT_TRUE( |
| 179 BackgroundContentsServiceFactory::GetForProfile(browser()->profile())-> | 220 BackgroundContentsServiceFactory::GetForProfile(browser()->profile())-> |
| 180 GetAppBackgroundContents(ASCIIToUTF16(extension->id()))); | 221 GetAppBackgroundContents(ASCIIToUTF16(extension->id()))); |
| 181 ASSERT_TRUE(RunExtensionTest("app_background_page/no_js")) << message_; | 222 ASSERT_TRUE(RunExtensionTest("app_background_page/no_js_manifest")) << |
| 223 message_; |
| 182 } | 224 } |
| 183 | 225 |
| 184 IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, OpenTwoBackgroundPages) { | 226 IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, OpenTwoBackgroundPages) { |
| 185 host_resolver()->AddRule("a.com", "127.0.0.1"); | 227 host_resolver()->AddRule("a.com", "127.0.0.1"); |
| 186 ASSERT_TRUE(StartTestServer()); | 228 ASSERT_TRUE(StartTestServer()); |
| 187 | 229 |
| 188 std::string app_manifest = base::StringPrintf( | 230 std::string app_manifest = base::StringPrintf( |
| 189 "{" | 231 "{" |
| 190 " \"name\": \"App\"," | 232 " \"name\": \"App\"," |
| 191 " \"version\": \"0.1\"," | 233 " \"version\": \"0.1\"," |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 " \"permissions\": [\"background\"]" | 305 " \"permissions\": [\"background\"]" |
| 264 "}", | 306 "}", |
| 265 test_server()->host_port_pair().port(), | 307 test_server()->host_port_pair().port(), |
| 266 test_server()->host_port_pair().port()); | 308 test_server()->host_port_pair().port()); |
| 267 | 309 |
| 268 FilePath app_dir; | 310 FilePath app_dir; |
| 269 ASSERT_TRUE(CreateApp(app_manifest, &app_dir)); | 311 ASSERT_TRUE(CreateApp(app_manifest, &app_dir)); |
| 270 ASSERT_TRUE(LoadExtension(app_dir)); | 312 ASSERT_TRUE(LoadExtension(app_dir)); |
| 271 ASSERT_TRUE(RunExtensionTest("app_background_page/bg_open")) << message_; | 313 ASSERT_TRUE(RunExtensionTest("app_background_page/bg_open")) << message_; |
| 272 } | 314 } |
| OLD | NEW |