1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/public/test/render_view_test.h"
6 #include "extensions/renderer/script_context.h"
7 #include "third_party/WebKit/public/web/WebDocument.h"
8 #include "third_party/WebKit/public/web/WebLocalFrame.h"
11 using blink::WebFrame
;
13 namespace extensions
{
16 class ScriptContextTest
: public content::RenderViewTest
{
18 GURL
GetEffectiveDocumentURL(const WebFrame
* frame
) {
19 return ScriptContext::GetEffectiveDocumentURL(
20 frame
, frame
->document().url(), true);
24 // http://crbug.com/391894
25 TEST_F(ScriptContextTest
, DISABLED_GetEffectiveDocumentURL
) {
26 GURL
top_url("http://example.com/");
27 GURL
different_url("http://example.net/");
28 GURL
blank_url("about:blank");
29 GURL
srcdoc_url("about:srcdoc");
31 const char frame_html
[] =
32 "<iframe name='frame1' srcdoc=\""
33 " <iframe name='frame1_1'></iframe>"
34 " <iframe name='frame1_2' sandbox=''></iframe>"
36 "<iframe name='frame2' sandbox='' srcdoc=\""
37 " <iframe name='frame2_1'></iframe>"
39 "<iframe name='frame3'></iframe>";
41 const char frame3_html
[] = "<iframe name='frame3_1'></iframe>";
43 WebFrame
* frame
= GetMainFrame();
46 frame
->loadHTMLString(frame_html
, top_url
);
48 ProcessPendingMessages();
49 } while (frame
->isLoading());
51 WebFrame
* frame1
= frame
->findChildByName("frame1");
53 WebFrame
* frame1_1
= frame1
->findChildByName("frame1_1");
54 ASSERT_TRUE(frame1_1
);
55 WebFrame
* frame1_2
= frame1
->findChildByName("frame1_2");
56 ASSERT_TRUE(frame1_2
);
57 WebFrame
* frame2
= frame
->findChildByName("frame2");
59 WebFrame
* frame2_1
= frame2
->findChildByName("frame2_1");
60 ASSERT_TRUE(frame2_1
);
61 WebFrame
* frame3
= frame
->findChildByName("frame3");
64 // Load a blank document in a frame from a different origin.
65 frame3
->loadHTMLString(frame3_html
, different_url
);
67 ProcessPendingMessages();
68 } while (frame3
->isLoading());
70 WebFrame
* frame3_1
= frame
->findChildByName("frame3");
71 ASSERT_TRUE(frame3_1
);
74 EXPECT_EQ(GetEffectiveDocumentURL(frame
), top_url
);
75 // top -> srcdoc = inherit
76 EXPECT_EQ(GetEffectiveDocumentURL(frame1
), top_url
);
77 // top -> srcdoc -> about:blank = inherit
78 EXPECT_EQ(GetEffectiveDocumentURL(frame1_1
), top_url
);
79 // top -> srcdoc -> about:blank sandboxed = same URL
80 EXPECT_EQ(GetEffectiveDocumentURL(frame1_2
), blank_url
);
82 // top -> srcdoc [sandboxed] = same URL
83 EXPECT_EQ(GetEffectiveDocumentURL(frame2
), srcdoc_url
);
84 // top -> srcdoc [sandboxed] -> about:blank = same URL
85 EXPECT_EQ(GetEffectiveDocumentURL(frame2_1
), blank_url
);
87 // top -> different origin = different origin
88 EXPECT_EQ(GetEffectiveDocumentURL(frame3
), different_url
);
89 // top -> different origin -> about:blank = inherit
90 EXPECT_EQ(GetEffectiveDocumentURL(frame3_1
), different_url
);
94 } // namespace extensions