OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
83 #include "platform/UserGestureIndicator.h" | 83 #include "platform/UserGestureIndicator.h" |
84 #include "platform/geometry/FloatRect.h" | 84 #include "platform/geometry/FloatRect.h" |
85 #include "platform/network/ResourceError.h" | 85 #include "platform/network/ResourceError.h" |
86 #include "platform/scroll/ScrollbarTheme.h" | 86 #include "platform/scroll/ScrollbarTheme.h" |
87 #include "platform/testing/URLTestHelpers.h" | 87 #include "platform/testing/URLTestHelpers.h" |
88 #include "platform/testing/UnitTestHelpers.h" | 88 #include "platform/testing/UnitTestHelpers.h" |
89 #include "platform/weborigin/SchemeRegistry.h" | 89 #include "platform/weborigin/SchemeRegistry.h" |
90 #include "platform/weborigin/SecurityOrigin.h" | 90 #include "platform/weborigin/SecurityOrigin.h" |
91 #include "public/platform/Platform.h" | 91 #include "public/platform/Platform.h" |
92 #include "public/platform/WebCachePolicy.h" | 92 #include "public/platform/WebCachePolicy.h" |
93 #include "public/platform/WebClipboard.h" | |
93 #include "public/platform/WebFloatRect.h" | 94 #include "public/platform/WebFloatRect.h" |
95 #include "public/platform/WebMockClipboard.h" | |
94 #include "public/platform/WebSecurityOrigin.h" | 96 #include "public/platform/WebSecurityOrigin.h" |
95 #include "public/platform/WebThread.h" | 97 #include "public/platform/WebThread.h" |
96 #include "public/platform/WebURL.h" | 98 #include "public/platform/WebURL.h" |
97 #include "public/platform/WebURLLoaderMockFactory.h" | 99 #include "public/platform/WebURLLoaderMockFactory.h" |
98 #include "public/platform/WebURLResponse.h" | 100 #include "public/platform/WebURLResponse.h" |
99 #include "public/web/WebCache.h" | 101 #include "public/web/WebCache.h" |
100 #include "public/web/WebConsoleMessage.h" | 102 #include "public/web/WebConsoleMessage.h" |
101 #include "public/web/WebDataSource.h" | 103 #include "public/web/WebDataSource.h" |
102 #include "public/web/WebDeviceEmulationParams.h" | 104 #include "public/web/WebDeviceEmulationParams.h" |
103 #include "public/web/WebDocument.h" | 105 #include "public/web/WebDocument.h" |
(...skipping 8558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8662 | 8664 |
8663 WebLocalFrame* mainFrame = helper.webView()->mainFrame()->toWebLocalFrame(); | 8665 WebLocalFrame* mainFrame = helper.webView()->mainFrame()->toWebLocalFrame(); |
8664 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 8666 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
8665 mainFrame->executeScript(WebScriptSource("hello = 'world';")); | 8667 mainFrame->executeScript(WebScriptSource("hello = 'world';")); |
8666 FrameTestHelpers::loadFrame(mainFrame, "data:text/html,new page"); | 8668 FrameTestHelpers::loadFrame(mainFrame, "data:text/html,new page"); |
8667 v8::Local<v8::Value> result = mainFrame->executeScriptAndReturnValue(WebScri ptSource("hello")); | 8669 v8::Local<v8::Value> result = mainFrame->executeScriptAndReturnValue(WebScri ptSource("hello")); |
8668 ASSERT_TRUE(result->IsString()); | 8670 ASSERT_TRUE(result->IsString()); |
8669 EXPECT_EQ("world", toCoreString(result->ToString(mainFrame->mainWorldScriptC ontext()).ToLocalChecked())); | 8671 EXPECT_EQ("world", toCoreString(result->ToString(mainFrame->mainWorldScriptC ontext()).ToLocalChecked())); |
8670 } | 8672 } |
8671 | 8673 |
8674 static void setSecurityOrigin(WebFrame* frame, PassRefPtr<SecurityOrigin> securi tyOrigin) | |
dcheng
2016/06/12 05:58:34
Lines 8674 through 8731 look like they're from cod
| |
8675 { | |
8676 Document* document = frame->document(); | |
8677 document->setSecurityOrigin(securityOrigin); | |
8678 } | |
8679 | |
8680 TEST_F(WebFrameTest, CanHaveSecureChild) | |
8681 { | |
8682 FrameTestHelpers::WebViewHelper helper; | |
8683 FrameTestHelpers::TestWebFrameClient client; | |
8684 helper.initialize(true, &client, nullptr, nullptr); | |
8685 WebFrame* mainFrame = helper.webView()->mainFrame(); | |
8686 RefPtr<SecurityOrigin> secureOrigin = SecurityOrigin::createFromString("http s://example.com"); | |
8687 RefPtr<SecurityOrigin> insecureOrigin = SecurityOrigin::createFromString("ht tp://example.com"); | |
8688 | |
8689 // Secure frame. | |
8690 setSecurityOrigin(mainFrame, secureOrigin); | |
8691 ASSERT_TRUE(mainFrame->canHaveSecureChild()); | |
8692 | |
8693 // Insecure frame. | |
8694 setSecurityOrigin(mainFrame, insecureOrigin); | |
8695 ASSERT_FALSE(mainFrame->canHaveSecureChild()); | |
8696 | |
8697 // Create a chain of frames. | |
8698 FrameTestHelpers::loadFrame(mainFrame, "data:text/html,<iframe></iframe>"); | |
8699 WebFrame* childFrame = mainFrame->firstChild(); | |
8700 FrameTestHelpers::loadFrame(childFrame, "data:text/html,<iframe></iframe>"); | |
8701 WebFrame* grandchildFrame = childFrame->firstChild(); | |
8702 | |
8703 // Secure -> insecure -> secure frame. | |
8704 setSecurityOrigin(mainFrame, secureOrigin); | |
8705 setSecurityOrigin(childFrame, insecureOrigin); | |
8706 setSecurityOrigin(grandchildFrame, secureOrigin); | |
8707 ASSERT_TRUE(mainFrame->canHaveSecureChild()); | |
8708 ASSERT_FALSE(childFrame->canHaveSecureChild()); | |
8709 ASSERT_FALSE(grandchildFrame->canHaveSecureChild()); | |
8710 | |
8711 // A document in an insecure context can be considered secure if it has a | |
8712 // scheme that bypasses the secure context check. But the exception doesn't | |
8713 // apply to children of that document's frame. | |
8714 SchemeRegistry::registerURLSchemeBypassingSecureContextCheck("very-special-s cheme"); | |
8715 SchemeRegistry::registerURLSchemeAsSecure("very-special-scheme"); | |
8716 RefPtr<SecurityOrigin> specialOrigin = SecurityOrigin::createFromString("ver y-special-scheme://example.com"); | |
8717 | |
8718 setSecurityOrigin(mainFrame, insecureOrigin); | |
8719 setSecurityOrigin(childFrame, specialOrigin); | |
8720 setSecurityOrigin(grandchildFrame, secureOrigin); | |
8721 ASSERT_FALSE(mainFrame->canHaveSecureChild()); | |
8722 ASSERT_FALSE(childFrame->canHaveSecureChild()); | |
8723 ASSERT_FALSE(grandchildFrame->canHaveSecureChild()); | |
8724 Document* mainDocument = mainFrame->document(); | |
8725 Document* childDocument = childFrame->document(); | |
8726 Document* grandchildDocument = grandchildFrame->document(); | |
8727 ASSERT_FALSE(mainDocument->isSecureContext()); | |
8728 ASSERT_TRUE(childDocument->isSecureContext()); | |
8729 ASSERT_FALSE(grandchildDocument->isSecureContext()); | |
8730 } | |
8731 | |
8732 class SaveImageFromDataURLWebFrameClient : public FrameTestHelpers::TestWebFrame Client { | |
8733 public: | |
8734 // WebFrameClient methods | |
8735 void saveImageFromDataURL(const WebString& dataURL) override { m_dataURL = d ataURL; } | |
8736 | |
8737 // Local methods | |
8738 const WebString& result() const { return m_dataURL; } | |
8739 void reset() { m_dataURL = WebString(); } | |
8740 | |
8741 private: | |
8742 WebString m_dataURL; | |
8743 }; | |
8744 | |
8745 TEST_F(WebFrameTest, SaveImageAt) | |
8746 { | |
8747 std::string url = m_baseURL + "image-with-data-url.html"; | |
8748 URLTestHelpers::registerMockedURLLoad(toKURL(url), "image-with-data-url.html "); | |
8749 URLTestHelpers::registerMockedURLLoad(toKURL("http://test"), "white-1x1.png" ); | |
8750 | |
8751 FrameTestHelpers::WebViewHelper helper; | |
8752 SaveImageFromDataURLWebFrameClient client; | |
8753 WebViewImpl* webView = helper.initializeAndLoad(url, true, &client); | |
8754 webView->resize(WebSize(400, 400)); | |
8755 webView->updateAllLifecyclePhases(); | |
8756 | |
8757 WebLocalFrame* localFrame = webView->mainFrame()->toWebLocalFrame(); | |
8758 | |
8759 client.reset(); | |
8760 localFrame->saveImageAt(WebPoint(1, 1)); | |
8761 EXPECT_EQ(WebString::fromUTF8("data:image/gif;base64" | |
8762 ",R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs="), client.result()); | |
8763 | |
8764 client.reset(); | |
8765 localFrame->saveImageAt(WebPoint(1, 2)); | |
8766 EXPECT_EQ(WebString(), client.result()); | |
8767 | |
8768 webView->setPageScaleFactor(4); | |
8769 webView->setVisualViewportOffset(WebFloatPoint(1, 1)); | |
8770 | |
8771 client.reset(); | |
8772 localFrame->saveImageAt(WebPoint(3, 3)); | |
8773 EXPECT_EQ(WebString::fromUTF8("data:image/gif;base64" | |
8774 ",R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs="), client.result()); | |
8775 | |
8776 helper.reset(); // Explicitly reset to break dependency on locally scoped cl ient. | |
8777 } | |
8778 | |
8779 TEST_F(WebFrameTest, SaveImageWithImageMap) | |
8780 { | |
8781 std::string url = m_baseURL + "image-map.html"; | |
8782 URLTestHelpers::registerMockedURLLoad(toKURL(url), "image-map.html"); | |
8783 | |
8784 FrameTestHelpers::WebViewHelper helper; | |
8785 SaveImageFromDataURLWebFrameClient client; | |
8786 WebView* webView = helper.initializeAndLoad(url, true, &client); | |
8787 webView->resize(WebSize(400, 400)); | |
8788 | |
8789 WebLocalFrame* localFrame = webView->mainFrame()->toWebLocalFrame(); | |
8790 | |
8791 client.reset(); | |
8792 localFrame->saveImageAt(WebPoint(25, 25)); | |
8793 EXPECT_EQ(WebString::fromUTF8("data:image/gif;base64" | |
8794 ",R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs="), client.result()); | |
8795 | |
8796 client.reset(); | |
8797 localFrame->saveImageAt(WebPoint(75, 25)); | |
8798 EXPECT_EQ(WebString::fromUTF8("data:image/gif;base64" | |
8799 ",R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs="), client.result()); | |
8800 | |
8801 client.reset(); | |
8802 localFrame->saveImageAt(WebPoint(125, 25)); | |
8803 EXPECT_EQ(WebString(), client.result()); | |
8804 | |
8805 helper.reset(); // Explicitly reset to break dependency on locally scoped cl ient. | |
8806 } | |
8807 | |
8808 TEST_F(WebFrameTest, CopyImageAt) | |
8809 { | |
8810 std::string url = m_baseURL + "canvas-copy-image.html"; | |
8811 URLTestHelpers::registerMockedURLLoad(toKURL(url), "canvas-copy-image.html") ; | |
8812 | |
8813 FrameTestHelpers::WebViewHelper helper; | |
8814 WebView* webView = helper.initializeAndLoad(url, true, 0); | |
8815 webView->resize(WebSize(400, 400)); | |
8816 | |
8817 uint64_t sequence = Platform::current()->clipboard()->sequenceNumber(WebClip board::BufferStandard); | |
8818 | |
8819 WebLocalFrame* localFrame = webView->mainFrame()->toWebLocalFrame(); | |
8820 localFrame->copyImageAt(WebPoint(50, 50)); | |
8821 | |
8822 EXPECT_NE(sequence, Platform::current()->clipboard()->sequenceNumber(WebClip board::BufferStandard)); | |
8823 | |
8824 WebImage image = static_cast<WebMockClipboard*>(Platform::current()->clipboa rd())->readRawImage(WebClipboard::Buffer()); | |
8825 | |
8826 SkAutoLockPixels autoLock(image.getSkBitmap()); | |
8827 EXPECT_EQ(SkColorSetARGB(255, 255, 0, 0), image.getSkBitmap().getColor(0, 0) ); | |
8828 }; | |
8829 | |
8830 TEST_F(WebFrameTest, CopyImageAtWithPinchZoom) | |
8831 { | |
8832 std::string url = m_baseURL + "canvas-copy-image.html"; | |
8833 URLTestHelpers::registerMockedURLLoad(toKURL(url), "canvas-copy-image.html") ; | |
8834 | |
8835 FrameTestHelpers::WebViewHelper helper; | |
8836 WebViewImpl* webView = helper.initializeAndLoad(url, true, 0); | |
8837 webView->resize(WebSize(400, 400)); | |
8838 webView->updateAllLifecyclePhases(); | |
8839 webView->setPageScaleFactor(2); | |
8840 webView->setVisualViewportOffset(WebFloatPoint(200, 200)); | |
8841 | |
8842 uint64_t sequence = Platform::current()->clipboard()->sequenceNumber(WebClip board::BufferStandard); | |
8843 | |
8844 WebLocalFrame* localFrame = webView->mainFrame()->toWebLocalFrame(); | |
8845 localFrame->copyImageAt(WebPoint(0, 0)); | |
8846 | |
8847 EXPECT_NE(sequence, Platform::current()->clipboard()->sequenceNumber(WebClip board::BufferStandard)); | |
8848 | |
8849 WebImage image = static_cast<WebMockClipboard*>(Platform::current()->clipboa rd())->readRawImage(WebClipboard::Buffer()); | |
8850 | |
8851 SkAutoLockPixels autoLock(image.getSkBitmap()); | |
8852 EXPECT_EQ(SkColorSetARGB(255, 255, 0, 0), image.getSkBitmap().getColor(0, 0) ); | |
8853 }; | |
8854 | |
8855 TEST_F(WebFrameTest, CopyImageWithImageMap) | |
8856 { | |
8857 SaveImageFromDataURLWebFrameClient client; | |
8858 | |
8859 std::string url = m_baseURL + "image-map.html"; | |
8860 URLTestHelpers::registerMockedURLLoad(toKURL(url), "image-map.html"); | |
8861 | |
8862 FrameTestHelpers::WebViewHelper helper; | |
8863 WebView* webView = helper.initializeAndLoad(url, true, &client); | |
8864 webView->resize(WebSize(400, 400)); | |
8865 | |
8866 client.reset(); | |
8867 WebLocalFrame* localFrame = webView->mainFrame()->toWebLocalFrame(); | |
8868 localFrame->saveImageAt(WebPoint(25, 25)); | |
8869 EXPECT_EQ(WebString::fromUTF8("data:image/gif;base64" | |
8870 ",R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs="), client.result()); | |
8871 | |
8872 client.reset(); | |
8873 localFrame->saveImageAt(WebPoint(75, 25)); | |
8874 EXPECT_EQ(WebString::fromUTF8("data:image/gif;base64" | |
8875 ",R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs="), client.result()); | |
8876 | |
8877 client.reset(); | |
8878 localFrame->saveImageAt(WebPoint(125, 25)); | |
8879 EXPECT_EQ(WebString(), client.result()); | |
8880 | |
8881 helper.reset(); // Explicitly reset to break dependency on locally scoped cl ient. | |
8882 } | |
8883 | |
8672 } // namespace blink | 8884 } // namespace blink |
OLD | NEW |