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

Side by Side Diff: extensions/renderer/script_context_browsertest.cc

Issue 226663003: Allow content script insertion on about:-URLs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move GetEffectiveDocumentURL to ScriptContext Created 6 years, 7 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
« no previous file with comments | « extensions/renderer/script_context.cc ('k') | extensions/renderer/user_script_scheduler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 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.
4
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"
9 #include "url/gurl.h"
10
11 using blink::WebFrame;
12
13 namespace extensions {
14 namespace {
15
16 class ScriptContextTest : public content::RenderViewTest {
17 protected:
18 GURL GetEffectiveDocumentURL(const WebFrame* frame) {
19 return ScriptContext::GetEffectiveDocumentURL(
20 frame, frame->document().url(), true);
21 }
22 };
23
24 TEST_F(ScriptContextTest, GetEffectiveDocumentURL) {
25 GURL top_url("http://example.com/");
26 GURL different_url("http://example.net/");
27 GURL blank_url("about:blank");
28 GURL srcdoc_url("about:srcdoc");
29
30 const char frame_html[] =
31 "<iframe name='frame1' srcdoc=\""
32 " <iframe name='frame1_1'></iframe>"
33 " <iframe name='frame1_2' sandbox=''></iframe>"
34 "\"></iframe>"
35 "<iframe name='frame2' sandbox='' srcdoc=\""
36 " <iframe name='frame2_1'></iframe>"
37 "\"></iframe>"
38 "<iframe name='frame3'></iframe>";
39
40 const char frame3_html[] = "<iframe name='frame3_1'></iframe>";
41
42 WebFrame* frame = GetMainFrame();
43 ASSERT_TRUE(frame);
44
45 frame->loadHTMLString(frame_html, top_url);
46 do {
47 ProcessPendingMessages();
48 } while (frame->isLoading());
49
50 WebFrame* frame1 = frame->findChildByName("frame1");
51 ASSERT_TRUE(frame1);
52 WebFrame* frame1_1 = frame1->findChildByName("frame1_1");
53 ASSERT_TRUE(frame1_1);
54 WebFrame* frame1_2 = frame1->findChildByName("frame1_2");
55 ASSERT_TRUE(frame1_2);
56 WebFrame* frame2 = frame->findChildByName("frame2");
57 ASSERT_TRUE(frame2);
58 WebFrame* frame2_1 = frame2->findChildByName("frame2_1");
59 ASSERT_TRUE(frame2_1);
60 WebFrame* frame3 = frame->findChildByName("frame3");
61 ASSERT_TRUE(frame3);
62
63 // Load a blank document in a frame from a different origin.
64 frame3->loadHTMLString(frame3_html, different_url);
65 do {
66 ProcessPendingMessages();
67 } while (frame3->isLoading());
68
69 WebFrame* frame3_1 = frame->findChildByName("frame3");
70 ASSERT_TRUE(frame3_1);
71
72 // Top-level frame
73 EXPECT_EQ(GetEffectiveDocumentURL(frame), top_url);
74 // top -> srcdoc = inherit
75 EXPECT_EQ(GetEffectiveDocumentURL(frame1), top_url);
76 // top -> srcdoc -> about:blank = inherit
77 EXPECT_EQ(GetEffectiveDocumentURL(frame1_1), top_url);
78 // top -> srcdoc -> about:blank sandboxed = same URL
79 EXPECT_EQ(GetEffectiveDocumentURL(frame1_2), blank_url);
80
81 // top -> srcdoc [sandboxed] = same URL
82 EXPECT_EQ(GetEffectiveDocumentURL(frame2), srcdoc_url);
83 // top -> srcdoc [sandboxed] -> about:blank = same URL
84 EXPECT_EQ(GetEffectiveDocumentURL(frame2_1), blank_url);
85
86 // top -> different origin = different origin
87 EXPECT_EQ(GetEffectiveDocumentURL(frame3), different_url);
88 // top -> different origin -> about:blank = inherit
89 EXPECT_EQ(GetEffectiveDocumentURL(frame3_1), different_url);
90 }
91
92 } // namespace
93 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/script_context.cc ('k') | extensions/renderer/user_script_scheduler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698