| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 "platform/network/ResourceResponse.h" | 5 #include "platform/network/ResourceResponse.h" |
| 6 | 6 |
| 7 #include "platform/CrossThreadFunctional.h" |
| 8 #include "platform/WebTaskRunner.h" |
| 9 #include "public/platform/Platform.h" |
| 10 #include "public/platform/WebThread.h" |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 8 | 12 |
| 9 namespace blink { | 13 namespace blink { |
| 10 | 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 |
| 11 TEST(ResourceResponseTest, SignedCertificateTimestampIsolatedCopy) { | 46 TEST(ResourceResponseTest, SignedCertificateTimestampIsolatedCopy) { |
| 12 ResourceResponse::SignedCertificateTimestamp src( | 47 ResourceResponse::SignedCertificateTimestamp src( |
| 13 "status", "origin", "logDescription", "logId", 7, "hashAlgorithm", | 48 "status", "origin", "logDescription", "logId", 7, "hashAlgorithm", |
| 14 "signatureAlgorithm", "signatureData"); | 49 "signatureAlgorithm", "signatureData"); |
| 15 | 50 |
| 16 ResourceResponse::SignedCertificateTimestamp dest = src.isolatedCopy(); | 51 ResourceResponse::SignedCertificateTimestamp dest = src.isolatedCopy(); |
| 17 | 52 |
| 18 EXPECT_EQ(src.m_status, dest.m_status); | 53 EXPECT_EQ(src.m_status, dest.m_status); |
| 19 EXPECT_NE(src.m_status.impl(), dest.m_status.impl()); | 54 EXPECT_NE(src.m_status.impl(), dest.m_status.impl()); |
| 20 EXPECT_EQ(src.m_origin, dest.m_origin); | 55 EXPECT_EQ(src.m_origin, dest.m_origin); |
| 21 EXPECT_NE(src.m_origin.impl(), dest.m_origin.impl()); | 56 EXPECT_NE(src.m_origin.impl(), dest.m_origin.impl()); |
| 22 EXPECT_EQ(src.m_logDescription, dest.m_logDescription); | 57 EXPECT_EQ(src.m_logDescription, dest.m_logDescription); |
| 23 EXPECT_NE(src.m_logDescription.impl(), dest.m_logDescription.impl()); | 58 EXPECT_NE(src.m_logDescription.impl(), dest.m_logDescription.impl()); |
| 24 EXPECT_EQ(src.m_logId, dest.m_logId); | 59 EXPECT_EQ(src.m_logId, dest.m_logId); |
| 25 EXPECT_NE(src.m_logId.impl(), dest.m_logId.impl()); | 60 EXPECT_NE(src.m_logId.impl(), dest.m_logId.impl()); |
| 26 EXPECT_EQ(src.m_timestamp, dest.m_timestamp); | 61 EXPECT_EQ(src.m_timestamp, dest.m_timestamp); |
| 27 EXPECT_EQ(src.m_hashAlgorithm, dest.m_hashAlgorithm); | 62 EXPECT_EQ(src.m_hashAlgorithm, dest.m_hashAlgorithm); |
| 28 EXPECT_NE(src.m_hashAlgorithm.impl(), dest.m_hashAlgorithm.impl()); | 63 EXPECT_NE(src.m_hashAlgorithm.impl(), dest.m_hashAlgorithm.impl()); |
| 29 EXPECT_EQ(src.m_signatureAlgorithm, dest.m_signatureAlgorithm); | 64 EXPECT_EQ(src.m_signatureAlgorithm, dest.m_signatureAlgorithm); |
| 30 EXPECT_NE(src.m_signatureAlgorithm.impl(), dest.m_signatureAlgorithm.impl()); | 65 EXPECT_NE(src.m_signatureAlgorithm.impl(), dest.m_signatureAlgorithm.impl()); |
| 31 EXPECT_EQ(src.m_signatureData, dest.m_signatureData); | 66 EXPECT_EQ(src.m_signatureData, dest.m_signatureData); |
| 32 EXPECT_NE(src.m_signatureData.impl(), dest.m_signatureData.impl()); | 67 EXPECT_NE(src.m_signatureData.impl(), dest.m_signatureData.impl()); |
| 33 } | 68 } |
| 34 | 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 |
| 35 } // namespace blink | 82 } // namespace blink |
| OLD | NEW |