OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2015, Google Inc. All rights reserved. | 2 * Copyright (c) 2015, Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
487 resource_request.SetRequestContext(WebURLRequest::kRequestContextScript); | 487 resource_request.SetRequestContext(WebURLRequest::kRequestContextScript); |
488 fetch_context->PopulateResourceRequest( | 488 fetch_context->PopulateResourceRequest( |
489 url, Resource::kScript, ClientHintsPreferences(), | 489 url, Resource::kScript, ClientHintsPreferences(), |
490 FetchParameters::ResourceWidth(), ResourceLoaderOptions(), | 490 FetchParameters::ResourceWidth(), ResourceLoaderOptions(), |
491 SecurityViolationReportingPolicy::kReport, resource_request); | 491 SecurityViolationReportingPolicy::kReport, resource_request); |
492 EXPECT_EQ(1u, policy->violation_reports_sent_.size()); | 492 EXPECT_EQ(1u, policy->violation_reports_sent_.size()); |
493 // Check that the resource was upgraded to a secure URL. | 493 // Check that the resource was upgraded to a secure URL. |
494 EXPECT_EQ(KURL(KURL(), "https://baz.test"), resource_request.Url()); | 494 EXPECT_EQ(KURL(KURL(), "https://baz.test"), resource_request.Url()); |
495 } | 495 } |
496 | 496 |
497 class FrameFetchContextHintsTest : public FrameFetchContextTest { | 497 class FrameFetchContextHintsTest : public FrameFetchContextTest { |
kinuko
2017/05/25 05:05:51
For these ones I suspect we could just use Testing
fmeawad
2017/05/25 19:53:34
Done.
| |
498 public: | 498 public: |
499 FrameFetchContextHintsTest() {} | 499 FrameFetchContextHintsTest() {} |
500 | 500 |
501 protected: | 501 protected: |
502 void ExpectHeader(const char* input, | 502 void ExpectHeader(const char* input, |
503 const char* header_name, | 503 const char* header_name, |
504 bool is_present, | 504 bool is_present, |
505 const char* header_value, | 505 const char* header_value, |
506 float width = 0) { | 506 float width = 0) { |
507 ClientHintsPreferences hints_preferences; | 507 ClientHintsPreferences hints_preferences; |
508 | 508 |
509 FetchParameters::ResourceWidth resource_width; | 509 FetchParameters::ResourceWidth resource_width; |
510 if (width > 0) { | 510 if (width > 0) { |
511 resource_width.width = width; | 511 resource_width.width = width; |
512 resource_width.is_set = true; | 512 resource_width.is_set = true; |
513 } | 513 } |
514 | 514 |
515 KURL input_url(kParsedURLString, input); | 515 KURL input_url(kParsedURLString, input); |
516 ResourceRequest resource_request(input_url); | 516 ResourceRequest resource_request(input_url); |
517 | 517 |
518 fetch_context->AddClientHintsIfNecessary(hints_preferences, resource_width, | 518 fetch_context->AddClientHintsIfNecessary(hints_preferences, resource_width, |
519 resource_request); | 519 resource_request); |
520 | 520 |
521 EXPECT_EQ(is_present ? String(header_value) : String(), | 521 EXPECT_EQ(is_present ? String(header_value) : String(), |
522 resource_request.HttpHeaderField(header_name)); | 522 resource_request.HttpHeaderField(header_name)); |
523 } | 523 } |
524 }; | 524 }; |
525 | 525 |
526 TEST_F(FrameFetchContextHintsTest, MonitorDeviceRAMHints) { | |
527 ExpectHeader("http://www.example.com/1.gif", "device-ram", false, ""); | |
528 ClientHintsPreferences preferences; | |
529 preferences.SetShouldSendDeviceRAM(true); | |
530 document->GetClientHintsPreferences().UpdateFrom(preferences); | |
531 Platform::Current()->SetDevicePhysicalMemoryMBForTesting(4096); | |
532 ExpectHeader("http://www.example.com/1.gif", "device-ram", true, "4"); | |
533 Platform::Current()->SetDevicePhysicalMemoryMBForTesting(2048); | |
534 ExpectHeader("http://www.example.com/1.gif", "device-ram", true, "2"); | |
535 Platform::Current()->SetDevicePhysicalMemoryMBForTesting(64385); | |
536 ExpectHeader("http://www.example.com/1.gif", "device-ram", true, "32"); | |
537 Platform::Current()->SetDevicePhysicalMemoryMBForTesting(768); | |
538 ExpectHeader("http://www.example.com/1.gif", "device-ram", true, "0.5"); | |
539 ExpectHeader("http://www.example.com/1.gif", "DPR", false, ""); | |
540 ExpectHeader("http://www.example.com/1.gif", "Width", false, ""); | |
541 ExpectHeader("http://www.example.com/1.gif", "Viewport-Width", false, ""); | |
542 } | |
543 | |
526 TEST_F(FrameFetchContextHintsTest, MonitorDPRHints) { | 544 TEST_F(FrameFetchContextHintsTest, MonitorDPRHints) { |
527 ExpectHeader("http://www.example.com/1.gif", "DPR", false, ""); | 545 ExpectHeader("http://www.example.com/1.gif", "DPR", false, ""); |
528 ClientHintsPreferences preferences; | 546 ClientHintsPreferences preferences; |
529 preferences.SetShouldSendDPR(true); | 547 preferences.SetShouldSendDPR(true); |
530 document->GetClientHintsPreferences().UpdateFrom(preferences); | 548 document->GetClientHintsPreferences().UpdateFrom(preferences); |
531 ExpectHeader("http://www.example.com/1.gif", "DPR", true, "1"); | 549 ExpectHeader("http://www.example.com/1.gif", "DPR", true, "1"); |
532 dummy_page_holder->GetPage().SetDeviceScaleFactorDeprecated(2.5); | 550 dummy_page_holder->GetPage().SetDeviceScaleFactorDeprecated(2.5); |
533 ExpectHeader("http://www.example.com/1.gif", "DPR", true, "2.5"); | 551 ExpectHeader("http://www.example.com/1.gif", "DPR", true, "2.5"); |
534 ExpectHeader("http://www.example.com/1.gif", "Width", false, ""); | 552 ExpectHeader("http://www.example.com/1.gif", "Width", false, ""); |
535 ExpectHeader("http://www.example.com/1.gif", "Viewport-Width", false, ""); | 553 ExpectHeader("http://www.example.com/1.gif", "Viewport-Width", false, ""); |
(...skipping 20 matching lines...) Expand all Loading... | |
556 ExpectHeader("http://www.example.com/1.gif", "Viewport-Width", true, "500"); | 574 ExpectHeader("http://www.example.com/1.gif", "Viewport-Width", true, "500"); |
557 dummy_page_holder->GetFrameView().SetLayoutSizeFixedToFrameSize(false); | 575 dummy_page_holder->GetFrameView().SetLayoutSizeFixedToFrameSize(false); |
558 dummy_page_holder->GetFrameView().SetLayoutSize(IntSize(800, 800)); | 576 dummy_page_holder->GetFrameView().SetLayoutSize(IntSize(800, 800)); |
559 ExpectHeader("http://www.example.com/1.gif", "Viewport-Width", true, "800"); | 577 ExpectHeader("http://www.example.com/1.gif", "Viewport-Width", true, "800"); |
560 ExpectHeader("http://www.example.com/1.gif", "Viewport-Width", true, "800", | 578 ExpectHeader("http://www.example.com/1.gif", "Viewport-Width", true, "800", |
561 666.6666); | 579 666.6666); |
562 ExpectHeader("http://www.example.com/1.gif", "DPR", false, ""); | 580 ExpectHeader("http://www.example.com/1.gif", "DPR", false, ""); |
563 } | 581 } |
564 | 582 |
565 TEST_F(FrameFetchContextHintsTest, MonitorAllHints) { | 583 TEST_F(FrameFetchContextHintsTest, MonitorAllHints) { |
584 ExpectHeader("http://www.example.com/1.gif", "device-ram", false, ""); | |
566 ExpectHeader("http://www.example.com/1.gif", "DPR", false, ""); | 585 ExpectHeader("http://www.example.com/1.gif", "DPR", false, ""); |
567 ExpectHeader("http://www.example.com/1.gif", "Viewport-Width", false, ""); | 586 ExpectHeader("http://www.example.com/1.gif", "Viewport-Width", false, ""); |
568 ExpectHeader("http://www.example.com/1.gif", "Width", false, ""); | 587 ExpectHeader("http://www.example.com/1.gif", "Width", false, ""); |
569 | 588 |
570 ClientHintsPreferences preferences; | 589 ClientHintsPreferences preferences; |
590 preferences.SetShouldSendDeviceRAM(true); | |
571 preferences.SetShouldSendDPR(true); | 591 preferences.SetShouldSendDPR(true); |
572 preferences.SetShouldSendResourceWidth(true); | 592 preferences.SetShouldSendResourceWidth(true); |
573 preferences.SetShouldSendViewportWidth(true); | 593 preferences.SetShouldSendViewportWidth(true); |
594 Platform::Current()->SetDevicePhysicalMemoryMBForTesting(4096); | |
574 document->GetClientHintsPreferences().UpdateFrom(preferences); | 595 document->GetClientHintsPreferences().UpdateFrom(preferences); |
596 ExpectHeader("http://www.example.com/1.gif", "device-ram", true, "4"); | |
575 ExpectHeader("http://www.example.com/1.gif", "DPR", true, "1"); | 597 ExpectHeader("http://www.example.com/1.gif", "DPR", true, "1"); |
576 ExpectHeader("http://www.example.com/1.gif", "Width", true, "400", 400); | 598 ExpectHeader("http://www.example.com/1.gif", "Width", true, "400", 400); |
577 ExpectHeader("http://www.example.com/1.gif", "Viewport-Width", true, "500"); | 599 ExpectHeader("http://www.example.com/1.gif", "Viewport-Width", true, "500"); |
578 } | 600 } |
579 | 601 |
602 TEST_F(FrameFetchContextHintsTest, ClientHintsDeviceRAM) { | |
603 EXPECT_EQ(0.125, FrameFetchContext::ClientHintsDeviceRAM(128)); // 128MB | |
604 EXPECT_EQ(0.25, FrameFetchContext::ClientHintsDeviceRAM(256)); // 256MB | |
605 EXPECT_EQ(0.25, FrameFetchContext::ClientHintsDeviceRAM(510)); // <512MB | |
606 EXPECT_EQ(0.5, FrameFetchContext::ClientHintsDeviceRAM(512)); // 512MB | |
607 EXPECT_EQ(0.5, FrameFetchContext::ClientHintsDeviceRAM(640)); // 512+128MB | |
608 EXPECT_EQ(0.5, FrameFetchContext::ClientHintsDeviceRAM(768)); // 512+256MB | |
609 EXPECT_EQ(0.5, FrameFetchContext::ClientHintsDeviceRAM(1000)); // <1GB | |
610 EXPECT_EQ(1, FrameFetchContext::ClientHintsDeviceRAM(1024)); // 1GB | |
611 EXPECT_EQ(1, FrameFetchContext::ClientHintsDeviceRAM(1536)); // 1.5GB | |
612 EXPECT_EQ(1, FrameFetchContext::ClientHintsDeviceRAM(2000)); // <2GB | |
613 EXPECT_EQ(2, FrameFetchContext::ClientHintsDeviceRAM(2048)); // 2GB | |
614 EXPECT_EQ(4, FrameFetchContext::ClientHintsDeviceRAM(5120)); // 5GB | |
615 EXPECT_EQ(8, FrameFetchContext::ClientHintsDeviceRAM(8192)); // 8GB | |
616 EXPECT_EQ(16, FrameFetchContext::ClientHintsDeviceRAM(16384)); // 16GB | |
617 EXPECT_EQ(32, FrameFetchContext::ClientHintsDeviceRAM(32768)); // 32GB | |
618 EXPECT_EQ(32, FrameFetchContext::ClientHintsDeviceRAM(64385)); // <64GB | |
619 } | |
620 | |
580 TEST_F(FrameFetchContextTest, MainResourceCachePolicy) { | 621 TEST_F(FrameFetchContextTest, MainResourceCachePolicy) { |
581 // Default case | 622 // Default case |
582 ResourceRequest request("http://www.example.com"); | 623 ResourceRequest request("http://www.example.com"); |
583 EXPECT_EQ(WebCachePolicy::kUseProtocolCachePolicy, | 624 EXPECT_EQ(WebCachePolicy::kUseProtocolCachePolicy, |
584 fetch_context->ResourceRequestCachePolicy( | 625 fetch_context->ResourceRequestCachePolicy( |
585 request, Resource::kMainResource, FetchParameters::kNoDefer)); | 626 request, Resource::kMainResource, FetchParameters::kNoDefer)); |
586 | 627 |
587 // Post | 628 // Post |
588 ResourceRequest post_request("http://www.example.com"); | 629 ResourceRequest post_request("http://www.example.com"); |
589 post_request.SetHTTPMethod(HTTPNames::POST); | 630 post_request.SetHTTPMethod(HTTPNames::POST); |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
905 SetFilterPolicy(WebDocumentSubresourceFilter::kWouldDisallow); | 946 SetFilterPolicy(WebDocumentSubresourceFilter::kWouldDisallow); |
906 | 947 |
907 EXPECT_EQ(ResourceRequestBlockedReason::kNone, CanRequest()); | 948 EXPECT_EQ(ResourceRequestBlockedReason::kNone, CanRequest()); |
908 EXPECT_EQ(0, GetFilteredLoadCallCount()); | 949 EXPECT_EQ(0, GetFilteredLoadCallCount()); |
909 | 950 |
910 EXPECT_EQ(ResourceRequestBlockedReason::kNone, CanRequestPreload()); | 951 EXPECT_EQ(ResourceRequestBlockedReason::kNone, CanRequestPreload()); |
911 EXPECT_EQ(0, GetFilteredLoadCallCount()); | 952 EXPECT_EQ(0, GetFilteredLoadCallCount()); |
912 } | 953 } |
913 | 954 |
914 } // namespace blink | 955 } // namespace blink |
OLD | NEW |