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

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

Issue 2912213002: Support serializing shadow DOM to MHTML (Closed)
Patch Set: Strip anoter shadow attribute Created 3 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) 2014 Google Inc. All rights reserved. 2 * Copyright (C) 2014 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 11 matching lines...) Expand all
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "core/dom/Document.h" 31 #include "core/dom/Document.h"
32 #include "core/dom/Element.h"
33 #include "core/dom/shadow/ElementShadow.h"
32 #include "core/frame/FrameTestHelpers.h" 34 #include "core/frame/FrameTestHelpers.h"
33 #include "core/frame/LocalFrame.h" 35 #include "core/frame/LocalFrame.h"
34 #include "core/frame/Location.h" 36 #include "core/frame/Location.h"
35 #include "core/page/Page.h" 37 #include "core/page/Page.h"
36 #include "platform/SerializedResource.h" 38 #include "platform/SerializedResource.h"
37 #include "platform/SharedBuffer.h" 39 #include "platform/SharedBuffer.h"
38 #include "platform/mhtml/MHTMLArchive.h" 40 #include "platform/mhtml/MHTMLArchive.h"
39 #include "platform/mhtml/MHTMLParser.h" 41 #include "platform/mhtml/MHTMLParser.h"
40 #include "platform/testing/URLTestHelpers.h" 42 #include "platform/testing/URLTestHelpers.h"
41 #include "platform/testing/UnitTestHelpers.h" 43 #include "platform/testing/UnitTestHelpers.h"
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 EXPECT_EQ(nullptr, MHTMLArchive::Create(special_scheme_url, data.Get())); 272 EXPECT_EQ(nullptr, MHTMLArchive::Create(special_scheme_url, data.Get()));
271 SchemeRegistry::RegisterURLSchemeAsLocal("fooscheme"); 273 SchemeRegistry::RegisterURLSchemeAsLocal("fooscheme");
272 EXPECT_NE(nullptr, MHTMLArchive::Create(special_scheme_url, data.Get())); 274 EXPECT_NE(nullptr, MHTMLArchive::Create(special_scheme_url, data.Get()));
273 } 275 }
274 276
275 // Checks that full sandboxing protection has been turned on. 277 // Checks that full sandboxing protection has been turned on.
276 TEST_F(MHTMLTest, EnforceSandboxFlags) { 278 TEST_F(MHTMLTest, EnforceSandboxFlags) {
277 const char kURL[] = "http://www.example.com"; 279 const char kURL[] = "http://www.example.com";
278 280
279 // Register the mocked frame and load it. 281 // Register the mocked frame and load it.
280 RegisterMockedURLLoad(kURL, "simple_test.mht"); 282 RegisterMockedURLLoad(kURL, "page_with_javascript.mht");
281 LoadURLInTopFrame(ToKURL(kURL)); 283 LoadURLInTopFrame(ToKURL(kURL));
282 ASSERT_TRUE(GetPage()); 284 ASSERT_TRUE(GetPage());
283 LocalFrame* frame = ToLocalFrame(GetPage()->MainFrame()); 285 LocalFrame* frame = ToLocalFrame(GetPage()->MainFrame());
284 ASSERT_TRUE(frame); 286 ASSERT_TRUE(frame);
285 Document* document = frame->GetDocument(); 287 Document* document = frame->GetDocument();
286 ASSERT_TRUE(document); 288 ASSERT_TRUE(document);
287 289
288 // Full sandboxing with the exception to new top-level windows should be 290 // Full sandboxing with the exception to new top-level windows should be
289 // turned on. 291 // turned on.
290 EXPECT_EQ(kSandboxAll & ~(kSandboxPopups | 292 EXPECT_EQ(kSandboxAll & ~(kSandboxPopups |
291 kSandboxPropagatesToAuxiliaryBrowsingContexts), 293 kSandboxPropagatesToAuxiliaryBrowsingContexts),
292 document->GetSandboxFlags()); 294 document->GetSandboxFlags());
293 295
294 // MHTML document should be loaded into unique origin. 296 // MHTML document should be loaded into unique origin.
295 EXPECT_TRUE(document->GetSecurityOrigin()->IsUnique()); 297 EXPECT_TRUE(document->GetSecurityOrigin()->IsUnique());
296 // Script execution should be disabled. 298 // Script execution should be disabled.
297 EXPECT_FALSE(document->CanExecuteScripts(kNotAboutToExecuteScript)); 299 EXPECT_FALSE(document->CanExecuteScripts(kNotAboutToExecuteScript));
300
301 // The element to be created by the script is not there.
302 EXPECT_FALSE(document->getElementById("mySpan"));
303 }
304
305 TEST_F(MHTMLTest, ShadowDom) {
306 const char kURL[] = "http://www.example.com";
307
308 // Register the mocked frame and load it.
309 RegisterMockedURLLoad(kURL, "shadow.mht");
310 LoadURLInTopFrame(ToKURL(kURL));
311 ASSERT_TRUE(GetPage());
312 LocalFrame* frame = ToLocalFrame(GetPage()->MainFrame());
313 ASSERT_TRUE(frame);
314 Document* document = frame->GetDocument();
315 ASSERT_TRUE(document);
316
317 EXPECT_TRUE(IsShadowHost(document->getElementById("h1")));
318 EXPECT_TRUE(IsShadowHost(document->getElementById("h2")));
319 // The nested shadow DOM tree is created.
320 EXPECT_TRUE(IsShadowHost(document->getElementById("h2")
321 ->Shadow()
322 ->OldestShadowRoot()
323 .getElementById("h3")));
324
325 EXPECT_TRUE(IsShadowHost(document->getElementById("h4")));
326 // The static element in the shadow dom template is found.
327 EXPECT_TRUE(document->getElementById("h4")
328 ->Shadow()
329 ->OldestShadowRoot()
330 .getElementById("s1"));
331 // The element to be created by the script in the shadow dom template is
332 // not found because the script is blocked.
333 EXPECT_FALSE(document->getElementById("h4")
334 ->Shadow()
335 ->OldestShadowRoot()
336 .getElementById("s2"));
298 } 337 }
299 338
300 } // namespace blink 339 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698