• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "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"
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:
MHTMLTest()63     MHTMLTest()
64     {
65     }
66 
67 protected:
SetUp()68     virtual void SetUp()
69     {
70         m_helper.initialize();
71     }
72 
TearDown()73     virtual void TearDown()
74     {
75         Platform::current()->unitTestSupport()->unregisterAllMockedURLs();
76     }
77 
registerMockedURLLoad(const std::string & url,const WebString & fileName)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 
loadURLInTopFrame(const WebURL & url)83     void loadURLInTopFrame(const WebURL& url)
84     {
85         FrameTestHelpers::loadFrame(m_helper.webView()->mainFrame(), url.string().utf8().data());
86     }
87 
page() const88     Page* page() const { return m_helper.webViewImpl()->page(); }
89 
90 private:
91     FrameTestHelpers::WebViewHelper m_helper;
92 };
93 
94 // Checks that the domain is set to the actual MHTML file, not the URL it was
95 // generated from.
TEST_F(MHTMLTest,CheckDomain)96 TEST_F(MHTMLTest, CheckDomain)
97 {
98     const char kFileURL[] = "file:///simple_test.mht";
99 
100     // Register the mocked frame and load it.
101     WebURL url = toKURL(kFileURL);
102     registerMockedURLLoad(kFileURL, WebString::fromUTF8("simple_test.mht"));
103     loadURLInTopFrame(url);
104     ASSERT_TRUE(page());
105     LocalFrame* frame = toLocalFrame(page()->mainFrame());
106     ASSERT_TRUE(frame);
107     Document* document = frame->document();
108     ASSERT_TRUE(document);
109 
110     EXPECT_STREQ(kFileURL, frame->domWindow()->location().href().ascii().data());
111 
112     WebCore::SecurityOrigin* origin = document->securityOrigin();
113     EXPECT_STRNE("localhost", origin->domain().ascii().data());
114 }
115 
116 }
117