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

Side by Side Diff: third_party/WebKit/Source/web/tests/WebFrameTest.cpp

Issue 1836973003: Move download messages from Renderer to Frame filter. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comments, merge Created 4 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 unified diff | Download patch
OLDNEW
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
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 8533 matching lines...) Expand 10 before | Expand all | Expand 10 after
8637 8639
8638 WebLocalFrame* mainFrame = helper.webView()->mainFrame()->toWebLocalFrame(); 8640 WebLocalFrame* mainFrame = helper.webView()->mainFrame()->toWebLocalFrame();
8639 v8::HandleScope scope(v8::Isolate::GetCurrent()); 8641 v8::HandleScope scope(v8::Isolate::GetCurrent());
8640 mainFrame->executeScript(WebScriptSource("hello = 'world';")); 8642 mainFrame->executeScript(WebScriptSource("hello = 'world';"));
8641 FrameTestHelpers::loadFrame(mainFrame, "data:text/html,new page"); 8643 FrameTestHelpers::loadFrame(mainFrame, "data:text/html,new page");
8642 v8::Local<v8::Value> result = mainFrame->executeScriptAndReturnValue(WebScri ptSource("hello")); 8644 v8::Local<v8::Value> result = mainFrame->executeScriptAndReturnValue(WebScri ptSource("hello"));
8643 ASSERT_TRUE(result->IsString()); 8645 ASSERT_TRUE(result->IsString());
8644 EXPECT_EQ("world", toCoreString(result->ToString(mainFrame->mainWorldScriptC ontext()).ToLocalChecked())); 8646 EXPECT_EQ("world", toCoreString(result->ToString(mainFrame->mainWorldScriptC ontext()).ToLocalChecked()));
8645 } 8647 }
8646 8648
8649 class SaveImageFromDataURLWebFrameClient : public FrameTestHelpers::TestWebFrame Client {
8650 public:
8651 // WebFrameClient methods
8652 void saveImageFromDataURL(const WebString& dataURL) override { m_dataURL = d ataURL; }
8653
8654 // Local methods
8655 const WebString& result() const { return m_dataURL; }
8656 void reset() { m_dataURL = WebString(); }
8657
8658 private:
8659 WebString m_dataURL;
8660 };
8661
8662 TEST_F(WebFrameTest, SaveImageAt)
8663 {
8664 std::string url = m_baseURL + "image-with-data-url.html";
8665 URLTestHelpers::registerMockedURLLoad(toKURL(url), "image-with-data-url.html ");
8666 URLTestHelpers::registerMockedURLLoad(toKURL("http://test"), "white-1x1.png" );
8667
8668 FrameTestHelpers::WebViewHelper helper;
8669 SaveImageFromDataURLWebFrameClient client;
8670 WebViewImpl* webView = helper.initializeAndLoad(url, true, &client);
8671 webView->resize(WebSize(400, 400));
8672 webView->updateAllLifecyclePhases();
8673
8674 WebLocalFrame* localFrame = webView->mainFrame()->toWebLocalFrame();
8675
8676 client.reset();
8677 localFrame->saveImageAt(WebPoint(1, 1));
8678 EXPECT_EQ(WebString::fromUTF8("data:image/gif;base64"
8679 ",R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs="), client.result());
8680
8681 client.reset();
8682 localFrame->saveImageAt(WebPoint(1, 2));
8683 EXPECT_EQ(WebString(), client.result());
8684
8685 webView->setPageScaleFactor(4);
8686 webView->setVisualViewportOffset(WebFloatPoint(1, 1));
8687
8688 client.reset();
8689 localFrame->saveImageAt(WebPoint(3, 3));
8690 EXPECT_EQ(WebString::fromUTF8("data:image/gif;base64"
8691 ",R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs="), client.result());
8692
8693 helper.reset(); // Explicitly reset to break dependency on locally scoped cl ient.
8694 }
8695
8696 TEST_F(WebFrameTest, SaveImageWithImageMap)
8697 {
8698 std::string url = m_baseURL + "image-map.html";
8699 URLTestHelpers::registerMockedURLLoad(toKURL(url), "image-map.html");
8700
8701 FrameTestHelpers::WebViewHelper helper;
8702 SaveImageFromDataURLWebFrameClient client;
8703 WebView* webView = helper.initializeAndLoad(url, true, &client);
8704 webView->resize(WebSize(400, 400));
8705
8706 WebLocalFrame* localFrame = webView->mainFrame()->toWebLocalFrame();
8707
8708 client.reset();
8709 localFrame->saveImageAt(WebPoint(25, 25));
8710 EXPECT_EQ(WebString::fromUTF8("data:image/gif;base64"
8711 ",R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs="), client.result());
8712
8713 client.reset();
8714 localFrame->saveImageAt(WebPoint(75, 25));
8715 EXPECT_EQ(WebString::fromUTF8("data:image/gif;base64"
8716 ",R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs="), client.result());
8717
8718 client.reset();
8719 localFrame->saveImageAt(WebPoint(125, 25));
8720 EXPECT_EQ(WebString(), client.result());
8721
8722 helper.reset(); // Explicitly reset to break dependency on locally scoped cl ient.
8723 }
8724
8725 TEST_F(WebFrameTest, CopyImageAt)
8726 {
8727 std::string url = m_baseURL + "canvas-copy-image.html";
8728 URLTestHelpers::registerMockedURLLoad(toKURL(url), "canvas-copy-image.html") ;
8729
8730 FrameTestHelpers::WebViewHelper helper;
8731 WebView* webView = helper.initializeAndLoad(url, true, 0);
8732 webView->resize(WebSize(400, 400));
8733
8734 uint64_t sequence = Platform::current()->clipboard()->sequenceNumber(WebClip board::BufferStandard);
8735
8736 WebLocalFrame* localFrame = webView->mainFrame()->toWebLocalFrame();
8737 localFrame->copyImageAt(WebPoint(50, 50));
8738
8739 EXPECT_NE(sequence, Platform::current()->clipboard()->sequenceNumber(WebClip board::BufferStandard));
8740
8741 WebImage image = static_cast<WebMockClipboard*>(Platform::current()->clipboa rd())->readRawImage(WebClipboard::Buffer());
8742
8743 SkAutoLockPixels autoLock(image.getSkBitmap());
8744 EXPECT_EQ(SkColorSetARGB(255, 255, 0, 0), image.getSkBitmap().getColor(0, 0) );
8745 };
8746
8747 TEST_F(WebFrameTest, CopyImageAtWithPinchZoom)
8748 {
8749 std::string url = m_baseURL + "canvas-copy-image.html";
8750 URLTestHelpers::registerMockedURLLoad(toKURL(url), "canvas-copy-image.html") ;
8751
8752 FrameTestHelpers::WebViewHelper helper;
8753 WebViewImpl* webView = helper.initializeAndLoad(url, true, 0);
8754 webView->resize(WebSize(400, 400));
8755 webView->updateAllLifecyclePhases();
8756 webView->setPageScaleFactor(2);
8757 webView->setVisualViewportOffset(WebFloatPoint(200, 200));
8758
8759 uint64_t sequence = Platform::current()->clipboard()->sequenceNumber(WebClip board::BufferStandard);
8760
8761 WebLocalFrame* localFrame = webView->mainFrame()->toWebLocalFrame();
8762 localFrame->copyImageAt(WebPoint(0, 0));
8763
8764 EXPECT_NE(sequence, Platform::current()->clipboard()->sequenceNumber(WebClip board::BufferStandard));
8765
8766 WebImage image = static_cast<WebMockClipboard*>(Platform::current()->clipboa rd())->readRawImage(WebClipboard::Buffer());
8767
8768 SkAutoLockPixels autoLock(image.getSkBitmap());
8769 EXPECT_EQ(SkColorSetARGB(255, 255, 0, 0), image.getSkBitmap().getColor(0, 0) );
8770 };
8771
8772 TEST_F(WebFrameTest, CopyImageWithImageMap)
8773 {
8774 SaveImageFromDataURLWebFrameClient client;
8775
8776 std::string url = m_baseURL + "image-map.html";
8777 URLTestHelpers::registerMockedURLLoad(toKURL(url), "image-map.html");
8778
8779 FrameTestHelpers::WebViewHelper helper;
8780 WebView* webView = helper.initializeAndLoad(url, true, &client);
8781 webView->resize(WebSize(400, 400));
8782
8783 client.reset();
8784 WebLocalFrame* localFrame = webView->mainFrame()->toWebLocalFrame();
8785 localFrame->saveImageAt(WebPoint(25, 25));
8786 EXPECT_EQ(WebString::fromUTF8("data:image/gif;base64"
8787 ",R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs="), client.result());
8788
8789 client.reset();
8790 localFrame->saveImageAt(WebPoint(75, 25));
8791 EXPECT_EQ(WebString::fromUTF8("data:image/gif;base64"
8792 ",R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs="), client.result());
8793
8794 client.reset();
8795 localFrame->saveImageAt(WebPoint(125, 25));
8796 EXPECT_EQ(WebString(), client.result());
8797
8798 helper.reset(); // Explicitly reset to break dependency on locally scoped cl ient.
8799 }
8800
8647 static void setSecurityOrigin(WebFrame* frame, PassRefPtr<SecurityOrigin> securi tyOrigin) 8801 static void setSecurityOrigin(WebFrame* frame, PassRefPtr<SecurityOrigin> securi tyOrigin)
8648 { 8802 {
8649 Document* document = frame->document(); 8803 Document* document = frame->document();
8650 document->setSecurityOrigin(securityOrigin); 8804 document->setSecurityOrigin(securityOrigin);
8651 } 8805 }
8652 8806
8653 TEST_F(WebFrameTest, CanHaveSecureChild) 8807 TEST_F(WebFrameTest, CanHaveSecureChild)
8654 { 8808 {
8655 FrameTestHelpers::WebViewHelper helper; 8809 FrameTestHelpers::WebViewHelper helper;
8656 FrameTestHelpers::TestWebFrameClient client; 8810 FrameTestHelpers::TestWebFrameClient client;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
8696 ASSERT_FALSE(grandchildFrame->canHaveSecureChild()); 8850 ASSERT_FALSE(grandchildFrame->canHaveSecureChild());
8697 Document* mainDocument = mainFrame->document(); 8851 Document* mainDocument = mainFrame->document();
8698 Document* childDocument = childFrame->document(); 8852 Document* childDocument = childFrame->document();
8699 Document* grandchildDocument = grandchildFrame->document(); 8853 Document* grandchildDocument = grandchildFrame->document();
8700 ASSERT_FALSE(mainDocument->isSecureContext()); 8854 ASSERT_FALSE(mainDocument->isSecureContext());
8701 ASSERT_TRUE(childDocument->isSecureContext()); 8855 ASSERT_TRUE(childDocument->isSecureContext());
8702 ASSERT_FALSE(grandchildDocument->isSecureContext()); 8856 ASSERT_FALSE(grandchildDocument->isSecureContext());
8703 } 8857 }
8704 8858
8705 } // namespace blink 8859 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/web/WebViewImpl.cpp ('k') | third_party/WebKit/Source/web/tests/WebViewTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698