2 * Copyright (C) 2014 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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
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.
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.
33 #include "core/dom/Document.h"
34 #include "core/frame/LocalFrame.h"
35 #include "core/frame/Location.h"
36 #include "core/page/Page.h"
37 #include "platform/weborigin/KURL.h"
38 #include "public/platform/Platform.h"
39 #include "public/platform/WebString.h"
40 #include "public/platform/WebURL.h"
41 #include "public/platform/WebURLRequest.h"
42 #include "public/platform/WebURLResponse.h"
43 #include "public/platform/WebUnitTestSupport.h"
44 #include "public/web/WebDocument.h"
45 #include "public/web/WebFrame.h"
46 #include "public/web/WebView.h"
47 #include "web/tests/FrameTestHelpers.h"
48 #include "web/tests/URLTestHelpers.h"
50 #include <gtest/gtest.h>
52 using namespace blink;
53 using WebCore::Document;
54 using WebCore::LocalFrame;
57 using blink::URLTestHelpers::toKURL;
61 class MHTMLTest : public testing::Test {
70 m_helper.initialize();
73 virtual void TearDown()
75 Platform::current()->unitTestSupport()->unregisterAllMockedURLs();
78 void registerMockedURLLoad(const std::string& url, const WebString& fileName)
80 URLTestHelpers::registerMockedURLLoad(toKURL(url), fileName, WebString::fromUTF8("mhtml/"), WebString::fromUTF8("text/html"));
83 void loadURLInTopFrame(const WebURL& url)
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();
93 Page* page() const { return m_helper.webViewImpl()->page(); }
96 FrameTestHelpers::WebViewHelper m_helper;
99 // Checks that the domain is set to the actual MHTML file, not the URL it was
101 TEST_F(MHTMLTest, CheckDomain)
103 const char kFileURL[] = "file:///simple_test.mht";
105 // Register the mocked frame and load it.
106 WebURL url = toKURL(kFileURL);
107 registerMockedURLLoad(kFileURL, WebString::fromUTF8("simple_test.mht"));
108 loadURLInTopFrame(url);
110 LocalFrame* frame = page()->mainFrame();
112 Document* document = frame->document();
113 ASSERT_TRUE(document);
115 EXPECT_STREQ(kFileURL, frame->domWindow()->location().href().ascii().data());
117 WebCore::SecurityOrigin* origin = document->securityOrigin();
118 EXPECT_STRNE("localhost", origin->domain().ascii().data());