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

Side by Side Diff: chrome/browser/chrome_service_worker_browsertest.cc

Issue 2158253002: Use WebContents::GetManifest in ServiceWorker FetchTest instead of RequestAppBannerFromDevTools (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 // This file tests that Service Workers (a Content feature) work in the Chromium 5 // This file tests that Service Workers (a Content feature) work in the Chromium
6 // embedder. 6 // embedder.
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 RequestString("https://www.example.com/test.pdf", "no-cors", "include"), 234 RequestString("https://www.example.com/test.pdf", "no-cors", "include"),
235 result); 235 result);
236 } 236 }
237 237
238 class ChromeServiceWorkerManifestFetchTest 238 class ChromeServiceWorkerManifestFetchTest
239 : public ChromeServiceWorkerFetchTest { 239 : public ChromeServiceWorkerFetchTest {
240 protected: 240 protected:
241 ChromeServiceWorkerManifestFetchTest() {} 241 ChromeServiceWorkerManifestFetchTest() {}
242 ~ChromeServiceWorkerManifestFetchTest() override {} 242 ~ChromeServiceWorkerManifestFetchTest() override {}
243 243
244 void SetUpCommandLine(base::CommandLine* command_line) override {
245 ChromeServiceWorkerFetchTest::SetUpCommandLine(command_line);
246 command_line->AppendSwitch(switches::kEnableAddToShelf);
247 }
248
249 std::string ExecuteManifestFetchTest(const std::string& url, 244 std::string ExecuteManifestFetchTest(const std::string& url,
250 const std::string& cross_origin) { 245 const std::string& cross_origin) {
251 std::string js( 246 std::string js(
252 base::StringPrintf("reportOnFetch = false;" 247 base::StringPrintf("reportOnFetch = false;"
253 "var link = document.createElement('link');" 248 "var link = document.createElement('link');"
254 "link.rel = 'manifest';" 249 "link.rel = 'manifest';"
255 "link.href = '%s';", 250 "link.href = '%s';",
256 url.c_str())); 251 url.c_str()));
257 if (!cross_origin.empty()) { 252 if (!cross_origin.empty()) {
258 js += 253 js +=
259 base::StringPrintf("link.crossOrigin = '%s';", cross_origin.c_str()); 254 base::StringPrintf("link.crossOrigin = '%s';", cross_origin.c_str());
260 } 255 }
261 js += "document.head.appendChild(link);"; 256 js += "document.head.appendChild(link);";
262 ExecuteJavaScriptForTests(js); 257 ExecuteJavaScriptForTests(js);
263 return RequestAppBannerAndGetIssuedRequests(); 258 return RequestAppBannerAndGetIssuedRequests();
264 } 259 }
265 260
266 private: 261 private:
267 void ExecuteJavaScriptForTests(const std::string& js) { 262 void ExecuteJavaScriptForTests(const std::string& js) {
268 browser() 263 browser()
269 ->tab_strip_model() 264 ->tab_strip_model()
270 ->GetActiveWebContents() 265 ->GetActiveWebContents()
271 ->GetMainFrame() 266 ->GetMainFrame()
272 ->ExecuteJavaScriptForTests(base::ASCIIToUTF16(js)); 267 ->ExecuteJavaScriptForTests(base::ASCIIToUTF16(js));
273 } 268 }
274 269
275 std::string RequestAppBannerAndGetIssuedRequests() { 270 std::string RequestAppBannerAndGetIssuedRequests() {
dominickn 2016/07/19 03:06:27 Nit: rename this GetManifestAndIssuedRequests?
horo 2016/07/19 03:13:40 Done.
276 browser()->RequestAppBannerFromDevTools( 271 base::RunLoop run_loop;
277 browser()->tab_strip_model()->GetActiveWebContents()); 272 browser()->tab_strip_model()->GetActiveWebContents()->GetManifest(
273 base::Bind(&ManifestCallbackAndRun, run_loop.QuitClosure()));
274 run_loop.Run();
278 return ExecuteScriptAndExtractString( 275 return ExecuteScriptAndExtractString(
279 "if (issuedRequests.length != 0) reportRequests();" 276 "if (issuedRequests.length != 0) reportRequests();"
280 "else reportOnFetch = true;"); 277 "else reportOnFetch = true;");
281 } 278 }
279
280 static void ManifestCallbackAndRun(const base::Closure& continuation,
281 const GURL&,
282 const content::Manifest&) {
283 continuation.Run();
284 }
285
282 DISALLOW_COPY_AND_ASSIGN(ChromeServiceWorkerManifestFetchTest); 286 DISALLOW_COPY_AND_ASSIGN(ChromeServiceWorkerManifestFetchTest);
283 }; 287 };
284 288
285 IN_PROC_BROWSER_TEST_F(ChromeServiceWorkerManifestFetchTest, SameOrigin) { 289 IN_PROC_BROWSER_TEST_F(ChromeServiceWorkerManifestFetchTest, SameOrigin) {
286 // <link rel="manifest" href="manifest.json"> 290 // <link rel="manifest" href="manifest.json">
287 EXPECT_EQ(RequestString(GetURL("/manifest.json"), "cors", "same-origin"), 291 EXPECT_EQ(RequestString(GetURL("/manifest.json"), "cors", "same-origin"),
288 ExecuteManifestFetchTest("manifest.json", "")); 292 ExecuteManifestFetchTest("manifest.json", ""));
289 } 293 }
290 294
291 IN_PROC_BROWSER_TEST_F(ChromeServiceWorkerManifestFetchTest, 295 IN_PROC_BROWSER_TEST_F(ChromeServiceWorkerManifestFetchTest,
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 ExecutePNACLUrlLoaderTest("OtherCredentials")); 496 ExecutePNACLUrlLoaderTest("OtherCredentials"));
493 } 497 }
494 498
495 IN_PROC_BROWSER_TEST_F(ChromeServiceWorkerFetchPPAPIPrivateTest, 499 IN_PROC_BROWSER_TEST_F(ChromeServiceWorkerFetchPPAPIPrivateTest,
496 OtherOriginCORSCredentials) { 500 OtherOriginCORSCredentials) {
497 EXPECT_EQ(GetRequestStringForPNACL(), 501 EXPECT_EQ(GetRequestStringForPNACL(),
498 ExecutePNACLUrlLoaderTest("OtherCORSCredentials")); 502 ExecutePNACLUrlLoaderTest("OtherCORSCredentials"));
499 } 503 }
500 504
501 } // namespace 505 } // namespace
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698