Chromium Code Reviews| 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 "chrome/browser/extensions/extension_apitest.h" | 7 #include "chrome/browser/extensions/extension_apitest.h" |
| 8 #include "chrome/browser/extensions/extension_service.h" | 8 #include "chrome/browser/extensions/extension_service.h" |
| 9 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 9 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 10 #include "chrome/test/base/ui_test_utils.h" | 10 #include "chrome/test/base/ui_test_utils.h" |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 125 std::string error; | 125 std::string error; |
| 126 const Extension* extension = | 126 const Extension* extension = |
| 127 StartTestFromBackgroundPage("register.js", &error); | 127 StartTestFromBackgroundPage("register.js", &error); |
| 128 EXPECT_EQ( | 128 EXPECT_EQ( |
| 129 "Failed to register a ServiceWorker: The URL protocol of the current " | 129 "Failed to register a ServiceWorker: The URL protocol of the current " |
| 130 "origin ('chrome-extension://" + | 130 "origin ('chrome-extension://" + |
| 131 extension->id() + "') is not supported.", | 131 extension->id() + "') is not supported.", |
| 132 error); | 132 error); |
| 133 } | 133 } |
| 134 | 134 |
| 135 IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, UpdateRefreshesServiceWorker) { | |
| 136 base::ScopedTempDir scoped_temp_dir; | |
| 137 ASSERT_TRUE(scoped_temp_dir.CreateUniqueTempDir()); | |
| 138 base::FilePath pem_path = test_data_dir_.AppendASCII("service_worker") | |
| 139 .AppendASCII("update") | |
| 140 .AppendASCII("service_worker.pem"); | |
| 141 base::FilePath path_v1 = PackExtensionWithOptions( | |
| 142 test_data_dir_.AppendASCII("service_worker") | |
| 143 .AppendASCII("update") | |
| 144 .AppendASCII("v1"), | |
| 145 scoped_temp_dir.path().AppendASCII("v1.crx"), pem_path, base::FilePath()); | |
| 146 base::FilePath path_v2 = PackExtensionWithOptions( | |
| 147 test_data_dir_.AppendASCII("service_worker") | |
| 148 .AppendASCII("update") | |
| 149 .AppendASCII("v2"), | |
| 150 scoped_temp_dir.path().AppendASCII("v2.crx"), pem_path, base::FilePath()); | |
| 151 | |
| 152 ExtensionService* service = | |
|
Devlin
2015/11/11 17:10:29
nit: there's an extension_service() accessor on Ex
lazyboy
2015/11/11 22:32:23
Not needed anymore.
| |
| 153 ExtensionSystem::Get(browser()->profile())->extension_service(); | |
| 154 const char kId[] = "hfaanndiiilofhfokeanhddpkfffchdi"; | |
| 155 | |
| 156 // Install version 1.0 of the extension. | |
| 157 ASSERT_TRUE(InstallExtension(path_v1, 1)); | |
| 158 EXPECT_TRUE(service->GetExtensionById(kId, false) != NULL); | |
|
Devlin
2015/11/11 17:10:29
nit: GetExtensionById is deprecated. Prefer Extens
lazyboy
2015/11/11 22:32:23
Done.
| |
| 159 | |
| 160 const char* kScript = "window.testResolver();"; | |
|
Devlin
2015/11/11 17:10:29
nitty nit: pick one between const char[] (line 154
lazyboy
2015/11/11 22:32:23
Done.
| |
| 161 EXPECT_EQ("true", ExecuteScriptInBackgroundPage(kId, kScript)); | |
|
Devlin
2015/11/11 17:10:29
This is an interesting pattern. Usually we would
lazyboy
2015/11/11 22:32:23
Changed to compare with the actual received messag
| |
| 162 | |
| 163 // Update to version 2.0. | |
| 164 EXPECT_TRUE(UpdateExtension(kId, path_v2, 0)); | |
| 165 EXPECT_TRUE(service->GetExtensionById(kId, false) != NULL); | |
| 166 | |
| 167 EXPECT_EQ("true", ExecuteScriptInBackgroundPage(kId, kScript)); | |
| 168 } | |
| 169 | |
| 135 IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, FetchArbitraryPaths) { | 170 IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, FetchArbitraryPaths) { |
| 136 const Extension* extension = | 171 const Extension* extension = |
| 137 StartTestFromBackgroundPage("fetch.js", kExpectSuccess); | 172 StartTestFromBackgroundPage("fetch.js", kExpectSuccess); |
| 138 | 173 |
| 139 // Open some arbirary paths. Their contents should be what the service worker | 174 // Open some arbirary paths. Their contents should be what the service worker |
| 140 // responds with, which in this case is the path of the fetch. | 175 // responds with, which in this case is the path of the fetch. |
| 141 EXPECT_EQ( | 176 EXPECT_EQ( |
| 142 "Caught a fetch for /index.html", | 177 "Caught a fetch for /index.html", |
| 143 NavigateAndExtractInnerText(extension->GetResourceURL("index.html"))); | 178 NavigateAndExtractInnerText(extension->GetResourceURL("index.html"))); |
| 144 EXPECT_EQ("Caught a fetch for /path/to/other.html", | 179 EXPECT_EQ("Caught a fetch for /path/to/other.html", |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 331 IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, | 366 IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, |
| 332 GetBackgroundClientFailsWithNoBackgroundPage) { | 367 GetBackgroundClientFailsWithNoBackgroundPage) { |
| 333 // This extension doesn't have a background page, only a tab at page.html. | 368 // This extension doesn't have a background page, only a tab at page.html. |
| 334 // The service worker it registers tries to call getBackgroundClient() and | 369 // The service worker it registers tries to call getBackgroundClient() and |
| 335 // should fail. | 370 // should fail. |
| 336 // Note that this also tests that service workers can be registered from tabs. | 371 // Note that this also tests that service workers can be registered from tabs. |
| 337 EXPECT_TRUE(RunExtensionSubtest("service_worker/no_background", "page.html")); | 372 EXPECT_TRUE(RunExtensionSubtest("service_worker/no_background", "page.html")); |
| 338 } | 373 } |
| 339 | 374 |
| 340 } // namespace extensions | 375 } // namespace extensions |
| OLD | NEW |