DeferredLoadingScope incorrectly disabled images or enables deferred loading
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 21 Dec 2017 06:48:48 +0000 (06:48 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 21 Dec 2017 06:48:48 +0000 (06:48 +0000)
https://bugs.webkit.org/show_bug.cgi?id=181077

Reviewed by Wenson Hsieh.

Source/WebCore:

Fixed the bug that DeferredLoadingScope::~DeferredLoadingScope was checking the wrong flag
for restoring the disabledness of images and deferred loading.

Test: editing/pasteboard/pasting-with-images-disabled-should-not-enable-deferred-loading.html

* editing/cocoa/WebContentReaderCocoa.mm:
(WebCore::DeferredLoadingScope::~DeferredLoadingScope): Fixed the bug.
* testing/Internals.cpp:
(WebCore::Internals::pageDefersLoading): Added for testing.
* testing/Internals.h:
* testing/Internals.idl: Added pageDefersLoading.

LayoutTests:

Added a regression test.

* editing/pasteboard/pasting-with-images-disabled-should-not-enable-deferred-loading-expected.txt: Added.
* editing/pasteboard/pasting-with-images-disabled-should-not-enable-deferred-loading.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@226216 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/editing/pasteboard/pasting-with-images-disabled-should-not-enable-deferred-loading-expected.txt [new file with mode: 0644]
LayoutTests/editing/pasteboard/pasting-with-images-disabled-should-not-enable-deferred-loading.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm
Source/WebCore/testing/Internals.cpp
Source/WebCore/testing/Internals.h
Source/WebCore/testing/Internals.idl

index ae38167..4b72736 100644 (file)
@@ -1,3 +1,15 @@
+2017-12-20  Ryosuke Niwa  <rniwa@webkit.org>
+
+        DeferredLoadingScope incorrectly disabled images or enables deferred loading
+        https://bugs.webkit.org/show_bug.cgi?id=181077
+
+        Reviewed by Wenson Hsieh.
+
+        Added a regression test.
+
+        * editing/pasteboard/pasting-with-images-disabled-should-not-enable-deferred-loading-expected.txt: Added.
+        * editing/pasteboard/pasting-with-images-disabled-should-not-enable-deferred-loading.html: Added.
+
 2017-12-20  Eric Carlson  <eric.carlson@apple.com>
 
         [MediaStream] Add screen capture IDL and stub functions
diff --git a/LayoutTests/editing/pasteboard/pasting-with-images-disabled-should-not-enable-deferred-loading-expected.txt b/LayoutTests/editing/pasteboard/pasting-with-images-disabled-should-not-enable-deferred-loading-expected.txt
new file mode 100644 (file)
index 0000000..24530c6
--- /dev/null
@@ -0,0 +1,17 @@
+This tests makes sure that pasting content while images are disabled does not enable deferred loading.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+internals.settings.setImagesEnabled(false)
+document.execCommand("copy")
+PASS editor.querySelector("img").width is 76
+setTimeout(waitForImagesToBeDisabled, 0)
+PASS internals.pageDefersLoading() is false
+document.execCommand("paste")
+PASS internals.pageDefersLoading() is false
+PASS successfullyParsed is true
+
+TEST COMPLETE
+hello
+
diff --git a/LayoutTests/editing/pasteboard/pasting-with-images-disabled-should-not-enable-deferred-loading.html b/LayoutTests/editing/pasteboard/pasting-with-images-disabled-should-not-enable-deferred-loading.html
new file mode 100644 (file)
index 0000000..b0533ed
--- /dev/null
@@ -0,0 +1,37 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src="../../resources/js-test-pre.js"></script>
+<div id="editor" contenteditable>hello<img src="../resources/abe.png"></div>
+<script>
+
+description('This tests makes sure that pasting content while images are disabled does not enable deferred loading.')
+
+if (!window.internals)
+    testFailed('This test requires internals.settings');
+else {
+    jsTestIsAsync = true;
+
+    window.onload = () => {
+        editor.focus();
+        document.execCommand("selectAll");
+        evalAndLog('internals.settings.setImagesEnabled(false)');
+        evalAndLog('document.execCommand("copy")');
+        shouldBe('editor.querySelector("img").width', '76');
+        evalAndLog('setTimeout(waitForImagesToBeDisabled, 0)');
+    }
+
+    function waitForImagesToBeDisabled()
+    {
+        shouldBeFalse('internals.pageDefersLoading()');
+        evalAndLog('document.execCommand("paste")');
+        shouldBeFalse('internals.pageDefersLoading()');
+        finishJSTest();
+    }
+
+}
+
+</script>
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
index 8980292..2e4be4e 100644 (file)
@@ -1,5 +1,24 @@
 2017-12-20  Ryosuke Niwa  <rniwa@webkit.org>
 
+        DeferredLoadingScope incorrectly disabled images or enables deferred loading
+        https://bugs.webkit.org/show_bug.cgi?id=181077
+
+        Reviewed by Wenson Hsieh.
+
+        Fixed the bug that DeferredLoadingScope::~DeferredLoadingScope was checking the wrong flag
+        for restoring the disabledness of images and deferred loading.
+
+        Test: editing/pasteboard/pasting-with-images-disabled-should-not-enable-deferred-loading.html
+
+        * editing/cocoa/WebContentReaderCocoa.mm:
+        (WebCore::DeferredLoadingScope::~DeferredLoadingScope): Fixed the bug.
+        * testing/Internals.cpp:
+        (WebCore::Internals::pageDefersLoading): Added for testing.
+        * testing/Internals.h:
+        * testing/Internals.idl: Added pageDefersLoading.
+
+2017-12-20  Ryosuke Niwa  <rniwa@webkit.org>
+
         isSafari check should take Safari Technology Preview into account
         https://bugs.webkit.org/show_bug.cgi?id=181076
 
index a0a4a0b..e408560 100644 (file)
@@ -162,9 +162,9 @@ public:
 
     ~DeferredLoadingScope()
     {
-        if (m_didEnabledDeferredLoading)
-            m_cachedResourceLoader->setImagesEnabled(true);
         if (m_didDisableImage)
+            m_cachedResourceLoader->setImagesEnabled(true);
+        if (m_didEnabledDeferredLoading)
             m_frame->page()->setDefersLoading(false);
     }
 
index f68513c..3d952ec 100644 (file)
@@ -3694,6 +3694,14 @@ void Internals::setPageDefersLoading(bool defersLoading)
         page->setDefersLoading(defersLoading);
 }
 
+ExceptionOr<bool> Internals::pageDefersLoading()
+{
+    Document* document = contextDocument();
+    if (!document || !document->page())
+        return Exception { InvalidAccessError };
+    return document->page()->defersLoading();
+}
+
 RefPtr<File> Internals::createFile(const String& path)
 {
     Document* document = contextDocument();
index f34eaca..a2b9886 100644 (file)
@@ -530,6 +530,7 @@ public:
     String pageMediaState();
 
     void setPageDefersLoading(bool);
+    ExceptionOr<bool> pageDefersLoading();
 
     RefPtr<File> createFile(const String&);
     void queueMicroTask(int);
index 4160703..7272871 100644 (file)
@@ -484,6 +484,7 @@ enum EventThrottlingBehavior {
     DOMString pageMediaState();
 
     void setPageDefersLoading(boolean defersLoading);
+    [MayThrowException] boolean pageDefersLoading();
 
     File? createFile(DOMString url);
     void queueMicroTask(long testNumber);