From d88f3e04a981378af45e08a90b1c7bb37a12520c Mon Sep 17 00:00:00 2001 From: Andrew Osmond Date: Tue, 4 Jun 2019 18:50:47 -0400 Subject: [PATCH 001/491] Bug 1556822 - Add the display color profile to about:support. r=miko This adds the base64 encoded color profile to the about:support page in order to allow us to better diagnose and reproduce color management issues. We can extract this, decode it and load it directly via the gfx.color_management.display_profile pref. --- gfx/thebes/gfxPlatform.cpp | 22 ++++++++++++++++++++++ gfx/thebes/gfxPlatform.h | 2 ++ toolkit/content/aboutSupport.js | 4 +++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/gfx/thebes/gfxPlatform.cpp b/gfx/thebes/gfxPlatform.cpp index 05104e964e6bc..847fa52017fa3 100644 --- a/gfx/thebes/gfxPlatform.cpp +++ b/gfx/thebes/gfxPlatform.cpp @@ -25,6 +25,7 @@ #include "mozilla/TimeStamp.h" #include "mozilla/Unused.h" #include "mozilla/IntegerPrintfMacros.h" +#include "mozilla/Base64.h" #include "mozilla/Logging.h" #include "mozilla/Services.h" @@ -462,6 +463,7 @@ gfxPlatform::gfxPlatform() mApzSupportCollector(this, &gfxPlatform::GetApzSupportInfo), mTilesInfoCollector(this, &gfxPlatform::GetTilesSupportInfo), mFrameStatsCollector(this, &gfxPlatform::GetFrameStats), + mCMSInfoCollector(this, &gfxPlatform::GetCMSSupportInfo), mCompositorBackend(layers::LayersBackend::LAYERS_NONE), mScreenDepth(0) { mAllowDownloadableFonts = UNINITIALIZED_VALUE; @@ -3258,6 +3260,26 @@ void gfxPlatform::GetFrameStats(mozilla::widget::InfoObject& aObj) { } } +void gfxPlatform::GetCMSSupportInfo(mozilla::widget::InfoObject& aObj) { + void* profile = nullptr; + size_t size = 0; + + GetCMSOutputProfileData(profile, size); + if (!profile) { + return; + } + + char* encodedProfile = nullptr; + nsresult rv = + Base64Encode(reinterpret_cast(profile), size, &encodedProfile); + if (NS_SUCCEEDED(rv)) { + aObj.DefineProperty("CMSOutputProfile", encodedProfile); + free(encodedProfile); + } + + free(profile); +} + class FrameStatsComparator { public: bool Equals(const FrameStats& aA, const FrameStats& aB) const { diff --git a/gfx/thebes/gfxPlatform.h b/gfx/thebes/gfxPlatform.h index 94deaddb64231..d4da68c01af5c 100644 --- a/gfx/thebes/gfxPlatform.h +++ b/gfx/thebes/gfxPlatform.h @@ -281,6 +281,7 @@ class gfxPlatform : public mozilla::layers::MemoryPressureListener { void GetApzSupportInfo(mozilla::widget::InfoObject& aObj); void GetTilesSupportInfo(mozilla::widget::InfoObject& aObj); void GetFrameStats(mozilla::widget::InfoObject& aObj); + void GetCMSSupportInfo(mozilla::widget::InfoObject& aObj); // Get the default content backend that will be used with the default // compositor. If the compositor is known when calling this function, @@ -911,6 +912,7 @@ class gfxPlatform : public mozilla::layers::MemoryPressureListener { mozilla::widget::GfxInfoCollector mApzSupportCollector; mozilla::widget::GfxInfoCollector mTilesInfoCollector; mozilla::widget::GfxInfoCollector mFrameStatsCollector; + mozilla::widget::GfxInfoCollector mCMSInfoCollector; nsTArray mFrameStats; diff --git a/toolkit/content/aboutSupport.js b/toolkit/content/aboutSupport.js index b3b6a8f7fe788..5385dd9a197f1 100644 --- a/toolkit/content/aboutSupport.js +++ b/toolkit/content/aboutSupport.js @@ -343,9 +343,11 @@ var snapshotFormatters = { apzInfo = formatApzInfo(data.info); let trs = sortedArrayFromObject(data.info).map(function([prop, val]) { + let td = $.new("td", String(val)); + td.style["word-break"] = "break-all"; return $.new("tr", [ $.new("th", prop, "column"), - $.new("td", String(val)), + td, ]); }); addRows("diagnostics", trs); From 2f955dea5ed2b877124b95b396456738427bef96 Mon Sep 17 00:00:00 2001 From: "J.C. Jones" Date: Tue, 4 Jun 2019 19:39:40 +0000 Subject: [PATCH 002/491] Bug 1550889 - land NSS 8082be3a6363 UPGRADE_NSS_RELEASE, r=me --HG-- extra : rebase_source : 84cb27998d0b4e36d9a7d388e3a8b2a4fc3bb886 --- security/nss/TAG-INFO | 2 +- .../abi-check/expected-report-libnss3.so.txt | 4 + security/nss/coreconf/coreconf.dep | 1 + security/nss/cpputil/nss_scoped_ptrs.h | 3 + security/nss/gtests/common/util.h | 91 +++++ security/nss/gtests/pk11_gtest/manifest.mn | 2 + .../pk11_gtest/pk11_find_certs_unittest.cc | 347 ++++++++++++++++++ security/nss/gtests/pk11_gtest/pk11_gtest.gyp | 1 + .../nss/gtests/softoken_gtest/manifest.mn | 1 + .../gtests/softoken_gtest/softoken_gtest.cc | 88 +---- security/nss/gtests/ssl_gtest/ssl_gtest.gyp | 2 +- security/nss/lib/ckfw/builtins/certdata.txt | 166 --------- security/nss/lib/ckfw/builtins/nssckbi.h | 4 +- security/nss/lib/freebl/fipsfreebl.c | 344 ++++++++++++++++- security/nss/lib/freebl/intel-gcm-wrap.c | 1 + security/nss/lib/freebl/pqg.c | 118 +++--- security/nss/lib/freebl/rijndael.c | 8 +- security/nss/lib/nss/nss.def | 6 + security/nss/lib/pk11wrap/pk11obj.c | 92 +++++ security/nss/lib/pk11wrap/pk11pub.h | 11 + security/nss/lib/softoken/pkcs11c.c | 28 +- 21 files changed, 999 insertions(+), 321 deletions(-) create mode 100644 security/nss/gtests/pk11_gtest/pk11_find_certs_unittest.cc diff --git a/security/nss/TAG-INFO b/security/nss/TAG-INFO index ff30ac5d8e95f..c87d07b2306df 100644 --- a/security/nss/TAG-INFO +++ b/security/nss/TAG-INFO @@ -1 +1 @@ -29a48b604602 +8082be3a6363 diff --git a/security/nss/automation/abi-check/expected-report-libnss3.so.txt b/security/nss/automation/abi-check/expected-report-libnss3.so.txt index e69de29bb2d1d..76d0de68876c4 100644 --- a/security/nss/automation/abi-check/expected-report-libnss3.so.txt +++ b/security/nss/automation/abi-check/expected-report-libnss3.so.txt @@ -0,0 +1,4 @@ + +1 Added function: + + 'function SECStatus PK11_FindRawCertsWithSubject(PK11SlotInfo*, SECItem*, CERTCertificateList**)' {PK11_FindRawCertsWithSubject@@NSS_3.45} diff --git a/security/nss/coreconf/coreconf.dep b/security/nss/coreconf/coreconf.dep index 5182f75552c81..590d1bfaeee3f 100644 --- a/security/nss/coreconf/coreconf.dep +++ b/security/nss/coreconf/coreconf.dep @@ -10,3 +10,4 @@ */ #error "Do not include this header file." + diff --git a/security/nss/cpputil/nss_scoped_ptrs.h b/security/nss/cpputil/nss_scoped_ptrs.h index 450e787af53f5..9b1fbb47f019e 100644 --- a/security/nss/cpputil/nss_scoped_ptrs.h +++ b/security/nss/cpputil/nss_scoped_ptrs.h @@ -14,6 +14,7 @@ #include "pk11pqg.h" #include "pk11pub.h" #include "pkcs11uri.h" +#include "secmod.h" struct ScopedDelete { void operator()(CERTCertificate* cert) { CERT_DestroyCertificate(cert); } @@ -47,6 +48,7 @@ struct ScopedDelete { SEC_PKCS12DecoderFinish(dcx); } void operator()(CERTDistNames* names) { CERT_FreeDistNames(names); } + void operator()(SECMODModule* module) { SECMOD_DestroyModule(module); } }; template @@ -82,6 +84,7 @@ SCOPED(PK11Context); SCOPED(PK11GenericObject); SCOPED(SEC_PKCS12DecoderContext); SCOPED(CERTDistNames); +SCOPED(SECMODModule); #undef SCOPED diff --git a/security/nss/gtests/common/util.h b/security/nss/gtests/common/util.h index 7ed1fd7991b53..9a4c8da10623d 100644 --- a/security/nss/gtests/common/util.h +++ b/security/nss/gtests/common/util.h @@ -8,7 +8,21 @@ #define util_h__ #include +#include +#include +#include +#include +#include #include +#if defined(_WIN32) +#include +#include +#include +#else +#include +#endif + +#include "nspr.h" static inline std::vector hex_string_to_bytes(std::string s) { std::vector bytes; @@ -18,4 +32,81 @@ static inline std::vector hex_string_to_bytes(std::string s) { return bytes; } +// Given a prefix, attempts to create a unique directory that the user can do +// work in without impacting other tests. For example, if given the prefix +// "scratch", a directory like "scratch05c17b25" will be created in the current +// working directory (or the location specified by NSS_GTEST_WORKDIR, if +// defined). +// Upon destruction, the implementation will attempt to delete the directory. +// However, no attempt is made to first remove files in the directory - the +// user is responsible for this. If the directory is not empty, deleting it will +// fail. +// Statistically, it is technically possible to fail to create a unique +// directory name, but this is extremely unlikely given the expected workload of +// this implementation. +class ScopedUniqueDirectory { + public: + explicit ScopedUniqueDirectory(const std::string &prefix) { + std::string path; + const char *workingDirectory = PR_GetEnvSecure("NSS_GTEST_WORKDIR"); + if (workingDirectory) { + path.assign(workingDirectory); + } + path.append(prefix); + for (int i = 0; i < RETRY_LIMIT; i++) { + std::string pathCopy(path); + // TryMakingDirectory will modify its input. If it fails, we want to throw + // away the modified result. + if (TryMakingDirectory(pathCopy)) { + mPath.assign(pathCopy); + break; + } + } + assert(mPath.length() > 0); +#if defined(_WIN32) + // sqldb always uses UTF-8 regardless of the current system locale. + DWORD len = + MultiByteToWideChar(CP_ACP, 0, mPath.data(), mPath.size(), nullptr, 0); + std::vector buf(len, L'\0'); + MultiByteToWideChar(CP_ACP, 0, mPath.data(), mPath.size(), buf.data(), + buf.size()); + std::wstring_convert> converter; + mUTF8Path = converter.to_bytes(std::wstring(buf.begin(), buf.end())); +#else + mUTF8Path = mPath; +#endif + } + + // NB: the directory must be empty upon destruction + ~ScopedUniqueDirectory() { assert(rmdir(mPath.c_str()) == 0); } + + const std::string &GetPath() { return mPath; } + const std::string &GetUTF8Path() { return mUTF8Path; } + + private: + static const int RETRY_LIMIT = 5; + + static void GenerateRandomName(/*in/out*/ std::string &prefix) { + std::stringstream ss; + ss << prefix; + // RAND_MAX is at least 32767. + ss << std::setfill('0') << std::setw(4) << std::hex << rand() << rand(); + // This will overwrite the value of prefix. This is a little inefficient, + // but at least it makes the code simple. + ss >> prefix; + } + + static bool TryMakingDirectory(/*in/out*/ std::string &prefix) { + GenerateRandomName(prefix); +#if defined(_WIN32) + return _mkdir(prefix.c_str()) == 0; +#else + return mkdir(prefix.c_str(), 0777) == 0; +#endif + } + + std::string mPath; + std::string mUTF8Path; +}; + #endif // util_h__ diff --git a/security/nss/gtests/pk11_gtest/manifest.mn b/security/nss/gtests/pk11_gtest/manifest.mn index 1e5c2bbad80fb..b774f1d00690c 100644 --- a/security/nss/gtests/pk11_gtest/manifest.mn +++ b/security/nss/gtests/pk11_gtest/manifest.mn @@ -7,6 +7,7 @@ DEPTH = ../.. MODULE = nss CPPSRCS = \ + pk11_aes_gcm_unittest.cc \ pk11_aeskeywrap_unittest.cc \ pk11_cbc_unittest.cc \ pk11_chacha20poly1305_unittest.cc \ @@ -14,6 +15,7 @@ CPPSRCS = \ pk11_ecdsa_unittest.cc \ pk11_encrypt_derive_unittest.cc \ pk11_export_unittest.cc \ + pk11_find_certs_unittest.cc \ pk11_import_unittest.cc \ pk11_pbkdf2_unittest.cc \ pk11_prf_unittest.cc \ diff --git a/security/nss/gtests/pk11_gtest/pk11_find_certs_unittest.cc b/security/nss/gtests/pk11_gtest/pk11_find_certs_unittest.cc new file mode 100644 index 0000000000000..bf7000b016a4f --- /dev/null +++ b/security/nss/gtests/pk11_gtest/pk11_find_certs_unittest.cc @@ -0,0 +1,347 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* vim: set ts=4 et sw=4 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include + +#include "nss.h" +#include "pk11pub.h" +#include "prenv.h" +#include "prerror.h" +#include "secmod.h" + +#include "gtest/gtest.h" +#include "nss_scoped_ptrs.h" +#include "util.h" + +namespace nss_test { + +// These test certificates were generated using pycert/pykey from +// mozilla-central (https://hg.mozilla.org/mozilla-central/file/ ... +// 9968319230a74eb8c1953444a0e6973c7500a9f8/security/manager/ssl/ ... +// tests/unit/pycert.py). + +// issuer:test cert +// subject:test cert +// issuerKey:secp256r1 +// subjectKey:secp256r1 +// serialNumber:1 +std::vector kTestCert1DER = { + 0x30, 0x82, 0x01, 0x1D, 0x30, 0x81, 0xC2, 0xA0, 0x03, 0x02, 0x01, 0x02, + 0x02, 0x01, 0x01, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, + 0x0D, 0x01, 0x01, 0x0B, 0x05, 0x00, 0x30, 0x14, 0x31, 0x12, 0x30, 0x10, + 0x06, 0x03, 0x55, 0x04, 0x03, 0x0C, 0x09, 0x74, 0x65, 0x73, 0x74, 0x20, + 0x63, 0x65, 0x72, 0x74, 0x30, 0x22, 0x18, 0x0F, 0x32, 0x30, 0x31, 0x37, + 0x31, 0x31, 0x32, 0x37, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x5A, 0x18, + 0x0F, 0x32, 0x30, 0x32, 0x30, 0x30, 0x32, 0x30, 0x35, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x5A, 0x30, 0x14, 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, + 0x55, 0x04, 0x03, 0x0C, 0x09, 0x74, 0x65, 0x73, 0x74, 0x20, 0x63, 0x65, + 0x72, 0x74, 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2A, 0x86, 0x48, 0xCE, + 0x3D, 0x02, 0x01, 0x06, 0x08, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x03, 0x01, + 0x07, 0x03, 0x42, 0x00, 0x04, 0x4F, 0xBF, 0xBB, 0xBB, 0x61, 0xE0, 0xF8, + 0xF9, 0xB1, 0xA6, 0x0A, 0x59, 0xAC, 0x87, 0x04, 0xE2, 0xEC, 0x05, 0x0B, + 0x42, 0x3E, 0x3C, 0xF7, 0x2E, 0x92, 0x3F, 0x2C, 0x4F, 0x79, 0x4B, 0x45, + 0x5C, 0x2A, 0x69, 0xD2, 0x33, 0x45, 0x6C, 0x36, 0xC4, 0x11, 0x9D, 0x07, + 0x06, 0xE0, 0x0E, 0xED, 0xC8, 0xD1, 0x93, 0x90, 0xD7, 0x99, 0x1B, 0x7B, + 0x2D, 0x07, 0xA3, 0x04, 0xEA, 0xA0, 0x4A, 0xA6, 0xC0, 0x30, 0x0D, 0x06, + 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0B, 0x05, 0x00, + 0x03, 0x47, 0x00, 0x30, 0x44, 0x02, 0x20, 0x5C, 0x75, 0x51, 0x9F, 0x13, + 0x11, 0x50, 0xCD, 0x5D, 0x8A, 0xDE, 0x20, 0xA3, 0xBC, 0x06, 0x30, 0x91, + 0xFF, 0xB2, 0x73, 0x75, 0x5F, 0x31, 0x64, 0xEC, 0xFD, 0xCB, 0x42, 0x80, + 0x0A, 0x70, 0xE6, 0x02, 0x20, 0x11, 0xFA, 0xA2, 0xCA, 0x06, 0xF3, 0xBC, + 0x5F, 0x8A, 0xCA, 0x17, 0x63, 0x36, 0x87, 0xCF, 0x8D, 0x5C, 0xA0, 0x56, + 0x84, 0x44, 0x61, 0xB2, 0x33, 0x42, 0x07, 0x58, 0x9F, 0x0C, 0x9E, 0x49, + 0x83, +}; + +// issuer:test cert +// subject:test cert +// issuerKey:secp256r1 +// subjectKey:secp256r1 +// serialNumber:2 +std::vector kTestCert2DER = { + 0x30, 0x82, 0x01, 0x1E, 0x30, 0x81, 0xC2, 0xA0, 0x03, 0x02, 0x01, 0x02, + 0x02, 0x01, 0x02, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, + 0x0D, 0x01, 0x01, 0x0B, 0x05, 0x00, 0x30, 0x14, 0x31, 0x12, 0x30, 0x10, + 0x06, 0x03, 0x55, 0x04, 0x03, 0x0C, 0x09, 0x74, 0x65, 0x73, 0x74, 0x20, + 0x63, 0x65, 0x72, 0x74, 0x30, 0x22, 0x18, 0x0F, 0x32, 0x30, 0x31, 0x37, + 0x31, 0x31, 0x32, 0x37, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x5A, 0x18, + 0x0F, 0x32, 0x30, 0x32, 0x30, 0x30, 0x32, 0x30, 0x35, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x5A, 0x30, 0x14, 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, + 0x55, 0x04, 0x03, 0x0C, 0x09, 0x74, 0x65, 0x73, 0x74, 0x20, 0x63, 0x65, + 0x72, 0x74, 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2A, 0x86, 0x48, 0xCE, + 0x3D, 0x02, 0x01, 0x06, 0x08, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x03, 0x01, + 0x07, 0x03, 0x42, 0x00, 0x04, 0x4F, 0xBF, 0xBB, 0xBB, 0x61, 0xE0, 0xF8, + 0xF9, 0xB1, 0xA6, 0x0A, 0x59, 0xAC, 0x87, 0x04, 0xE2, 0xEC, 0x05, 0x0B, + 0x42, 0x3E, 0x3C, 0xF7, 0x2E, 0x92, 0x3F, 0x2C, 0x4F, 0x79, 0x4B, 0x45, + 0x5C, 0x2A, 0x69, 0xD2, 0x33, 0x45, 0x6C, 0x36, 0xC4, 0x11, 0x9D, 0x07, + 0x06, 0xE0, 0x0E, 0xED, 0xC8, 0xD1, 0x93, 0x90, 0xD7, 0x99, 0x1B, 0x7B, + 0x2D, 0x07, 0xA3, 0x04, 0xEA, 0xA0, 0x4A, 0xA6, 0xC0, 0x30, 0x0D, 0x06, + 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0B, 0x05, 0x00, + 0x03, 0x48, 0x00, 0x30, 0x45, 0x02, 0x20, 0x5C, 0x75, 0x51, 0x9F, 0x13, + 0x11, 0x50, 0xCD, 0x5D, 0x8A, 0xDE, 0x20, 0xA3, 0xBC, 0x06, 0x30, 0x91, + 0xFF, 0xB2, 0x73, 0x75, 0x5F, 0x31, 0x64, 0xEC, 0xFD, 0xCB, 0x42, 0x80, + 0x0A, 0x70, 0xE6, 0x02, 0x21, 0x00, 0xF6, 0x5E, 0x42, 0xC7, 0x54, 0x40, + 0x81, 0xE9, 0x4C, 0x16, 0x48, 0xB1, 0x39, 0x0A, 0xA0, 0xE2, 0x8C, 0x23, + 0xAA, 0xC5, 0xBB, 0xAC, 0xEB, 0x9B, 0x15, 0x0B, 0x2F, 0xB7, 0xF5, 0x85, + 0xB2, 0x54, +}; + +std::vector kTestCertSubjectDER = { + 0x30, 0x14, 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, 0x55, 0x04, 0x03, + 0x0C, 0x09, 0x74, 0x65, 0x73, 0x74, 0x20, 0x63, 0x65, 0x72, 0x74, +}; + +// issuer:test cert +// subject:unrelated subject DN +// issuerKey:secp256r1 +// subjectKey:secp256r1 +// serialNumber:3 +std::vector kUnrelatedTestCertDER = { + 0x30, 0x82, 0x01, 0x28, 0x30, 0x81, 0xCD, 0xA0, 0x03, 0x02, 0x01, 0x02, + 0x02, 0x01, 0x03, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, + 0x0D, 0x01, 0x01, 0x0B, 0x05, 0x00, 0x30, 0x14, 0x31, 0x12, 0x30, 0x10, + 0x06, 0x03, 0x55, 0x04, 0x03, 0x0C, 0x09, 0x74, 0x65, 0x73, 0x74, 0x20, + 0x63, 0x65, 0x72, 0x74, 0x30, 0x22, 0x18, 0x0F, 0x32, 0x30, 0x31, 0x37, + 0x31, 0x31, 0x32, 0x37, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x5A, 0x18, + 0x0F, 0x32, 0x30, 0x32, 0x30, 0x30, 0x32, 0x30, 0x35, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x5A, 0x30, 0x1F, 0x31, 0x1D, 0x30, 0x1B, 0x06, 0x03, + 0x55, 0x04, 0x03, 0x0C, 0x14, 0x75, 0x6E, 0x72, 0x65, 0x6C, 0x61, 0x74, + 0x65, 0x64, 0x20, 0x73, 0x75, 0x62, 0x6A, 0x65, 0x63, 0x74, 0x20, 0x44, + 0x4E, 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2A, 0x86, 0x48, 0xCE, 0x3D, + 0x02, 0x01, 0x06, 0x08, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x03, 0x01, 0x07, + 0x03, 0x42, 0x00, 0x04, 0x4F, 0xBF, 0xBB, 0xBB, 0x61, 0xE0, 0xF8, 0xF9, + 0xB1, 0xA6, 0x0A, 0x59, 0xAC, 0x87, 0x04, 0xE2, 0xEC, 0x05, 0x0B, 0x42, + 0x3E, 0x3C, 0xF7, 0x2E, 0x92, 0x3F, 0x2C, 0x4F, 0x79, 0x4B, 0x45, 0x5C, + 0x2A, 0x69, 0xD2, 0x33, 0x45, 0x6C, 0x36, 0xC4, 0x11, 0x9D, 0x07, 0x06, + 0xE0, 0x0E, 0xED, 0xC8, 0xD1, 0x93, 0x90, 0xD7, 0x99, 0x1B, 0x7B, 0x2D, + 0x07, 0xA3, 0x04, 0xEA, 0xA0, 0x4A, 0xA6, 0xC0, 0x30, 0x0D, 0x06, 0x09, + 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0B, 0x05, 0x00, 0x03, + 0x47, 0x00, 0x30, 0x44, 0x02, 0x20, 0x5C, 0x75, 0x51, 0x9F, 0x13, 0x11, + 0x50, 0xCD, 0x5D, 0x8A, 0xDE, 0x20, 0xA3, 0xBC, 0x06, 0x30, 0x91, 0xFF, + 0xB2, 0x73, 0x75, 0x5F, 0x31, 0x64, 0xEC, 0xFD, 0xCB, 0x42, 0x80, 0x0A, + 0x70, 0xE6, 0x02, 0x20, 0x0F, 0x1A, 0x04, 0xC2, 0xF8, 0xBA, 0xC2, 0x94, + 0x26, 0x6E, 0xBC, 0x91, 0x7D, 0xDB, 0x75, 0x7B, 0xE8, 0xA3, 0x4F, 0x69, + 0x1B, 0xF3, 0x1F, 0x2C, 0xCE, 0x82, 0x67, 0xC9, 0x5B, 0xBB, 0xBA, 0x0A, +}; + +class PK11FindRawCertsBySubjectTest : public ::testing::Test { + protected: + PK11FindRawCertsBySubjectTest() + : mSlot(nullptr), mTestCertDBDir("PK11FindRawCertsBySubjectTest-") {} + + virtual void SetUp() { + std::string testCertDBPath(mTestCertDBDir.GetPath()); + const char* testName = + ::testing::UnitTest::GetInstance()->current_test_info()->name(); + std::string modspec = "configDir='sql:"; + modspec.append(testCertDBPath); + modspec.append("' tokenDescription='"); + modspec.append(testName); + modspec.append("'"); + mSlot = SECMOD_OpenUserDB(modspec.c_str()); + ASSERT_NE(mSlot, nullptr); + } + + virtual void TearDown() { + ASSERT_EQ(SECMOD_CloseUserDB(mSlot), SECSuccess); + PK11_FreeSlot(mSlot); + std::string testCertDBPath(mTestCertDBDir.GetPath()); + ASSERT_EQ(0, unlink((testCertDBPath + "/cert9.db").c_str())); + ASSERT_EQ(0, unlink((testCertDBPath + "/key4.db").c_str())); + } + + PK11SlotInfo* mSlot; + ScopedUniqueDirectory mTestCertDBDir; +}; + +// If we don't have any certificates, we shouldn't get any when we search for +// them. +TEST_F(PK11FindRawCertsBySubjectTest, TestNoCertsImportedNoCertsFound) { + SECItem subjectItem = {siBuffer, + const_cast(kTestCertSubjectDER.data()), + (unsigned int)kTestCertSubjectDER.size()}; + CERTCertificateList* certificates = nullptr; + SECStatus rv = + PK11_FindRawCertsWithSubject(mSlot, &subjectItem, &certificates); + EXPECT_EQ(rv, SECSuccess); + EXPECT_EQ(certificates, nullptr); +} + +// If we have one certificate but it has an unrelated subject DN, we shouldn't +// get it when we search. +TEST_F(PK11FindRawCertsBySubjectTest, TestOneCertImportedNoCertsFound) { + char certNickname[] = "Unrelated Cert"; + SECItem certItem = {siBuffer, + const_cast(kUnrelatedTestCertDER.data()), + (unsigned int)kUnrelatedTestCertDER.size()}; + ASSERT_EQ(PK11_ImportDERCert(mSlot, &certItem, CK_INVALID_HANDLE, + certNickname, false), + SECSuccess); + + SECItem subjectItem = {siBuffer, + const_cast(kTestCertSubjectDER.data()), + (unsigned int)kTestCertSubjectDER.size()}; + CERTCertificateList* certificates = nullptr; + SECStatus rv = + PK11_FindRawCertsWithSubject(mSlot, &subjectItem, &certificates); + EXPECT_EQ(rv, SECSuccess); + EXPECT_EQ(certificates, nullptr); +} + +TEST_F(PK11FindRawCertsBySubjectTest, TestMultipleMatchingCertsFound) { + char cert1Nickname[] = "Test Cert 1"; + SECItem cert1Item = {siBuffer, + const_cast(kTestCert1DER.data()), + (unsigned int)kTestCert1DER.size()}; + ASSERT_EQ(PK11_ImportDERCert(mSlot, &cert1Item, CK_INVALID_HANDLE, + cert1Nickname, false), + SECSuccess); + char cert2Nickname[] = "Test Cert 2"; + SECItem cert2Item = {siBuffer, + const_cast(kTestCert2DER.data()), + (unsigned int)kTestCert2DER.size()}; + ASSERT_EQ(PK11_ImportDERCert(mSlot, &cert2Item, CK_INVALID_HANDLE, + cert2Nickname, false), + SECSuccess); + char unrelatedCertNickname[] = "Unrelated Test Cert"; + SECItem unrelatedCertItem = { + siBuffer, const_cast(kUnrelatedTestCertDER.data()), + (unsigned int)kUnrelatedTestCertDER.size()}; + ASSERT_EQ(PK11_ImportDERCert(mSlot, &unrelatedCertItem, CK_INVALID_HANDLE, + unrelatedCertNickname, false), + SECSuccess); + + CERTCertificateList* certificates = nullptr; + SECItem subjectItem = {siBuffer, + const_cast(kTestCertSubjectDER.data()), + (unsigned int)kTestCertSubjectDER.size()}; + SECStatus rv = + PK11_FindRawCertsWithSubject(mSlot, &subjectItem, &certificates); + EXPECT_EQ(rv, SECSuccess); + ASSERT_NE(certificates, nullptr); + ScopedCERTCertificateList scopedCertificates(certificates); + ASSERT_EQ(scopedCertificates->len, 2); + + std::vector foundCert1( + scopedCertificates->certs[0].data, + scopedCertificates->certs[0].data + scopedCertificates->certs[0].len); + std::vector foundCert2( + scopedCertificates->certs[1].data, + scopedCertificates->certs[1].data + scopedCertificates->certs[1].len); + EXPECT_TRUE(foundCert1 == kTestCert1DER || foundCert1 == kTestCert2DER); + EXPECT_TRUE(foundCert2 == kTestCert1DER || foundCert2 == kTestCert2DER); + EXPECT_TRUE(foundCert1 != foundCert2); +} + +// If we try to search the internal slots, we won't find the certificate we just +// imported (because it's on a different slot). +TEST_F(PK11FindRawCertsBySubjectTest, TestNoCertsOnInternalSlots) { + char cert1Nickname[] = "Test Cert 1"; + SECItem cert1Item = {siBuffer, + const_cast(kTestCert1DER.data()), + (unsigned int)kTestCert1DER.size()}; + ASSERT_EQ(PK11_ImportDERCert(mSlot, &cert1Item, CK_INVALID_HANDLE, + cert1Nickname, false), + SECSuccess); + + SECItem subjectItem = {siBuffer, + const_cast(kTestCertSubjectDER.data()), + (unsigned int)kTestCertSubjectDER.size()}; + CERTCertificateList* internalKeySlotCertificates = nullptr; + ScopedPK11SlotInfo internalKeySlot(PK11_GetInternalKeySlot()); + SECStatus rv = PK11_FindRawCertsWithSubject( + internalKeySlot.get(), &subjectItem, &internalKeySlotCertificates); + EXPECT_EQ(rv, SECSuccess); + EXPECT_EQ(internalKeySlotCertificates, nullptr); + + CERTCertificateList* internalSlotCertificates = nullptr; + ScopedPK11SlotInfo internalSlot(PK11_GetInternalSlot()); + rv = PK11_FindRawCertsWithSubject(internalSlot.get(), &subjectItem, + &internalSlotCertificates); + EXPECT_EQ(rv, SECSuccess); + EXPECT_EQ(internalSlotCertificates, nullptr); +} + +// issuer:test cert +// subject:(empty - this had to be done by hand as pycert doesn't support this) +// issuerKey:secp256r1 +// subjectKey:secp256r1 +// serialNumber:4 +std::vector kEmptySubjectCertDER = { + 0x30, 0x82, 0x01, 0x09, 0x30, 0x81, 0xAE, 0xA0, 0x03, 0x02, 0x01, 0x02, + 0x02, 0x01, 0x04, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, + 0x0D, 0x01, 0x01, 0x0B, 0x05, 0x00, 0x30, 0x14, 0x31, 0x12, 0x30, 0x10, + 0x06, 0x03, 0x55, 0x04, 0x03, 0x0C, 0x09, 0x74, 0x65, 0x73, 0x74, 0x20, + 0x63, 0x65, 0x72, 0x74, 0x30, 0x22, 0x18, 0x0F, 0x32, 0x30, 0x31, 0x37, + 0x31, 0x31, 0x32, 0x37, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x5A, 0x18, + 0x0F, 0x32, 0x30, 0x32, 0x30, 0x30, 0x32, 0x30, 0x35, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x5A, 0x30, 0x00, 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, + 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x02, 0x01, 0x06, 0x08, 0x2A, 0x86, 0x48, + 0xCE, 0x3D, 0x03, 0x01, 0x07, 0x03, 0x42, 0x00, 0x04, 0x4F, 0xBF, 0xBB, + 0xBB, 0x61, 0xE0, 0xF8, 0xF9, 0xB1, 0xA6, 0x0A, 0x59, 0xAC, 0x87, 0x04, + 0xE2, 0xEC, 0x05, 0x0B, 0x42, 0x3E, 0x3C, 0xF7, 0x2E, 0x92, 0x3F, 0x2C, + 0x4F, 0x79, 0x4B, 0x45, 0x5C, 0x2A, 0x69, 0xD2, 0x33, 0x45, 0x6C, 0x36, + 0xC4, 0x11, 0x9D, 0x07, 0x06, 0xE0, 0x0E, 0xED, 0xC8, 0xD1, 0x93, 0x90, + 0xD7, 0x99, 0x1B, 0x7B, 0x2D, 0x07, 0xA3, 0x04, 0xEA, 0xA0, 0x4A, 0xA6, + 0xC0, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, + 0x01, 0x0B, 0x05, 0x00, 0x03, 0x47, 0x00, 0x30, 0x44, 0x02, 0x20, 0x5C, + 0x75, 0x51, 0x9F, 0x13, 0x11, 0x50, 0xCD, 0x5D, 0x8A, 0xDE, 0x20, 0xA3, + 0xBC, 0x06, 0x30, 0x91, 0xFF, 0xB2, 0x73, 0x75, 0x5F, 0x31, 0x64, 0xEC, + 0xFD, 0xCB, 0x42, 0x80, 0x0A, 0x70, 0xE6, 0x02, 0x20, 0x31, 0x1B, 0x92, + 0xAA, 0xA8, 0xB7, 0x51, 0x52, 0x7B, 0x64, 0xD6, 0xF7, 0x2F, 0x0C, 0xFB, + 0xBB, 0xD5, 0xDF, 0x86, 0xA3, 0x97, 0x96, 0x60, 0x42, 0xDA, 0xD4, 0xA8, + 0x5F, 0x2F, 0xA4, 0xDE, 0x7C}; + +std::vector kEmptySubjectDER = {0x30, 0x00}; + +// This certificate has the smallest possible subject. Finding it should work. +TEST_F(PK11FindRawCertsBySubjectTest, TestFindEmptySubject) { + char emptySubjectCertNickname[] = "Empty Subject Cert"; + SECItem emptySubjectCertItem = { + siBuffer, const_cast(kEmptySubjectCertDER.data()), + (unsigned int)kEmptySubjectCertDER.size()}; + ASSERT_EQ(PK11_ImportDERCert(mSlot, &emptySubjectCertItem, CK_INVALID_HANDLE, + emptySubjectCertNickname, false), + SECSuccess); + + SECItem subjectItem = {siBuffer, + const_cast(kEmptySubjectDER.data()), + (unsigned int)kEmptySubjectDER.size()}; + CERTCertificateList* certificates = nullptr; + SECStatus rv = + PK11_FindRawCertsWithSubject(mSlot, &subjectItem, &certificates); + EXPECT_EQ(rv, SECSuccess); + ASSERT_NE(certificates, nullptr); + ScopedCERTCertificateList scopedCertificates(certificates); + ASSERT_EQ(scopedCertificates->len, 1); + + std::vector foundCert( + scopedCertificates->certs[0].data, + scopedCertificates->certs[0].data + scopedCertificates->certs[0].len); + EXPECT_EQ(foundCert, kEmptySubjectCertDER); +} + +// Searching for a zero-length subject doesn't make sense (the minimum subject +// is the SEQUENCE tag followed by a length byte of 0), but it shouldn't cause +// problems. +TEST_F(PK11FindRawCertsBySubjectTest, TestSearchForNullSubject) { + char cert1Nickname[] = "Test Cert 1"; + SECItem cert1Item = {siBuffer, + const_cast(kTestCert1DER.data()), + (unsigned int)kTestCert1DER.size()}; + ASSERT_EQ(PK11_ImportDERCert(mSlot, &cert1Item, CK_INVALID_HANDLE, + cert1Nickname, false), + SECSuccess); + + SECItem subjectItem = {siBuffer, nullptr, 0}; + CERTCertificateList* certificates = nullptr; + SECStatus rv = + PK11_FindRawCertsWithSubject(mSlot, &subjectItem, &certificates); + EXPECT_EQ(rv, SECSuccess); + EXPECT_EQ(certificates, nullptr); +} + +} // namespace nss_test diff --git a/security/nss/gtests/pk11_gtest/pk11_gtest.gyp b/security/nss/gtests/pk11_gtest/pk11_gtest.gyp index 0ffed1f9c3940..8d7bf7e8e023e 100644 --- a/security/nss/gtests/pk11_gtest/pk11_gtest.gyp +++ b/security/nss/gtests/pk11_gtest/pk11_gtest.gyp @@ -19,6 +19,7 @@ 'pk11_curve25519_unittest.cc', 'pk11_ecdsa_unittest.cc', 'pk11_encrypt_derive_unittest.cc', + 'pk11_find_certs_unittest.cc', 'pk11_import_unittest.cc', 'pk11_pbkdf2_unittest.cc', 'pk11_prf_unittest.cc', diff --git a/security/nss/gtests/softoken_gtest/manifest.mn b/security/nss/gtests/softoken_gtest/manifest.mn index 4b34c099f5761..0e998adf4c15b 100644 --- a/security/nss/gtests/softoken_gtest/manifest.mn +++ b/security/nss/gtests/softoken_gtest/manifest.mn @@ -12,6 +12,7 @@ CPPSRCS = \ INCLUDES += \ -I$(CORE_DEPTH)/gtests/google_test/gtest/include \ + -I$(CORE_DEPTH)/gtests/common \ -I$(CORE_DEPTH)/cpputil \ $(NULL) diff --git a/security/nss/gtests/softoken_gtest/softoken_gtest.cc b/security/nss/gtests/softoken_gtest/softoken_gtest.cc index 5e2a497b8b0a2..c6cd32afdb63e 100644 --- a/security/nss/gtests/softoken_gtest/softoken_gtest.cc +++ b/security/nss/gtests/softoken_gtest/softoken_gtest.cc @@ -1,9 +1,3 @@ -#include -#if defined(_WIN32) -#include -#include -#endif - #include "cert.h" #include "certdb.h" #include "nspr.h" @@ -12,93 +6,13 @@ #include "secerr.h" #include "nss_scoped_ptrs.h" +#include "util.h" #define GTEST_HAS_RTTI 0 #include "gtest/gtest.h" namespace nss_test { -// Given a prefix, attempts to create a unique directory that the user can do -// work in without impacting other tests. For example, if given the prefix -// "scratch", a directory like "scratch05c17b25" will be created in the current -// working directory (or the location specified by NSS_GTEST_WORKDIR, if -// defined). -// Upon destruction, the implementation will attempt to delete the directory. -// However, no attempt is made to first remove files in the directory - the -// user is responsible for this. If the directory is not empty, deleting it will -// fail. -// Statistically, it is technically possible to fail to create a unique -// directory name, but this is extremely unlikely given the expected workload of -// this implementation. -class ScopedUniqueDirectory { - public: - explicit ScopedUniqueDirectory(const std::string &prefix); - - // NB: the directory must be empty upon destruction - ~ScopedUniqueDirectory() { assert(rmdir(mPath.c_str()) == 0); } - - const std::string &GetPath() { return mPath; } - const std::string &GetUTF8Path() { return mUTF8Path; } - - private: - static const int RETRY_LIMIT = 5; - static void GenerateRandomName(/*in/out*/ std::string &prefix); - static bool TryMakingDirectory(/*in/out*/ std::string &prefix); - - std::string mPath; - std::string mUTF8Path; -}; - -ScopedUniqueDirectory::ScopedUniqueDirectory(const std::string &prefix) { - std::string path; - const char *workingDirectory = PR_GetEnvSecure("NSS_GTEST_WORKDIR"); - if (workingDirectory) { - path.assign(workingDirectory); - } - path.append(prefix); - for (int i = 0; i < RETRY_LIMIT; i++) { - std::string pathCopy(path); - // TryMakingDirectory will modify its input. If it fails, we want to throw - // away the modified result. - if (TryMakingDirectory(pathCopy)) { - mPath.assign(pathCopy); - break; - } - } - assert(mPath.length() > 0); -#if defined(_WIN32) - // sqldb always uses UTF-8 regardless of the current system locale. - DWORD len = - MultiByteToWideChar(CP_ACP, 0, mPath.data(), mPath.size(), nullptr, 0); - std::vector buf(len, L'\0'); - MultiByteToWideChar(CP_ACP, 0, mPath.data(), mPath.size(), buf.data(), - buf.size()); - std::wstring_convert> converter; - mUTF8Path = converter.to_bytes(std::wstring(buf.begin(), buf.end())); -#else - mUTF8Path = mPath; -#endif -} - -void ScopedUniqueDirectory::GenerateRandomName(std::string &prefix) { - std::stringstream ss; - ss << prefix; - // RAND_MAX is at least 32767. - ss << std::setfill('0') << std::setw(4) << std::hex << rand() << rand(); - // This will overwrite the value of prefix. This is a little inefficient, but - // at least it makes the code simple. - ss >> prefix; -} - -bool ScopedUniqueDirectory::TryMakingDirectory(std::string &prefix) { - GenerateRandomName(prefix); -#if defined(_WIN32) - return _mkdir(prefix.c_str()) == 0; -#else - return mkdir(prefix.c_str(), 0777) == 0; -#endif -} - class SoftokenTest : public ::testing::Test { protected: SoftokenTest() : mNSSDBDir("SoftokenTest.d-") {} diff --git a/security/nss/gtests/ssl_gtest/ssl_gtest.gyp b/security/nss/gtests/ssl_gtest/ssl_gtest.gyp index 304e8da176264..c0f6c1cd22b9a 100644 --- a/security/nss/gtests/ssl_gtest/ssl_gtest.gyp +++ b/security/nss/gtests/ssl_gtest/ssl_gtest.gyp @@ -93,7 +93,7 @@ '<(DEPTH)/lib/dbm/src/src.gyp:dbm', ], }], - [ 'enable_sslkeylogfile==1', { + [ 'enable_sslkeylogfile==1 and sanitizer_flags==0', { 'sources': [ 'ssl_keylog_unittest.cc', ], diff --git a/security/nss/lib/ckfw/builtins/certdata.txt b/security/nss/lib/ckfw/builtins/certdata.txt index 61ce1dee63db3..3466f6ee40ed9 100644 --- a/security/nss/lib/ckfw/builtins/certdata.txt +++ b/security/nss/lib/ckfw/builtins/certdata.txt @@ -17745,172 +17745,6 @@ CKA_TRUST_EMAIL_PROTECTION CK_TRUST CKT_NSS_MUST_VERIFY_TRUST CKA_TRUST_CODE_SIGNING CK_TRUST CKT_NSS_MUST_VERIFY_TRUST CKA_TRUST_STEP_UP_APPROVED CK_BBOOL CK_FALSE -# -# Certificate "Certinomis - Root CA" -# -# Issuer: CN=Certinomis - Root CA,OU=0002 433998903,O=Certinomis,C=FR -# Serial Number: 1 (0x1) -# Subject: CN=Certinomis - Root CA,OU=0002 433998903,O=Certinomis,C=FR -# Not Valid Before: Mon Oct 21 09:17:18 2013 -# Not Valid After : Fri Oct 21 09:17:18 2033 -# Fingerprint (SHA-256): 2A:99:F5:BC:11:74:B7:3C:BB:1D:62:08:84:E0:1C:34:E5:1C:CB:39:78:DA:12:5F:0E:33:26:88:83:BF:41:58 -# Fingerprint (SHA1): 9D:70:BB:01:A5:A4:A0:18:11:2E:F7:1C:01:B9:32:C5:34:E7:88:A8 -CKA_CLASS CK_OBJECT_CLASS CKO_CERTIFICATE -CKA_TOKEN CK_BBOOL CK_TRUE -CKA_PRIVATE CK_BBOOL CK_FALSE -CKA_MODIFIABLE CK_BBOOL CK_FALSE -CKA_LABEL UTF8 "Certinomis - Root CA" -CKA_CERTIFICATE_TYPE CK_CERTIFICATE_TYPE CKC_X_509 -CKA_SUBJECT MULTILINE_OCTAL -\060\132\061\013\060\011\006\003\125\004\006\023\002\106\122\061 -\023\060\021\006\003\125\004\012\023\012\103\145\162\164\151\156 -\157\155\151\163\061\027\060\025\006\003\125\004\013\023\016\060 -\060\060\062\040\064\063\063\071\071\070\071\060\063\061\035\060 -\033\006\003\125\004\003\023\024\103\145\162\164\151\156\157\155 -\151\163\040\055\040\122\157\157\164\040\103\101 -END -CKA_ID UTF8 "0" -CKA_ISSUER MULTILINE_OCTAL -\060\132\061\013\060\011\006\003\125\004\006\023\002\106\122\061 -\023\060\021\006\003\125\004\012\023\012\103\145\162\164\151\156 -\157\155\151\163\061\027\060\025\006\003\125\004\013\023\016\060 -\060\060\062\040\064\063\063\071\071\070\071\060\063\061\035\060 -\033\006\003\125\004\003\023\024\103\145\162\164\151\156\157\155 -\151\163\040\055\040\122\157\157\164\040\103\101 -END -CKA_SERIAL_NUMBER MULTILINE_OCTAL -\002\001\001 -END -CKA_VALUE MULTILINE_OCTAL -\060\202\005\222\060\202\003\172\240\003\002\001\002\002\001\001 -\060\015\006\011\052\206\110\206\367\015\001\001\013\005\000\060 -\132\061\013\060\011\006\003\125\004\006\023\002\106\122\061\023 -\060\021\006\003\125\004\012\023\012\103\145\162\164\151\156\157 -\155\151\163\061\027\060\025\006\003\125\004\013\023\016\060\060 -\060\062\040\064\063\063\071\071\070\071\060\063\061\035\060\033 -\006\003\125\004\003\023\024\103\145\162\164\151\156\157\155\151 -\163\040\055\040\122\157\157\164\040\103\101\060\036\027\015\061 -\063\061\060\062\061\060\071\061\067\061\070\132\027\015\063\063 -\061\060\062\061\060\071\061\067\061\070\132\060\132\061\013\060 -\011\006\003\125\004\006\023\002\106\122\061\023\060\021\006\003 -\125\004\012\023\012\103\145\162\164\151\156\157\155\151\163\061 -\027\060\025\006\003\125\004\013\023\016\060\060\060\062\040\064 -\063\063\071\071\070\071\060\063\061\035\060\033\006\003\125\004 -\003\023\024\103\145\162\164\151\156\157\155\151\163\040\055\040 -\122\157\157\164\040\103\101\060\202\002\042\060\015\006\011\052 -\206\110\206\367\015\001\001\001\005\000\003\202\002\017\000\060 -\202\002\012\002\202\002\001\000\324\314\011\012\054\077\222\366 -\177\024\236\013\234\232\152\035\100\060\144\375\252\337\016\036 -\006\133\237\120\205\352\315\215\253\103\147\336\260\372\176\200 -\226\236\204\170\222\110\326\343\071\356\316\344\131\130\227\345 -\056\047\230\352\223\250\167\233\112\360\357\164\200\055\353\060 -\037\265\331\307\200\234\142\047\221\210\360\112\211\335\334\210 -\346\024\371\325\003\057\377\225\333\275\237\354\054\372\024\025 -\131\225\012\306\107\174\151\030\271\247\003\371\312\166\251\317 -\307\157\264\136\005\376\356\301\122\262\165\062\207\354\355\051 -\146\073\363\112\026\202\366\326\232\333\162\230\351\336\360\305 -\114\245\253\265\352\001\342\214\056\144\177\144\157\375\243\045 -\223\213\310\242\016\111\215\064\360\037\354\130\105\056\064\252 -\204\120\275\347\262\112\023\270\260\017\256\070\135\260\251\033 -\346\163\311\132\241\331\146\100\252\251\115\246\064\002\255\204 -\176\262\043\301\373\052\306\147\364\064\266\260\225\152\063\117 -\161\104\265\255\300\171\063\210\340\277\355\243\240\024\264\234 -\011\260\012\343\140\276\370\370\146\210\315\133\361\167\005\340 -\265\163\156\301\175\106\056\216\113\047\246\315\065\012\375\345 -\115\175\252\052\243\051\307\132\150\004\350\345\326\223\244\142 -\302\305\346\364\117\306\371\237\032\215\202\111\031\212\312\131 -\103\072\350\015\062\301\364\114\023\003\157\156\246\077\221\163 -\313\312\163\157\022\040\213\356\300\202\170\336\113\056\302\111 -\303\035\355\026\366\044\364\047\033\134\127\061\334\125\356\250 -\036\157\154\254\342\105\314\127\127\212\165\127\031\340\265\130 -\231\111\066\061\074\063\001\155\026\112\315\270\052\203\204\206 -\233\371\140\322\037\155\221\003\323\140\246\325\075\232\335\167 -\220\075\065\244\237\017\136\365\122\104\151\271\300\272\334\317 -\175\337\174\331\304\254\206\042\062\274\173\153\221\357\172\370 -\027\150\260\342\123\125\140\055\257\076\302\203\330\331\011\053 -\360\300\144\333\207\213\221\314\221\353\004\375\166\264\225\232 -\346\024\006\033\325\064\035\276\330\377\164\034\123\205\231\340 -\131\122\112\141\355\210\236\153\111\211\106\176\040\132\331\347 -\112\345\152\356\322\145\021\103\002\003\001\000\001\243\143\060 -\141\060\016\006\003\125\035\017\001\001\377\004\004\003\002\001 -\006\060\017\006\003\125\035\023\001\001\377\004\005\060\003\001 -\001\377\060\035\006\003\125\035\016\004\026\004\024\357\221\114 -\365\245\303\060\350\057\010\352\323\161\042\244\222\150\170\164 -\331\060\037\006\003\125\035\043\004\030\060\026\200\024\357\221 -\114\365\245\303\060\350\057\010\352\323\161\042\244\222\150\170 -\164\331\060\015\006\011\052\206\110\206\367\015\001\001\013\005 -\000\003\202\002\001\000\176\075\124\332\042\135\032\130\076\073 -\124\047\272\272\314\310\343\032\152\352\076\371\022\353\126\137 -\075\120\316\340\352\110\046\046\317\171\126\176\221\034\231\077 -\320\241\221\034\054\017\117\230\225\131\123\275\320\042\330\210 -\135\234\067\374\373\144\301\170\214\213\232\140\011\352\325\372 -\041\137\320\164\145\347\120\305\277\056\271\013\013\255\265\260 -\027\246\022\214\324\142\170\352\126\152\354\012\322\100\303\074 -\005\060\076\115\224\267\237\112\003\323\175\047\113\266\376\104 -\316\372\031\063\032\155\244\102\321\335\314\310\310\327\026\122 -\203\117\065\224\263\022\125\175\345\342\102\353\344\234\223\011 -\300\114\133\007\253\307\155\021\240\120\027\224\043\250\265\012 -\222\017\262\172\301\140\054\070\314\032\246\133\377\362\014\343 -\252\037\034\334\270\240\223\047\336\143\343\177\041\237\072\345 -\236\372\340\023\152\165\353\226\134\142\221\224\216\147\123\266 -\211\370\022\011\313\157\122\133\003\162\206\120\225\010\324\215 -\207\206\025\037\225\044\330\244\157\232\316\244\235\233\155\322 -\262\166\006\206\306\126\010\305\353\011\332\066\302\033\133\101 -\276\141\052\343\160\346\270\246\370\266\132\304\275\041\367\377 -\252\137\241\154\166\071\146\326\352\114\125\341\000\063\233\023 -\230\143\311\157\320\001\040\011\067\122\347\014\117\076\315\274 -\365\137\226\047\247\040\002\225\340\056\350\007\101\005\037\025 -\156\326\260\344\031\340\017\002\223\000\047\162\305\213\321\124 -\037\135\112\303\100\227\176\125\246\174\301\063\004\024\001\035 -\111\040\151\013\031\223\235\156\130\042\367\100\014\106\014\043 -\143\363\071\322\177\166\121\247\364\310\241\361\014\166\042\043 -\106\122\051\055\342\243\101\007\126\151\230\322\005\011\274\151 -\307\132\141\315\217\201\140\025\115\200\335\220\342\175\304\120 -\362\214\073\156\112\307\306\346\200\053\074\201\274\021\200\026 -\020\047\327\360\315\077\171\314\163\052\303\176\123\221\326\156 -\370\365\363\307\320\121\115\216\113\245\133\346\031\027\073\326 -\201\011\334\042\334\356\216\271\304\217\123\341\147\273\063\270 -\210\025\106\317\355\151\065\377\165\015\106\363\316\161\341\305 -\153\206\102\006\271\101 -END -CKA_NSS_MOZILLA_CA_POLICY CK_BBOOL CK_TRUE - -# Trust for "Certinomis - Root CA" -# Issuer: CN=Certinomis - Root CA,OU=0002 433998903,O=Certinomis,C=FR -# Serial Number: 1 (0x1) -# Subject: CN=Certinomis - Root CA,OU=0002 433998903,O=Certinomis,C=FR -# Not Valid Before: Mon Oct 21 09:17:18 2013 -# Not Valid After : Fri Oct 21 09:17:18 2033 -# Fingerprint (SHA-256): 2A:99:F5:BC:11:74:B7:3C:BB:1D:62:08:84:E0:1C:34:E5:1C:CB:39:78:DA:12:5F:0E:33:26:88:83:BF:41:58 -# Fingerprint (SHA1): 9D:70:BB:01:A5:A4:A0:18:11:2E:F7:1C:01:B9:32:C5:34:E7:88:A8 -CKA_CLASS CK_OBJECT_CLASS CKO_NSS_TRUST -CKA_TOKEN CK_BBOOL CK_TRUE -CKA_PRIVATE CK_BBOOL CK_FALSE -CKA_MODIFIABLE CK_BBOOL CK_FALSE -CKA_LABEL UTF8 "Certinomis - Root CA" -CKA_CERT_SHA1_HASH MULTILINE_OCTAL -\235\160\273\001\245\244\240\030\021\056\367\034\001\271\062\305 -\064\347\210\250 -END -CKA_CERT_MD5_HASH MULTILINE_OCTAL -\024\012\375\215\250\050\265\070\151\333\126\176\141\042\003\077 -END -CKA_ISSUER MULTILINE_OCTAL -\060\132\061\013\060\011\006\003\125\004\006\023\002\106\122\061 -\023\060\021\006\003\125\004\012\023\012\103\145\162\164\151\156 -\157\155\151\163\061\027\060\025\006\003\125\004\013\023\016\060 -\060\060\062\040\064\063\063\071\071\070\071\060\063\061\035\060 -\033\006\003\125\004\003\023\024\103\145\162\164\151\156\157\155 -\151\163\040\055\040\122\157\157\164\040\103\101 -END -CKA_SERIAL_NUMBER MULTILINE_OCTAL -\002\001\001 -END -CKA_TRUST_SERVER_AUTH CK_TRUST CKT_NSS_TRUSTED_DELEGATOR -CKA_TRUST_EMAIL_PROTECTION CK_TRUST CKT_NSS_MUST_VERIFY_TRUST -CKA_TRUST_CODE_SIGNING CK_TRUST CKT_NSS_MUST_VERIFY_TRUST -CKA_TRUST_STEP_UP_APPROVED CK_BBOOL CK_FALSE - # # Certificate "OISTE WISeKey Global Root GB CA" # diff --git a/security/nss/lib/ckfw/builtins/nssckbi.h b/security/nss/lib/ckfw/builtins/nssckbi.h index 953c15b0a93d5..d46217eb46fc9 100644 --- a/security/nss/lib/ckfw/builtins/nssckbi.h +++ b/security/nss/lib/ckfw/builtins/nssckbi.h @@ -46,8 +46,8 @@ * It's recommend to switch back to 0 after having reached version 98/99. */ #define NSS_BUILTINS_LIBRARY_VERSION_MAJOR 2 -#define NSS_BUILTINS_LIBRARY_VERSION_MINOR 32 -#define NSS_BUILTINS_LIBRARY_VERSION "2.32" +#define NSS_BUILTINS_LIBRARY_VERSION_MINOR 34 +#define NSS_BUILTINS_LIBRARY_VERSION "2.34" /* These version numbers detail the semantic changes to the ckfw engine. */ #define NSS_BUILTINS_HARDWARE_VERSION_MAJOR 1 diff --git a/security/nss/lib/freebl/fipsfreebl.c b/security/nss/lib/freebl/fipsfreebl.c index 2328a677f48eb..93a9a0de72b5a 100644 --- a/security/nss/lib/freebl/fipsfreebl.c +++ b/security/nss/lib/freebl/fipsfreebl.c @@ -15,8 +15,10 @@ #include "seccomon.h" /* Required for RSA and DSA. */ #include "secerr.h" #include "prtypes.h" +#include "secitem.h" +#include "pkcs11t.h" -#include "ec.h" /* Required for ECDSA */ +#include "ec.h" /* Required for EC */ /* * different platforms have different ways of calling and initial entry point @@ -288,6 +290,8 @@ freebl_fips_AES_PowerUpSelfTest(int aes_key_size) /* AES Known Plaintext (128-bits). (blocksize is 128-bits) */ static const PRUint8 aes_known_plaintext[] = { "NetscapeepacsteN" }; + static const PRUint8 aes_gcm_known_aad[] = { "MozillaallizoM" }; + /* AES Known Ciphertext (128-bit key). */ static const PRUint8 aes_ecb128_known_ciphertext[] = { 0x3c, 0xa5, 0x96, 0xf3, 0x34, 0x6a, 0x96, 0xc1, @@ -299,6 +303,13 @@ freebl_fips_AES_PowerUpSelfTest(int aes_key_size) 0x15, 0x54, 0x14, 0x1d, 0x4e, 0xd8, 0xd5, 0xea }; + static const PRUint8 aes_gcm128_known_ciphertext[] = { + 0x63, 0xf4, 0x95, 0x28, 0xe6, 0x78, 0xee, 0x6e, + 0x4f, 0xe0, 0xfc, 0x8d, 0xd7, 0xa2, 0xb1, 0xff, + 0x0c, 0x97, 0x1b, 0x0a, 0xdd, 0x97, 0x75, 0xed, + 0x8b, 0xde, 0xbf, 0x16, 0x5e, 0x57, 0x6b, 0x4f + }; + /* AES Known Ciphertext (192-bit key). */ static const PRUint8 aes_ecb192_known_ciphertext[] = { 0xa0, 0x18, 0x62, 0xed, 0x88, 0x19, 0xcb, 0x62, @@ -310,6 +321,13 @@ freebl_fips_AES_PowerUpSelfTest(int aes_key_size) 0x07, 0xbc, 0x43, 0x2f, 0x6d, 0xad, 0x29, 0xe1 }; + static const PRUint8 aes_gcm192_known_ciphertext[] = { + 0xc1, 0x0b, 0x92, 0x1d, 0x68, 0x21, 0xf4, 0x25, + 0x41, 0x61, 0x20, 0x2d, 0x59, 0x7f, 0x53, 0xde, + 0x93, 0x39, 0xab, 0x09, 0x76, 0x41, 0x57, 0x2b, + 0x90, 0x2e, 0x44, 0xbb, 0x52, 0x03, 0xe9, 0x07 + }; + /* AES Known Ciphertext (256-bit key). */ static const PRUint8 aes_ecb256_known_ciphertext[] = { 0xdb, 0xa6, 0x52, 0x01, 0x8a, 0x70, 0xae, 0x66, @@ -321,18 +339,29 @@ freebl_fips_AES_PowerUpSelfTest(int aes_key_size) 0xc5, 0xc5, 0x68, 0x71, 0x6e, 0x34, 0x40, 0x16 }; + static const PRUint8 aes_gcm256_known_ciphertext[] = { + 0x5d, 0x9e, 0xd2, 0xa2, 0x74, 0x9c, 0xd9, 0x1c, + 0xd1, 0xc9, 0xee, 0x5d, 0xb6, 0xf2, 0xc9, 0xb6, + 0x79, 0x27, 0x53, 0x02, 0xa3, 0xdc, 0x22, 0xce, + 0xf4, 0xb0, 0xc1, 0x8c, 0x86, 0x51, 0xf5, 0xa1 + }; + const PRUint8 *aes_ecb_known_ciphertext = (aes_key_size == FIPS_AES_128_KEY_SIZE) ? aes_ecb128_known_ciphertext : (aes_key_size == FIPS_AES_192_KEY_SIZE) ? aes_ecb192_known_ciphertext : aes_ecb256_known_ciphertext; const PRUint8 *aes_cbc_known_ciphertext = (aes_key_size == FIPS_AES_128_KEY_SIZE) ? aes_cbc128_known_ciphertext : (aes_key_size == FIPS_AES_192_KEY_SIZE) ? aes_cbc192_known_ciphertext : aes_cbc256_known_ciphertext; + const PRUint8 *aes_gcm_known_ciphertext = + (aes_key_size == FIPS_AES_128_KEY_SIZE) ? aes_gcm128_known_ciphertext : (aes_key_size == FIPS_AES_192_KEY_SIZE) ? aes_gcm192_known_ciphertext : aes_gcm256_known_ciphertext; + /* AES variables. */ - PRUint8 aes_computed_ciphertext[FIPS_AES_ENCRYPT_LENGTH]; - PRUint8 aes_computed_plaintext[FIPS_AES_DECRYPT_LENGTH]; + PRUint8 aes_computed_ciphertext[FIPS_AES_ENCRYPT_LENGTH * 2]; + PRUint8 aes_computed_plaintext[FIPS_AES_DECRYPT_LENGTH * 2]; AESContext *aes_context; unsigned int aes_bytes_encrypted; unsigned int aes_bytes_decrypted; + CK_GCM_PARAMS gcmParams; SECStatus aes_status; /*check if aes_key_size is 128, 192, or 256 bits */ @@ -455,6 +484,69 @@ freebl_fips_AES_PowerUpSelfTest(int aes_key_size) return (SECFailure); } + /******************************************************/ + /* AES-GCM Single-Round Known Answer Encryption Test. */ + /******************************************************/ + + gcmParams.pIv = (PRUint8 *)aes_cbc_known_initialization_vector; + gcmParams.ulIvLen = FIPS_AES_BLOCK_SIZE; + gcmParams.pAAD = (PRUint8 *)aes_gcm_known_aad; + gcmParams.ulAADLen = sizeof(aes_gcm_known_aad); + gcmParams.ulTagBits = FIPS_AES_BLOCK_SIZE * 8; + aes_context = AES_CreateContext(aes_known_key, + (PRUint8 *)&gcmParams, + NSS_AES_GCM, PR_TRUE, aes_key_size, + FIPS_AES_BLOCK_SIZE); + + if (aes_context == NULL) { + PORT_SetError(SEC_ERROR_NO_MEMORY); + return (SECFailure); + } + + aes_status = AES_Encrypt(aes_context, aes_computed_ciphertext, + &aes_bytes_encrypted, FIPS_AES_ENCRYPT_LENGTH * 2, + aes_known_plaintext, + FIPS_AES_DECRYPT_LENGTH); + + AES_DestroyContext(aes_context, PR_TRUE); + + if ((aes_status != SECSuccess) || + (aes_bytes_encrypted != FIPS_AES_ENCRYPT_LENGTH * 2) || + (PORT_Memcmp(aes_computed_ciphertext, aes_gcm_known_ciphertext, + FIPS_AES_ENCRYPT_LENGTH * 2) != 0)) { + PORT_SetError(SEC_ERROR_LIBRARY_FAILURE); + return (SECFailure); + } + + /******************************************************/ + /* AES-GCM Single-Round Known Answer Decryption Test. */ + /******************************************************/ + + aes_context = AES_CreateContext(aes_known_key, + (PRUint8 *)&gcmParams, + NSS_AES_GCM, PR_FALSE, aes_key_size, + FIPS_AES_BLOCK_SIZE); + + if (aes_context == NULL) { + PORT_SetError(SEC_ERROR_NO_MEMORY); + return (SECFailure); + } + + aes_status = AES_Decrypt(aes_context, aes_computed_plaintext, + &aes_bytes_decrypted, FIPS_AES_DECRYPT_LENGTH * 2, + aes_gcm_known_ciphertext, + FIPS_AES_ENCRYPT_LENGTH * 2); + + AES_DestroyContext(aes_context, PR_TRUE); + + if ((aes_status != SECSuccess) || + (aes_bytes_decrypted != FIPS_AES_DECRYPT_LENGTH) || + (PORT_Memcmp(aes_computed_plaintext, aes_known_plaintext, + FIPS_AES_DECRYPT_LENGTH) != 0)) { + PORT_SetError(SEC_ERROR_LIBRARY_FAILURE); + return (SECFailure); + } + return (SECSuccess); } @@ -1094,7 +1186,7 @@ freebl_fips_ECDSA_Test(ECParams *ecparams, "Firefox and ThunderBird are awesome!" }; - unsigned char sha1[SHA1_LENGTH]; /* SHA-1 hash (160 bits) */ + unsigned char sha256[SHA256_LENGTH]; /* SHA-256 hash (256 bits) */ unsigned char sig[2 * MAX_ECKEY_LEN]; SECItem signature, digest; ECPrivateKey *ecdsa_private_key = NULL; @@ -1136,13 +1228,13 @@ freebl_fips_ECDSA_Test(ECParams *ecparams, /* ECDSA Single-Round Known Answer Signature Test. */ /***************************************************/ - ecdsaStatus = SHA1_HashBuf(sha1, msg, sizeof msg); + ecdsaStatus = SHA256_HashBuf(sha256, msg, sizeof msg); if (ecdsaStatus != SECSuccess) { goto loser; } digest.type = siBuffer; - digest.data = sha1; - digest.len = SHA1_LENGTH; + digest.data = sha256; + digest.len = SHA256_LENGTH; memset(sig, 0, sizeof sig); signature.type = siBuffer; @@ -1181,10 +1273,83 @@ freebl_fips_ECDSA_Test(ECParams *ecparams, } static SECStatus -freebl_fips_ECDSA_PowerUpSelfTest() +freebl_fips_ECDH_Test(ECParams *ecparams) { - /* ECDSA Known curve nistp256 == ECCCurve_X9_62_PRIME_256V1 params */ + /* ECDH Known result (reused old CAVS vector) */ + static const PRUint8 ecdh_known_pub_key_1[] = { + EC_POINT_FORM_UNCOMPRESSED, + /* pubX */ + 0x16, 0x81, 0x32, 0x86, 0xc8, 0xe4, 0x3a, 0x1f, + 0x5d, 0xe3, 0x06, 0x22, 0x8b, 0x99, 0x14, 0x25, + 0xf7, 0x9c, 0x5b, 0x1e, 0x96, 0x84, 0x85, 0x3b, + 0x17, 0xfe, 0xf3, 0x1c, 0x0e, 0xed, 0xc4, 0xce, + /* pubY */ + 0x7a, 0x44, 0xfe, 0xbd, 0x91, 0x71, 0x7d, 0x73, + 0xd9, 0x45, 0xea, 0xae, 0x66, 0x78, 0xfa, 0x6e, + 0x46, 0xcd, 0xfa, 0x95, 0x15, 0x47, 0x62, 0x5d, + 0xbb, 0x1b, 0x9f, 0xe6, 0x39, 0xfc, 0xfd, 0x47 + }; + static const PRUint8 ecdh_known_priv_key_2[] = { + 0xb4, 0x2a, 0xe3, 0x69, 0x19, 0xec, 0xf0, 0x42, + 0x6d, 0x45, 0x8c, 0x94, 0x4a, 0x26, 0xa7, 0x5c, + 0xea, 0x9d, 0xd9, 0x0f, 0x59, 0xe0, 0x1a, 0x9d, + 0x7c, 0xb7, 0x1c, 0x04, 0x53, 0xb8, 0x98, 0x5a + }; + static const PRUint8 ecdh_known_hash_result[] = { + 0x16, 0xf3, 0x85, 0xa2, 0x41, 0xf3, 0x7f, 0xc4, + 0x0b, 0x56, 0x47, 0xee, 0xa7, 0x74, 0xb9, 0xdb, + 0xe1, 0xfa, 0x22, 0xe9, 0x04, 0xf1, 0xb6, 0x12, + 0x4b, 0x44, 0x8a, 0xbb, 0xbc, 0x08, 0x2b, 0xa7, + }; + + SECItem ecdh_priv_2, ecdh_pub_1; + SECItem ZZ = { 0, 0, 0 }; + SECStatus ecdhStatus = SECSuccess; + PRUint8 computed_hash_result[HASH_LENGTH_MAX]; + + ecdh_priv_2.data = (PRUint8 *)ecdh_known_priv_key_2; + ecdh_priv_2.len = sizeof(ecdh_known_priv_key_2); + ecdh_pub_1.data = (PRUint8 *)ecdh_known_pub_key_1; + ecdh_pub_1.len = sizeof(ecdh_known_pub_key_1); + + /* Generates a new EC key pair. The private key is a supplied + * random value (in seed) and the public key is the result of + * performing a scalar point multiplication of that value with + * the curve's base point. + */ + ecdhStatus = ECDH_Derive(&ecdh_pub_1, ecparams, &ecdh_priv_2, PR_FALSE, &ZZ); + if (ecdhStatus != SECSuccess) { + goto loser; + } + ecdhStatus = SHA256_HashBuf(computed_hash_result, ZZ.data, ZZ.len); + if (ecdhStatus != SECSuccess) { + goto loser; + } + + if (PORT_Memcmp(computed_hash_result, ecdh_known_hash_result, + sizeof(ecdh_known_hash_result)) != 0) { + ecdhStatus = SECFailure; + goto loser; + } + +loser: + if (ZZ.data) { + SECITEM_FreeItem(&ZZ, PR_FALSE); + } + + if (ecdhStatus != SECSuccess) { + PORT_SetError(SEC_ERROR_LIBRARY_FAILURE); + return (SECFailure); + } + return (SECSuccess); +} + +static SECStatus +freebl_fips_EC_PowerUpSelfTest() +{ + + /* EC Known curve nistp256 == ECCCurve_X9_62_PRIME_256V1 params */ static const unsigned char p256_prime[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, @@ -1217,7 +1382,7 @@ freebl_fips_ECDSA_PowerUpSelfTest() static const unsigned char p256_encoding[] = { 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07 }; - static const ECParams ecdsa_known_P256_Params = { + static const ECParams ec_known_P256_Params = { NULL, ec_params_named, /* arena, type */ /* fieldID */ { 256, ec_field_GFp, /* size and type */ @@ -1250,10 +1415,10 @@ freebl_fips_ECDSA_PowerUpSelfTest() 0x9d, 0x37, 0x4b, 0x1c, 0xdc, 0x35, 0x90, 0xff, 0x1a, 0x2d, 0x98, 0x95, 0x1b, 0x2f, 0xeb, 0x7f, 0xbb, 0x81, 0xca, 0xc0, 0x69, 0x75, 0xea, 0xc5, - 0x59, 0x6a, 0x62, 0x49, 0x3d, 0x50, 0xc9, 0xe1, - 0x27, 0x3b, 0xff, 0x9b, 0x13, 0x66, 0x67, 0xdd, - 0x7d, 0xd1, 0x0d, 0x2d, 0x7c, 0x44, 0x04, 0x1b, - 0x16, 0x21, 0x12, 0xc5, 0xcb, 0xbd, 0x9e, 0x75 + 0xa7, 0xd2, 0x20, 0xdd, 0x45, 0xf9, 0x2b, 0xdd, + 0xda, 0x98, 0x99, 0x5b, 0x1c, 0x02, 0x3a, 0x27, + 0x8b, 0x7d, 0xb6, 0xed, 0x0e, 0xe0, 0xa7, 0xac, + 0xaa, 0x36, 0x2c, 0xfa, 0x1a, 0xdf, 0x0d, 0xe1, }; ECParams ecparams; @@ -1261,13 +1426,18 @@ freebl_fips_ECDSA_PowerUpSelfTest() SECStatus rv; /* ECDSA GF(p) prime field curve test */ - ecparams = ecdsa_known_P256_Params; + ecparams = ec_known_P256_Params; rv = freebl_fips_ECDSA_Test(&ecparams, ecdsa_known_P256_signature, sizeof ecdsa_known_P256_signature); if (rv != SECSuccess) { return (SECFailure); } + /* ECDH GF(p) prime field curve test */ + rv = freebl_fips_ECDH_Test(&ecparams); + if (rv != SECSuccess) { + return (SECFailure); + } return (SECSuccess); } @@ -1417,6 +1587,138 @@ freebl_fips_DSA_PowerUpSelfTest(void) return (SECSuccess); } +static SECStatus +freebl_fips_DH_PowerUpSelfTest(void) +{ + /* DH Known P (2048-bits) */ + static const PRUint8 dh_known_P[] = { + 0xc2, 0x79, 0xbb, 0x76, 0x32, 0x0d, 0x43, 0xfd, + 0x1b, 0x8c, 0xa2, 0x3c, 0x00, 0xdd, 0x6d, 0xef, + 0xf8, 0x1a, 0xd9, 0xc1, 0xa2, 0xf5, 0x73, 0x2b, + 0xdb, 0x1a, 0x3e, 0x84, 0x90, 0xeb, 0xe7, 0x8e, + 0x5f, 0x5c, 0x6b, 0xb6, 0x61, 0x89, 0xd1, 0x03, + 0xb0, 0x5f, 0x91, 0xe4, 0xd2, 0x82, 0x90, 0xfc, + 0x3c, 0x49, 0x69, 0x59, 0xc1, 0x51, 0x6a, 0x85, + 0x71, 0xe7, 0x5d, 0x72, 0x5a, 0x45, 0xad, 0x01, + 0x6f, 0x82, 0xae, 0xec, 0x91, 0x08, 0x2e, 0x7c, + 0x64, 0x93, 0x46, 0x1c, 0x68, 0xef, 0xc2, 0x03, + 0x28, 0x1d, 0x75, 0x3a, 0xeb, 0x9c, 0x46, 0xf0, + 0xc9, 0xdb, 0x99, 0x95, 0x13, 0x66, 0x4d, 0xd5, + 0x1a, 0x78, 0x92, 0x51, 0x89, 0x72, 0x28, 0x7f, + 0x20, 0x70, 0x41, 0x49, 0xa2, 0x86, 0xe9, 0xf9, + 0x78, 0x5f, 0x8d, 0x2e, 0x5d, 0xfa, 0xdb, 0x57, + 0xd4, 0x71, 0xdf, 0x66, 0xe3, 0x9e, 0x88, 0x70, + 0xa4, 0x21, 0x44, 0x6a, 0xc7, 0xae, 0x30, 0x2c, + 0x9c, 0x1f, 0x91, 0x57, 0xc8, 0x24, 0x34, 0x2d, + 0x7a, 0x4a, 0x43, 0xc2, 0x5f, 0xab, 0x64, 0x2e, + 0xaa, 0x28, 0x32, 0x95, 0x42, 0x7b, 0xa0, 0xcc, + 0xdf, 0xfd, 0x22, 0xc8, 0x56, 0x84, 0xc1, 0x62, + 0x15, 0xb2, 0x77, 0x86, 0x81, 0xfc, 0xa5, 0x12, + 0x3c, 0xca, 0x28, 0x17, 0x8f, 0x03, 0x16, 0x6e, + 0xb8, 0x24, 0xfa, 0x1b, 0x15, 0x02, 0xfd, 0x8b, + 0xb6, 0x0a, 0x1a, 0xf7, 0x47, 0x41, 0xc5, 0x2b, + 0x37, 0x3e, 0xa1, 0xbf, 0x68, 0xda, 0x1c, 0x55, + 0x44, 0xc3, 0xee, 0xa1, 0x63, 0x07, 0x11, 0x3b, + 0x5f, 0x00, 0x84, 0xb4, 0xc4, 0xe4, 0xa7, 0x97, + 0x29, 0xf8, 0xce, 0xab, 0xfc, 0x27, 0x3e, 0x34, + 0xe4, 0xc7, 0x81, 0x52, 0x32, 0x0e, 0x27, 0x3c, + 0xa6, 0x70, 0x3f, 0x4a, 0x54, 0xda, 0xdd, 0x60, + 0x26, 0xb3, 0x6e, 0x45, 0x26, 0x19, 0x41, 0x6f + }; + + static const PRUint8 dh_known_Y_1[] = { + 0xb4, 0xc7, 0x85, 0xba, 0xa6, 0x98, 0xb3, 0x77, + 0x41, 0x2b, 0xd9, 0x9a, 0x72, 0x90, 0xa4, 0xac, + 0xc4, 0xf7, 0xc2, 0x23, 0x9a, 0x68, 0xe2, 0x7d, + 0x3a, 0x54, 0x45, 0x91, 0xc1, 0xd7, 0x8a, 0x17, + 0x54, 0xd3, 0x37, 0xaa, 0x0c, 0xcd, 0x0b, 0xe2, + 0xf2, 0x34, 0x0f, 0x17, 0xa8, 0x07, 0x88, 0xaf, + 0xed, 0xc1, 0x02, 0xd4, 0xdb, 0xdc, 0x0f, 0x22, + 0x51, 0x23, 0x40, 0xb9, 0x65, 0x6d, 0x39, 0xf4, + 0xe1, 0x8b, 0x57, 0x7d, 0xb6, 0xd3, 0xf2, 0x6b, + 0x02, 0xa9, 0x36, 0xf0, 0x0d, 0xe3, 0xdb, 0x9a, + 0xbf, 0x20, 0x00, 0x4d, 0xec, 0x6f, 0x68, 0x95, + 0xee, 0x59, 0x4e, 0x3c, 0xb6, 0xda, 0x7b, 0x19, + 0x08, 0x9a, 0xef, 0x61, 0x43, 0xf5, 0xfb, 0x25, + 0x70, 0x19, 0xc1, 0x5f, 0x0e, 0x0f, 0x6a, 0x63, + 0x44, 0xe9, 0xcf, 0x33, 0xce, 0x13, 0x4f, 0x34, + 0x3c, 0x94, 0x40, 0x8d, 0xf2, 0x65, 0x42, 0xef, + 0x70, 0x54, 0xdd, 0x5f, 0xc1, 0xd7, 0x0b, 0xa6, + 0x06, 0xd5, 0xa6, 0x47, 0xae, 0x2c, 0x1f, 0x5a, + 0xa6, 0xb3, 0xc1, 0x38, 0x3a, 0x3b, 0x60, 0x94, + 0xa2, 0x95, 0xab, 0xb2, 0x86, 0x82, 0xc5, 0x3b, + 0xb8, 0x6f, 0x3e, 0x55, 0x86, 0x84, 0xe0, 0x00, + 0xe5, 0xef, 0xca, 0x5c, 0xec, 0x7e, 0x38, 0x0f, + 0x82, 0xa2, 0xb1, 0xee, 0x48, 0x1b, 0x32, 0xbb, + 0x5a, 0x33, 0xa5, 0x01, 0xba, 0xca, 0xa6, 0x64, + 0x61, 0xb6, 0xe5, 0x5c, 0x0e, 0x5f, 0x2c, 0x66, + 0x0d, 0x01, 0x6a, 0x20, 0x04, 0x70, 0x68, 0x82, + 0x93, 0x29, 0x15, 0x3b, 0x7a, 0x06, 0xb2, 0x92, + 0x61, 0xcd, 0x7e, 0xa4, 0xc1, 0x15, 0x64, 0x3b, + 0x3c, 0x51, 0x10, 0x4c, 0x87, 0xa6, 0xaf, 0x07, + 0xce, 0x46, 0x82, 0x75, 0xf3, 0x90, 0xf3, 0x21, + 0x55, 0x74, 0xc2, 0xe4, 0x96, 0x7d, 0xc3, 0xe6, + 0x33, 0xa5, 0xc6, 0x51, 0xef, 0xec, 0x90, 0x08 + }; + + static const PRUint8 dh_known_x_2[] = { + 0x9e, 0x9b, 0xc3, 0x25, 0x53, 0xf9, 0xfc, 0x92, + 0xb6, 0xae, 0x54, 0x8e, 0x23, 0x4c, 0x94, 0xba, + 0x41, 0xe6, 0x29, 0x33, 0xb9, 0xdb, 0xff, 0x6d, + 0xa8, 0xb8, 0x48, 0x49, 0x66, 0x11, 0xa6, 0x13 + }; + + static const PRUint8 dh_known_hash_result[] = { + 0x93, 0xa2, 0x89, 0x1c, 0x8a, 0xc3, 0x70, 0xbf, + 0xa7, 0xdf, 0xb6, 0xd7, 0x82, 0xfb, 0x87, 0x81, + 0x09, 0x47, 0xf3, 0x9f, 0x5a, 0xbf, 0x4f, 0x3f, + 0x8e, 0x5e, 0x06, 0xca, 0x30, 0xa7, 0xaf, 0x10 + }; + + /* DH variables. */ + SECStatus dhStatus; + SECItem dh_prime; + SECItem dh_pub_key_1; + SECItem dh_priv_key_2; + SECItem ZZ = { 0, 0, 0 }; + PRUint8 computed_hash_result[HASH_LENGTH_MAX]; + + dh_prime.data = (PRUint8 *)dh_known_P; + dh_prime.len = sizeof(dh_known_P); + dh_pub_key_1.data = (PRUint8 *)dh_known_Y_1; + dh_pub_key_1.len = sizeof(dh_known_Y_1); + dh_priv_key_2.data = (PRUint8 *)dh_known_x_2; + dh_priv_key_2.len = sizeof(dh_known_x_2); + + /* execute the derive */ + dhStatus = DH_Derive(&dh_pub_key_1, &dh_prime, &dh_priv_key_2, &ZZ, dh_prime.len); + if (dhStatus != SECSuccess) { + goto loser; + } + + dhStatus = SHA256_HashBuf(computed_hash_result, ZZ.data, ZZ.len); + if (dhStatus != SECSuccess) { + goto loser; + } + + if (PORT_Memcmp(computed_hash_result, dh_known_hash_result, + sizeof(dh_known_hash_result)) != 0) { + dhStatus = SECFailure; + goto loser; + } + +loser: + if (ZZ.data) { + SECITEM_FreeItem(&ZZ, PR_FALSE); + } + + if (dhStatus != SECSuccess) { + PORT_SetError(SEC_ERROR_LIBRARY_FAILURE); + return (SECFailure); + } + return (SECSuccess); +} + static SECStatus freebl_fips_RNG_PowerUpSelfTest(void) { @@ -1541,7 +1843,7 @@ freebl_fipsPowerUpSelfTest(unsigned int tests) return rv; /* NOTE: RSA can only be tested in full freebl. It requires access to - * the locking primitives */ + * the locking primitives */ /* RSA Power-Up SelfTest(s). */ rv = freebl_fips_RSA_PowerUpSelfTest(); @@ -1554,8 +1856,14 @@ freebl_fipsPowerUpSelfTest(unsigned int tests) if (rv != SECSuccess) return rv; - /* ECDSA Power-Up SelfTest(s). */ - rv = freebl_fips_ECDSA_PowerUpSelfTest(); + /* DH Power-Up SelfTest(s). */ + rv = freebl_fips_DH_PowerUpSelfTest(); + + if (rv != SECSuccess) + return rv; + + /* EC Power-Up SelfTest(s). */ + rv = freebl_fips_EC_PowerUpSelfTest(); if (rv != SECSuccess) return rv; diff --git a/security/nss/lib/freebl/intel-gcm-wrap.c b/security/nss/lib/freebl/intel-gcm-wrap.c index 37a1af7652c0f..7bc07a6e98af1 100644 --- a/security/nss/lib/freebl/intel-gcm-wrap.c +++ b/security/nss/lib/freebl/intel-gcm-wrap.c @@ -143,6 +143,7 @@ intel_AES_GCM_CreateContext(void *context, void intel_AES_GCM_DestroyContext(intel_AES_GCMContext *gcm, PRBool freeit) { + PORT_Memset(gcm, 0, sizeof(intel_AES_GCMContext)); if (freeit) { PORT_Free(gcm); } diff --git a/security/nss/lib/freebl/pqg.c b/security/nss/lib/freebl/pqg.c index 98fe20f0daf3e..28930e2e4850e 100644 --- a/security/nss/lib/freebl/pqg.c +++ b/security/nss/lib/freebl/pqg.c @@ -491,11 +491,11 @@ makeQ2fromSeed( ** This implments steps 4 thorough 22 of FIPS 186-3 A.1.2.1 and ** steps 16 through 34 of FIPS 186-2 C.6 */ -#define MAX_ST_SEED_BITS (HASH_LENGTH_MAX * PR_BITS_PER_BYTE) static SECStatus makePrimefromPrimesShaweTaylor( HASH_HashType hashtype, /* selected Hashing algorithm */ unsigned int length, /* input. Length of prime in bits. */ + unsigned int seedlen, /* input seed length in bits */ mp_int *c0, /* seed prime */ mp_int *q, /* sub prime, can be 1 */ mp_int *prime, /* output. */ @@ -557,7 +557,7 @@ makePrimefromPrimesShaweTaylor( old_counter = *prime_gen_counter; /* ** Comment: Generate a pseudorandom integer x in the interval - ** [2**(lenght-1), 2**length]. + ** [2**(length-1), 2**length]. ** ** Step 6/18 x = 0 */ @@ -569,11 +569,10 @@ makePrimefromPrimesShaweTaylor( for (i = 0; i < iterations; i++) { /* is bigger than prime_seed should get to */ CHECK_SEC_OK(addToSeedThenHash(hashtype, prime_seed, i, - MAX_ST_SEED_BITS, &x[(iterations - i - 1) * hashlen])); + seedlen, &x[(iterations - i - 1) * hashlen])); } /* Step 8/20 prime_seed = prime_seed + iterations + 1 */ - CHECK_SEC_OK(addToSeed(prime_seed, iterations, MAX_ST_SEED_BITS, - prime_seed)); + CHECK_SEC_OK(addToSeed(prime_seed, iterations, seedlen, prime_seed)); /* ** Step 9/21 x = 2 ** (length-1) + x mod 2 ** (length-1) ** @@ -595,7 +594,7 @@ makePrimefromPrimesShaweTaylor( x[offset] = (mask & x[offset]) | bit; /* ** Comment: Generate a candidate prime c in the interval - ** [2**(lenght-1), 2**length]. + ** [2**(length-1), 2**length]. ** ** Step 10 t = ceiling(x/(2q(p0))) ** Step 22 t = ceiling(x/(2(c0))) @@ -624,7 +623,7 @@ makePrimefromPrimesShaweTaylor( /* t = 2**(length-1) + 2qc0 -1 */ CHECK_MPI_OK(mp_add(&two_length_minus_1, &t, &t)); /* t = floor((2**(length-1)+2qc0 -1)/2qco) - * = ceil(2**(lenght-2)/2qc0) */ + * = ceil(2**(length-2)/2qc0) */ CHECK_MPI_OK(mp_div(&t, &c0_2, &t, NULL)); CHECK_MPI_OK(mp_mul(&t, &c0_2, &c)); CHECK_MPI_OK(mp_add_d(&c, (mp_digit)1, &c)); /* c= 2tqc0 + 1*/ @@ -645,13 +644,11 @@ makePrimefromPrimesShaweTaylor( ** NOTE: we reuse the x array for 'a' initially. */ for (i = 0; i < iterations; i++) { - /* MAX_ST_SEED_BITS is bigger than prime_seed should get to */ CHECK_SEC_OK(addToSeedThenHash(hashtype, prime_seed, i, - MAX_ST_SEED_BITS, &x[(iterations - i - 1) * hashlen])); + seedlen, &x[(iterations - i - 1) * hashlen])); } /* Step 16/28 prime_seed = prime_seed + iterations + 1 */ - CHECK_SEC_OK(addToSeed(prime_seed, iterations, MAX_ST_SEED_BITS, - prime_seed)); + CHECK_SEC_OK(addToSeed(prime_seed, iterations, seedlen, prime_seed)); /* Step 17/29 a = 2 + (a mod (c-3)). */ CHECK_MPI_OK(mp_read_unsigned_octets(&a, x, iterations * hashlen)); CHECK_MPI_OK(mp_sub_d(&c, (mp_digit)3, &z)); /* z = c -3 */ @@ -742,6 +739,7 @@ makePrimefromSeedShaweTaylor( int hashlen = HASH_ResultLen(hashtype); int outlen = hashlen * PR_BITS_PER_BYTE; int offset; + int seedlen = input_seed->len * 8; /*seedlen is in bits */ unsigned char bit, mask; unsigned char x[HASH_LENGTH_MAX * 2]; mp_digit dummy; @@ -775,7 +773,7 @@ makePrimefromSeedShaweTaylor( goto cleanup; } /* Steps 16-34 */ - rv = makePrimefromPrimesShaweTaylor(hashtype, length, &c0, &one, + rv = makePrimefromPrimesShaweTaylor(hashtype, length, seedlen, &c0, &one, prime, prime_seed, prime_gen_counter); goto cleanup; /* we're done, one way or the other */ } @@ -787,8 +785,7 @@ makePrimefromSeedShaweTaylor( step_5: /* Step 5 c = Hash(prime_seed) xor Hash(prime_seed+1). */ CHECK_SEC_OK(HASH_HashBuf(hashtype, x, prime_seed->data, prime_seed->len)); - CHECK_SEC_OK(addToSeedThenHash(hashtype, prime_seed, 1, - MAX_ST_SEED_BITS, &x[hashlen])); + CHECK_SEC_OK(addToSeedThenHash(hashtype, prime_seed, 1, seedlen, &x[hashlen])); for (i = 0; i < hashlen; i++) { x[i] = x[i] ^ x[i + hashlen]; } @@ -817,7 +814,7 @@ makePrimefromSeedShaweTaylor( /* Step 8 prime_gen_counter = prime_gen_counter + 1 */ (*prime_gen_counter)++; /* Step 9 prime_seed = prime_seed + 2 */ - CHECK_SEC_OK(addToSeed(prime_seed, 2, MAX_ST_SEED_BITS, prime_seed)); + CHECK_SEC_OK(addToSeed(prime_seed, 2, seedlen, prime_seed)); /* Step 10 Perform deterministic primality test on c. For example, since ** c is small, it's primality can be tested by trial division, See ** See Appendic C.7. @@ -890,7 +887,8 @@ findQfromSeed( mp_int *Q_, /* output. */ unsigned int *qseed_len, /* output */ HASH_HashType *hashtypePtr, /* output. Hash uses */ - pqgGenType *typePtr) /* output. Generation Type used */ + pqgGenType *typePtr, /* output. Generation Type used */ + unsigned int *qgen_counter) /* output. q_counter */ { HASH_HashType hashtype; SECItem firstseed = { 0, 0, 0 }; @@ -964,6 +962,7 @@ findQfromSeed( *qseed_len = qseed.len; *hashtypePtr = hashtype; *typePtr = FIPS186_3_ST_TYPE; + *qgen_counter = count; SECITEM_FreeItem(&qseed, PR_FALSE); return SECSuccess; } @@ -1390,19 +1389,26 @@ pqg_ParamGen(unsigned int L, unsigned int N, pqgGenType type, CHECK_SEC_OK(makePrimefromSeedShaweTaylor(hashtype, (L + 1) / 2 + 1, &qseed, &p0, &pseed, &pgen_counter)); /* Steps 4-22 FIPS 186-3 appendix A.1.2.1.2 */ - CHECK_SEC_OK(makePrimefromPrimesShaweTaylor(hashtype, L, + CHECK_SEC_OK(makePrimefromPrimesShaweTaylor(hashtype, L, seedBytes * 8, &p0, &Q, &P, &pseed, &pgen_counter)); /* combine all the seeds */ - seed->len = firstseed.len + qseed.len + pseed.len; + if ((qseed.len > firstseed.len) || (pseed.len > firstseed.len)) { + PORT_SetError(SEC_ERROR_LIBRARY_FAILURE); /* shouldn't happen */ + goto cleanup; + } + /* If the seed overflows, then pseed and qseed may have leading zeros which the mpl code clamps. + * we want to make sure those are added back in so the individual seed lengths are predictable from + * the overall seed length */ + seed->len = firstseed.len * 3; seed->data = PORT_ArenaZAlloc(verify->arena, seed->len); if (seed->data == NULL) { goto cleanup; } PORT_Memcpy(seed->data, firstseed.data, firstseed.len); - PORT_Memcpy(seed->data + firstseed.len, pseed.data, pseed.len); - PORT_Memcpy(seed->data + firstseed.len + pseed.len, qseed.data, qseed.len); - counter = 0; /* (qgen_counter << 16) | pgen_counter; */ + PORT_Memcpy(seed->data + 2 * firstseed.len - pseed.len, pseed.data, pseed.len); + PORT_Memcpy(seed->data + 3 * firstseed.len - qseed.len, qseed.data, qseed.len); + counter = (qgen_counter << 16) | pgen_counter; /* we've generated both P and Q now, skip to generating G */ goto generate_G; @@ -1622,6 +1628,7 @@ PQG_VerifyParams(const PQGParams *params, int j; unsigned int counter_max = 0; /* handle legacy L < 1024 */ unsigned int qseed_len; + unsigned int qgen_counter_ = 0; SECItem pseed_ = { 0, 0, 0 }; HASH_HashType hashtype; pqgGenType type; @@ -1701,48 +1708,55 @@ PQG_VerifyParams(const PQGParams *params, /* Steps 7-12 are done only if the optional PQGVerify is supplied. */ /* continue processing P */ /* 7. counter < 4*L */ - CHECKPARAM((vfy->counter == -1) || (vfy->counter < counter_max)); /* 8. g >= N and g < 2*L (g is length of seed in bits) */ - g = vfy->seed.len * 8; - CHECKPARAM(g >= N && g < counter_max / 2); + /* step 7 and 8 are delayed until we determine which type of generation + * was used */ /* 9. Q generated from SEED matches Q in PQGParams. */ /* This function checks all possible hash and generation types to * find a Q_ which matches Q. */ + g = vfy->seed.len * 8; CHECKPARAM(findQfromSeed(L, N, g, &vfy->seed, &Q, &Q_, &qseed_len, - &hashtype, &type) == SECSuccess); + &hashtype, &type, &qgen_counter_) == SECSuccess); CHECKPARAM(mp_cmp(&Q, &Q_) == 0); + /* now we can do steps 7 & 8*/ + if ((type == FIPS186_1_TYPE) || (type == FIPS186_3_TYPE)) { + CHECKPARAM((vfy->counter == -1) || (vfy->counter < counter_max)); + CHECKPARAM(g >= N && g < counter_max / 2); + } if (type == FIPS186_3_ST_TYPE) { SECItem qseed = { 0, 0, 0 }; SECItem pseed = { 0, 0, 0 }; unsigned int first_seed_len; - unsigned int pgen_counter = 0; + unsigned int pgen_counter_ = 0; + unsigned int qgen_counter = (vfy->counter >> 16) & 0xffff; + unsigned int pgen_counter = (vfy->counter) & 0xffff; /* extract pseed and qseed from domain_parameter_seed, which is * first_seed || pseed || qseed. qseed is first_seed + small_integer - * pseed is qseed + small_integer. This means most of the time + * mod the length of first_seed. pseed is qseed + small_integer mod + * the length of first_seed. This means most of the time * first_seed.len == qseed.len == pseed.len. Rarely qseed.len and/or - * pseed.len will be one greater than first_seed.len, so we can - * depend on the fact that - * first_seed.len = floor(domain_parameter_seed.len/3). - * findQfromSeed returned qseed.len, so we can calculate pseed.len as - * pseed.len = domain_parameter_seed.len - first_seed.len - qseed.len - * this is probably over kill, since 99.999% of the time they will all - * be equal. - * - * With the lengths, we can now find the offsets; + * pseed.len will be smaller because mpi clamps them. pqgGen + * automatically adds the zero pad back though, so we can depend + * domain_parameter_seed.len to be a multiple of three. We only have + * to deal with the fact that the returned seeds from our functions + * could be shorter. + * first_seed.len = domain_parameter_seed.len/3 + * We can now find the offsets; * first_seed.data = domain_parameter_seed.data + 0 * pseed.data = domain_parameter_seed.data + first_seed.len * qseed.data = domain_parameter_seed.data * + domain_paramter_seed.len - qseed.len - * + * We deal with pseed possibly having zero pad in the pseed check later. */ first_seed_len = vfy->seed.len / 3; CHECKPARAM(qseed_len < vfy->seed.len); CHECKPARAM(first_seed_len * 8 > N - 1); - CHECKPARAM(first_seed_len + qseed_len < vfy->seed.len); + CHECKPARAM(first_seed_len * 8 < counter_max / 2); + CHECKPARAM(first_seed_len >= qseed_len); qseed.len = qseed_len; qseed.data = vfy->seed.data + vfy->seed.len - qseed.len; - pseed.len = vfy->seed.len - (first_seed_len + qseed_len); + pseed.len = first_seed_len; pseed.data = vfy->seed.data + first_seed_len; /* @@ -1754,14 +1768,34 @@ PQG_VerifyParams(const PQGParams *params, ** (ST_Random_Prime((ceil(length/2)+1, input_seed) */ CHECK_SEC_OK(makePrimefromSeedShaweTaylor(hashtype, (L + 1) / 2 + 1, - &qseed, &p0, &pseed_, &pgen_counter)); + &qseed, &p0, &pseed_, &pgen_counter_)); /* Steps 4-22 FIPS 186-3 appendix A.1.2.1.2 */ - CHECK_SEC_OK(makePrimefromPrimesShaweTaylor(hashtype, L, - &p0, &Q_, &P_, &pseed_, &pgen_counter)); + CHECK_SEC_OK(makePrimefromPrimesShaweTaylor(hashtype, L, first_seed_len * 8, + &p0, &Q_, &P_, &pseed_, &pgen_counter_)); CHECKPARAM(mp_cmp(&P, &P_) == 0); /* make sure pseed wasn't tampered with (since it is part of * calculating G) */ + if (pseed.len > pseed_.len) { + /* handle the case of zero pad for pseed */ + int extra = pseed.len - pseed_.len; + int i; + for (i = 0; i < extra; i++) { + if (pseed.data[i] != 0) { + *result = SECFailure; + goto cleanup; + } + } + pseed.data += extra; + pseed.len -= extra; + /* the rest is handled in the normal compare below */ + } CHECKPARAM(SECITEM_CompareItem(&pseed, &pseed_) == SECEqual); + if (vfy->counter != -1) { + CHECKPARAM(pgen_counter < counter_max); + CHECKPARAM(qgen_counter < counter_max); + CHECKPARAM((pgen_counter_ == pgen_counter)); + CHECKPARAM((qgen_counter_ == qgen_counter)); + } } else if (vfy->counter == -1) { /* If counter is set to -1, we are really only verifying G, skip * the remainder of the checks for P */ diff --git a/security/nss/lib/freebl/rijndael.c b/security/nss/lib/freebl/rijndael.c index 5de27de9ce72a..6dab440f8ba94 100644 --- a/security/nss/lib/freebl/rijndael.c +++ b/security/nss/lib/freebl/rijndael.c @@ -1032,13 +1032,19 @@ AES_CreateContext(const unsigned char *key, const unsigned char *iv, void AES_DestroyContext(AESContext *cx, PRBool freeit) { + void *mem = cx->mem; if (cx->worker_cx && cx->destroy) { (*cx->destroy)(cx->worker_cx, PR_TRUE); cx->worker_cx = NULL; cx->destroy = NULL; } + PORT_Memset(cx, 0, sizeof(AESContext)); if (freeit) { - PORT_Free(cx->mem); + PORT_Free(mem); + } else { + /* if we are not freeing the context, restore mem, We may get called + * again to actually free the context */ + cx->mem = mem; } } diff --git a/security/nss/lib/nss/nss.def b/security/nss/lib/nss/nss.def index 53d463a66ffd4..17c69a7797727 100644 --- a/security/nss/lib/nss/nss.def +++ b/security/nss/lib/nss/nss.def @@ -1151,3 +1151,9 @@ CERT_GetCertificateDer; ;+ local: ;+ *; ;+}; +;+NSS_3.45 { # NSS 3.45 release +;+ global: +PK11_FindRawCertsWithSubject; +;+ local: +;+ *; +;+}; diff --git a/security/nss/lib/pk11wrap/pk11obj.c b/security/nss/lib/pk11wrap/pk11obj.c index 468f94ebccfdb..16ff15a809caa 100644 --- a/security/nss/lib/pk11wrap/pk11obj.c +++ b/security/nss/lib/pk11wrap/pk11obj.c @@ -4,6 +4,8 @@ /* * This file manages object type indepentent functions. */ +#include + #include "seccomon.h" #include "secmod.h" #include "secmodi.h" @@ -1883,6 +1885,96 @@ pk11_FindObjectsByTemplate(PK11SlotInfo *slot, CK_ATTRIBUTE *findTemplate, *object_count = -1; return objID; } + +SECStatus +PK11_FindRawCertsWithSubject(PK11SlotInfo *slot, SECItem *derSubject, + CERTCertificateList **results) +{ + if (!slot || !derSubject || !results) { + PORT_SetError(SEC_ERROR_INVALID_ARGS); + return SECFailure; + } + *results = NULL; + + // derSubject->data may be null. If so, derSubject->len must be 0. + if (!derSubject->data && derSubject->len != 0) { + PORT_SetError(SEC_ERROR_INVALID_ARGS); + return SECFailure; + } + + CK_CERTIFICATE_TYPE ckc_x_509 = CKC_X_509; + CK_OBJECT_CLASS cko_certificate = CKO_CERTIFICATE; + CK_ATTRIBUTE subjectTemplate[] = { + { CKA_CERTIFICATE_TYPE, &ckc_x_509, sizeof(ckc_x_509) }, + { CKA_CLASS, &cko_certificate, sizeof(cko_certificate) }, + { CKA_SUBJECT, derSubject->data, derSubject->len }, + }; + int templateCount = sizeof(subjectTemplate) / sizeof(subjectTemplate[0]); + int handleCount = 0; + CK_OBJECT_HANDLE *handles = + pk11_FindObjectsByTemplate(slot, subjectTemplate, templateCount, + &handleCount); + if (!handles) { + // pk11_FindObjectsByTemplate indicates there was an error by setting + // handleCount to -1 (and it has set an error with PORT_SetError). + if (handleCount == -1) { + return SECFailure; + } + return SECSuccess; + } + PORT_Assert(handleCount > 0); + if (handleCount <= 0) { + PORT_Free(handles); + PORT_SetError(SEC_ERROR_LIBRARY_FAILURE); + return SECFailure; + } + if (handleCount > INT_MAX / sizeof(SECItem)) { + PORT_Free(handles); + PORT_SetError(SEC_ERROR_LIBRARY_FAILURE); + return SECFailure; + } + PLArenaPool *arena = PORT_NewArena(DER_DEFAULT_CHUNKSIZE); + if (!arena) { + PORT_Free(handles); + return SECFailure; + } + CERTCertificateList *rawCertificates = + PORT_ArenaNew(arena, CERTCertificateList); + if (!rawCertificates) { + PORT_Free(handles); + PORT_FreeArena(arena, PR_FALSE); + return SECFailure; + } + rawCertificates->arena = arena; + rawCertificates->certs = PORT_ArenaNewArray(arena, SECItem, handleCount); + if (!rawCertificates->certs) { + PORT_Free(handles); + PORT_FreeArena(arena, PR_FALSE); + return SECFailure; + } + rawCertificates->len = handleCount; + int handleIndex; + for (handleIndex = 0; handleIndex < handleCount; handleIndex++) { + SECStatus rv = + PK11_ReadAttribute(slot, handles[handleIndex], CKA_VALUE, arena, + &rawCertificates->certs[handleIndex]); + if (rv != SECSuccess) { + PORT_Free(handles); + PORT_FreeArena(arena, PR_FALSE); + return SECFailure; + } + if (!rawCertificates->certs[handleIndex].data) { + PORT_Free(handles); + PORT_FreeArena(arena, PR_FALSE); + PORT_SetError(SEC_ERROR_LIBRARY_FAILURE); + return SECFailure; + } + } + PORT_Free(handles); + *results = rawCertificates; + return SECSuccess; +} + /* * given a PKCS #11 object, match it's peer based on the KeyID. searchID * is typically a privateKey or a certificate while the peer is the opposite diff --git a/security/nss/lib/pk11wrap/pk11pub.h b/security/nss/lib/pk11wrap/pk11pub.h index 8db969e4cfde8..9ca4018d94530 100644 --- a/security/nss/lib/pk11wrap/pk11pub.h +++ b/security/nss/lib/pk11wrap/pk11pub.h @@ -875,6 +875,17 @@ SECStatus PK11_WriteRawAttribute(PK11ObjectType type, void *object, PK11SlotList * PK11_GetAllSlotsForCert(CERTCertificate *cert, void *arg); +/* + * Finds all certificates on the given slot with the given subject distinguished + * name and returns them as DER bytes. If no such certificates can be found, + * returns SECSuccess and sets *results to NULL. If a failure is encountered + * while fetching any of the matching certificates, SECFailure is returned and + * *results will be NULL. + */ +SECStatus +PK11_FindRawCertsWithSubject(PK11SlotInfo *slot, SECItem *derSubject, + CERTCertificateList **results); + /********************************************************************** * New functions which are already deprecated.... **********************************************************************/ diff --git a/security/nss/lib/softoken/pkcs11c.c b/security/nss/lib/softoken/pkcs11c.c index 5830a8857325f..8b3c68d444bca 100644 --- a/security/nss/lib/softoken/pkcs11c.c +++ b/security/nss/lib/softoken/pkcs11c.c @@ -4727,6 +4727,13 @@ sftk_PairwiseConsistencyCheck(CK_SESSION_HANDLE hSession, return crv; } + /* detect trivial signing transforms */ + if ((signature_length >= pairwise_digest_length) && + (PORT_Memcmp(known_digest, signature + (signature_length - pairwise_digest_length), pairwise_digest_length) == 0)) { + PORT_Free(signature); + return CKR_DEVICE_ERROR; + } + /* Verify the known hash using the public key. */ crv = NSC_VerifyInit(hSession, &mech, publicKey->handle); if (crv != CKR_OK) { @@ -7562,14 +7569,14 @@ NSC_DeriveKey(CK_SESSION_HANDLE hSession, case CKM_DH_PKCS_DERIVE: { SECItem derived, dhPublic; - SECItem dhPrime, dhValue; + SECItem dhPrime, dhSubPrime, dhValue; /* sourceKey - values for the local existing low key */ /* get prime and value attributes */ crv = sftk_Attribute2SecItem(NULL, &dhPrime, sourceKey, CKA_PRIME); - if (crv != SECSuccess) + if (crv != CKR_OK) break; crv = sftk_Attribute2SecItem(NULL, &dhValue, sourceKey, CKA_VALUE); - if (crv != SECSuccess) { + if (crv != CKR_OK) { PORT_Free(dhPrime.data); break; } @@ -7577,6 +7584,20 @@ NSC_DeriveKey(CK_SESSION_HANDLE hSession, dhPublic.data = pMechanism->pParameter; dhPublic.len = pMechanism->ulParameterLen; + /* If the caller bothered to provide Q, use Q to validate + * the public key. */ + crv = sftk_Attribute2SecItem(NULL, &dhSubPrime, sourceKey, CKA_SUBPRIME); + if (crv == CKR_OK) { + rv = KEA_Verify(&dhPublic, &dhPrime, &dhSubPrime); + PORT_Free(dhSubPrime.data); + if (rv != SECSuccess) { + crv = CKR_ARGUMENTS_BAD; + PORT_Free(dhPrime.data); + PORT_Free(dhValue.data); + break; + } + } + /* calculate private value - oct */ rv = DH_Derive(&dhPublic, &dhPrime, &dhValue, &derived, keySize); @@ -7586,6 +7607,7 @@ NSC_DeriveKey(CK_SESSION_HANDLE hSession, if (rv == SECSuccess) { sftk_forceAttribute(key, CKA_VALUE, derived.data, derived.len); PORT_ZFree(derived.data, derived.len); + crv = CKR_OK; } else crv = CKR_HOST_MEMORY; From 4cf78a2ed9810f9d407a60e37e913400e6e6f49f Mon Sep 17 00:00:00 2001 From: Jonathan Watt Date: Tue, 14 May 2019 17:04:37 +0100 Subject: [PATCH 003/491] Bug 1552785. Remove macOS print dialog UI for selecting frameset behavior. r=mstange The 85 pixel change in y-axis offset is the distance between the "Print Background Images" checkbox and (removed) "Each Frame on Separate Pages" radio button. Differential Revision: https://phabricator.services.mozilla.com/D33379 --HG-- extra : rebase_source : ca0aa5291f1631a40fba18e22cf609a0768cbdb3 --- .../chrome/global/printdialog.properties | 2 - widget/cocoa/nsPrintDialogX.h | 3 - widget/cocoa/nsPrintDialogX.mm | 98 ++----------------- 3 files changed, 7 insertions(+), 96 deletions(-) diff --git a/toolkit/locales/en-US/chrome/global/printdialog.properties b/toolkit/locales/en-US/chrome/global/printdialog.properties index ae583eda598cb..da7d7221069f3 100644 --- a/toolkit/locales/en-US/chrome/global/printdialog.properties +++ b/toolkit/locales/en-US/chrome/global/printdialog.properties @@ -12,7 +12,6 @@ printFramesTitleGTK=Print Frames # Mac titles: optionsTitleMac=Options: appearanceTitleMac=Appearance: -framesTitleMac=Frames: pageHeadersTitleMac=Page Headers: pageFootersTitleMac=Page Footers: @@ -51,7 +50,6 @@ headerFooterCustom=Custom… customHeaderFooterPrompt=Please enter your custom header/footer text # These are for the summary view in the Mac dialog: -summaryFramesTitle=Print Frames summarySelectionOnlyTitle=Print Selection summaryShrinkToFitTitle=Shrink To Fit summaryPrintBGColorsTitle=Print BG Colors diff --git a/widget/cocoa/nsPrintDialogX.h b/widget/cocoa/nsPrintDialogX.h index 6a21b09b532b6..2b1a817436e87 100644 --- a/widget/cocoa/nsPrintDialogX.h +++ b/widget/cocoa/nsPrintDialogX.h @@ -37,9 +37,6 @@ class nsPrintDialogServiceX : public nsIPrintDialogService { NSButton* mShrinkToFitCheckbox; NSButton* mPrintBGColorsCheckbox; NSButton* mPrintBGImagesCheckbox; - NSButtonCell* mAsLaidOutRadio; - NSButtonCell* mSelectedFrameRadio; - NSButtonCell* mSeparateFramesRadio; NSPopUpButton* mHeaderLeftList; NSPopUpButton* mHeaderCenterList; NSPopUpButton* mHeaderRightList; diff --git a/widget/cocoa/nsPrintDialogX.mm b/widget/cocoa/nsPrintDialogX.mm index 7e2ab57cedcf6..1076a637686e9 100644 --- a/widget/cocoa/nsPrintDialogX.mm +++ b/widget/cocoa/nsPrintDialogX.mm @@ -207,8 +207,6 @@ @interface PrintPanelAccessoryView (Private) - (NSString*)localizedString:(const char*)aKey; -- (int16_t)chosenFrameSetting; - - (const char*)headerFooterStringForList:(NSPopUpButton*)aList; - (void)exportHeaderFooterSettings; @@ -234,14 +232,10 @@ - (void)addOptionsSection; - (void)addAppearanceSection; -- (void)addFramesSection; - - (void)addHeaderFooterSection; - (NSString*)summaryValueForCheckbox:(NSButton*)aCheckbox; -- (NSString*)framesSummaryValue; - - (NSString*)headerSummaryValue; - (NSString*)footerSummaryValue; @@ -255,13 +249,12 @@ @implementation PrintPanelAccessoryView // Public methods - (id)initWithSettings:(nsIPrintSettings*)aSettings { - [super initWithFrame:NSMakeRect(0, 0, 540, 270)]; + [super initWithFrame:NSMakeRect(0, 0, 540, 185)]; mSettings = aSettings; [self initBundle]; [self addOptionsSection]; [self addAppearanceSection]; - [self addFramesSection]; [self addHeaderFooterSection]; return self; @@ -274,7 +267,6 @@ - (void)exportSettings { mSettings->SetShrinkToFit([mShrinkToFitCheckbox state] == NSOnState); mSettings->SetPrintBGColors([mPrintBGColorsCheckbox state] == NSOnState); mSettings->SetPrintBGImages([mPrintBGImagesCheckbox state] == NSOnState); - mSettings->SetPrintFrameType([self chosenFrameSetting]); [self exportHeaderFooterSettings]; } @@ -372,11 +364,11 @@ - (NSPopUpButton*)headerFooterItemListWithFrame:(NSRect)aRect - (void)addOptionsSection { // Title - [self addLabel:"optionsTitleMac" withFrame:NSMakeRect(0, 240, 151, 22)]; + [self addLabel:"optionsTitleMac" withFrame:NSMakeRect(0, 155, 151, 22)]; // "Print Selection Only" mPrintSelectionOnlyCheckbox = [self checkboxWithLabel:"selectionOnly" - andFrame:NSMakeRect(156, 240, 0, 0)]; + andFrame:NSMakeRect(156, 155, 0, 0)]; bool canPrintSelection; mSettings->GetPrintOptions(nsIPrintSettings::kEnableSelectionRB, &canPrintSelection); @@ -391,7 +383,7 @@ - (void)addOptionsSection { [self addSubview:mPrintSelectionOnlyCheckbox]; // "Shrink To Fit" - mShrinkToFitCheckbox = [self checkboxWithLabel:"shrinkToFit" andFrame:NSMakeRect(156, 218, 0, 0)]; + mShrinkToFitCheckbox = [self checkboxWithLabel:"shrinkToFit" andFrame:NSMakeRect(156, 133, 0, 0)]; bool shrinkToFit; mSettings->GetShrinkToFit(&shrinkToFit); @@ -402,11 +394,11 @@ - (void)addOptionsSection { - (void)addAppearanceSection { // Title - [self addLabel:"appearanceTitleMac" withFrame:NSMakeRect(0, 188, 151, 22)]; + [self addLabel:"appearanceTitleMac" withFrame:NSMakeRect(0, 103, 151, 22)]; // "Print Background Colors" mPrintBGColorsCheckbox = [self checkboxWithLabel:"printBGColors" - andFrame:NSMakeRect(156, 188, 0, 0)]; + andFrame:NSMakeRect(156, 103, 0, 0)]; bool geckoBool; mSettings->GetPrintBGColors(&geckoBool); @@ -416,7 +408,7 @@ - (void)addAppearanceSection { // "Print Background Images" mPrintBGImagesCheckbox = [self checkboxWithLabel:"printBGImages" - andFrame:NSMakeRect(156, 166, 0, 0)]; + andFrame:NSMakeRect(156, 81, 0, 0)]; mSettings->GetPrintBGImages(&geckoBool); [mPrintBGImagesCheckbox setState:(geckoBool ? NSOnState : NSOffState)]; @@ -424,58 +416,6 @@ - (void)addAppearanceSection { [self addSubview:mPrintBGImagesCheckbox]; } -- (void)addFramesSection { - // Title - [self addLabel:"framesTitleMac" withFrame:NSMakeRect(0, 124, 151, 22)]; - - // Radio matrix - NSButtonCell* radio = [[NSButtonCell alloc] init]; - [radio setButtonType:NSRadioButton]; - [radio setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]]; - NSMatrix* matrix = [[NSMatrix alloc] initWithFrame:NSMakeRect(156, 81, 400, 66) - mode:NSRadioModeMatrix - prototype:(NSCell*)radio - numberOfRows:3 - numberOfColumns:1]; - [radio release]; - [matrix setCellSize:NSMakeSize(400, 21)]; - [self addSubview:matrix]; - [matrix release]; - NSArray* cellArray = [matrix cells]; - mAsLaidOutRadio = [cellArray objectAtIndex:0]; - mSelectedFrameRadio = [cellArray objectAtIndex:1]; - mSeparateFramesRadio = [cellArray objectAtIndex:2]; - [mAsLaidOutRadio setTitle:[self localizedString:"asLaidOut"]]; - [mSelectedFrameRadio setTitle:[self localizedString:"selectedFrame"]]; - [mSeparateFramesRadio setTitle:[self localizedString:"separateFrames"]]; - - // Radio enabled state - int16_t frameUIFlag; - mSettings->GetHowToEnableFrameUI(&frameUIFlag); - if (frameUIFlag == nsIPrintSettings::kFrameEnableNone) { - [mAsLaidOutRadio setEnabled:NO]; - [mSelectedFrameRadio setEnabled:NO]; - [mSeparateFramesRadio setEnabled:NO]; - } else if (frameUIFlag == nsIPrintSettings::kFrameEnableAsIsAndEach) { - [mSelectedFrameRadio setEnabled:NO]; - } - - // Radio values - int16_t printFrameType; - mSettings->GetPrintFrameType(&printFrameType); - switch (printFrameType) { - case nsIPrintSettings::kFramesAsIs: - [mAsLaidOutRadio setState:NSOnState]; - break; - case nsIPrintSettings::kSelectedFrame: - [mSelectedFrameRadio setState:NSOnState]; - break; - case nsIPrintSettings::kEachFrameSep: - [mSeparateFramesRadio setState:NSOnState]; - break; - } -} - - (void)addHeaderFooterSection { // Labels [self addLabel:"pageHeadersTitleMac" withFrame:NSMakeRect(0, 44, 151, 22)]; @@ -520,13 +460,6 @@ - (void)addHeaderFooterSection { // Export settings -- (int16_t)chosenFrameSetting { - if ([mAsLaidOutRadio state] == NSOnState) return nsIPrintSettings::kFramesAsIs; - if ([mSelectedFrameRadio state] == NSOnState) return nsIPrintSettings::kSelectedFrame; - if ([mSeparateFramesRadio state] == NSOnState) return nsIPrintSettings::kEachFrameSep; - return nsIPrintSettings::kNoFrames; -} - - (const char*)headerFooterStringForList:(NSPopUpButton*)aList { NSInteger index = [aList indexOfSelectedItem]; NS_ASSERTION(index < NSInteger(ArrayLength(sHeaderFooterTags)), @@ -564,18 +497,6 @@ - (NSString*)summaryValueForCheckbox:(NSButton*)aCheckbox { : [self localizedString:"summaryOffValue"]; } -- (NSString*)framesSummaryValue { - switch ([self chosenFrameSetting]) { - case nsIPrintSettings::kFramesAsIs: - return [self localizedString:"asLaidOut"]; - case nsIPrintSettings::kSelectedFrame: - return [self localizedString:"selectedFrame"]; - case nsIPrintSettings::kEachFrameSep: - return [self localizedString:"separateFrames"]; - } - return [self localizedString:"summaryNAValue"]; -} - - (NSString*)headerSummaryValue { return [[mHeaderLeftList titleOfSelectedItem] stringByAppendingString: @@ -599,11 +520,6 @@ - (NSString*)footerSummaryValue { - (NSArray*)localizedSummaryItems { return [NSArray arrayWithObjects: - [NSDictionary dictionaryWithObjectsAndKeys:[self localizedString:"summaryFramesTitle"], - NSPrintPanelAccessorySummaryItemNameKey, - [self framesSummaryValue], - NSPrintPanelAccessorySummaryItemDescriptionKey, - nil], [NSDictionary dictionaryWithObjectsAndKeys:[self localizedString:"summarySelectionOnlyTitle"], NSPrintPanelAccessorySummaryItemNameKey, From 2214ab28af4c20284743797ad15ae76c584f6663 Mon Sep 17 00:00:00 2001 From: Jonathan Watt Date: Wed, 15 May 2019 10:36:08 +0100 Subject: [PATCH 004/491] Bug 1552785. Remove Windows print dialog UI for selecting frameset behavior. r=bobowen Note that this makes Firefox use the standard system Print dialog as opposed to just removing our "Frames" section from our custom dialog. Differential Revision: https://phabricator.services.mozilla.com/D33389 --HG-- extra : rebase_source : a6d85b5c57bbc3ecd83135dae2581db56e8a7fab --- .../chrome/global/printdialog.properties | 4 - toolkit/locales/jar.mn | 2 +- widget/windows/nsPrintDialogUtil.cpp | 431 +----------------- 3 files changed, 3 insertions(+), 434 deletions(-) diff --git a/toolkit/locales/en-US/chrome/global/printdialog.properties b/toolkit/locales/en-US/chrome/global/printdialog.properties index da7d7221069f3..6565b7904c7ad 100644 --- a/toolkit/locales/en-US/chrome/global/printdialog.properties +++ b/toolkit/locales/en-US/chrome/global/printdialog.properties @@ -17,7 +17,6 @@ pageFootersTitleMac=Page Footers: # Windows titles: optionsTitleWindows=Options -printFramesTitleWindows=Print Frames # TRANSLATOR NOTE: For radio button labels and check button labels, an underscore _ # before a character will turn that character into an accesskey in the GTK dialog. @@ -26,11 +25,8 @@ printFramesTitleWindows=Print Frames # On Mac, underscores will be stripped. asLaidOut=_As Laid Out on the Screen -asLaidOutWindows=As &laid out on the screen selectedFrame=The _Selected Frame -selectedFrameWindows=The selected &frame separateFrames=Each Frame on Separate _Pages -separateFramesWindows=&Each frame separately shrinkToFit=Ignore Scaling and S_hrink To Fit Page Width selectionOnly=Print Selection _Only printBGOptions=Print Backgrounds diff --git a/toolkit/locales/jar.mn b/toolkit/locales/jar.mn index 38af9188ffae2..1e8f1e767e7ff 100644 --- a/toolkit/locales/jar.mn +++ b/toolkit/locales/jar.mn @@ -41,7 +41,7 @@ locale/@AB_CD@/global/narrate.properties (%chrome/global/narrate.properties) #endif locale/@AB_CD@/global/notification.dtd (%chrome/global/notification.dtd) -#ifndef MOZ_FENNEC +#if !defined(XP_WIN) && !defined(MOZ_FENNEC) locale/@AB_CD@/global/printdialog.properties (%chrome/global/printdialog.properties) #endif locale/@AB_CD@/global/resetProfile.dtd (%chrome/global/resetProfile.dtd) diff --git a/widget/windows/nsPrintDialogUtil.cpp b/widget/windows/nsPrintDialogUtil.cpp index 1eb6553e91a81..e27cbe5f39f90 100644 --- a/widget/windows/nsPrintDialogUtil.cpp +++ b/widget/windows/nsPrintDialogUtil.cpp @@ -59,373 +59,12 @@ WIN_LIBS= \ #include "nsWindowsHelpers.h" #include "WinUtils.h" -// Default labels for the radio buttons -static const wchar_t* kAsLaidOutOnScreenStr = L"As &laid out on the screen"; -static const wchar_t* kTheSelectedFrameStr = L"The selected &frame"; -static const wchar_t* kEachFrameSeparately = L"&Each frame separately"; - //----------------------------------------------- // Global Data //----------------------------------------------- -// Identifies which new radio btn was cliked on -static UINT gFrameSelectedRadioBtn = 0; - -// Indicates whether the native print dialog was successfully extended -static bool gDialogWasExtended = false; - -#define PRINTDLG_PROPERTIES "chrome://global/locale/printdialog.properties" static HWND gParentWnd = nullptr; -//---------------------------------------------------------------------------------- -// Return localized bundle for resource strings -static nsresult GetLocalizedBundle(const char* aPropFileName, - nsIStringBundle** aStrBundle) { - NS_ENSURE_ARG_POINTER(aPropFileName); - NS_ENSURE_ARG_POINTER(aStrBundle); - - nsresult rv; - nsCOMPtr bundle; - - // Create bundle - nsCOMPtr stringService = - do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv); - if (NS_SUCCEEDED(rv) && stringService) { - rv = stringService->CreateBundle(aPropFileName, aStrBundle); - } - - return rv; -} - -//-------------------------------------------------------- -// Return localized string -static nsresult GetLocalizedString(nsIStringBundle* aStrBundle, - const char* aKey, nsString& oVal) { - NS_ENSURE_ARG_POINTER(aStrBundle); - NS_ENSURE_ARG_POINTER(aKey); - - // Determine default label from string bundle - nsAutoString valUni; - nsresult rv = aStrBundle->GetStringFromName(aKey, valUni); - if (NS_SUCCEEDED(rv)) { - oVal.Assign(valUni); - } else { - oVal.Truncate(); - } - return rv; -} - -//-------------------------------------------------------- -// Set a multi-byte string in the control -static void SetTextOnWnd(HWND aControl, const nsAString& aStr) { - ::SetWindowTextW(aControl, - reinterpret_cast(aStr.BeginReading())); -} - -//-------------------------------------------------------- -// Will get the control and localized string by "key" -static void SetText(HWND aParent, UINT aId, nsIStringBundle* aStrBundle, - const char* aKey) { - HWND wnd = GetDlgItem(aParent, aId); - if (!wnd) { - return; - } - nsAutoString str; - nsresult rv = GetLocalizedString(aStrBundle, aKey, str); - if (NS_SUCCEEDED(rv)) { - SetTextOnWnd(wnd, str); - } -} - -//-------------------------------------------------------- -static void SetRadio(HWND aParent, UINT aId, bool aIsSet, - bool isEnabled = true) { - HWND wnd = ::GetDlgItem(aParent, aId); - if (!wnd) { - return; - } - if (!isEnabled) { - ::EnableWindow(wnd, FALSE); - return; - } - ::EnableWindow(wnd, TRUE); - ::SendMessage(wnd, BM_SETCHECK, (WPARAM)aIsSet, (LPARAM)0); -} - -//-------------------------------------------------------- -static void SetRadioOfGroup(HWND aDlg, int aRadId) { - int radioIds[] = {rad4, rad5, rad6}; - int numRads = 3; - - for (int i = 0; i < numRads; i++) { - HWND radWnd = ::GetDlgItem(aDlg, radioIds[i]); - if (radWnd != nullptr) { - ::SendMessage(radWnd, BM_SETCHECK, (WPARAM)(radioIds[i] == aRadId), - (LPARAM)0); - } - } -} - -//-------------------------------------------------------- -typedef struct { - const char* mKeyStr; - long mKeyId; -} PropKeyInfo; - -// These are the control ids used in the dialog and -// defined by MS-Windows in commdlg.h -static PropKeyInfo gAllPropKeys[] = {{"printFramesTitleWindows", grp3}, - {"asLaidOutWindows", rad4}, - {"selectedFrameWindows", rad5}, - {"separateFramesWindows", rad6}, - {nullptr, 0}}; - -//-------------------------------------------------------- -//-------------------------------------------------------- -//-------------------------------------------------------- -//-------------------------------------------------------- -// Get the absolute coords of the child windows relative -// to its parent window -static void GetLocalRect(HWND aWnd, RECT& aRect, HWND aParent) { - ::GetWindowRect(aWnd, &aRect); - - // MapWindowPoints converts screen coordinates to client coordinates. - // It works correctly in both left-to-right and right-to-left windows. - ::MapWindowPoints(nullptr, aParent, (LPPOINT)&aRect, 2); -} - -//-------------------------------------------------------- -// Show or Hide the control -static void Show(HWND aWnd, bool bState) { - if (aWnd) { - ::ShowWindow(aWnd, bState ? SW_SHOW : SW_HIDE); - } -} - -//-------------------------------------------------------- -// Create a child window "control" -static HWND CreateControl(LPCWSTR aType, DWORD aStyle, HINSTANCE aHInst, - HWND aHdlg, int aId, LPCWSTR aStr, - const nsIntRect& aRect) { - HWND hWnd = ::CreateWindowW( - aType, aStr, WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | aStyle, aRect.X(), - aRect.Y(), aRect.Width(), aRect.Height(), (HWND)aHdlg, - (HMENU)(intptr_t)aId, aHInst, nullptr); - if (hWnd == nullptr) return nullptr; - - // get the native font for the dialog and - // set it into the new control - HFONT hFont = (HFONT)::SendMessage(aHdlg, WM_GETFONT, (WPARAM)0, (LPARAM)0); - if (hFont != nullptr) { - ::SendMessage(hWnd, WM_SETFONT, (WPARAM)hFont, (LPARAM)0); - } - return hWnd; -} - -//-------------------------------------------------------- -// Create a Radio Button -static HWND CreateRadioBtn(HINSTANCE aHInst, HWND aHdlg, int aId, LPCWSTR aStr, - const nsIntRect& aRect) { - return CreateControl(L"BUTTON", BS_RADIOBUTTON, aHInst, aHdlg, aId, aStr, - aRect); -} - -//-------------------------------------------------------- -// Create a Group Box -static HWND CreateGroupBox(HINSTANCE aHInst, HWND aHdlg, int aId, LPCWSTR aStr, - const nsIntRect& aRect) { - return CreateControl(L"BUTTON", BS_GROUPBOX, aHInst, aHdlg, aId, aStr, aRect); -} - -//-------------------------------------------------------- -// Localizes and initializes the radio buttons and group -static void InitializeExtendedDialog(HWND hdlg, int16_t aHowToEnableFrameUI) { - MOZ_ASSERT(aHowToEnableFrameUI != nsIPrintSettings::kFrameEnableNone, - "should not be called"); - - // Localize the new controls in the print dialog - nsCOMPtr strBundle; - if (NS_SUCCEEDED( - GetLocalizedBundle(PRINTDLG_PROPERTIES, getter_AddRefs(strBundle)))) { - int32_t i = 0; - while (gAllPropKeys[i].mKeyStr != nullptr) { - SetText(hdlg, gAllPropKeys[i].mKeyId, strBundle, gAllPropKeys[i].mKeyStr); - i++; - } - } - - // Set up radio buttons - if (aHowToEnableFrameUI == nsIPrintSettings::kFrameEnableAll) { - SetRadio(hdlg, rad4, false); - SetRadio(hdlg, rad5, true); - SetRadio(hdlg, rad6, false); - // set default so user doesn't have to actually press on it - gFrameSelectedRadioBtn = rad5; - - } else { // nsIPrintSettings::kFrameEnableAsIsAndEach - SetRadio(hdlg, rad4, false); - SetRadio(hdlg, rad5, false, false); - SetRadio(hdlg, rad6, true); - // set default so user doesn't have to actually press on it - gFrameSelectedRadioBtn = rad6; - } -} - -//-------------------------------------------------------- -// Special Hook Procedure for handling the print dialog messages -static UINT CALLBACK PrintHookProc(HWND hdlg, UINT uiMsg, WPARAM wParam, - LPARAM lParam) { - if (uiMsg == WM_COMMAND) { - UINT id = LOWORD(wParam); - if (id == rad4 || id == rad5 || id == rad6) { - gFrameSelectedRadioBtn = id; - SetRadioOfGroup(hdlg, id); - } - - } else if (uiMsg == WM_INITDIALOG) { - PRINTDLG* printDlg = (PRINTDLG*)lParam; - if (printDlg == nullptr) return 0L; - - int16_t howToEnableFrameUI = (int16_t)printDlg->lCustData; - // don't add frame options if they would be disabled anyway - // because there are no frames - if (howToEnableFrameUI == nsIPrintSettings::kFrameEnableNone) return TRUE; - - HINSTANCE hInst = (HINSTANCE)::GetWindowLongPtr(hdlg, GWLP_HINSTANCE); - if (hInst == nullptr) return 0L; - - // Start by getting the local rects of several of the controls - // so we can calculate where the new controls are - HWND wnd = ::GetDlgItem(hdlg, grp1); - if (wnd == nullptr) return 0L; - RECT dlgRect; - GetLocalRect(wnd, dlgRect, hdlg); - - wnd = ::GetDlgItem(hdlg, rad1); // this is the top control "All" - if (wnd == nullptr) return 0L; - RECT rad1Rect; - GetLocalRect(wnd, rad1Rect, hdlg); - - wnd = ::GetDlgItem(hdlg, rad2); // this is the bottom control "Selection" - if (wnd == nullptr) return 0L; - RECT rad2Rect; - GetLocalRect(wnd, rad2Rect, hdlg); - - wnd = ::GetDlgItem(hdlg, rad3); // this is the middle control "Pages" - if (wnd == nullptr) return 0L; - RECT rad3Rect; - GetLocalRect(wnd, rad3Rect, hdlg); - - HWND okWnd = ::GetDlgItem(hdlg, IDOK); - if (okWnd == nullptr) return 0L; - RECT okRect; - GetLocalRect(okWnd, okRect, hdlg); - - wnd = ::GetDlgItem(hdlg, grp4); // this is the "Print range" groupbox - if (wnd == nullptr) return 0L; - RECT prtRect; - GetLocalRect(wnd, prtRect, hdlg); - - // calculate various different "gaps" for layout purposes - - int rbGap = rad3Rect.top - rad1Rect.bottom; // gap between radiobtns - int grpBotGap = dlgRect.bottom - - rad2Rect.bottom; // gap from bottom rb to bottom of grpbox - int grpGap = dlgRect.top - prtRect.bottom; // gap between group boxes - int top = dlgRect.bottom + grpGap; - int radHgt = rad1Rect.bottom - rad1Rect.top + 1; // top of new group box - int y = top + (rad1Rect.top - dlgRect.top); // starting pos of first radio - int rbWidth = - dlgRect.right - rad1Rect.left - 5; // measure from rb left to the edge - // of the groupbox (5 is arbitrary) - nsIntRect rect; - - // Create and position the radio buttons - // - // If any one control cannot be created then - // hide the others and bail out - // - rect.SetRect(rad1Rect.left, y, rbWidth, radHgt); - HWND rad4Wnd = - CreateRadioBtn(hInst, hdlg, rad4, kAsLaidOutOnScreenStr, rect); - if (rad4Wnd == nullptr) return 0L; - y += radHgt + rbGap; - - rect.SetRect(rad1Rect.left, y, rbWidth, radHgt); - HWND rad5Wnd = - CreateRadioBtn(hInst, hdlg, rad5, kTheSelectedFrameStr, rect); - if (rad5Wnd == nullptr) { - Show(rad4Wnd, FALSE); // hide - return 0L; - } - y += radHgt + rbGap; - - rect.SetRect(rad1Rect.left, y, rbWidth, radHgt); - HWND rad6Wnd = - CreateRadioBtn(hInst, hdlg, rad6, kEachFrameSeparately, rect); - if (rad6Wnd == nullptr) { - Show(rad4Wnd, FALSE); // hide - Show(rad5Wnd, FALSE); // hide - return 0L; - } - y += radHgt + grpBotGap; - - // Create and position the group box - rect.SetRect(dlgRect.left, top, dlgRect.right - dlgRect.left + 1, - y - top + 1); - HWND grpBoxWnd = CreateGroupBox(hInst, hdlg, grp3, L"Print Frame", rect); - if (grpBoxWnd == nullptr) { - Show(rad4Wnd, FALSE); // hide - Show(rad5Wnd, FALSE); // hide - Show(rad6Wnd, FALSE); // hide - return 0L; - } - - // Here we figure out the old height of the dlg - // then figure its gap from the old grpbx to the bottom - // then size the dlg - RECT pr, cr; - ::GetWindowRect(hdlg, &pr); - ::GetClientRect(hdlg, &cr); - - int dlgHgt = (cr.bottom - cr.top) + 1; - int bottomGap = dlgHgt - okRect.bottom; - pr.bottom += (dlgRect.bottom - dlgRect.top) + grpGap + 1 - - (dlgHgt - dlgRect.bottom) + bottomGap; - - ::SetWindowPos(hdlg, nullptr, pr.left, pr.top, pr.right - pr.left + 1, - pr.bottom - pr.top + 1, - SWP_NOMOVE | SWP_NOREDRAW | SWP_NOZORDER); - - // figure out the new height of the dialog - ::GetClientRect(hdlg, &cr); - dlgHgt = (cr.bottom - cr.top) + 1; - - // Reposition the OK and Cancel btns - int okHgt = okRect.bottom - okRect.top + 1; - ::SetWindowPos(okWnd, nullptr, okRect.left, dlgHgt - bottomGap - okHgt, 0, - 0, SWP_NOSIZE | SWP_NOREDRAW | SWP_NOZORDER); - - HWND cancelWnd = ::GetDlgItem(hdlg, IDCANCEL); - if (cancelWnd == nullptr) return 0L; - - RECT cancelRect; - GetLocalRect(cancelWnd, cancelRect, hdlg); - int cancelHgt = cancelRect.bottom - cancelRect.top + 1; - ::SetWindowPos(cancelWnd, nullptr, cancelRect.left, - dlgHgt - bottomGap - cancelHgt, 0, 0, - SWP_NOSIZE | SWP_NOREDRAW | SWP_NOZORDER); - - // localize and initialize the groupbox and radiobuttons - InitializeExtendedDialog(hdlg, howToEnableFrameUI); - - // Looks like we were able to extend the dialog - gDialogWasExtended = true; - return TRUE; - } - return 0L; -} - //---------------------------------------------------------------------------------- // Returns a Global Moveable Memory Handle to a DevMode // from the Printer by the name of aPrintName @@ -510,23 +149,6 @@ static void GetDefaultPrinterNameFromGlobalPrinters(nsAString& printerName) { } } -// Determine whether we have a completely native dialog -// or whether we cshould extend it -static bool ShouldExtendPrintDialog() { - nsresult rv; - nsCOMPtr prefs = - do_GetService(NS_PREFSERVICE_CONTRACTID, &rv); - NS_ENSURE_SUCCESS(rv, true); - nsCOMPtr prefBranch; - rv = prefs->GetBranch(nullptr, getter_AddRefs(prefBranch)); - NS_ENSURE_SUCCESS(rv, true); - - bool result; - rv = prefBranch->GetBoolPref("print.extend_native_print_dialog", &result); - NS_ENSURE_SUCCESS(rv, true); - return result; -} - //------------------------------------------------------------------ // Displays the native Print Dialog static nsresult ShowNativePrintDialog(HWND aHWnd, @@ -534,8 +156,6 @@ static nsresult ShowNativePrintDialog(HWND aHWnd, // NS_ENSURE_ARG_POINTER(aHWnd); NS_ENSURE_ARG_POINTER(aPrintSettings); - gDialogWasExtended = false; - // Get the Print Name to be used nsString printerName; aPrintSettings->GetPrinterName(printerName); @@ -597,13 +217,11 @@ static nsresult ShowNativePrintDialog(HWND aHWnd, PD_ALLPAGES | PD_RETURNIC | PD_USEDEVMODECOPIESANDCOLLATE | PD_COLLATE; // if there is a current selection then enable the "Selection" radio button - int16_t howToEnableFrameUI = nsIPrintSettings::kFrameEnableNone; bool isOn; aPrintSettings->GetPrintOptions(nsIPrintSettings::kEnableSelectionRB, &isOn); if (!isOn) { prntdlg.Flags |= PD_NOSELECTION; } - aPrintSettings->GetHowToEnableFrameUI(&howToEnableFrameUI); int32_t pg = 1; aPrintSettings->GetStartPageRange(&pg); @@ -623,15 +241,8 @@ static nsresult ShowNativePrintDialog(HWND aHWnd, prntdlg.hInstance = nullptr; prntdlg.lpPrintTemplateName = nullptr; - if (!ShouldExtendPrintDialog()) { - prntdlg.lCustData = 0; - prntdlg.lpfnPrintHook = nullptr; - } else { - // Set up print dialog "hook" procedure for extending the dialog - prntdlg.lCustData = (DWORD)howToEnableFrameUI; - prntdlg.lpfnPrintHook = (LPPRINTHOOKPROC)PrintHookProc; - prntdlg.Flags |= PD_ENABLEPRINTHOOK; - } + prntdlg.lCustData = 0; + prntdlg.lpfnPrintHook = nullptr; BOOL result; { @@ -704,29 +315,6 @@ static nsresult ShowNativePrintDialog(HWND aHWnd, aPrintSettings->SetPrintRange(nsIPrintSettings::kRangeAllPages); } - if (howToEnableFrameUI != nsIPrintSettings::kFrameEnableNone) { - // make sure the dialog got extended - if (gDialogWasExtended) { - // check to see about the frame radio buttons - switch (gFrameSelectedRadioBtn) { - case rad4: - aPrintSettings->SetPrintFrameType(nsIPrintSettings::kFramesAsIs); - break; - case rad5: - aPrintSettings->SetPrintFrameType(nsIPrintSettings::kSelectedFrame); - break; - case rad6: - aPrintSettings->SetPrintFrameType(nsIPrintSettings::kEachFrameSep); - break; - } // switch - } else { - // if it didn't get extended then have it default to printing - // each frame separately - aPrintSettings->SetPrintFrameType(nsIPrintSettings::kEachFrameSep); - } - } else { - aPrintSettings->SetPrintFrameType(nsIPrintSettings::kNoFrames); - } // Unlock DeviceNames ::GlobalUnlock(prntdlg.hDevNames); @@ -777,27 +365,12 @@ static void PrepareForPrintDialog(nsIWebBrowserPrint* aWebBrowserPrint, NS_ASSERTION(aWebBrowserPrint, "Can't be null"); NS_ASSERTION(aPS, "Can't be null"); - bool isFramesetDocument; - bool isFramesetFrameSelected; bool isIFrameSelected; bool isRangeSelection; - aWebBrowserPrint->GetIsFramesetDocument(&isFramesetDocument); - aWebBrowserPrint->GetIsFramesetFrameSelected(&isFramesetFrameSelected); aWebBrowserPrint->GetIsIFrameSelected(&isIFrameSelected); aWebBrowserPrint->GetIsRangeSelection(&isRangeSelection); - // Setup print options for UI - if (isFramesetDocument) { - if (isFramesetFrameSelected) { - aPS->SetHowToEnableFrameUI(nsIPrintSettings::kFrameEnableAll); - } else { - aPS->SetHowToEnableFrameUI(nsIPrintSettings::kFrameEnableAsIsAndEach); - } - } else { - aPS->SetHowToEnableFrameUI(nsIPrintSettings::kFrameEnableNone); - } - // Now determine how to set up the Frame print UI aPS->SetPrintOptions(nsIPrintSettings::kEnableSelectionRB, isRangeSelection || isIFrameSelected); From 9516915bb504b4eb77e7b165ed69be4232f9e500 Mon Sep 17 00:00:00 2001 From: Jonathan Watt Date: Wed, 15 May 2019 20:13:46 +0100 Subject: [PATCH 005/491] Bug 1552785. Remove Linux print dialog UI for selecting frameset behavior. r=karlt Differential Revision: https://phabricator.services.mozilla.com/D33390 --HG-- extra : rebase_source : cf725f00d9a6b8e8903bb472193efaeb65eade69 --- .../chrome/global/printdialog.properties | 4 -- widget/gtk/nsPrintDialogGTK.cpp | 68 +------------------ 2 files changed, 1 insertion(+), 71 deletions(-) diff --git a/toolkit/locales/en-US/chrome/global/printdialog.properties b/toolkit/locales/en-US/chrome/global/printdialog.properties index 6565b7904c7ad..4bf4440e1280b 100644 --- a/toolkit/locales/en-US/chrome/global/printdialog.properties +++ b/toolkit/locales/en-US/chrome/global/printdialog.properties @@ -7,7 +7,6 @@ # GTK titles: printTitleGTK=Print optionsTabLabelGTK=Options -printFramesTitleGTK=Print Frames # Mac titles: optionsTitleMac=Options: @@ -24,9 +23,6 @@ optionsTitleWindows=Options # In the Windows labels, use an ampersand (&). # On Mac, underscores will be stripped. -asLaidOut=_As Laid Out on the Screen -selectedFrame=The _Selected Frame -separateFrames=Each Frame on Separate _Pages shrinkToFit=Ignore Scaling and S_hrink To Fit Page Width selectionOnly=Print Selection _Only printBGOptions=Print Backgrounds diff --git a/widget/gtk/nsPrintDialogGTK.cpp b/widget/gtk/nsPrintDialogGTK.cpp index e1684b89b2a29..e7885427cea0a 100644 --- a/widget/gtk/nsPrintDialogGTK.cpp +++ b/widget/gtk/nsPrintDialogGTK.cpp @@ -138,9 +138,6 @@ class nsPrintDialogWidgetGTK { private: GtkWidget* dialog; - GtkWidget* radio_as_laid_out; - GtkWidget* radio_selected_frame; - GtkWidget* radio_separate_frames; GtkWidget* shrink_to_fit_toggle; GtkWidget* print_bg_colors_toggle; GtkWidget* print_bg_images_toggle; @@ -160,7 +157,6 @@ class nsPrintDialogWidgetGTK { * "Import" means to copy from NS to GTK * "Export" means to copy from GTK to NS */ - void ExportFramePrinting(nsIPrintSettings* aNS, GtkPrintSettings* aSettings); void ExportHeaderFooter(nsIPrintSettings* aNS); }; @@ -194,49 +190,6 @@ nsPrintDialogWidgetGTK::nsPrintDialogWidgetGTK(nsPIDOMWindowOuter* aParent, GtkWidget* tab_label = gtk_label_new(GetUTF8FromBundle("optionsTabLabelGTK").get()); - int16_t frameUIFlag; - aSettings->GetHowToEnableFrameUI(&frameUIFlag); - radio_as_laid_out = gtk_radio_button_new_with_mnemonic( - nullptr, GetUTF8FromBundle("asLaidOut").get()); - if (frameUIFlag == nsIPrintSettings::kFrameEnableNone) - gtk_widget_set_sensitive(radio_as_laid_out, FALSE); - - radio_selected_frame = gtk_radio_button_new_with_mnemonic_from_widget( - GTK_RADIO_BUTTON(radio_as_laid_out), - GetUTF8FromBundle("selectedFrame").get()); - if (frameUIFlag == nsIPrintSettings::kFrameEnableNone || - frameUIFlag == nsIPrintSettings::kFrameEnableAsIsAndEach) - gtk_widget_set_sensitive(radio_selected_frame, FALSE); - - radio_separate_frames = gtk_radio_button_new_with_mnemonic_from_widget( - GTK_RADIO_BUTTON(radio_as_laid_out), - GetUTF8FromBundle("separateFrames").get()); - if (frameUIFlag == nsIPrintSettings::kFrameEnableNone) - gtk_widget_set_sensitive(radio_separate_frames, FALSE); - - // "Print Frames" options label, bold and center-aligned - GtkWidget* print_frames_label = gtk_label_new(nullptr); - char* pangoMarkup = g_markup_printf_escaped( - "%s", GetUTF8FromBundle("printFramesTitleGTK").get()); - gtk_label_set_markup(GTK_LABEL(print_frames_label), pangoMarkup); - g_free(pangoMarkup); - gtk_misc_set_alignment(GTK_MISC(print_frames_label), 0, 0); - - // Align the radio buttons slightly so they appear to fall under the - // aforementioned label as per the GNOME HIG - GtkWidget* frames_radio_container = gtk_alignment_new(0, 0, 0, 0); - gtk_alignment_set_padding(GTK_ALIGNMENT(frames_radio_container), 8, 0, 12, 0); - - // Radio buttons for the print frames options - GtkWidget* frames_radio_list = gtk_vbox_new(TRUE, 2); - gtk_box_pack_start(GTK_BOX(frames_radio_list), radio_as_laid_out, FALSE, - FALSE, 0); - gtk_box_pack_start(GTK_BOX(frames_radio_list), radio_selected_frame, FALSE, - FALSE, 0); - gtk_box_pack_start(GTK_BOX(frames_radio_list), radio_separate_frames, FALSE, - FALSE, 0); - gtk_container_add(GTK_CONTAINER(frames_radio_container), frames_radio_list); - // Check buttons for shrink-to-fit and print selection GtkWidget* check_buttons_container = gtk_vbox_new(TRUE, 2); shrink_to_fit_toggle = gtk_check_button_new_with_mnemonic( @@ -277,7 +230,7 @@ nsPrintDialogWidgetGTK::nsPrintDialogWidgetGTK(nsPIDOMWindowOuter* aParent, // "Appearance" options label, bold and center-aligned GtkWidget* appearance_label = gtk_label_new(nullptr); - pangoMarkup = g_markup_printf_escaped( + char* pangoMarkup = g_markup_printf_escaped( "%s", GetUTF8FromBundle("printBGOptions").get()); gtk_label_set_markup(GTK_LABEL(appearance_label), pangoMarkup); g_free(pangoMarkup); @@ -355,10 +308,6 @@ nsPrintDialogWidgetGTK::nsPrintDialogWidgetGTK(nsPIDOMWindowOuter* aParent, header_footer_container, FALSE, FALSE, 0); // Construction of everything - gtk_box_pack_start(GTK_BOX(custom_options_tab), print_frames_label, FALSE, - FALSE, 0); - gtk_box_pack_start(GTK_BOX(custom_options_tab), frames_radio_container, FALSE, - FALSE, 0); gtk_box_pack_start(GTK_BOX(custom_options_tab), check_buttons_container, FALSE, FALSE, 10); // 10px padding gtk_box_pack_start(GTK_BOX(custom_options_tab), appearance_vertical_squasher, @@ -397,20 +346,6 @@ gint nsPrintDialogWidgetGTK::Run() { return response; } -void nsPrintDialogWidgetGTK::ExportFramePrinting(nsIPrintSettings* aNS, - GtkPrintSettings* aSettings) { - if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radio_as_laid_out))) - aNS->SetPrintFrameType(nsIPrintSettings::kFramesAsIs); - else if (gtk_toggle_button_get_active( - GTK_TOGGLE_BUTTON(radio_selected_frame))) - aNS->SetPrintFrameType(nsIPrintSettings::kSelectedFrame); - else if (gtk_toggle_button_get_active( - GTK_TOGGLE_BUTTON(radio_separate_frames))) - aNS->SetPrintFrameType(nsIPrintSettings::kEachFrameSep); - else - aNS->SetPrintFrameType(nsIPrintSettings::kNoFrames); -} - void nsPrintDialogWidgetGTK::ExportHeaderFooter(nsIPrintSettings* aNS) { const char* header_footer_str; header_footer_str = OptionWidgetToString(header_dropdown[0]); @@ -472,7 +407,6 @@ nsresult nsPrintDialogWidgetGTK::ExportSettings(nsIPrintSettings* aNSSettings) { GtkPrinter* printer = gtk_print_unix_dialog_get_selected_printer(GTK_PRINT_UNIX_DIALOG(dialog)); if (settings && setup && printer) { - ExportFramePrinting(aNSSettings, settings); ExportHeaderFooter(aNSSettings); aNSSettings->SetOutputFormat(nsIPrintSettings::kOutputFormatNative); From 266860bac6b6fad72aaf0ed76a501a67bb2188c0 Mon Sep 17 00:00:00 2001 From: Jonathan Watt Date: Fri, 17 May 2019 14:52:25 +0100 Subject: [PATCH 006/491] Bug 1552785. Stop setting frameset printing behavior for nsIPrintSettings::kRangeSelection. r=bobowen Differential Revision: https://phabricator.services.mozilla.com/D33623 --HG-- extra : rebase_source : 8f1cb0aadd99501ea54c566d8ef437898fb90bd9 --- layout/printing/nsPrintJob.cpp | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/layout/printing/nsPrintJob.cpp b/layout/printing/nsPrintJob.cpp index db4ef8f5dd487..fcfbe751a83be 100644 --- a/layout/printing/nsPrintJob.cpp +++ b/layout/printing/nsPrintJob.cpp @@ -1438,7 +1438,10 @@ void nsPrintJob::GetDisplayTitleAndURL(const UniquePtr& aPO, //--------------------------------------------------------------------- nsresult nsPrintJob::DocumentReadyForPrinting() { - if (mPrt->mPrintFrameType == nsIPrintSettings::kEachFrameSep) { + int16_t printRangeType = nsIPrintSettings::kRangeAllPages; + mPrt->mPrintSettings->GetPrintRange(&printRangeType); + if (mPrt->mPrintFrameType == nsIPrintSettings::kEachFrameSep && + printRangeType != nsIPrintSettings::kRangeSelection) { // Guarantee that mPrt->mPrintObject won't be deleted during a call of // CheckForChildFrameSets(). RefPtr printData = mPrt; @@ -1995,9 +1998,13 @@ void nsPrintJob::UpdateZoomRatio(nsPrintObject* aPO, bool aSetPixelScale) { // Here is where we set the shrinkage value into the DC // and this is what actually makes it shrink if (aSetPixelScale && aPO->mFrameType != eIFrame) { + int16_t printRangeType = nsIPrintSettings::kRangeAllPages; + mPrt->mPrintSettings->GetPrintRange(&printRangeType); + float ratio; - if (mPrt->mPrintFrameType == nsIPrintSettings::kFramesAsIs || - mPrt->mPrintFrameType == nsIPrintSettings::kNoFrames) { + if ((mPrt->mPrintFrameType == nsIPrintSettings::kFramesAsIs || + mPrt->mPrintFrameType == nsIPrintSettings::kNoFrames) && + printRangeType != nsIPrintSettings::kRangeSelection) { ratio = mPrt->mShrinkRatio - 0.005f; // round down } else { ratio = aPO->mShrinkRatio - 0.005f; // round down @@ -2679,7 +2686,10 @@ bool nsPrintJob::PrintPage(nsPrintObject* aPO, bool& aInRange) { // XXX This is wrong, but the actual behavior in the presence of a print // range sucks. - if (printData->mPrintFrameType == nsIPrintSettings::kEachFrameSep) { + int16_t printRangeType = nsIPrintSettings::kRangeAllPages; + printData->mPrintSettings->GetPrintRange(&printRangeType); + if (printData->mPrintFrameType == nsIPrintSettings::kEachFrameSep && + printRangeType != nsIPrintSettings::kRangeSelection) { endPage = printData->mNumPrintablePages; } @@ -2905,7 +2915,6 @@ nsresult nsPrintJob::EnablePOsForPrinting() { // if we are printing the selection (either an IFrame or selection range) // then set the mPrintFrameType as if it were the selected frame if (printRangeType == nsIPrintSettings::kRangeSelection) { - printData->mPrintFrameType = nsIPrintSettings::kSelectedFrame; printHowEnable = nsIPrintSettings::kFrameEnableNone; } @@ -3029,7 +3038,8 @@ nsresult nsPrintJob::EnablePOsForPrinting() { } // If we are printing "AsIs" then sets all the POs to be printed as is - if (printData->mPrintFrameType == nsIPrintSettings::kFramesAsIs) { + if (printData->mPrintFrameType == nsIPrintSettings::kFramesAsIs && + printRangeType != nsIPrintSettings::kRangeSelection) { SetPrintAsIs(printData->mPrintObject.get()); SetPrintPO(printData->mPrintObject.get(), true); return NS_OK; @@ -3038,7 +3048,8 @@ nsresult nsPrintJob::EnablePOsForPrinting() { // If we are printing the selected Frame then // find that PO for that selected DOMWin and set it all of its // children to be printed - if (printData->mPrintFrameType == nsIPrintSettings::kSelectedFrame) { + if (printData->mPrintFrameType == nsIPrintSettings::kSelectedFrame || + printRangeType == nsIPrintSettings::kRangeSelection) { if ((printData->mIsParentAFrameSet && printData->mCurrentFocusWin) || printData->mIsIFrameSelected) { nsPrintObject* po = FindPrintObjectByDOMWin(printData->mPrintObject.get(), @@ -3061,7 +3072,8 @@ nsresult nsPrintJob::EnablePOsForPrinting() { // If we are print each subdoc separately, // then don't print any of the FraneSet Docs - if (printData->mPrintFrameType == nsIPrintSettings::kEachFrameSep) { + if (printData->mPrintFrameType == nsIPrintSettings::kEachFrameSep && + printRangeType != nsIPrintSettings::kRangeSelection) { SetPrintPO(printData->mPrintObject.get(), true); int32_t cnt = printData->mPrintDocList.Length(); for (int32_t i = 0; i < cnt; i++) { From 659bdf822a09ac67c48c4e56e36b8f16b0fc8571 Mon Sep 17 00:00:00 2001 From: Jonathan Watt Date: Fri, 17 May 2019 16:38:10 +0100 Subject: [PATCH 007/491] Bug 1552785. Stop using GetHowToEnableFrameUI in nsPrintJob::EnablePOsForPrinting. r=bobowen kFrameEnableNone is synonymous with having a non-frameset document. This makes what is going on here explicit. It also gets rid of the kRangeSelection based override and makes that explicit too. Differential Revision: https://phabricator.services.mozilla.com/D33684 --HG-- extra : rebase_source : 7cb1c4be168816f13f01189f672c43b80ab9bbe0 --- layout/printing/nsPrintJob.cpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/layout/printing/nsPrintJob.cpp b/layout/printing/nsPrintJob.cpp index fcfbe751a83be..7cad4cf654ba0 100644 --- a/layout/printing/nsPrintJob.cpp +++ b/layout/printing/nsPrintJob.cpp @@ -2911,19 +2911,13 @@ nsresult nsPrintJob::EnablePOsForPrinting() { PR_PL(("PrintRange: %s \n", gPrintRangeStr[printRangeType])); PR_PL(("----\n")); - // ***** This is the ultimate override ***** - // if we are printing the selection (either an IFrame or selection range) - // then set the mPrintFrameType as if it were the selected frame - if (printRangeType == nsIPrintSettings::kRangeSelection) { - printHowEnable = nsIPrintSettings::kFrameEnableNone; - } - // This tells us that the "Frame" UI has turned off, // so therefore there are no FrameSets/Frames/IFrames to be printed // // This means there are not FrameSets, // but the document could contain an IFrame - if (printHowEnable == nsIPrintSettings::kFrameEnableNone) { + if (!printData->mIsParentAFrameSet || + printRangeType == nsIPrintSettings::kRangeSelection) { // Print all the pages or a sub range of pages if (printRangeType == nsIPrintSettings::kRangeAllPages || printRangeType == nsIPrintSettings::kRangeSpecifiedPageRange) { From 83558018e6ef9402c156e4c91f8bad3212f6822d Mon Sep 17 00:00:00 2001 From: Jonathan Watt Date: Mon, 20 May 2019 15:29:01 +0100 Subject: [PATCH 008/491] Bug 1552785. Reduce code duplication in nsPrintJob::EnablePOsForPrinting. r=bobowen Differential Revision: https://phabricator.services.mozilla.com/D33686 --HG-- extra : rebase_source : c1c0d1712f10b6de417046f517e171f45a6822b3 --- layout/printing/nsPrintJob.cpp | 115 +++++++++++---------------------- 1 file changed, 36 insertions(+), 79 deletions(-) diff --git a/layout/printing/nsPrintJob.cpp b/layout/printing/nsPrintJob.cpp index 7cad4cf654ba0..d219785294bdd 100644 --- a/layout/printing/nsPrintJob.cpp +++ b/layout/printing/nsPrintJob.cpp @@ -2911,90 +2911,35 @@ nsresult nsPrintJob::EnablePOsForPrinting() { PR_PL(("PrintRange: %s \n", gPrintRangeStr[printRangeType])); PR_PL(("----\n")); - // This tells us that the "Frame" UI has turned off, - // so therefore there are no FrameSets/Frames/IFrames to be printed - // - // This means there are not FrameSets, - // but the document could contain an IFrame - if (!printData->mIsParentAFrameSet || - printRangeType == nsIPrintSettings::kRangeSelection) { - // Print all the pages or a sub range of pages - if (printRangeType == nsIPrintSettings::kRangeAllPages || - printRangeType == nsIPrintSettings::kRangeSpecifiedPageRange) { - SetPrintPO(printData->mPrintObject.get(), true); - - // Set the children so they are PrinAsIs - // In this case, the children are probably IFrames - if (printData->mPrintObject->mKids.Length() > 0) { - for (const UniquePtr& po : - printData->mPrintObject->mKids) { - NS_ASSERTION(po, "nsPrintObject can't be null!"); - SetPrintAsIs(po.get()); - } - - // ***** Another override ***** - printData->mPrintFrameType = nsIPrintSettings::kFramesAsIs; - } - PR_PL(("PrintFrameType: %s \n", - gPrintFrameTypeStr[printData->mPrintFrameType])); - PR_PL( - ("HowToEnableFrameUI: %s \n", gFrameHowToEnableStr[printHowEnable])); - PR_PL(("PrintRange: %s \n", gPrintRangeStr[printRangeType])); - return NS_OK; - } - - // This means we are either printed a selected IFrame or - // we are printing the current selection - if (printRangeType == nsIPrintSettings::kRangeSelection) { - // If the currentFocusDOMWin can'r be null if something is selected - if (printData->mCurrentFocusWin) { - // Find the selected IFrame - nsPrintObject* po = FindPrintObjectByDOMWin( - printData->mPrintObject.get(), printData->mCurrentFocusWin); - if (po) { - // Makes sure all of its children are be printed "AsIs" - SetPrintAsIs(po); + bool treatAsNonFrameset = !printData->mIsParentAFrameSet || + printRangeType == nsIPrintSettings::kRangeSelection; - // Now, only enable this POs (the selected PO) and all of its children - SetPrintPO(po, true); + if (treatAsNonFrameset && + (printRangeType == nsIPrintSettings::kRangeAllPages || + printRangeType == nsIPrintSettings::kRangeSpecifiedPageRange)) { + SetPrintPO(printData->mPrintObject.get(), true); - // check to see if we have a range selection, - // as oppose to a insert selection - // this means if the user just clicked on the IFrame then - // there will not be a selection so we want the entire page to print - // - // XXX this is sort of a hack right here to make the page - // not try to reposition itself when printing selection - nsPIDOMWindowOuter* domWin = - po->mDocument->GetOriginalDocument()->GetWindow(); - if (!IsThereARangeSelection(domWin)) { - printRangeType = nsIPrintSettings::kRangeAllPages; - printData->mPrintSettings->SetPrintRange(printRangeType); - } - PR_PL(("PrintFrameType: %s \n", - gPrintFrameTypeStr[printData->mPrintFrameType])); - PR_PL(("HowToEnableFrameUI: %s \n", - gFrameHowToEnableStr[printHowEnable])); - PR_PL(("PrintRange: %s \n", gPrintRangeStr[printRangeType])); - return NS_OK; - } - } else { - for (uint32_t i = 0; i < printData->mPrintDocList.Length(); i++) { - nsPrintObject* po = printData->mPrintDocList.ElementAt(i); - NS_ASSERTION(po, "nsPrintObject can't be null!"); - nsCOMPtr domWin = po->mDocShell->GetWindow(); - if (IsThereARangeSelection(domWin)) { - printData->mCurrentFocusWin = domWin.forget(); - SetPrintPO(po, true); - break; - } - } - return NS_OK; + // Set the children so they are PrinAsIs + // In this case, the children are probably IFrames + if (printData->mPrintObject->mKids.Length() > 0) { + for (const UniquePtr& po : + printData->mPrintObject->mKids) { + NS_ASSERTION(po, "nsPrintObject can't be null!"); + SetPrintAsIs(po.get()); } + + // ***** Another override ***** + printData->mPrintFrameType = nsIPrintSettings::kFramesAsIs; } + PR_PL(("PrintFrameType: %s \n", + gPrintFrameTypeStr[printData->mPrintFrameType])); + PR_PL(("HowToEnableFrameUI: %s \n", gFrameHowToEnableStr[printHowEnable])); + PR_PL(("PrintRange: %s \n", gPrintRangeStr[printRangeType])); + return NS_OK; } - // check to see if there is a selection when a FrameSet is present + // This means we are either printed a selected IFrame or + // we are printing the current selection if (printRangeType == nsIPrintSettings::kRangeSelection) { // If the currentFocusDOMWin can'r be null if something is selected if (printData->mCurrentFocusWin) { @@ -3015,7 +2960,7 @@ nsresult nsPrintJob::EnablePOsForPrinting() { // // XXX this is sort of a hack right here to make the page // not try to reposition itself when printing selection - nsCOMPtr domWin = + nsPIDOMWindowOuter* domWin = po->mDocument->GetOriginalDocument()->GetWindow(); if (!IsThereARangeSelection(domWin)) { printRangeType = nsIPrintSettings::kRangeAllPages; @@ -3028,6 +2973,18 @@ nsresult nsPrintJob::EnablePOsForPrinting() { PR_PL(("PrintRange: %s \n", gPrintRangeStr[printRangeType])); return NS_OK; } + } else if (treatAsNonFrameset) { + for (uint32_t i = 0; i < printData->mPrintDocList.Length(); i++) { + nsPrintObject* po = printData->mPrintDocList.ElementAt(i); + NS_ASSERTION(po, "nsPrintObject can't be null!"); + nsCOMPtr domWin = po->mDocShell->GetWindow(); + if (IsThereARangeSelection(domWin)) { + printData->mCurrentFocusWin = domWin.forget(); + SetPrintPO(po, true); + break; + } + } + return NS_OK; } } From 098392f0932310f98dc28d0e7f7193a519efea41 Mon Sep 17 00:00:00 2001 From: Jonathan Watt Date: Tue, 21 May 2019 16:01:34 +0100 Subject: [PATCH 009/491] Bug 1552785. Remove internal code for various frameset printing behaviors. r=bobowen Differential Revision: https://phabricator.services.mozilla.com/D33624 --HG-- extra : rebase_source : 336e87a05970895684602c9db3e5222918f861c8 extra : source : 98fbf1ed617549496036099b5aee333aa6b29925 --- .../components/extensions/parent/ext-tabs.js | 1 - layout/printing/nsPrintData.cpp | 1 - layout/printing/nsPrintData.h | 1 - layout/printing/nsPrintJob.cpp | 157 ++---------------- layout/printing/nsPrintJob.h | 2 - layout/tools/reftest/reftest-content.js | 1 - mobile/android/chrome/content/PrintHelper.js | 1 - modules/libpref/init/all.js | 3 - toolkit/components/downloads/DownloadCore.jsm | 1 - .../printingui/ipc/PPrintingTypes.ipdlh | 2 - widget/nsIPrintSettings.idl | 17 -- widget/nsIPrintSettingsService.idl | 8 +- widget/nsPrintSettingsImpl.cpp | 26 --- widget/nsPrintSettingsImpl.h | 2 - widget/nsPrintSettingsService.cpp | 4 - 15 files changed, 21 insertions(+), 206 deletions(-) diff --git a/browser/components/extensions/parent/ext-tabs.js b/browser/components/extensions/parent/ext-tabs.js index 8795af3a14558..b62322ebe40c8 100644 --- a/browser/components/extensions/parent/ext-tabs.js +++ b/browser/components/extensions/parent/ext-tabs.js @@ -1163,7 +1163,6 @@ this.tabs = class extends ExtensionAPI { printSettings.printSilent = true; printSettings.showPrintProgress = false; - printSettings.printFrameType = Ci.nsIPrintSettings.kFramesAsIs; printSettings.outputFormat = Ci.nsIPrintSettings.kOutputFormatPDF; if (pageSettings.paperSizeUnit !== null) { diff --git a/layout/printing/nsPrintData.cpp b/layout/printing/nsPrintData.cpp index e0ac4e9421ab7..4b19405d8e2e2 100644 --- a/layout/printing/nsPrintData.cpp +++ b/layout/printing/nsPrintData.cpp @@ -35,7 +35,6 @@ nsPrintData::nsPrintData(ePrintDataType aType) mPreparingForPrint(false), mDocWasToBeDestroyed(false), mShrinkToFit(false), - mPrintFrameType(nsIPrintSettings::kFramesAsIs), mNumPrintablePages(0), mNumPagesPrinted(0), mShrinkRatio(1.0) { diff --git a/layout/printing/nsPrintData.h b/layout/printing/nsPrintData.h index c3c599e71905b..17738dd5c1e9d 100644 --- a/layout/printing/nsPrintData.h +++ b/layout/printing/nsPrintData.h @@ -81,7 +81,6 @@ class nsPrintData { bool mPreparingForPrint; // see comments above bool mDocWasToBeDestroyed; // see comments above bool mShrinkToFit; - int16_t mPrintFrameType; int32_t mNumPrintablePages; int32_t mNumPagesPrinted; float mShrinkRatio; diff --git a/layout/printing/nsPrintJob.cpp b/layout/printing/nsPrintJob.cpp index d219785294bdd..447443b0e5fa3 100644 --- a/layout/printing/nsPrintJob.cpp +++ b/layout/printing/nsPrintJob.cpp @@ -149,10 +149,6 @@ static uint32_t gDumpLOFileNameCnt = 0; #define PRT_YESNO(_p) ((_p) ? "YES" : "NO") static const char* gFrameTypesStr[] = {"eDoc", "eFrame", "eIFrame", "eFrameSet"}; -static const char* gPrintFrameTypeStr[] = {"kNoFrames", "kFramesAsIs", - "kSelectedFrame", "kEachFrameSep"}; -static const char* gFrameHowToEnableStr[] = { - "kFrameEnableNone", "kFrameEnableAll", "kFrameEnableAsIsAndEach"}; static const char* gPrintRangeStr[] = { "kRangeAllPages", "kRangeSpecifiedPageRange", "kRangeSelection"}; @@ -850,19 +846,6 @@ nsresult nsPrintJob::DoCommonPrint(bool aIsPrintPreview, printData->mIsIFrameSelected = IsThereAnIFrameSelected( docShell, printData->mCurrentFocusWin, printData->mIsParentAFrameSet); - // Setup print options for UI - if (printData->mIsParentAFrameSet) { - if (printData->mCurrentFocusWin) { - printData->mPrintSettings->SetHowToEnableFrameUI( - nsIPrintSettings::kFrameEnableAll); - } else { - printData->mPrintSettings->SetHowToEnableFrameUI( - nsIPrintSettings::kFrameEnableAsIsAndEach); - } - } else { - printData->mPrintSettings->SetHowToEnableFrameUI( - nsIPrintSettings::kFrameEnableNone); - } // Now determine how to set up the Frame print UI printData->mPrintSettings->SetPrintOptions( nsIPrintSettings::kEnableSelectionRB, @@ -980,17 +963,9 @@ nsresult nsPrintJob::DoCommonPrint(bool aIsPrintPreview, } if (aIsPrintPreview) { - printData->mPrintSettings->SetPrintFrameType(nsIPrintSettings::kFramesAsIs); - // override any UI that wants to PrintPreview any selection or page range // we want to view every page in PrintPreview each time printData->mPrintSettings->SetPrintRange(nsIPrintSettings::kRangeAllPages); - } else { - printData->mPrintSettings->GetPrintFrameType(&printData->mPrintFrameType); - } - - if (printData->mPrintFrameType == nsIPrintSettings::kEachFrameSep) { - CheckForChildFrameSets(printData->mPrintObject); } if (NS_FAILED(EnablePOsForPrinting())) { @@ -1315,37 +1290,6 @@ void nsPrintJob::BuildDocTree(nsIDocShell* aParentNode, } } -//------------------------------------------------------- -// A Frame's sub-doc may contain content or a FrameSet -// When it contains a FrameSet the mFrameType for the PrintObject -// is always set to an eFrame. Which is fine when printing "AsIs" -// but is incorrect when when printing "Each Frame Separately". -// When printing "Each Frame Separately" the Frame really acts like -// a frameset. -// -// This method walks the PO tree and checks to see if the PrintObject is -// an eFrame and has children that are eFrames (meaning it's a Frame containing -// a FrameSet) If so, then the mFrameType need to be changed to eFrameSet -// -// Also note: We only want to call this we are printing "Each Frame Separately" -// when printing "As Is" leave it as an eFrame -void nsPrintJob::CheckForChildFrameSets(const UniquePtr& aPO) { - NS_ASSERTION(aPO, "Pointer is null!"); - - // Continue recursively walking the chilren of this PO - bool hasChildFrames = false; - for (const UniquePtr& po : aPO->mKids) { - if (po->mFrameType == eFrame) { - hasChildFrames = true; - CheckForChildFrameSets(po); - } - } - - if (hasChildFrames && aPO->mFrameType == eFrame) { - aPO->mFrameType = eFrameSet; - } -} - //--------------------------------------------------------------------- bool nsPrintJob::IsThereAnIFrameSelected(nsIDocShell* aDocShell, nsPIDOMWindowOuter* aDOMWin, @@ -1438,19 +1382,7 @@ void nsPrintJob::GetDisplayTitleAndURL(const UniquePtr& aPO, //--------------------------------------------------------------------- nsresult nsPrintJob::DocumentReadyForPrinting() { - int16_t printRangeType = nsIPrintSettings::kRangeAllPages; - mPrt->mPrintSettings->GetPrintRange(&printRangeType); - if (mPrt->mPrintFrameType == nsIPrintSettings::kEachFrameSep && - printRangeType != nsIPrintSettings::kRangeSelection) { - // Guarantee that mPrt->mPrintObject won't be deleted during a call of - // CheckForChildFrameSets(). - RefPtr printData = mPrt; - CheckForChildFrameSets(printData->mPrintObject); - } - - // // Send the document to the printer... - // nsresult rv = SetupToPrintContent(); if (NS_FAILED(rv)) { // The print job was canceled or there was a problem @@ -2002,9 +1934,7 @@ void nsPrintJob::UpdateZoomRatio(nsPrintObject* aPO, bool aSetPixelScale) { mPrt->mPrintSettings->GetPrintRange(&printRangeType); float ratio; - if ((mPrt->mPrintFrameType == nsIPrintSettings::kFramesAsIs || - mPrt->mPrintFrameType == nsIPrintSettings::kNoFrames) && - printRangeType != nsIPrintSettings::kRangeSelection) { + if (printRangeType != nsIPrintSettings::kRangeSelection) { ratio = mPrt->mShrinkRatio - 0.005f; // round down } else { ratio = aPO->mShrinkRatio - 0.005f; // round down @@ -2684,15 +2614,6 @@ bool nsPrintJob::PrintPage(nsPrintObject* aPO, bool& aInRange) { aInRange = true; } - // XXX This is wrong, but the actual behavior in the presence of a print - // range sucks. - int16_t printRangeType = nsIPrintSettings::kRangeAllPages; - printData->mPrintSettings->GetPrintRange(&printRangeType); - if (printData->mPrintFrameType == nsIPrintSettings::kEachFrameSep && - printRangeType != nsIPrintSettings::kRangeSelection) { - endPage = printData->mNumPrintablePages; - } - printData->DoOnProgressChange(++printData->mNumPagesPrinted, endPage, false, 0); if (NS_WARN_IF(mPrt != printData)) { @@ -2894,20 +2815,11 @@ nsresult nsPrintJob::EnablePOsForPrinting() { return NS_ERROR_FAILURE; } - printData->mPrintFrameType = nsIPrintSettings::kNoFrames; - printData->mPrintSettings->GetPrintFrameType(&printData->mPrintFrameType); - - int16_t printHowEnable = nsIPrintSettings::kFrameEnableNone; - printData->mPrintSettings->GetHowToEnableFrameUI(&printHowEnable); - int16_t printRangeType = nsIPrintSettings::kRangeAllPages; printData->mPrintSettings->GetPrintRange(&printRangeType); PR_PL(("\n")); PR_PL(("********* nsPrintJob::EnablePOsForPrinting *********\n")); - PR_PL(("PrintFrameType: %s \n", - gPrintFrameTypeStr[printData->mPrintFrameType])); - PR_PL(("HowToEnableFrameUI: %s \n", gFrameHowToEnableStr[printHowEnable])); PR_PL(("PrintRange: %s \n", gPrintRangeStr[printRangeType])); PR_PL(("----\n")); @@ -2927,13 +2839,7 @@ nsresult nsPrintJob::EnablePOsForPrinting() { NS_ASSERTION(po, "nsPrintObject can't be null!"); SetPrintAsIs(po.get()); } - - // ***** Another override ***** - printData->mPrintFrameType = nsIPrintSettings::kFramesAsIs; } - PR_PL(("PrintFrameType: %s \n", - gPrintFrameTypeStr[printData->mPrintFrameType])); - PR_PL(("HowToEnableFrameUI: %s \n", gFrameHowToEnableStr[printHowEnable])); PR_PL(("PrintRange: %s \n", gPrintRangeStr[printRangeType])); return NS_OK; } @@ -2966,10 +2872,6 @@ nsresult nsPrintJob::EnablePOsForPrinting() { printRangeType = nsIPrintSettings::kRangeAllPages; printData->mPrintSettings->SetPrintRange(printRangeType); } - PR_PL(("PrintFrameType: %s \n", - gPrintFrameTypeStr[printData->mPrintFrameType])); - PR_PL(("HowToEnableFrameUI: %s \n", - gFrameHowToEnableStr[printHowEnable])); PR_PL(("PrintRange: %s \n", gPrintRangeStr[printRangeType])); return NS_OK; } @@ -2988,51 +2890,27 @@ nsresult nsPrintJob::EnablePOsForPrinting() { } } - // If we are printing "AsIs" then sets all the POs to be printed as is - if (printData->mPrintFrameType == nsIPrintSettings::kFramesAsIs && - printRangeType != nsIPrintSettings::kRangeSelection) { + if (printRangeType != nsIPrintSettings::kRangeSelection) { SetPrintAsIs(printData->mPrintObject.get()); SetPrintPO(printData->mPrintObject.get(), true); return NS_OK; } - // If we are printing the selected Frame then - // find that PO for that selected DOMWin and set it all of its - // children to be printed - if (printData->mPrintFrameType == nsIPrintSettings::kSelectedFrame || - printRangeType == nsIPrintSettings::kRangeSelection) { - if ((printData->mIsParentAFrameSet && printData->mCurrentFocusWin) || - printData->mIsIFrameSelected) { - nsPrintObject* po = FindPrintObjectByDOMWin(printData->mPrintObject.get(), - printData->mCurrentFocusWin); - if (po) { - // NOTE: Calling this sets the "po" and - // we don't want to do this for documents that have no children, - // because then the "DoEndPage" gets called and it shouldn't - if (po->mKids.Length() > 0) { - // Makes sure that itself, and all of its children are printed "AsIs" - SetPrintAsIs(po); - } - - // Now, only enable this POs (the selected PO) and all of its children - SetPrintPO(po, true); + if ((printData->mIsParentAFrameSet && printData->mCurrentFocusWin) || + printData->mIsIFrameSelected) { + nsPrintObject* po = FindPrintObjectByDOMWin(printData->mPrintObject.get(), + printData->mCurrentFocusWin); + if (po) { + // NOTE: Calling this sets the "po" and + // we don't want to do this for documents that have no children, + // because then the "DoEndPage" gets called and it shouldn't + if (po->mKids.Length() > 0) { + // Makes sure that itself, and all of its children are printed "AsIs" + SetPrintAsIs(po); } - } - return NS_OK; - } - // If we are print each subdoc separately, - // then don't print any of the FraneSet Docs - if (printData->mPrintFrameType == nsIPrintSettings::kEachFrameSep && - printRangeType != nsIPrintSettings::kRangeSelection) { - SetPrintPO(printData->mPrintObject.get(), true); - int32_t cnt = printData->mPrintDocList.Length(); - for (int32_t i = 0; i < cnt; i++) { - nsPrintObject* po = printData->mPrintDocList.ElementAt(i); - NS_ASSERTION(po, "nsPrintObject can't be null!"); - if (po->mFrameType == eFrameSet) { - po->mDontPrint = true; - } + // Now, only enable this POs (the selected PO) and all of its children + SetPrintPO(po, true); } } @@ -3520,9 +3398,8 @@ static void DumpPrintObjectsList(const nsTArray& aDocList) { } } - PR_PL(("%s %d %d %d %p %p %p\n", types[po->mFrameType], po->IsPrintable(), - po->mPrintAsIs, po->mHasBeenPrinted, po, po->mDocShell.get(), - rootFrame)); + PR_PL(("%s %d %d %p %p %p\n", types[po->mFrameType], po->IsPrintable(), + po->mHasBeenPrinted, po, po->mDocShell.get(), rootFrame)); } } diff --git a/layout/printing/nsPrintJob.h b/layout/printing/nsPrintJob.h index eb332995a6858..601eb314111a1 100644 --- a/layout/printing/nsPrintJob.h +++ b/layout/printing/nsPrintJob.h @@ -181,8 +181,6 @@ class nsPrintJob final : public nsIObserver, MOZ_CAN_RUN_SCRIPT_BOUNDARY nsresult ReflowPrintObject(const mozilla::UniquePtr& aPO); - void CheckForChildFrameSets(const mozilla::UniquePtr& aPO); - void CalcNumPrintablePages(int32_t& aNumPages); void ShowPrintProgress(bool aIsForPrinting, bool& aDoNotify); nsresult CleanupOnFailure(nsresult aResult, bool aIsPrinting); diff --git a/layout/tools/reftest/reftest-content.js b/layout/tools/reftest/reftest-content.js index b12f212a3d715..2f2a628fa76cf 100644 --- a/layout/tools/reftest/reftest-content.js +++ b/layout/tools/reftest/reftest-content.js @@ -256,7 +256,6 @@ function printToPdf(callback) { ps.printBGColors = true; ps.printToFile = true; ps.toFileName = file.path; - ps.printFrameType = Ci.nsIPrintSettings.kFramesAsIs; ps.outputFormat = Ci.nsIPrintSettings.kOutputFormatPDF; if (isPrintSelection) { diff --git a/mobile/android/chrome/content/PrintHelper.js b/mobile/android/chrome/content/PrintHelper.js index 7ac989230faed..5beabe9fa7342 100644 --- a/mobile/android/chrome/content/PrintHelper.js +++ b/mobile/android/chrome/content/PrintHelper.js @@ -34,7 +34,6 @@ var PrintHelper = { printSettings.printBGColors = false; printSettings.printToFile = true; printSettings.toFileName = file.path; - printSettings.printFrameType = Ci.nsIPrintSettings.kFramesAsIs; printSettings.outputFormat = Ci.nsIPrintSettings.kOutputFormatPDF; let webBrowserPrint = aBrowser.contentWindow.getInterface(Ci.nsIWebBrowserPrint); diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index 912b2d36e89b6..5ea517e812371 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -3867,9 +3867,6 @@ pref("layout.word_select.eat_space_to_next_word", true); // scrollbar snapping region pref("slider.snapMultiplier", 6); -// Whether to extend the native dialog with information on printing frames. -pref("print.extend_native_print_dialog", true); - // Locate plugins by the directories specified in the Windows registry for PLIDs // Which is currently HKLM\Software\MozillaPlugins\xxxPLIDxxx\Path pref("plugin.scan.plid.all", true); diff --git a/toolkit/components/downloads/DownloadCore.jsm b/toolkit/components/downloads/DownloadCore.jsm index 84d570398853c..bee0632c31f1e 100644 --- a/toolkit/components/downloads/DownloadCore.jsm +++ b/toolkit/components/downloads/DownloadCore.jsm @@ -2653,7 +2653,6 @@ this.DownloadPDFSaver.prototype = { printSettings.printBGImages = true; printSettings.printBGColors = true; - printSettings.printFrameType = Ci.nsIPrintSettings.kFramesAsIs; printSettings.headerStrCenter = ""; printSettings.headerStrLeft = ""; printSettings.headerStrRight = ""; diff --git a/toolkit/components/printingui/ipc/PPrintingTypes.ipdlh b/toolkit/components/printingui/ipc/PPrintingTypes.ipdlh index 12aebe0b335f6..5a8787a0d663a 100644 --- a/toolkit/components/printingui/ipc/PPrintingTypes.ipdlh +++ b/toolkit/components/printingui/ipc/PPrintingTypes.ipdlh @@ -42,9 +42,7 @@ struct PrintData { nsString footerStrCenter; nsString footerStrRight; - short howToEnableFrameUI; bool isCancelled; - short printFrameType; bool printSilent; bool shrinkToFit; bool showPrintProgress; diff --git a/widget/nsIPrintSettings.idl b/widget/nsIPrintSettings.idl index 0c8219a4fc17d..3c8a0b4367ff7 100644 --- a/widget/nsIPrintSettings.idl +++ b/widget/nsIPrintSettings.idl @@ -94,21 +94,6 @@ interface nsIPrintSettings : nsISupports const short kPortraitOrientation = 0; const short kLandscapeOrientation = 1; - /** - * Print Frame Constants - */ - const short kNoFrames = 0; - const short kFramesAsIs = 1; - const short kSelectedFrame = 2; - const short kEachFrameSep = 3; - - /** - * How to Enable Frame Set Printing Constants - */ - const short kFrameEnableNone = 0; - const short kFrameEnableAll = 1; - const short kFrameEnableAsIsAndEach = 2; - /** * Output file format */ @@ -205,10 +190,8 @@ interface nsIPrintSettings : nsISupports attribute AString footerStrCenter; attribute AString footerStrRight; - attribute short howToEnableFrameUI; /* indicates how to enable the frameset UI */ attribute boolean isCancelled; /* indicates whether the print job has been cancelled */ readonly attribute boolean saveOnCancel; /* indicates whether the print settings should be saved after a cancel */ - attribute short printFrameType; attribute boolean printSilent; /* print without putting up the dialog */ attribute boolean shrinkToFit; /* shrinks content to fit on page */ attribute boolean showPrintProgress; /* indicates whether the progress dialog should be shown */ diff --git a/widget/nsIPrintSettingsService.idl b/widget/nsIPrintSettingsService.idl index 79e863282db7c..f1391fa8f5a08 100644 --- a/widget/nsIPrintSettingsService.idl +++ b/widget/nsIPrintSettingsService.idl @@ -87,8 +87,8 @@ interface nsIPrintSettingsService : nsISupports * * Items not read: * startPageRange, endPageRange, scaling, printRange, title - * docURL, howToEnableFrameUI, isCancelled, - * printFrameType, printSilent, shrinkToFit, numCopies, + * docURL, isCancelled, + * printSilent, shrinkToFit, numCopies, * printerName * */ @@ -108,8 +108,8 @@ interface nsIPrintSettingsService : nsISupports * * Items not written: * startPageRange, endPageRange, scaling, printRange, title - * docURL, howToEnableFrameUI, isCancelled, - * printFrameType, printSilent, shrinkToFit, numCopies + * docURL, isCancelled, + * printSilent, shrinkToFit, numCopies * */ void savePrintSettingsToPrefs(in nsIPrintSettings aPrintSettings, in boolean aUsePrinterNamePrefix, in unsigned long aFlags); diff --git a/widget/nsPrintSettingsImpl.cpp b/widget/nsPrintSettingsImpl.cpp index 69f6c4fb3e96d..b7e0c7414da0f 100644 --- a/widget/nsPrintSettingsImpl.cpp +++ b/widget/nsPrintSettingsImpl.cpp @@ -20,8 +20,6 @@ nsPrintSettings::nsPrintSettings() mScaling(1.0), mPrintBGColors(false), mPrintBGImages(false), - mPrintFrameType(kFramesAsIs), - mHowToEnableFrameUI(kFrameEnableNone), mIsCancelled(false), mSaveOnCancel(true), mPrintSilent(false), @@ -536,16 +534,6 @@ NS_IMETHODIMP nsPrintSettings::SetFooterStrRight(const nsAString& aTitle) { return NS_OK; } -NS_IMETHODIMP nsPrintSettings::GetPrintFrameType(int16_t* aPrintFrameType) { - NS_ENSURE_ARG_POINTER(aPrintFrameType); - *aPrintFrameType = (int32_t)mPrintFrameType; - return NS_OK; -} -NS_IMETHODIMP nsPrintSettings::SetPrintFrameType(int16_t aPrintFrameType) { - mPrintFrameType = aPrintFrameType; - return NS_OK; -} - NS_IMETHODIMP nsPrintSettings::GetPrintSilent(bool* aPrintSilent) { NS_ENSURE_ARG_POINTER(aPrintSilent); *aPrintSilent = mPrintSilent; @@ -585,18 +573,6 @@ NS_IMETHODIMP nsPrintSettings::SetPaperName(const nsAString& aPaperName) { return NS_OK; } -NS_IMETHODIMP nsPrintSettings::GetHowToEnableFrameUI( - int16_t* aHowToEnableFrameUI) { - NS_ENSURE_ARG_POINTER(aHowToEnableFrameUI); - *aHowToEnableFrameUI = mHowToEnableFrameUI; - return NS_OK; -} -NS_IMETHODIMP nsPrintSettings::SetHowToEnableFrameUI( - int16_t aHowToEnableFrameUI) { - mHowToEnableFrameUI = aHowToEnableFrameUI; - return NS_OK; -} - NS_IMETHODIMP nsPrintSettings::GetIsCancelled(bool* aIsCancelled) { NS_ENSURE_ARG_POINTER(aIsCancelled); *aIsCancelled = mIsCancelled; @@ -784,9 +760,7 @@ nsPrintSettings& nsPrintSettings::operator=(const nsPrintSettings& rhs) { mPrintRange = rhs.mPrintRange; mTitle = rhs.mTitle; mURL = rhs.mURL; - mHowToEnableFrameUI = rhs.mHowToEnableFrameUI; mIsCancelled = rhs.mIsCancelled; - mPrintFrameType = rhs.mPrintFrameType; mPrintSilent = rhs.mPrintSilent; mShrinkToFit = rhs.mShrinkToFit; mShowPrintProgress = rhs.mShowPrintProgress; diff --git a/widget/nsPrintSettingsImpl.h b/widget/nsPrintSettingsImpl.h index 1cb96e3028ff4..66d44508db03f 100644 --- a/widget/nsPrintSettingsImpl.h +++ b/widget/nsPrintSettingsImpl.h @@ -55,8 +55,6 @@ class nsPrintSettings : public nsIPrintSettings { bool mPrintBGColors; // print background colors bool mPrintBGImages; // print background images - int16_t mPrintFrameType; - int16_t mHowToEnableFrameUI; bool mIsCancelled; bool mSaveOnCancel; bool mPrintSilent; diff --git a/widget/nsPrintSettingsService.cpp b/widget/nsPrintSettingsService.cpp index 487b496a32a05..c481fe08f91c9 100644 --- a/widget/nsPrintSettingsService.cpp +++ b/widget/nsPrintSettingsService.cpp @@ -133,9 +133,7 @@ nsPrintSettingsService::SerializeToPrintData(nsIPrintSettings* aSettings, aSettings->GetFooterStrCenter(data->footerStrCenter()); aSettings->GetFooterStrRight(data->footerStrRight()); - aSettings->GetHowToEnableFrameUI(&data->howToEnableFrameUI()); aSettings->GetIsCancelled(&data->isCancelled()); - aSettings->GetPrintFrameType(&data->printFrameType()); aSettings->GetPrintSilent(&data->printSilent()); aSettings->GetShrinkToFit(&data->shrinkToFit()); aSettings->GetShowPrintProgress(&data->showPrintProgress()); @@ -240,9 +238,7 @@ nsPrintSettingsService::DeserializeToPrintSettings(const PrintData& data, settings->SetFooterStrCenter(data.footerStrCenter()); settings->SetFooterStrRight(data.footerStrRight()); - settings->SetHowToEnableFrameUI(data.howToEnableFrameUI()); settings->SetIsCancelled(data.isCancelled()); - settings->SetPrintFrameType(data.printFrameType()); settings->SetPrintSilent(data.printSilent()); settings->SetShrinkToFit(data.shrinkToFit()); settings->SetShowPrintProgress(data.showPrintProgress()); From 39945059b32e4d3f1437033233a0000d390f2d07 Mon Sep 17 00:00:00 2001 From: Jonathan Watt Date: Tue, 21 May 2019 23:25:57 +0100 Subject: [PATCH 010/491] Bug 1552785. Remove printing related isFramesetDocument and isFramesetFrameSelected code. r=bobowen Differential Revision: https://phabricator.services.mozilla.com/D33696 --HG-- extra : rebase_source : 2e7f854a808059b4955ffaad425fe8b68263883e --- layout/base/nsDocumentViewer.cpp | 26 ------------------- layout/printing/nsPrintJob.cpp | 13 ---------- layout/printing/nsPrintJob.h | 2 -- .../components/browser/nsIWebBrowserPrint.idl | 10 ------- .../printingui/ipc/PPrintingTypes.ipdlh | 2 -- .../printingui/ipc/PrintDataUtils.cpp | 13 ---------- widget/nsPrintSettingsService.cpp | 2 -- widget/windows/nsPrintSettingsServiceWin.cpp | 2 -- 8 files changed, 70 deletions(-) diff --git a/layout/base/nsDocumentViewer.cpp b/layout/base/nsDocumentViewer.cpp index e84d67dcb475e..de32b278bc47e 100644 --- a/layout/base/nsDocumentViewer.cpp +++ b/layout/base/nsDocumentViewer.cpp @@ -3779,19 +3779,6 @@ nsDocumentViewer::EnumerateDocumentNames(uint32_t* aCount, # endif } -NS_IMETHODIMP -nsDocumentViewer::GetIsFramesetFrameSelected(bool* aIsFramesetFrameSelected) { -# ifdef NS_PRINTING - *aIsFramesetFrameSelected = false; - NS_ENSURE_TRUE(mPrintJob, NS_ERROR_FAILURE); - - *aIsFramesetFrameSelected = mPrintJob->IsFramesetFrameSelected(); - return NS_OK; -# else - return NS_ERROR_FAILURE; -# endif -} - NS_IMETHODIMP nsDocumentViewer::GetPrintPreviewNumPages(int32_t* aPrintPreviewNumPages) { # ifdef NS_PRINTING @@ -3805,19 +3792,6 @@ nsDocumentViewer::GetPrintPreviewNumPages(int32_t* aPrintPreviewNumPages) { # endif } -NS_IMETHODIMP -nsDocumentViewer::GetIsFramesetDocument(bool* aIsFramesetDocument) { -# ifdef NS_PRINTING - *aIsFramesetDocument = false; - NS_ENSURE_TRUE(mPrintJob, NS_ERROR_FAILURE); - - *aIsFramesetDocument = mPrintJob->IsFramesetDocument(); - return NS_OK; -# else - return NS_ERROR_FAILURE; -# endif -} - NS_IMETHODIMP nsDocumentViewer::GetIsIFrameSelected(bool* aIsIFrameSelected) { # ifdef NS_PRINTING diff --git a/layout/printing/nsPrintJob.cpp b/layout/printing/nsPrintJob.cpp index 447443b0e5fa3..1a2587dc63b59 100644 --- a/layout/printing/nsPrintJob.cpp +++ b/layout/printing/nsPrintJob.cpp @@ -1044,12 +1044,6 @@ nsresult nsPrintJob::PrintPreview( return CommonPrint(true, aPrintSettings, aWebProgressListener, aSourceDoc); } -//---------------------------------------------------------------------------------- -bool nsPrintJob::IsFramesetDocument() const { - nsCOMPtr docShell(do_QueryReferent(mDocShell)); - return IsParentAFrameSet(docShell); -} - //---------------------------------------------------------------------------------- bool nsPrintJob::IsIFrameSelected() { // Get the docshell for this documentviewer @@ -1073,13 +1067,6 @@ bool nsPrintJob::IsRangeSelection() { return IsThereARangeSelection(currentFocusWin); } -//---------------------------------------------------------------------------------- -bool nsPrintJob::IsFramesetFrameSelected() const { - // Get the currently focused window - nsCOMPtr currentFocusWin = FindFocusedDOMWindow(); - return currentFocusWin != nullptr; -} - //---------------------------------------------------------------------------------- int32_t nsPrintJob::GetPrintPreviewNumPages() { // When calling this function, the FinishPrintPreview() function might not diff --git a/layout/printing/nsPrintJob.h b/layout/printing/nsPrintJob.h index 601eb314111a1..c1173afbdd469 100644 --- a/layout/printing/nsPrintJob.h +++ b/layout/printing/nsPrintJob.h @@ -113,10 +113,8 @@ class nsPrintJob final : public nsIObserver, bool IsDoingPrint() const { return mIsDoingPrinting; } bool IsDoingPrintPreview() const { return mIsDoingPrintPreview; } - bool IsFramesetDocument() const; bool IsIFrameSelected(); bool IsRangeSelection(); - bool IsFramesetFrameSelected() const; /// If the returned value is not greater than zero, an error occurred. int32_t GetPrintPreviewNumPages(); /// Callers are responsible for free'ing aResult. diff --git a/toolkit/components/browser/nsIWebBrowserPrint.idl b/toolkit/components/browser/nsIWebBrowserPrint.idl index 00d3ee7eac708..c05ba9039830c 100644 --- a/toolkit/components/browser/nsIWebBrowserPrint.idl +++ b/toolkit/components/browser/nsIWebBrowserPrint.idl @@ -55,16 +55,6 @@ interface nsIWebBrowserPrint : nsISupports */ readonly attribute boolean doingPrintPreview; - /** - * This returns whether the current document is a frameset document - */ - readonly attribute boolean isFramesetDocument; - - /** - * This returns whether the current document is a frameset document - */ - readonly attribute boolean isFramesetFrameSelected; - /** * This returns whether there is an IFrame selected */ diff --git a/toolkit/components/printingui/ipc/PPrintingTypes.ipdlh b/toolkit/components/printingui/ipc/PPrintingTypes.ipdlh index 5a8787a0d663a..8e5f725667df8 100644 --- a/toolkit/components/printingui/ipc/PPrintingTypes.ipdlh +++ b/toolkit/components/printingui/ipc/PPrintingTypes.ipdlh @@ -72,8 +72,6 @@ struct PrintData { nsString deviceName; double printableWidthInInches; double printableHeightInInches; - bool isFramesetDocument; - bool isFramesetFrameSelected; bool isIFrameSelected; bool isRangeSelection; uint8_t[] devModeData; diff --git a/toolkit/components/printingui/ipc/PrintDataUtils.cpp b/toolkit/components/printingui/ipc/PrintDataUtils.cpp index 1e386bb7a738c..581464e0a5e7c 100644 --- a/toolkit/components/printingui/ipc/PrintDataUtils.cpp +++ b/toolkit/components/printingui/ipc/PrintDataUtils.cpp @@ -48,19 +48,6 @@ MockWebBrowserPrint::GetDoingPrintPreview(bool* aDoingPrintPreview) { return NS_ERROR_NOT_IMPLEMENTED; } -NS_IMETHODIMP -MockWebBrowserPrint::GetIsFramesetDocument(bool* aIsFramesetDocument) { - *aIsFramesetDocument = mData.isFramesetDocument(); - return NS_OK; -} - -NS_IMETHODIMP -MockWebBrowserPrint::GetIsFramesetFrameSelected( - bool* aIsFramesetFrameSelected) { - *aIsFramesetFrameSelected = mData.isFramesetFrameSelected(); - return NS_OK; -} - NS_IMETHODIMP MockWebBrowserPrint::GetIsIFrameSelected(bool* aIsIFrameSelected) { *aIsIFrameSelected = mData.isIFrameSelected(); diff --git a/widget/nsPrintSettingsService.cpp b/widget/nsPrintSettingsService.cpp index c481fe08f91c9..c73c8d6dfa600 100644 --- a/widget/nsPrintSettingsService.cpp +++ b/widget/nsPrintSettingsService.cpp @@ -173,8 +173,6 @@ nsPrintSettingsService::SerializeToPrintData(nsIPrintSettings* aSettings, // data->deviceName() default-initializes data->printableWidthInInches() = 0; data->printableHeightInInches() = 0; - data->isFramesetDocument() = false; - data->isFramesetFrameSelected() = false; data->isIFrameSelected() = false; data->isRangeSelection() = false; // data->GTKPrintSettings() default-initializes diff --git a/widget/windows/nsPrintSettingsServiceWin.cpp b/widget/windows/nsPrintSettingsServiceWin.cpp index b49108ba7e17c..7fbbec706266c 100644 --- a/widget/windows/nsPrintSettingsServiceWin.cpp +++ b/widget/windows/nsPrintSettingsServiceWin.cpp @@ -30,8 +30,6 @@ nsPrintSettingsServiceWin::SerializeToPrintData(nsIPrintSettings* aSettings, // Windows wants this information for its print dialogs if (aWBP) { - aWBP->GetIsFramesetDocument(&data->isFramesetDocument()); - aWBP->GetIsFramesetFrameSelected(&data->isFramesetFrameSelected()); aWBP->GetIsIFrameSelected(&data->isIFrameSelected()); aWBP->GetIsRangeSelection(&data->isRangeSelection()); } From af80e5b23ad194f1b82d1c9768df0c8028b41c73 Mon Sep 17 00:00:00 2001 From: moz-wptsync-bot Date: Fri, 17 May 2019 10:59:04 +0000 Subject: [PATCH 011/491] Bug 1540419 [wpt PR 16116] - Use python3-style imports in wptrunner., a=testonly Automatic update from web-platform-tests Use six for modules that move in python 3. -- Use relative imports. -- Use items() instead of iteritems() in the global scope. -- wpt-commits: 03131d0b62c73b3f05e43603b678b3725772640d, cd8431a363be03b9be14036ddbb4647b68ac0018, 8085afbf75e41d56be67652a879147d65edbb258 wpt-pr: 16116 --- .../tests/tools/wptrunner/requirements.txt | 1 + .../tests/tools/wptrunner/wptrunner/config.py | 4 ++-- .../tests/tools/wptrunner/wptrunner/environment.py | 8 ++++++-- .../wptrunner/wptrunner/executors/__init__.py | 8 ++++---- .../tools/wptrunner/wptrunner/executors/base.py | 14 +++++++------- .../wptrunner/formatters/tests/test_chromium.py | 2 +- .../tools/wptrunner/wptrunner/manifestexpected.py | 8 ++++---- .../tools/wptrunner/wptrunner/manifestinclude.py | 6 +++--- .../tools/wptrunner/wptrunner/manifestupdate.py | 8 ++++---- .../tests/tools/wptrunner/wptrunner/metadata.py | 12 ++++++------ .../tests/tools/wptrunner/wptrunner/testloader.py | 12 ++++++------ .../tests/tools/wptrunner/wptrunner/testrunner.py | 2 +- .../tests/tools/wptrunner/wptrunner/tests/base.py | 2 +- .../wptrunner/wptrunner/tests/test_formatters.py | 10 +++------- .../wptrunner/tests/test_manifestexpected.py | 6 +----- .../wptrunner/wptrunner/tests/test_products.py | 10 ++-------- .../wptrunner/wptrunner/tests/test_stability.py | 7 +------ .../wptrunner/wptrunner/tests/test_testloader.py | 5 +---- .../wptrunner/wptrunner/tests/test_wpttest.py | 6 +----- .../tools/wptrunner/wptrunner/update/__init__.py | 2 +- .../tools/wptrunner/wptrunner/update/metadata.py | 2 +- .../tools/wptrunner/wptrunner/update/state.py | 2 +- .../tests/tools/wptrunner/wptrunner/update/sync.py | 5 ++--- .../tools/wptrunner/wptrunner/update/update.py | 10 +++++----- .../tools/wptrunner/wptrunner/wptcommandline.py | 6 +++--- .../wptrunner/wptrunner/wptmanifest/__init__.py | 8 ++++---- .../wptrunner/wptrunner/wptmanifest/parser.py | 10 +++++----- .../wptrunner/wptrunner/wptmanifest/serializer.py | 6 +++--- .../wptrunner/wptmanifest/tests/test_parser.py | 2 +- .../wptrunner/wptmanifest/tests/test_tokenizer.py | 5 +---- .../tests/tools/wptrunner/wptrunner/wpttest.py | 10 +++++----- 31 files changed, 87 insertions(+), 112 deletions(-) diff --git a/testing/web-platform/tests/tools/wptrunner/requirements.txt b/testing/web-platform/tests/tools/wptrunner/requirements.txt index f17b12b3dddff..f2a336875f0ed 100644 --- a/testing/web-platform/tests/tools/wptrunner/requirements.txt +++ b/testing/web-platform/tests/tools/wptrunner/requirements.txt @@ -5,3 +5,4 @@ mozdebug==0.1.1 pillow==5.4.1 urllib3[secure]==1.24.1 requests==2.21.0 +six>=1.8 diff --git a/testing/web-platform/tests/tools/wptrunner/wptrunner/config.py b/testing/web-platform/tests/tools/wptrunner/wptrunner/config.py index 5bd3f467f3eda..d2a61a87594bc 100644 --- a/testing/web-platform/tests/tools/wptrunner/wptrunner/config.py +++ b/testing/web-platform/tests/tools/wptrunner/wptrunner/config.py @@ -1,4 +1,4 @@ -import ConfigParser +from six.moves.configparser import SafeConfigParser import os import sys from collections import OrderedDict @@ -20,7 +20,7 @@ def get_path(self, key, default=None): def read(config_path): config_path = os.path.abspath(config_path) config_root = os.path.split(config_path)[0] - parser = ConfigParser.SafeConfigParser() + parser = SafeConfigParser() success = parser.read(config_path) assert config_path in success, success diff --git a/testing/web-platform/tests/tools/wptrunner/wptrunner/environment.py b/testing/web-platform/tests/tools/wptrunner/wptrunner/environment.py index 6563721caee82..e7a9e4b1e771b 100644 --- a/testing/web-platform/tests/tools/wptrunner/wptrunner/environment.py +++ b/testing/web-platform/tests/tools/wptrunner/wptrunner/environment.py @@ -8,12 +8,16 @@ from mozlog import get_default_logger, handlers, proxy -from wptlogging import LogLevelRewriter -from wptserve.handlers import StringHandler +from .wptlogging import LogLevelRewriter here = os.path.split(__file__)[0] repo_root = os.path.abspath(os.path.join(here, os.pardir, os.pardir, os.pardir)) +sys.path.insert(0, repo_root) +from tools import localpaths # noqa: flake8 + +from wptserve.handlers import StringHandler + serve = None diff --git a/testing/web-platform/tests/tools/wptrunner/wptrunner/executors/__init__.py b/testing/web-platform/tests/tools/wptrunner/wptrunner/executors/__init__.py index a580730db82d8..bf829d93e968d 100644 --- a/testing/web-platform/tests/tools/wptrunner/wptrunner/executors/__init__.py +++ b/testing/web-platform/tests/tools/wptrunner/wptrunner/executors/__init__.py @@ -1,5 +1,5 @@ # flake8: noqa (not ideal, but nicer than adding noqa: F401 to every line!) -from base import (executor_kwargs, - testharness_result_converter, - reftest_result_converter, - TestExecutor) +from .base import (executor_kwargs, + testharness_result_converter, + reftest_result_converter, + TestExecutor) diff --git a/testing/web-platform/tests/tools/wptrunner/wptrunner/executors/base.py b/testing/web-platform/tests/tools/wptrunner/wptrunner/executors/base.py index 4487c2711027c..d1c123a3ef39c 100644 --- a/testing/web-platform/tests/tools/wptrunner/wptrunner/executors/base.py +++ b/testing/web-platform/tests/tools/wptrunner/wptrunner/executors/base.py @@ -1,16 +1,16 @@ import base64 import hashlib -import httplib +from six.moves.http_client import HTTPConnection import io import os import threading import traceback import socket -import urlparse +from six.moves.urllib.parse import urljoin, urlsplit, urlunsplit from abc import ABCMeta, abstractmethod from ..testrunner import Stop -from protocol import Protocol, BaseProtocolPart +from .protocol import Protocol, BaseProtocolPart here = os.path.split(__file__)[0] @@ -48,10 +48,10 @@ def strip_server(url): e.g. http://example.org:8000/tests?id=1#2 becomes /tests?id=1#2""" - url_parts = list(urlparse.urlsplit(url)) + url_parts = list(urlsplit(url)) url_parts[0] = "" url_parts[1] = "" - return urlparse.urlunsplit(url_parts) + return urlunsplit(url_parts) class TestharnessResultConverter(object): @@ -211,7 +211,7 @@ def server_url(self, protocol): self.server_config["ports"][protocol][0]) def test_url(self, test): - return urlparse.urljoin(self.server_url(test.environment["protocol"]), test.url) + return urljoin(self.server_url(test.environment["protocol"]), test.url) @abstractmethod def do_test(self, test): @@ -565,7 +565,7 @@ def is_alive(self): An HTTP request to an invalid path that results in a 404 is proof enough to us that the server is alive and kicking. """ - conn = httplib.HTTPConnection(self.server.host, self.server.port) + conn = HTTPConnection(self.server.host, self.server.port) conn.request("HEAD", self.server.base_path + "invalid") res = conn.getresponse() return res.status == 404 diff --git a/testing/web-platform/tests/tools/wptrunner/wptrunner/formatters/tests/test_chromium.py b/testing/web-platform/tests/tools/wptrunner/wptrunner/formatters/tests/test_chromium.py index 22d9fb4e7ea02..12962f4d8bcab 100644 --- a/testing/web-platform/tests/tools/wptrunner/wptrunner/formatters/tests/test_chromium.py +++ b/testing/web-platform/tests/tools/wptrunner/wptrunner/formatters/tests/test_chromium.py @@ -1,7 +1,7 @@ import json import sys from os.path import dirname, join -from StringIO import StringIO +from six.moves import cStringIO as StringIO from mozlog import handlers, structuredlog diff --git a/testing/web-platform/tests/tools/wptrunner/wptrunner/manifestexpected.py b/testing/web-platform/tests/tools/wptrunner/wptrunner/manifestexpected.py index aef9e1b96ccc8..d3cc8f4624222 100644 --- a/testing/web-platform/tests/tools/wptrunner/wptrunner/manifestexpected.py +++ b/testing/web-platform/tests/tools/wptrunner/wptrunner/manifestexpected.py @@ -1,5 +1,5 @@ import os -import urlparse +from six.moves.urllib.parse import urljoin from collections import deque from wptmanifest.backends import static @@ -237,8 +237,8 @@ def get_test(self, test_id): @property def url(self): - return urlparse.urljoin(self.url_base, - "/".join(self.test_path.split(os.path.sep))) + return urljoin(self.url_base, + "/".join(self.test_path.split(os.path.sep))) @property def disabled(self): @@ -365,7 +365,7 @@ def test_type(self): @property def id(self): - return urlparse.urljoin(self.parent.url, self.name) + return urljoin(self.parent.url, self.name) @property def disabled(self): diff --git a/testing/web-platform/tests/tools/wptrunner/wptrunner/manifestinclude.py b/testing/web-platform/tests/tools/wptrunner/wptrunner/manifestinclude.py index a68fdeb39bc6f..46618c98cf456 100644 --- a/testing/web-platform/tests/tools/wptrunner/wptrunner/manifestinclude.py +++ b/testing/web-platform/tests/tools/wptrunner/wptrunner/manifestinclude.py @@ -6,7 +6,7 @@ """ import glob import os -import urlparse +from six.moves.urllib.parse import urlparse, urlsplit from wptmanifest.node import DataNode from wptmanifest.backends import conditional @@ -68,7 +68,7 @@ def _include(self, test, path_components): def _get_components(self, url): rv = [] - url_parts = urlparse.urlsplit(url) + url_parts = urlsplit(url) variant = "" if url_parts.query: variant += "?" + url_parts.query @@ -103,7 +103,7 @@ def _add_rule(self, test_manifests, url, direction): continue url = test.url if query or fragment: - parsed = urlparse.urlparse(url) + parsed = urlparse(url) if ((query and query != parsed.query) or (fragment and fragment != parsed.fragment)): continue diff --git a/testing/web-platform/tests/tools/wptrunner/wptrunner/manifestupdate.py b/testing/web-platform/tests/tools/wptrunner/wptrunner/manifestupdate.py index 86ac55f791572..452c583d32737 100644 --- a/testing/web-platform/tests/tools/wptrunner/wptrunner/manifestupdate.py +++ b/testing/web-platform/tests/tools/wptrunner/wptrunner/manifestupdate.py @@ -1,7 +1,7 @@ from __future__ import print_function import itertools import os -import urlparse +from six.moves.urllib.parse import urljoin from collections import namedtuple, defaultdict from math import ceil @@ -114,8 +114,8 @@ def has_test(self, test_id): @property def url(self): - return urlparse.urljoin(self.url_base, - "/".join(self.test_path.split(os.path.sep))) + return urljoin(self.url_base, + "/".join(self.test_path.split(os.path.sep))) def set_lsan(self, run_info, result): """Set the result of the test in a particular run @@ -195,7 +195,7 @@ def test_type(self): @property def id(self): """The id of the test represented by this TestNode""" - return urlparse.urljoin(self.parent.url, self.name) + return urljoin(self.parent.url, self.name) def disabled(self, run_info): """Boolean indicating whether this test is disabled when run in an diff --git a/testing/web-platform/tests/tools/wptrunner/wptrunner/metadata.py b/testing/web-platform/tests/tools/wptrunner/wptrunner/metadata.py index ff012eb89ad77..1582ba1130c63 100644 --- a/testing/web-platform/tests/tools/wptrunner/wptrunner/metadata.py +++ b/testing/web-platform/tests/tools/wptrunner/wptrunner/metadata.py @@ -8,12 +8,12 @@ from mozlog import structuredlog -import manifestupdate -import testloader -import wptmanifest -import wpttest -from expected import expected_path -from vcs import git +from . import manifestupdate +from . import testloader +from . import wptmanifest +from . import wpttest +from .expected import expected_path +from .vcs import git manifest = None # Module that will be imported relative to test_root manifestitem = None diff --git a/testing/web-platform/tests/tools/wptrunner/wptrunner/testloader.py b/testing/web-platform/tests/tools/wptrunner/wptrunner/testloader.py index 04d4a32821fa2..7b9bbf3237035 100644 --- a/testing/web-platform/tests/tools/wptrunner/wptrunner/testloader.py +++ b/testing/web-platform/tests/tools/wptrunner/wptrunner/testloader.py @@ -1,14 +1,14 @@ import hashlib import os -import urlparse +from six.moves.urllib.parse import urlsplit from abc import ABCMeta, abstractmethod -from Queue import Empty +from six.moves.queue import Empty from collections import defaultdict, deque from multiprocessing import Queue -import manifestinclude -import manifestexpected -import wpttest +from . import manifestinclude +from . import manifestexpected +from . import wpttest from mozlog import structured manifest = None @@ -348,7 +348,7 @@ def new_group(cls, state, test, **kwargs): depth = kwargs.get("depth") if depth is True or depth == 0: depth = None - path = urlparse.urlsplit(test.url).path.split("/")[1:-1][:depth] + path = urlsplit(test.url).path.split("/")[1:-1][:depth] rv = path != state.get("prev_path") state["prev_path"] = path return rv diff --git a/testing/web-platform/tests/tools/wptrunner/wptrunner/testrunner.py b/testing/web-platform/tests/tools/wptrunner/wptrunner/testrunner.py index 3d9f2dc8f4995..3d930369791e1 100644 --- a/testing/web-platform/tests/tools/wptrunner/wptrunner/testrunner.py +++ b/testing/web-platform/tests/tools/wptrunner/wptrunner/testrunner.py @@ -3,7 +3,7 @@ import multiprocessing import threading import traceback -from Queue import Empty +from six.moves.queue import Empty from collections import namedtuple from multiprocessing import Process, current_process, Queue diff --git a/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/base.py b/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/base.py index 47a31de9ba85d..35c4582e7cbd2 100644 --- a/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/base.py +++ b/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/base.py @@ -7,7 +7,7 @@ sys.path.insert(0, join(dirname(__file__), "..", "..")) -from wptrunner import browsers +from .. import browsers _products = browsers.product_list diff --git a/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/test_formatters.py b/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/test_formatters.py index 37ede150ef0dc..ec91cca1c13e7 100644 --- a/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/test_formatters.py +++ b/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/test_formatters.py @@ -1,17 +1,13 @@ import json -import sys import time -from os.path import dirname, join -from StringIO import StringIO +from six.moves import cStringIO as StringIO import mock from mozlog import handlers, structuredlog -sys.path.insert(0, join(dirname(__file__), "..", "..")) - -from wptrunner.formatters import wptreport -from wptrunner.formatters.wptreport import WptreportFormatter +from ..formatters import wptreport +from ..formatters.wptreport import WptreportFormatter def test_wptreport_runtime(capfd): diff --git a/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/test_manifestexpected.py b/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/test_manifestexpected.py index 93557108fc7a4..0633c5d3720fd 100644 --- a/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/test_manifestexpected.py +++ b/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/test_manifestexpected.py @@ -1,12 +1,8 @@ -import os -import sys from io import BytesIO import pytest -sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..", "..")) - -from wptrunner import manifestexpected +from .. import manifestexpected @pytest.mark.parametrize("fuzzy, expected", [ diff --git a/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/test_products.py b/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/test_products.py index c3454a0dd8f55..5d2bcf075d0f5 100644 --- a/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/test_products.py +++ b/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/test_products.py @@ -1,17 +1,11 @@ -import sys - from os.path import join, dirname import mock import pytest from .base import all_products, active_products - -sys.path.insert(0, join(dirname(__file__), "..", "..", "..", "..")) # repo root -from tools import localpaths # noqa: flake8 - -from wptrunner import environment -from wptrunner import products +from .. import environment +from .. import products test_paths = {"/": {"tests_path": join(dirname(__file__), "..", "..", "..", "..")}} # repo root environment.do_delayed_imports(None, test_paths) diff --git a/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/test_stability.py b/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/test_stability.py index c3c89f2f192e9..474056dde6c67 100644 --- a/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/test_stability.py +++ b/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/test_stability.py @@ -1,9 +1,4 @@ -import sys -from os.path import dirname, join - -sys.path.insert(0, join(dirname(__file__), "..", "..")) - -from wptrunner import stability +from .. import stability def test_is_inconsistent(): diff --git a/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/test_testloader.py b/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/test_testloader.py index c4b49359ad768..836003d106038 100644 --- a/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/test_testloader.py +++ b/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/test_testloader.py @@ -1,15 +1,12 @@ from __future__ import unicode_literals -import os import sys import tempfile import pytest -sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..")) - from mozlog import structured -from wptrunner.testloader import TestFilter as Filter +from ..testloader import TestFilter as Filter from .test_wpttest import make_mock_manifest structured.set_default_logger(structured.structuredlog.StructuredLogger("TestLoader")) diff --git a/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/test_wpttest.py b/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/test_wpttest.py index 6daa59b584738..b4a9d8ca9199d 100644 --- a/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/test_wpttest.py +++ b/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/test_wpttest.py @@ -1,14 +1,10 @@ -import os -import sys from io import BytesIO from mock import Mock -sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..")) - from manifest import manifest as wptmanifest from manifest.item import TestharnessTest -from wptrunner import manifestexpected, wpttest +from .. import manifestexpected, wpttest dir_ini_0 = """\ prefs: [a:b] diff --git a/testing/web-platform/tests/tools/wptrunner/wptrunner/update/__init__.py b/testing/web-platform/tests/tools/wptrunner/wptrunner/update/__init__.py index 9ff3e69f94efb..2626183fc80db 100644 --- a/testing/web-platform/tests/tools/wptrunner/wptrunner/update/__init__.py +++ b/testing/web-platform/tests/tools/wptrunner/wptrunner/update/__init__.py @@ -4,7 +4,7 @@ from .. import wptcommandline -from update import WPTUpdate +from .update import WPTUpdate def remove_logging_args(args): """Take logging args out of the dictionary of command line arguments so diff --git a/testing/web-platform/tests/tools/wptrunner/wptrunner/update/metadata.py b/testing/web-platform/tests/tools/wptrunner/wptrunner/update/metadata.py index 5c42fa3267115..d7e8ba2b47c12 100644 --- a/testing/web-platform/tests/tools/wptrunner/wptrunner/update/metadata.py +++ b/testing/web-platform/tests/tools/wptrunner/wptrunner/update/metadata.py @@ -2,7 +2,7 @@ from .. import metadata, products -from base import Step, StepRunner +from .base import Step, StepRunner class GetUpdatePropertyList(Step): diff --git a/testing/web-platform/tests/tools/wptrunner/wptrunner/update/state.py b/testing/web-platform/tests/tools/wptrunner/wptrunner/update/state.py index ad58513a5d9d8..64dbf1180604c 100644 --- a/testing/web-platform/tests/tools/wptrunner/wptrunner/update/state.py +++ b/testing/web-platform/tests/tools/wptrunner/wptrunner/update/state.py @@ -1,5 +1,5 @@ import os -import cPickle as pickle +from six.moves import cPickle as pickle # noqa: N813 here = os.path.abspath(os.path.split(__file__)[0]) diff --git a/testing/web-platform/tests/tools/wptrunner/wptrunner/update/sync.py b/testing/web-platform/tests/tools/wptrunner/wptrunner/update/sync.py index 2de102057dd49..0d75a1232fc0c 100644 --- a/testing/web-platform/tests/tools/wptrunner/wptrunner/update/sync.py +++ b/testing/web-platform/tests/tools/wptrunner/wptrunner/update/sync.py @@ -5,9 +5,8 @@ import sys import uuid - -from base import Step, StepRunner -from tree import Commit +from .base import Step, StepRunner +from .tree import Commit here = os.path.abspath(os.path.split(__file__)[0]) diff --git a/testing/web-platform/tests/tools/wptrunner/wptrunner/update/update.py b/testing/web-platform/tests/tools/wptrunner/wptrunner/update/update.py index 1097315b42d00..6374e07e5aa3c 100644 --- a/testing/web-platform/tests/tools/wptrunner/wptrunner/update/update.py +++ b/testing/web-platform/tests/tools/wptrunner/wptrunner/update/update.py @@ -1,12 +1,12 @@ import os import sys -from metadata import MetadataUpdateRunner -from sync import SyncFromUpstreamRunner -from tree import GitTree, HgTree, NoVCSTree +from .metadata import MetadataUpdateRunner +from .sync import SyncFromUpstreamRunner +from .tree import GitTree, HgTree, NoVCSTree -from base import Step, StepRunner, exit_clean, exit_unclean -from state import SavedState, UnsavedState +from .base import Step, StepRunner, exit_clean, exit_unclean +from .state import SavedState, UnsavedState def setup_paths(sync_path): diff --git a/testing/web-platform/tests/tools/wptrunner/wptrunner/wptcommandline.py b/testing/web-platform/tests/tools/wptrunner/wptrunner/wptcommandline.py index fef246ddba168..080b1c6b00aa9 100644 --- a/testing/web-platform/tests/tools/wptrunner/wptrunner/wptcommandline.py +++ b/testing/web-platform/tests/tools/wptrunner/wptrunner/wptcommandline.py @@ -6,9 +6,9 @@ from distutils.spawn import find_executable from datetime import timedelta -import config -import wpttest -from formatters import chromium, wptreport, wptscreenshot +from . import config +from . import wpttest +from .formatters import chromium, wptreport, wptscreenshot def abs_path(path): return os.path.abspath(os.path.expanduser(path)) diff --git a/testing/web-platform/tests/tools/wptrunner/wptrunner/wptmanifest/__init__.py b/testing/web-platform/tests/tools/wptrunner/wptrunner/wptmanifest/__init__.py index 8985b5ae35067..e354d5ff4f829 100644 --- a/testing/web-platform/tests/tools/wptrunner/wptrunner/wptmanifest/__init__.py +++ b/testing/web-platform/tests/tools/wptrunner/wptrunner/wptmanifest/__init__.py @@ -1,5 +1,5 @@ # flake8: noqa (not ideal, but nicer than adding noqa: F401 to every line!) -from serializer import serialize -from parser import parse -from backends.static import compile as compile_static -from backends.conditional import compile as compile_condition +from .serializer import serialize +from .parser import parse +from .backends.static import compile as compile_static +from .backends.conditional import compile as compile_condition diff --git a/testing/web-platform/tests/tools/wptrunner/wptrunner/wptmanifest/parser.py b/testing/web-platform/tests/tools/wptrunner/wptrunner/wptmanifest/parser.py index 0db608c4831ac..a347c1bce0dd7 100644 --- a/testing/web-platform/tests/tools/wptrunner/wptrunner/wptmanifest/parser.py +++ b/testing/web-platform/tests/tools/wptrunner/wptrunner/wptmanifest/parser.py @@ -14,12 +14,12 @@ from __future__ import unicode_literals -from cStringIO import StringIO +from six.moves import cStringIO as StringIO -from node import (AtomNode, BinaryExpressionNode, BinaryOperatorNode, - ConditionalNode, DataNode, IndexNode, KeyValueNode, ListNode, - NumberNode, StringNode, UnaryExpressionNode, - UnaryOperatorNode, ValueNode, VariableNode) +from .node import (AtomNode, BinaryExpressionNode, BinaryOperatorNode, + ConditionalNode, DataNode, IndexNode, KeyValueNode, ListNode, + NumberNode, StringNode, UnaryExpressionNode, + UnaryOperatorNode, ValueNode, VariableNode) class ParseError(Exception): diff --git a/testing/web-platform/tests/tools/wptrunner/wptrunner/wptmanifest/serializer.py b/testing/web-platform/tests/tools/wptrunner/wptrunner/wptmanifest/serializer.py index a7e01313ae540..e4749128bf96d 100644 --- a/testing/web-platform/tests/tools/wptrunner/wptrunner/wptmanifest/serializer.py +++ b/testing/web-platform/tests/tools/wptrunner/wptrunner/wptmanifest/serializer.py @@ -1,7 +1,7 @@ -from node import NodeVisitor, ValueNode, ListNode, BinaryExpressionNode -from parser import atoms, precedence +from .node import NodeVisitor, ValueNode, ListNode, BinaryExpressionNode +from .parser import atoms, precedence -atom_names = {v:"@%s" % k for (k,v) in atoms.iteritems()} +atom_names = {v:"@%s" % k for (k,v) in atoms.items()} named_escapes = set(["\a", "\b", "\f", "\n", "\r", "\t", "\v"]) diff --git a/testing/web-platform/tests/tools/wptrunner/wptrunner/wptmanifest/tests/test_parser.py b/testing/web-platform/tests/tools/wptrunner/wptrunner/wptmanifest/tests/test_parser.py index 428ba5a2c7284..3c0781cab4825 100644 --- a/testing/web-platform/tests/tools/wptrunner/wptrunner/wptmanifest/tests/test_parser.py +++ b/testing/web-platform/tests/tools/wptrunner/wptrunner/wptmanifest/tests/test_parser.py @@ -1,6 +1,6 @@ import unittest -from cStringIO import StringIO +from six.moves import cStringIO as StringIO from .. import parser diff --git a/testing/web-platform/tests/tools/wptrunner/wptrunner/wptmanifest/tests/test_tokenizer.py b/testing/web-platform/tests/tools/wptrunner/wptrunner/wptmanifest/tests/test_tokenizer.py index a64ce0c7bb7d8..e0fb8559a1e79 100644 --- a/testing/web-platform/tests/tools/wptrunner/wptrunner/wptmanifest/tests/test_tokenizer.py +++ b/testing/web-platform/tests/tools/wptrunner/wptrunner/wptmanifest/tests/test_tokenizer.py @@ -1,9 +1,6 @@ -import sys -import os import unittest -sys.path.insert(0, os.path.abspath("..")) -from cStringIO import StringIO +from six.moves import cStringIO as StringIO from .. import parser from ..parser import token_types diff --git a/testing/web-platform/tests/tools/wptrunner/wptrunner/wpttest.py b/testing/web-platform/tests/tools/wptrunner/wptrunner/wpttest.py index 10c76eea545e9..85321286ea6d8 100644 --- a/testing/web-platform/tests/tools/wptrunner/wptrunner/wpttest.py +++ b/testing/web-platform/tests/tools/wptrunner/wptrunner/wpttest.py @@ -1,9 +1,9 @@ import os import subprocess -import urlparse +from six.moves.urllib.parse import urljoin from collections import defaultdict -from wptmanifest.parser import atoms +from .wptmanifest.parser import atoms atom_reset = atoms["Reset"] enabled_tests = set(["testharness", "reftest", "wdspec"]) @@ -474,12 +474,12 @@ def fuzzy_override(self): for key, data in value: if isinstance(key, (tuple, list)): key = list(key) - key[0] = urlparse.urljoin(self.url, key[0]) - key[1] = urlparse.urljoin(self.url, key[1]) + key[0] = urljoin(self.url, key[0]) + key[1] = urljoin(self.url, key[1]) key = tuple(key) elif key: # Key is just a relative url to a ref - key = urlparse.urljoin(self.url, key) + key = urljoin(self.url, key) values[key] = data return values From edf83b8c77b0281de40eebc5d93d1ba529b48e23 Mon Sep 17 00:00:00 2001 From: autofoolip Date: Fri, 17 May 2019 11:01:29 +0000 Subject: [PATCH 012/491] Bug 1531478 [wpt PR 15515] - Update interfaces/html.idl, a=testonly Automatic update from web-platform-tests Update interfaces/html.idl (#15515) Note: This file was recently manually updated in commit 4c70b5a6f3. This commit may revert some of those changes. Source: https://github.com/tidoust/reffy-reports/blob/66323ce/whatwg/idl/html.idl Build: https://travis-ci.org/tidoust/reffy-reports/builds/498574778 -- wpt-commits: 4af2964244316ebe198a1d472c99ee6bd1cbdbcf wpt-pr: 15515 --- testing/web-platform/tests/interfaces/html.idl | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/testing/web-platform/tests/interfaces/html.idl b/testing/web-platform/tests/interfaces/html.idl index 5e318377a0b7a..4d4f655542602 100644 --- a/testing/web-platform/tests/interfaces/html.idl +++ b/testing/web-platform/tests/interfaces/html.idl @@ -114,8 +114,6 @@ interface HTMLElement : Element { [CEReactions] attribute DOMString autocapitalize; [CEReactions] attribute [TreatNullAs=EmptyString] DOMString innerText; - - ElementInternals attachInternals(); }; HTMLElement includes GlobalEventHandlers; @@ -178,6 +176,8 @@ interface HTMLLinkElement : HTMLElement { [CEReactions] attribute DOMString hreflang; [CEReactions] attribute DOMString type; [SameObject, PutForwards=value] readonly attribute DOMTokenList sizes; + [CEReactions] attribute USVString imageSrcset; + [CEReactions] attribute DOMString imageSizes; [CEReactions] attribute DOMString referrerPolicy; }; HTMLLinkElement includes LinkStyle; @@ -1411,11 +1411,6 @@ dictionary ElementDefinitionOptions { DOMString extends; }; -[Exposed=Window] -interface ElementInternals { - -}; - dictionary FocusOptions { boolean preventScroll = false; }; From 99ef394fa913ff3272a74b4a77bb5c776e6f0a21 Mon Sep 17 00:00:00 2001 From: Matt Falkenhagen Date: Fri, 17 May 2019 11:01:34 +0000 Subject: [PATCH 013/491] Bug 1541696 [wpt PR 16171] - Gardening: dedicated-worker-options-credentials.html is slow., a=testonly Automatic update from web-platform-tests Gardening: dedicated-worker-options-credentials.html is slow. This test creates a lot of workers and sometimes times out. Bug: 947253 Change-Id: I5cdea1f518109802c96d68571fddb0786b11ec10 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1545968 Commit-Queue: Matt Falkenhagen Commit-Queue: Hiroki Nakagawa Auto-Submit: Matt Falkenhagen Reviewed-by: Hiroki Nakagawa Cr-Commit-Position: refs/heads/master@{#646216} -- wpt-commits: 90cf9684e1eee91559fde5bd014bf66700629cbe wpt-pr: 16171 --- .../workers/modules/dedicated-worker-options-credentials.html | 1 + 1 file changed, 1 insertion(+) diff --git a/testing/web-platform/tests/workers/modules/dedicated-worker-options-credentials.html b/testing/web-platform/tests/workers/modules/dedicated-worker-options-credentials.html index 34f223981ca92..03736cbb6202b 100644 --- a/testing/web-platform/tests/workers/modules/dedicated-worker-options-credentials.html +++ b/testing/web-platform/tests/workers/modules/dedicated-worker-options-credentials.html @@ -1,5 +1,6 @@ DedicatedWorker: WorkerOptions 'credentials' + From 8ef414f749591471f5dda0fa4b4d3389dbc52cf9 Mon Sep 17 00:00:00 2001 From: Javier Fernandez Date: Fri, 17 May 2019 11:01:38 +0000 Subject: [PATCH 014/491] Bug 1541698 [wpt PR 16159] - [css-text] Consider former breaking opportunities before breaking a word, a=testonly Automatic update from web-platform-tests [css-text] Consider former breaking opportunities before breaking a word When using the break-spaces+break-word combination, there are breaking opportunities before the first whitespace after a word. However, these should be avoided if there are previous soft-breaking opportunities in the line. We were only considering single leading whitespaces as one of this former breaking opportunities, which leads to wrong line-breaking behaviors like the one described in the bug. With this change we try to generalize the pattern of using one of this former breaking opportunities, but maximizing the line's length. Bug: 905315 Change-Id: I289e44277a3953290f865efb28e3c83deb31fa03 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1546098 Reviewed-by: Koji Ishii Commit-Queue: Javier Fernandez Cr-Commit-Position: refs/heads/master@{#646230} -- wpt-commits: 54ece6de4bf85e253b49c6f564d00b2d2fa5edbe wpt-pr: 16159 --- .../white-space/break-spaces-003.html | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 testing/web-platform/tests/css/css-text/white-space/break-spaces-003.html diff --git a/testing/web-platform/tests/css/css-text/white-space/break-spaces-003.html b/testing/web-platform/tests/css/css-text/white-space/break-spaces-003.html new file mode 100644 index 0000000000000..c0101fd7dec54 --- /dev/null +++ b/testing/web-platform/tests/css/css-text/white-space/break-spaces-003.html @@ -0,0 +1,37 @@ + + +CSS Text Test: white-space: break-spaces + + + + + + + + + + +

