Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(324)

Side by Side Diff: chrome/browser/extensions/service_worker_apitest.cc

Issue 1432823003: Add a test to cover service worker update codepath when extension is updated (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: test updated Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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").AppendASCII("service_worker.pem");
140 base::FilePath path_v1 = PackExtensionWithOptions(
141 test_data_dir_.AppendASCII("service_worker").AppendASCII("update")
142 .AppendASCII("v1"),
143 scoped_temp_dir.path().AppendASCII("v1.crx"),
144 pem_path, base::FilePath());
145 base::FilePath path_v2 = PackExtensionWithOptions(
146 test_data_dir_.AppendASCII("service_worker").AppendASCII("update")
147 .AppendASCII("v2"),
148 scoped_temp_dir.path().AppendASCII("v2.crx"),
149 pem_path, base::FilePath());
150
151 ExtensionService* service = ExtensionSystem::Get(browser()->profile())->
152 extension_service();
153 const char kId[] = "hfaanndiiilofhfokeanhddpkfffchdi";
154
155 // Install version 1.0 of the extension.
156 ASSERT_TRUE(InstallExtension(path_v1, 1));
157 EXPECT_TRUE(service->GetExtensionById(kId, false) != NULL);
158
159 const char* kScript = "window.testResolver();";
160 EXPECT_EQ("true", ExecuteScriptInBackgroundPage(kId, kScript));
161
162 // Update to version 2.0.
163 EXPECT_TRUE(UpdateExtension(kId, path_v2, 0));
164 EXPECT_TRUE(service->GetExtensionById(kId, false) != NULL);
165
166 EXPECT_EQ("true", ExecuteScriptInBackgroundPage(kId, kScript));
167 }
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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698