Commit 5fb64779 authored by Ian Clelland's avatar Ian Clelland Committed by Commit Bot

Add stream printer for WebSandboxFlags

This allows debug messages to print sandbox flags in a convenient binary
format, rather than outputting them as decimal numbers or 4-byte arrays.

This means that you can easily add debug statements for sandboxing code like:

DLOG(INFO) << "The sandbox flags here look like " << sandbox_flags_;

rather than having to cast:

DLOG(INFO) << "The sandbox flags here look like " <<
    std::bitset<32>(static_cast<int>(sandbox_flags_));

It also changes the test output from EXPECT_EQ failures from looking like:

../../content/browser/some_browsertest.cc:12345: Failure
      Expected: blink::WebSandboxFlags::kAll & ~blink::WebSandboxFlags::kScripts & ~blink::WebSandboxFlags::kAutomaticFeatures
      Which is: 4-byte object <6F-FF FF-FF>
To be equal to: root->child_at(1)->effective_frame_policy().sandbox_flags
      Which is: 4-byte object <FF-FA FF-FF>

to the more reasonable:

../../content/browser/some_browsertest.cc:12345: Failure
      Expected: blink::WebSandboxFlags::kAll & ~blink::WebSandboxFlags::kScripts & ~blink::WebSandboxFlags::kAutomaticFeatures
      Which is: 11111111111111111111111101101111
To be equal to: root->child_at(1)->effective_frame_policy().sandbox_flags
      Which is: 11111111111111111111101011111111

in which single bit errors can easily be spotted.

Change-Id: Ibc9020d67654c555e1c70dcb99829e2eb29d0b3c
Reviewed-on: https://chromium-review.googlesource.com/772320Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarJeremy Roman <jbroman@chromium.org>
Commit-Queue: Ian Clelland <iclelland@chromium.org>
Cr-Commit-Position: refs/heads/master@{#574151}
parent ca00af37
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifndef THIRD_PARTY_BLINK_PUBLIC_COMMON_FRAME_SANDBOX_FLAGS_H_ #ifndef THIRD_PARTY_BLINK_PUBLIC_COMMON_FRAME_SANDBOX_FLAGS_H_
#define THIRD_PARTY_BLINK_PUBLIC_COMMON_FRAME_SANDBOX_FLAGS_H_ #define THIRD_PARTY_BLINK_PUBLIC_COMMON_FRAME_SANDBOX_FLAGS_H_
#include <bitset>
namespace blink { namespace blink {
// See http://www.whatwg.org/specs/web-apps/current-work/#attr-iframe-sandbox // See http://www.whatwg.org/specs/web-apps/current-work/#attr-iframe-sandbox
...@@ -51,6 +53,10 @@ inline constexpr WebSandboxFlags operator~(WebSandboxFlags flags) { ...@@ -51,6 +53,10 @@ inline constexpr WebSandboxFlags operator~(WebSandboxFlags flags) {
return static_cast<WebSandboxFlags>(~static_cast<int>(flags)); return static_cast<WebSandboxFlags>(~static_cast<int>(flags));
} }
inline std::ostream& operator<<(std::ostream& out, WebSandboxFlags flags) {
return out << std::bitset<sizeof(int) * 8>(static_cast<int>(flags));
}
} // namespace blink } // namespace blink
#endif // THIRD_PARTY_BLINK_PUBLIC_COMMON_FRAME_SANDBOX_FLAGS_H_ #endif // THIRD_PARTY_BLINK_PUBLIC_COMMON_FRAME_SANDBOX_FLAGS_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment