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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 #include "core/css/resolver/ViewportStyleResolver.h" | 42 #include "core/css/resolver/ViewportStyleResolver.h" |
43 #include "core/dom/DocumentMarkerController.h" | 43 #include "core/dom/DocumentMarkerController.h" |
44 #include "core/dom/Fullscreen.h" | 44 #include "core/dom/Fullscreen.h" |
45 #include "core/dom/NodeRenderStyle.h" | 45 #include "core/dom/NodeRenderStyle.h" |
46 #include "core/dom/Range.h" | 46 #include "core/dom/Range.h" |
47 #include "core/editing/Editor.h" | 47 #include "core/editing/Editor.h" |
48 #include "core/editing/FrameSelection.h" | 48 #include "core/editing/FrameSelection.h" |
49 #include "core/editing/SpellChecker.h" | 49 #include "core/editing/SpellChecker.h" |
50 #include "core/editing/VisiblePosition.h" | 50 #include "core/editing/VisiblePosition.h" |
51 #include "core/events/MouseEvent.h" | 51 #include "core/events/MouseEvent.h" |
| 52 #include "core/fetch/FetchRequest.h" |
52 #include "core/fetch/MemoryCache.h" | 53 #include "core/fetch/MemoryCache.h" |
| 54 #include "core/fetch/ResourceFetcher.h" |
53 #include "core/frame/FrameHost.h" | 55 #include "core/frame/FrameHost.h" |
54 #include "core/frame/FrameView.h" | 56 #include "core/frame/FrameView.h" |
55 #include "core/frame/LocalFrame.h" | 57 #include "core/frame/LocalFrame.h" |
56 #include "core/frame/PinchViewport.h" | 58 #include "core/frame/PinchViewport.h" |
57 #include "core/frame/Settings.h" | 59 #include "core/frame/Settings.h" |
58 #include "core/html/HTMLDocument.h" | 60 #include "core/html/HTMLDocument.h" |
59 #include "core/html/HTMLFormElement.h" | 61 #include "core/html/HTMLFormElement.h" |
60 #include "core/loader/DocumentThreadableLoader.h" | 62 #include "core/loader/DocumentThreadableLoader.h" |
61 #include "core/loader/DocumentThreadableLoaderClient.h" | 63 #include "core/loader/DocumentThreadableLoaderClient.h" |
62 #include "core/loader/FrameLoadRequest.h" | 64 #include "core/loader/FrameLoadRequest.h" |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 | 147 |
146 class FakeCompositingWebViewClient : public FrameTestHelpers::TestWebViewClient
{ | 148 class FakeCompositingWebViewClient : public FrameTestHelpers::TestWebViewClient
{ |
147 public: | 149 public: |
148 virtual bool enterFullScreen() OVERRIDE { return true; } | 150 virtual bool enterFullScreen() OVERRIDE { return true; } |
149 }; | 151 }; |
150 | 152 |
151 class WebFrameTest : public testing::Test { | 153 class WebFrameTest : public testing::Test { |
152 protected: | 154 protected: |
153 WebFrameTest() | 155 WebFrameTest() |
154 : m_baseURL("http://www.test.com/") | 156 : m_baseURL("http://www.test.com/") |
| 157 , m_notBaseURL("http://www.nottest.com/") |
155 , m_chromeURL("chrome://") | 158 , m_chromeURL("chrome://") |
156 { | 159 { |
157 } | 160 } |
158 | 161 |
159 virtual ~WebFrameTest() | 162 virtual ~WebFrameTest() |
160 { | 163 { |
161 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); | 164 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); |
162 } | 165 } |
163 | 166 |
164 void registerMockedHttpURLLoad(const std::string& fileName) | 167 void registerMockedHttpURLLoad(const std::string& fileName) |
165 { | 168 { |
166 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseU
RL.c_str()), WebString::fromUTF8(fileName.c_str())); | 169 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseU
RL.c_str()), WebString::fromUTF8(fileName.c_str())); |
167 } | 170 } |
168 | 171 |
169 void registerMockedChromeURLLoad(const std::string& fileName) | 172 void registerMockedChromeURLLoad(const std::string& fileName) |
170 { | 173 { |
171 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_chrom
eURL.c_str()), WebString::fromUTF8(fileName.c_str())); | 174 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_chrom
eURL.c_str()), WebString::fromUTF8(fileName.c_str())); |
172 } | 175 } |
173 | 176 |
| 177 |
| 178 void registerMockedHttpURLLoadWithCSP(const std::string& fileName, const std
::string& csp, bool reportOnly = false) |
| 179 { |
| 180 WebURLResponse response; |
| 181 response.initialize(); |
| 182 response.setMIMEType("text/html"); |
| 183 response.addHTTPHeaderField(reportOnly ? WebString("Content-Security-Pol
icy-Report-Only") : WebString("Content-Security-Policy"), WebString::fromUTF8(cs
p)); |
| 184 std::string fullString = m_baseURL + fileName; |
| 185 URLTestHelpers::registerMockedURLLoadWithCustomResponse(toKURL(fullStrin
g.c_str()), WebString::fromUTF8(fileName.c_str()), WebString::fromUTF8(""), resp
onse); |
| 186 } |
| 187 |
174 void applyViewportStyleOverride(FrameTestHelpers::WebViewHelper* webViewHelp
er) | 188 void applyViewportStyleOverride(FrameTestHelpers::WebViewHelper* webViewHelp
er) |
175 { | 189 { |
176 RefPtrWillBeRawPtr<StyleSheetContents> styleSheet = StyleSheetContents::
create(CSSParserContext(UASheetMode, 0)); | 190 RefPtrWillBeRawPtr<StyleSheetContents> styleSheet = StyleSheetContents::
create(CSSParserContext(UASheetMode, 0)); |
177 styleSheet->parseString(String(blink::viewportAndroidCss, sizeof(blink::
viewportAndroidCss))); | 191 styleSheet->parseString(String(blink::viewportAndroidCss, sizeof(blink::
viewportAndroidCss))); |
178 OwnPtrWillBeRawPtr<RuleSet> ruleSet = RuleSet::create(); | 192 OwnPtrWillBeRawPtr<RuleSet> ruleSet = RuleSet::create(); |
179 ruleSet->addRulesFromSheet(styleSheet.get(), MediaQueryEvaluator("screen
")); | 193 ruleSet->addRulesFromSheet(styleSheet.get(), MediaQueryEvaluator("screen
")); |
180 | 194 |
181 Document* document = toLocalFrame(webViewHelper->webViewImpl()->page()->
mainFrame())->document(); | 195 Document* document = toLocalFrame(webViewHelper->webViewImpl()->page()->
mainFrame())->document(); |
182 document->ensureStyleResolver().viewportStyleResolver()->collectViewport
Rules(ruleSet.get(), ViewportStyleResolver::UserAgentOrigin); | 196 document->ensureStyleResolver().viewportStyleResolver()->collectViewport
Rules(ruleSet.get(), ViewportStyleResolver::UserAgentOrigin); |
183 document->ensureStyleResolver().viewportStyleResolver()->resolve(); | 197 document->ensureStyleResolver().viewportStyleResolver()->resolve(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 webViewHelper->initializeAndLoad(m_baseURL + "nodeimage.html"); | 230 webViewHelper->initializeAndLoad(m_baseURL + "nodeimage.html"); |
217 webViewHelper->webView()->resize(WebSize(640, 480)); | 231 webViewHelper->webView()->resize(WebSize(640, 480)); |
218 webViewHelper->webView()->layout(); | 232 webViewHelper->webView()->layout(); |
219 RefPtrWillBeRawPtr<LocalFrame> frame = toLocalFrame(webViewHelper->webVi
ewImpl()->page()->mainFrame()); | 233 RefPtrWillBeRawPtr<LocalFrame> frame = toLocalFrame(webViewHelper->webVi
ewImpl()->page()->mainFrame()); |
220 ASSERT(frame); | 234 ASSERT(frame); |
221 Element* element = frame->document()->getElementById(testcase.c_str()); | 235 Element* element = frame->document()->getElementById(testcase.c_str()); |
222 return frame->nodeImage(*element); | 236 return frame->nodeImage(*element); |
223 } | 237 } |
224 | 238 |
225 std::string m_baseURL; | 239 std::string m_baseURL; |
| 240 std::string m_notBaseURL; |
226 std::string m_chromeURL; | 241 std::string m_chromeURL; |
227 }; | 242 }; |
228 | 243 |
229 class UseMockScrollbarSettings { | 244 class UseMockScrollbarSettings { |
230 public: | 245 public: |
231 UseMockScrollbarSettings() | 246 UseMockScrollbarSettings() |
232 { | 247 { |
233 Settings::setMockScrollbarsEnabled(true); | 248 Settings::setMockScrollbarsEnabled(true); |
234 RuntimeEnabledFeatures::setOverlayScrollbarsEnabled(true); | 249 RuntimeEnabledFeatures::setOverlayScrollbarsEnabled(true); |
235 EXPECT_TRUE(ScrollbarTheme::theme()->usesOverlayScrollbars()); | 250 EXPECT_TRUE(ScrollbarTheme::theme()->usesOverlayScrollbars()); |
(...skipping 5972 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6208 { | 6223 { |
6209 registerMockedHttpURLLoad("link-manifest-change.html"); | 6224 registerMockedHttpURLLoad("link-manifest-change.html"); |
6210 | 6225 |
6211 ManifestChangeWebFrameClient webFrameClient; | 6226 ManifestChangeWebFrameClient webFrameClient; |
6212 FrameTestHelpers::WebViewHelper webViewHelper; | 6227 FrameTestHelpers::WebViewHelper webViewHelper; |
6213 webViewHelper.initializeAndLoad(m_baseURL + "link-manifest-change.html", tru
e, &webFrameClient); | 6228 webViewHelper.initializeAndLoad(m_baseURL + "link-manifest-change.html", tru
e, &webFrameClient); |
6214 | 6229 |
6215 EXPECT_EQ(14, webFrameClient.manifestChangeCount()); | 6230 EXPECT_EQ(14, webFrameClient.manifestChangeCount()); |
6216 } | 6231 } |
6217 | 6232 |
| 6233 static ResourcePtr<Resource> fetchManifest(Document* document, const KURL& url) |
| 6234 { |
| 6235 FetchRequest fetchRequest = FetchRequest(ResourceRequest(url), FetchInitiato
rInfo()); |
| 6236 fetchRequest.mutableResourceRequest().setRequestContext(WebURLRequest::Reque
stContextManifest); |
| 6237 |
| 6238 return document->fetcher()->fetchSynchronously(fetchRequest); |
| 6239 } |
| 6240 |
| 6241 TEST_F(WebFrameTest, ManifestFetch) |
| 6242 { |
| 6243 registerMockedHttpURLLoad("foo.html"); |
| 6244 registerMockedHttpURLLoad("link-manifest-fetch.json"); |
| 6245 |
| 6246 FrameTestHelpers::WebViewHelper webViewHelper; |
| 6247 webViewHelper.initializeAndLoad(m_baseURL + "foo.html"); |
| 6248 Document* document = toWebLocalFrameImpl(webViewHelper.webViewImpl()->mainFr
ame())->frame()->document(); |
| 6249 |
| 6250 ResourcePtr<Resource> resource = fetchManifest(document, toKURL(m_baseURL +
"link-manifest-fetch.json")); |
| 6251 |
| 6252 EXPECT_TRUE(resource->isLoaded()); |
| 6253 } |
| 6254 |
| 6255 TEST_F(WebFrameTest, ManifestCSPFetchAllow) |
| 6256 { |
| 6257 URLTestHelpers::registerMockedURLLoad(toKURL(m_notBaseURL + "link-manifest-f
etch.json"), "link-manifest-fetch.json"); |
| 6258 registerMockedHttpURLLoadWithCSP("foo.html", "manifest-src *"); |
| 6259 |
| 6260 FrameTestHelpers::WebViewHelper webViewHelper; |
| 6261 webViewHelper.initializeAndLoad(m_baseURL + "foo.html"); |
| 6262 Document* document = toWebLocalFrameImpl(webViewHelper.webViewImpl()->mainFr
ame())->frame()->document(); |
| 6263 |
| 6264 ResourcePtr<Resource> resource = fetchManifest(document, toKURL(m_notBaseURL
+ "link-manifest-fetch.json")); |
| 6265 |
| 6266 EXPECT_TRUE(resource->isLoaded()); |
| 6267 } |
| 6268 |
| 6269 TEST_F(WebFrameTest, ManifestCSPFetchSelf) |
| 6270 { |
| 6271 URLTestHelpers::registerMockedURLLoad(toKURL(m_notBaseURL + "link-manifest-f
etch.json"), "link-manifest-fetch.json"); |
| 6272 registerMockedHttpURLLoadWithCSP("foo.html", "manifest-src 'self'"); |
| 6273 |
| 6274 FrameTestHelpers::WebViewHelper webViewHelper; |
| 6275 webViewHelper.initializeAndLoad(m_baseURL + "foo.html"); |
| 6276 Document* document = toWebLocalFrameImpl(webViewHelper.webViewImpl()->mainFr
ame())->frame()->document(); |
| 6277 |
| 6278 ResourcePtr<Resource> resource = fetchManifest(document, toKURL(m_notBaseURL
+ "link-manifest-fetch.json")); |
| 6279 |
| 6280 EXPECT_EQ(0, resource.get()); // Fetching resource wasn't allowed. |
| 6281 } |
| 6282 |
| 6283 TEST_F(WebFrameTest, ManifestCSPFetchSelfReportOnly) |
| 6284 { |
| 6285 URLTestHelpers::registerMockedURLLoad(toKURL(m_notBaseURL + "link-manifest-f
etch.json"), "link-manifest-fetch.json"); |
| 6286 registerMockedHttpURLLoadWithCSP("foo.html", "manifest-src 'self'", /* repor
t only */ true); |
| 6287 |
| 6288 FrameTestHelpers::WebViewHelper webViewHelper; |
| 6289 webViewHelper.initializeAndLoad(m_baseURL + "foo.html"); |
| 6290 Document* document = toWebLocalFrameImpl(webViewHelper.webViewImpl()->mainFr
ame())->frame()->document(); |
| 6291 |
| 6292 ResourcePtr<Resource> resource = fetchManifest(document, toKURL(m_notBaseURL
+ "link-manifest-fetch.json")); |
| 6293 |
| 6294 EXPECT_TRUE(resource->isLoaded()); |
| 6295 } |
| 6296 |
| 6297 |
6218 TEST_F(WebFrameTest, ReloadBypassingCache) | 6298 TEST_F(WebFrameTest, ReloadBypassingCache) |
6219 { | 6299 { |
6220 // Check that a reload ignoring cache on a frame will result in the cache | 6300 // Check that a reload ignoring cache on a frame will result in the cache |
6221 // policy of the request being set to ReloadBypassingCache. | 6301 // policy of the request being set to ReloadBypassingCache. |
6222 registerMockedHttpURLLoad("foo.html"); | 6302 registerMockedHttpURLLoad("foo.html"); |
6223 FrameTestHelpers::WebViewHelper webViewHelper; | 6303 FrameTestHelpers::WebViewHelper webViewHelper; |
6224 webViewHelper.initializeAndLoad(m_baseURL + "foo.html", true); | 6304 webViewHelper.initializeAndLoad(m_baseURL + "foo.html", true); |
6225 WebFrame* frame = webViewHelper.webView()->mainFrame(); | 6305 WebFrame* frame = webViewHelper.webView()->mainFrame(); |
6226 FrameTestHelpers::reloadFrameIgnoringCache(frame); | 6306 FrameTestHelpers::reloadFrameIgnoringCache(frame); |
6227 EXPECT_EQ(WebURLRequest::ReloadBypassingCache, frame->dataSource()->request(
).cachePolicy()); | 6307 EXPECT_EQ(WebURLRequest::ReloadBypassingCache, frame->dataSource()->request(
).cachePolicy()); |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6629 EXPECT_EQ(1u, frameClient.navigationalDataReceivedCount()); | 6709 EXPECT_EQ(1u, frameClient.navigationalDataReceivedCount()); |
6630 | 6710 |
6631 // Neither should a page reload. | 6711 // Neither should a page reload. |
6632 localFrame->reload(); | 6712 localFrame->reload(); |
6633 EXPECT_EQ(4u, frameClient.provisionalLoadCount()); | 6713 EXPECT_EQ(4u, frameClient.provisionalLoadCount()); |
6634 EXPECT_FALSE(frameClient.wasLastProvisionalLoadATransition()); | 6714 EXPECT_FALSE(frameClient.wasLastProvisionalLoadATransition()); |
6635 EXPECT_EQ(1u, frameClient.navigationalDataReceivedCount()); | 6715 EXPECT_EQ(1u, frameClient.navigationalDataReceivedCount()); |
6636 } | 6716 } |
6637 | 6717 |
6638 } // namespace | 6718 } // namespace |
OLD | NEW |