Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 "chrome/renderer/extensions/user_script_slave.h" | |
| 6 #include "content/public/test/render_view_test.h" | |
| 7 #include "third_party/WebKit/public/web/WebDocument.h" | |
| 8 #include "url/gurl.h" | |
| 9 | |
| 10 using blink::WebFrame; | |
| 11 using extensions::UserScriptSlave; | |
| 12 | |
| 13 namespace { | |
| 14 | |
| 15 class UserScriptSlaveTest : public content::RenderViewTest { | |
| 16 protected: | |
| 17 GURL GetEffectiveDocumentURL(const WebFrame* frame) { | |
| 18 return UserScriptSlave::GetEffectiveDocumentURL( | |
| 19 frame, frame->document().url(), true); | |
| 20 } | |
| 21 }; | |
| 22 | |
| 23 } // namespace | |
| 24 | |
| 25 TEST_F(UserScriptSlaveTest, 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"); | |
| 30 | |
| 31 const char frame_html[] = | |
| 32 "<iframe name='frame1' srcdoc=\"" | |
| 33 " <iframe name='frame1_1'></iframe>" | |
| 34 " <iframe name='frame1_2' sandbox=''></iframe>" | |
| 35 "\"></iframe>" | |
| 36 "<iframe name='frame2' sandbox='' srcdoc=\"" | |
| 37 " <iframe name='frame2_1'></iframe>" | |
| 38 "\"></iframe>" | |
| 39 "<iframe name='frame3'></iframe>"; | |
| 40 | |
| 41 const char frame3_html[] = "<iframe name='frame3_1'></iframe>"; | |
| 42 | |
| 43 WebFrame* frame = GetMainFrame(); | |
| 44 ASSERT_TRUE(frame); | |
| 45 | |
| 46 frame->loadHTMLString(frame_html, top_url); | |
| 47 do { | |
| 48 ProcessPendingMessages(); | |
| 49 } while (frame->isLoading()); | |
| 50 | |
| 51 WebFrame* frame1 = frame->findChildByName("frame1"); | |
| 52 ASSERT_TRUE(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"); | |
| 58 ASSERT_TRUE(frame2); | |
| 59 WebFrame* frame2_1 = frame2->findChildByName("frame2_1"); | |
| 60 ASSERT_TRUE(frame2_1); | |
| 61 WebFrame* frame3 = frame->findChildByName("frame3"); | |
| 62 ASSERT_TRUE(frame3); | |
| 63 | |
| 64 // Load a blank document in a frame from a different origin. | |
| 65 frame3->loadHTMLString(frame3_html, different_url); | |
| 66 ProcessPendingMessages(); | |
|
dcheng
2014/05/08 00:26:05
How come we call ProcessPendingMessages in a loop
robwu
2014/05/08 12:44:10
I honestly don't know why calling this method once
| |
| 67 | |
| 68 WebFrame* frame3_1 = frame->findChildByName("frame3"); | |
| 69 ASSERT_TRUE(frame3_1); | |
| 70 | |
| 71 // Top-level frame | |
| 72 EXPECT_EQ(GetEffectiveDocumentURL(frame), top_url); | |
| 73 // top -> srcdoc = inherit | |
| 74 EXPECT_EQ(GetEffectiveDocumentURL(frame1), top_url); | |
| 75 // top -> srcdoc -> about:blank = inherit | |
| 76 EXPECT_EQ(GetEffectiveDocumentURL(frame1_1), top_url); | |
| 77 // top -> srcdoc -> about:blank sandboxed = same URL | |
| 78 EXPECT_EQ(GetEffectiveDocumentURL(frame1_2), blank_url); | |
| 79 | |
| 80 // top -> srcdoc [sandboxed] = same URL | |
| 81 EXPECT_EQ(GetEffectiveDocumentURL(frame2), srcdoc_url); | |
| 82 // top -> srcdoc [sandboxed] -> about:blank = same URL | |
| 83 EXPECT_EQ(GetEffectiveDocumentURL(frame2_1), blank_url); | |
| 84 | |
| 85 // top -> different origin = different origin | |
| 86 EXPECT_EQ(GetEffectiveDocumentURL(frame3), different_url); | |
| 87 // top -> different origin -> about:blank = inherit | |
| 88 EXPECT_EQ(GetEffectiveDocumentURL(frame3_1), different_url); | |
| 89 } | |
| OLD | NEW |