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

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

Issue 1411073005: Migrating tests to use EmbeddedTestServer (/content) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. 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 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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/path_service.h" 6 #include "base/path_service.h"
7 #include "base/strings/string_util.h" 7 #include "base/strings/string_util.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "content/public/browser/web_contents.h" 9 #include "content/public/browser/web_contents.h"
10 #include "content/public/common/content_switches.h" 10 #include "content/public/common/content_switches.h"
(...skipping 29 matching lines...) Expand all
40 private: 40 private:
41 WebContents* web_contents_; 41 WebContents* web_contents_;
42 ManifestBrowserTest* test_; 42 ManifestBrowserTest* test_;
43 }; 43 };
44 44
45 class ManifestBrowserTest : public ContentBrowserTest { 45 class ManifestBrowserTest : public ContentBrowserTest {
46 protected: 46 protected:
47 friend MockWebContentsDelegate; 47 friend MockWebContentsDelegate;
48 48
49 ManifestBrowserTest() : console_error_count_(0), has_manifest_(false) { 49 ManifestBrowserTest() : console_error_count_(0), has_manifest_(false) {
50 cors_embedded_test_server_.reset(new net::test_server::EmbeddedTestServer); 50 cors_embedded_test_server_.reset(new net::EmbeddedTestServer);
51 base::FilePath test_data_dir; 51 cors_embedded_test_server_->ServeFilesFromSourceDirectory(
52 CHECK(PathService::Get(base::DIR_SOURCE_ROOT, &test_data_dir)); 52 "content/test/data");
53 cors_embedded_test_server_->ServeFilesFromDirectory(
54 test_data_dir.AppendASCII("content/test/data/"));
55 } 53 }
56 54
57 ~ManifestBrowserTest() override {} 55 ~ManifestBrowserTest() override {}
58 56
59 void SetUpOnMainThread() override { 57 void SetUpOnMainThread() override {
60 ContentBrowserTest::SetUpOnMainThread(); 58 ContentBrowserTest::SetUpOnMainThread();
61 DCHECK(shell()->web_contents()); 59 DCHECK(shell()->web_contents());
62 60
63 mock_web_contents_delegate_.reset( 61 mock_web_contents_delegate_.reset(
64 new MockWebContentsDelegate(shell()->web_contents(), this)); 62 new MockWebContentsDelegate(shell()->web_contents(), this));
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 } 100 }
103 101
104 unsigned int console_error_count() const { 102 unsigned int console_error_count() const {
105 return console_error_count_; 103 return console_error_count_;
106 } 104 }
107 105
108 void OnReceivedConsoleError() { 106 void OnReceivedConsoleError() {
109 console_error_count_++; 107 console_error_count_++;
110 } 108 }
111 109
112 net::test_server::EmbeddedTestServer* cors_embedded_test_server() const { 110 net::EmbeddedTestServer* cors_embedded_test_server() const {
113 return cors_embedded_test_server_.get(); 111 return cors_embedded_test_server_.get();
114 } 112 }
115 113
116 private: 114 private:
117 scoped_refptr<MessageLoopRunner> message_loop_runner_; 115 scoped_refptr<MessageLoopRunner> message_loop_runner_;
118 scoped_ptr<MockWebContentsDelegate> mock_web_contents_delegate_; 116 scoped_ptr<MockWebContentsDelegate> mock_web_contents_delegate_;
119 scoped_ptr<net::test_server::EmbeddedTestServer> cors_embedded_test_server_; 117 scoped_ptr<net::EmbeddedTestServer> cors_embedded_test_server_;
120 Manifest manifest_; 118 Manifest manifest_;
121 int console_error_count_; 119 int console_error_count_;
122 bool has_manifest_; 120 bool has_manifest_;
123 121
124 DISALLOW_COPY_AND_ASSIGN(ManifestBrowserTest); 122 DISALLOW_COPY_AND_ASSIGN(ManifestBrowserTest);
125 }; 123 };
126 124
127 // The implementation of AddMessageToConsole isn't inlined because it needs 125 // The implementation of AddMessageToConsole isn't inlined because it needs
128 // to know about |test_|. 126 // to know about |test_|.
129 bool MockWebContentsDelegate::AddMessageToConsole( 127 bool MockWebContentsDelegate::AddMessageToConsole(
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 EXPECT_TRUE(has_manifest()); 265 EXPECT_TRUE(has_manifest());
268 } 266 }
269 267
270 EXPECT_EQ(0u, console_error_count()); 268 EXPECT_EQ(0u, console_error_count());
271 } 269 }
272 270
273 // If a page's manifest lives in a different origin, it should follow the CORS 271 // If a page's manifest lives in a different origin, it should follow the CORS
274 // rules and requesting the manifest should return an empty manifest (unless the 272 // rules and requesting the manifest should return an empty manifest (unless the
275 // response contains CORS headers). 273 // response contains CORS headers).
276 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, CORSManifest) { 274 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, CORSManifest) {
277 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 275 ASSERT_TRUE(embedded_test_server()->Start());
278 ASSERT_TRUE(cors_embedded_test_server()->InitializeAndWaitUntilReady()); 276 ASSERT_TRUE(cors_embedded_test_server()->Start());
279 ASSERT_NE(embedded_test_server()->port(), 277 ASSERT_NE(embedded_test_server()->port(),
280 cors_embedded_test_server()->port()); 278 cors_embedded_test_server()->port());
281 279
282 GURL test_url = 280 GURL test_url =
283 embedded_test_server()->GetURL("/manifest/dynamic-manifest.html"); 281 embedded_test_server()->GetURL("/manifest/dynamic-manifest.html");
284 282
285 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); 283 TestNavigationObserver navigation_observer(shell()->web_contents(), 1);
286 shell()->LoadURL(test_url); 284 shell()->LoadURL(test_url);
287 navigation_observer.Wait(); 285 navigation_observer.Wait();
288 286
(...skipping 18 matching lines...) Expand all
307 manifest_url = 305 manifest_url =
308 embedded_test_server()->GetURL("/manifest/dummy-manifest.json").spec(); 306 embedded_test_server()->GetURL("/manifest/dummy-manifest.json").spec();
309 ASSERT_TRUE(content::ExecuteScript(shell()->web_contents(), 307 ASSERT_TRUE(content::ExecuteScript(shell()->web_contents(),
310 "setManifestTo('" + manifest_url + "')")); 308 "setManifestTo('" + manifest_url + "')"));
311 GetManifestAndWait(); 309 GetManifestAndWait();
312 } 310 }
313 311
314 // If a page's manifest lives in a different origin, it should be accessible if 312 // If a page's manifest lives in a different origin, it should be accessible if
315 // it has valid access controls headers. 313 // it has valid access controls headers.
316 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, CORSManifestWithAcessControls) { 314 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, CORSManifestWithAcessControls) {
317 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 315 ASSERT_TRUE(embedded_test_server()->Start());
318 ASSERT_TRUE(cors_embedded_test_server()->InitializeAndWaitUntilReady()); 316 ASSERT_TRUE(cors_embedded_test_server()->Start());
319 ASSERT_NE(embedded_test_server()->port(), 317 ASSERT_NE(embedded_test_server()->port(),
320 cors_embedded_test_server()->port()); 318 cors_embedded_test_server()->port());
321 319
322 GURL test_url = 320 GURL test_url =
323 embedded_test_server()->GetURL("/manifest/dynamic-manifest.html"); 321 embedded_test_server()->GetURL("/manifest/dynamic-manifest.html");
324 322
325 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); 323 TestNavigationObserver navigation_observer(shell()->web_contents(), 1);
326 shell()->LoadURL(test_url); 324 shell()->LoadURL(test_url);
327 navigation_observer.Wait(); 325 navigation_observer.Wait();
328 326
329 std::string manifest_url = cors_embedded_test_server()->GetURL( 327 std::string manifest_url = cors_embedded_test_server()->GetURL(
330 "/manifest/manifest-cors.json").spec(); 328 "/manifest/manifest-cors.json").spec();
331 ASSERT_TRUE(content::ExecuteScript(shell()->web_contents(), 329 ASSERT_TRUE(content::ExecuteScript(shell()->web_contents(),
332 "setManifestTo('" + manifest_url + "')")); 330 "setManifestTo('" + manifest_url + "')"));
333 331
334 GetManifestAndWait(); 332 GetManifestAndWait();
335 EXPECT_FALSE(manifest().IsEmpty()); 333 EXPECT_FALSE(manifest().IsEmpty());
336 334
337 HasManifestAndWait(); 335 HasManifestAndWait();
338 EXPECT_TRUE(has_manifest()); 336 EXPECT_TRUE(has_manifest());
339 EXPECT_EQ(0u, console_error_count()); 337 EXPECT_EQ(0u, console_error_count());
340 } 338 }
341 339
342 // If a page's manifest is in an insecure origin while the page is in a secure 340 // If a page's manifest is in an insecure origin while the page is in a secure
343 // origin, requesting the manifest should return the empty manifest. 341 // origin, requesting the manifest should return the empty manifest.
344 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, MixedContentManifest) { 342 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, MixedContentManifest) {
345 scoped_ptr<net::SpawnedTestServer> https_server(new net::SpawnedTestServer( 343 scoped_ptr<net::EmbeddedTestServer> https_server(
346 net::SpawnedTestServer::TYPE_HTTPS, 344 new net::EmbeddedTestServer(net::EmbeddedTestServer::TYPE_HTTPS));
347 net::BaseTestServer::SSLOptions(net::BaseTestServer::SSLOptions::CERT_OK), 345 https_server->ServeFilesFromSourceDirectory("content/test/data");
348 base::FilePath(FILE_PATH_LITERAL("content/test/data"))));
349 346
350 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 347 ASSERT_TRUE(embedded_test_server()->Start());
351 ASSERT_TRUE(https_server->Start()); 348 ASSERT_TRUE(https_server->Start());
352 349
353 GURL test_url = 350 GURL test_url =
354 embedded_test_server()->GetURL("/manifest/dynamic-manifest.html"); 351 embedded_test_server()->GetURL("/manifest/dynamic-manifest.html");
355 352
356 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); 353 TestNavigationObserver navigation_observer(shell()->web_contents(), 1);
357 shell()->LoadURL(test_url); 354 shell()->LoadURL(test_url);
358 navigation_observer.Wait(); 355 navigation_observer.Wait();
359 356
360 std::string manifest_url = 357 std::string manifest_url =
(...skipping 22 matching lines...) Expand all
383 EXPECT_TRUE(manifest().IsEmpty()); 380 EXPECT_TRUE(manifest().IsEmpty());
384 EXPECT_EQ(6u, console_error_count()); 381 EXPECT_EQ(6u, console_error_count());
385 382
386 HasManifestAndWait(); 383 HasManifestAndWait();
387 EXPECT_TRUE(has_manifest()); 384 EXPECT_TRUE(has_manifest());
388 } 385 }
389 386
390 // If a page has a manifest and the page is navigated to a page without a 387 // If a page has a manifest and the page is navigated to a page without a
391 // manifest, the page's manifest should be updated. 388 // manifest, the page's manifest should be updated.
392 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, Navigation) { 389 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, Navigation) {
393 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 390 ASSERT_TRUE(embedded_test_server()->Start());
394 { 391 {
395 GURL test_url = 392 GURL test_url =
396 embedded_test_server()->GetURL("/manifest/dummy-manifest.html"); 393 embedded_test_server()->GetURL("/manifest/dummy-manifest.html");
397 394
398 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); 395 TestNavigationObserver navigation_observer(shell()->web_contents(), 1);
399 shell()->LoadURL(test_url); 396 shell()->LoadURL(test_url);
400 navigation_observer.Wait(); 397 navigation_observer.Wait();
401 398
402 GetManifestAndWait(); 399 GetManifestAndWait();
403 EXPECT_FALSE(manifest().IsEmpty()); 400 EXPECT_FALSE(manifest().IsEmpty());
(...skipping 16 matching lines...) Expand all
420 EXPECT_EQ(0u, console_error_count()); 417 EXPECT_EQ(0u, console_error_count());
421 418
422 HasManifestAndWait(); 419 HasManifestAndWait();
423 EXPECT_FALSE(has_manifest()); 420 EXPECT_FALSE(has_manifest());
424 } 421 }
425 } 422 }
426 423
427 // If a page has a manifest and the page is navigated using pushState (ie. same 424 // If a page has a manifest and the page is navigated using pushState (ie. same
428 // page), it should keep its manifest state. 425 // page), it should keep its manifest state.
429 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, PushStateNavigation) { 426 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, PushStateNavigation) {
430 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 427 ASSERT_TRUE(embedded_test_server()->Start());
431 GURL test_url = 428 GURL test_url =
432 embedded_test_server()->GetURL("/manifest/dummy-manifest.html"); 429 embedded_test_server()->GetURL("/manifest/dummy-manifest.html");
433 430
434 { 431 {
435 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); 432 TestNavigationObserver navigation_observer(shell()->web_contents(), 1);
436 shell()->LoadURL(test_url); 433 shell()->LoadURL(test_url);
437 navigation_observer.Wait(); 434 navigation_observer.Wait();
438 } 435 }
439 436
440 { 437 {
441 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); 438 TestNavigationObserver navigation_observer(shell()->web_contents(), 1);
442 ASSERT_TRUE(content::ExecuteScript( 439 ASSERT_TRUE(content::ExecuteScript(
443 shell()->web_contents(), 440 shell()->web_contents(),
444 "history.pushState({foo: \"bar\"}, 'page', 'page.html');")); 441 "history.pushState({foo: \"bar\"}, 'page', 'page.html');"));
445 navigation_observer.Wait(); 442 navigation_observer.Wait();
446 } 443 }
447 444
448 GetManifestAndWait(); 445 GetManifestAndWait();
449 EXPECT_FALSE(manifest().IsEmpty()); 446 EXPECT_FALSE(manifest().IsEmpty());
450 447
451 HasManifestAndWait(); 448 HasManifestAndWait();
452 EXPECT_TRUE(has_manifest()); 449 EXPECT_TRUE(has_manifest());
453 EXPECT_EQ(0u, console_error_count()); 450 EXPECT_EQ(0u, console_error_count());
454 } 451 }
455 452
456 // If a page has a manifest and is navigated using an anchor (ie. same page), it 453 // If a page has a manifest and is navigated using an anchor (ie. same page), it
457 // should keep its manifest state. 454 // should keep its manifest state.
458 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, AnchorNavigation) { 455 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, AnchorNavigation) {
459 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 456 ASSERT_TRUE(embedded_test_server()->Start());
460 GURL test_url = 457 GURL test_url =
461 embedded_test_server()->GetURL("/manifest/dummy-manifest.html"); 458 embedded_test_server()->GetURL("/manifest/dummy-manifest.html");
462 459
463 { 460 {
464 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); 461 TestNavigationObserver navigation_observer(shell()->web_contents(), 1);
465 shell()->LoadURL(test_url); 462 shell()->LoadURL(test_url);
466 navigation_observer.Wait(); 463 navigation_observer.Wait();
467 } 464 }
468 465
469 { 466 {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 base::StringPrintf("{\"name\": \"%s\"}", iter->second.c_str())); 509 base::StringPrintf("{\"name\": \"%s\"}", iter->second.c_str()));
513 510
514 return http_response.Pass(); 511 return http_response.Pass();
515 } 512 }
516 513
517 } // anonymous namespace 514 } // anonymous namespace
518 515
519 // This tests that when fetching a Manifest with 'use-credentials' set, the 516 // This tests that when fetching a Manifest with 'use-credentials' set, the
520 // cookies associated with it are passed along the request. 517 // cookies associated with it are passed along the request.
521 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, UseCredentialsSendCookies) { 518 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, UseCredentialsSendCookies) {
522 scoped_ptr<net::test_server::EmbeddedTestServer> custom_embedded_test_server( 519 scoped_ptr<net::EmbeddedTestServer> custom_embedded_test_server(
523 new net::test_server::EmbeddedTestServer()); 520 new net::EmbeddedTestServer());
524 custom_embedded_test_server->RegisterRequestHandler( 521 custom_embedded_test_server->RegisterRequestHandler(
525 base::Bind(&CustomHandleRequestForCookies)); 522 base::Bind(&CustomHandleRequestForCookies));
526 523
527 ASSERT_TRUE(custom_embedded_test_server->InitializeAndWaitUntilReady()); 524 ASSERT_TRUE(custom_embedded_test_server->Start());
528 525
529 ASSERT_TRUE(SetCookie(shell()->web_contents()->GetBrowserContext(), 526 ASSERT_TRUE(SetCookie(shell()->web_contents()->GetBrowserContext(),
530 custom_embedded_test_server->base_url(), 527 custom_embedded_test_server->base_url(),
531 "foobar")); 528 "foobar"));
532 529
533 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); 530 TestNavigationObserver navigation_observer(shell()->web_contents(), 1);
534 shell()->LoadURL(custom_embedded_test_server->GetURL("/index.html")); 531 shell()->LoadURL(custom_embedded_test_server->GetURL("/index.html"));
535 navigation_observer.Wait(); 532 navigation_observer.Wait();
536 533
537 GetManifestAndWait(); 534 GetManifestAndWait();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 http_response->set_content("{\"name\": \"no cookies\"}"); 568 http_response->set_content("{\"name\": \"no cookies\"}");
572 569
573 return http_response.Pass(); 570 return http_response.Pass();
574 } 571 }
575 572
576 } // anonymous namespace 573 } // anonymous namespace
577 574
578 // This tests that when fetching a Manifest without 'use-credentials' set, the 575 // This tests that when fetching a Manifest without 'use-credentials' set, the
579 // cookies associated with it are not passed along the request. 576 // cookies associated with it are not passed along the request.
580 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, NoUseCredentialsNoCookies) { 577 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, NoUseCredentialsNoCookies) {
581 scoped_ptr<net::test_server::EmbeddedTestServer> custom_embedded_test_server( 578 scoped_ptr<net::EmbeddedTestServer> custom_embedded_test_server(
582 new net::test_server::EmbeddedTestServer()); 579 new net::EmbeddedTestServer());
583 custom_embedded_test_server->RegisterRequestHandler( 580 custom_embedded_test_server->RegisterRequestHandler(
584 base::Bind(&CustomHandleRequestForNoCookies)); 581 base::Bind(&CustomHandleRequestForNoCookies));
585 582
586 ASSERT_TRUE(custom_embedded_test_server->InitializeAndWaitUntilReady()); 583 ASSERT_TRUE(custom_embedded_test_server->Start());
587 584
588 ASSERT_TRUE(SetCookie(shell()->web_contents()->GetBrowserContext(), 585 ASSERT_TRUE(SetCookie(shell()->web_contents()->GetBrowserContext(),
589 custom_embedded_test_server->base_url(), 586 custom_embedded_test_server->base_url(),
590 "foobar")); 587 "foobar"));
591 588
592 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); 589 TestNavigationObserver navigation_observer(shell()->web_contents(), 1);
593 shell()->LoadURL(custom_embedded_test_server->GetURL("/index.html")); 590 shell()->LoadURL(custom_embedded_test_server->GetURL("/index.html"));
594 navigation_observer.Wait(); 591 navigation_observer.Wait();
595 592
596 GetManifestAndWait(); 593 GetManifestAndWait();
597 EXPECT_FALSE(manifest().IsEmpty()); 594 EXPECT_FALSE(manifest().IsEmpty());
598 595
599 HasManifestAndWait(); 596 HasManifestAndWait();
600 EXPECT_TRUE(has_manifest()); 597 EXPECT_TRUE(has_manifest());
601 EXPECT_EQ(0u, console_error_count()); 598 EXPECT_EQ(0u, console_error_count());
602 599
603 // The custom embedded test server will fill set the name to 'no cookies' if 600 // The custom embedded test server will fill set the name to 'no cookies' if
604 // it did not find cookies. 601 // it did not find cookies.
605 EXPECT_TRUE(base::EqualsASCII(manifest().name.string(), "no cookies")); 602 EXPECT_TRUE(base::EqualsASCII(manifest().name.string(), "no cookies"));
606 } 603 }
607 604
608 } // namespace content 605 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/loader/resource_dispatcher_host_browsertest.cc ('k') | content/browser/media/media_browsertest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698