| 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 #include "modules/mediastream/MediaStreamRegistry.h" | 80 #include "modules/mediastream/MediaStreamRegistry.h" |
| 81 #include "platform/DragImage.h" | 81 #include "platform/DragImage.h" |
| 82 #include "platform/PlatformResourceLoader.h" | 82 #include "platform/PlatformResourceLoader.h" |
| 83 #include "platform/RuntimeEnabledFeatures.h" | 83 #include "platform/RuntimeEnabledFeatures.h" |
| 84 #include "platform/UserGestureIndicator.h" | 84 #include "platform/UserGestureIndicator.h" |
| 85 #include "platform/geometry/FloatRect.h" | 85 #include "platform/geometry/FloatRect.h" |
| 86 #include "platform/network/ResourceError.h" | 86 #include "platform/network/ResourceError.h" |
| 87 #include "platform/scroll/ScrollbarTheme.h" | 87 #include "platform/scroll/ScrollbarTheme.h" |
| 88 #include "platform/testing/URLTestHelpers.h" | 88 #include "platform/testing/URLTestHelpers.h" |
| 89 #include "platform/testing/UnitTestHelpers.h" | 89 #include "platform/testing/UnitTestHelpers.h" |
| 90 #include "platform/weborigin/KURLHash.h" |
| 90 #include "platform/weborigin/SchemeRegistry.h" | 91 #include "platform/weborigin/SchemeRegistry.h" |
| 91 #include "platform/weborigin/SecurityOrigin.h" | 92 #include "platform/weborigin/SecurityOrigin.h" |
| 92 #include "public/platform/Platform.h" | 93 #include "public/platform/Platform.h" |
| 93 #include "public/platform/WebCachePolicy.h" | 94 #include "public/platform/WebCachePolicy.h" |
| 94 #include "public/platform/WebClipboard.h" | 95 #include "public/platform/WebClipboard.h" |
| 95 #include "public/platform/WebFloatRect.h" | 96 #include "public/platform/WebFloatRect.h" |
| 96 #include "public/platform/WebMockClipboard.h" | 97 #include "public/platform/WebMockClipboard.h" |
| 97 #include "public/platform/WebSecurityOrigin.h" | 98 #include "public/platform/WebSecurityOrigin.h" |
| 98 #include "public/platform/WebThread.h" | 99 #include "public/platform/WebThread.h" |
| 99 #include "public/platform/WebURL.h" | 100 #include "public/platform/WebURL.h" |
| (...skipping 5813 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5913 | 5914 |
| 5914 virtual void didStopLoading() | 5915 virtual void didStopLoading() |
| 5915 { | 5916 { |
| 5916 if (m_parentClient) { | 5917 if (m_parentClient) { |
| 5917 m_parentClient->didStopLoading(); | 5918 m_parentClient->didStopLoading(); |
| 5918 return; | 5919 return; |
| 5919 } | 5920 } |
| 5920 TestWebFrameClient::didStopLoading(); | 5921 TestWebFrameClient::didStopLoading(); |
| 5921 } | 5922 } |
| 5922 | 5923 |
| 5923 void willSendRequest(WebLocalFrame* frame, unsigned, WebURLRequest& request,
const WebURLResponse&) override | 5924 void willSendRequest(WebLocalFrame*, WebURLRequest& request) override |
| 5924 { | 5925 { |
| 5925 m_policy = request.getCachePolicy(); | 5926 m_policy = request.getCachePolicy(); |
| 5926 m_willSendRequestCallCount++; | 5927 m_willSendRequestCallCount++; |
| 5927 } | 5928 } |
| 5928 | 5929 |
| 5929 private: | 5930 private: |
| 5930 TestCachePolicyWebFrameClient* m_parentClient; | 5931 TestCachePolicyWebFrameClient* m_parentClient; |
| 5931 | 5932 |
| 5932 WebCachePolicy m_policy; | 5933 WebCachePolicy m_policy; |
| 5933 TestCachePolicyWebFrameClient* m_childClient; | 5934 TestCachePolicyWebFrameClient* m_childClient; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 5964 EXPECT_EQ(childClient.getCachePolicy(), WebCachePolicy::ValidatingCacheData)
; | 5965 EXPECT_EQ(childClient.getCachePolicy(), WebCachePolicy::ValidatingCacheData)
; |
| 5965 } | 5966 } |
| 5966 | 5967 |
| 5967 class TestSameDocumentWebFrameClient : public FrameTestHelpers::TestWebFrameClie
nt { | 5968 class TestSameDocumentWebFrameClient : public FrameTestHelpers::TestWebFrameClie
nt { |
| 5968 public: | 5969 public: |
| 5969 TestSameDocumentWebFrameClient() | 5970 TestSameDocumentWebFrameClient() |
| 5970 : m_frameLoadTypeReloadMainResourceSeen(false) | 5971 : m_frameLoadTypeReloadMainResourceSeen(false) |
| 5971 { | 5972 { |
| 5972 } | 5973 } |
| 5973 | 5974 |
| 5974 virtual void willSendRequest(WebLocalFrame* frame, unsigned, WebURLRequest&,
const WebURLResponse&) | 5975 virtual void willSendRequest(WebLocalFrame* frame, WebURLRequest&) |
| 5975 { | 5976 { |
| 5976 if (toWebLocalFrameImpl(frame)->frame()->loader().loadType() == FrameLoa
dTypeReloadMainResource) | 5977 if (toWebLocalFrameImpl(frame)->frame()->loader().loadType() == FrameLoa
dTypeReloadMainResource) |
| 5977 m_frameLoadTypeReloadMainResourceSeen = true; | 5978 m_frameLoadTypeReloadMainResourceSeen = true; |
| 5978 } | 5979 } |
| 5979 | 5980 |
| 5980 bool frameLoadTypeReloadMainResourceSeen() const { return m_frameLoadTypeRel
oadMainResourceSeen; } | 5981 bool frameLoadTypeReloadMainResourceSeen() const { return m_frameLoadTypeRel
oadMainResourceSeen; } |
| 5981 | 5982 |
| 5982 private: | 5983 private: |
| 5983 bool m_frameLoadTypeReloadMainResourceSeen; | 5984 bool m_frameLoadTypeReloadMainResourceSeen; |
| 5984 }; | 5985 }; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 5998 EXPECT_TRUE(client.frameLoadTypeReloadMainResourceSeen()); | 5999 EXPECT_TRUE(client.frameLoadTypeReloadMainResourceSeen()); |
| 5999 } | 6000 } |
| 6000 | 6001 |
| 6001 class TestSameDocumentWithImageWebFrameClient : public FrameTestHelpers::TestWeb
FrameClient { | 6002 class TestSameDocumentWithImageWebFrameClient : public FrameTestHelpers::TestWeb
FrameClient { |
| 6002 public: | 6003 public: |
| 6003 TestSameDocumentWithImageWebFrameClient() | 6004 TestSameDocumentWithImageWebFrameClient() |
| 6004 : m_numOfImageRequests(0) | 6005 : m_numOfImageRequests(0) |
| 6005 { | 6006 { |
| 6006 } | 6007 } |
| 6007 | 6008 |
| 6008 virtual void willSendRequest(WebLocalFrame* frame, unsigned, WebURLRequest&
request, const WebURLResponse&) | 6009 virtual void willSendRequest(WebLocalFrame*, WebURLRequest& request) |
| 6009 { | 6010 { |
| 6010 if (request.getRequestContext() == WebURLRequest::RequestContextImage) { | 6011 if (request.getRequestContext() == WebURLRequest::RequestContextImage) { |
| 6011 m_numOfImageRequests++; | 6012 m_numOfImageRequests++; |
| 6012 EXPECT_EQ(WebCachePolicy::UseProtocolCachePolicy, request.getCachePo
licy()); | 6013 EXPECT_EQ(WebCachePolicy::UseProtocolCachePolicy, request.getCachePo
licy()); |
| 6013 } | 6014 } |
| 6014 } | 6015 } |
| 6015 | 6016 |
| 6016 int numOfImageRequests() const { return m_numOfImageRequests; } | 6017 int numOfImageRequests() const { return m_numOfImageRequests; } |
| 6017 | 6018 |
| 6018 private: | 6019 private: |
| (...skipping 2805 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8824 request.setURL(toKURL("javascript:location='" + redirectURL + "'")); | 8825 request.setURL(toKURL("javascript:location='" + redirectURL + "'")); |
| 8825 request.setRequestorOrigin(WebSecurityOrigin::createUnique()); | 8826 request.setRequestorOrigin(WebSecurityOrigin::createUnique()); |
| 8826 helper.webView()->mainFrameImpl()->loadRequest(request); | 8827 helper.webView()->mainFrameImpl()->loadRequest(request); |
| 8827 | 8828 |
| 8828 // Normally, the result of the JS url replaces the existing contents on the | 8829 // Normally, the result of the JS url replaces the existing contents on the |
| 8829 // Document. However, if the JS triggers a navigation, the contents should | 8830 // Document. However, if the JS triggers a navigation, the contents should |
| 8830 // not be replaced. | 8831 // not be replaced. |
| 8831 EXPECT_EQ("", toLocalFrame(helper.webView()->page()->mainFrame())->document(
)->documentElement()->innerText()); | 8832 EXPECT_EQ("", toLocalFrame(helper.webView()->page()->mainFrame())->document(
)->documentElement()->innerText()); |
| 8832 } | 8833 } |
| 8833 | 8834 |
| 8835 class TestResourcePriorityWebFrameClient : public FrameTestHelpers::TestWebFrame
Client { |
| 8836 public: |
| 8837 class ExpectedRequest { |
| 8838 public: |
| 8839 ExpectedRequest(const KURL& url, WebURLRequest::Priority priority) |
| 8840 : url(url) |
| 8841 , priority(priority) |
| 8842 , seen(false) |
| 8843 { |
| 8844 } |
| 8845 |
| 8846 KURL url; |
| 8847 WebURLRequest::Priority priority; |
| 8848 bool seen; |
| 8849 }; |
| 8850 |
| 8851 TestResourcePriorityWebFrameClient() |
| 8852 { |
| 8853 } |
| 8854 |
| 8855 void willSendRequest(WebLocalFrame*, WebURLRequest& request) override |
| 8856 { |
| 8857 ExpectedRequest* expectedRequest = m_expectedRequests.get(request.url())
; |
| 8858 DCHECK(expectedRequest); |
| 8859 EXPECT_EQ(expectedRequest->priority, request.getPriority()); |
| 8860 expectedRequest->seen = true; |
| 8861 } |
| 8862 |
| 8863 void addExpectedRequest(const KURL& url, WebURLRequest::Priority priority) |
| 8864 { |
| 8865 m_expectedRequests.add(url, wrapUnique(new ExpectedRequest(url, priority
))); |
| 8866 } |
| 8867 |
| 8868 void verifyAllRequests() |
| 8869 { |
| 8870 for (const auto& request : m_expectedRequests) |
| 8871 EXPECT_TRUE(request.value->seen); |
| 8872 } |
| 8873 |
| 8874 private: |
| 8875 HashMap<KURL, std::unique_ptr<ExpectedRequest>> m_expectedRequests; |
| 8876 }; |
| 8877 |
| 8878 TEST_F(WebFrameTest, ChangeResourcePriority) |
| 8879 { |
| 8880 TestResourcePriorityWebFrameClient client; |
| 8881 registerMockedHttpURLLoad("promote_img_in_viewport_priority.html"); |
| 8882 registerMockedHttpURLLoad("image_slow.pl"); |
| 8883 registerMockedHttpURLLoad("image_slow_out_of_viewport.pl"); |
| 8884 client.addExpectedRequest(toKURL("http://internal.test/promote_img_in_viewpo
rt_priority.html"), WebURLRequest::PriorityVeryHigh); |
| 8885 client.addExpectedRequest(toKURL("http://internal.test/image_slow.pl"), WebU
RLRequest::PriorityLow); |
| 8886 client.addExpectedRequest(toKURL("http://internal.test/image_slow_out_of_vie
wport.pl"), WebURLRequest::PriorityLow); |
| 8887 |
| 8888 FrameTestHelpers::WebViewHelper helper; |
| 8889 helper.initialize(true, &client); |
| 8890 helper.resize(WebSize(640, 480)); |
| 8891 FrameTestHelpers::loadFrame(helper.webView()->mainFrame(), m_baseURL + "prom
ote_img_in_viewport_priority.html"); |
| 8892 |
| 8893 // Ensure the image in the viewport got promoted after the request was sent. |
| 8894 Resource* image = toWebLocalFrameImpl(helper.webView()->mainFrame())->frame(
)->document()->fetcher()->allResources().get(toKURL("http://internal.test/image_
slow.pl")); |
| 8895 DCHECK(image); |
| 8896 EXPECT_EQ(ResourceLoadPriorityHigh, image->resourceRequest().priority()); |
| 8897 |
| 8898 client.verifyAllRequests(); |
| 8899 } |
| 8900 |
| 8901 TEST_F(WebFrameTest, ScriptPriority) |
| 8902 { |
| 8903 TestResourcePriorityWebFrameClient client; |
| 8904 registerMockedHttpURLLoad("script_priority.html"); |
| 8905 registerMockedHttpURLLoad("priorities/defer.js"); |
| 8906 registerMockedHttpURLLoad("priorities/async.js"); |
| 8907 registerMockedHttpURLLoad("priorities/head.js"); |
| 8908 registerMockedHttpURLLoad("priorities/document-write.js"); |
| 8909 registerMockedHttpURLLoad("priorities/injected.js"); |
| 8910 registerMockedHttpURLLoad("priorities/injected-async.js"); |
| 8911 registerMockedHttpURLLoad("priorities/body.js"); |
| 8912 client.addExpectedRequest(toKURL("http://internal.test/script_priority.html"
), WebURLRequest::PriorityVeryHigh); |
| 8913 client.addExpectedRequest(toKURL("http://internal.test/priorities/defer.js")
, WebURLRequest::PriorityLow); |
| 8914 client.addExpectedRequest(toKURL("http://internal.test/priorities/async.js")
, WebURLRequest::PriorityLow); |
| 8915 client.addExpectedRequest(toKURL("http://internal.test/priorities/head.js"),
WebURLRequest::PriorityHigh); |
| 8916 client.addExpectedRequest(toKURL("http://internal.test/priorities/document-w
rite.js"), WebURLRequest::PriorityHigh); |
| 8917 client.addExpectedRequest(toKURL("http://internal.test/priorities/injected.j
s"), WebURLRequest::PriorityLow); |
| 8918 client.addExpectedRequest(toKURL("http://internal.test/priorities/injected-a
sync.js"), WebURLRequest::PriorityLow); |
| 8919 client.addExpectedRequest(toKURL("http://internal.test/priorities/body.js"),
WebURLRequest::PriorityHigh); |
| 8920 |
| 8921 FrameTestHelpers::WebViewHelper helper; |
| 8922 helper.initializeAndLoad(m_baseURL + "script_priority.html", true, &client); |
| 8923 client.verifyAllRequests(); |
| 8924 } |
| 8925 |
| 8834 } // namespace blink | 8926 } // namespace blink |
| OLD | NEW |