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

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

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

Powered by Google App Engine
This is Rietveld 408576698