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

Side by Side Diff: content/browser/manifest/manifest_browsertest.cc

Issue 2052633002: Extend the ToRenderFrameHost magic to FrameTreeNode* and Shell* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix induced script bug. Created 4 years, 6 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
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 #include <stdint.h> 5 #include <stdint.h>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 EXPECT_TRUE(manifest().IsEmpty()); 240 EXPECT_TRUE(manifest().IsEmpty());
241 241
242 HasManifestAndWait(); 242 HasManifestAndWait();
243 EXPECT_FALSE(has_manifest()); 243 EXPECT_FALSE(has_manifest());
244 } 244 }
245 245
246 { 246 {
247 std::string manifest_url = 247 std::string manifest_url =
248 GetTestUrl("manifest", "dummy-manifest.json").spec(); 248 GetTestUrl("manifest", "dummy-manifest.json").spec();
249 ASSERT_TRUE(content::ExecuteScript( 249 ASSERT_TRUE(content::ExecuteScript(
250 shell()->web_contents(), "setManifestTo('" + manifest_url + "')")); 250 shell(), "setManifestTo('" + manifest_url + "')"));
251 251
252 GetManifestAndWait(); 252 GetManifestAndWait();
253 EXPECT_FALSE(manifest().IsEmpty()); 253 EXPECT_FALSE(manifest().IsEmpty());
254 254
255 HasManifestAndWait(); 255 HasManifestAndWait();
256 EXPECT_TRUE(has_manifest()); 256 EXPECT_TRUE(has_manifest());
257 } 257 }
258 258
259 { 259 {
260 std::string manifest_url = 260 std::string manifest_url =
261 GetTestUrl("manifest", "empty-manifest.json").spec(); 261 GetTestUrl("manifest", "empty-manifest.json").spec();
262 ASSERT_TRUE(content::ExecuteScript( 262 ASSERT_TRUE(content::ExecuteScript(
263 shell()->web_contents(), "setManifestTo('" + manifest_url + "')")); 263 shell(), "setManifestTo('" + manifest_url + "')"));
264 264
265 GetManifestAndWait(); 265 GetManifestAndWait();
266 EXPECT_TRUE(manifest().IsEmpty()); 266 EXPECT_TRUE(manifest().IsEmpty());
267 267
268 HasManifestAndWait(); 268 HasManifestAndWait();
269 EXPECT_TRUE(has_manifest()); 269 EXPECT_TRUE(has_manifest());
270 } 270 }
271 271
272 EXPECT_EQ(0u, console_error_count()); 272 EXPECT_EQ(0u, console_error_count());
273 } 273 }
274 274
275 // If a page's manifest lives in a different origin, it should follow the CORS 275 // If a page's manifest lives in a different origin, it should follow the CORS
276 // rules and requesting the manifest should return an empty manifest (unless the 276 // rules and requesting the manifest should return an empty manifest (unless the
277 // response contains CORS headers). 277 // response contains CORS headers).
278 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, CORSManifest) { 278 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, CORSManifest) {
279 ASSERT_TRUE(embedded_test_server()->Start()); 279 ASSERT_TRUE(embedded_test_server()->Start());
280 ASSERT_TRUE(cors_embedded_test_server()->Start()); 280 ASSERT_TRUE(cors_embedded_test_server()->Start());
281 ASSERT_NE(embedded_test_server()->port(), 281 ASSERT_NE(embedded_test_server()->port(),
282 cors_embedded_test_server()->port()); 282 cors_embedded_test_server()->port());
283 283
284 GURL test_url = 284 GURL test_url =
285 embedded_test_server()->GetURL("/manifest/dynamic-manifest.html"); 285 embedded_test_server()->GetURL("/manifest/dynamic-manifest.html");
286 286
287 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); 287 TestNavigationObserver navigation_observer(shell()->web_contents(), 1);
288 shell()->LoadURL(test_url); 288 shell()->LoadURL(test_url);
289 navigation_observer.Wait(); 289 navigation_observer.Wait();
290 290
291 std::string manifest_url = cors_embedded_test_server()->GetURL( 291 std::string manifest_url = cors_embedded_test_server()->GetURL(
292 "/manifest/dummy-manifest.json").spec(); 292 "/manifest/dummy-manifest.json").spec();
293 ASSERT_TRUE(content::ExecuteScript(shell()->web_contents(), 293 ASSERT_TRUE(
294 "setManifestTo('" + manifest_url + "')")); 294 content::ExecuteScript(shell(), "setManifestTo('" + manifest_url + "')"));
295 295
296 GetManifestAndWait(); 296 GetManifestAndWait();
297 EXPECT_TRUE(manifest().IsEmpty()); 297 EXPECT_TRUE(manifest().IsEmpty());
298 298
299 HasManifestAndWait(); 299 HasManifestAndWait();
300 EXPECT_TRUE(has_manifest()); 300 EXPECT_TRUE(has_manifest());
301 EXPECT_EQ(0u, console_error_count()); 301 EXPECT_EQ(0u, console_error_count());
302 302
303 // The purpose of this second load is to make sure the first load is fully 303 // The purpose of this second load is to make sure the first load is fully
304 // finished. The first load will fail because of Access Control error but the 304 // finished. The first load will fail because of Access Control error but the
305 // underlying Blink loader will continue fetching the file. There is no 305 // underlying Blink loader will continue fetching the file. There is no
306 // reliable way to know when the fetch is finished from the browser test 306 // reliable way to know when the fetch is finished from the browser test
307 // except by fetching the same file from same origin, making it succeed when 307 // except by fetching the same file from same origin, making it succeed when
308 // it is actually fully loaded. 308 // it is actually fully loaded.
309 manifest_url = 309 manifest_url =
310 embedded_test_server()->GetURL("/manifest/dummy-manifest.json").spec(); 310 embedded_test_server()->GetURL("/manifest/dummy-manifest.json").spec();
311 ASSERT_TRUE(content::ExecuteScript(shell()->web_contents(), 311 ASSERT_TRUE(
312 "setManifestTo('" + manifest_url + "')")); 312 content::ExecuteScript(shell(), "setManifestTo('" + manifest_url + "')"));
313 GetManifestAndWait(); 313 GetManifestAndWait();
314 } 314 }
315 315
316 // If a page's manifest lives in a different origin, it should be accessible if 316 // If a page's manifest lives in a different origin, it should be accessible if
317 // it has valid access controls headers. 317 // it has valid access controls headers.
318 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, CORSManifestWithAcessControls) { 318 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, CORSManifestWithAcessControls) {
319 ASSERT_TRUE(embedded_test_server()->Start()); 319 ASSERT_TRUE(embedded_test_server()->Start());
320 ASSERT_TRUE(cors_embedded_test_server()->Start()); 320 ASSERT_TRUE(cors_embedded_test_server()->Start());
321 ASSERT_NE(embedded_test_server()->port(), 321 ASSERT_NE(embedded_test_server()->port(),
322 cors_embedded_test_server()->port()); 322 cors_embedded_test_server()->port());
323 323
324 GURL test_url = 324 GURL test_url =
325 embedded_test_server()->GetURL("/manifest/dynamic-manifest.html"); 325 embedded_test_server()->GetURL("/manifest/dynamic-manifest.html");
326 326
327 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); 327 TestNavigationObserver navigation_observer(shell()->web_contents(), 1);
328 shell()->LoadURL(test_url); 328 shell()->LoadURL(test_url);
329 navigation_observer.Wait(); 329 navigation_observer.Wait();
330 330
331 std::string manifest_url = cors_embedded_test_server()->GetURL( 331 std::string manifest_url = cors_embedded_test_server()->GetURL(
332 "/manifest/manifest-cors.json").spec(); 332 "/manifest/manifest-cors.json").spec();
333 ASSERT_TRUE(content::ExecuteScript(shell()->web_contents(), 333 ASSERT_TRUE(
334 "setManifestTo('" + manifest_url + "')")); 334 content::ExecuteScript(shell(), "setManifestTo('" + manifest_url + "')"));
335 335
336 GetManifestAndWait(); 336 GetManifestAndWait();
337 EXPECT_FALSE(manifest().IsEmpty()); 337 EXPECT_FALSE(manifest().IsEmpty());
338 338
339 HasManifestAndWait(); 339 HasManifestAndWait();
340 EXPECT_TRUE(has_manifest()); 340 EXPECT_TRUE(has_manifest());
341 EXPECT_EQ(0u, console_error_count()); 341 EXPECT_EQ(0u, console_error_count());
342 } 342 }
343 343
344 // If a page's manifest is in an insecure origin while the page is in a secure 344 // If a page's manifest is in an insecure origin while the page is in a secure
345 // origin, requesting the manifest should return the empty manifest. 345 // origin, requesting the manifest should return the empty manifest.
346 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, MixedContentManifest) { 346 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, MixedContentManifest) {
347 std::unique_ptr<net::EmbeddedTestServer> https_server( 347 std::unique_ptr<net::EmbeddedTestServer> https_server(
348 new net::EmbeddedTestServer(net::EmbeddedTestServer::TYPE_HTTPS)); 348 new net::EmbeddedTestServer(net::EmbeddedTestServer::TYPE_HTTPS));
349 https_server->ServeFilesFromSourceDirectory("content/test/data"); 349 https_server->ServeFilesFromSourceDirectory("content/test/data");
350 350
351 ASSERT_TRUE(embedded_test_server()->Start()); 351 ASSERT_TRUE(embedded_test_server()->Start());
352 ASSERT_TRUE(https_server->Start()); 352 ASSERT_TRUE(https_server->Start());
353 353
354 GURL test_url = 354 GURL test_url =
355 embedded_test_server()->GetURL("/manifest/dynamic-manifest.html"); 355 embedded_test_server()->GetURL("/manifest/dynamic-manifest.html");
356 356
357 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); 357 TestNavigationObserver navigation_observer(shell()->web_contents(), 1);
358 shell()->LoadURL(test_url); 358 shell()->LoadURL(test_url);
359 navigation_observer.Wait(); 359 navigation_observer.Wait();
360 360
361 std::string manifest_url = 361 std::string manifest_url =
362 https_server->GetURL("/manifest/dummy-manifest.json").spec(); 362 https_server->GetURL("/manifest/dummy-manifest.json").spec();
363 ASSERT_TRUE(content::ExecuteScript(shell()->web_contents(), 363 ASSERT_TRUE(
364 "setManifestTo('" + manifest_url + "')")); 364 content::ExecuteScript(shell(), "setManifestTo('" + manifest_url + "')"));
365 365
366 GetManifestAndWait(); 366 GetManifestAndWait();
367 EXPECT_TRUE(manifest().IsEmpty()); 367 EXPECT_TRUE(manifest().IsEmpty());
368 368
369 HasManifestAndWait(); 369 HasManifestAndWait();
370 EXPECT_TRUE(has_manifest()); 370 EXPECT_TRUE(has_manifest());
371 EXPECT_EQ(0u, console_error_count()); 371 EXPECT_EQ(0u, console_error_count());
372 } 372 }
373 373
374 // If a page's manifest has some parsing errors, they should show up in the 374 // If a page's manifest has some parsing errors, they should show up in the
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 434
435 { 435 {
436 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); 436 TestNavigationObserver navigation_observer(shell()->web_contents(), 1);
437 shell()->LoadURL(test_url); 437 shell()->LoadURL(test_url);
438 navigation_observer.Wait(); 438 navigation_observer.Wait();
439 } 439 }
440 440
441 { 441 {
442 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); 442 TestNavigationObserver navigation_observer(shell()->web_contents(), 1);
443 ASSERT_TRUE(content::ExecuteScript( 443 ASSERT_TRUE(content::ExecuteScript(
444 shell()->web_contents(), 444 shell(), "history.pushState({foo: \"bar\"}, 'page', 'page.html');"));
445 "history.pushState({foo: \"bar\"}, 'page', 'page.html');"));
446 navigation_observer.Wait(); 445 navigation_observer.Wait();
447 } 446 }
448 447
449 GetManifestAndWait(); 448 GetManifestAndWait();
450 EXPECT_FALSE(manifest().IsEmpty()); 449 EXPECT_FALSE(manifest().IsEmpty());
451 450
452 HasManifestAndWait(); 451 HasManifestAndWait();
453 EXPECT_TRUE(has_manifest()); 452 EXPECT_TRUE(has_manifest());
454 EXPECT_EQ(0u, console_error_count()); 453 EXPECT_EQ(0u, console_error_count());
455 } 454 }
456 455
457 // If a page has a manifest and is navigated using an anchor (ie. same page), it 456 // If a page has a manifest and is navigated using an anchor (ie. same page), it
458 // should keep its manifest state. 457 // should keep its manifest state.
459 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, AnchorNavigation) { 458 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, AnchorNavigation) {
460 ASSERT_TRUE(embedded_test_server()->Start()); 459 ASSERT_TRUE(embedded_test_server()->Start());
461 GURL test_url = 460 GURL test_url =
462 embedded_test_server()->GetURL("/manifest/dummy-manifest.html"); 461 embedded_test_server()->GetURL("/manifest/dummy-manifest.html");
463 462
464 { 463 {
465 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); 464 TestNavigationObserver navigation_observer(shell()->web_contents(), 1);
466 shell()->LoadURL(test_url); 465 shell()->LoadURL(test_url);
467 navigation_observer.Wait(); 466 navigation_observer.Wait();
468 } 467 }
469 468
470 { 469 {
471 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); 470 TestNavigationObserver navigation_observer(shell()->web_contents(), 1);
472 ASSERT_TRUE(content::ExecuteScript( 471 ASSERT_TRUE(content::ExecuteScript(
473 shell()->web_contents(), 472 shell(),
474 "var a = document.createElement('a'); a.href='#foo';" 473 "var a = document.createElement('a'); a.href='#foo';"
475 "document.body.appendChild(a); a.click();")); 474 "document.body.appendChild(a); a.click();"));
476 navigation_observer.Wait(); 475 navigation_observer.Wait();
477 } 476 }
478 477
479 GetManifestAndWait(); 478 GetManifestAndWait();
480 EXPECT_FALSE(manifest().IsEmpty()); 479 EXPECT_FALSE(manifest().IsEmpty());
481 EXPECT_EQ(0u, console_error_count()); 480 EXPECT_EQ(0u, console_error_count());
482 481
483 HasManifestAndWait(); 482 HasManifestAndWait();
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 HasManifestAndWait(); 599 HasManifestAndWait();
601 EXPECT_TRUE(has_manifest()); 600 EXPECT_TRUE(has_manifest());
602 EXPECT_EQ(0u, console_error_count()); 601 EXPECT_EQ(0u, console_error_count());
603 602
604 // The custom embedded test server will fill set the name to 'no cookies' if 603 // The custom embedded test server will fill set the name to 'no cookies' if
605 // it did not find cookies. 604 // it did not find cookies.
606 EXPECT_TRUE(base::EqualsASCII(manifest().name.string(), "no cookies")); 605 EXPECT_TRUE(base::EqualsASCII(manifest().name.string(), "no cookies"));
607 } 606 }
608 607
609 } // namespace content 608 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698