OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/bind_helpers.h" |
6 #include "base/strings/stringprintf.h" | 6 #include "base/strings/stringprintf.h" |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "chrome/browser/extensions/extension_apitest.h" | 8 #include "chrome/browser/extensions/extension_apitest.h" |
9 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
10 #include "chrome/browser/notifications/desktop_notification_profile_util.h" | 10 #include "chrome/browser/notifications/desktop_notification_profile_util.h" |
11 #include "chrome/browser/push_messaging/push_messaging_app_identifier.h" | 11 #include "chrome/browser/push_messaging/push_messaging_app_identifier.h" |
12 #include "chrome/browser/push_messaging/push_messaging_service_factory.h" | 12 #include "chrome/browser/push_messaging/push_messaging_service_factory.h" |
13 #include "chrome/browser/push_messaging/push_messaging_service_impl.h" | 13 #include "chrome/browser/push_messaging/push_messaging_service_impl.h" |
14 #include "chrome/browser/services/gcm/fake_gcm_profile_service.h" | 14 #include "chrome/browser/services/gcm/fake_gcm_profile_service.h" |
15 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" | 15 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" |
16 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
17 #include "chrome/test/base/ui_test_utils.h" | 17 #include "chrome/test/base/ui_test_utils.h" |
18 #include "components/version_info/version_info.h" | 18 #include "components/version_info/version_info.h" |
19 #include "content/public/browser/navigation_controller.h" | 19 #include "content/public/browser/navigation_controller.h" |
20 #include "content/public/browser/navigation_entry.h" | 20 #include "content/public/browser/navigation_entry.h" |
21 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
22 #include "content/public/common/content_switches.h" | 22 #include "content/public/common/content_switches.h" |
23 #include "content/public/common/page_type.h" | 23 #include "content/public/common/page_type.h" |
24 #include "content/public/test/background_sync_test_util.h" | 24 #include "content/public/test/background_sync_test_util.h" |
25 #include "content/public/test/browser_test_utils.h" | 25 #include "content/public/test/browser_test_utils.h" |
26 #include "extensions/browser/extension_host.h" | 26 #include "extensions/browser/extension_host.h" |
| 27 #include "extensions/browser/extension_registry.h" |
27 #include "extensions/browser/process_manager.h" | 28 #include "extensions/browser/process_manager.h" |
28 #include "extensions/test/background_page_watcher.h" | 29 #include "extensions/test/background_page_watcher.h" |
29 #include "extensions/test/extension_test_message_listener.h" | 30 #include "extensions/test/extension_test_message_listener.h" |
30 #include "net/test/embedded_test_server/embedded_test_server.h" | 31 #include "net/test/embedded_test_server/embedded_test_server.h" |
31 | 32 |
32 namespace extensions { | 33 namespace extensions { |
33 | 34 |
34 namespace { | 35 namespace { |
35 | 36 |
36 // Pass into ServiceWorkerTest::StartTestFromBackgroundPage to indicate that | 37 // Pass into ServiceWorkerTest::StartTestFromBackgroundPage to indicate that |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 std::string error; | 208 std::string error; |
208 const Extension* extension = | 209 const Extension* extension = |
209 StartTestFromBackgroundPage("register.js", &error); | 210 StartTestFromBackgroundPage("register.js", &error); |
210 EXPECT_EQ( | 211 EXPECT_EQ( |
211 "Failed to register a ServiceWorker: The URL protocol of the current " | 212 "Failed to register a ServiceWorker: The URL protocol of the current " |
212 "origin ('chrome-extension://" + | 213 "origin ('chrome-extension://" + |
213 extension->id() + "') is not supported.", | 214 extension->id() + "') is not supported.", |
214 error); | 215 error); |
215 } | 216 } |
216 | 217 |
| 218 IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, UpdateRefreshesServiceWorker) { |
| 219 base::ScopedTempDir scoped_temp_dir; |
| 220 ASSERT_TRUE(scoped_temp_dir.CreateUniqueTempDir()); |
| 221 base::FilePath pem_path = test_data_dir_.AppendASCII("service_worker") |
| 222 .AppendASCII("update") |
| 223 .AppendASCII("service_worker.pem"); |
| 224 base::FilePath path_v1 = PackExtensionWithOptions( |
| 225 test_data_dir_.AppendASCII("service_worker") |
| 226 .AppendASCII("update") |
| 227 .AppendASCII("v1"), |
| 228 scoped_temp_dir.path().AppendASCII("v1.crx"), pem_path, base::FilePath()); |
| 229 base::FilePath path_v2 = PackExtensionWithOptions( |
| 230 test_data_dir_.AppendASCII("service_worker") |
| 231 .AppendASCII("update") |
| 232 .AppendASCII("v2"), |
| 233 scoped_temp_dir.path().AppendASCII("v2.crx"), pem_path, base::FilePath()); |
| 234 const char* kId = "hfaanndiiilofhfokeanhddpkfffchdi"; |
| 235 |
| 236 ExtensionTestMessageListener listener_v1("Pong from version 1", false); |
| 237 listener_v1.set_failure_message("FAILURE_V1"); |
| 238 // Install version 1.0 of the extension. |
| 239 ASSERT_TRUE(InstallExtension(path_v1, 1)); |
| 240 EXPECT_TRUE(extensions::ExtensionRegistry::Get(profile()) |
| 241 ->enabled_extensions() |
| 242 .GetByID(kId)); |
| 243 EXPECT_TRUE(listener_v1.WaitUntilSatisfied()); |
| 244 |
| 245 ExtensionTestMessageListener listener_v2("Pong from version 2", false); |
| 246 listener_v2.set_failure_message("FAILURE_V2"); |
| 247 |
| 248 // Update to version 2.0. |
| 249 EXPECT_TRUE(UpdateExtension(kId, path_v2, 0)); |
| 250 EXPECT_TRUE(extensions::ExtensionRegistry::Get(profile()) |
| 251 ->enabled_extensions() |
| 252 .GetByID(kId)); |
| 253 EXPECT_TRUE(listener_v2.WaitUntilSatisfied()); |
| 254 } |
| 255 |
217 IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, FetchArbitraryPaths) { | 256 IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, FetchArbitraryPaths) { |
218 const Extension* extension = | 257 const Extension* extension = |
219 StartTestFromBackgroundPage("fetch.js", kExpectSuccess); | 258 StartTestFromBackgroundPage("fetch.js", kExpectSuccess); |
220 | 259 |
221 // Open some arbirary paths. Their contents should be what the service worker | 260 // Open some arbirary paths. Their contents should be what the service worker |
222 // responds with, which in this case is the path of the fetch. | 261 // responds with, which in this case is the path of the fetch. |
223 EXPECT_EQ( | 262 EXPECT_EQ( |
224 "Caught a fetch for /index.html", | 263 "Caught a fetch for /index.html", |
225 NavigateAndExtractInnerText(extension->GetResourceURL("index.html"))); | 264 NavigateAndExtractInnerText(extension->GetResourceURL("index.html"))); |
226 EXPECT_EQ("Caught a fetch for /path/to/other.html", | 265 EXPECT_EQ("Caught a fetch for /path/to/other.html", |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 push_message_listener.set_failure_message("FAIL"); | 540 push_message_listener.set_failure_message("FAIL"); |
502 gcm::IncomingMessage message; | 541 gcm::IncomingMessage message; |
503 message.sender_id = "1234567890"; | 542 message.sender_id = "1234567890"; |
504 message.raw_data = "testdata"; | 543 message.raw_data = "testdata"; |
505 message.decrypted = true; | 544 message.decrypted = true; |
506 push_service()->OnMessage(app_identifier.app_id(), message); | 545 push_service()->OnMessage(app_identifier.app_id(), message); |
507 EXPECT_TRUE(push_message_listener.WaitUntilSatisfied()); | 546 EXPECT_TRUE(push_message_listener.WaitUntilSatisfied()); |
508 } | 547 } |
509 | 548 |
510 } // namespace extensions | 549 } // namespace extensions |
OLD | NEW |