Test passes if there is a filled green square and no red.

+
XXXX
XXXX
XXXX
XXXX
+
XX X X
+ From c6a4bcb4b43bdd82cfac805591b08141778137a8 Mon Sep 17 00:00:00 2001 From: Sam Sneddon Date: Fri, 17 May 2019 11:01:42 +0000 Subject: [PATCH 015/491] Bug 1541707 [wpt PR 16135] - Fix manifest regeneration differences, a=testonly Automatic update from web-platform-tests Don't bother downloading manifest if we're rebuilding -- Ensure items are removed from json_data when set -- Bump manifest version to v6 This is needed as we need to force regeneration to fix the bugs fixed in cb839d72f8dbb28f10775377771e4799deb79928 and f759f0b3a8cb7457adbf30dc0734d3a158ce4990. -- Get rid of special-casing for old manifests URLs are guaranteed to be relative paths, and script_metadata is guaranteed to exist if it's non-empty and never needs recomputed. -- __bool__ doesn't exist; we want __nonzero__ -- wpt-commits: 55b021a2529c0bde4e488b89af7fdaa63a3037ff, 3f250e3a22634ba043320b562cf3bc27413afdc7, 398466b252b3da92204001db8c37b452cb22e3c8, fc73997d2bc182c7d806fc8cd73eabc19fe466bb, ab9bf5190a3152cef6eda56404ba623356268ea7 wpt-pr: 16135 --- .../web-platform/tests/tools/manifest/item.py | 23 +----- .../tests/tools/manifest/manifest.py | 10 ++- .../tests/tools/manifest/tests/test_item.py | 4 +- .../tools/manifest/tests/test_manifest.py | 79 +++++++++++-------- .../tests/tools/manifest/update.py | 2 +- 5 files changed, 62 insertions(+), 56 deletions(-) diff --git a/testing/web-platform/tests/tools/manifest/item.py b/testing/web-platform/tests/tools/manifest/item.py index 5e313faa751e8..b6d33e8452cde 100644 --- a/testing/web-platform/tests/tools/manifest/item.py +++ b/testing/web-platform/tests/tools/manifest/item.py @@ -63,16 +63,12 @@ class URLManifestItem(ManifestItem): def __init__(self, tests_root, path, url_base, url, **extras): super(URLManifestItem, self).__init__(tests_root, path) + assert url_base[0] == "/" self.url_base = url_base + assert url[0] != "/" self._url = url self._extras = extras - @property - def _source_file(self): - """create a SourceFile for the item""" - from .sourcefile import SourceFile - return SourceFile(self._tests_root, self.path, self.url_base) - @property def id(self): return self.url @@ -80,11 +76,6 @@ def id(self): @property def url(self): # we can outperform urljoin, because we know we just have path relative URLs - if self._url[0] == "/": - # TODO: MANIFEST6 - # this is actually a bug in older generated manifests, _url shouldn't - # be an absolute path - return self._url if self.url_base == "/": return "/" + self._url return urljoin(self.url_base, self._url) @@ -125,12 +116,7 @@ def jsshell(self): @property def script_metadata(self): - if "script_metadata" in self._extras: - return self._extras["script_metadata"] - else: - # TODO: MANIFEST6 - # this branch should go when the manifest version is bumped - return self._source_file.script_metadata + return self._extras.get("script_metadata") def to_json(self): rv = super(TestharnessTest, self).to_json() @@ -140,8 +126,7 @@ def to_json(self): rv[-1]["testdriver"] = self.testdriver if self.jsshell: rv[-1]["jsshell"] = True - if self.script_metadata is not None: - # we store this even if it is [] to avoid having to read the source file + if self.script_metadata: rv[-1]["script_metadata"] = self.script_metadata return rv diff --git a/testing/web-platform/tests/tools/manifest/manifest.py b/testing/web-platform/tests/tools/manifest/manifest.py index afbc92ae8ab2e..bfe57c7823b26 100644 --- a/testing/web-platform/tests/tools/manifest/manifest.py +++ b/testing/web-platform/tests/tools/manifest/manifest.py @@ -15,7 +15,7 @@ except ImportError: fast_json = json -CURRENT_VERSION = 5 +CURRENT_VERSION = 6 class ManifestError(Exception): @@ -68,8 +68,8 @@ def __getitem__(self, key): self.load(key) return self.data[key] - def __bool__(self): - return bool(self.data) + def __nonzero__(self): + return bool(self.data) or bool(self.json_data) def __len__(self): rv = len(self.data) @@ -86,6 +86,10 @@ def __delitem__(self, key): raise KeyError def __setitem__(self, key, value): + if self.json_data is not None: + path = from_os_path(key) + if path in self.json_data: + del self.json_data[path] self.data[key] = value def __contains__(self, key): diff --git a/testing/web-platform/tests/tools/manifest/tests/test_item.py b/testing/web-platform/tests/tools/manifest/tests/test_item.py index a73d46be68579..385180b25ce1e 100644 --- a/testing/web-platform/tests/tools/manifest/tests/test_item.py +++ b/testing/web-platform/tests/tools/manifest/tests/test_item.py @@ -14,7 +14,7 @@ "a.b.serviceworker.c.d", ]) def test_url_https(path): - m = URLManifestItem("/foobar", "/" + path, "/", "/foo.bar/" + path) + m = URLManifestItem("/foo", "bar/" + path, "/", "bar/" + path) assert m.https is True @@ -36,6 +36,6 @@ def test_url_https(path): "a.serviceworkerb.c", ]) def test_url_not_https(path): - m = URLManifestItem("/foobar", "/" + path, "/", "/foo.bar/" + path) + m = URLManifestItem("/foo", "bar/" + path, "/", "bar/" + path) assert m.https is False diff --git a/testing/web-platform/tests/tools/manifest/tests/test_manifest.py b/testing/web-platform/tests/tools/manifest/tests/test_manifest.py index 4a56b633f5624..22335564b7c8a 100644 --- a/testing/web-platform/tests/tools/manifest/tests/test_manifest.py +++ b/testing/web-platform/tests/tools/manifest/tests/test_manifest.py @@ -15,7 +15,7 @@ def SourceFileWithTest(path, hash, cls, **kwargs): if cls == item.SupportFile: test = cls("/foobar", path, **kwargs) else: - test = cls("/foobar", path, "/", utils.rel_path_to_url(path), **kwargs) + test = cls("/foobar", path, "/", utils.from_os_path(path), **kwargs) s.manifest_items = mock.Mock(return_value=(cls.item_type, [test])) return s @@ -58,11 +58,11 @@ def sourcefile_strategy(draw): ref_path = draw(rel_dir_file_path()) h.assume(path != ref_path) ref_eq = draw(hs.sampled_from(["==", "!="])) - test = cls("/foobar", path, "/", utils.rel_path_to_url(path), references=[(utils.rel_path_to_url(ref_path), ref_eq)]) + test = cls("/foobar", path, "/", utils.from_os_path(path), references=[(utils.from_os_path(ref_path), ref_eq)]) elif cls is item.SupportFile: test = cls("/foobar", path) else: - test = cls("/foobar", path, "/", utils.rel_path_to_url(path)) + test = cls("/foobar", path, "/", utils.from_os_path(path)) s.manifest_items = mock.Mock(return_value=(cls.item_type, [test])) return s @@ -111,42 +111,36 @@ def test_manifest_to_json_forwardslash(): 'paths': { 'a/b': ('0000000000000000000000000000000000000000', 'testharness') }, - 'version': 5, + 'version': 6, 'url_base': '/', 'items': { 'testharness': { - 'a/b': [['/a/b', {}]] + 'a/b': [['a/b', {}]] } } } +@pytest.mark.skipif(os.sep != "\\", reason="backslash path") def test_manifest_to_json_backslash(): m = manifest.Manifest() s = SourceFileWithTest("a\\b", "0"*40, item.TestharnessTest) - if os.path.sep == "\\": - assert m.update([(s, True)]) is True - - assert m.to_json() == { - 'paths': { - 'a/b': ('0000000000000000000000000000000000000000', 'testharness') - }, - 'version': 5, - 'url_base': '/', - 'items': { - 'testharness': { - 'a/b': [['/a/b', {}]] - } + assert m.update([(s, True)]) is True + + assert m.to_json() == { + 'paths': { + 'a/b': ('0000000000000000000000000000000000000000', 'testharness') + }, + 'version': 6, + 'url_base': '/', + 'items': { + 'testharness': { + 'a/b': [['a/b', {}]] } } - else: - with pytest.raises(ValueError): - # one of these must raise ValueError - # the first must return True if it doesn't raise - assert m.update([(s, True)]) is True - m.to_json() + } def test_manifest_from_json_backslash(): @@ -154,11 +148,11 @@ def test_manifest_from_json_backslash(): 'paths': { 'a\\b': ('0000000000000000000000000000000000000000', 'testharness') }, - 'version': 5, + 'version': 6, 'url_base': '/', 'items': { 'testharness': { - 'a\\b': [['/a/b', {}]] + 'a\\b': [['a/b', {}]] } } } @@ -294,8 +288,8 @@ def test_iterpath(): m = manifest.Manifest() sources = [SourceFileWithTest("test1", "0"*40, item.RefTestNode, references=[("/test1-ref", "==")]), - SourceFileWithTests("test2", "1"*40, item.TestharnessTest, [("/test2-1.html",), - ("/test2-2.html",)]), + SourceFileWithTests("test2", "1"*40, item.TestharnessTest, [("test2-1.html",), + ("test2-2.html",)]), SourceFileWithTest("test3", "0"*40, item.TestharnessTest)] m.update([(s, True) for s in sources]) @@ -308,8 +302,8 @@ def test_filter(): m = manifest.Manifest() sources = [SourceFileWithTest("test1", "0"*40, item.RefTestNode, references=[("/test1-ref", "==")]), - SourceFileWithTests("test2", "0"*40, item.TestharnessTest, [("/test2-1.html",), - ("/test2-2.html",)]), + SourceFileWithTests("test2", "0"*40, item.TestharnessTest, [("test2-1.html",), + ("test2-2.html",)]), SourceFileWithTest("test3", "0"*40, item.TestharnessTest)] m.update([(s, True) for s in sources]) @@ -317,7 +311,7 @@ def test_filter(): def filter(it): for test in it: - if test[0] in ["/test2-2.html", "/test3"]: + if test[0] in ["test2-2.html", "test3"]: yield test filtered_manifest = manifest.Manifest.from_json("/", json, types=["testharness"], meta_filters=[filter]) @@ -407,3 +401,26 @@ def test_update_from_json(): test1 = s1.manifest_items()[1][0] assert list(m) == [("testharness", test1.path, {test1})] + + +def test_update_from_json_modified(): + # Create the original manifest + m = manifest.Manifest() + s1 = SourceFileWithTest("test1", "0"*40, item.TestharnessTest) + m.update([(s1, True)]) + json_str = m.to_json() + + # Reload it from JSON + m = manifest.Manifest.from_json("/", json_str) + + # Update it with timeout="long" + s2 = SourceFileWithTest("test1", "1"*40, item.TestharnessTest, timeout="long") + m.update([(s2, True)]) + json_str = m.to_json() + assert json_str == { + 'items': {'testharness': {'test1': [['test1', {"timeout": "long"}]]}}, + 'paths': {'test1': ('1111111111111111111111111111111111111111', + 'testharness')}, + 'url_base': '/', + 'version': 6 + } diff --git a/testing/web-platform/tests/tools/manifest/update.py b/testing/web-platform/tests/tools/manifest/update.py index 217d767cece27..321cfebe2a605 100755 --- a/testing/web-platform/tests/tools/manifest/update.py +++ b/testing/web-platform/tests/tools/manifest/update.py @@ -33,7 +33,7 @@ def update_from_cli(**kwargs): path = kwargs["path"] assert tests_root is not None - if kwargs["download"]: + if not kwargs["rebuild"] and kwargs["download"]: download_from_github(path, tests_root) manifest.load_and_update(tests_root, From da3c039cb12a95de40682698687a0bd0b70b9f8a Mon Sep 17 00:00:00 2001 From: jugglinmike Date: Fri, 17 May 2019 11:01:47 +0000 Subject: [PATCH 016/491] Bug 1541713 [wpt PR 16157] - [wptrunner] Detect crash during script execution, a=testonly Automatic update from web-platform-tests [wptrunner] Detect crash during script execution (#16157) As of 2019-03-29, WebDriver does not define expected behavior for cases where the browser crashes during script execution [1]. The type of the value returned by `execute_script` therefore may defy the expectations of subsequent statements, resulting in a Python exception which obscures the reason for the problem. Raise an exception describing a crash to make test results more clear than the Python type-related error that would otherwise occur. [1] https://github.com/w3c/webdriver/issues/1308 -- wpt-commits: 449559550829e690d0c68edc37d1c21c0894c72c wpt-pr: 16157 --- .../wptrunner/executors/executorwebdriver.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/testing/web-platform/tests/tools/wptrunner/wptrunner/executors/executorwebdriver.py b/testing/web-platform/tests/tools/wptrunner/wptrunner/executors/executorwebdriver.py index 563252ce2bbfe..e449390116b06 100644 --- a/testing/web-platform/tests/tools/wptrunner/wptrunner/executors/executorwebdriver.py +++ b/testing/web-platform/tests/tools/wptrunner/wptrunner/executors/executorwebdriver.py @@ -356,6 +356,20 @@ def do_testharness(self, protocol, url, timeout): while True: result = protocol.base.execute_script( self.script_resume % format_map, async=True) + + # As of 2019-03-29, WebDriver does not define expected behavior for + # cases where the browser crashes during script execution: + # + # https://github.com/w3c/webdriver/issues/1308 + if not isinstance(result, list) or len(result) != 2: + try: + is_alive = self.is_alive() + except client.WebDriverException: + is_alive = False + + if not is_alive: + raise Exception("Browser crashed during script execution.") + done, rv = handler(result) if done: break From 3832dca9ee59bfaeb16640a3b42aa9f59104b940 Mon Sep 17 00:00:00 2001 From: jgraham Date: Fri, 17 May 2019 11:01:51 +0000 Subject: [PATCH 017/491] Bug 1541718 [wpt PR 16176] - Fix downloading stable Firefox, a=testonly Automatic update from web-platform-tests Fix downloading stable Firefox (#16176) -- wpt-commits: 4c49fb8ca681cd8d294a2f6bb39b1b5ca592e6d3 wpt-pr: 16176 --- testing/web-platform/tests/tools/wpt/browser.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testing/web-platform/tests/tools/wpt/browser.py b/testing/web-platform/tests/tools/wpt/browser.py index f5bc7c0af0269..52157bca4e71a 100644 --- a/testing/web-platform/tests/tools/wpt/browser.py +++ b/testing/web-platform/tests/tools/wpt/browser.py @@ -101,7 +101,7 @@ def install(self, dest=None, channel="nightly"): product = { "nightly": "firefox-nightly-latest-ssl", "beta": "firefox-beta-latest-ssl", - "stable": "firefox-beta-latest-ssl" + "stable": "firefox-latest-ssl" } os_builds = { @@ -267,7 +267,7 @@ def install_prefs(self, binary, dest=None, channel=None): if version: dest = os.path.join(dest, version) have_cache = False - if os.path.exists(dest): + if os.path.exists(dest) and len(os.listdir(dest)) > 0: if channel != "nightly": have_cache = True else: From 76748726c714a9dcb5c90140072bdac40838a828 Mon Sep 17 00:00:00 2001 From: Sam Sneddon Date: Fri, 17 May 2019 11:01:55 +0000 Subject: [PATCH 018/491] Bug 1541725 [wpt PR 16179] - Fix wptrunner unit tests, a=testonly Automatic update from web-platform-tests Update wptrunner tests after #16135 -- Run wptrunner unit tests for all tools/ changes -- wpt-commits: f737eb59a0ab3b9cba8b8dac08fae20eead4e448, da590a9ed11ca182d253b43c19b3d4e6c9dfcea2 wpt-pr: 16179 --- testing/web-platform/tests/tools/ci/jobs.py | 2 +- testing/web-platform/tests/tools/ci/tests/test_jobs.py | 2 +- .../tools/wptrunner/wptrunner/tests/test_update.py | 10 +++------- .../tools/wptrunner/wptrunner/tests/test_wpttest.py | 4 ++-- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/testing/web-platform/tests/tools/ci/jobs.py b/testing/web-platform/tests/tools/ci/jobs.py index 2b54327ad2050..ddf110096440f 100644 --- a/testing/web-platform/tests/tools/ci/jobs.py +++ b/testing/web-platform/tests/tools/ci/jobs.py @@ -25,7 +25,7 @@ "manifest_upload": [".*"], "resources_unittest": ["resources/", "tools/"], "tools_unittest": ["tools/"], - "wptrunner_unittest": ["tools/wptrunner/*"], + "wptrunner_unittest": ["tools/"], "build_css": ["css/"], "update_built": ["2dcontext/", "html/", diff --git a/testing/web-platform/tests/tools/ci/tests/test_jobs.py b/testing/web-platform/tests/tools/ci/tests/test_jobs.py index 1548171376efa..363401a01b7ad 100644 --- a/testing/web-platform/tests/tools/ci/tests/test_jobs.py +++ b/testing/web-platform/tests/tools/ci/tests/test_jobs.py @@ -74,7 +74,7 @@ def test_wptrunner_unittest(): assert jobs.get_jobs(["tools/wptrunner/wptrunner/wptrunner.py"], includes=["wptrunner_unittest"]) == set(["wptrunner_unittest"]) assert jobs.get_jobs(["tools/example.py"], - includes=["wptrunner_unittest"]) == set() + includes=["wptrunner_unittest"]) == set(["wptrunner_unittest"]) def test_build_css(): diff --git a/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/test_update.py b/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/test_update.py index 62d780f878801..adc875b5243ec 100644 --- a/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/test_update.py +++ b/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/test_update.py @@ -13,18 +13,14 @@ from manifest import manifest, item as manifest_item -def rel_path_to_url(rel_path, url_base="/"): +def rel_path_to_test_url(rel_path): assert not os.path.isabs(rel_path) - if url_base[0] != "/": - url_base = "/" + url_base - if url_base[-1] != "/": - url_base += "/" - return url_base + rel_path.replace(os.sep, "/") + return rel_path.replace(os.sep, "/") def SourceFileWithTest(path, hash, cls, *args): s = mock.Mock(rel_path=path, hash=hash) - test = cls("/foobar", path, "/", rel_path_to_url(path), *args) + test = cls("/foobar", path, "/", rel_path_to_test_url(path), *args) s.manifest_items = mock.Mock(return_value=(cls.item_type, [test])) return s diff --git a/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/test_wpttest.py b/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/test_wpttest.py index b4a9d8ca9199d..21e41bcb014c4 100644 --- a/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/test_wpttest.py +++ b/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/test_wpttest.py @@ -145,12 +145,12 @@ def test_metadata_lsan_stack_depth(): def test_metadata_fuzzy(): manifest_data = { - "items": {"reftest": {"a/fuzzy.html": [["/a/fuzzy.html", + "items": {"reftest": {"a/fuzzy.html": [["a/fuzzy.html", [["/a/fuzzy-ref.html", "=="]], {"fuzzy": [[["/a/fuzzy.html", '/a/fuzzy-ref.html', '=='], [[2, 3], [10, 15]]]]}]]}}, "paths": {"a/fuzzy.html": ["0"*40, "reftest"]}, - "version": wptmanifest.CURRENT_VERSION, + "version": 6, "url_base": "/"} manifest = wptmanifest.Manifest.from_json(".", manifest_data) test_metadata = manifestexpected.static.compile(BytesIO(test_fuzzy), From 9330e7007e375ad7cdd404f29be47d27640954eb Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Fri, 17 May 2019 11:01:59 +0000 Subject: [PATCH 019/491] Bug 1541729 [wpt PR 16174] - Run base wptrunner tests on python 3., a=testonly Automatic update from web-platform-tests Run base wptrunner tests on python 3. (#16174) -- wpt-commits: 33ee873bd1da77405b6cf7c9d282447d7dd6c9bc wpt-pr: 16174 --- .../tests/tools/wptrunner/tox.ini | 3 +- .../wptrunner/tests/test_manifestexpected.py | 3 ++ .../wptrunner/tests/test_products.py | 5 +- .../wptrunner/tests/test_testloader.py | 2 + .../wptrunner/wptrunner/tests/test_update.py | 53 +++++++++++++++++++ .../wptrunner/wptrunner/tests/test_wpttest.py | 11 +++- .../wptmanifest/tests/test_conditional.py | 4 ++ .../wptmanifest/tests/test_parser.py | 4 ++ .../wptmanifest/tests/test_serializer.py | 2 + .../wptmanifest/tests/test_static.py | 4 ++ .../wptmanifest/tests/test_tokenizer.py | 4 ++ 11 files changed, 92 insertions(+), 3 deletions(-) diff --git a/testing/web-platform/tests/tools/wptrunner/tox.ini b/testing/web-platform/tests/tools/wptrunner/tox.ini index d784c5b299e35..5d343751c5488 100644 --- a/testing/web-platform/tests/tools/wptrunner/tox.ini +++ b/testing/web-platform/tests/tools/wptrunner/tox.ini @@ -2,7 +2,8 @@ xfail_strict=true [tox] -envlist = py27-{base,chrome,edge,firefox,ie,opera,safari,sauce,servo} +envlist = py27-{base,chrome,edge,firefox,ie,opera,safari,sauce,servo},py36-base +skip_missing_interpreters = true [testenv] deps = diff --git a/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/test_manifestexpected.py b/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/test_manifestexpected.py index 0633c5d3720fd..525915d1832ac 100644 --- a/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/test_manifestexpected.py +++ b/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/test_manifestexpected.py @@ -1,3 +1,4 @@ +import sys from io import BytesIO import pytest @@ -5,6 +6,8 @@ from .. import manifestexpected +@pytest.mark.xfail(sys.version[0] == "3", + reason="bytes/text confusion in py3") @pytest.mark.parametrize("fuzzy, expected", [ (b"ref.html:1;200", [("ref.html", ((1, 1), (200, 200)))]), (b"ref.html:0-1;100-200", [("ref.html", ((0, 1), (100, 200)))]), diff --git a/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/test_products.py b/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/test_products.py index 5d2bcf075d0f5..d6a16a192cfa8 100644 --- a/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/test_products.py +++ b/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/test_products.py @@ -2,6 +2,7 @@ import mock import pytest +import sys from .base import all_products, active_products from .. import environment @@ -18,7 +19,9 @@ def test_load_active_product(product): # test passes if it doesn't throw -@all_products("product") +@all_products("product", marks={ + "firefox": pytest.mark.xfail(sys.version[0] == "3", reason="mozinfo 0.10 doesn't support py3"), +}) def test_load_all_products(product): """test every product either loads or throws ImportError""" try: diff --git a/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/test_testloader.py b/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/test_testloader.py index 836003d106038..e857cd43db6d2 100644 --- a/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/test_testloader.py +++ b/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/test_testloader.py @@ -20,6 +20,8 @@ @pytest.mark.xfail(sys.platform == "win32", reason="NamedTemporaryFile cannot be reopened on Win32") +@pytest.mark.xfail(sys.version[0] == "3", + reason="wptmanifest.parser doesn't support py3") def test_filter_unicode(): tests = make_mock_manifest(("test", "a", 10), ("test", "a/b", 10), ("test", "c", 10)) diff --git a/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/test_update.py b/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/test_update.py index adc875b5243ec..a37ea88dd7ccc 100644 --- a/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/test_update.py +++ b/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/test_update.py @@ -1,6 +1,7 @@ import json import mock import os +import pytest import sys from io import BytesIO @@ -97,6 +98,8 @@ def create_test_manifest(tests, url_base="/"): return m +@pytest.mark.xfail(sys.version[0] == "3", + reason="metadata doesn't support py3") def test_update_0(): tests = [("path/to/test.htm", ["/path/to/test.htm"], "testharness", """[test.htm] @@ -117,6 +120,8 @@ def test_update_0(): assert updated[0][1].is_empty +@pytest.mark.xfail(sys.version[0] == "3", + reason="metadata doesn't support py3") def test_update_1(): test_id = "/path/to/test.htm" tests = [("path/to/test.htm", [test_id], "testharness", @@ -139,6 +144,8 @@ def test_update_1(): assert new_manifest.get_test(test_id).children[0].get("expected") == "FAIL" +@pytest.mark.xfail(sys.version[0] == "3", + reason="metadata doesn't support py3") def test_skip_0(): test_id = "/path/to/test.htm" tests = [("path/to/test.htm", [test_id], "testharness", @@ -158,6 +165,8 @@ def test_skip_0(): assert not updated +@pytest.mark.xfail(sys.version[0] == "3", + reason="metadata doesn't support py3") def test_new_subtest(): test_id = "/path/to/test.htm" tests = [("path/to/test.htm", [test_id], "testharness", """[test.htm] @@ -182,6 +191,8 @@ def test_new_subtest(): assert new_manifest.get_test(test_id).children[1].get("expected") == "FAIL" +@pytest.mark.xfail(sys.version[0] == "3", + reason="metadata doesn't support py3") def test_update_multiple_0(): test_id = "/path/to/test.htm" tests = [("path/to/test.htm", [test_id], "testharness", """[test.htm] @@ -216,6 +227,8 @@ def test_update_multiple_0(): "expected", {"debug": False, "os": "linux"}) == "TIMEOUT" +@pytest.mark.xfail(sys.version[0] == "3", + reason="metadata doesn't support py3") def test_update_multiple_1(): test_id = "/path/to/test.htm" tests = [("path/to/test.htm", [test_id], "testharness", """[test.htm] @@ -252,6 +265,8 @@ def test_update_multiple_1(): "expected", {"debug": False, "os": "windows"}) == "FAIL" +@pytest.mark.xfail(sys.version[0] == "3", + reason="metadata doesn't support py3") def test_update_multiple_2(): test_id = "/path/to/test.htm" tests = [("path/to/test.htm", [test_id], "testharness", """[test.htm] @@ -286,6 +301,8 @@ def test_update_multiple_2(): "expected", {"debug": True, "os": "osx"}) == "TIMEOUT" +@pytest.mark.xfail(sys.version[0] == "3", + reason="metadata doesn't support py3") def test_update_multiple_3(): test_id = "/path/to/test.htm" tests = [("path/to/test.htm", [test_id], "testharness", """[test.htm] @@ -322,6 +339,8 @@ def test_update_multiple_3(): "expected", {"debug": True, "os": "osx"}) == "TIMEOUT" +@pytest.mark.xfail(sys.version[0] == "3", + reason="metadata doesn't support py3") def test_update_ignore_existing(): test_id = "/path/to/test.htm" tests = [("path/to/test.htm", [test_id], "testharness", """[test.htm] @@ -358,6 +377,8 @@ def test_update_ignore_existing(): "expected", {"debug": False, "os": "osx"}) == "NOTRUN" +@pytest.mark.xfail(sys.version[0] == "3", + reason="metadata doesn't support py3") def test_update_assertion_count_0(): test_id = "/path/to/test.htm" tests = [("path/to/test.htm", [test_id], "testharness", """[test.htm] @@ -381,6 +402,8 @@ def test_update_assertion_count_0(): assert new_manifest.get_test(test_id).get("min-asserts") == 2 +@pytest.mark.xfail(sys.version[0] == "3", + reason="metadata doesn't support py3") def test_update_assertion_count_1(): test_id = "/path/to/test.htm" tests = [("path/to/test.htm", [test_id], "testharness", """[test.htm] @@ -404,6 +427,8 @@ def test_update_assertion_count_1(): assert new_manifest.get_test(test_id).has_key("min-asserts") is False +@pytest.mark.xfail(sys.version[0] == "3", + reason="metadata doesn't support py3") def test_update_assertion_count_2(): test_id = "/path/to/test.htm" tests = [("path/to/test.htm", [test_id], "testharness", """[test.htm] @@ -423,6 +448,8 @@ def test_update_assertion_count_2(): assert not updated +@pytest.mark.xfail(sys.version[0] == "3", + reason="metadata doesn't support py3") def test_update_assertion_count_3(): test_id = "/path/to/test.htm" tests = [("path/to/test.htm", [test_id], "testharness", """[test.htm] @@ -456,6 +483,8 @@ def test_update_assertion_count_3(): assert new_manifest.get_test(test_id).get("min-asserts") == 2 +@pytest.mark.xfail(sys.version[0] == "3", + reason="metadata doesn't support py3") def test_update_assertion_count_4(): test_id = "/path/to/test.htm" tests = [("path/to/test.htm", [test_id], "testharness", """[test.htm]""")] @@ -486,6 +515,8 @@ def test_update_assertion_count_4(): assert new_manifest.get_test(test_id).has_key("min-asserts") is False +@pytest.mark.xfail(sys.version[0] == "3", + reason="metadata doesn't support py3") def test_update_lsan_0(): test_id = "/path/to/test.htm" dir_id = "path/to/__dir__" @@ -503,6 +534,8 @@ def test_update_lsan_0(): assert new_manifest.get("lsan-allowed") == ["foo"] +@pytest.mark.xfail(sys.version[0] == "3", + reason="metadata doesn't support py3") def test_update_lsan_1(): test_id = "/path/to/test.htm" dir_id = "path/to/__dir__" @@ -523,6 +556,8 @@ def test_update_lsan_1(): assert new_manifest.get("lsan-allowed") == ["baz", "foo"] +@pytest.mark.xfail(sys.version[0] == "3", + reason="metadata doesn't support py3") def test_update_lsan_2(): test_id = "/path/to/test.htm" dir_id = "path/to/__dir__" @@ -545,6 +580,8 @@ def test_update_lsan_2(): assert new_manifest.get("lsan-allowed") == ["baz"] +@pytest.mark.xfail(sys.version[0] == "3", + reason="metadata doesn't support py3") def test_update_lsan_3(): test_id = "/path/to/test.htm" dir_id = "path/to/__dir__" @@ -567,6 +604,8 @@ def test_update_lsan_3(): assert new_manifest.get("lsan-allowed") == ["baz", "foo"] +@pytest.mark.xfail(sys.version[0] == "3", + reason="metadata doesn't support py3") def test_update_wptreport_0(): tests = [("path/to/test.htm", ["/path/to/test.htm"], "testharness", """[test.htm] @@ -588,6 +627,8 @@ def test_update_wptreport_0(): assert updated[0][1].is_empty +@pytest.mark.xfail(sys.version[0] == "3", + reason="metadata doesn't support py3") def test_update_wptreport_1(): tests = [("path/to/test.htm", ["/path/to/test.htm"], "testharness", ""), ("path/to/__dir__", ["path/to/__dir__"], None, "")] @@ -603,6 +644,8 @@ def test_update_wptreport_1(): assert updated[0][1].get("lsan-allowed") == ["baz"] +@pytest.mark.xfail(sys.version[0] == "3", + reason="metadata doesn't support py3") def test_update_leak_total_0(): test_id = "/path/to/test.htm" dir_id = "path/to/__dir__" @@ -622,6 +665,8 @@ def test_update_leak_total_0(): assert new_manifest.get("leak-threshold") == ['default:51200'] +@pytest.mark.xfail(sys.version[0] == "3", + reason="metadata doesn't support py3") def test_update_leak_total_1(): test_id = "/path/to/test.htm" dir_id = "path/to/__dir__" @@ -638,6 +683,8 @@ def test_update_leak_total_1(): assert not updated +@pytest.mark.xfail(sys.version[0] == "3", + reason="metadata doesn't support py3") def test_update_leak_total_2(): test_id = "/path/to/test.htm" dir_id = "path/to/__dir__" @@ -655,6 +702,8 @@ def test_update_leak_total_2(): assert not updated +@pytest.mark.xfail(sys.version[0] == "3", + reason="metadata doesn't support py3") def test_update_leak_total_3(): test_id = "/path/to/test.htm" dir_id = "path/to/__dir__" @@ -675,6 +724,8 @@ def test_update_leak_total_3(): assert new_manifest.get("leak-threshold") == ['default:51200'] +@pytest.mark.xfail(sys.version[0] == "3", + reason="metadata doesn't support py3") def test_update_leak_total_4(): test_id = "/path/to/test.htm" dir_id = "path/to/__dir__" @@ -707,6 +758,8 @@ def create(self, state): class UpdateRunner(StepRunner): steps = [TestStep] +@pytest.mark.xfail(sys.version[0] == "3", + reason="update.state doesn't support py3") def test_update_pickle(): logger = structuredlog.StructuredLogger("expected_test") args = { diff --git a/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/test_wpttest.py b/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/test_wpttest.py index 21e41bcb014c4..2b96ee74e76bf 100644 --- a/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/test_wpttest.py +++ b/testing/web-platform/tests/tools/wptrunner/wptrunner/tests/test_wpttest.py @@ -1,5 +1,6 @@ +import pytest +import sys from io import BytesIO - from mock import Mock from manifest import manifest as wptmanifest @@ -65,6 +66,8 @@ def make_mock_manifest(*items): return rv +@pytest.mark.xfail(sys.version[0] == "3", + reason="bytes/text confusion in py3") def test_metadata_inherit(): tests = make_mock_manifest(("test", "a", 10), ("test", "a/b", 10), ("test", "c", 10)) @@ -89,6 +92,8 @@ def test_metadata_inherit(): assert test_obj.tags == {"a", "dir:a"} +@pytest.mark.xfail(sys.version[0] == "3", + reason="bytes/text confusion in py3") def test_conditional(): tests = make_mock_manifest(("test", "a", 10), ("test", "a/b", 10), ("test", "c", 10)) @@ -105,6 +110,8 @@ def test_conditional(): assert test_obj.expected() == "FAIL" +@pytest.mark.xfail(sys.version[0] == "3", + reason="bytes/text confusion in py3") def test_metadata_lsan_stack_depth(): tests = make_mock_manifest(("test", "a", 10), ("test", "a/b", 10)) @@ -143,6 +150,8 @@ def test_metadata_lsan_stack_depth(): assert test_obj.lsan_max_stack_depth == 42 +@pytest.mark.xfail(sys.version[0] == "3", + reason="bytes/text confusion in py3") def test_metadata_fuzzy(): manifest_data = { "items": {"reftest": {"a/fuzzy.html": [["a/fuzzy.html", diff --git a/testing/web-platform/tests/tools/wptrunner/wptrunner/wptmanifest/tests/test_conditional.py b/testing/web-platform/tests/tools/wptrunner/wptrunner/wptmanifest/tests/test_conditional.py index 9da1a0f180ca2..10b6319143230 100644 --- a/testing/web-platform/tests/tools/wptrunner/wptrunner/wptmanifest/tests/test_conditional.py +++ b/testing/web-platform/tests/tools/wptrunner/wptrunner/wptmanifest/tests/test_conditional.py @@ -1,9 +1,13 @@ +import pytest +import sys import unittest from ..backends import conditional from ..node import BinaryExpressionNode, BinaryOperatorNode, VariableNode, NumberNode +@pytest.mark.xfail(sys.version[0] == "3", + reason="wptmanifest.parser doesn't support py3") class TestConditional(unittest.TestCase): def compile(self, input_text): return conditional.compile(input_text) diff --git a/testing/web-platform/tests/tools/wptrunner/wptrunner/wptmanifest/tests/test_parser.py b/testing/web-platform/tests/tools/wptrunner/wptrunner/wptmanifest/tests/test_parser.py index 3c0781cab4825..6a891669a34a6 100644 --- a/testing/web-platform/tests/tools/wptrunner/wptrunner/wptmanifest/tests/test_parser.py +++ b/testing/web-platform/tests/tools/wptrunner/wptrunner/wptmanifest/tests/test_parser.py @@ -1,3 +1,5 @@ +import pytest +import sys import unittest from six.moves import cStringIO as StringIO @@ -8,6 +10,8 @@ # use test_serializer for the majority of cases +@pytest.mark.xfail(sys.version[0] == "3", + reason="wptmanifest.parser doesn't support py3") class TestExpression(unittest.TestCase): def setUp(self): self.parser = parser.Parser() diff --git a/testing/web-platform/tests/tools/wptrunner/wptrunner/wptmanifest/tests/test_serializer.py b/testing/web-platform/tests/tools/wptrunner/wptrunner/wptmanifest/tests/test_serializer.py index f7c3ca24c709f..05d881c28c44b 100644 --- a/testing/web-platform/tests/tools/wptrunner/wptrunner/wptmanifest/tests/test_serializer.py +++ b/testing/web-platform/tests/tools/wptrunner/wptrunner/wptmanifest/tests/test_serializer.py @@ -8,6 +8,8 @@ from .. import parser, serializer +@pytest.mark.xfail(sys.version[0] == "3", + reason="wptmanifest.parser doesn't support py3") class TokenizerTest(unittest.TestCase): def setUp(self): self.serializer = serializer.ManifestSerializer() diff --git a/testing/web-platform/tests/tools/wptrunner/wptrunner/wptmanifest/tests/test_static.py b/testing/web-platform/tests/tools/wptrunner/wptrunner/wptmanifest/tests/test_static.py index f63869636da79..e0e83c83e80df 100644 --- a/testing/web-platform/tests/tools/wptrunner/wptrunner/wptmanifest/tests/test_static.py +++ b/testing/web-platform/tests/tools/wptrunner/wptrunner/wptmanifest/tests/test_static.py @@ -1,3 +1,5 @@ +import pytest +import sys import unittest from ..backends import static @@ -6,6 +8,8 @@ # use test_serializer for the majority of cases +@pytest.mark.xfail(sys.version[0] == "3", + reason="wptmanifest.parser doesn't support py3") class TestStatic(unittest.TestCase): def compile(self, input_text, input_data): return static.compile(input_text, input_data) diff --git a/testing/web-platform/tests/tools/wptrunner/wptrunner/wptmanifest/tests/test_tokenizer.py b/testing/web-platform/tests/tools/wptrunner/wptrunner/wptmanifest/tests/test_tokenizer.py index e0fb8559a1e79..b7c62c0041496 100644 --- a/testing/web-platform/tests/tools/wptrunner/wptrunner/wptmanifest/tests/test_tokenizer.py +++ b/testing/web-platform/tests/tools/wptrunner/wptrunner/wptmanifest/tests/test_tokenizer.py @@ -1,3 +1,5 @@ +import sys +import pytest import unittest from six.moves import cStringIO as StringIO @@ -6,6 +8,8 @@ from ..parser import token_types +@pytest.mark.xfail(sys.version[0] == "3", + reason="Tokenizer doesn't support py3") class TokenizerTest(unittest.TestCase): def setUp(self): self.tokenizer = parser.Tokenizer() From 582c7970ec7933c42c7227473b23a71fb32f59a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Fri, 17 May 2019 11:02:03 +0000 Subject: [PATCH 020/491] Bug 1541730 [wpt PR 16180] - Add a test for missing closing parenthesis in functional pseudo-selector., a=testonly Automatic update from web-platform-tests Add a test for missing closing parenthesis in functional pseudo-selector. (#16180) This was reviewed in https://bugs.webkit.org/show_bug.cgi?id=142167. -- wpt-commits: a8e6f75e3f7477bcaeff7516a3c540cc4680e7e2 wpt-pr: 16180 --- testing/web-platform/tests/dom/nodes/selectors.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/testing/web-platform/tests/dom/nodes/selectors.js b/testing/web-platform/tests/dom/nodes/selectors.js index c4e87330b44d0..553e62f2587dc 100644 --- a/testing/web-platform/tests/dom/nodes/selectors.js +++ b/testing/web-platform/tests/dom/nodes/selectors.js @@ -373,6 +373,10 @@ var validSelectors = [ {name: "Syntax, group of selectors separator, whitespace after", selector: "#group em,\t\r\n#group strong", expect: ["group-em1", "group-strong1"], level: 1, testType: TEST_QSA | TEST_MATCH}, {name: "Syntax, group of selectors separator, whitespace before", selector: "#group em\t\r\n,#group strong", expect: ["group-em1", "group-strong1"], level: 1, testType: TEST_QSA | TEST_MATCH}, {name: "Syntax, group of selectors separator, no whitespace", selector: "#group em,#group strong", expect: ["group-em1", "group-strong1"], level: 1, testType: TEST_QSA | TEST_MATCH}, + + // ::slotted (shouldn't match anything, but is a valid selector) + {name: "Slotted selector", selector: "::slotted(foo)", expect: [], level: 3, testType: TEST_QSA}, + {name: "Slotted selector (no matching closing paren)", selector: "::slotted(foo", expect: [], level: 3, testType: TEST_QSA}, ]; From e755e5f3249c9d49c20333275702c695f34ed88a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Pe=C3=B1a=20Moreno?= Date: Fri, 17 May 2019 11:02:08 +0000 Subject: [PATCH 021/491] Bug 1541732 [wpt PR 16144] - [ElementTiming] Add intrinsic size, a=testonly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Automatic update from web-platform-tests [ElementTiming] Add intrinsic size This CL adds naturalWidth and naturalHeight members to PerformanceElementTiming to allow developers to compute a size that aligns more with the importance of the image with the help of these attributes and intersectionRect. This CL also adds tests for CSS scaling and rotation. Bug: 879270 Change-Id: I9dbbe802dd430c2dd0fd9a476608c0c744a98095 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1545169 Commit-Queue: Nicolás Peña Moreno Reviewed-by: Chris Harrelson Cr-Commit-Position: refs/heads/master@{#646368} -- wpt-commits: cf8e88189017c6080e0fda6701aa7f3923a77252 wpt-pr: 16144 --- .../element-timing/buffer-before-onload.html | 1 + .../cross-origin-element.sub.html | 1 + .../image-TAO-wildcard.sub.html | 1 + .../tests/element-timing/image-carousel.html | 2 + .../element-timing/image-clipped-svg.html | 1 + .../image-not-fully-visible.html | 1 + .../element-timing/image-rect-iframe.html | 2 + .../element-timing/image-with-css-scale.html | 42 ++++++++++++++++ .../element-timing/image-with-rotation.html | 50 +++++++++++++++++++ .../images-repeated-resource.html | 1 + .../element-timing/observe-elementtiming.html | 3 +- .../element-timing/observe-large-image.html | 1 + .../observe-multiple-images.html | 3 ++ .../element-timing/observe-svg-image.html | 1 + .../element-timing/observe-video-poster.html | 1 + .../progressively-loaded-image.html | 1 + .../element-timing/rectangular-image.html | 43 ++++++++++++++++ .../resources/element-timing-helpers.js | 8 ++- .../iframe-with-square-sends-entry.html | 2 + 19 files changed, 163 insertions(+), 2 deletions(-) create mode 100644 testing/web-platform/tests/element-timing/image-with-css-scale.html create mode 100644 testing/web-platform/tests/element-timing/image-with-rotation.html create mode 100644 testing/web-platform/tests/element-timing/rectangular-image.html diff --git a/testing/web-platform/tests/element-timing/buffer-before-onload.html b/testing/web-platform/tests/element-timing/buffer-before-onload.html index 1fd02776927d1..d3772c0d224d1 100644 --- a/testing/web-platform/tests/element-timing/buffer-before-onload.html +++ b/testing/web-platform/tests/element-timing/buffer-before-onload.html @@ -28,6 +28,7 @@ const pathname = window.location.href.substring(0, index) + '/resources/square20.jpg'; checkElement(entry, pathname, 'my_image', beforeRender); + checkNaturalSize(entry, 20, 20); }); }, "Element Timing: image loads before onload."); diff --git a/testing/web-platform/tests/element-timing/cross-origin-element.sub.html b/testing/web-platform/tests/element-timing/cross-origin-element.sub.html index a122819fc499b..c0912f37c2f48 100644 --- a/testing/web-platform/tests/element-timing/cross-origin-element.sub.html +++ b/testing/web-platform/tests/element-timing/cross-origin-element.sub.html @@ -22,6 +22,7 @@ assert_equals(entry.startTime, 0, 'The startTime of a cross-origin image should be 0.'); checkRect(entry, [0, 100, 0, 100]); + checkNaturalSize(entry, 100, 100); }) ); observer.observe({entryTypes: ['element']}); diff --git a/testing/web-platform/tests/element-timing/image-TAO-wildcard.sub.html b/testing/web-platform/tests/element-timing/image-TAO-wildcard.sub.html index 3ba12a7d01f1c..4c407175b5d32 100644 --- a/testing/web-platform/tests/element-timing/image-TAO-wildcard.sub.html +++ b/testing/web-platform/tests/element-timing/image-TAO-wildcard.sub.html @@ -22,6 +22,7 @@ checkElement(entry, img_src, 'my_image', beforeRender); // Assume viewport has size at least 20, so the element is fully visible. checkRect(entry, [0, 20, 0, 20]); + checkNaturalSize(entry, 20, 20); }) ); observer.observe({entryTypes: ['element']}); diff --git a/testing/web-platform/tests/element-timing/image-carousel.html b/testing/web-platform/tests/element-timing/image-carousel.html index 0bd99ab2507a1..f914f741ddc8a 100644 --- a/testing/web-platform/tests/element-timing/image-carousel.html +++ b/testing/web-platform/tests/element-timing/image-carousel.html @@ -39,11 +39,13 @@ if (entry_count % 2 == 0) { checkElement(entry, pathname0, 'image0', beforeRenderTimes[entry_count]); checkRect(entry, [0, 200, 0, 200]); + checkNaturalSize(entry, 200, 200); entry_count_per_element[0]++; } else { checkElement(entry, pathname1, 'image1', beforeRenderTimes[entry_count]); checkRect(entry, [0, 100, 0, 100]); + checkNaturalSize(entry, 100, 100); entry_count_per_element[1]++; } entry_count++; diff --git a/testing/web-platform/tests/element-timing/image-clipped-svg.html b/testing/web-platform/tests/element-timing/image-clipped-svg.html index 13c4a81a1e02f..54c074c9801d8 100644 --- a/testing/web-platform/tests/element-timing/image-clipped-svg.html +++ b/testing/web-platform/tests/element-timing/image-clipped-svg.html @@ -17,6 +17,7 @@ checkElement(entry, pathname, 'my_svg', beforeRender); // Image size is 200x200 but SVG size is 100x100 so it is clipped. checkRect(entry, [0, 100, 0, 100]); + checkNaturalSize(entry, 200, 200); }) ); observer.observe({entryTypes: ['element']}); diff --git a/testing/web-platform/tests/element-timing/image-not-fully-visible.html b/testing/web-platform/tests/element-timing/image-not-fully-visible.html index d3e2c105bffdf..b61a9483b3618 100644 --- a/testing/web-platform/tests/element-timing/image-not-fully-visible.html +++ b/testing/web-platform/tests/element-timing/image-not-fully-visible.html @@ -25,6 +25,7 @@ // of the document, excluding the margin, and then overflow. checkRect(entry, [100, document.documentElement.clientWidth, 200, document.documentElement.clientHeight]); + checkNaturalSize(entry, 20, 20); }) ); observer.observe({entryTypes: ['element']}); diff --git a/testing/web-platform/tests/element-timing/image-rect-iframe.html b/testing/web-platform/tests/element-timing/image-rect-iframe.html index da46d785a0b7d..f94b25930a8e5 100644 --- a/testing/web-platform/tests/element-timing/image-rect-iframe.html +++ b/testing/web-platform/tests/element-timing/image-rect-iframe.html @@ -20,6 +20,8 @@ assert_equals(rect.right, 100); assert_equals(rect.top, 0); assert_equals(rect.bottom, 100); + assert_equals(e.data.naturalWidth, 100); + assert_equals(e.data.naturalHeight, 100); t.done(); }); }, 'Element Timing entry in iframe has coordinates relative to the iframe.'); diff --git a/testing/web-platform/tests/element-timing/image-with-css-scale.html b/testing/web-platform/tests/element-timing/image-with-css-scale.html new file mode 100644 index 0000000000000..4cd0830aea5d8 --- /dev/null +++ b/testing/web-platform/tests/element-timing/image-with-css-scale.html @@ -0,0 +1,42 @@ + + +Element Timing: image with scaling. + + + + + + + + +
+ +
+ diff --git a/testing/web-platform/tests/element-timing/image-with-rotation.html b/testing/web-platform/tests/element-timing/image-with-rotation.html new file mode 100644 index 0000000000000..4e00c685c8577 --- /dev/null +++ b/testing/web-platform/tests/element-timing/image-with-rotation.html @@ -0,0 +1,50 @@ + + +Element Timing: image with rotation. + + + + + + + + +
+ +
+ diff --git a/testing/web-platform/tests/element-timing/images-repeated-resource.html b/testing/web-platform/tests/element-timing/images-repeated-resource.html index 18c72cdad1b31..7ad00e0c2dc64 100644 --- a/testing/web-platform/tests/element-timing/images-repeated-resource.html +++ b/testing/web-platform/tests/element-timing/images-repeated-resource.html @@ -23,6 +23,7 @@ t.step_func(function(entryList) { entryList.getEntries().forEach(entry => { checkElement(entry, pathname, entry.identifier, beforeRender); + checkNaturalSize(entry, 100, 100); if (entry.identifier === 'my_image') { ++numEntries; responseEnd1 = entry.responseEnd; diff --git a/testing/web-platform/tests/element-timing/observe-elementtiming.html b/testing/web-platform/tests/element-timing/observe-elementtiming.html index 9170b36d7c7fb..c9755a8bf0ae1 100644 --- a/testing/web-platform/tests/element-timing/observe-elementtiming.html +++ b/testing/web-platform/tests/element-timing/observe-elementtiming.html @@ -23,13 +23,14 @@ checkElement(entry, pathname, 'my_image', beforeRender); // Assume viewport has size at least 100, so the element is fully visible. checkRect(entry, [0, 100, 0, 100]); + checkNaturalSize(entry, 100, 100); }) ); observer.observe({entryTypes: ['element']}); // We add the image during onload to be sure that the observer is registered // in time for it to observe the element timing. window.onload = () => { - // Add image of width and height equal to 100. + // Add image of width equal to 100 and height equal to 100. const img = document.createElement('img'); img.src = 'resources/square100.png'; img.setAttribute('elementtiming', 'my_image'); diff --git a/testing/web-platform/tests/element-timing/observe-large-image.html b/testing/web-platform/tests/element-timing/observe-large-image.html index fb2884381ab30..3a3149bdafcbf 100644 --- a/testing/web-platform/tests/element-timing/observe-large-image.html +++ b/testing/web-platform/tests/element-timing/observe-large-image.html @@ -24,6 +24,7 @@ // Assume viewport hasn't changed, so the element occupies all of it. checkRect(entry, [0, document.documentElement.clientWidth, 0, document.documentElement.clientHeight]); + checkNaturalSize(entry, 20, 20); }) ); observer.observe({entryTypes: ['element']}); diff --git a/testing/web-platform/tests/element-timing/observe-multiple-images.html b/testing/web-platform/tests/element-timing/observe-multiple-images.html index aa91aa839896c..79f991fb31edd 100644 --- a/testing/web-platform/tests/element-timing/observe-multiple-images.html +++ b/testing/web-platform/tests/element-timing/observe-multiple-images.html @@ -48,6 +48,7 @@ assert_equals(entry.intersectionRect.top, 0, 'top of rect for image1'); assert_equals(entry.intersectionRect.bottom, 100, 'bottom of rect for image1'); + checkNaturalSize(entry, 100, 100); } else if (entry.identifier === 'image2') { if (image2Observed) { @@ -60,6 +61,7 @@ checkElement(entry, pathname2, 'image2', beforeRender); // This image should be below image 1, and should respect the margin. checkRect(entry, [50, 250, 250, 450], "of image2"); + checkNaturalSize(entry, 20, 20); } else if (entry.identifier === 'image3') { if (image3Observed) { @@ -72,6 +74,7 @@ checkElement(entry, pathname3, 'image3', beforeRender); // This image is just to the right of image2. checkRect(entry, [250, 450, 250, 450], "of image3"); + checkNaturalSize(entry, 200, 200); } else { assert_unreached("Received an unexpected identifier."); diff --git a/testing/web-platform/tests/element-timing/observe-svg-image.html b/testing/web-platform/tests/element-timing/observe-svg-image.html index fdfe25ec9ff8b..ea4537458cb64 100644 --- a/testing/web-platform/tests/element-timing/observe-svg-image.html +++ b/testing/web-platform/tests/element-timing/observe-svg-image.html @@ -17,6 +17,7 @@ checkElement(entry, pathname, 'my_svg', beforeRender); // Assume viewport has size at least 200, so the element is fully visible. checkRect(entry, [0, 200, 0, 200]); + checkNaturalSize(entry, 200, 200); }) ); observer.observe({entryTypes: ['element']}); diff --git a/testing/web-platform/tests/element-timing/observe-video-poster.html b/testing/web-platform/tests/element-timing/observe-video-poster.html index 40961382ffba6..41e6edffd5c5c 100644 --- a/testing/web-platform/tests/element-timing/observe-video-poster.html +++ b/testing/web-platform/tests/element-timing/observe-video-poster.html @@ -17,6 +17,7 @@ checkElement(entry, pathname, 'my_poster', beforeRender); // Assume viewport has size at least 200, so the element is fully visible. checkRect(entry, [0, 200, 0, 200]); + checkNaturalSize(entry, 200, 200); }) ); observer.observe({entryTypes: ['element']}); diff --git a/testing/web-platform/tests/element-timing/progressively-loaded-image.html b/testing/web-platform/tests/element-timing/progressively-loaded-image.html index cf54e1e5c7a28..63ba9a3bf024c 100644 --- a/testing/web-platform/tests/element-timing/progressively-loaded-image.html +++ b/testing/web-platform/tests/element-timing/progressively-loaded-image.html @@ -25,6 +25,7 @@ // Since the image is only fully loaded after the sleep, the render timestamp // must be greater than |beforeRender| + |sleep|. checkElement(entry, pathname, 'my_image', beforeRender + sleep); + checkNaturalSize(entry, 20, 20); }) ); observer.observe({entryTypes: ['element']}); diff --git a/testing/web-platform/tests/element-timing/rectangular-image.html b/testing/web-platform/tests/element-timing/rectangular-image.html new file mode 100644 index 0000000000000..9903d47cdc29f --- /dev/null +++ b/testing/web-platform/tests/element-timing/rectangular-image.html @@ -0,0 +1,43 @@ + + +Element Timing: observe a rectangular image + + + + + + + diff --git a/testing/web-platform/tests/element-timing/resources/element-timing-helpers.js b/testing/web-platform/tests/element-timing/resources/element-timing-helpers.js index e952930ef5e49..2462c2d20fc00 100644 --- a/testing/web-platform/tests/element-timing/resources/element-timing-helpers.js +++ b/testing/web-platform/tests/element-timing/resources/element-timing-helpers.js @@ -12,7 +12,7 @@ function checkElement(entry, expectedName, expectedIdentifier, beforeRender) { assert_equals(rt_entries[0].responseEnd, entry.responseEnd); } -// Checks that the rect matches the desired values [left right top bottom] +// Checks that the rect matches the desired values [left right top bottom]. function checkRect(entry, expected, description="") { assert_equals(entry.intersectionRect.left, expected[0], 'left of rect ' + description); @@ -23,3 +23,9 @@ function checkRect(entry, expected, description="") { assert_equals(entry.intersectionRect.bottom, expected[3], 'bottom of rect ' + description); } + +// Checks that the intrinsic size matches the desired values. +function checkNaturalSize(entry, width, height) { + assert_equals(entry.naturalWidth, width); + assert_equals(entry.naturalHeight, height); +} diff --git a/testing/web-platform/tests/element-timing/resources/iframe-with-square-sends-entry.html b/testing/web-platform/tests/element-timing/resources/iframe-with-square-sends-entry.html index 3c43a41c7d910..1165a788dbcdf 100644 --- a/testing/web-platform/tests/element-timing/resources/iframe-with-square-sends-entry.html +++ b/testing/web-platform/tests/element-timing/resources/iframe-with-square-sends-entry.html @@ -12,6 +12,8 @@ 'length' : entryList.getEntries().length, 'entryType' : entryList.getEntries()[0].entryType, 'rect' : entryList.getEntries()[0].intersectionRect, + 'naturalWidth' : entryList.getEntries()[0].naturalWidth, + 'naturalHeight' : entryList.getEntries()[0].naturalHeight, }, '*'); }); observer.observe({entryTypes: ['element']}); From 3771fae74d1ec39e16ad18d92cce626a88fa495b Mon Sep 17 00:00:00 2001 From: Dave Tapuska Date: Fri, 17 May 2019 11:02:12 +0000 Subject: [PATCH 022/491] Bug 1541735 [wpt PR 16189] - Fix fullscreen-options wpt test, a=testonly Automatic update from web-platform-tests Fix fullscreen-options wpt test The test failed because a promise was uncaught. Ensure that either a rejected or allowed promise will allow the test to pass provided Change-Id: I604ab23fe32a1dee1ed60182dd25e4ffbd60a688 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1548032 Reviewed-by: Robert Ma Commit-Queue: Dave Tapuska Cr-Commit-Position: refs/heads/master@{#646438} -- wpt-commits: 691cf75b7818a699b58c0d5ce94e5f7b21841193 wpt-pr: 16189 --- .../api/element-request-fullscreen-options.html | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/testing/web-platform/tests/fullscreen/api/element-request-fullscreen-options.html b/testing/web-platform/tests/fullscreen/api/element-request-fullscreen-options.html index c6ce1fdc016ec..6a0bfa1f5fac3 100644 --- a/testing/web-platform/tests/fullscreen/api/element-request-fullscreen-options.html +++ b/testing/web-platform/tests/fullscreen/api/element-request-fullscreen-options.html @@ -8,11 +8,14 @@ // no normative requirements on what navigationUI should do, just test for // basic support. (One could also check that the three allowed enum valid are // supported and no others, but that would overlap with UA-specific tests.) -test(() => { +promise_test(() => { let invoked = false; - document.body.requestFullscreen({ + return document.body.requestFullscreen({ get navigationUI() { invoked = true; return "irrelevant-value"; } + }).then(() => { + assert_unreached("promise should be rejected due to invalid navigationUI value"); + }, () => { + assert_true(invoked, "navigationUI getter invoked"); }); - assert_true(invoked, "navigationUI getter invoked"); }); From 45a0c875eb3a69cfb699ba6c22e65accd8ed61ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Pe=C3=B1a=20Moreno?= Date: Fri, 17 May 2019 11:02:16 +0000 Subject: [PATCH 023/491] Bug 1541739 [wpt PR 16191] - [ElementTiming] Add element ID, a=testonly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Automatic update from web-platform-tests [ElementTiming] Add element ID The element ID helps developers and analytics providers determine which element the PerformanceElementTiming entry is referring to. While we have other ways to find out the element for Image Element Timing (for\ example, we can use the image requested URL), for text the available resources will be much limited and thus ID is needed. Bug: 879270, 942033 Change-Id: I0f20609cf4edc7eb6431448c439b9cf911f89fb9 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1544948 Commit-Queue: Nicolás Peña Moreno Reviewed-by: Chris Harrelson Cr-Commit-Position: refs/heads/master@{#646432} -- wpt-commits: 15d2855d6d01c8a0350f2bf08c25f5839e0936c6 wpt-pr: 16191 --- .../tests/element-timing/buffer-before-onload.html | 3 ++- .../tests/element-timing/cross-origin-element.sub.html | 3 ++- .../tests/element-timing/image-TAO-wildcard.sub.html | 3 ++- .../web-platform/tests/element-timing/image-carousel.html | 8 ++++---- .../tests/element-timing/image-clipped-svg.html | 4 ++-- .../tests/element-timing/image-not-fully-visible.html | 2 +- .../tests/element-timing/image-rect-iframe.html | 1 + .../tests/element-timing/image-with-css-scale.html | 6 +++--- .../tests/element-timing/image-with-rotation.html | 6 +++--- .../tests/element-timing/images-repeated-resource.html | 4 +++- .../tests/element-timing/observe-elementtiming.html | 3 ++- .../tests/element-timing/observe-large-image.html | 3 ++- .../tests/element-timing/observe-multiple-images.html | 8 +++++--- .../tests/element-timing/observe-svg-image.html | 4 ++-- .../tests/element-timing/observe-video-poster.html | 4 ++-- .../tests/element-timing/progressively-loaded-image.html | 2 +- .../tests/element-timing/rectangular-image.html | 3 ++- .../element-timing/resources/element-timing-helpers.js | 3 ++- .../resources/iframe-with-square-sends-entry.html | 3 ++- 19 files changed, 43 insertions(+), 30 deletions(-) diff --git a/testing/web-platform/tests/element-timing/buffer-before-onload.html b/testing/web-platform/tests/element-timing/buffer-before-onload.html index d3772c0d224d1..805777f29c297 100644 --- a/testing/web-platform/tests/element-timing/buffer-before-onload.html +++ b/testing/web-platform/tests/element-timing/buffer-before-onload.html @@ -18,6 +18,7 @@ const img = document.createElement('img'); img.src = 'resources/square20.jpg'; img.setAttribute('elementtiming', 'my_image'); + img.setAttribute('id', 'my_id'); document.body.appendChild(img); window.onload = t.step_func_done( () => { const entries = performance.getEntriesByType('element'); @@ -27,7 +28,7 @@ const index = window.location.href.lastIndexOf('/'); const pathname = window.location.href.substring(0, index) + '/resources/square20.jpg'; - checkElement(entry, pathname, 'my_image', beforeRender); + checkElement(entry, pathname, 'my_image', 'my_id', beforeRender); checkNaturalSize(entry, 20, 20); }); }, "Element Timing: image loads before onload."); diff --git a/testing/web-platform/tests/element-timing/cross-origin-element.sub.html b/testing/web-platform/tests/element-timing/cross-origin-element.sub.html index c0912f37c2f48..b1a5b7ccd7acd 100644 --- a/testing/web-platform/tests/element-timing/cross-origin-element.sub.html +++ b/testing/web-platform/tests/element-timing/cross-origin-element.sub.html @@ -18,7 +18,7 @@ t.step_func_done((entryList) => { assert_equals(entryList.getEntries().length, 1); const entry = entryList.getEntries()[0]; - checkElement(entry, pathname, 'my_image', 0); + checkElement(entry, pathname, 'my_image', 'the_id', 0); assert_equals(entry.startTime, 0, 'The startTime of a cross-origin image should be 0.'); checkRect(entry, [0, 100, 0, 100]); @@ -34,6 +34,7 @@ const img = document.createElement('img'); img.src = pathname; img.setAttribute('elementtiming', 'my_image'); + img.setAttribute('id', 'the_id'); document.body.appendChild(img); }); }, 'Cross-origin image element is NOT observable.'); diff --git a/testing/web-platform/tests/element-timing/image-TAO-wildcard.sub.html b/testing/web-platform/tests/element-timing/image-TAO-wildcard.sub.html index 4c407175b5d32..0e24af068a6d9 100644 --- a/testing/web-platform/tests/element-timing/image-TAO-wildcard.sub.html +++ b/testing/web-platform/tests/element-timing/image-TAO-wildcard.sub.html @@ -19,7 +19,7 @@ t.step_func_done((entryList) => { assert_equals(entryList.getEntries().length, 1); const entry = entryList.getEntries()[0]; - checkElement(entry, img_src, 'my_image', beforeRender); + checkElement(entry, img_src, 'my_image', 'my_id', beforeRender); // Assume viewport has size at least 20, so the element is fully visible. checkRect(entry, [0, 20, 0, 20]); checkNaturalSize(entry, 20, 20); @@ -33,6 +33,7 @@ const img = document.createElement('img'); img.src = img_src; img.setAttribute('elementtiming', 'my_image'); + img.setAttribute('id', 'my_id'); img.onload = t.step_func(() => { // After a short delay, assume that the entry was not dispatched. t.step_timeout(() => { diff --git a/testing/web-platform/tests/element-timing/image-carousel.html b/testing/web-platform/tests/element-timing/image-carousel.html index f914f741ddc8a..9f0ef79e354df 100644 --- a/testing/web-platform/tests/element-timing/image-carousel.html +++ b/testing/web-platform/tests/element-timing/image-carousel.html @@ -17,10 +17,10 @@
@@ -37,13 +37,13 @@ const observer = new PerformanceObserver(list => { list.getEntries().forEach(entry => { if (entry_count % 2 == 0) { - checkElement(entry, pathname0, 'image0', beforeRenderTimes[entry_count]); + checkElement(entry, pathname0, 'image0', 'image0', beforeRenderTimes[entry_count]); checkRect(entry, [0, 200, 0, 200]); checkNaturalSize(entry, 200, 200); entry_count_per_element[0]++; } else { - checkElement(entry, pathname1, 'image1', beforeRenderTimes[entry_count]); + checkElement(entry, pathname1, 'image1', 'image1', beforeRenderTimes[entry_count]); checkRect(entry, [0, 100, 0, 100]); checkNaturalSize(entry, 100, 100); entry_count_per_element[1]++; diff --git a/testing/web-platform/tests/element-timing/image-clipped-svg.html b/testing/web-platform/tests/element-timing/image-clipped-svg.html index 54c074c9801d8..36cf1b15e0df0 100644 --- a/testing/web-platform/tests/element-timing/image-clipped-svg.html +++ b/testing/web-platform/tests/element-timing/image-clipped-svg.html @@ -14,7 +14,7 @@ const index = window.location.href.lastIndexOf('/'); const pathname = window.location.href.substring(0, index) + '/resources/circle.svg'; - checkElement(entry, pathname, 'my_svg', beforeRender); + checkElement(entry, pathname, 'my_svg', 'SVG', beforeRender); // Image size is 200x200 but SVG size is 100x100 so it is clipped. checkRect(entry, [0, 100, 0, 100]); checkNaturalSize(entry, 200, 200); @@ -30,5 +30,5 @@ } - + diff --git a/testing/web-platform/tests/element-timing/image-not-fully-visible.html b/testing/web-platform/tests/element-timing/image-not-fully-visible.html index b61a9483b3618..279fa03cc2b42 100644 --- a/testing/web-platform/tests/element-timing/image-not-fully-visible.html +++ b/testing/web-platform/tests/element-timing/image-not-fully-visible.html @@ -20,7 +20,7 @@ const index = window.location.href.lastIndexOf('/'); const pathname = window.location.href.substring(0, index) + '/resources/square20.png'; - checkElement(entry, pathname, 'not_fully_visible', beforeRender); + checkElement(entry, pathname, 'not_fully_visible', '', beforeRender); // Image will not be fully visible. It should start from the top left part // of the document, excluding the margin, and then overflow. checkRect(entry, diff --git a/testing/web-platform/tests/element-timing/image-rect-iframe.html b/testing/web-platform/tests/element-timing/image-rect-iframe.html index f94b25930a8e5..94c872e8e02fe 100644 --- a/testing/web-platform/tests/element-timing/image-rect-iframe.html +++ b/testing/web-platform/tests/element-timing/image-rect-iframe.html @@ -22,6 +22,7 @@ assert_equals(rect.bottom, 100); assert_equals(e.data.naturalWidth, 100); assert_equals(e.data.naturalHeight, 100); + assert_equals(e.data.id, 'iframe_img_id'); t.done(); }); }, 'Element Timing entry in iframe has coordinates relative to the iframe.'); diff --git a/testing/web-platform/tests/element-timing/image-with-css-scale.html b/testing/web-platform/tests/element-timing/image-with-css-scale.html index 4cd0830aea5d8..6d77429e485ed 100644 --- a/testing/web-platform/tests/element-timing/image-with-css-scale.html +++ b/testing/web-platform/tests/element-timing/image-with-css-scale.html @@ -28,7 +28,7 @@ const index = window.location.href.lastIndexOf('/'); const pathname = window.location.href.substring(0, index - 14) + 'images/black-rectangle.png'; - checkElement(entry, pathname, 'rectangle', beforeRender); + checkElement(entry, pathname, 'rectangle', 'rect_id', beforeRender); checkRect(entry, [0, 200, 25, 125]); checkNaturalSize(entry, 100, 50); }) @@ -36,7 +36,7 @@ observer.observe({entryTypes: ['element']}); }, 'Image intersectionRect is affected by scaling, but not its intrinsic size.'); -
- +
+
diff --git a/testing/web-platform/tests/element-timing/image-with-rotation.html b/testing/web-platform/tests/element-timing/image-with-rotation.html index 4e00c685c8577..70b635e012a68 100644 --- a/testing/web-platform/tests/element-timing/image-with-rotation.html +++ b/testing/web-platform/tests/element-timing/image-with-rotation.html @@ -28,7 +28,7 @@ const index = window.location.href.lastIndexOf('/'); const pathname = window.location.href.substring(0, index - 14) + 'images/black-rectangle.png'; - checkElement(entry, pathname, 'rectangle', beforeRender); + checkElement(entry, pathname, 'rectangle', 'rect_id', beforeRender); checkNaturalSize(entry, 100, 50); const rect = entry.intersectionRect; // The div rotates with respect to the origin, so part of it will be invisible. @@ -44,7 +44,7 @@ observer.observe({entryTypes: ['element']}); }, 'Image intersectionRect is affected by rotation, but not its intrinsic size.'); -
- +
+
diff --git a/testing/web-platform/tests/element-timing/images-repeated-resource.html b/testing/web-platform/tests/element-timing/images-repeated-resource.html index 7ad00e0c2dc64..dbcad248e3aea 100644 --- a/testing/web-platform/tests/element-timing/images-repeated-resource.html +++ b/testing/web-platform/tests/element-timing/images-repeated-resource.html @@ -22,7 +22,7 @@ const observer = new PerformanceObserver( t.step_func(function(entryList) { entryList.getEntries().forEach(entry => { - checkElement(entry, pathname, entry.identifier, beforeRender); + checkElement(entry, pathname, entry.identifier, 'image_id', beforeRender); checkNaturalSize(entry, 100, 100); if (entry.identifier === 'my_image') { ++numEntries; @@ -47,11 +47,13 @@ const img = document.createElement('img'); img.src = 'resources/square100.png'; img.setAttribute('elementtiming', 'my_image'); + img.setAttribute('id', 'image_id'); document.body.appendChild(img); const img2 = document.createElement('img'); img2.src = 'resources/square100.png'; img2.setAttribute('elementtiming', 'my_image2'); + img2.setAttribute('id', 'image_id'); document.body.appendChild(img2); beforeRender = performance.now(); diff --git a/testing/web-platform/tests/element-timing/observe-elementtiming.html b/testing/web-platform/tests/element-timing/observe-elementtiming.html index c9755a8bf0ae1..39fea05431107 100644 --- a/testing/web-platform/tests/element-timing/observe-elementtiming.html +++ b/testing/web-platform/tests/element-timing/observe-elementtiming.html @@ -20,7 +20,7 @@ const index = window.location.href.lastIndexOf('/'); const pathname = window.location.href.substring(0, index) + '/resources/square100.png'; - checkElement(entry, pathname, 'my_image', beforeRender); + checkElement(entry, pathname, 'my_image', 'my_id', beforeRender); // Assume viewport has size at least 100, so the element is fully visible. checkRect(entry, [0, 100, 0, 100]); checkNaturalSize(entry, 100, 100); @@ -34,6 +34,7 @@ const img = document.createElement('img'); img.src = 'resources/square100.png'; img.setAttribute('elementtiming', 'my_image'); + img.setAttribute('id', 'my_id'); document.body.appendChild(img); beforeRender = performance.now(); }; diff --git a/testing/web-platform/tests/element-timing/observe-large-image.html b/testing/web-platform/tests/element-timing/observe-large-image.html index 3a3149bdafcbf..a08274caa5254 100644 --- a/testing/web-platform/tests/element-timing/observe-large-image.html +++ b/testing/web-platform/tests/element-timing/observe-large-image.html @@ -20,7 +20,7 @@ const index = window.location.href.lastIndexOf('/'); const pathname = window.location.href.substring(0, index) + '/resources/square20.jpg'; - checkElement(entry, pathname, '', beforeRender); + checkElement(entry, pathname, '', 'large_one', beforeRender); // Assume viewport hasn't changed, so the element occupies all of it. checkRect(entry, [0, document.documentElement.clientWidth, 0, document.documentElement.clientHeight]); @@ -36,6 +36,7 @@ img.src = 'resources/square20.jpg'; img.width = document.documentElement.clientWidth; img.height = document.documentElement.clientHeight; + img.setAttribute('id', 'large_one'); document.body.appendChild(img); beforeRender = performance.now(); }; diff --git a/testing/web-platform/tests/element-timing/observe-multiple-images.html b/testing/web-platform/tests/element-timing/observe-multiple-images.html index 79f991fb31edd..05c54ac050fe8 100644 --- a/testing/web-platform/tests/element-timing/observe-multiple-images.html +++ b/testing/web-platform/tests/element-timing/observe-multiple-images.html @@ -34,7 +34,8 @@ image1Observed = 1; const pathname1 = window.location.href.substring(0, index) + '/resources/square100.png'; - checkElement(entry, pathname1, 'image1', beforeRender); + // The images do not contain ID, so expect an empty ID. + checkElement(entry, pathname1, 'image1', 'img1', beforeRender); // This image is horizontally centered. // Using abs and comparing to 1 because the viewport sizes could be odd. // If a size is odd, then image cannot be in the pure center, but left @@ -58,7 +59,7 @@ image2Observed = 1; const pathname2 = window.location.href.substring(0, index) + '/resources/square20.png'; - checkElement(entry, pathname2, 'image2', beforeRender); + checkElement(entry, pathname2, 'image2', 'img2', beforeRender); // This image should be below image 1, and should respect the margin. checkRect(entry, [50, 250, 250, 450], "of image2"); checkNaturalSize(entry, 20, 20); @@ -71,7 +72,7 @@ image3Observed = 1; const pathname3 = window.location.href.substring(0, index) + '/resources/circle.svg'; - checkElement(entry, pathname3, 'image3', beforeRender); + checkElement(entry, pathname3, 'image3', 'img3', beforeRender); // This image is just to the right of image2. checkRect(entry, [250, 450, 250, 450], "of image3"); checkNaturalSize(entry, 200, 200); @@ -90,6 +91,7 @@ function addImage(number, source, width=0) { const img = document.createElement('img'); img.src = source; + // Set a different id and elementtiming value for each image. img.id = 'img' + number; img.setAttribute('elementtiming', 'image' + number); if (width !== 0) diff --git a/testing/web-platform/tests/element-timing/observe-svg-image.html b/testing/web-platform/tests/element-timing/observe-svg-image.html index ea4537458cb64..45e800d25da14 100644 --- a/testing/web-platform/tests/element-timing/observe-svg-image.html +++ b/testing/web-platform/tests/element-timing/observe-svg-image.html @@ -14,7 +14,7 @@ const index = window.location.href.lastIndexOf('/'); const pathname = window.location.href.substring(0, index) + '/resources/circle.svg'; - checkElement(entry, pathname, 'my_svg', beforeRender); + checkElement(entry, pathname, 'my_svg', 'svg_id', beforeRender); // Assume viewport has size at least 200, so the element is fully visible. checkRect(entry, [0, 200, 0, 200]); checkNaturalSize(entry, 200, 200); @@ -30,5 +30,5 @@ } - + diff --git a/testing/web-platform/tests/element-timing/observe-video-poster.html b/testing/web-platform/tests/element-timing/observe-video-poster.html index 41e6edffd5c5c..d3a69937d3c3c 100644 --- a/testing/web-platform/tests/element-timing/observe-video-poster.html +++ b/testing/web-platform/tests/element-timing/observe-video-poster.html @@ -14,7 +14,7 @@ const index = window.location.href.lastIndexOf('/'); const pathname = window.location.href.substring(0, index) + '/resources/circle.svg'; - checkElement(entry, pathname, 'my_poster', beforeRender); + checkElement(entry, pathname, 'my_poster', 'the_poster', beforeRender); // Assume viewport has size at least 200, so the element is fully visible. checkRect(entry, [0, 200, 0, 200]); checkNaturalSize(entry, 200, 200); @@ -29,4 +29,4 @@ margin: 0; } -