Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(939)

Unified Diff: Source/core/html/HTMLImageElementTest.cpp

Issue 1186333004: Add support for `width` based Width Client Hint (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Moar comments Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/html/HTMLImageElement.cpp ('k') | Source/core/html/parser/HTMLPreloadScanner.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/html/HTMLImageElementTest.cpp
diff --git a/Source/core/html/HTMLImageElementTest.cpp b/Source/core/html/HTMLImageElementTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..442f08c3fddd4ba2b411dc30993bd7a1a1fd1c68
--- /dev/null
+++ b/Source/core/html/HTMLImageElementTest.cpp
@@ -0,0 +1,45 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "config.h"
+#include "core/html/HTMLImageElement.h"
+
+#include "core/dom/Document.h"
+#include "core/frame/FrameView.h"
+#include "core/testing/DummyPageHolder.h"
+#include <gtest/gtest.h>
+
+namespace blink {
+
+const int viewportWidth = 500;
+const int viewportHeight = 600;
+class HTMLImageElementTest : public testing::Test {
+protected:
+ HTMLImageElementTest()
+ : m_dummyPageHolder(DummyPageHolder::create(IntSize(viewportWidth, viewportHeight)))
+ {
+ }
+
+ OwnPtr<DummyPageHolder> m_dummyPageHolder;
+};
+
+TEST_F(HTMLImageElementTest, width)
+{
+ RefPtrWillBeRawPtr<HTMLImageElement> image = HTMLImageElement::create(m_dummyPageHolder->document(), nullptr, /* createdByParser */ false);
+ image->setAttribute(HTMLNames::widthAttr, "400");
+ EXPECT_EQ(400, image->resourceWidth().width);
+ image->setAttribute(HTMLNames::sizesAttr, "100vw");
+ EXPECT_EQ(500, image->resourceWidth().width);
+}
+
+TEST_F(HTMLImageElementTest, sourceSize)
+{
+ RefPtrWillBeRawPtr<HTMLImageElement> image = HTMLImageElement::create(m_dummyPageHolder->document(), nullptr, /* createdByParser */ false);
+ image->setAttribute(HTMLNames::widthAttr, "400");
+ EXPECT_EQ(viewportWidth, image->sourceSize(*image));
+ image->setAttribute(HTMLNames::sizesAttr, "50vw");
+ EXPECT_EQ(250, image->sourceSize(*image));
+}
+
+} // namespace blink
« no previous file with comments | « Source/core/html/HTMLImageElement.cpp ('k') | Source/core/html/parser/HTMLPreloadScanner.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698