OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/site_per_process_browsertest.h" | 5 #include "content/browser/site_per_process_browsertest.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 } | 155 } |
156 | 156 |
157 void RenderFrameHostCreatedObserver::RenderFrameCreated( | 157 void RenderFrameHostCreatedObserver::RenderFrameCreated( |
158 RenderFrameHost* render_frame_host) { | 158 RenderFrameHost* render_frame_host) { |
159 frames_created_++; | 159 frames_created_++; |
160 if (frames_created_ == expected_frame_count_) { | 160 if (frames_created_ == expected_frame_count_) { |
161 message_loop_runner_->Quit(); | 161 message_loop_runner_->Quit(); |
162 } | 162 } |
163 } | 163 } |
164 | 164 |
| 165 // A WebContentsDelegate that catches messages sent to the console. |
| 166 class ConsoleObserverDelegate : public WebContentsDelegate { |
| 167 public: |
| 168 ConsoleObserverDelegate(WebContents* web_contents, const std::string& filter) |
| 169 : web_contents_(web_contents), |
| 170 filter_(filter), |
| 171 message_(""), |
| 172 message_loop_runner_(new MessageLoopRunner) {} |
| 173 |
| 174 ~ConsoleObserverDelegate() override {} |
| 175 |
| 176 bool AddMessageToConsole(WebContents* source, |
| 177 int32 level, |
| 178 const base::string16& message, |
| 179 int32 line_no, |
| 180 const base::string16& source_id) override; |
| 181 |
| 182 std::string message() { return message_; } |
| 183 |
| 184 void Wait(); |
| 185 |
| 186 private: |
| 187 WebContents* web_contents_; |
| 188 std::string filter_; |
| 189 std::string message_; |
| 190 |
| 191 // The MessageLoopRunner used to spin the message loop. |
| 192 scoped_refptr<MessageLoopRunner> message_loop_runner_; |
| 193 |
| 194 DISALLOW_COPY_AND_ASSIGN(ConsoleObserverDelegate); |
| 195 }; |
| 196 |
| 197 void ConsoleObserverDelegate::Wait() { |
| 198 message_loop_runner_->Run(); |
| 199 } |
| 200 |
| 201 bool ConsoleObserverDelegate::AddMessageToConsole( |
| 202 WebContents* source, |
| 203 int32 level, |
| 204 const base::string16& message, |
| 205 int32 line_no, |
| 206 const base::string16& source_id) { |
| 207 DCHECK(source == web_contents_); |
| 208 |
| 209 std::string ascii_message = UTF16ToASCII(message); |
| 210 if (MatchPattern(ascii_message, filter_)) { |
| 211 message_ = ascii_message; |
| 212 message_loop_runner_->Quit(); |
| 213 } |
| 214 return false; |
| 215 } |
| 216 |
165 // | 217 // |
166 // SitePerProcessBrowserTest | 218 // SitePerProcessBrowserTest |
167 // | 219 // |
168 | 220 |
169 SitePerProcessBrowserTest::SitePerProcessBrowserTest() { | 221 SitePerProcessBrowserTest::SitePerProcessBrowserTest() { |
170 }; | 222 }; |
171 | 223 |
172 std::string SitePerProcessBrowserTest::DepictFrameTree(FrameTreeNode* node) { | 224 std::string SitePerProcessBrowserTest::DepictFrameTree(FrameTreeNode* node) { |
173 return visualizer_.DepictFrameTree(node); | 225 return visualizer_.DepictFrameTree(node); |
174 } | 226 } |
(...skipping 1614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1789 GURL foo_url(embedded_test_server()->GetURL("foo.com", "/title1.html")); | 1841 GURL foo_url(embedded_test_server()->GetURL("foo.com", "/title1.html")); |
1790 std::string script = base::StringPrintf( | 1842 std::string script = base::StringPrintf( |
1791 "window.domAutomationController.send(" | 1843 "window.domAutomationController.send(" |
1792 "frames['updated-name'].location.href = '%s');", | 1844 "frames['updated-name'].location.href = '%s');", |
1793 foo_url.spec().c_str()); | 1845 foo_url.spec().c_str()); |
1794 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), script)); | 1846 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), script)); |
1795 frame_observer.Wait(); | 1847 frame_observer.Wait(); |
1796 EXPECT_EQ(foo_url, root->child_at(0)->current_url()); | 1848 EXPECT_EQ(foo_url, root->child_at(0)->current_url()); |
1797 } | 1849 } |
1798 | 1850 |
| 1851 // Verify that when a frame is navigated to a new origin, the origin update |
| 1852 // propagates to the frame's proxies. |
| 1853 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, OriginUpdatesReachProxies) { |
| 1854 GURL main_url( |
| 1855 embedded_test_server()->GetURL("/frame_tree/page_with_two_frames.html")); |
| 1856 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
| 1857 |
| 1858 // It is safe to obtain the root frame tree node here, as it doesn't change. |
| 1859 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
| 1860 ->GetFrameTree() |
| 1861 ->root(); |
| 1862 TestNavigationObserver observer(shell()->web_contents()); |
| 1863 |
| 1864 EXPECT_EQ( |
| 1865 " Site A ------------ proxies for B\n" |
| 1866 " |--Site B ------- proxies for A\n" |
| 1867 " +--Site A ------- proxies for B\n" |
| 1868 "Where A = http://127.0.0.1/\n" |
| 1869 " B = http://bar.com/", |
| 1870 DepictFrameTree(root)); |
| 1871 |
| 1872 // Navigate second subframe to a baz.com. This should send an origin update |
| 1873 // to the frame's proxy in the bar.com (first frame's) process. |
| 1874 GURL frame_url = embedded_test_server()->GetURL("baz.com", "/title2.html"); |
| 1875 NavigateFrameToURL(root->child_at(1), frame_url); |
| 1876 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 1877 EXPECT_EQ(frame_url, observer.last_navigation_url()); |
| 1878 |
| 1879 // The first frame can't directly observe the second frame's origin with |
| 1880 // JavaScript. Instead, try to navigate the second frame from the first |
| 1881 // frame. This should fail with a console error message, which should |
| 1882 // contain the second frame's updated origin (see blink::Frame::canNavigate). |
| 1883 scoped_ptr<ConsoleObserverDelegate> console_delegate( |
| 1884 new ConsoleObserverDelegate( |
| 1885 shell()->web_contents(), |
| 1886 "Unsafe JavaScript attempt to initiate navigation*")); |
| 1887 shell()->web_contents()->SetDelegate(console_delegate.get()); |
| 1888 |
| 1889 // frames[1] can't be used due to a bug where RemoteFrames are created out of |
| 1890 // order (https://crbug.com/478792). Instead, target second frame by name. |
| 1891 EXPECT_TRUE(ExecuteScript( |
| 1892 root->child_at(0)->current_frame_host(), |
| 1893 "window.domAutomationController.send(" |
| 1894 " parent.frames['frame2'].location.href = 'data:text/html,foo');")); |
| 1895 console_delegate->Wait(); |
| 1896 |
| 1897 std::string frame_origin = |
| 1898 root->child_at(1)->current_replication_state().origin.string(); |
| 1899 EXPECT_EQ(frame_origin + "/", frame_url.GetOrigin().spec()); |
| 1900 EXPECT_TRUE( |
| 1901 MatchPattern(console_delegate->message(), "*" + frame_origin + "*")) |
| 1902 << "Error message does not contain the frame's latest origin (" |
| 1903 << frame_origin << ")"; |
| 1904 } |
| 1905 |
1799 // Ensure that navigating subframes in --site-per-process mode properly fires | 1906 // Ensure that navigating subframes in --site-per-process mode properly fires |
1800 // the DidStopLoading event on WebContentsObserver. | 1907 // the DidStopLoading event on WebContentsObserver. |
1801 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, CrossSiteDidStopLoading) { | 1908 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, CrossSiteDidStopLoading) { |
1802 GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html")); | 1909 GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html")); |
1803 NavigateToURL(shell(), main_url); | 1910 NavigateToURL(shell(), main_url); |
1804 | 1911 |
1805 // It is safe to obtain the root frame tree node here, as it doesn't change. | 1912 // It is safe to obtain the root frame tree node here, as it doesn't change. |
1806 FrameTreeNode* root = | 1913 FrameTreeNode* root = |
1807 static_cast<WebContentsImpl*>(shell()->web_contents())-> | 1914 static_cast<WebContentsImpl*>(shell()->web_contents())-> |
1808 GetFrameTree()->root(); | 1915 GetFrameTree()->root(); |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2038 " |--Site A\n" | 2145 " |--Site A\n" |
2039 " +--Site A\n" | 2146 " +--Site A\n" |
2040 " |--Site A\n" | 2147 " |--Site A\n" |
2041 " +--Site A\n" | 2148 " +--Site A\n" |
2042 " +--Site A\n" | 2149 " +--Site A\n" |
2043 "Where A = http://127.0.0.1/", | 2150 "Where A = http://127.0.0.1/", |
2044 DepictFrameTree(root)); | 2151 DepictFrameTree(root)); |
2045 } | 2152 } |
2046 | 2153 |
2047 } // namespace content | 2154 } // namespace content |
OLD | NEW |