| OLD | NEW |
| 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 return true; | 77 return true; |
| 78 } | 78 } |
| 79 | 79 |
| 80 private: | 80 private: |
| 81 std::string m_text; | 81 std::string m_text; |
| 82 size_t m_index; | 82 size_t m_index; |
| 83 }; | 83 }; |
| 84 | 84 |
| 85 class MHTMLTest : public ::testing::Test { | 85 class MHTMLTest : public ::testing::Test { |
| 86 public: | 86 public: |
| 87 MHTMLTest() { | 87 MHTMLTest() { m_filePath = testing::webTestDataPath("mhtml/"); } |
| 88 m_filePath = testing::blinkRootDir(); | |
| 89 m_filePath.append("/Source/web/tests/data/mhtml/"); | |
| 90 } | |
| 91 | 88 |
| 92 protected: | 89 protected: |
| 93 void SetUp() override { m_helper.initialize(); } | 90 void SetUp() override { m_helper.initialize(); } |
| 94 | 91 |
| 95 void TearDown() override { | 92 void TearDown() override { |
| 96 Platform::current()->getURLLoaderMockFactory()->unregisterAllURLs(); | 93 Platform::current()->getURLLoaderMockFactory()->unregisterAllURLs(); |
| 97 WebCache::clear(); | 94 WebCache::clear(); |
| 98 } | 95 } |
| 99 | 96 |
| 100 void registerMockedURLLoad(const std::string& url, | 97 void registerMockedURLLoad(const std::string& url, |
| 101 const WebString& fileName) { | 98 const std::string& fileName) { |
| 102 URLTestHelpers::registerMockedURLLoad( | 99 URLTestHelpers::registerMockedURLLoad( |
| 103 toKURL(url), fileName, WebString::fromUTF8("mhtml/"), | 100 toKURL(url), testing::webTestDataPath("mhtml/" + fileName), |
| 104 WebString::fromUTF8("multipart/related")); | 101 WebString::fromUTF8("multipart/related")); |
| 105 } | 102 } |
| 106 | 103 |
| 107 void loadURLInTopFrame(const WebURL& url) { | 104 void loadURLInTopFrame(const WebURL& url) { |
| 108 FrameTestHelpers::loadFrame(m_helper.webView()->mainFrame(), | 105 FrameTestHelpers::loadFrame(m_helper.webView()->mainFrame(), |
| 109 url.string().utf8().data()); | 106 url.string().utf8().data()); |
| 110 } | 107 } |
| 111 | 108 |
| 112 Page* page() const { return m_helper.webView()->page(); } | 109 Page* page() const { return m_helper.webView()->page(); } |
| 113 | 110 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 FrameTestHelpers::WebViewHelper m_helper; | 180 FrameTestHelpers::WebViewHelper m_helper; |
| 184 }; | 181 }; |
| 185 | 182 |
| 186 // Checks that the domain is set to the actual MHTML file, not the URL it was | 183 // Checks that the domain is set to the actual MHTML file, not the URL it was |
| 187 // generated from. | 184 // generated from. |
| 188 TEST_F(MHTMLTest, CheckDomain) { | 185 TEST_F(MHTMLTest, CheckDomain) { |
| 189 const char kFileURL[] = "file:///simple_test.mht"; | 186 const char kFileURL[] = "file:///simple_test.mht"; |
| 190 | 187 |
| 191 // Register the mocked frame and load it. | 188 // Register the mocked frame and load it. |
| 192 WebURL url = toKURL(kFileURL); | 189 WebURL url = toKURL(kFileURL); |
| 193 registerMockedURLLoad(kFileURL, WebString::fromUTF8("simple_test.mht")); | 190 registerMockedURLLoad(kFileURL, "simple_test.mht"); |
| 194 loadURLInTopFrame(url); | 191 loadURLInTopFrame(url); |
| 195 ASSERT_TRUE(page()); | 192 ASSERT_TRUE(page()); |
| 196 LocalFrame* frame = toLocalFrame(page()->mainFrame()); | 193 LocalFrame* frame = toLocalFrame(page()->mainFrame()); |
| 197 ASSERT_TRUE(frame); | 194 ASSERT_TRUE(frame); |
| 198 Document* document = frame->document(); | 195 Document* document = frame->document(); |
| 199 ASSERT_TRUE(document); | 196 ASSERT_TRUE(document); |
| 200 | 197 |
| 201 EXPECT_STREQ(kFileURL, frame->domWindow()->location()->href().ascii().data()); | 198 EXPECT_STREQ(kFileURL, frame->domWindow()->location()->href().ascii().data()); |
| 202 | 199 |
| 203 SecurityOrigin* origin = document->getSecurityOrigin(); | 200 SecurityOrigin* origin = document->getSecurityOrigin(); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 EXPECT_EQ(nullptr, MHTMLArchive::create(specialSchemeURL, data.get())); | 260 EXPECT_EQ(nullptr, MHTMLArchive::create(specialSchemeURL, data.get())); |
| 264 SchemeRegistry::registerURLSchemeAsLocal("fooscheme"); | 261 SchemeRegistry::registerURLSchemeAsLocal("fooscheme"); |
| 265 EXPECT_NE(nullptr, MHTMLArchive::create(specialSchemeURL, data.get())); | 262 EXPECT_NE(nullptr, MHTMLArchive::create(specialSchemeURL, data.get())); |
| 266 } | 263 } |
| 267 | 264 |
| 268 // Checks that full sandboxing protection has been turned on. | 265 // Checks that full sandboxing protection has been turned on. |
| 269 TEST_F(MHTMLTest, EnforceSandboxFlags) { | 266 TEST_F(MHTMLTest, EnforceSandboxFlags) { |
| 270 const char kURL[] = "http://www.example.com"; | 267 const char kURL[] = "http://www.example.com"; |
| 271 | 268 |
| 272 // Register the mocked frame and load it. | 269 // Register the mocked frame and load it. |
| 273 registerMockedURLLoad(kURL, WebString::fromUTF8("simple_test.mht")); | 270 registerMockedURLLoad(kURL, "simple_test.mht"); |
| 274 loadURLInTopFrame(toKURL(kURL)); | 271 loadURLInTopFrame(toKURL(kURL)); |
| 275 ASSERT_TRUE(page()); | 272 ASSERT_TRUE(page()); |
| 276 LocalFrame* frame = toLocalFrame(page()->mainFrame()); | 273 LocalFrame* frame = toLocalFrame(page()->mainFrame()); |
| 277 ASSERT_TRUE(frame); | 274 ASSERT_TRUE(frame); |
| 278 Document* document = frame->document(); | 275 Document* document = frame->document(); |
| 279 ASSERT_TRUE(document); | 276 ASSERT_TRUE(document); |
| 280 | 277 |
| 281 // Full sandboxing should be turned on. | 278 // Full sandboxing should be turned on. |
| 282 EXPECT_TRUE(document->isSandboxed(SandboxAll)); | 279 EXPECT_TRUE(document->isSandboxed(SandboxAll)); |
| 283 | 280 |
| 284 // MHTML document should be loaded into unique origin. | 281 // MHTML document should be loaded into unique origin. |
| 285 EXPECT_TRUE(document->getSecurityOrigin()->isUnique()); | 282 EXPECT_TRUE(document->getSecurityOrigin()->isUnique()); |
| 286 // Script execution should be disabled. | 283 // Script execution should be disabled. |
| 287 EXPECT_FALSE(frame->script().canExecuteScripts(NotAboutToExecuteScript)); | 284 EXPECT_FALSE(frame->script().canExecuteScripts(NotAboutToExecuteScript)); |
| 288 } | 285 } |
| 289 | 286 |
| 290 } // namespace blink | 287 } // namespace blink |
| OLD | NEW |