| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "platform/network/ResourceResponse.h" | |
| 6 | |
| 7 #include "platform/CrossThreadFunctional.h" | |
| 8 #include "platform/WebTaskRunner.h" | |
| 9 #include "public/platform/Platform.h" | |
| 10 #include "public/platform/WebThread.h" | |
| 11 #include "testing/gtest/include/gtest/gtest.h" | |
| 12 | |
| 13 namespace blink { | |
| 14 | |
| 15 namespace { | |
| 16 | |
| 17 ResourceResponse createTestResponse() { | |
| 18 ResourceResponse response; | |
| 19 response.addHTTPHeaderField("age", "0"); | |
| 20 response.addHTTPHeaderField("cache-control", "no-cache"); | |
| 21 response.addHTTPHeaderField("date", "Tue, 17 Jan 2017 04:01:00 GMT"); | |
| 22 response.addHTTPHeaderField("expires", "Tue, 17 Jan 2017 04:11:00 GMT"); | |
| 23 response.addHTTPHeaderField("last-modified", "Tue, 17 Jan 2017 04:00:00 GMT"); | |
| 24 response.addHTTPHeaderField("pragma", "public"); | |
| 25 response.addHTTPHeaderField("etag", "abc"); | |
| 26 response.addHTTPHeaderField("content-disposition", | |
| 27 "attachment; filename=a.txt"); | |
| 28 return response; | |
| 29 } | |
| 30 | |
| 31 void runHeaderRelatedTest(const ResourceResponse& response) { | |
| 32 EXPECT_EQ(0, response.age()); | |
| 33 EXPECT_NE(0, response.date()); | |
| 34 EXPECT_NE(0, response.expires()); | |
| 35 EXPECT_NE(0, response.lastModified()); | |
| 36 EXPECT_EQ(true, response.cacheControlContainsNoCache()); | |
| 37 } | |
| 38 | |
| 39 void runInThread() { | |
| 40 ResourceResponse response(createTestResponse()); | |
| 41 runHeaderRelatedTest(response); | |
| 42 } | |
| 43 | |
| 44 } // namespace | |
| 45 | |
| 46 TEST(ResourceResponseTest, SignedCertificateTimestampIsolatedCopy) { | |
| 47 ResourceResponse::SignedCertificateTimestamp src( | |
| 48 "status", "origin", "logDescription", "logId", 7, "hashAlgorithm", | |
| 49 "signatureAlgorithm", "signatureData"); | |
| 50 | |
| 51 ResourceResponse::SignedCertificateTimestamp dest = src.isolatedCopy(); | |
| 52 | |
| 53 EXPECT_EQ(src.m_status, dest.m_status); | |
| 54 EXPECT_NE(src.m_status.impl(), dest.m_status.impl()); | |
| 55 EXPECT_EQ(src.m_origin, dest.m_origin); | |
| 56 EXPECT_NE(src.m_origin.impl(), dest.m_origin.impl()); | |
| 57 EXPECT_EQ(src.m_logDescription, dest.m_logDescription); | |
| 58 EXPECT_NE(src.m_logDescription.impl(), dest.m_logDescription.impl()); | |
| 59 EXPECT_EQ(src.m_logId, dest.m_logId); | |
| 60 EXPECT_NE(src.m_logId.impl(), dest.m_logId.impl()); | |
| 61 EXPECT_EQ(src.m_timestamp, dest.m_timestamp); | |
| 62 EXPECT_EQ(src.m_hashAlgorithm, dest.m_hashAlgorithm); | |
| 63 EXPECT_NE(src.m_hashAlgorithm.impl(), dest.m_hashAlgorithm.impl()); | |
| 64 EXPECT_EQ(src.m_signatureAlgorithm, dest.m_signatureAlgorithm); | |
| 65 EXPECT_NE(src.m_signatureAlgorithm.impl(), dest.m_signatureAlgorithm.impl()); | |
| 66 EXPECT_EQ(src.m_signatureData, dest.m_signatureData); | |
| 67 EXPECT_NE(src.m_signatureData.impl(), dest.m_signatureData.impl()); | |
| 68 } | |
| 69 | |
| 70 TEST(ResourceResponseTest, CrossThreadAtomicStrings) { | |
| 71 // This test checks that AtomicStrings in ResourceResponse doesn't cause the | |
| 72 // failure of ThreadRestrictionVerifier check. | |
| 73 ResourceResponse response(createTestResponse()); | |
| 74 runHeaderRelatedTest(response); | |
| 75 std::unique_ptr<WebThread> thread = | |
| 76 WTF::wrapUnique(Platform::current()->createThread("WorkerThread")); | |
| 77 thread->getWebTaskRunner()->postTask(BLINK_FROM_HERE, | |
| 78 crossThreadBind(&runInThread)); | |
| 79 thread.reset(); | |
| 80 } | |
| 81 | |
| 82 } // namespace blink | |
| OLD | NEW |