OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (C) 2014 Google Inc. All rights reserved. |
| 3 * |
| 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are |
| 6 * met: |
| 7 * |
| 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above |
| 11 * copyright notice, this list of conditions and the following disclaimer |
| 12 * in the documentation and/or other materials provided with the |
| 13 * distribution. |
| 14 * * Neither the name of Google Inc. nor the names of its |
| 15 * contributors may be used to endorse or promote products derived from |
| 16 * this software without specific prior written permission. |
| 17 * |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 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. |
| 29 */ |
| 30 |
| 31 #include "config.h" |
| 32 |
| 33 #include "FrameTestHelpers.h" |
| 34 #include "URLTestHelpers.h" |
| 35 #include "WebFrame.h" |
| 36 #include "WebView.h" |
| 37 #include "core/dom/Document.h" |
| 38 #include "core/frame/LocalFrame.h" |
| 39 #include "core/frame/Location.h" |
| 40 #include "core/page/Page.h" |
| 41 #include "platform/weborigin/KURL.h" |
| 42 #include "public/platform/Platform.h" |
| 43 #include "public/platform/WebString.h" |
| 44 #include "public/platform/WebURL.h" |
| 45 #include "public/platform/WebURLRequest.h" |
| 46 #include "public/platform/WebURLResponse.h" |
| 47 #include "public/platform/WebUnitTestSupport.h" |
| 48 #include "public/web/WebDocument.h" |
| 49 |
| 50 #include <gtest/gtest.h> |
| 51 |
| 52 using namespace blink; |
| 53 using WebCore::Document; |
| 54 using WebCore::LocalFrame; |
| 55 using WebCore::Page; |
| 56 using WebCore::KURL; |
| 57 using blink::URLTestHelpers::toKURL; |
| 58 |
| 59 namespace { |
| 60 |
| 61 class MHTMLTest : public testing::Test { |
| 62 public: |
| 63 MHTMLTest() |
| 64 { |
| 65 } |
| 66 |
| 67 protected: |
| 68 virtual void SetUp() |
| 69 { |
| 70 m_helper.initialize(); |
| 71 } |
| 72 |
| 73 virtual void TearDown() |
| 74 { |
| 75 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); |
| 76 } |
| 77 |
| 78 void registerMockedURLLoad(const std::string& url, const WebString& fileName
) |
| 79 { |
| 80 URLTestHelpers::registerMockedURLLoad(toKURL(url), fileName, WebString::
fromUTF8("mhtml/"), WebString::fromUTF8("text/html")); |
| 81 } |
| 82 |
| 83 void loadURLInTopFrame(const WebURL& url) |
| 84 { |
| 85 WebURLRequest urlRequest; |
| 86 urlRequest.initialize(); |
| 87 urlRequest.setURL(url); |
| 88 m_helper.webView()->mainFrame()->loadRequest(urlRequest); |
| 89 // Make sure any pending request get served. |
| 90 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(
); |
| 91 } |
| 92 |
| 93 Page* page() const { return m_helper.webViewImpl()->page(); } |
| 94 |
| 95 private: |
| 96 FrameTestHelpers::WebViewHelper m_helper; |
| 97 }; |
| 98 |
| 99 // Checks that the domain is set to the actual MHTML file, not the URL it was |
| 100 // generated from. |
| 101 TEST_F(MHTMLTest, CheckDomain) |
| 102 { |
| 103 const char kFileURL[] = "file:///simple_test.mht"; |
| 104 |
| 105 // Register the mocked frame and load it. |
| 106 WebURL url = toKURL(kFileURL); |
| 107 registerMockedURLLoad(kFileURL, WebString::fromUTF8("simple_test.mht")); |
| 108 loadURLInTopFrame(url); |
| 109 ASSERT_TRUE(page()); |
| 110 LocalFrame* frame = page()->mainFrame(); |
| 111 ASSERT_TRUE(frame); |
| 112 Document* document = frame->document(); |
| 113 ASSERT_TRUE(document); |
| 114 |
| 115 EXPECT_STREQ(kFileURL, frame->domWindow()->location().href().ascii().data())
; |
| 116 |
| 117 WebCore::SecurityOrigin* origin = document->securityOrigin(); |
| 118 EXPECT_STRNE("localhost", origin->domain().ascii().data()); |
| 119 } |
| 120 |
| 121 } |
OLD | NEW |