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), |
| 101 testing::webTestDataPath(WebString::fromUTF8("mhtml/" + fileName)), |
104 WebString::fromUTF8("multipart/related")); | 102 WebString::fromUTF8("multipart/related")); |
105 } | 103 } |
106 | 104 |
107 void loadURLInTopFrame(const WebURL& url) { | 105 void loadURLInTopFrame(const WebURL& url) { |
108 FrameTestHelpers::loadFrame(m_helper.webView()->mainFrame(), | 106 FrameTestHelpers::loadFrame(m_helper.webView()->mainFrame(), |
109 url.string().utf8().data()); | 107 url.string().utf8().data()); |
110 } | 108 } |
111 | 109 |
112 Page* page() const { return m_helper.webView()->page(); } | 110 Page* page() const { return m_helper.webView()->page(); } |
113 | 111 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 FrameTestHelpers::WebViewHelper m_helper; | 181 FrameTestHelpers::WebViewHelper m_helper; |
184 }; | 182 }; |
185 | 183 |
186 // Checks that the domain is set to the actual MHTML file, not the URL it was | 184 // Checks that the domain is set to the actual MHTML file, not the URL it was |
187 // generated from. | 185 // generated from. |
188 TEST_F(MHTMLTest, CheckDomain) { | 186 TEST_F(MHTMLTest, CheckDomain) { |
189 const char kFileURL[] = "file:///simple_test.mht"; | 187 const char kFileURL[] = "file:///simple_test.mht"; |
190 | 188 |
191 // Register the mocked frame and load it. | 189 // Register the mocked frame and load it. |
192 WebURL url = toKURL(kFileURL); | 190 WebURL url = toKURL(kFileURL); |
193 registerMockedURLLoad(kFileURL, WebString::fromUTF8("simple_test.mht")); | 191 registerMockedURLLoad(kFileURL, "simple_test.mht"); |
194 loadURLInTopFrame(url); | 192 loadURLInTopFrame(url); |
195 ASSERT_TRUE(page()); | 193 ASSERT_TRUE(page()); |
196 LocalFrame* frame = toLocalFrame(page()->mainFrame()); | 194 LocalFrame* frame = toLocalFrame(page()->mainFrame()); |
197 ASSERT_TRUE(frame); | 195 ASSERT_TRUE(frame); |
198 Document* document = frame->document(); | 196 Document* document = frame->document(); |
199 ASSERT_TRUE(document); | 197 ASSERT_TRUE(document); |
200 | 198 |
201 EXPECT_STREQ(kFileURL, frame->domWindow()->location()->href().ascii().data()); | 199 EXPECT_STREQ(kFileURL, frame->domWindow()->location()->href().ascii().data()); |
202 | 200 |
203 SecurityOrigin* origin = document->getSecurityOrigin(); | 201 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())); | 261 EXPECT_EQ(nullptr, MHTMLArchive::create(specialSchemeURL, data.get())); |
264 SchemeRegistry::registerURLSchemeAsLocal("fooscheme"); | 262 SchemeRegistry::registerURLSchemeAsLocal("fooscheme"); |
265 EXPECT_NE(nullptr, MHTMLArchive::create(specialSchemeURL, data.get())); | 263 EXPECT_NE(nullptr, MHTMLArchive::create(specialSchemeURL, data.get())); |
266 } | 264 } |
267 | 265 |
268 // Checks that full sandboxing protection has been turned on. | 266 // Checks that full sandboxing protection has been turned on. |
269 TEST_F(MHTMLTest, EnforceSandboxFlags) { | 267 TEST_F(MHTMLTest, EnforceSandboxFlags) { |
270 const char kURL[] = "http://www.example.com"; | 268 const char kURL[] = "http://www.example.com"; |
271 | 269 |
272 // Register the mocked frame and load it. | 270 // Register the mocked frame and load it. |
273 registerMockedURLLoad(kURL, WebString::fromUTF8("simple_test.mht")); | 271 registerMockedURLLoad(kURL, "simple_test.mht"); |
274 loadURLInTopFrame(toKURL(kURL)); | 272 loadURLInTopFrame(toKURL(kURL)); |
275 ASSERT_TRUE(page()); | 273 ASSERT_TRUE(page()); |
276 LocalFrame* frame = toLocalFrame(page()->mainFrame()); | 274 LocalFrame* frame = toLocalFrame(page()->mainFrame()); |
277 ASSERT_TRUE(frame); | 275 ASSERT_TRUE(frame); |
278 Document* document = frame->document(); | 276 Document* document = frame->document(); |
279 ASSERT_TRUE(document); | 277 ASSERT_TRUE(document); |
280 | 278 |
281 // Full sandboxing should be turned on. | 279 // Full sandboxing should be turned on. |
282 EXPECT_TRUE(document->isSandboxed(SandboxAll)); | 280 EXPECT_TRUE(document->isSandboxed(SandboxAll)); |
283 | 281 |
284 // MHTML document should be loaded into unique origin. | 282 // MHTML document should be loaded into unique origin. |
285 EXPECT_TRUE(document->getSecurityOrigin()->isUnique()); | 283 EXPECT_TRUE(document->getSecurityOrigin()->isUnique()); |
286 // Script execution should be disabled. | 284 // Script execution should be disabled. |
287 EXPECT_FALSE(frame->script().canExecuteScripts(NotAboutToExecuteScript)); | 285 EXPECT_FALSE(frame->script().canExecuteScripts(NotAboutToExecuteScript)); |
288 } | 286 } |
289 | 287 |
290 } // namespace blink | 288 } // namespace blink |
OLD | NEW |